Ejemplo n.º 1
0
        public async void Create_Errors()
        {
            ProductCategoryControllerMockFacade mock = new ProductCategoryControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiProductCategoryResponseModel> >(new FluentValidation.Results.ValidationResult());
            var mockRecord   = new ApiProductCategoryResponseModel();

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiProductCategoryRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiProductCategoryResponseModel> >(mockResponse.Object));
            ProductCategoryController controller = new ProductCategoryController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiProductCategoryRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiProductCategoryRequestModel>()));
        }