public async Task Can_add_Order() { const int ORDER = 3; const string SITE_MANAGER_ID = "EMP1"; const string SUPPLIER_CODE = "SP1"; const string SITE_CODE = "SITE001"; const string SHIPPING_ADDRESS = "MALABE"; const double TOTAL_COST = 2000.00; const string STATUS = "PENDING"; string[] ITEMS = { "IT001", "IT001", "IT002", "IT002", "IT002", "IT003" }; using (var context = new ProcurementDbContext(ContextOptions)) { PurchaseOrdersController ordersController = new PurchaseOrdersController(context); var order = new PurchaseOrderDTO { SiteManagerId = SITE_MANAGER_ID, SupplierCode = SUPPLIER_CODE, SiteCode = SITE_CODE, ShippingAddress = SHIPPING_ADDRESS, TotalCost = TOTAL_COST, OrderStatus = STATUS, ItemIds = ITEMS }; var result = await ordersController.PostPurchaseOrder(order); var viewResult = Assert.IsType <ActionResult <PurchaseOrder> >(result); var actionResult = Assert.IsType <CreatedAtActionResult>(viewResult.Result); var model = Assert.IsType <PurchaseOrder>(actionResult.Value); Assert.Equal(ORDER, model.OrderReference); } }
public async Task PostPurchaseOrder_ReturnBadRequest_IdExist() { //Arrange PurchaseOrderViewModel purchaseOrderViewModel = new PurchaseOrderViewModel() { Id = 1, CustomerId = 1, EmployeeId = 1 }; _mockrepo.Setup(repo => repo.PurchaseOrder.GetPurchaseOrderById(purchaseOrderViewModel.Id)) .ReturnsAsync(GetTestPurchaseOrders().FirstOrDefault( c => c.Id == purchaseOrderViewModel.Id)); //Act var result = await _controller.PostPurchaseOrder(purchaseOrderViewModel); //Assert var badResult = Assert.IsType <BadRequestObjectResult>(result); badResult.Value.Should().Be(LogMessage.ExistsId(nameof(PurchaseOrder), purchaseOrderViewModel.Id)); }