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 Update_ShouldUpdateParticipant() { // Arrange var options = BuildContextOptions(); Participant participant; using (var context = new BorrowBuddyContext(options)) { participant = context.AddParticipant(); context.SaveChanges(); } // Act using (var context = new BorrowBuddyContext(options)) { var service = new ParticipantService(context); await service.UpdateAsync(participant.Id, new ParticipantDto { FirstName = "FirstName_Modified", LastName = "LastName_Modified", MiddleName = "MiddleName_Modified" }); } // Assert using (var context = new BorrowBuddyContext(options)) { var result = context.Participants.FirstOrDefault(); Assert.NotNull(result); Assert.Equal("FirstName_Modified", result.FirstName); Assert.Equal("LastName_Modified", result.LastName); Assert.Equal("MiddleName_Modified", result.MiddleName); } }
public async Task Get_Exists_ShouldReturnParticipants() { // Arrange var options = BuildContextOptions(); using (var context = new BorrowBuddyContext(options)) { context.AddParticipant(); context.AddParticipant(); context.SaveChanges(); } using (var context = new BorrowBuddyContext(options)) { var service = new ParticipantService(context); // Act var result = await service.GetAsync(); // Assert Assert.NotNull(result); Assert.Equal(2, result.Count); } }
public async Task Add_ShouldAddFlow() { // Arrange var options = BuildContextOptions(); Currency currency; Participant lender; Participant lendee; using (var context = new BorrowBuddyContext(options)) { currency = context.AddCurrency(); lender = context.AddParticipant(); lendee = context.AddParticipant(); context.SaveChanges(); } using (var context = new BorrowBuddyContext(options)) { // Act var service = new FlowService(context); var dto = new FlowDto { LendeeId = lendee.Id, LenderId = lender.Id, Amount = 100, CurrencyCode = currency.Code }; await service.AddAsync(dto); } // Assert using (var context = new BorrowBuddyContext(options)) { var flow = context.Flows.FirstOrDefault(); Assert.NotNull(flow); Assert.Equal(lender.Id, flow.Lender.Id); Assert.Equal(lendee.Id, flow.Lendee.Id); Assert.Equal(100, flow.Amount.Value); Assert.Equal(currency.Code, flow.Amount.Currency.Code); } }
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); } }
public async Task Delete_ShouldDeleteParticipant() { // Arrange var options = BuildContextOptions(); Participant participant; using (var context = new BorrowBuddyContext(options)) { participant = context.AddParticipant(); } using (var context = new BorrowBuddyContext(options)) { // Act var service = new ParticipantService(context); await service.DeleteAsync(participant.Id); } using (var context = new BorrowBuddyContext(options)) { // Assert var result = context.Participants.FirstOrDefault(); Assert.Null(result); } }