예제 #1
0
        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.GetAsync(transactionId);

            Assert.Single(sut.LineItems);

            // Get Product
            var prod = await ProductHelpers.CreateValidProduct();

            var lineItem = LineItemBuilder
                           .LineItem(new Price(2.54m))
                           .WithProduct(prod)
                           .Build();

            await UpdateLineItem(sut.Id, lineItem);

            sut = await ReloadPurchaseTransaction(sut.Id);

            Assert.Equal(2, sut.LineItems.Count);
        }
예제 #2
0
        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);
        }
예제 #3
0
        public async Task Update_LineItem_price()
        {
            PurchaseTransactionId transactionId = await CreateValidPurchaseTransaction(22.33m);

            var repository = new PurchaseTransactionRepository(fixture.context);

            var sut = await repository.GetAsync(transactionId);

            Assert.NotNull(sut.LineItems);
            Assert.Single(sut.LineItems);
            Assert.Equal(22.33m, sut.LineItems.FirstOrDefault()?.Price.Amount);

            var lineItemId = sut.LineItems.FirstOrDefault()?.Id;

            // Get Product
            var prod = await ProductHelpers.CreateValidProduct();

            var updatedLineItem = LineItemBuilder
                                  .LineItem(new Price(33.44m), lineItemId)
                                  .WithProduct(prod)
                                  .Build();

            await UpdateLineItem(transactionId, updatedLineItem);

            sut = await ReloadPurchaseTransaction(sut.Id);

            Assert.Single(sut.LineItems);
            Assert.Equal(33.44m, sut.LineItems.FirstOrDefault()?.Price.Amount);
        }
