public async void BulkInsert_No_Errors() { AddressControllerMockFacade mock = new AddressControllerMockFacade(); var mockResponse = new CreateResponse <ApiAddressResponseModel>(new FluentValidation.Results.ValidationResult()); mockResponse.SetRecord(new ApiAddressResponseModel()); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiAddressRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiAddressResponseModel> >(mockResponse)); AddressController controller = new AddressController(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 <ApiAddressRequestModel>(); records.Add(new ApiAddressRequestModel()); 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 <ApiAddressResponseModel>; result.Should().NotBeEmpty(); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiAddressRequestModel>())); }
public async void BulkInsert_Errors() { AddressControllerMockFacade mock = new AddressControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiAddressServerResponseModel> >(null as ApiAddressServerResponseModel); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiAddressServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiAddressServerResponseModel> >(mockResponse.Object)); AddressController controller = new AddressController(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 <ApiAddressServerRequestModel>(); records.Add(new ApiAddressServerRequestModel()); 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 <ApiAddressServerRequestModel>())); }