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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 2 additions & 5 deletions .github/workflows/createrelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ jobs:
echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}"
dotnet test "TransactionProcessor.BusinessLogic.Tests\TransactionProcessor.BusinessLogic.Tests.csproj"
dotnet test "TransactionProcessor.ProjectionEngine.Tests\TransactionProcessor.ProjectionEngine.Tests.csproj"
dotnet test "TransactionProcessor.ReconciliationAggregate.Tests\TransactionProcessor.ReconciliationAggregate.Tests.csproj"
dotnet test "TransactionProcessor.SettlementAggregates.Tests\TransactionProcessor.SettlementAggregates.Tests.csproj"
dotnet test "TransactionProcessor.Tests\TransactionProcessor.Tests.csproj"
dotnet test "TransactionProcessor.TransactionAggregate.Tests\TransactionProcessor.TransactionAggregate.Tests.csproj"
dotnet test "TransactionProcessor.VoucherAggregate.Tests\TransactionProcessor.VoucherAggregate.Tests.csproj"
dotnet test "TransactionProcessor.Aggregates.Tests\TransactionProcessor.Aggregates.Tests.csproj"
dotnet test "TransactionProcessor.Tests\TransactionProcessor.Tests.csproj"

- name: Publish Images to Docker Hub - Pre Release
if: ${{ github.event.release.prerelease == true }}
Expand Down
11 changes: 4 additions & 7 deletions .github/workflows/nightlybuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,14 @@ jobs:
echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}"
dotnet test "TransactionProcessor.BusinessLogic.Tests\TransactionProcessor.BusinessLogic.Tests.csproj" /p:CollectCoverage=true /p:Exclude="[xunit*]*" /p:ExcludeByAttribute="Obsolete" /p:ExcludeByAttribute="GeneratedCodeAttribute" /p:ExcludeByAttribute="CompilerGeneratedAttribute" /p:ExcludeByAttribute="ExcludeFromCodeCoverageAttribute" /p:CoverletOutput="../lcov1.info" /maxcpucount:1 /p:CoverletOutputFormat="lcov"
dotnet test "TransactionProcessor.ProjectionEngine.Tests\TransactionProcessor.ProjectionEngine.Tests.csproj" /p:CollectCoverage=true /p:Exclude="[xunit*]*" /p:ExcludeByAttribute="Obsolete" /p:ExcludeByAttribute="GeneratedCodeAttribute" /p:ExcludeByAttribute="CompilerGeneratedAttribute" /p:ExcludeByAttribute="ExcludeFromCodeCoverageAttribute" /p:CoverletOutput="../lcov2.info" /maxcpucount:1 /p:CoverletOutputFormat="lcov"
dotnet test "TransactionProcessor.ReconciliationAggregate.Tests\TransactionProcessor.ReconciliationAggregate.Tests.csproj" /p:CollectCoverage=true /p:Exclude="[xunit*]*" /p:ExcludeByAttribute="Obsolete" /p:ExcludeByAttribute="GeneratedCodeAttribute" /p:ExcludeByAttribute="CompilerGeneratedAttribute" /p:ExcludeByAttribute="ExcludeFromCodeCoverageAttribute" /p:CoverletOutput="../lcov3.info" /maxcpucount:1 /p:CoverletOutputFormat="lcov"
dotnet test "TransactionProcessor.SettlementAggregates.Tests\TransactionProcessor.SettlementAggregates.Tests.csproj" /p:CollectCoverage=true /p:Exclude="[xunit*]*" /p:ExcludeByAttribute="Obsolete" /p:ExcludeByAttribute="GeneratedCodeAttribute" /p:ExcludeByAttribute="CompilerGeneratedAttribute" /p:ExcludeByAttribute="ExcludeFromCodeCoverageAttribute" /p:CoverletOutput="../lcov4.info" /maxcpucount:1 /p:CoverletOutputFormat="lcov"
dotnet test "TransactionProcessor.Tests\TransactionProcessor.Tests.csproj" /p:CollectCoverage=true /p:Exclude="[xunit*]*" /p:ExcludeByAttribute="Obsolete" /p:ExcludeByAttribute="GeneratedCodeAttribute" /p:ExcludeByAttribute="CompilerGeneratedAttribute" /p:ExcludeByAttribute="ExcludeFromCodeCoverageAttribute" /p:CoverletOutput="../lcov5.info" /maxcpucount:1 /p:CoverletOutputFormat="lcov"
dotnet test "TransactionProcessor.TransactionAggregate.Tests\TransactionProcessor.TransactionAggregate.Tests.csproj" /p:CollectCoverage=true /p:Exclude="[xunit*]*" /p:ExcludeByAttribute="Obsolete" /p:ExcludeByAttribute="GeneratedCodeAttribute" /p:ExcludeByAttribute="CompilerGeneratedAttribute" /p:ExcludeByAttribute="ExcludeFromCodeCoverageAttribute" /p:CoverletOutput="../lcov6.info" /maxcpucount:1 /p:CoverletOutputFormat="lcov"
dotnet test "TransactionProcessor.VoucherAggregate.Tests\TransactionProcessor.VoucherAggregate.Tests.csproj" /p:CollectCoverage=true /p:Exclude="[xunit*]*" /p:ExcludeByAttribute="Obsolete" /p:ExcludeByAttribute="GeneratedCodeAttribute" /p:ExcludeByAttribute="CompilerGeneratedAttribute" /p:ExcludeByAttribute="ExcludeFromCodeCoverageAttribute" /p:CoverletOutput="../lcov7.info" /maxcpucount:1 /p:CoverletOutputFormat="lcov"

