Skip to content

Commit

Permalink
refactor: use domain events in sign contracts tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilbaczek committed Mar 23, 2024
1 parent 8b05e1f commit a00566d
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace EvolutionaryArchitecture.Fitnet.Contracts.Core.UnitTests.Common;

using DomainDrivenDesign.BuildingBlocks;

internal static class EntityExtensions
{
public static TEvent? GetPublishedEvent<TEvent>(this Entity entity) where TEvent : class, IDomainEvent => entity.Events.OfType<TEvent>()
.MinBy(domainEvent => domainEvent.OccuredAt);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace EvolutionaryArchitecture.Fitnet.Contracts.Core.UnitTests.PrepareContract.BusinessRules;

using Common.Core.BusinessRules;
using Core.PrepareContract.BusinessRules;
using Fitnet.Common.Core.BusinessRules;

public sealed class ContractCanBePreparedOnlyForAdultRuleTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace EvolutionaryArchitecture.Fitnet.Contracts.Core.UnitTests.PrepareContract.BusinessRules;

using Common.Core.BusinessRules;
using Core.PrepareContract.BusinessRules;
using Fitnet.Common.Core.BusinessRules;

public sealed class CustomerMustBeSmallerThanMaximumHeightLimitRuleTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace EvolutionaryArchitecture.Fitnet.Contracts.Core.UnitTests.PrepareContract.BusinessRules;

using Common.Core.BusinessRules;
using Core.PrepareContract.BusinessRules;
using Fitnet.Common.Core.BusinessRules;

public sealed class PreviousContractHasToBeSignedRuleTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace EvolutionaryArchitecture.Fitnet.Contracts.Core.UnitTests.SignContract.BusinessRules;

using Common.Core.BusinessRules;
using Core.SignContract.BusinessRules;
using Fitnet.Common.Core.BusinessRules;

public sealed class ContractCanOnlyBeSignedWithin30DaysFromPreparationTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace EvolutionaryArchitecture.Fitnet.Contracts.Core.UnitTests.SignContract;

using Common;
using Core.SignContract;
using PrepareContract;

public class SignContractTests
public sealed class SignContractTests
{
[Theory]
[ClassData(typeof(SignContractTestData))]
Expand All @@ -19,7 +21,8 @@ internal void Given_sign_contract_Then_expiration_date_is_set_to_contract_durati
var bindingContract = contract.Sign(signedAt, fakeNow);

// Assert
bindingContract.ExpiringAt.Should().Be(expectedExpirationDate);
var @event = bindingContract.GetPublishedEvent<ContractStartedBindingEvent>();
@event?.ExpiringAt.Should().Be(expectedExpirationDate);
}

private static readonly DateTimeOffset PreparedAt = new(2023, 1, 1, 0, 0, 0, TimeSpan.Zero);
Expand All @@ -36,8 +39,8 @@ internal void Given_sign_contract_Then_contracts_becomes_binding_contract()
var bindingContract = contract.Sign(SignedAt, FakeNow);

// Assert
bindingContract.Should().NotBeNull();
bindingContract.Should().BeOfType<BindingContract>();
var @event = bindingContract.GetPublishedEvent<ContractStartedBindingEvent>();
@event?.BindingFrom.Should().Be(SignedAt);
}

private static Contract PrepareContract(DateTimeOffset preparedAt)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace EvolutionaryArchitecture.Fitnet.Contracts.Core.UnitTests.TerminateBindingContract.BusinessRules;

using Common.Core.BusinessRules;
using Fitnet.Common.Core.BusinessRules;
using TerminateContract.BusinessRules;
using TerminationIsPossibleOnlyAfterThreeMonthsHavePassed.TestData;

Expand Down

0 comments on commit a00566d

Please sign in to comment.