예제 #4
0
        public async Task Total_price_of_line_items()
        {
            PurchaseTransactionId transactionId = await CreateValidPurchaseTransaction(1.23m);

            var repository = new PurchaseTransactionRepository(fixture.context);

            Assert.True(await repository.ExistsAsync(transactionId));

            var sut = await repository.GetAsync(transactionId);

            Assert.Single(sut.LineItems);

            // Get Product
            var prod = await ProductHelpers.CreateValidProduct();

            var secondLineItem = LineItemBuilder
                                 .LineItem(new Price(2.54m))
                                 .WithProduct(prod)
                                 .Build();

            await UpdateLineItem(sut.Id, secondLineItem);

            sut = await ReloadPurchaseTransaction(sut.Id);

            Assert.Equal(2, sut.LineItems.Count);
            var result = decimal.Parse(sut.TotalPrice.Substring(0, sut.TotalPrice.IndexOf(' ', StringComparison.Ordinal)));

            Assert.Equal(3.77m, result);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        public void Has_product()
        {
            var price = new Price(1.00m);

            var brand       = Brand.Create(Guid.NewGuid(), "test");
            var productType = ProductType.Create(Guid.NewGuid(), "product type");
            var size        = Size.Create(Guid.NewGuid(), "your size");

            var prodId  = new ProductId(SequentialGuid.NewSequentialGuid());
            var product = Product.Create(prodId, "newProd", brand, productType, size);
            var sut     = LineItemBuilder.LineItem(price).WithProduct(product).Build();

            Assert.Contains("newProd", sut.Product.Name);
        }
예제 #8
0
        public void Has_notes()
        {
            var brand       = Brand.Create(Guid.NewGuid(), "brand");
            var productType = ProductType.Create(Guid.NewGuid(), "product type");
            var size        = Size.Create(Guid.NewGuid(), "your size");

            var product = Product.Create(Guid.NewGuid(), "product", brand, productType, size);

            var price = new Price(1.00m);
            var sut   = LineItemBuilder.LineItem(price)
                        .WithNotes("No kun sai niin halvalla.")
                        .WithProduct(product)
                        .Build();

            Assert.Contains("halvalla", sut.Notes);
        }
예제 #9
0
        public async Task Add_lineItem_with_notes()
        {
            var brand       = Brand.Create(Guid.NewGuid(), "brand");
            var productType = ProductType.Create(Guid.NewGuid(), "product type");
            var size        = Size.Create(Guid.NewGuid(), "your size");

            var product  = Product.Create(Guid.NewGuid(), "product", brand, productType, size);
            var lineItem = LineItemBuilder.LineItem(new Price(1.00m))
                           .WithNotes("My Notes!")
                           .WithProduct(product)
                           .Build();

            PurchaseTransactionId transactionId = await CreateValidPurchaseTransaction(1m, lineItem);

            var repository = new PurchaseTransactionRepository(fixture.context);
            var sut        = await repository.GetAsync(transactionId);

            Assert.True(await repository.ExistsAsync(transactionId));
            Assert.Equal("My Notes!", sut.LineItems.FirstOrDefault()?.Notes);
        }
예제 #10
0
        public void Total_sum_of_line_items()
        {
            var sut = CreatePurchaseTransaction();

            var brand       = Brand.Create(Guid.NewGuid(), "brand");
            var productType = ProductType.Create(Guid.NewGuid(), "product type");
            var size        = Size.Create(Guid.NewGuid(), "your size");

            var product = Product.Create(Guid.NewGuid(), "prod", brand, productType, size);

            for (int i = 1; i < 6; i++)
            {
                var lineItem = LineItemBuilder.LineItem(new Price(1.0m * i))
                               .WithProduct(product)
                               .Build();
                sut.UpdateLineItem(lineItem);
            }

            Assert.Contains("15.0", sut.TotalPrice);
        }
예제 #11
0
 public Task Handle(object command)
 {
     return(command switch
     {
         CreateFull cmd => HandleCreateFull(cmd),
         SetPurchaseTransactionDate cmd
         => HandleUpdate(cmd.Id, c => c.UpdatePurchaseTransactionDate(cmd.TransactionDate)),
         SetPurchaseTransactionStore cmd
         => HandleUpdateAsync(cmd.Id, async c => await UpdateStoreAsync(c, cmd.StoreId)),
         SetPurchaseTransactionLineItem cmd
         => HandleUpdateAsync(cmd.Id, async c
                              => await UpdateLineItemAsync(c, cmd, LineItemBuilder
                                                           .LineItem(new Price(cmd.Price, cmd.Booking, cmd.Currency, cmd.CurrencySymbol, cmd.CurrencySymbolPosition),
                                                                     cmd.LineItemId)
                                                           .WithNotes(cmd.Notes)
                                                           .WithProduct(cmd.Product)
                                                           .Build())),
         DeletePurchaseTransaction cmd => HandleUpdateAsync(cmd.Id, _ => this._repository.RemoveAsync(cmd.Id)),
         _ => Task.CompletedTask
     });
예제 #12
0
        public void Valid_line_item_update()
        {
            var sut = CreatePurchaseTransaction();

            Assert.NotNull(sut.LineItems);
            Assert.True(sut.LineItems.Count == 0);

            var brand       = Brand.Create(Guid.NewGuid(), "brand");
            var productType = ProductType.Create(Guid.NewGuid(), "product type");
            var size        = Size.Create(Guid.NewGuid(), "your size");

            var product = Product.Create(Guid.NewGuid(), "prod", brand, productType, size);

            var newLineItem = LineItemBuilder
                              .LineItem(new Price(1.1m))
                              .WithProduct(product)
                              .Build();

            sut.UpdateLineItem(newLineItem);

            Assert.True(sut.LineItems.Count == 1);
        }
예제 #13
0
        public void Valid_lineItem(decimal amount,
                                   Booking booking,
                                   string currencyCode,
                                   string currencySymbol,
                                   CurrencySymbolPosition currencySymbolPosition)
        {
            var brand       = Brand.Create(Guid.NewGuid(), "brand");
            var productType = ProductType.Create(Guid.NewGuid(), "product type");
            var size        = Size.Create(Guid.NewGuid(), "your size");

            var product = Product.Create(Guid.NewGuid(), "product", brand, productType, size);

            var price = new Price(amount, booking, currencyCode, currencySymbol, currencySymbolPosition);
            var sut   = LineItemBuilder.LineItem(price).WithProduct(product).Build();

            Assert.IsType <LineItem>(sut);
            Assert.Equal(amount, sut.Price.Amount);
            Assert.Equal(booking, sut.Price.Booking);
            Assert.Equal(currencyCode, sut.Price.Currency.CurrencyCode);
            Assert.Equal(currencySymbol, sut.Price.Currency.CurrencySymbol);
            Assert.Equal(currencySymbolPosition, sut.Price.Currency.PositionRelativeToPrice);
        }
예제 #14
0
        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);
        }
예제 #15
0
 public void Invalid_lineItem_no_product()
 {
     Assert.Throws <ArgumentNullException>(()
                                           => LineItemBuilder.LineItem(new Price(1.00m)).Build());
 }
예제 #16
0
 public void Invalid_lineItem_no_price()
 {
     Assert.Throws <ArgumentNullException>(()
                                           => LineItemBuilder.LineItem(null).Build());
 }