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 static Participant AddParticipant(this BorrowBuddyContext context) { var participant = new Participant(); context.Participants.Add(participant); context.SaveChanges(); return(participant); }
public static Currency AddCurrency(this BorrowBuddyContext context, string code = "") { if (string.IsNullOrEmpty(code)) { code = Guid.NewGuid().ToString(); } var currency = new Currency { Code = code }; context.Currencies.Add(currency); context.SaveChanges(); return(currency); }
public static Flow AddFlow(this BorrowBuddyContext context, Participant from, Participant to, Currency currency, long amount) { var flow = new Flow { Lendee = to, Lender = from, Amount = new Money { Currency = currency, Value = amount } }; context.Flows.Add(flow); context.SaveChanges(); return(flow); }
public async Task Get_Exists_ShouldReturnCurrency() { // Arrange var options = BuildContextOptions(); using (var context = new BorrowBuddyContext(options)) { context.AddCurrency("code"); context.SaveChanges(); } using (var context = new BorrowBuddyContext(options)) { var service = new CurrencyService(context); // Act var result = await service.GetAsync("code"); // Assert Assert.NotNull(result); } }
public async Task Get_Exists_ShouldReturnFlow() { // Arrange var options = BuildContextOptions(); Flow flow; using (var context = new BorrowBuddyContext(options)) { flow = context.AddFlow(); context.SaveChanges(); } using (var context = new BorrowBuddyContext(options)) { var service = new FlowService(context); // Act var result = await service.GetAsync(flow.Id); // Assert Assert.NotNull(result); } }
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); } }