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