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

closes #161 Auto-Evaluation of the Status property when Errors ou ValidationErrors are added to the result. #162

Merged

Conversation

Ewerton
Copy link
Contributor

@Ewerton Ewerton commented Feb 1, 2024

Auto-evaluate the Status property when Errors ou ValidationErrors are added to the result.
It only works when the result is created as Ok(), Error() ou Invalid().

The following unit test describes the functioning of this PR

 [Fact]
 public void ErrorAndValidationErrorChanged()
 {
     Result result = Result.Success(); // Created as Ok
     result.IsSuccess.Should().Be(true);
     result.Status.Should().Be(ResultStatus.Ok);

     // Adding a validation error
     result.ValidationErrors.Add(new ValidationError("Validation Error 1"));
     result.IsSuccess.Should().Be(false);
     result.Status.Should().Be(ResultStatus.Invalid); // <- Status changed to Invalid

     // Adding an Error
     result.Errors.Add("Error 1");
     result.IsSuccess.Should().Be(false);
     result.Status.Should().Be(ResultStatus.Error); // <- Status changed to Error

     // clearing the errors (still remain one Validation Error, so it's Invalid)
     result.Errors.Clear();
     result.IsSuccess.Should().Be(false);
     result.Status.Should().Be(ResultStatus.Invalid); // <- Status changed to Invalid

     // clearing the validation errors. It should revert back to the initial status
     result.ValidationErrors.Clear();
     result.IsSuccess.Should().Be(true);
     result.Status.Should().Be(ResultStatus.Ok); // <- reverted back to its initial state
 }

Auto-evaluatie the Status property when Errors ou ValidationErrors are added to the result.
It only works when teh result is created as Ok(), Error() ou Invalid()
@ardalis
Copy link
Owner

ardalis commented Feb 28, 2024

I'll bring this in separately since it's breaking change.

Copy link

Code Coverage

Package Line Rate Branch Rate Complexity Health
Ardalis.Result.AspNetCore 54% 60% 159
Ardalis.Result.Sample.Core 38% 38% 63
Ardalis.Result.SampleWeb 66% 50% 43
Ardalis.Result 38% 24% 137
Ardalis.Result.FluentValidation 0% 0% 6
Summary 48% (497 / 1041) 45% (114 / 256) 408

@ardalis ardalis merged commit 60a0dbe into ardalis:main Feb 28, 2024
1 check passed
KyleMcMaster added a commit that referenced this pull request Mar 9, 2024
This reverts commit 60a0dbe.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants