public async void BulkInsert_No_Errors() { TestAllFieldTypeControllerMockFacade mock = new TestAllFieldTypeControllerMockFacade(); var mockResponse = new CreateResponse <ApiTestAllFieldTypeResponseModel>(new FluentValidation.Results.ValidationResult()); mockResponse.SetRecord(new ApiTestAllFieldTypeResponseModel()); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiTestAllFieldTypeRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiTestAllFieldTypeResponseModel> >(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(); var records = new List <ApiTestAllFieldTypeRequestModel>(); records.Add(new ApiTestAllFieldTypeRequestModel()); 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 List <ApiTestAllFieldTypeResponseModel>; result.Should().NotBeEmpty(); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiTestAllFieldTypeRequestModel>())); }
public async void BulkInsert_Errors() { TestAllFieldTypeControllerMockFacade mock = new TestAllFieldTypeControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiTestAllFieldTypeServerResponseModel> >(null as ApiTestAllFieldTypeServerResponseModel); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiTestAllFieldTypeServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiTestAllFieldTypeServerResponseModel> >(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(); var records = new List <ApiTestAllFieldTypeServerRequestModel>(); records.Add(new ApiTestAllFieldTypeServerRequestModel()); 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 <ApiTestAllFieldTypeServerRequestModel>())); }