public async Task CreateNewOrderViaServiceTest() { var order = new OrderDto() { Id = 2, ProductId = "csklcdmsdklcmkldscm", ProductJson = "{name: 'Test Product 1', price: 2.99, currency: 'GBP'}", OrderDate = DateTime.Now, OrderCompleteDate = DateTime.Now, OrderComplete = false, UserId = 1, Quantity = 1, WorkflowId = 1 }; await _service.CreateNewOrder(order); var result = await _service.GetAllOpenOrders(); var insertedOrder = await _repository.GetById(2); Assert.Equal(2, result.Count); Assert.Equal("csklcdmsdklcmkldscm", insertedOrder.ProductId); Assert.Equal("{name: 'Test Product 1', price: 2.99, currency: 'GBP'}", insertedOrder.ProductJson); Assert.Equal(1, insertedOrder.UserId); Assert.Equal(1, insertedOrder.Quantity); Assert.Equal(1, insertedOrder.WorkflowId); }
public async Task <IActionResult> CreateNewOrder([FromBody] OrderDto order) { if (!ModelState.IsValid) { _logger.LogWarning(3, "Order modelstate invalid"); var messages = string.Join(";", ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage)); return(BadRequest(new { Error = messages })); } try { _logger.LogTrace(0, "Create new order"); await _service.CreateNewOrder(order); return(Created("", new { Message = "Order has been created successfully" })); } catch (Exception e) { _logger.LogError(5, e.InnerException.Message); throw; } }