Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ namespace EvolutionaryArchitecture.Fitnet.Common.Api.UnitTests;

using ErrorHandling;
using Core.BusinessRules;
using System.IO;
using System.Threading.Tasks;
using System;

public sealed class ExceptionMiddlewareTests
{
Expand All @@ -19,10 +22,10 @@ internal async Task Given_business_rule_validation_exception_Then_returns_confli
await middleware.InvokeAsync(_context);

// Assert
_context.Response.StatusCode.Should().Be((int)HttpStatusCode.Conflict);
_context.Response.StatusCode.ShouldBe((int)HttpStatusCode.Conflict);

var responseMessage = await GetExceptionResponseMessage();
responseMessage.Should().Be(exceptionMessage);
responseMessage.ShouldBe(exceptionMessage);
}

[Fact]
Expand All @@ -37,10 +40,10 @@ internal async Task Given_other_than_business_rule_validation_exception_Then_ret
await middleware.InvokeAsync(_context);

// Assert
_context.Response.StatusCode.Should().Be((int)HttpStatusCode.InternalServerError);
_context.Response.StatusCode.ShouldBe((int)HttpStatusCode.InternalServerError);

var responseMessage = await GetExceptionResponseMessage();
responseMessage.Should().Be(exceptionMessage);
responseMessage.ShouldBe(exceptionMessage);
}

private static DefaultHttpContext GetHttpContext() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Shouldly" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
global using System.Net;
global using Xunit;
global using FluentAssertions;
global using Microsoft.AspNetCore.Http;
global using Newtonsoft.Json;
global using Newtonsoft.Json;
global using Shouldly;
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ internal void Given_concrete_business_rule_which_is_met_Then_validation_should_p
// Arrange

// Act
var act = () => BusinessRuleValidator.Validate(new FakeBusinessRule(20));
static void FakeBusinessRule()
{
BusinessRuleValidator.Validate(new FakeBusinessRule(20));
}

// Assert
act.Should().NotThrow<BusinessRuleValidationException>();
Should.NotThrow(FakeBusinessRule);
}

[Fact]
Expand All @@ -22,9 +25,13 @@ internal void Given_concrete_business_rule_which_is_not_met_Then_validation_shou
// Arrange

// Act
var act = () => BusinessRuleValidator.Validate(new FakeBusinessRule(1));
static void NotMetRuleAction()
{
BusinessRuleValidator.Validate(new FakeBusinessRule(1));
}

// Assert
act.Should().Throw<BusinessRuleValidationException>().WithMessage("Fake business rule was not met");
var exception = Should.Throw<BusinessRuleValidationException>(NotMetRuleAction);
exception.Message.ShouldBe("Fake business rule was not met");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Shouldly" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
global using Shouldly;
global using Xunit;
global using FluentAssertions;
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ namespace EvolutionaryArchitecture.Fitnet.Common.IntegrationTestsToolbox.TestEng

public interface IDatabaseConfiguration
{
public Dictionary<string, string?> Get();
}
Dictionary<string, string?> Get();
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ public static async Task<IEnumerable<IReceivedMessage<TMessage>>> WaitToConsumeM
}
}

return testHarness.Consumed!.Select<TMessage>(cancellationToken)!.ToList();
return [.. testHarness.Consumed!.Select<TMessage>(cancellationToken)];
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Bogus" Version="35.6.1" />
<PackageReference Include="FluentAssertions" Version="6.12.2" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.analyzers" Version="1.17.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ItemGroup>
<PackageReference Include="Bogus" Version="35.6.1" />
<PackageReference Include="EvolutionaryArchitecture.Fitnet.Common.Core" Version="3.2.5" />
<PackageReference Include="FluentAssertions" Version="6.12.2" />
<PackageReference Include="Shouldly" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.analyzers" Version="1.17.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
global using FluentAssertions;
global using System;
global using Shouldly;
global using Xunit;
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,31 @@ public sealed class ContractCanBePreparedOnlyForAdultRuleTests
internal void Given_customer_age_which_is_less_than_18_Then_validation_should_throw()
{
// Arrange
const int minorAge = 17;

// Act
var act = () => BusinessRuleValidator.Validate(new ContractCanBePreparedOnlyForAdultRule(17));

// Assert
act.Should().Throw<BusinessRuleValidationException>().WithMessage("Contract can not be prepared for a person who is not adult");
// Act & Assert
var exception = Should.Throw<BusinessRuleValidationException>(() =>
BusinessRuleValidator.Validate(new ContractCanBePreparedOnlyForAdultRule(minorAge)));
exception.Message.ShouldBe("Contract can not be prepared for a person who is not adult");
}

