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