Created
August 9, 2023 10:34
-
-
Save JayGhb/846f5df0287d7239abf4e33938615c69 to your computer and use it in GitHub Desktop.
ValidationUnitTests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CreateCustomerCommandValidatorUnitTests | |
{ | |
private CreateCustomerCommandValidator validator; | |
public CreateCustomerCommandValidatorUnitTests() | |
{ | |
validator = new CreateCustomerCommandValidator(); | |
} | |
[Fact] | |
public async Task Empty_Latitude_Fails_Validation() | |
{ | |
//Arrange | |
AddressValue fakeAddress = new AddressValue("", "23.2565"); | |
CreateCustomerCommand fakeCommand = new CreateCustomerCommand(fakeAddress); | |
//Act | |
TestValidationResult<CreateCustomerCommand> actualResult = await validator.TestValidateAsync(fakeCommand); | |
//Assert | |
actualResult.ShouldHaveValidationErrorFor(command => command.Address.Latitude); | |
} | |
[Fact] | |
public async Task Valid_Address_Passes_Validation() | |
{ | |
//Arrange | |
AddressValue fakeAddress = new AddressValue("40.367404", "22.419266"); | |
CreateCustomerCommand fakeCommand = new CreateCustomerCommand(fakeAddress); | |
//Act | |
TestValidationResult<CreateCustomerCommand> actualResult = await validator.TestValidateAsync(fakeCommand); | |
//Assert | |
actualResult.ShouldNotHaveValidationErrorFor(command => command.Address.Latitude); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment