Skip to content

Commit

Permalink
Merge pull request #564 from dlcs/feature/update_tests
Browse files Browse the repository at this point in the history
Tweak customerValidationTests
  • Loading branch information
donaldgray authored Jul 26, 2023
2 parents 8c7bcff + dfa0aee commit 18407e0
Showing 1 changed file with 41 additions and 25 deletions.
66 changes: 41 additions & 25 deletions src/protagonist/API.Tests/Customers/CustomerValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,15 @@ public CustomerValidationTests()
{
sut = new HydraCustomerValidator();
}

private Customer GetValidNewCustomer()

[Fact]
public void NewCustomer_RequiresOnly_Names()
{
return new Customer
var customer = new Customer
{
Name = "my-test-customer",
DisplayName = "My test customer"
};
}

[Fact]
public void NewCustomer_RequiresOnly_Names()
{
var customer = GetValidNewCustomer();

var result = sut.TestValidate(customer);

Expand All @@ -39,39 +34,60 @@ public void NewCustomer_Requires_Fields()

var result = sut.TestValidate(customer);

result.ShouldHaveAnyValidationError();
result.ShouldHaveValidationErrorFor(c => c.Name);
result.ShouldHaveValidationErrorFor(c => c.DisplayName);
}

[Fact]
public void NewCustomer_CannotBe_Admin()
{
var customer = GetValidNewCustomer();
customer.Administrator = true;

var customer = new Customer
{
Name = "my-test-customer",
DisplayName = "My test customer",
Administrator = true,
};

var result = sut.TestValidate(customer);

result.ShouldHaveAnyValidationError();
result.ShouldHaveValidationErrorFor(c => c.Administrator);
}

[Fact]
public void NewCustomer_CannotHaveName_Admin()
[Theory]
[InlineData("Admin")]
[InlineData("admin")]
[InlineData("ADMIN")]
public void NewCustomer_CannotHaveName_Admin(string invalidName)
{
var customer = GetValidNewCustomer();
customer.Name = "Admin";

var customer = new Customer
{
Name = invalidName,
DisplayName = "My test customer"
};

var result = sut.TestValidate(customer);

result.ShouldHaveAnyValidationError();
result
.ShouldHaveValidationErrorFor(c => c.Name)
.WithErrorMessage($"Name field [{invalidName}] cannot be a reserved word.");
}

[Fact]
public void NewCustomer_CannotHaveName_Version()
[Theory]
[InlineData("v2-customer")]
[InlineData("v2")]
[InlineData("v3")]
public void NewCustomer_CannotHaveName_Version(string invalidName)
{
var customer = GetValidNewCustomer();
customer.Name = "v2-customer";
var customer = new Customer
{
Name = invalidName,
DisplayName = "My test customer"
};

var result = sut.TestValidate(customer);

result.ShouldHaveAnyValidationError();
result
.ShouldHaveValidationErrorFor(c => c.Name)
.WithErrorMessage($"Name field [{invalidName}] cannot start with a version slug.");
}
}

0 comments on commit 18407e0

Please sign in to comment.