Example #1
0
 public async Task GetByIdAsync_Should_Fail_Access()
 {
     // Arrange
     mockProjRepo.Setup(repo => repo.GetByIdAsync(1)).ReturnsAsync(GetSampleProjects()[0]);
     mockProjectUserRepo.Setup(repo => repo.GetRoleOfMember(It.IsAny <string>(), It.IsAny <int>())).ReturnsAsync(AppUserRole.None);
     var projectBL = new ProjectBl(mockProjRepo.Object, mapper, mockProjectUserRepo.Object, mockSprintRepo.Object);
     // Act
     var resultFromBl = projectBL.GetByIdAsync(It.IsAny <int>(), It.IsAny <string>());
     // Assert
     await Assert.ThrowsAsync <ForbiddenResponseException>(() => projectBL.GetByIdAsync(It.IsAny <int>(), It.IsAny <string>()));
 }
Example #2
0
        public async Task GetByIdAsync_Should_Throw_NotFoundResponseException(int projectId)
        {
            string userId = It.IsAny <string>();

            // Arrange
            mockProjRepo.Setup(repo => repo.GetByIdAsync(projectId)).ReturnsAsync(null as Project);
            mockProjectUserRepo.Setup(repo => repo.GetRoleOfMember(userId, projectId)).ReturnsAsync(AppUserRole.Owner);
            var projectBL = new ProjectBl(mockProjRepo.Object, mapper, mockProjectUserRepo.Object, mockSprintRepo.Object);
            // Act
            var resultFromBl = projectBL.GetByIdAsync(projectId, userId);
            // Assert
            await Assert.ThrowsAsync <NotFoundResponseException>(() => projectBL.GetByIdAsync(projectId, userId));
        }
Example #3
0
        public void GetByIdAsync_Should_Work_Can_Access(string userIdRole)
        {
            // Arrange
            mockProjRepo.Setup(repo => repo.GetByIdAsync(1)).ReturnsAsync(GetSampleProjects()[0]);
            mockProjectUserRepo.Setup(repo => repo.GetRoleOfMember("IsObserver", It.IsAny <int>())).ReturnsAsync(AppUserRole.Observer);
            mockProjectUserRepo.Setup(repo => repo.GetRoleOfMember("IsDeveloper", It.IsAny <int>())).ReturnsAsync(AppUserRole.Developer);
            mockProjectUserRepo.Setup(repo => repo.GetRoleOfMember("IsScrumMaster", It.IsAny <int>())).ReturnsAsync(AppUserRole.ScrumMaster);
            mockProjectUserRepo.Setup(repo => repo.GetRoleOfMember("IsOwner", It.IsAny <int>())).ReturnsAsync(AppUserRole.Owner);
            var projectBL = new ProjectBl(mockProjRepo.Object, mapper, mockProjectUserRepo.Object, mockSprintRepo.Object);
            // Act
            var resultFromBl = projectBL.GetByIdAsync(1, userIdRole);

            // Assert
            mockProjRepo.Verify(r => r.GetByIdAsync(1), Times.Once);
        }
Example #4
0
        public void GetByIdAsync_Should_Call_Once_ReadAsync()
        {
            string userId    = It.IsAny <string>();
            int    projectId = 1;
            int    index     = projectId - 1;

            // Arrange
            mockProjRepo.Setup(repo => repo.GetByIdAsync(projectId)).ReturnsAsync(GetSampleProjects()[index]);
            mockProjectUserRepo.Setup(repo => repo.GetRoleOfMember(userId, projectId)).ReturnsAsync(AppUserRole.Owner);
            var projectBL = new ProjectBl(mockProjRepo.Object, mapper, mockProjectUserRepo.Object, mockSprintRepo.Object);
            // Act
            var resultFromBl = projectBL.GetByIdAsync(projectId, userId);
            // Assert
            var typeResult = Assert.IsType <Task <ProjectDto> >(resultFromBl);

            mockProjRepo.Verify(r => r.GetByIdAsync(projectId), Times.Once);
        }
Example #5
0
        public void GetByIdAsync_Should_Return_The_Same_Resault()
        {
            // Arrange
            string userId    = It.IsAny <string>();
            int    projectId = 1;
            int    index     = projectId - 1;

            mockProjRepo.Setup(repo => repo.GetByIdAsync(projectId)).ReturnsAsync(GetSampleProjects()[index]);
            mockProjectUserRepo.Setup(repo => repo.GetRoleOfMember(userId, projectId)).ReturnsAsync(AppUserRole.Owner);
            var projectBL = new ProjectBl(mockProjRepo.Object, mapper, mockProjectUserRepo.Object, mockSprintRepo.Object);
            // Act
            var resultFromBl = projectBL.GetByIdAsync(projectId, userId);

            // Assert
            Assert.Equal(GetSampleProjects()[index].Id, resultFromBl.Result.Id);
            Assert.Equal(GetSampleProjects()[index].Name, resultFromBl.Result.Name);
            Assert.Equal(GetSampleProjects()[index].Description, resultFromBl.Result.Description);
        }