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