示例#1
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);
        }
示例#2
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);
        }
示例#3
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);
        }