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)); }
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")); }
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); }
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)); }
public HandlerBuilder WithBillInterceptor(RepositoryInterceptor <Bill> interceptor) { billRepo = interceptor; return(this); }