public async Task Update_Should_Fail_Only_Owner_Can_Update(string userIdRole) { // Arrange var projectDto = new ProjectDto { Id = 1, Name = "First Update", Description = "Some description for Project1" }; mockProjRepo.Setup(repo => repo.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(GetSampleProjects()[0]); mockProjectUserRepo.Setup(repo => repo.GetRoleOfMember("IsObserver", 1)).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("IsNone", It.IsAny <int>())).ReturnsAsync(AppUserRole.None); var projectBL = new ProjectBl(mockProjRepo.Object, mapper, mockProjectUserRepo.Object, mockSprintRepo.Object); // Act var result = projectBL.UpdateAsync(projectDto, userIdRole); // Assert mockProjRepo.Verify(r => r.UpdateAsync(It.IsAny <Project>()), Times.Never); await Assert.ThrowsAsync <ForbiddenResponseException>(() => projectBL.UpdateAsync(projectDto, userIdRole)); }
public void Update_Should_Call_Once_UpdateAsync() { // Arrange var projectDto = new ProjectDto { Id = 1, Name = "First Update", Description = "Some description for Project1" }; mockProjRepo.Setup(repo => repo.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(GetSampleProjects()[0]); mockProjectUserRepo.Setup(repo => repo.GetRoleOfMember(It.IsAny <string>(), It.IsAny <int>())).ReturnsAsync(AppUserRole.Owner); var projectBL = new ProjectBl(mockProjRepo.Object, mapper, mockProjectUserRepo.Object, mockSprintRepo.Object); // Act var result = projectBL.UpdateAsync(projectDto, It.IsAny <string>()); // Assert mockProjRepo.Verify(r => r.UpdateAsync(It.IsAny <Project>()), Times.Once); Assert.IsType <ProjectResponse>(result.Result); Assert.True(result.Result.Success); }
public void UpdateAsync_Should_Not_Found(int projectId) { // Arrange string userId = It.IsAny <string>(); var projectDto = new ProjectDto { Id = projectId, Name = "First Update", Description = "Some description for Project1" }; 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 result = projectBL.UpdateAsync(projectDto, userId); // Assert Assert.IsType <ProjectResponse>(result.Result); Assert.False(result.Result.Success); Assert.Equal("Project not found", result.Result.Message); }