public async Task <IActionResult> SendToVerification([FromBody] SendToVerificationAccountingFormDto form) { try { VerifyUser(); _validateService.Validate(form); var id = await _service.SendToVerification(form); var result = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE).Ok(); return(Created(string.Concat(Request.Path, "/", id), result)); } catch (ServiceValidationException e) { var result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE).Fail(e); return(BadRequest(result)); } 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 async Task SendToAccounting_Return_InternalServerError() { //Setup Mock <IServiceProvider> serviceProviderMock = GetServiceProvider(); var service = new Mock <IGarmentDispositionExpeditionService>(); service .Setup(s => s.SendToAccounting(It.IsAny <SendToVerificationAccountingFormDto>())) .ThrowsAsync(new Exception()); serviceProviderMock .Setup(serviceProvider => serviceProvider.GetService(typeof(IGarmentDispositionExpeditionService))) .Returns(service.Object); //Act SendToVerificationAccountingFormDto formDto = new SendToVerificationAccountingFormDto() { Items = new List <FormItemDto>() { new FormItemDto() } }; IActionResult response = await GetController(serviceProviderMock).SendToAccounting(formDto);; //Assert int statusCode = this.GetStatusCode(response); Assert.Equal((int)HttpStatusCode.InternalServerError, statusCode); }