public void Cannot_Assign_Users_To_Non_Existing_Project() { //Arrange var eventBusMock = new Mock <IEventBus>(); var tempDataMock = new Mock <ITempDataDictionary>(); var messageSenderMock = new Mock <IMessageSender>(); var projectRepositoryMock = new Mock <IProjectRepository>(); projectRepositoryMock.Setup(m => m.GetById(It.IsAny <int>())).Returns(() => null); var getProjectFactoryMock = new Mock <IGetProjectWithAllFactory>(); getProjectFactoryMock.Setup(m => m.Create()).Returns(new GetProjectWithAll(projectRepositoryMock.Object)); //Act var target = new ProjectsController(eventWatcher.Object, logger.Object, eventBus.Object, null, null, null, null, null, null, messageSenderMock.Object, null, getProjectFactoryMock.Object, null); target.TempData = tempDataMock.Object; var targetResult = (ViewResult)target.AsignUsersToProject(1, new[] { 1, 2 }); //Assert Assert.True(targetResult.ViewName == "ErrorPage"); }
public void Can_Assign_No_Users_To_Project() { //Arrange var model = new Project { Id = 1, Status = ProjectStatus.Active, Name = "first" }; var tempDataMock = new Mock <ITempDataDictionary>(); var messageSenderMock = new Mock <IMessageSender>(); var projectRepositoryMock = new Mock <IProjectRepository>(); projectRepositoryMock.Setup(m => m.GetById(It.IsAny <int>())).Returns(model); projectRepositoryMock.Setup(m => m.GetAllUsersFromProject(It.IsAny <int>())).Returns(new List <User>()); var userRepositoryMock = new Mock <IUserRepository>(); var projectMock = new Mock <IGetProjectFactory>(); projectMock.Setup(m => m.Create()).Returns(new GetProject(projectRepositoryMock.Object)); var setDefaultUserCustomDataMock = new Mock <ISetDefaultUserCustomDataBasedOnProject>(); var getUserFactoryMock = new Mock <IGetUserFactory>(); var getProjectFactoryMock = new Mock <IGetProjectWithAllFactory>(); getProjectFactoryMock.Setup(m => m.Create()).Returns(new GetProjectWithAll(projectRepositoryMock.Object)); var factoryMock = new Mock <IAssignUserFactory>(); factoryMock.Setup(m => m.Create()) .Returns(new AssignUser(projectRepositoryMock.Object, eventBus.Object, userRepositoryMock.Object, setDefaultUserCustomDataMock.Object)); //Act var target = new ProjectsController(eventWatcher.Object, logger.Object, eventBus.Object, null, projectMock.Object, null, null, null, factoryMock.Object, messageSenderMock.Object, getUserFactoryMock.Object, getProjectFactoryMock.Object, null); target.TempData = tempDataMock.Object; var targetResult = (RedirectToActionResult)target.AsignUsersToProject(1, new int[] {}); //Assert Assert.True(targetResult.ActionName == "GetById"); Assert.True((int)targetResult.RouteValues["id"] == 1); Assert.True(model.ProjectUsers == null); }
public void Cannot_Assign_Null_As_Users_To_Project() { //Arrange var model = new Project { Id = 1, Status = ProjectStatus.Active, Name = "first" }; var tempDataMock = new Mock <ITempDataDictionary>(); var messageSenderMock = new Mock <IMessageSender>(); var projectRepositoryMock = new Mock <IProjectRepository>(); projectRepositoryMock.Setup(m => m.GetById(It.IsAny <int>())).Returns(model); projectRepositoryMock.Setup(m => m.GetAllUsersFromProject(It.IsAny <int>())).Returns(new List <User>()); var usersRepository = new Mock <IUserRepository>(); var getUserFactoryMock = new Mock <IGetUserFactory>(); var getProjectFactoryMock = new Mock <IGetProjectWithAllFactory>(); getProjectFactoryMock.Setup(m => m.Create()).Returns(new GetProjectWithAll(projectRepositoryMock.Object)); var factoryMock = new Mock <IAssignUserFactory>(); factoryMock.Setup(m => m.Create()) .Returns(new AssignUser(projectRepositoryMock.Object, eventBus.Object, usersRepository.Object, null)); //Act var target = new ProjectsController(eventWatcher.Object, logger.Object, eventBus.Object, null, null, null, null, null, factoryMock.Object, messageSenderMock.Object, getUserFactoryMock.Object, getProjectFactoryMock.Object, null); target.TempData = tempDataMock.Object; var targetResult = (ViewResult)target.AsignUsersToProject(1, null); //Assert Assert.True(targetResult.ViewName == "ErrorPage"); }