// [Fact] public async Task AddOrder_Should_Correctly_Add_Order_For_Non_Charm_Product_Without_Discounts() { // arrange var shipment = await GetShipmentForTest(); var product = await GetNonCharmProductForTest(); var httpClient = factory.CreateClient(); var expectedOrderPrice = 35; var expectedOrderPriceAndShipment = 35 + shipment.Price; var token = await UserFactory.AuthenticateUser(httpClient, "*****@*****.**", "1qaz@WSX"); httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}"); var addOrderCommand = new AddOrderCommandModel { ShipmentId = shipment.Id, Address = new NewAddressDto { City = "NY", Country = "USA", PhoneNumber = 123456789, PostCode = "234-987", Street = "Main" }, Products = new List <ProductWithCharmsOrderDto> { new ProductWithCharmsOrderDto { Amount = 1, ProductId = product.Id } } }; // act var result = await httpClient.PostAsJsonAsync(baseEndpoint, addOrderCommand); var content = await result.Content.ReadAsStringAsync(); if (!result.IsSuccessStatusCode) { output.WriteLine(content); } var newId = JsonConvert.DeserializeObject <NewOrderDto>(content); var newOrder = await GetOrder(newId.Id); // assert newOrder.BasePrice.Should().Be(expectedOrderPrice); newOrder.Address.Should().NotBe(null); newOrder.ProductOrders.Count().Should().Be(1); (newOrder.FinalPrice + newOrder.ShipmentPrice).Should().Be(expectedOrderPriceAndShipment); }
public AddOrderCommandHandlerFixture() { UserQueryServiceMock = new Mock <IUserQueryService>(); ShipmentQueryServiceMock = new Mock <IShipmentQueryService>(); OrderDiscountQueryServiceMock = new Mock <IOrderDiscountQueryService>(); ProductOrderQueryServiceMock = new Mock <IProductOrderQueryService>(); AddressQueryServiceMock = new Mock <IAddressQueryService>(); OrderCommandServiceMock = new Mock <IOrderCommandService>(); EmailServiceMock = new Mock <IEmailService>(); MapperMock = new Mock <IMapper>(); Sut = new AddOrderCommandHandler(UserQueryServiceMock.Object, ShipmentQueryServiceMock.Object, OrderDiscountQueryServiceMock.Object, ProductOrderQueryServiceMock.Object, AddressQueryServiceMock.Object, OrderCommandServiceMock.Object, EmailServiceMock.Object, MapperMock.Object); Request = Fixture.Build <AddOrderCommandModel>() .Do(s => s.SetUserId(Guid.NewGuid())) .Create(); }
public async Task <IActionResult> Post([FromBody] AddOrderCommandModel model) { var orderId = await mediator.Send(model.SetUserId(User.Identity.GetUserId())); return(Ok(new { orderId })); }
public async Task <IActionResult> Post([FromBody] AddOrderCommandModel model) { var orderId = await bus.SendAsync(model.SetUserId(User.GetUserId())); return(Ok(new NewOrderDto(orderId))); }