예제 #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);
        }
예제 #4
0
        public static async Task <PurchaseTransaction> ReloadPurchaseTransaction(PurchaseTransactionId id)
        {
            var connectionString = ConnectivityService.GetConnectionString("TEMP");
            var context          = new SplurgeStopDbContext(connectionString);
            var repository       = new PurchaseTransactionRepository(context);

            return(await repository.GetAsync(id));
        }
예제 #5
0
        public async Task FullPurchase_transaction_inserted_to_database()
        {
            PurchaseTransactionId transactionId = await CreateFullValidPurchaseTransaction();

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

            Assert.True(await repository.ExistsAsync(transactionId));
            Assert.Equal(DateTime.Now.Date, sut.PurchaseDate);
            Assert.NotNull(sut.Store);
            Assert.Single(sut.LineItems);
        }
예제 #6
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);
        }
예제 #7
0
        public async Task Change_Store()
        {
            var purchaseTransactionId = await CreateValidPurchaseTransaction();

            var repository = new PurchaseTransactionRepository(fixture.context);

            var sut = await repository.GetAsync(purchaseTransactionId);

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

            Assert.NotNull(sut);

            var newStore = await StoreHelpers.CreateValidStore();

            await UpdateStore(sut.Id, newStore);

            sut = await repository.LoadFullPurchaseTransactionAsync(sut.Id);

            await fixture.context.Entry(sut).ReloadAsync();

            Assert.Equal(newStore.Id, sut.Store.Id);
        }