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
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

# CA1806: Do not ignore method results
dotnet_diagnostic.CA1806.severity = warning
86 changes: 32 additions & 54 deletions TransactionProcessor.Aggregates.Tests/EstateAggregateTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Shouldly;
using SimpleResults;
using TransactionProcessor.Models.Estate;
using TransactionProcessor.Testing;

Expand All @@ -19,7 +20,6 @@ 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);
Expand All @@ -33,45 +33,29 @@ public void EstateAggregate_Create_IsCreated()
public void EstateAggregate_Create_InvalidEstateName_ErrorThrown(String estateName)
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);
ArgumentNullException exception = Should.Throw<ArgumentNullException>(() =>
{
aggregate.Create(estateName);
});
Result result = 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);
result.IsFailed.ShouldBeTrue();
result.Status.ShouldBe(ResultStatus.Invalid);

Should.NotThrow(() =>
{
aggregate.Create(TestData.EstateName);
});
result.Message.ShouldContain("Estate name must be provided when registering a new estate");
}

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

Should.NotThrow(() =>
{
aggregate.GenerateReference();
});
var result = aggregate.Create(TestData.EstateName);
result.IsSuccess.ShouldBeTrue();
}

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

model.EstateId.ShouldBe(TestData.EstateId);
Expand All @@ -85,7 +69,6 @@ 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.Estate model = aggregate.GetEstate();
Expand All @@ -104,7 +87,6 @@ public void EstateAggregate_GetEstate_NoSecurityUsers_EstateIsReturned()
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);
aggregate.Create(TestData.EstateName);
aggregate.GenerateReference();
TransactionProcessor.Models.Estate.Estate model = aggregate.GetEstate();

model.EstateId.ShouldBe(TestData.EstateId);
Expand All @@ -119,7 +101,6 @@ 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.Estate model = aggregate.GetEstate();
Expand Down Expand Up @@ -153,12 +134,12 @@ public void EstateAggregate_AddOperatorToEstate_EstateNotCreated_ErrorThrown()
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);

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

result.IsFailed.ShouldBeTrue();
result.Status.ShouldBe(ResultStatus.Invalid);

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

[Fact]
Expand All @@ -168,12 +149,11 @@ public void EstateAggregate_AddOperatorToEstate_OperatorWithIdAlreadyAdded_Error
aggregate.Create(TestData.EstateName);
aggregate.AddOperator(TestData.OperatorId);

InvalidOperationException exception = Should.Throw<InvalidOperationException>(() =>
{
aggregate.AddOperator(TestData.OperatorId);
});
var result = aggregate.AddOperator(TestData.OperatorId);
result.IsFailed.ShouldBeTrue();
result.Status.ShouldBe(ResultStatus.Invalid);

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

[Fact]
Expand All @@ -193,12 +173,12 @@ public void EstateAggregate_AddSecurityUserToEstate_EstateNotCreated_ErrorThrown
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);

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

exception.Message.ShouldContain("Estate has not been created");
result.IsFailed.ShouldBeTrue();
result.Status.ShouldBe(ResultStatus.Invalid);

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

[Fact]
Expand All @@ -220,26 +200,24 @@ public void EstateAggregate_RemoveOperatorFromEstate_EstateNotCreated_ErrorThrow
{
EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId);

InvalidOperationException exception = Should.Throw<InvalidOperationException>(() =>
{
aggregate.RemoveOperator(TestData.OperatorId);
});
Result result = aggregate.RemoveOperator(TestData.OperatorId);
result.IsFailed.ShouldBeTrue();
result.Status.ShouldBe(ResultStatus.Invalid);

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

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

var result = aggregate.RemoveOperator(TestData.OperatorId);
result.IsFailed.ShouldBeTrue();
result.Status.ShouldBe(ResultStatus.Invalid);

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

exception.Message.ShouldContain($"Operator not added to this Estate with Id [{TestData.OperatorId}]");
result.Message.ShouldContain($"Operator not added to this Estate with Id [{TestData.OperatorId}]");
}
}
}
Loading
Loading