dotnet test "TransactionProcessor.Aggregates.Tests\TransactionProcessor.Aggregates.Tests.csproj" /p:CollectCoverage=true /p:Exclude="[xunit*]*" /p:ExcludeByAttribute="Obsolete" /p:ExcludeByAttribute="GeneratedCodeAttribute" /p:ExcludeByAttribute="CompilerGeneratedAttribute" /p:ExcludeByAttribute="ExcludeFromCodeCoverageAttribute" /p:CoverletOutput="../lcov3.info" /maxcpucount:1 /p:CoverletOutputFormat="lcov"
dotnet test "TransactionProcessor.Tests\TransactionProcessor.Tests.csproj" /p:CollectCoverage=true /p:Exclude="[xunit*]*" /p:ExcludeByAttribute="Obsolete" /p:ExcludeByAttribute="GeneratedCodeAttribute" /p:ExcludeByAttribute="CompilerGeneratedAttribute" /p:ExcludeByAttribute="ExcludeFromCodeCoverageAttribute" /p:CoverletOutput="../lcov4.info" /maxcpucount:1 /p:CoverletOutputFormat="lcov"

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./lcov1.info,./lcov2.info,./lcov3.info,./lcov4.info,./lcov5.info,./lcov6.info,./lcov7.info
files: ./lcov1.info,./lcov2.info,./lcov3.info,./lcov4.info

- name: Build Docker Image
run: docker build . --file TransactionProcessor/Dockerfile --tag transactionprocessor:latest
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ jobs:
echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}"
dotnet test "TransactionProcessor.BusinessLogic.Tests\TransactionProcessor.BusinessLogic.Tests.csproj"
dotnet test "TransactionProcessor.ProjectionEngine.Tests\TransactionProcessor.ProjectionEngine.Tests.csproj"
dotnet test "TransactionProcessor.ReconciliationAggregate.Tests\TransactionProcessor.ReconciliationAggregate.Tests.csproj"
dotnet test "TransactionProcessor.SettlementAggregates.Tests\TransactionProcessor.SettlementAggregates.Tests.csproj"
dotnet test "TransactionProcessor.Aggregates.Tests\TransactionProcessor.Aggregates.Tests.csproj"
dotnet test "TransactionProcessor.Tests\TransactionProcessor.Tests.csproj"
dotnet test "TransactionProcessor.TransactionAggregate.Tests\TransactionProcessor.TransactionAggregate.Tests.csproj"
dotnet test "TransactionProcessor.VoucherAggregate.Tests\TransactionProcessor.VoucherAggregate.Tests.csproj"

- name: Build Docker Image
run: docker build . --file TransactionProcessor/Dockerfile --tag transactionprocessor:latest
Expand Down
245 changes: 245 additions & 0 deletions TransactionProcessor.Aggregates.Tests/EstateAggregateTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
using Shouldly;
using TransactionProcessor.Models;
using TransactionProcessor.Testing;

namespace TransactionProcessor.Aggregates.Tests
{
public class EstateAggregateTests
{
[Fact]
public void EstateAggregate_CanBeCreated_IsCreated()
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);

aggregate.AggregateId.ShouldBe(TestData.EstateId);
}

[Fact]
public void EstateAggregate_Create_IsCreated()
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);
aggregate.Create(TestData.EstateName);
aggregate.GenerateReference();

aggregate.AggregateId.ShouldBe(TestData.EstateId);
aggregate.EstateName.ShouldBe(TestData.EstateName);
aggregate.IsCreated.ShouldBeTrue();
aggregate.EstateReference.ShouldBe(TestData.EstateReference);
}

[Theory]
[InlineData("")]
[InlineData(null)]
public void EstateAggregate_Create_InvalidEstateName_ErrorThrown(String estateName)
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);
ArgumentNullException exception = Should.Throw<ArgumentNullException>(() =>
{
aggregate.Create(estateName);
});

exception.Message.ShouldContain("Estate name must be provided when registering a new estate");
}

[Fact]
public void EstateAggregate_Create_EstateAlreadyCreated_NoErrorThrown()
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);
aggregate.Create(TestData.EstateName);

Should.NotThrow(() =>
{
aggregate.Create(TestData.EstateName);
});
}

[Fact]
public void EstateAggregate_GenerateReference_CalledTwice_NoErrorThrown()
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);
aggregate.Create(TestData.EstateName);
aggregate.GenerateReference();

Should.NotThrow(() =>
{
aggregate.GenerateReference();
});
}

[Fact]
public void EstateAggregate_GetEstate_NoOperators_EstateIsReturned()
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);
aggregate.Create(TestData.EstateName);
aggregate.GenerateReference();
TransactionProcessor.Models.Estate model = aggregate.GetEstate();

model.EstateId.ShouldBe(TestData.EstateId);
model.Name.ShouldBe(TestData.EstateName);
model.Reference.ShouldBe(TestData.EstateReference);
model.Operators.ShouldBeEmpty();
}

[Fact]
public void EstateAggregate_GetEstate_WithAnOperator_EstateIsReturned()
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);
aggregate.Create(TestData.EstateName);
aggregate.GenerateReference();
aggregate.AddOperator(TestData.OperatorId);

TransactionProcessor.Models.Estate model = aggregate.GetEstate();

model.EstateId.ShouldBe(TestData.EstateId);
model.Name.ShouldBe(TestData.EstateName);
model.Reference.ShouldBe(TestData.EstateReference);
model.Operators.ShouldHaveSingleItem();

EstateOperator? @operator =model.Operators.Single();
@operator.OperatorId.ShouldBe(TestData.OperatorId);
}

[Fact]
public void EstateAggregate_GetEstate_NoSecurityUsers_EstateIsReturned()
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);
aggregate.Create(TestData.EstateName);
aggregate.GenerateReference();
TransactionProcessor.Models.Estate model = aggregate.GetEstate();

model.EstateId.ShouldBe(TestData.EstateId);
model.Name.ShouldBe(TestData.EstateName);
model.Reference.ShouldBe(TestData.EstateReference);
model.Operators.ShouldBeEmpty();
model.SecurityUsers.ShouldBeEmpty();
}

[Fact]
public void EstateAggregate_GetEstate_WithASecurityUser_EstateIsReturned()
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);
aggregate.Create(TestData.EstateName);
aggregate.GenerateReference();
aggregate.AddSecurityUser(TestData.SecurityUserId,TestData.EstateUserEmailAddress);

TransactionProcessor.Models.Estate model = aggregate.GetEstate();

model.EstateId.ShouldBe(TestData.EstateId);
model.Name.ShouldBe(TestData.EstateName);
model.Reference.ShouldBe(TestData.EstateReference);
model.SecurityUsers.ShouldHaveSingleItem();

