Example #1
0
        public async void Newly_created_product_contains_price_equal_to_cost_divided_by_amount()
        {
            //Arrange
            var billInterceptor = new RepositoryInterceptor <Bill>();

            var handler = new HandlerBuilder()
                          .WithBillInterceptor(billInterceptor)
                          .Build();

            var command = new AddBill(
                new DateTime(),
                Guid.NewGuid(),
                new PurchaseInputDto[] {
                new PurchaseInputDto {
                    Product = new ProductDto {
                        Id = Guid.Empty, Barcode = "AXD"
                    }, Price = 10, Amount = 2
                },
            }
                );

            //Act
            await handler.Handle(command, CancellationToken.None);

            var createdBill = billInterceptor.InterceptedEntity;

            //Assert
            Assert.NotNull(createdBill.Purchases);
            Assert.Equal(1, createdBill.Purchases.Count);
            Assert.NotNull(createdBill.Purchases.FirstOrDefault(p => p.Product.Price.Value == 5));
        }
Example #2
0
        public void Throw_if_no_purchases()
        {
            var command = new AddBill(new DateTime(), Guid.NewGuid(), new PurchaseInputDto[] { });
            var handler = new HandlerBuilder().Build();

            Assert.ThrowsAsync <InvalidOperationException>(
                () => handler.Handle(command, CancellationToken.None)
                );
        }
Example #3
0
        public async void Create_collection_of_products_from_dtos_with_epmty_ids()
        {
            //Arrange
            var billInterceptor = new RepositoryInterceptor <Bill>();

            var handler = new HandlerBuilder()
                          .WithBillInterceptor(billInterceptor)
                          .Build();

            var command = new AddBill(
                new DateTime(),
                Guid.NewGuid(),
                new PurchaseInputDto[] {
                new PurchaseInputDto {
                    Product = new ProductDto {
                        Id = Guid.Empty, Barcode = "AXD"
                    }
                },
                new PurchaseInputDto {
                    Product = new ProductDto {
                        Id = Guid.Empty, Barcode = "33"
                    }
                },
                new PurchaseInputDto {
                    Product = new ProductDto {
                        Id = Guid.Empty, Barcode = "null"
                    }
                }
            }
                );

            //Act
            await handler.Handle(command, CancellationToken.None);

            var createdBill = billInterceptor.InterceptedEntity;

            //Assert
            Assert.NotNull(createdBill.Purchases);
            Assert.Equal(3, createdBill.Purchases.Count);
            Assert.NotNull(createdBill.Purchases.FirstOrDefault(p => p.Product.Barcode.Value == "AXD"));
            Assert.NotNull(createdBill.Purchases.FirstOrDefault(p => p.Product.Barcode.Value == "33"));
            Assert.NotNull(createdBill.Purchases.FirstOrDefault(p => p.Product.Barcode.Value == "null"));
        }
Example #4
0
        public async void Purchases_date_is_same_as_bill_from_command()
        {
            //Arrange
            var billInterceptor = new RepositoryInterceptor <Bill>();

            var products = new List <Product>
            {
                new Product("", ProductBarcode.GetRandomBarcode(), new MoneyValue(1), null)
            };

            var billDate = new DateTime(2019, 5, 11);

            var handler = new HandlerBuilder()
                          .WithBillInterceptor(billInterceptor)
                          .WithCustomProductRepo(products)
                          .Build();

            var command = new AddBill(
                billDate,
                Guid.NewGuid(),
                new PurchaseInputDto[] {
                new PurchaseInputDto {
                    Product = new ProductDto {
                    }
                },
                new PurchaseInputDto {
                    Product = new ProductDto {
                        Id = products[0].Id.Value
                    }
                }
            }
                );

            //Act
            await handler.Handle(command, CancellationToken.None);

            var createdBill = billInterceptor.InterceptedEntity;

            //Assert
            Assert.Equal(2, createdBill.Purchases.Where(p => p.Date == billDate).ToList().Count);
        }
Example #5
0
        public async void New_purchases_contains_amount_and_cost_data()
        {
            //Arrange
            var billInterceptor = new RepositoryInterceptor <Bill>();

            var products = new List <Product>
            {
                new Product("", ProductBarcode.GetRandomBarcode(), new MoneyValue(1), null)
            };

            var handler = new HandlerBuilder()
                          .WithBillInterceptor(billInterceptor)
                          .WithCustomProductRepo(products)
                          .Build();

            var command = new AddBill(
                new DateTime(),
                Guid.Empty,
                new PurchaseInputDto[] {
                new PurchaseInputDto {
                    Product = new ProductDto {
                    }, Amount = 10, Price = 15
                },
                new PurchaseInputDto {
                    Product = new ProductDto {
                        Id = products[0].Id.Value
                    }, Amount = 5, Price = 4
                }
            }
                );

            //Act
            await handler.Handle(command, CancellationToken.None);

            var createdBill = billInterceptor.InterceptedEntity;

            //Assert
            Assert.Equal(2, createdBill.Purchases.Count);
            Assert.NotNull(createdBill.Purchases.FirstOrDefault(p => p.Amount == 10 && p.Cost == 15));
            Assert.NotNull(createdBill.Purchases.FirstOrDefault(p => p.Amount == 5 && p.Cost == 4));
        }