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