Skip to content

Instantly share code, notes, and snippets.

@JayGhb
Created August 9, 2023 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JayGhb/846f5df0287d7239abf4e33938615c69 to your computer and use it in GitHub Desktop.
Save JayGhb/846f5df0287d7239abf4e33938615c69 to your computer and use it in GitHub Desktop.
ValidationUnitTests
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