Skip to content

Commit 50431c6

Browse files
Merge pull request #1515 from TransactionProcessing/copilot/update-test-coverage-float-service
Update test coverage for Float Domain service
2 parents 108b0a9 + 7941d3f commit 50431c6

1 file changed

Lines changed: 124 additions & 0 deletions

File tree

TransactionProcessor.BusinessLogic.Tests/Services/FloatDomainServiceTests.cs

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,129 @@ public async Task FloatDomainService_RecordCreditPurchase_FloatActivity_Exceptio
166166
Result result = await this.FloatDomainService.RecordCreditPurchase(command, CancellationToken.None);
167167
result.IsFailed.ShouldBeTrue();
168168
}
169+
170+
[Fact]
171+
public async Task FloatDomainService_CreateFloatForContractProduct_GetFloatFailed()
172+
{
173+
this.AggregateService.Setup(f => f.Get<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.Aggregates.EstateAggregateWithOperator()));
174+
this.AggregateService.Setup(f => f.Get<ContractAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.Aggregates.CreatedContractAggregateWithAProductAndTransactionFee(Models.Contract.CalculationType.Fixed, Models.Contract.FeeType.Merchant)));
175+
this.AggregateService.Setup(f => f.GetLatest<FloatAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Failure());
176+
177+
FloatCommands.CreateFloatForContractProductCommand command = new FloatCommands.CreateFloatForContractProductCommand(TestData.EstateId, TestData.ContractId,
178+
TestData.ProductId, TestData.FloatCreatedDateTime);
179+
Result result = await this.FloatDomainService.CreateFloatForContractProduct(command, CancellationToken.None);
180+
result.IsFailed.ShouldBeTrue();
181+
}
182+
183+
[Fact]
184+
public async Task FloatDomainService_CreateFloatForContractProduct_SaveFailed()
185+
{
186+
this.AggregateService.Setup(f => f.Get<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.Aggregates.EstateAggregateWithOperator()));
187+
this.AggregateService.Setup(f => f.Get<ContractAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.Aggregates.CreatedContractAggregateWithAProductAndTransactionFee(Models.Contract.CalculationType.Fixed, Models.Contract.FeeType.Merchant)));
188+
this.AggregateService.Setup(f => f.GetLatest<FloatAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.GetEmptyFloatAggregate()));
189+
this.AggregateService.Setup(f => f.Save<FloatAggregate>(It.IsAny<FloatAggregate>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Failure());
190+
191+
FloatCommands.CreateFloatForContractProductCommand command = new FloatCommands.CreateFloatForContractProductCommand(TestData.EstateId, TestData.ContractId,
192+
TestData.ProductId, TestData.FloatCreatedDateTime);
193+
Result result = await this.FloatDomainService.CreateFloatForContractProduct(command, CancellationToken.None);
194+
result.IsFailed.ShouldBeTrue();
195+
}
196+
197+
[Fact]
198+
public async Task FloatDomainService_CreateFloatForContractProduct_ExceptionThrown()
199+
{
200+
this.AggregateService.Setup(f => f.Get<EstateAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.Aggregates.EstateAggregateWithOperator()));
201+
this.AggregateService.Setup(f => f.Get<ContractAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.Aggregates.CreatedContractAggregateWithAProductAndTransactionFee(Models.Contract.CalculationType.Fixed, Models.Contract.FeeType.Merchant)));
202+
this.AggregateService.Setup(f => f.GetLatest<FloatAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.GetEmptyFloatAggregate()));
203+
this.AggregateService.Setup(f => f.Save<FloatAggregate>(It.IsAny<FloatAggregate>(), It.IsAny<CancellationToken>())).ThrowsAsync(new Exception());
204+
205+
FloatCommands.CreateFloatForContractProductCommand command = new FloatCommands.CreateFloatForContractProductCommand(TestData.EstateId, TestData.ContractId,
206+
TestData.ProductId, TestData.FloatCreatedDateTime);
207+
Result result = await this.FloatDomainService.CreateFloatForContractProduct(command, CancellationToken.None);
208+
result.IsFailed.ShouldBeTrue();
209+
}
210+
211+
[Fact]
212+
public async Task FloatDomainService_RecordCreditPurchase_GetFloatFailed()
213+
{
214+
this.AggregateService.Setup(f => f.GetLatest<FloatAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Failure());
215+
216+
FloatCommands.RecordCreditPurchaseForFloatCommand command = new FloatCommands.RecordCreditPurchaseForFloatCommand(TestData.EstateId,
217+
TestData.FloatAggregateId, TestData.FloatCreditAmount, TestData.FloatCreditCostPrice,
218+
TestData.CreditPurchasedDateTime);
219+
Result result = await this.FloatDomainService.RecordCreditPurchase(command, CancellationToken.None);
220+
result.IsFailed.ShouldBeTrue();
221+
}
222+
223+
[Fact]
224+
public async Task FloatDomainService_RecordCreditPurchase_FloatActivity_GetFloatActivityFailed()
225+
{
226+
this.AggregateService.Setup(f => f.GetLatest<FloatActivityAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Failure());
227+
228+
FloatActivityCommands.RecordCreditPurchaseCommand command = new FloatActivityCommands.RecordCreditPurchaseCommand(TestData.EstateId,
229+
TestData.FloatAggregateId, TestData.CreditPurchasedDateTime, TestData.FloatCreditAmount, TestData.FloatCreditId);
230+
Result result = await this.FloatDomainService.RecordCreditPurchase(command, CancellationToken.None);
231+
result.IsFailed.ShouldBeTrue();
232+
}
233+
234+
[Fact]
235+
public async Task FloatDomainService_RecordTransaction_TransactionRecorded()
236+
{
237+
FloatActivityAggregate floatActivityAggregate = FloatActivityAggregate.Create(TestData.FloatAggregateId);
238+
this.AggregateService.Setup(f => f.GetLatest<TransactionAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.GetCompletedAuthorisedSaleTransactionAggregate()));
239+
this.AggregateService.Setup(f => f.GetLatest<FloatActivityAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(floatActivityAggregate));
240+
this.AggregateService.Setup(f => f.Save<FloatActivityAggregate>(It.IsAny<FloatActivityAggregate>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success());
241+
242+
FloatActivityCommands.RecordTransactionCommand command = new FloatActivityCommands.RecordTransactionCommand(TestData.EstateId, TestData.TransactionId);
243+
Result result = await this.FloatDomainService.RecordTransaction(command, CancellationToken.None);
244+
result.IsSuccess.ShouldBeTrue();
245+
}
246+
247+
[Fact]
248+
public async Task FloatDomainService_RecordTransaction_GetTransactionFailed()
249+
{
250+
this.AggregateService.Setup(f => f.GetLatest<TransactionAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Failure());
251+
252+
FloatActivityCommands.RecordTransactionCommand command = new FloatActivityCommands.RecordTransactionCommand(TestData.EstateId, TestData.TransactionId);
253+
Result result = await this.FloatDomainService.RecordTransaction(command, CancellationToken.None);
254+
result.IsFailed.ShouldBeTrue();
255+
}
256+
257+
[Fact]
258+
public async Task FloatDomainService_RecordTransaction_GetFloatActivityFailed()
259+
{
260+
this.AggregateService.Setup(f => f.GetLatest<TransactionAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.GetCompletedAuthorisedSaleTransactionAggregate()));
261+
this.AggregateService.Setup(f => f.GetLatest<FloatActivityAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Failure());
262+
263+
FloatActivityCommands.RecordTransactionCommand command = new FloatActivityCommands.RecordTransactionCommand(TestData.EstateId, TestData.TransactionId);
264+
Result result = await this.FloatDomainService.RecordTransaction(command, CancellationToken.None);
265+
result.IsFailed.ShouldBeTrue();
266+
}
267+
268+
[Fact]
269+
public async Task FloatDomainService_RecordTransaction_SaveFailed()
270+
{
271+
FloatActivityAggregate floatActivityAggregate = FloatActivityAggregate.Create(TestData.FloatAggregateId);
272+
this.AggregateService.Setup(f => f.GetLatest<TransactionAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.GetCompletedAuthorisedSaleTransactionAggregate()));
273+
this.AggregateService.Setup(f => f.GetLatest<FloatActivityAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(floatActivityAggregate));
274+
this.AggregateService.Setup(f => f.Save<FloatActivityAggregate>(It.IsAny<FloatActivityAggregate>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Failure());
275+
276+
FloatActivityCommands.RecordTransactionCommand command = new FloatActivityCommands.RecordTransactionCommand(TestData.EstateId, TestData.TransactionId);
277+
Result result = await this.FloatDomainService.RecordTransaction(command, CancellationToken.None);
278+
result.IsFailed.ShouldBeTrue();
279+
}
280+
281+
[Fact]
282+
public async Task FloatDomainService_RecordTransaction_ExceptionThrown()
283+
{
284+
FloatActivityAggregate floatActivityAggregate = FloatActivityAggregate.Create(TestData.FloatAggregateId);
285+
this.AggregateService.Setup(f => f.GetLatest<TransactionAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.GetCompletedAuthorisedSaleTransactionAggregate()));
286+
this.AggregateService.Setup(f => f.GetLatest<FloatActivityAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(floatActivityAggregate));
287+
this.AggregateService.Setup(f => f.Save<FloatActivityAggregate>(It.IsAny<FloatActivityAggregate>(), It.IsAny<CancellationToken>())).ThrowsAsync(new Exception());
288+
289+
FloatActivityCommands.RecordTransactionCommand command = new FloatActivityCommands.RecordTransactionCommand(TestData.EstateId, TestData.TransactionId);
290+
Result result = await this.FloatDomainService.RecordTransaction(command, CancellationToken.None);
291+
result.IsFailed.ShouldBeTrue();
292+
}
169293
}
170294
}

0 commit comments

Comments
 (0)