public void Handle_InvalidId_ShouldThrowNotFoundException() { var command = new DeleteReceiptItemCommand { Id = "nah", FinancialProjectId = "ada" }; FluentActions.Awaiting(() => SendAsync(command)).Should().Throw <NotFoundException>(); }
public void Handle_FinancialProjectIdEmpty_ShouldThrowValidationException() { var command = new DeleteReceiptItemCommand { Id = "asdas", FinancialProjectId = "" }; FluentActions.Awaiting(() => SendAsync(command)).Should().Throw <ValidationException>(); }
public async Task Handle_ValidId_ShouldDeleteEntity() { var project = await CreateFinancialProject(); var receiptId = await CreateReceipt(project); var createCommand = new CreateReceiptItemCommand { ReceiptId = receiptId, Price = 2, ItemGroup = (int)ItemGroup.Essentials, Count = 22, Name = "das", UserIds = new List <string> { User.Id, SecondUser.Id } }; var id = await SendAsync(createCommand); var entityBeforeDeletion = await FindAsync <ReceiptItem>(id); entityBeforeDeletion.Should().NotBeNull(); var deleteCommand = new DeleteReceiptItemCommand { Id = id, FinancialProjectId = project }; var context = CreateContext(); var oweRecordBeforeDeleted = context.OweRecords.First(x => x.UserId == SecondUser.Id && x.OwedUserId == User.Id); oweRecordBeforeDeleted.Amount.Should() .Be(createCommand.Price * createCommand.Count / createCommand.UserIds.Count); await SendAsync(deleteCommand); context = CreateContext(); var entity = await FindAsync <ReceiptItem>(id); entity.Should().BeNull(); var oweRecord = context.OweRecords.First(x => x.UserId == SecondUser.Id && x.OwedUserId == User.Id); oweRecord.Amount.Should().Be(0); }