Beispiel #1
0
        public async void Create_Errors()
        {
            TestAllFieldTypeControllerMockFacade mock = new TestAllFieldTypeControllerMockFacade();

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

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

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiTestAllFieldTypeRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiTestAllFieldTypeResponseModel> >(mockResponse.Object));
            TestAllFieldTypeController controller = new TestAllFieldTypeController(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 ApiTestAllFieldTypeRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiTestAllFieldTypeRequestModel>()));
        }
        public async void Create_No_Errors()
        {
            TestAllFieldTypeControllerMockFacade mock = new TestAllFieldTypeControllerMockFacade();

            var mockResponse = ValidationResponseFactory <ApiTestAllFieldTypeServerResponseModel> .CreateResponse(null as ApiTestAllFieldTypeServerResponseModel);

            mockResponse.SetRecord(new ApiTestAllFieldTypeServerResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiTestAllFieldTypeServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiTestAllFieldTypeServerResponseModel> >(mockResponse));
            TestAllFieldTypeController controller = new TestAllFieldTypeController(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 ApiTestAllFieldTypeServerRequestModel());

            response.Should().BeOfType <CreatedResult>();
            (response as CreatedResult).StatusCode.Should().Be((int)HttpStatusCode.Created);
            var createResponse = (response as CreatedResult).Value as CreateResponse <ApiTestAllFieldTypeServerResponseModel>;

            createResponse.Record.Should().NotBeNull();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiTestAllFieldTypeServerRequestModel>()));
        }