public async Task SubmitOrder_WithInvalidInput_ReturnsValidationError() { var book = new Book( BookGenre.Detective, "No Orchids for Miss Blandish", "James Hadley Chase", 10m); var cart = new Cart(book, null); DbContext.Add(cart); await DbContext.SaveChangesAsync(); var command = new SubmitOrderCommand { CartId = cart.Id, PhoneNumber = null }; var exception = await Client.Invoking(x => x.SubmitOrder(command)) .Should() .ThrowAsync <ServiceException>(); var error = exception.Which.Error.Should().BeOfType <ValidationError>().Subject; error.Errors.Should().ContainKey(nameof(command.PhoneNumber)); }
public async Task Step5__Customer_Submits_A_Valid_Order() { // Submit order var submitOrderCommand = new SubmitOrderCommand { PhoneNumber = "+375291234567", CartId = _cart.Id }; var order = await Client.SubmitOrder(submitOrderCommand); var expectedOrder = new OrderModel { Id = _cart.Id, PhoneNumber = submitOrderCommand.PhoneNumber, Lines = _selectedBooks.Select(book => new OrderLineModel { Book = book, Price = book.Price }).ToList() }; order.Should().BeEquivalentTo(expectedOrder); // Cart should become empty var cartQuery = new GetCartQuery { CartId = _cart.Id }; var cart = await Client.GetCart(cartQuery); cart.Books.Should().BeEmpty(); }
public async Task SubmitOrder_CreatesAnOrderSuccessfully() { // Set up data through the back door var book1 = new Book( BookGenre.Detective, "No Orchids for Miss Blandish", "James Hadley Chase", 10m); var book2 = new Book( BookGenre.Detective, "Come Easy – Go Easy", "James Hadley Chase", 15m); var cart = new Cart(book1, null); cart.AddBook(book2); DbContext.Add(cart); await DbContext.SaveChangesAsync(); // Set up data through the front door // Nothing here, did everything through the back door :) // Build inputs var command = new SubmitOrderCommand { CartId = cart.Id, PhoneNumber = "+375291234567" }; // Send inputs to system var actualOrder = await Client.SubmitOrder(command); // Verify direct outputs actualOrder.Id.Should().NotBeEmpty(); var expectedOrder = new OrderModel { Id = actualOrder.Id, PhoneNumber = command.PhoneNumber, Lines = cart.Books.Select(book => new OrderLineModel { Book = new BookModel { Id = book.Id, Author = book.Author, Genre = book.Genre, Price = book.Price, Title = book.Title }, Price = book.Price }).ToList() }; actualOrder.Should().BeEquivalentTo(expectedOrder); // Verify side-effects cart = DbContext.Carts.SingleOrDefault(x => x.Id == cart.Id); cart.Should().BeNull("cart should be deleted after order is submitted"); }
public async Task <ActionResult <SubmitOrderCommandResponse> > SubmitOrderAsync(Guid id) { var request = new SubmitOrderCommand { Id = id }; var response = await _messageBus.SendAsync(request); return(Ok(response)); }
public async Task <OrderModel> SubmitOrder(SubmitOrderCommand command) { var response = await _httpClient.PostAsJsonAsync("orders", command); var order = await SafelyReadFromJsonAsync <OrderModel>(response); order.Id.Should().Be(command.CartId); order.Lines.Should().HaveCountGreaterOrEqualTo(1); return(order); }
public DriveThruViewModel() { _items = new ObservableCollection <string>(); _orders = new ObservableQueue <OrderViewModel>(); SubmitOrderCommand = new SubmitOrderCommand(this); GiveOrderCommand = new GiveOrderCommand(this); _items.Add("Chicken"); _items.Add("Salad"); _items.Add("Fruit Cup"); }
public async Task <IActionResult> SubmitOrder([FromBody] SubmitOrderCommand submitOrderCommand) { var submitOrderDtoResult = await QueryProcessor.GetQueryHandler <SubmitOrderCommand, OrderDto>(submitOrderCommand); if (submitOrderDtoResult.Failure) { return(BadRequest(submitOrderDtoResult.ErrorMessages)); } var submitOrderDto = submitOrderDtoResult.Object; return(Ok(submitOrderDto)); }
public async void Post([FromBody] SubmitOrder submittedOrder) { var command = new SubmitOrderCommand() { CustomerId = submittedOrder.CustomerId, Items = submittedOrder.Items.Select(t => new Item() { ProductId = t.ProductId, Quantity = t.Quantity }).ToArray() }; await _bus.Send(command); }
public async Task <SubmitOrderResponse> SubmitOrderAsync() { var command = new SubmitOrderCommand { Number = DateTime.Now.Ticks }; _log.LogInformation($"SubmitOrderCommand {command.Number}"); var response = await _messageSession.Request <SubmitOrderResponse>(command); _log.LogInformation($"SubmitOrderResponse {response.Id}"); return(response); }
public async void Post([FromBody] SubmitOrder submittedOrder) { var command = new SubmitOrderCommand() { CustomerId = submittedOrder.CustomerId, Items = submittedOrder.Items.Select(t => new Item() { ProductId = t.ProductId, Quantity = t.Quantity }).ToArray() }; var sendEndpoint = await _bus.GetSendEndpoint(new Uri($"rabbitmq://{Configuration.RabbitMqHost}/sales_submit_orders")); await sendEndpoint.Send(command); }
public void Handle(SubmitOrderCommand message) { Data.OrderNumber = ORDER_NUMBER++; Data.CustomerUsername = message.CustomerUsername; Data.Products = MapProducts(message.ProductIds); //get user's credit card number Bus.Send(new ProcessCreditCardPaymentCommand { Id = Data.Id, CardholderName = "John Q. Public", CardNumber = "5454545454545454", Amount = Data.Total(), }); }
public async void Post([FromBody] SubmitOrder submittedOrder) { _logger.LogInformation($"A new order has been accepted for customer id '{submittedOrder.CustomerId}'."); var command = new SubmitOrderCommand() { CorrelationId = _correlationContextAccessor.CorrelationContext.CorrelationId.ToGuid(), CustomerId = submittedOrder.CustomerId, Items = submittedOrder.Items.Select(t => new Item() { ProductId = t.ProductId, Quantity = t.Quantity }).ToArray() }; await _bus.Send(command); }
public async void Post([FromBody] SubmitOrder submittedOrder) { // 从header中获取 Customer Id if (submittedOrder.CustomerId == 0) { submittedOrder.CustomerId = HttpContext.UserCustomerId(); } _logger.LogInformation($"收到了来自顾客 '{submittedOrder.CustomerId}' 的新订单"); var command = new SubmitOrderCommand() { CorrelationId = _correlationContextAccessor.CorrelationContext.CorrelationId.ToGuid(), CustomerId = submittedOrder.CustomerId, Items = submittedOrder.Items.Select(t => new Item() { ProductId = t.ProductId, Quantity = t.Quantity }).ToArray() }; await _bus.Send(command); }
public async Task Step4__Customer_Tries_To_Submit_An_Order_Without_Phone_Number() { // Visit the cart page and check that books are still there var cartQuery = new GetCartQuery { CartId = _cart.Id }; var cart = await Client.GetCart(cartQuery); cart.Should().BeEquivalentTo(_cart); // Submit order var submitOrderCommand = new SubmitOrderCommand { PhoneNumber = null, CartId = _cart.Id }; var exception = await Client.Invoking(x => x.SubmitOrder(submitOrderCommand)) .Should() .ThrowAsync <ServiceException>(); var error = exception.Which.Error.Should().BeOfType <ValidationError>().Subject; error.Errors.Should().ContainKey(nameof(submitOrderCommand.PhoneNumber)); }
public Task <ObjectClientResponse <SubmitOrderCommandResponse> > SubmitOrderAsync(SubmitOrderCommand request, HeaderData header) { var id = request.Id; return(Client.PostAsync <SubmitOrderCommandResponse>($"{id}/submit", GetHeaders(header))); }
public async Task <ActionResult <OrderModel> > SubmitOrder([FromBody] SubmitOrderCommand command) { var order = await _mediator.Send(command); return(order); }