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
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<NoWarn>$(NoWarn);NU1507</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="AspNetCore.HealthChecks.SqlServer" Version="9.0.0" />
Expand Down Expand Up @@ -101,4 +102,4 @@
<ItemGroup Condition="'$(MSBuildProjectName)' == 'TransactionProcessor.Reconciliation.DomainEvents'">
<PackageVersion Include="Shared.DomainDrivenDesign" Version="2025.1.2" />
</ItemGroup>
</Project>
</Project>
16 changes: 16 additions & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@
<add key="Feedz" value="https://f.feedz.io/transactionprocessing/nugets/nuget/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<packageSourceMapping>
<packageSource key="Feedz">
<package pattern="CallbackHandler.*" />
<package pattern="ClientProxyBase" />
<package pattern="EventStoreProjections" />
<package pattern="FileProcessor.*" />
<package pattern="MessagingService.*" />
<package pattern="SecurityService.*" />
<package pattern="Shared" />
<package pattern="Shared.*" />
<package pattern="TestHosts.Clients" />
</packageSource>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
</packageSourceMapping>
<packageSourceCredentials>
<Feedz>
<add key="Username" value="TestUser" />
Expand Down
16 changes: 7 additions & 9 deletions TransactionProcessor.Aggregates.Tests/FloatAggregateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,28 @@ public void FloatAggregate_CanBeCreated_IsCreated()
public void FloatAggregate_CreateFloat_IsCreated()
{
Aggregates.FloatAggregate aggregate = Aggregates.FloatAggregate.Create(TestData.FloatAggregateId);
Result result = aggregate.CreateFloat(TestData.EstateId, TestData.ContractId, TestData.ProductId, TestData.FloatCreatedDateTime);
Result result = aggregate.CreateFloat(TestData.EstateId, TestData.FloatCreatedDateTime);
result.IsSuccess.ShouldBeTrue();

aggregate.AggregateId.ShouldBe(TestData.FloatAggregateId);
aggregate.EstateId.ShouldBe(TestData.EstateId);
aggregate.ContractId.ShouldBe(TestData.ContractId);
aggregate.ProductId.ShouldBe(TestData.ProductId);
aggregate.CreatedDateTime.ShouldBe(TestData.FloatCreatedDateTime);
}

[Fact]
public void FloatAggregate_CreateFloat_FloatAlreadyCreated_NoErrorThrown() {
Aggregates.FloatAggregate aggregate = Aggregates.FloatAggregate.Create(TestData.FloatAggregateId);
aggregate.CreateFloat(TestData.EstateId, TestData.ContractId, TestData.ProductId, TestData.FloatCreatedDateTime);
aggregate.CreateFloat(TestData.EstateId, TestData.FloatCreatedDateTime);

Result result = aggregate.CreateFloat(TestData.EstateId, TestData.ContractId, TestData.ProductId, TestData.FloatCreatedDateTime);
Result result = aggregate.CreateFloat(TestData.EstateId, TestData.FloatCreatedDateTime);
result.IsSuccess.ShouldBeTrue();
}

