public async Task Balance_ShouldAddToEachOtherAsync() { // Arrange var options = BuildContextOptions(); Participant from; Participant to; Currency currency; using (var context = new BorrowBuddyContext(options)) { currency = context.AddCurrency(); from = context.AddParticipant(); to = context.AddParticipant(); context.AddFlow(from, to, currency, 50); context.AddFlow(from, to, currency, 100); } using (var context = new BorrowBuddyContext(options)) { var service = new BalanceService(context); // Act var balance = await service.BalanceAsync(from.Id, to.Id, currency.Code); // Assert Assert.Equal(150, balance); } }
public static Flow AddFlow(this BorrowBuddyContext context, long amount = 0) { var currency = context.AddCurrency(); var from = context.AddParticipant(); var to = context.AddParticipant(); return(context.AddFlow(from, to, currency, amount)); }
public async Task Get_Exists_ShouldReturnFlows() { // Arrange var options = BuildContextOptions(); using (var context = new BorrowBuddyContext(options)) { context.AddFlow(); context.AddFlow(); context.SaveChanges(); } using (var context = new BorrowBuddyContext(options)) { var service = new FlowService(context); // Act var result = await service.GetAsync(); // Assert Assert.NotNull(result); Assert.Equal(2, result.Count); } }
public async Task Delete_ShouldDeleteFlow() { // Arrange var options = BuildContextOptions(); Flow flow; using (var context = new BorrowBuddyContext(options)) { flow = context.AddFlow(); } using (var context = new BorrowBuddyContext(options)) { // Act var service = new FlowService(context); await service.DeleteAsync(flow.Id); } using (var context = new BorrowBuddyContext(options)) { // Assert var result = context.Flows.FirstOrDefault(); Assert.Null(result); } }
public async Task Update_ShouldUpdateFlow() { // Arrange var options = BuildContextOptions(); Flow flow; Participant newLender; Participant newLendee; using (var context = new BorrowBuddyContext(options)) { flow = context.AddFlow(); newLender = context.AddParticipant(); newLendee = context.AddParticipant(); context.SaveChanges(); } // Act using (var context = new BorrowBuddyContext(options)) { var service = new FlowService(context); await service.UpdateAsync(flow.Id, new FlowDto { Amount = 123, Comment = "newComment", LendeeId = newLendee.Id, LenderId = newLender.Id }); } // Assert using (var context = new BorrowBuddyContext(options)) { var result = context.Flows.FirstOrDefault(); Assert.NotNull(result); Assert.Equal(123, result.Amount.Value); Assert.Equal("newComment", result.Comment); Assert.Equal(newLendee.Id, result.Lendee.Id); Assert.Equal(newLender.Id, result.Lender.Id); } }