public static void Main(string[] args) { InitializeFake(); var command = new CreateOrderCommand { CustomerId = Guid.Parse("418be026-b301-4696-b062-08d70cfeca04"), DF = 4, Discount = 10, Items = new List <CreateOrderItemCommand> { new CreateOrderItemCommand { ProductId = Guid.Parse("608f1b52-07ed-42ec-a1a3-55c4e73a8755"), Quantity = 6 }, new CreateOrderItemCommand { ProductId = Guid.Parse("36d8130d-608f-45ff-a177-8137ca8bc7b6"), Quantity = 2 } } }; var appService = new OrderApplicationService(_customerRepository, _productRepository, _orderRepository); var result = (CreateOrderCommandResult)appService.Handle(command); Render(result); }
private async Task ClientAddOrderItemAsync(DbContextOptions <OrderDbContext> options, Guid orderId, string itemCode, CancellationToken cancellationToken) { await using var context = new OrderDbContext(options); var service = new OrderApplicationService(context, _dispatcher, _logger); await service.AddOrderItemAsync(orderId, itemCode, cancellationToken); }
public void PurchaseOnBirthday_SubTotalOver50_Discount10() { var command = GetCommand(customerId: "1a59d5bf-9233-44dc-9816-3cc93372da61"); var appService = new OrderApplicationService(_customerRepository, _productRepository, _orderRepository); var result = (CreateOrderCommandResult)appService.Handle(command); Assert.Equal(10, result.Discount); }
public void LastPurchase40DaysAgo_Discount5Percent_Total137() { var command = GetCommand(customerId: "25eef3d0-53c6-47e0-9c2b-76d67bbd0151"); var appService = new OrderApplicationService(_customerRepository, _productRepository, _orderRepository); var result = (CreateOrderCommandResult)appService.Handle(command); Assert.Equal(137, result.Total); }
public void FirstPurchase_Discount10Percent_Total126() { var command = GetCommand(); var appService = new OrderApplicationService(_customerRepository, _productRepository, _orderRepository); var result = (CreateOrderCommandResult)appService.Handle(command); Assert.Equal(130, result.Total); }
public void Handle_CreateOrderCommandNullProduct_ThrowsArgumentException() { var command = GetCommand(); command.Items.ToList().First().ProductId = Guid.Parse("1b63e81b-3cb0-46ca-ab45-80661321817f"); var appService = new OrderApplicationService(_customerRepository, _productRepository, _orderRepository); var ex = Assert.Throws <ArgumentException>(() => appService.Handle(command)); Assert.Equal("Product not found. (Parameter 'product')", ex.Message); }
public void Handle_CreateOrderCommandNullCustumer_ThrowsArgumentException() { var command = GetCommand(); command.CustomerId = Guid.Parse("20e24fb3-8bcd-4f48-b457-a64562b58d74"); var appService = new OrderApplicationService(_customerRepository, _productRepository, _orderRepository); var ex = Assert.Throws <ArgumentException>(() => appService.Handle(command)); Assert.Equal("Product not found. (Parameter 'customer')", ex.Message); }
public void Test_CreateOrder_and_SaveToRepository() { var(orderItems, shippingInfo) = OrderTestHelper.Given_OrderDetailsIsReady(); var orderRepository = Substitute.For <IRepository <Order> >(); var service = new OrderApplicationService(orderRepository); service.CreateOrder(orderItems, shippingInfo); orderRepository.Received(1).Save(Arg.Any <Order>()); }
public void Handle_CreateOrderCommandQuantityInvalid_ThrowsArgumentException(int quantity) { var command = GetCommand(); command.Items.ToList().First().Quantity = quantity; var appService = new OrderApplicationService(_customerRepository, _productRepository, _orderRepository); var ex = Assert.Throws <ArgumentException>(() => appService.Handle(command)); Assert.Equal("Quantity should be positive. (Parameter 'Quantity')", ex.Message); }
public void Handle_CreateOrderCommandDeliveryFeeInvalid_ThrowsArgumentException(decimal deliveryFee) { var command = GetCommand(); command.DF = deliveryFee; var appService = new OrderApplicationService(_customerRepository, _productRepository, _orderRepository); var ex = Assert.Throws <ArgumentException>(() => appService.Handle(command)); Assert.Equal("DF should be applied. (Parameter 'DF')", ex.Message); }
public void Handle_CreateOrderCommandDiscountInvalid_ThrowsArgumentException(decimal discount) { var command = GetCommand(); command.Discount = discount; var appService = new OrderApplicationService(_customerRepository, _productRepository, _orderRepository); var ex = Assert.Throws <ArgumentException>(() => appService.Handle(command)); Assert.Equal("Discount should be positive. (Parameter 'Discount')", ex.Message); }
public void Handle_CreateOrderCommandValid_OrderCreated() { var command = GetCommand(discount: 25); var appService = new OrderApplicationService(_customerRepository, _productRepository, _orderRepository); var result = (CreateOrderCommandResult)appService.Handle(command); Assert.Equal(DateTime.Today, result.CreatedDateTime, TimeSpan.FromDays(1)); Assert.Equal(140m, result.SubTotal); Assert.Equal(4m, result.DeliveryFee); Assert.Equal(25m, result.Discount); Assert.Equal(119m, result.Total); }
public void should_create_and_save_order_aggregate() { var customerId = Guid.NewGuid(); var senderId = Guid.NewGuid(); var agg = new OrderAggregate(); var repository = new Mock <IRepository>(); var eventsDispatcher = new Mock <IEventDispatcher>(); repository.Setup(r => r.Get <OrderAggregate>(It.IsAny <Guid>())).Returns(agg); var sut = new OrderApplicationService(repository.Object, eventsDispatcher.Object); sut.When(new CreateOrder { CustomerId = customerId, SenderId = senderId }); repository.Verify(x => x.Save(It.IsAny <OrderAggregate>()), Times.Once); }
public Client() { _service = new OrderApplicationService(_reader, _visitor); }
public OrderController(ILogger <OrderController> logger, OrderApplicationService appService) { this.logger = logger; this.appService = appService; }