Skip to content
Merged
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 @@ -11,7 +11,9 @@
using Shouldly;
using SimpleResults;
using TransactionProcessor.Aggregates;
using TransactionProcessor.BusinessLogic.Requests;
using TransactionProcessor.BusinessLogic.Services;
using TransactionProcessor.DataTransferObjects.Requests.Estate;
using TransactionProcessor.Testing;
using Xunit;

Expand Down Expand Up @@ -150,8 +152,240 @@ public async Task EstateDomainService_CreateEstateUser_NullUserReturned_ResultIs
result.IsFailed.ShouldBeTrue();
}

// TODO: EstateDomainServiceTests - CreateEstateUser - failed creating user test
// TODO: EstateDomainServiceTests - Estate Not Created tests missing
// TODO: EstateDomainServiceTests - Save Changes failed
[Fact]
public async Task EstateDomainService_CreateEstateUser_GetEstateFailed_ResultIsFailed()
{
this.AggregateService.Setup(m => m.GetLatest<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Failure());

this.SecurityServiceClient
.Setup(s => s.CreateUser(It.IsAny<CreateUserRequest>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Success);
this.SecurityServiceClient
.Setup(s => s.GetUsers(It.IsAny<String>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Success(new List<UserDetails>() {
new UserDetails {
UserId = Guid.Parse("FA077CE3-B915-4048-88E3-9B500699317F")
}
}));

Result result = await this.DomainService.CreateEstateUser(TestData.Commands.CreateEstateUserCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}

[Fact]
public async Task EstateDomainService_CreateEstateUser_EstateNotCreated_ResultIsFailed()
{
this.AggregateService.Setup(m => m.GetLatest<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Success(TestData.Aggregates.EmptyEstateAggregate));
this.AggregateService.Setup(m => m.Save(It.IsAny<EstateAggregate>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(SimpleResults.Result.Success());

this.SecurityServiceClient
.Setup(s => s.CreateUser(It.IsAny<CreateUserRequest>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Success);
this.SecurityServiceClient
.Setup(s => s.GetUsers(It.IsAny<String>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Success(new List<UserDetails>() {
new UserDetails {
UserId = Guid.Parse("FA077CE3-B915-4048-88E3-9B500699317F")
}
}));

Result result = await this.DomainService.CreateEstateUser(TestData.Commands.CreateEstateUserCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}

[Fact]
public async Task EstateDomainService_CreateEstateUser_SaveFailed_ResultIsFailed()
{
this.AggregateService.Setup(m => m.GetLatest<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Success(TestData.Aggregates.CreatedEstateAggregate()));
this.AggregateService.Setup(m => m.Save(It.IsAny<EstateAggregate>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Failure);

this.SecurityServiceClient
.Setup(s => s.CreateUser(It.IsAny<CreateUserRequest>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Success);
this.SecurityServiceClient
.Setup(s => s.GetUsers(It.IsAny<String>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Success(new List<UserDetails>() {
new UserDetails {
UserId = Guid.Parse("FA077CE3-B915-4048-88E3-9B500699317F")
}
}));

Result result = await this.DomainService.CreateEstateUser(TestData.Commands.CreateEstateUserCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}

[Fact]
public async Task EstateDomainService_CreateEstate_GetEstateFailed_ResultIsFailed()
{
this.AggregateService.Setup(m => m.GetLatest<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Failure());

Result result = await this.DomainService.CreateEstate(TestData.Commands.CreateEstateCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}

[Fact]
public async Task EstateDomainService_CreateEstate_EstateNameEmpty_ResultIsFailed()
{
this.AggregateService.Setup(m => m.GetLatest<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(SimpleResults.Result.Success(new EstateAggregate()));

EstateCommands.CreateEstateCommand emptyNameCommand = new EstateCommands.CreateEstateCommand(
new CreateEstateRequest { EstateId = TestData.EstateId, EstateName = String.Empty });

Result result = await this.DomainService.CreateEstate(emptyNameCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}

[Fact]
public async Task EstateDomainService_CreateEstate_SaveFailed_ResultIsFailed()
{
this.AggregateService.Setup(m => m.GetLatest<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(SimpleResults.Result.Success(new EstateAggregate()));
this.AggregateService
.Setup(m => m.Save(It.IsAny<EstateAggregate>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Failure);

Result result = await this.DomainService.CreateEstate(TestData.Commands.CreateEstateCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}

[Fact]
public async Task EstateDomainService_AddOperatorToEstate_GetOperatorFailed_ResultIsFailed()
{
this.AggregateService.Setup(m => m.Get<OperatorAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Failure());
this.AggregateService.Setup(m => m.GetLatest<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(SimpleResults.Result.Success(TestData.Aggregates.CreatedEstateAggregate()));

Result result = await this.DomainService.AddOperatorToEstate(TestData.Commands.AddOperatorToEstateCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}

[Fact]
public async Task EstateDomainService_AddOperatorToEstate_GetEstateFailed_ResultIsFailed()
{
this.AggregateService.Setup(m => m.Get<OperatorAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(SimpleResults.Result.Success(TestData.Aggregates.CreatedOperatorAggregate()));
this.AggregateService.Setup(m => m.GetLatest<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Failure());

Result result = await this.DomainService.AddOperatorToEstate(TestData.Commands.AddOperatorToEstateCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}

[Fact]
public async Task EstateDomainService_AddOperatorToEstate_EstateNotCreated_ResultIsFailed()
{
this.AggregateService.Setup(m => m.Get<OperatorAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(SimpleResults.Result.Success(TestData.Aggregates.CreatedOperatorAggregate()));
this.AggregateService.Setup(m => m.GetLatest<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(SimpleResults.Result.Success(TestData.Aggregates.EmptyEstateAggregate));

Result result = await this.DomainService.AddOperatorToEstate(TestData.Commands.AddOperatorToEstateCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}

[Fact]
public async Task EstateDomainService_AddOperatorToEstate_SaveFailed_ResultIsFailed()
{
this.AggregateService.Setup(m => m.Get<OperatorAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(SimpleResults.Result.Success(TestData.Aggregates.CreatedOperatorAggregate()));
this.AggregateService.Setup(m => m.GetLatest<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(SimpleResults.Result.Success(TestData.Aggregates.CreatedEstateAggregate()));
this.AggregateService.Setup(m => m.Save(It.IsAny<EstateAggregate>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Failure);

Result result = await this.DomainService.AddOperatorToEstate(TestData.Commands.AddOperatorToEstateCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}

[Fact]
public async Task EstateDomainService_RemoveOperatorFromEstate_GetEstateFailed_ResultIsFailed()
{
this.AggregateService.Setup(m => m.GetLatest<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Failure());

Result result = await this.DomainService.RemoveOperatorFromEstate(TestData.Commands.RemoveOperatorFromEstateCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}

[Fact]
public async Task EstateDomainService_RemoveOperatorFromEstate_EstateNotCreated_ResultIsFailed()
{
this.AggregateService.Setup(m => m.GetLatest<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Success(TestData.Aggregates.EmptyEstateAggregate));

Result result = await this.DomainService.RemoveOperatorFromEstate(TestData.Commands.RemoveOperatorFromEstateCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}

[Fact]
public async Task EstateDomainService_RemoveOperatorFromEstate_OperatorNotAdded_ResultIsFailed()
{
this.AggregateService.Setup(m => m.GetLatest<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Success(TestData.Aggregates.CreatedEstateAggregate()));

Result result = await this.DomainService.RemoveOperatorFromEstate(TestData.Commands.RemoveOperatorFromEstateCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}

[Fact]
public async Task EstateDomainService_RemoveOperatorFromEstate_SaveFailed_ResultIsFailed()
{
this.AggregateService.Setup(m => m.GetLatest<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Success(TestData.Aggregates.EstateAggregateWithOperator()));
this.AggregateService.Setup(m => m.Save(It.IsAny<EstateAggregate>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Failure);

Result result = await this.DomainService.RemoveOperatorFromEstate(TestData.Commands.RemoveOperatorFromEstateCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}

[Fact]
public async Task EstateDomainService_CreateEstate_ExceptionThrown_ResultIsFailed()
{
this.AggregateService.Setup(m => m.GetLatest<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ThrowsAsync(new Exception());

Result result = await this.DomainService.CreateEstate(TestData.Commands.CreateEstateCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}

[Fact]
public async Task EstateDomainService_AddOperatorToEstate_ExceptionThrown_ResultIsFailed()
{
this.AggregateService.Setup(m => m.Get<OperatorAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ThrowsAsync(new Exception());

Result result = await this.DomainService.AddOperatorToEstate(TestData.Commands.AddOperatorToEstateCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}

[Fact]
public async Task EstateDomainService_CreateEstateUser_ExceptionThrown_ResultIsFailed()
{
this.SecurityServiceClient
.Setup(s => s.CreateUser(It.IsAny<CreateUserRequest>(), It.IsAny<CancellationToken>()))
.ThrowsAsync(new Exception());

Result result = await this.DomainService.CreateEstateUser(TestData.Commands.CreateEstateUserCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}

[Fact]
public async Task EstateDomainService_RemoveOperatorFromEstate_ExceptionThrown_ResultIsFailed()
{
this.AggregateService.Setup(m => m.GetLatest<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ThrowsAsync(new Exception());

Result result = await this.DomainService.RemoveOperatorFromEstate(TestData.Commands.RemoveOperatorFromEstateCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}
}
}
Loading