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