[Fact]
internal void Given_customer_age_which_is_equal_to_18_Then_validation_should_pass()
{
// Arrange
const int exactLegalAge = 18;

// Act
var act = () => BusinessRuleValidator.Validate(new ContractCanBePreparedOnlyForAdultRule(18));

// Assert
act.Should().NotThrow<BusinessRuleValidationException>();
// Act & Assert
Should.NotThrow(() => BusinessRuleValidator.Validate(new ContractCanBePreparedOnlyForAdultRule(exactLegalAge)));
}

[Fact]
internal void Given_customer_age_which_is_greater_than_18_Then_validation_should_pass()
{
// Arrange
const int adultAge = 19;

// Act
var act = () => BusinessRuleValidator.Validate(new ContractCanBePreparedOnlyForAdultRule(19));

// Assert
act.Should().NotThrow<BusinessRuleValidationException>();
// Act & Assert
Should.NotThrow(() => BusinessRuleValidator.Validate(new ContractCanBePreparedOnlyForAdultRule(adultAge)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ internal void Given_customer_height_which_is_greater_than_maximum_height_limit_T
// Arrange
const int height = 211;

// Act
var act = () => BusinessRuleValidator.Validate(new CustomerMustBeSmallerThanMaximumHeightLimitRule(height));
// Act & Assert
var exception = Should.Throw<BusinessRuleValidationException>(() =>
BusinessRuleValidator.Validate(new CustomerMustBeSmallerThanMaximumHeightLimitRule(height)));

// Assert
act.Should().Throw<BusinessRuleValidationException>().WithMessage("Customer height must fit maximum limit for gym instruments");
exception.Message.ShouldBe("Customer height must fit maximum limit for gym instruments");
}

[Fact]
Expand All @@ -24,11 +24,8 @@ internal void Given_customer_height_which_is_equal_to_maximum_height_limit_Then_
// Arrange
const int height = 210;

// Act
var act = () => BusinessRuleValidator.Validate(new CustomerMustBeSmallerThanMaximumHeightLimitRule(height));

// Assert
act.Should().NotThrow<BusinessRuleValidationException>();
// Act & Assert
Should.NotThrow(() => BusinessRuleValidator.Validate(new CustomerMustBeSmallerThanMaximumHeightLimitRule(height)));
}

[Fact]
Expand All @@ -37,10 +34,7 @@ internal void Given_customer_height_which_is_less_than_maximum_height_limit_Then
// Arrange
const int height = 209;

// Act
var act = () => BusinessRuleValidator.Validate(new CustomerMustBeSmallerThanMaximumHeightLimitRule(height));

// Assert
act.Should().NotThrow<BusinessRuleValidationException>();
// Act & Assert
Should.NotThrow(() => BusinessRuleValidator.Validate(new CustomerMustBeSmallerThanMaximumHeightLimitRule(height)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,22 @@ namespace EvolutionaryArchitecture.Fitnet.Contracts.Core.UnitTests.PrepareContra
public sealed class PreviousContractHasToBeSignedRuleTests
{
[Fact]
internal void Given_previous_contract_signed_Then_validation_should_pass()
{
// Arrange

// Act
var act = () => BusinessRuleValidator.Validate(new PreviousContractHasToBeSignedRule(true));

// Assert
act.Should().NotThrow<BusinessRuleValidationException>();
}
internal void Given_previous_contract_signed_Then_validation_should_pass() =>
// Arrange & Act & Assert
Should.NotThrow(() => BusinessRuleValidator.Validate(new PreviousContractHasToBeSignedRule(true)));

[Fact]
internal void Given_previous_contract_not_exists_Then_validation_should_pass()
{
// Arrange

// Act
var act = () => BusinessRuleValidator.Validate(new PreviousContractHasToBeSignedRule(null));

// Assert
act.Should().NotThrow<BusinessRuleValidationException>();
}

internal void Given_previous_contract_not_exists_Then_validation_should_pass() =>
// Arrange & Act & Assert
Should.NotThrow(() => BusinessRuleValidator.Validate(new PreviousContractHasToBeSignedRule(null)));

[Fact]
internal void Given_previous_contract_unsigned_Then_validation_should_throw()
{
// Arrange

// Act
var act = () => BusinessRuleValidator.Validate(new PreviousContractHasToBeSignedRule(false));
// Arrange & Act & Assert
var exception = Should.Throw<BusinessRuleValidationException>(() =>
BusinessRuleValidator.Validate(new PreviousContractHasToBeSignedRule(false)));

// Assert
act.Should().Throw<BusinessRuleValidationException>().WithMessage("Previous contract must be signed by the customer");
exception.Message.ShouldBe("Previous contract must be signed by the customer");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,29 @@ public sealed class ContractCanOnlyBeSignedWithin30DaysFromPreparationTests
[Fact]
internal void Given_signed_at_date_which_is_more_than_30_days_from_prepared_at_date_Then_validation_should_throw()
{
// Arrange

// Act
var act = () =>
// Arrange & Act & Assert
var exception = Should.Throw<BusinessRuleValidationException>(() =>
BusinessRuleValidator.Validate(
new ContractCanOnlyBeSignedWithin30DaysFromPreparation(DateTimeOffset.Now,
DateTimeOffset.Now.AddDays(31)));
DateTimeOffset.Now.AddDays(31))));

// Assert
act.Should().Throw<BusinessRuleValidationException>().WithMessage(
exception.Message.ShouldBe(
"Contract can not be signed because more than 30 days have passed from the contract preparation");
}

[Fact]
internal void Given_signed_at_date_which_is_30_days_from_prepared_at_date_Then_validation_should_pass()
{
// Arrange

// Act
var act = () =>
internal void Given_signed_at_date_which_is_30_days_from_prepared_at_date_Then_validation_should_pass() =>
// Arrange & Act & Assert
Should.NotThrow(() =>
BusinessRuleValidator.Validate(
new ContractCanOnlyBeSignedWithin30DaysFromPreparation(DateTimeOffset.Now,
DateTimeOffset.Now.AddDays(30)));

// Assert
act.Should().NotThrow<BusinessRuleValidationException>();
}
DateTimeOffset.Now.AddDays(30))));

[Fact]
internal void Given_signed_at_date_which_is_less_than_30_days_from_prepared_at_date_Then_validation_should_pass()
{
// Arrange

// Act
var act = () =>
internal void Given_signed_at_date_which_is_less_than_30_days_from_prepared_at_date_Then_validation_should_pass() =>
// Arrange & Act & Assert
Should.NotThrow(() =>
BusinessRuleValidator.Validate(
new ContractCanOnlyBeSignedWithin30DaysFromPreparation(DateTimeOffset.Now,
DateTimeOffset.Now.AddDays(29)));

// Assert
act.Should().NotThrow<BusinessRuleValidationException>();
}
DateTimeOffset.Now.AddDays(29))));
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal void Given_sign_contract_Then_expiration_date_is_set_to_contract_durati
contract.Sign(signedAt, fakeNow);

// Assert
contract.ExpiringAt.Should().Be(expectedExpirationDate);
contract.ExpiringAt.ShouldBe(expectedExpirationDate);
}

private static Contract PrepareContract(DateTimeOffset preparedAt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<PackageReference Include="evolutionaryarchitecture.fitnet.common.api" Version="3.2.5" />
<PackageReference Include="evolutionaryarchitecture.fitnet.common.integrationteststoolbox" Version="3.2.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Shouldly" Version="4.3.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.Json" Version="9.0.0" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
global using System.Net.Http.Json;
global using Xunit;
global using Bogus;
global using FluentAssertions;
global using Shouldly;
Loading