68 lines
1.6 KiB
C#
68 lines
1.6 KiB
C#
using AwesomeAssertions;
|
|
using GerstITS.Examples.Logic.Customers;
|
|
using GerstITS.Examples.Logic.Customers.Validation;
|
|
using GerstITS.TestFramework;
|
|
using Xunit;
|
|
|
|
namespace GerstITS.Examples.Tests.Customers.Validation;
|
|
|
|
[TestCategory(TestCategories.Unit)]
|
|
public sealed class CustomerValidationRuleTest
|
|
{
|
|
#region Tests
|
|
|
|
[Fact]
|
|
public void If_a_customer_is_complete___It_is_valid()
|
|
{
|
|
var customer = CreateCustomer();
|
|
|
|
var result = new CustomerValidationRule().Validate((object)customer);
|
|
|
|
result.IsValid.Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void If_the_first_name_is_missing___It_is_invalid()
|
|
{
|
|
var customer = CreateCustomer();
|
|
customer.FirstName = string.Empty;
|
|
|
|
var result = new CustomerValidationRule().Validate((object)customer);
|
|
|
|
result.IsValid.Should().BeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void If_the_email_has_no_valid_format___It_is_invalid()
|
|
{
|
|
var customer = CreateCustomer();
|
|
customer.EMail = "not-an-email";
|
|
|
|
var result = new CustomerValidationRule().Validate((object)customer);
|
|
|
|
result.IsValid.Should().BeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void If_a_customer_type_is_checked___It_can_be_validated()
|
|
{
|
|
new CustomerValidationRule().CanValidate(typeof(Customer)).Should().BeTrue();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
private static Customer CreateCustomer()
|
|
{
|
|
return new Customer
|
|
{
|
|
FirstName = "Erika",
|
|
LastName = "Mustermann",
|
|
EMail = "erika.mustermann@example.com"
|
|
};
|
|
}
|
|
|
|
#endregion
|
|
}
|