SecurityUser securityUser = model.SecurityUsers.Single();
securityUser.SecurityUserId.ShouldBe(TestData.SecurityUserId);
securityUser.EmailAddress.ShouldBe(TestData.EstateUserEmailAddress);
}

[Fact]
public void EstateAggregate_AddOperatorToEstate_OperatorIsAdded()
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);
aggregate.Create(TestData.EstateName);

aggregate.AddOperator(TestData.OperatorId);

TransactionProcessor.Models.Estate estate = aggregate.GetEstate();
estate.Operators.ShouldHaveSingleItem();
estate.Operators.Single().OperatorId.ShouldBe(TestData.OperatorId);
estate.Operators.Single().IsDeleted.ShouldBeFalse();
}

[Fact]
public void EstateAggregate_AddOperatorToEstate_EstateNotCreated_ErrorThrown()
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);

InvalidOperationException exception = Should.Throw<InvalidOperationException>(() =>
{
aggregate.AddOperator(TestData.OperatorId);
});

exception.Message.ShouldContain("Estate has not been created");
}

[Fact]
public void EstateAggregate_AddOperatorToEstate_OperatorWithIdAlreadyAdded_ErrorThrown()
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);
aggregate.Create(TestData.EstateName);
aggregate.AddOperator(TestData.OperatorId);

InvalidOperationException exception = Should.Throw<InvalidOperationException>(() =>
{
aggregate.AddOperator(TestData.OperatorId);
});

exception.Message.ShouldContain($"Duplicate operator details are not allowed, an operator already exists on this estate with Id [{TestData.OperatorId}]");
}

[Fact]
public void EstateAggregate_AddSecurityUserToEstate_SecurityUserIsAdded()
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);
aggregate.Create(TestData.EstateName);
aggregate.AddSecurityUser(TestData.SecurityUserId, TestData.EstateUserEmailAddress);

TransactionProcessor.Models.Estate estate = aggregate.GetEstate();
estate.SecurityUsers.ShouldHaveSingleItem();
estate.SecurityUsers.Single().EmailAddress.ShouldBe(TestData.EstateUserEmailAddress);
}

[Fact]
public void EstateAggregate_AddSecurityUserToEstate_EstateNotCreated_ErrorThrown()
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);

InvalidOperationException exception = Should.Throw<InvalidOperationException>(() =>
{
aggregate.AddSecurityUser(TestData.SecurityUserId, TestData.EstateUserEmailAddress);
});

exception.Message.ShouldContain("Estate has not been created");
}

[Fact]
public void EstateAggregate_RemoveOperatorFromEstate_OperatorIsAdded()
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);
aggregate.Create(TestData.EstateName);
aggregate.AddOperator(TestData.OperatorId);

aggregate.RemoveOperator(TestData.OperatorId);

TransactionProcessor.Models.Estate estate = aggregate.GetEstate();
estate.Operators.ShouldHaveSingleItem();
estate.Operators.Single().IsDeleted.ShouldBeTrue();
}

[Fact]
public void EstateAggregate_RemoveOperatorFromEstate_EstateNotCreated_ErrorThrown()
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);

InvalidOperationException exception = Should.Throw<InvalidOperationException>(() =>
{
aggregate.RemoveOperator(TestData.OperatorId);
});

exception.Message.ShouldContain("Estate has not been created");
}

[Fact]
public void EstateAggregate_RemoveOperatorFromEstate_OperatorWithIdNotAlreadyAdded_ErrorThrown()
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);
aggregate.Create(TestData.EstateName);

InvalidOperationException exception = Should.Throw<InvalidOperationException>(() =>
{
aggregate.RemoveOperator(TestData.OperatorId);
});

exception.Message.ShouldContain($"Operator not added to this Estate with Id [{TestData.OperatorId}]");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Shouldly;
using TransactionProcessor.Testing;
using Xunit;

namespace TransactionProcessor.FloatAggregate.Tests;
namespace TransactionProcessor.Aggregates.Tests;

public class FloatActivityAggregateTests {
[Fact]
Expand Down
Loading
Loading