public async Task Update_LineItem_price() { PurchaseTransactionId transactionId = await CreateValidPurchaseTransaction(22.33m); var repository = new PurchaseTransactionRepository(fixture.context); var sut = await repository.GetPurchaseTransactionFullAsync(transactionId); Assert.NotNull(sut.LineItems); Assert.Single(sut.LineItems); Assert.Equal(22.33m, sut.LineItems.FirstOrDefault().Price.Amount); var lineItemId = sut.LineItems.FirstOrDefault().Id; var updatedLineItem = LineItemBuilder .LineItem(new Price(33.44m, Booking.Credit, "EUR", "€", CurrencySymbolPosition.end), lineItemId) .Build(); await UpdateLineItem(transactionId, updatedLineItem); sut = await ReloadPurchaseTransaction(sut.Id); Assert.Single(sut.LineItems); Assert.Equal(33.44m, sut.LineItems.FirstOrDefault().Price.Amount); }
public async Task Total_price_of_line_items_with_debit_item() { PurchaseTransactionId transactionId = await CreateValidPurchaseTransaction(1.23m); var repository = new PurchaseTransactionRepository(fixture.context); Assert.True(await repository.ExistsAsync(transactionId)); var sut = await repository.GetPurchaseTransactionFullAsync(transactionId); Assert.Single(sut.LineItems); var secondLineItem = LineItemBuilder.LineItem(new Price(2.54m, Booking.Credit, "EUR", "€", CurrencySymbolPosition.end)) .Build(); await UpdateLineItem(sut.Id, secondLineItem); var debitLineItem = LineItemBuilder.LineItem(new Price(1.54m, Booking.Debit, "EUR", "€", CurrencySymbolPosition.end)) .Build(); await UpdateLineItem(sut.Id, debitLineItem); sut = await ReloadPurchaseTransaction(sut.Id); Assert.Equal(3, sut.LineItems.Count); Assert.Equal(2, sut.LineItems.Count(i => i.Price.Booking == Booking.Credit)); Assert.Equal(1, sut.LineItems.Count(i => i.Price.Booking == Booking.Debit)); var result = decimal.Parse(sut.TotalPrice.Substring(0, sut.TotalPrice.IndexOf(' ', StringComparison.Ordinal))); Assert.Equal(2.23m, result); }
public async static Task <PurchaseTransaction> ReloadPurchaseTransaction(PurchaseTransactionId id) { var connectionString = ConnectivityService.GetConnectionString("TEMP"); var context = new SplurgeStopDbContext(connectionString); var repository = new PurchaseTransactionRepository(context); return(await repository.GetPurchaseTransactionFullAsync(id)); }
public async Task FullPurchase_transaction_inserted_to_database() { PurchaseTransactionId transactionId = await CreateFullValidPurchaseTransaction(); var repository = new PurchaseTransactionRepository(fixture.context); var sut = await repository.GetPurchaseTransactionFullAsync(transactionId); Assert.True(await repository.ExistsAsync(transactionId)); Assert.Equal(DateTime.Now.Date, sut.PurchaseDate); Assert.NotNull(sut.Store); Assert.Single(sut.LineItems); }
public async Task Add_lineItem_with_notes() { var lineItem = LineItemBuilder.LineItem(new Price(1.00m, Booking.Credit, "EUR", "€", CurrencySymbolPosition.end)) .WithNotes("My Notes!") .Build(); PurchaseTransactionId transactionId = await CreateValidPurchaseTransaction(1m, lineItem); var repository = new PurchaseTransactionRepository(fixture.context); var sut = await repository.GetPurchaseTransactionFullAsync(transactionId); Assert.True(await repository.ExistsAsync(transactionId)); Assert.Equal("My Notes!", sut.LineItems.FirstOrDefault().Notes); }
public async static Task <PurchaseTransactionId> CreateValidPurchaseTransaction(decimal price = 1.00m, LineItem lineItem = null) { var connectionString = ConnectivityService.GetConnectionString("TEMP"); var context = new SplurgeStopDbContext(connectionString); var repository = new PurchaseTransactionRepository(context); var unitOfWork = new EfCoreUnitOfWork(context); var service = new PurchaseTransactionService(repository, unitOfWork); var command = new transaction.Commands.Create(); command.Id = null; // Create PurchaseTransaction var transactionController = new PurchaseTransactionController(service); var result = await transactionController.Post(command); // Add PurchaseDate await UpdatePurchaseDate(result.Value.Id, DateTime.Now); var purchaseTransaction = await repository.GetPurchaseTransactionFullAsync(result.Value.Id); // Add Store var store = await CreateValidStore(); await UpdateStore(purchaseTransaction.Id, store); // Add one LineItem var updateLineItemCommand = new transaction.Commands.SetPurchaseTransactionLineItem(); updateLineItemCommand.Id = purchaseTransaction.Id; updateLineItemCommand.Price = price; updateLineItemCommand.Currency = "EUR"; updateLineItemCommand.CurrencySymbol = "€"; updateLineItemCommand.Booking = Booking.Credit; updateLineItemCommand.CurrencySymbolPosition = CurrencySymbolPosition.end; updateLineItemCommand.Notes = lineItem?.Notes; await transactionController.Put(updateLineItemCommand); return(command.Id); }
public async Task Add_transaction_lineItem() { PurchaseTransactionId transactionId = await CreateValidPurchaseTransaction(); var repository = new PurchaseTransactionRepository(fixture.context); Assert.True(await repository.ExistsAsync(transactionId)); var sut = await repository.GetPurchaseTransactionFullAsync(transactionId); Assert.Single(sut.LineItems); var lineItem = LineItemBuilder .LineItem(new Price(2.54m, Booking.Credit, "EUR", "€", CurrencySymbolPosition.end)) .Build(); await UpdateLineItem(sut.Id, lineItem); sut = await ReloadPurchaseTransaction(sut.Id); Assert.Equal(2, sut.LineItems.Count); }