public async void Create_Errors() { PipelineStepStatusControllerMockFacade mock = new PipelineStepStatusControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiPipelineStepStatusServerResponseModel> >(null as ApiPipelineStepStatusServerResponseModel); var mockRecord = new ApiPipelineStepStatusServerResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiPipelineStepStatusServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiPipelineStepStatusServerResponseModel> >(mockResponse.Object)); PipelineStepStatusController controller = new PipelineStepStatusController(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 ApiPipelineStepStatusServerRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiPipelineStepStatusServerRequestModel>())); }
public async void Create_No_Errors() { PipelineStepStatusControllerMockFacade mock = new PipelineStepStatusControllerMockFacade(); var mockResponse = ValidationResponseFactory <ApiPipelineStepStatusServerResponseModel> .CreateResponse(null as ApiPipelineStepStatusServerResponseModel); mockResponse.SetRecord(new ApiPipelineStepStatusServerResponseModel()); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiPipelineStepStatusServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiPipelineStepStatusServerResponseModel> >(mockResponse)); PipelineStepStatusController controller = new PipelineStepStatusController(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 ApiPipelineStepStatusServerRequestModel()); response.Should().BeOfType <CreatedResult>(); (response as CreatedResult).StatusCode.Should().Be((int)HttpStatusCode.Created); var createResponse = (response as CreatedResult).Value as CreateResponse <ApiPipelineStepStatusServerResponseModel>; createResponse.Record.Should().NotBeNull(); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiPipelineStepStatusServerRequestModel>())); }