public void Get_WhenCalled_ReturnNoItems() { mock.Setup(repo => repo.GetAllItems(null)).Returns(emptyListItems.AsQueryable()); var controller = new FamilyController(mockChild.Object, mock.Object); var result = controller.Get(); Assert.IsAssignableFrom <IEnumerable <Family> >(result); Assert.Equal(emptyListItems.Count, result.ToList().Count); }
public async void Get_Not_Exists() { FamilyControllerMockFacade mock = new FamilyControllerMockFacade(); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiFamilyResponseModel>(null)); 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(); IActionResult response = await controller.Get(default(int)); response.Should().BeOfType <StatusCodeResult>(); (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound); mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void Get_Exists() { FamilyControllerMockFacade mock = new FamilyControllerMockFacade(); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new ApiFamilyServerResponseModel())); 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(); IActionResult response = await controller.Get(default(int)); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var record = (response as OkObjectResult).Value as ApiFamilyServerResponseModel; record.Should().NotBeNull(); mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>())); }