Esempio n. 1
0
        public async Task <IActionResult> SendToAccounting([FromBody] SendToVerificationAccountingForm form)
        {
            try
            {
                VerifyUser();
                _validateService.Validate(form);

                var id = await _service.SendToAccounting(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 <IGarmentPurchasingExpeditionService>();
            var dto     = new SendToVerificationAccountingForm();

            service
            .Setup(s => s.SendToAccounting(It.IsAny <SendToVerificationAccountingForm>()))
            .ThrowsAsync(new Exception());

            serviceProviderMock
            .Setup(serviceProvider => serviceProvider.GetService(typeof(IGarmentPurchasingExpeditionService)))
            .Returns(service.Object);

            //Act
            IActionResult response = await GetController(serviceProviderMock).SendToAccounting(dto);

            //Assert
            int statusCode = this.GetStatusCode(response);

            Assert.Equal((int)HttpStatusCode.InternalServerError, statusCode);
        }