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