[Fact]
public void FloatAggregate_RecordCreditPurchase_CreditPurchaseIsRecorded()
{
Aggregates.FloatAggregate aggregate = Aggregates.FloatAggregate.Create(TestData.FloatAggregateId);
aggregate.CreateFloat(TestData.EstateId, TestData.ContractId, TestData.ProductId, TestData.FloatCreatedDateTime);
aggregate.CreateFloat(TestData.EstateId, TestData.FloatCreatedDateTime);
Result result = aggregate.RecordCreditPurchase(DateTime.Now, 1000, 900);
result.IsSuccess.ShouldBeTrue();
aggregate.NumberOfCreditPurchases.ShouldBe(1);
Expand All @@ -70,7 +68,7 @@ public void FloatAggregate_RecordCreditPurchase_FloatNotCreated_ErrorThrown()
public void FloatAggregate_RecordCreditPurchase_MultipleCreditPurchases_AllCreditPurchasesAreRecorded()
{
Aggregates.FloatAggregate aggregate = Aggregates.FloatAggregate.Create(TestData.FloatAggregateId);
aggregate.CreateFloat(TestData.EstateId, TestData.ContractId, TestData.ProductId, TestData.FloatCreatedDateTime);
aggregate.CreateFloat(TestData.EstateId, TestData.FloatCreatedDateTime);
aggregate.RecordCreditPurchase(DateTime.Now, 1000, 900);

aggregate.NumberOfCreditPurchases.ShouldBe(1);
Expand Down Expand Up @@ -103,7 +101,7 @@ public void FloatAggregate_RecordCreditPurchase_MultipleCreditPurchases_AllCredi
public void FloatAggregate_RecordCreditPurchase_DuplicateCreditPurchase_ErrorThrown()
{
Aggregates.FloatAggregate aggregate = Aggregates.FloatAggregate.Create(TestData.FloatAggregateId);
aggregate.CreateFloat(TestData.EstateId, TestData.ContractId, TestData.ProductId, TestData.FloatCreatedDateTime);
aggregate.CreateFloat(TestData.EstateId, TestData.FloatCreatedDateTime);
DateTime purchaseDateTime = DateTime.Now;
aggregate.RecordCreditPurchase(purchaseDateTime, 1000, 900);

Expand All @@ -118,7 +116,7 @@ public void FloatAggregate_RecordCreditPurchase_DuplicateCreditPurchase_ErrorThr
public void FloatAggregate_GetTotalCostPrice_TotalCostReturned()
{
Aggregates.FloatAggregate aggregate = Aggregates.FloatAggregate.Create(TestData.FloatAggregateId);
aggregate.CreateFloat(TestData.EstateId, TestData.ContractId, TestData.ProductId, TestData.FloatCreatedDateTime);
aggregate.CreateFloat(TestData.EstateId, TestData.FloatCreatedDateTime);
DateTime purchaseDateTime = DateTime.Now;
aggregate.RecordCreditPurchase(purchaseDateTime, 1000, 900);

Expand Down
20 changes: 10 additions & 10 deletions TransactionProcessor.Aggregates/FloatAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ namespace TransactionProcessor.Aggregates
{
public static class FloatAggregateExtensions
{
public static void PlayEvent(this FloatAggregate aggregate, FloatDomainEvents.FloatCreatedEvent domainEvent)
{
aggregate.EstateId = domainEvent.EstateId;
aggregate.CreatedDateTime = domainEvent.CreatedDateTime;
aggregate.IsCreated = true;
}

public static void PlayEvent(this FloatAggregate aggregate, FloatDomainEvents.FloatCreatedForContractProductEvent domainEvent)
{
aggregate.EstateId = domainEvent.EstateId;
aggregate.ContractId = domainEvent.ContractId;
aggregate.ProductId = domainEvent.ProductId;
aggregate.CreatedDateTime = domainEvent.CreatedDateTime;
aggregate.IsCreated = true;
}
Expand All @@ -29,18 +34,16 @@ public static void PlayEvent(this FloatAggregate aggregate, FloatDomainEvents.Fl

public static Result CreateFloat(this FloatAggregate aggregate,
Guid estateId,
Guid contractId,
Guid productId,
DateTime createdDateTime)
{
if (aggregate.IsCreated) {
return Result.Success(); // Idempotent
}

FloatDomainEvents.FloatCreatedForContractProductEvent floatCreatedForContractProductEvent = new(aggregate.AggregateId,
estateId, contractId, productId, createdDateTime);
FloatDomainEvents.FloatCreatedEvent floatCreatedEvent = new(aggregate.AggregateId,
estateId, createdDateTime);

aggregate.ApplyAndAppend(floatCreatedForContractProductEvent);
aggregate.ApplyAndAppend(floatCreatedEvent);

return Result.Success();
}
Expand Down Expand Up @@ -129,9 +132,6 @@ private FloatAggregate(Guid aggregateId)
public Boolean IsCreated { get; internal set; }

public Guid EstateId { get; internal set; }

public Guid ContractId { get; internal set; }
public Guid ProductId { get; internal set; }
public DateTime CreatedDateTime { get; internal set; }

public Int32 NumberOfCreditPurchases { get; internal set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Moq;
using Moq;
using Shared.Logger;
using Shared.Serialisation;
using Shouldly;
Expand Down Expand Up @@ -32,40 +32,40 @@ public void ContractDomainEventHandler_ContractCreatedEvent_EventIsHandled()
{
ContractDomainEvents.ContractCreatedEvent contractCreatedEvent = TestData.DomainEvents.ContractCreatedEvent;

Should.NotThrow(async () => { await this.DomainEventHandler.Handle(contractCreatedEvent, CancellationToken.None); });
Should.NotThrow(async () => { await this.DomainEventHandler.Handle(contractCreatedEvent, TestContext.Current.CancellationToken); });
}

[Fact]
public void ContractDomainEventHandler_FixedValueProductAddedToContractEvent_EventIsHandled()
{
ContractDomainEvents.FixedValueProductAddedToContractEvent fixedValueProductAddedToContractEvent = TestData.DomainEvents.FixedValueProductAddedToContractEvent;

Should.NotThrow(async () => { await this.DomainEventHandler.Handle(fixedValueProductAddedToContractEvent, CancellationToken.None); });
Should.NotThrow(async () => { await this.DomainEventHandler.Handle(fixedValueProductAddedToContractEvent, TestContext.Current.CancellationToken); });
}

[Fact]
public void ContractDomainEventHandler_TransactionFeeForProductAddedToContractEvent_EventIsHandled()
{
ContractDomainEvents.TransactionFeeForProductAddedToContractEvent transactionFeeForProductAddedToContractEvent = TestData.DomainEvents.TransactionFeeForProductAddedToContractEvent;

Should.NotThrow(async () => { await this.DomainEventHandler.Handle(transactionFeeForProductAddedToContractEvent, CancellationToken.None); });
Should.NotThrow(async () => { await this.DomainEventHandler.Handle(transactionFeeForProductAddedToContractEvent, TestContext.Current.CancellationToken); });
}

[Fact]
public void ContractDomainEventHandler_TransactionFeeForProductDisabledEvent_EventIsHandled()
{
ContractDomainEvents.TransactionFeeForProductDisabledEvent transactionFeeForProductDisabledEvent = TestData.DomainEvents.TransactionFeeForProductDisabledEvent;

Should.NotThrow(async () => { await this.DomainEventHandler.Handle(transactionFeeForProductDisabledEvent, CancellationToken.None); });
Should.NotThrow(async () => { await this.DomainEventHandler.Handle(transactionFeeForProductDisabledEvent, TestContext.Current.CancellationToken); });
}

[Fact]
public void ContractDomainEventHandler_VariableValueProductAddedToContractEvent_EventIsHandled()
{
ContractDomainEvents.VariableValueProductAddedToContractEvent variableValueProductAddedToContractEvent = TestData.DomainEvents.VariableValueProductAddedToContractEvent;

Should.NotThrow(async () => { await this.DomainEventHandler.Handle(variableValueProductAddedToContractEvent, CancellationToken.None); });
Should.NotThrow(async () => { await this.DomainEventHandler.Handle(variableValueProductAddedToContractEvent, TestContext.Current.CancellationToken); });
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Moq;
using Moq;
using Shared.Logger;
using Shared.Serialisation;
using Shouldly;
Expand Down Expand Up @@ -38,7 +38,7 @@ public void EstateDomainEventHandler_EstateCreatedEvent_EventIsHandled()
.Setup(r => r.CreateReadModel(It.IsAny<EstateDomainEvents.EstateCreatedEvent>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Success);

Should.NotThrow(async () => { await this.DomainEventHandler.Handle(estateCreatedEvent, CancellationToken.None); });
Should.NotThrow(async () => { await this.DomainEventHandler.Handle(estateCreatedEvent, TestContext.Current.CancellationToken); });
}

[Fact]
Expand All @@ -49,7 +49,7 @@ public async Task EstateDomainEventHandler_EstateCreatedEvent_CreateReadModelFai
.Setup(r => r.CreateReadModel(It.IsAny<EstateDomainEvents.EstateCreatedEvent>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Failure);

Result result = await this.DomainEventHandler.Handle(estateCreatedEvent, CancellationToken.None);
Result result = await this.DomainEventHandler.Handle(estateCreatedEvent, TestContext.Current.CancellationToken);
result.IsFailed.ShouldBeTrue();
}

Expand All @@ -58,16 +58,16 @@ public void EstateDomainEventHandler_EstateReferenceAllocatedEvent_EventIsHandle
{
EstateDomainEvents.EstateReferenceAllocatedEvent estateReferenceAllocatedEvent = TestData.DomainEvents.EstateReferenceAllocatedEvent;

Should.NotThrow(async () => { await this.DomainEventHandler.Handle(estateReferenceAllocatedEvent, CancellationToken.None); });
Should.NotThrow(async () => { await this.DomainEventHandler.Handle(estateReferenceAllocatedEvent, TestContext.Current.CancellationToken); });
}

[Fact]
public void EstateDomainEventHandler_SecurityUserAddedEvent_EventIsHandled()
{
EstateDomainEvents.SecurityUserAddedToEstateEvent securityUserAddedEvent = TestData.DomainEvents.EstateSecurityUserAddedEvent;

Should.NotThrow(async () => { await this.DomainEventHandler.Handle(securityUserAddedEvent, CancellationToken.None); });
Should.NotThrow(async () => { await this.DomainEventHandler.Handle(securityUserAddedEvent, TestContext.Current.CancellationToken); });
}

#endregion
}
}
Loading
Loading