public async void BulkInsert_No_Errors() { OffCapabilityControllerMockFacade mock = new OffCapabilityControllerMockFacade(); var mockResponse = ValidationResponseFactory <ApiOffCapabilityServerResponseModel> .CreateResponse(null as ApiOffCapabilityServerResponseModel); mockResponse.SetRecord(new ApiOffCapabilityServerResponseModel()); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiOffCapabilityServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiOffCapabilityServerResponseModel> >(mockResponse)); OffCapabilityController controller = new OffCapabilityController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); var records = new List <ApiOffCapabilityServerRequestModel>(); records.Add(new ApiOffCapabilityServerRequestModel()); IActionResult response = await controller.BulkInsert(records); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var result = (response as OkObjectResult).Value as CreateResponse <List <ApiOffCapabilityServerResponseModel> >; result.Success.Should().BeTrue(); result.Record.Should().NotBeEmpty(); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiOffCapabilityServerRequestModel>())); }
public async void BulkInsert_Errors() { OffCapabilityControllerMockFacade mock = new OffCapabilityControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiOffCapabilityServerResponseModel> >(null as ApiOffCapabilityServerResponseModel); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiOffCapabilityServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiOffCapabilityServerResponseModel> >(mockResponse.Object)); OffCapabilityController controller = new OffCapabilityController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); var records = new List <ApiOffCapabilityServerRequestModel>(); records.Add(new ApiOffCapabilityServerRequestModel()); IActionResult response = await controller.BulkInsert(records); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiOffCapabilityServerRequestModel>())); }