public async void BulkInsert_No_Errors() { FamilyControllerMockFacade mock = new FamilyControllerMockFacade(); var mockResponse = ValidationResponseFactory <ApiFamilyServerResponseModel> .CreateResponse(null as ApiFamilyServerResponseModel); mockResponse.SetRecord(new ApiFamilyServerResponseModel()); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiFamilyServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiFamilyServerResponseModel> >(mockResponse)); FamilyController controller = new FamilyController(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 <ApiFamilyServerRequestModel>(); records.Add(new ApiFamilyServerRequestModel()); 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 <ApiFamilyServerResponseModel> >; result.Success.Should().BeTrue(); result.Record.Should().NotBeEmpty(); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiFamilyServerRequestModel>())); }
public async void BulkInsert_Errors() { FamilyControllerMockFacade mock = new FamilyControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiFamilyResponseModel> >(new FluentValidation.Results.ValidationResult()); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiFamilyRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiFamilyResponseModel> >(mockResponse.Object)); FamilyController controller = new FamilyController(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 <ApiFamilyRequestModel>(); records.Add(new ApiFamilyRequestModel()); 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 <ApiFamilyRequestModel>())); }