Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block direct modification of Value-property in configuration options #1994

Merged
merged 1 commit into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/csharp/Pester/GenericOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Option(string description, T defaultValue, T value)

public T Default { get; private set; }
public string Description { get; private set; }
public T Value { get; set; }
public T Value { get; private set; }

public override string ToString()
{
Expand Down
17 changes: 17 additions & 0 deletions tst/Pester.RSpec.Configuration.ts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,23 @@ i -PassThru:$PassThru {
Verify-Equal $path[0].ToString() -Actual $config.Run.Path.Value[0]
Verify-Equal $path[1].ToString() -Actual $config.Run.Path.Value[1]
}

t "Modifying the private Default property of an option throws" {
$config = [PesterConfiguration]::Default
{ $config.Run.Path.Default = 'invalid' } | Verify-Throw
}

t "Modifying the private Value property of an option throws" {
$config = [PesterConfiguration]::Default
{ $config.Run.Path.Value = 'invalid' } | Verify-Throw
}

t "IsOriginalValue returns false after change even if same as default" {
$config = [PesterConfiguration]::Default
$config.Run.Path.IsOriginalValue() | Verify-True
$config.Run.Path = $config.Run.Path.Default
$config.Run.Path.IsOriginalValue() | Verify-False
}
}

b "Cloning" {
Expand Down