public void CreateAndSplitBillAsync_WhenGroupDoesNotExist_ShouldThrow() { //Arrange var sutBuilder = new BillServiceSutBuilder(); var group = sutBuilder.CreateGroupWithUsers("Test group", 0); var loaner = sutBuilder.CreateUser(); A.CallTo(() => sutBuilder.GroupRepository.GetByIdAsync(group.Id)) .Returns <Group?>(null); A.CallTo(() => sutBuilder.BillRepository.AddAsync(A <Bill> ._)) .ReturnsLazily((Bill bill) => bill); var createNewBill = sutBuilder.CreateNewBill("Test bill", 100, group.Id, loaner.Id); var billService = sutBuilder.CreateSut(); //Act & Assert var exception = Assert.ThrowsAsync <NotFoundException>(async() => await billService.CreateAndSplitBillAsync(createNewBill)); exception.Message.ShouldBe($"Group with id {group.Id} does not exist."); }
public void CreateAndSplitBillAsync_WhenBillPayeeIsNotInGroup_ShouldThrow(decimal total, int userCount) { //Arrange var sutBuilder = new BillServiceSutBuilder(); var group = sutBuilder.CreateGroupWithUsers("Test group", userCount); var loaner = sutBuilder.CreateUser(); A.CallTo(() => sutBuilder.GroupRepository.GetByIdAsync(group.Id)) .Returns(group); A.CallTo(() => sutBuilder.BillRepository.AddAsync(A <Bill> ._)) .ReturnsLazily((Bill bill) => bill); var createNewBill = sutBuilder.CreateNewBill("Test bill", total, group.Id, loaner.Id); var billService = sutBuilder.CreateSut(); //Act & Aseert var exception = Assert.ThrowsAsync <NotFoundException>(async() => await billService.CreateAndSplitBillAsync(createNewBill)); exception.Message.ShouldBe($"Payee with id {loaner.Id} does not exist in group."); }