public async void Create_No_Errors() { TenantVariableControllerMockFacade mock = new TenantVariableControllerMockFacade(); var mockResponse = new CreateResponse <ApiTenantVariableResponseModel>(new FluentValidation.Results.ValidationResult()); mockResponse.SetRecord(new ApiTenantVariableResponseModel()); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiTenantVariableRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiTenantVariableResponseModel> >(mockResponse)); TenantVariableController controller = new TenantVariableController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Create(new ApiTenantVariableRequestModel()); response.Should().BeOfType <CreatedResult>(); (response as CreatedResult).StatusCode.Should().Be((int)HttpStatusCode.Created); var createResponse = (response as CreatedResult).Value as CreateResponse <ApiTenantVariableResponseModel>; createResponse.Record.Should().NotBeNull(); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiTenantVariableRequestModel>())); }
public async void BulkInsert_Errors() { TenantVariableControllerMockFacade mock = new TenantVariableControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiTenantVariableResponseModel> >(new FluentValidation.Results.ValidationResult()); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiTenantVariableRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiTenantVariableResponseModel> >(mockResponse.Object)); TenantVariableController controller = new TenantVariableController(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 <ApiTenantVariableRequestModel>(); records.Add(new ApiTenantVariableRequestModel()); 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 <ApiTenantVariableRequestModel>())); }