Update to latest packages and show examples
This commit is contained in:
+35
@@ -0,0 +1,35 @@
|
||||
using AwesomeAssertions;
|
||||
using GerstITS.Examples.Logic.Customers;
|
||||
using GerstITS.Examples.Logic.Customers.Customizations;
|
||||
using GerstITS.System.Customizations;
|
||||
using GerstITS.TestFramework;
|
||||
using Xunit;
|
||||
|
||||
namespace GerstITS.Examples.Tests.Customers.Customizations;
|
||||
|
||||
[TestCategory(TestCategories.Unit)]
|
||||
public sealed class CustomerDisplayNameCustomizationTest
|
||||
{
|
||||
#region Tests
|
||||
|
||||
[Fact]
|
||||
public void If_a_customer_is_customized___The_display_name_is_composed()
|
||||
{
|
||||
ICustomization customization = new CustomerDisplayNameCustomization();
|
||||
var customer = new Customer { FirstName = "Erika", LastName = "Mustermann" };
|
||||
|
||||
var customized = customization.Customize(customer, null);
|
||||
|
||||
customized.DisplayName.Should().Be("Mustermann, Erika");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void If_the_customer_is_null___It_cannot_be_customized()
|
||||
{
|
||||
ICustomization customization = new CustomerDisplayNameCustomization();
|
||||
|
||||
customization.CanCustomize<Customer>(null, null).Should().BeFalse();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
using AwesomeAssertions;
|
||||
using GerstITS.Examples.Logic.Customers;
|
||||
using GerstITS.Examples.Logic.Customers.Search;
|
||||
using GerstITS.TestFramework;
|
||||
using Xunit;
|
||||
|
||||
namespace GerstITS.Examples.Tests.Customers.Search;
|
||||
|
||||
[TestCategory(TestCategories.Unit)]
|
||||
public sealed class CustomerSearchFilterInitializationRuleTest
|
||||
{
|
||||
#region Tests
|
||||
|
||||
[Fact]
|
||||
public void If_the_filter_is_empty___Defaults_are_applied()
|
||||
{
|
||||
var filter = new CustomerSearchFilter();
|
||||
|
||||
var initialized = new CustomerSearchFilterInitializationRule().Initialize(filter);
|
||||
|
||||
initialized.Skip.Should().Be(0);
|
||||
initialized.Take.Should().Be(50);
|
||||
initialized.SortBy.Should().Be(nameof(Customer.LastName));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void If_the_filter_is_already_configured___Values_are_kept()
|
||||
{
|
||||
var filter = new CustomerSearchFilter
|
||||
{
|
||||
Skip = 10,
|
||||
Take = 5,
|
||||
SortBy = nameof(Customer.EMail)
|
||||
};
|
||||
|
||||
var initialized = new CustomerSearchFilterInitializationRule().Initialize(filter);
|
||||
|
||||
initialized.Skip.Should().Be(10);
|
||||
initialized.Take.Should().Be(5);
|
||||
initialized.SortBy.Should().Be(nameof(Customer.EMail));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void If_another_filter_type_is_checked___It_cannot_be_initialized()
|
||||
{
|
||||
new CustomerSearchFilterInitializationRule().CanInitialize<string>().Should().BeFalse();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="GerstITS.TestFramework" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="AwesomeAssertions" />
|
||||
<PackageReference Include="xunit" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\GerstITS.Examples.Logic\GerstITS.Examples.Logic.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,57 @@
|
||||
using AwesomeAssertions;
|
||||
using GerstITS.Examples.Logic.Customers;
|
||||
using GerstITS.Examples.Logic.Shared.Search.Sorting;
|
||||
using GerstITS.Search;
|
||||
using GerstITS.TestFramework;
|
||||
using Xunit;
|
||||
|
||||
namespace GerstITS.Examples.Tests.Shared.Search.Sorting;
|
||||
|
||||
[TestCategory(TestCategories.Unit)]
|
||||
public sealed class SortingProviderTest
|
||||
{
|
||||
#region Tests
|
||||
|
||||
[Fact]
|
||||
public void If_customers_are_sorted_descending___The_order_is_reversed()
|
||||
{
|
||||
var query = CreateCustomers().AsQueryable();
|
||||
var sorting = new CustomerSearchFilter { SortBy = nameof(Customer.LastName), SortDirection = SortingDirections.Descending };
|
||||
|
||||
var sorted = new SortingProvider().Sort(query, sorting);
|
||||
|
||||
sorted.First().LastName.Should().Be("Zimmermann");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void If_the_sort_property_is_unknown___The_query_is_left_unchanged()
|
||||
{
|
||||
var query = CreateCustomers().AsQueryable();
|
||||
var sorting = new CustomerSearchFilter { SortBy = "Unknown" };
|
||||
|
||||
var sorted = new SortingProvider().Sort(query, sorting);
|
||||
|
||||
sorted.Last().LastName.Should().Be("Zimmermann");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void If_the_item_type_is_not_sortable___It_cannot_be_sorted()
|
||||
{
|
||||
new SortingProvider().CanSort(new[] { "a" }.AsQueryable()).Should().BeFalse();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private static IEnumerable<Customer> CreateCustomers()
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
new Customer { FirstName = "Anna", LastName = "Albrecht" },
|
||||
new Customer { FirstName = "Zoe", LastName = "Zimmermann" }
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using AwesomeAssertions;
|
||||
using GerstITS.Examples.Logic.Shared.Validation;
|
||||
using GerstITS.TestFramework;
|
||||
using Xunit;
|
||||
|
||||
namespace GerstITS.Examples.Tests.Shared.Validation;
|
||||
|
||||
[TestCategory(TestCategories.Unit)]
|
||||
public sealed class IdValidationRuleTest
|
||||
{
|
||||
#region Tests
|
||||
|
||||
[Fact]
|
||||
public void If_the_id_is_positive___It_is_valid()
|
||||
{
|
||||
var result = new IdValidationRule().Validate((object)1);
|
||||
|
||||
result.IsValid.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void If_the_id_is_zero___It_is_invalid()
|
||||
{
|
||||
var result = new IdValidationRule().Validate((object)0);
|
||||
|
||||
result.IsValid.Should().BeFalse();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user