Exemple #1
0
        public async Task AddToProjectBadRequestActiveStatus()
        {
            //Arrange
            List <UserProject> userProject = new List <UserProject>()
            {
                new UserProject {
                    UserId = 2, Status = "active"
                }
            };

            var user = new User {
                Id = 2, Nickname = "test"
            };
            var project = new Project {
                ProjectId = 1, Owner = 1, UserProjects = userProject
            };

            ProjectController controller = new ProjectController(mapperMock.Object, wrapperMock.Object);

            wrapperMock.Setup(w => w.UserRepository.GetUserByNick("test")).Returns(Task.FromResult(user));

            wrapperMock.Setup(w => w.ProjectRepository.GetProject(1)).Returns(Task.FromResult(project));

            //Act
            var action = await controller.AddToProject(1, 1, "test") as BadRequestObjectResult;

            //Assert
            Assert.Equal(400, action.StatusCode);
            Assert.Contains("already belong", action.Value.ToString());
        }
Exemple #2
0
        public async Task AddToProjectNotFoundUserStatus()
        {
            //Arrange
            ProjectController controller = new ProjectController(mapperMock.Object, wrapperMock.Object);

            wrapperMock.Setup(w => w.UserRepository.GetUserByNick("test")).Returns(Task.FromResult((User)null));

            //Act
            var action = await controller.AddToProject(1, It.IsAny <int>(), "test") as NotFoundObjectResult;

            //Assert
            Assert.Equal(404, action.StatusCode);
            Assert.NotNull(action.Value);
        }
Exemple #3
0
        public async Task AddToProjectNotFoundProjectStatus()
        {
            //Arrange
            var user = new User {
                Id = 1, Nickname = "test"
            };

            ProjectController controller = new ProjectController(mapperMock.Object, wrapperMock.Object);

            wrapperMock.Setup(w => w.UserRepository.GetUserByNick("test")).Returns(Task.FromResult(user));

            wrapperMock.Setup(w => w.ProjectRepository.GetProject(1)).Returns(Task.FromResult((Project)null));

            //Act
            var action = await controller.AddToProject(1, 1, "test") as NotFoundObjectResult;

            //Assert
            Assert.Equal(404, action.StatusCode);
            Assert.NotNull(action.Value);
        }
Exemple #4
0
        public async Task AddToProjectUnauthorizedOwnerStatus()
        {
            //Arrange
            var user = new User {
                Id = 1, Nickname = "test"
            };
            var project = new Project {
                ProjectId = 1, Owner = 2
            };

            ProjectController controller = new ProjectController(mapperMock.Object, wrapperMock.Object);

            wrapperMock.Setup(w => w.UserRepository.GetUserByNick("test")).Returns(Task.FromResult(user));

            wrapperMock.Setup(w => w.ProjectRepository.GetProject(1)).Returns(Task.FromResult(project));

            //Act
            var action = await controller.AddToProject(1, 1, "test") as UnauthorizedResult;

            //Assert
            Assert.Equal(401, action.StatusCode);
        }
Exemple #5
0
        public async Task AddToProjectBadRequestAlreadyBelongStatus()
        {
            //Arrange
            List <UserProject> userProject = new List <UserProject>()
            {
                new UserProject {
                    UserId = 2, Status = null
                }
            };

            var addUserProject = new UserProject {
                ProjectId = 1, UserId = 2, Status = "invited"
            };
            var user = new User {
                Id = 2, Nickname = "test"
            };
            var project = new Project {
                ProjectId = 1, Owner = 1, UserProjects = userProject
            };

            ProjectController controller = new ProjectController(mapperMock.Object, wrapperMock.Object);

            wrapperMock.Setup(w => w.UserRepository.GetUserByNick("test")).Returns(Task.FromResult(user));

            wrapperMock.Setup(w => w.ProjectRepository.GetProject(1)).Returns(Task.FromResult(project));

            wrapperMock.Setup(w => w.ProjectRepository.Add(userProject));

            wrapperMock.Setup(w => w.SaveAll()).Returns(Task.FromResult(false));

            //Act
            var action = await controller.AddToProject(1, 1, "test") as BadRequestObjectResult;

            //Assert
            Assert.Equal(400, action.StatusCode);
            Assert.NotNull(action.Value);
        }