public void JSONGetProjectById_WhenCalled_ThenUsesId226() { //Assign Mock<IDisposableCollection> disposables = new Mock<IDisposableCollection>(); Project project = new Project() { Id = 226 }; project.Employees.Add(new ProjectToEmployee() { EmploeeRoleOnProject = new ProjectRole() { Id = 4 }, Employee = new Employee() { LastName = "John" } }); Mock<IProjectRepository> mockedIProjectRepository = new Mock<IProjectRepository>(); mockedIProjectRepository.Setup(repository => repository.Get(It.Is<int>(i => i == project.Id))).Returns(project); Mock<IUnitOfWork> mockedUoW = new Mock<IUnitOfWork>(); ProjectController projectController = new ProjectController(mockedIProjectRepository.Object, mockedUoW.Object, disposables.Object); //Act ActionResult result = projectController.Get(project.Id); //Assert Assert.NotNull(result); mockedIProjectRepository.VerifyAll(); }
public void JSONGetProjectById_When226NotExists_ThenReturnSuccessIsFalse() { //Assign Mock<IDisposableCollection> disposables = new Mock<IDisposableCollection>(); Mock<IProjectRepository> mockedIProjectRepository = new Mock<IProjectRepository>(); Mock<IUnitOfWork> mockedUoW = new Mock<IUnitOfWork>(); ProjectController projectController = new ProjectController(mockedIProjectRepository.Object, mockedUoW.Object, disposables.Object); //Act ActionResult result = projectController.Get(100); //Assert Assert.NotNull(result); bool success = (bool)((JsonResult)result).Data.GetType().GetProperty("success").GetValue(((JsonResult)result).Data); Assert.True(success == false); }