public IActionResult PutInvoice([FromRoute] int deliveryOrderId, [FromBody] InvoiceFormDto form) { try { VerifyUser(); var id = _service.UpdateFromInvoice(deliveryOrderId, form); var result = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE).Ok(); return(NoContent()); } catch (Exception e) { var result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, result)); } }
public void PutInvoice_Return_InternalServerError() { //Setup Mock <IServiceProvider> serviceProviderMock = GetServiceProvider(); var service = new Mock <IGarmentDebtBalanceService>(); service .Setup(s => s.UpdateFromInvoice(It.IsAny <int>(), It.IsAny <InvoiceFormDto>())) .Throws(new Exception()); serviceProviderMock .Setup(serviceProvider => serviceProvider.GetService(typeof(IGarmentDebtBalanceService))) .Returns(service.Object); //Act InvoiceFormDto form = new InvoiceFormDto(); IActionResult response = GetController(serviceProviderMock).PutInvoice(1, form); //Assert int statusCode = this.GetStatusCode(response); Assert.Equal((int)HttpStatusCode.InternalServerError, statusCode); }