示例#1
0
        public async Task CreateProject_WithValidModel_ShouldReturnValidProject()
        {
            // ARRANGE
            this.repositoryAccessors.Setup(repositoryAccessor => repositoryAccessor.ProjectRepository).Returns(() => this.projectRepository.Object);
            this.repositoryAccessors.Setup(accessor => accessor.Context).Returns(FakeTimesheetContext.GetFakeTimesheetContext());

            this.projectRepository
            .Setup(projectRepo => projectRepo.CreateProject(It.IsAny <Project>()))
            .Returns(TestData.Project);
            this.userService
            .Setup(service => service.GetReporteesAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(TestData.Reportees.AsEnumerable()));
            this.timesheetContext
            .Setup(context => context.SaveChangesAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(1));

            var managerId = Guid.NewGuid();

            // ACT
            var result = await this.projectHelper.CreateProjectAsync(TestData.ProjectDTO, managerId);

            // ASSERT
            Assert.AreEqual(TestData.Project.CreatedBy, result.CreatedBy);
            this.projectRepository.Verify(projectRepo => projectRepo.CreateProject(It.IsAny <Project>()), Times.AtLeastOnce());
        }
        public async Task UpdateProject_WithValidModel_ShouldReturnTrue()
        {
            // ARRANGE
            this.repositoryAccessors.Setup(repositoryAccessor => repositoryAccessor.ProjectRepository).Returns(() => this.projectRepository.Object);
            this.repositoryAccessors.Setup(accessor => accessor.Context).Returns(FakeTimesheetContext.GetFakeTimesheetContext());
            this.projectRepository
            .Setup(projectRepo => projectRepo.GetProjectByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()))
            .Returns(Task.FromResult(this.project));
            this.projectRepository
            .Setup(projectRepo => projectRepo.Update(It.IsAny <Project>()))
            .Returns(this.project);
            this.timesheetContext
            .Setup(context => context.SaveChangesAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(1));

            var managerId = this.project.CreatedBy;

            // ACT
            var result = await this.projectHelper.UpdateProjectAsync(TestData.ProjectUpdateDTO, managerId);

            // ASSERT
            Assert.IsTrue(result);
            this.projectRepository.Verify(projectRepo => projectRepo.GetProjectByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.AtLeastOnce());
            this.projectRepository.Verify(projectRepo => projectRepo.Update(It.IsAny <Project>()), Times.AtLeastOnce());
        }
示例#3
0
        public async Task SubmitTimesheets_UserTimesheetsProvidedWithUnassignedProject_TimesheetsSubmitUnsuccessful()
        {
            var projectRepository   = new Mock <IProjectRepository>();
            var timesheetRepository = new Mock <ITimesheetRepository>();

            projectRepository
            .Setup(x => x.GetProjectsAsync(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <Guid>()))
            .Returns(Task.FromResult(TestData.Projects.AsEnumerable()));

            timesheetRepository
            .Setup(x => x.GetTimesheetsAsync(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <Guid>()))
            .Returns(Task.FromResult(TestData.Timesheets));

            timesheetRepository
            .Setup(x => x.FindAsync(It.IsAny <Expression <Func <TimesheetEntity, bool> > >()))
            .Returns(Task.FromResult(TestData.Timesheets.AsEnumerable()));

            this.repositoryAccessors.Setup(x => x.ProjectRepository).Returns(projectRepository.Object);
            this.repositoryAccessors.Setup(x => x.TimesheetRepository).Returns(timesheetRepository.Object);
            this.repositoryAccessors.Setup(x => x.Context).Returns(FakeTimesheetContext.GetFakeTimesheetContext());

            var result = await this.timesheetHelper.SubmitTimesheetsAsync(DateTime.UtcNow, TestData.UserTimesheets.AsEnumerable(), Guid.Parse("e9be1d47-2707-4dfc-b2a9-e62648c3a04e"));

            Assert.IsTrue(result.StatusCode == HttpStatusCode.BadRequest);

            // Ensure nothing has changed in database.
            Assert.IsTrue((IEnumerable <TimesheetDTO>)result.Response == Enumerable.Empty <TimesheetDTO>());
        }
示例#4
0
        public async Task SaveTimesheetsAsync_WithHoursExceedingWeeklyLimit_ShouldRetunEmptyList()
        {
            // ARRANGE
            var timesheetToSave = new List <UserTimesheet>
            {
                new UserTimesheet
                {
                    TimesheetDate  = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 5),
                    ProjectDetails = new List <ProjectDetails>
                    {
                        new ProjectDetails
                        {
                            Id               = Guid.Parse("bfb77fc0-12a9-4250-a5fb-e52ddc48ff86"),
                            Title            = "TimesheetEntity App",
                            StartDate        = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 2),
                            EndDate          = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 28),
                            TimesheetDetails = new List <TimesheetDetails>
                            {
                                new TimesheetDetails
                                {
                                    Hours           = 8,
                                    IsAddedByMember = false,
                                    TaskId          = Guid.Parse("2dcf17b4-9bc7-488a-a59c-b0d12b14782d"),
                                    TaskTitle       = "Development",
                                    StartDate       = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 2),
                                    EndDate         = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 28),
                                },
                            },
                        },
                    },
                },
            };

            this.repositoryAccessors.Setup(accessor => accessor.Context).Returns(FakeTimesheetContext.GetFakeTimesheetContext());
            this.repositoryAccessors.Setup(repositoryAccessor => repositoryAccessor.TimesheetRepository).Returns(() => this.timesheetRepository.Object);
            this.repositoryAccessors.Setup(repositoryAccessor => repositoryAccessor.ProjectRepository).Returns(() => this.projectRepository.Object);
            this.repositoryAccessors.Setup(repositoryAccessor => repositoryAccessor.SaveChangesAsync()).Returns(() => Task.FromResult(1));
            this.projectRepository
            .Setup(repository => repository.GetProjectsAsync(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <Guid>()))
            .Returns(Task.FromResult(this.projects.AsEnumerable()));
            this.timesheetRepository
            .Setup(repository => repository.GetTimesheetsOfUser(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <Guid>()))
            .Returns(TestData.ApprovedTimesheets);
            this.timesheetRepository
            .Setup(repository => repository.GetTimesheets(It.IsAny <DateTime>(), It.IsAny <List <Guid> >(), It.IsAny <Guid>()))
            .Returns(Enumerable.Empty <TimesheetEntity>);
            this.timesheetRepository
            .Setup(repository => repository.Add(It.IsAny <TimesheetEntity>()))
            .Returns(new TimesheetEntity());

            // ACT
            var result = await this.timesheetHelper.SaveTimesheetsAsync(timesheetToSave, DateTime.UtcNow, Guid.Parse("d3d964ae-2979-4dac-b1e0-6c1b936c2640"));

            // ASSERT
            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count);
        }
示例#5
0
        public async Task SaveTimesheets_UserTimesheetsProvided_TimesheetsSaveSuccessful()
        {
            var projectRepository   = new Mock <IProjectRepository>();
            var timesheetRepository = new Mock <ITimesheetRepository>();

            projectRepository
            .Setup(x => x.GetProjectsAsync(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <Guid>()))
            .Returns(Task.FromResult(TestData.Projects.AsEnumerable()));

            timesheetRepository
            .Setup(x => x.GetTimesheetsAsync(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <Guid>()))
            .Returns(Task.FromResult(TestData.Timesheets));

            this.repositoryAccessors.Setup(x => x.ProjectRepository).Returns(projectRepository.Object);
            this.repositoryAccessors.Setup(x => x.TimesheetRepository).Returns(timesheetRepository.Object);
            this.repositoryAccessors.Setup(x => x.SaveChangesAsync()).Returns(Task.FromResult(1));
            this.repositoryAccessors.Setup(x => x.Context).Returns(FakeTimesheetContext.GetFakeTimesheetContext());

            var userTimesheetsToSave = new List <UserTimesheet>
            {
                new UserTimesheet
                {
                    TimesheetDate  = new DateTime(2021, 01, 24),
                    ProjectDetails = new List <ProjectDetails>
                    {
                        new ProjectDetails
                        {
                            StartDate        = new DateTime(2021, 01, 02),
                            EndDate          = new DateTime(2021, 02, 10),
                            Id               = Guid.Parse("bfb77fc0-12a9-4250-a5fb-e52ddc48ff86"),
                            TimesheetDetails = new List <TimesheetDetails>
                            {
                                new TimesheetDetails
                                {
                                    Hours           = 6,
                                    ManagerComments = string.Empty,
                                    TaskId          = Guid.Parse("1eec371f-edbe-4ad1-be1d-d4cd3515540e"),
                                    TaskTitle       = "Task",
                                },
                            },
                        },
                    },
                },
            };

            var result = await this.timesheetHelper.SaveTimesheetsAsync(userTimesheetsToSave, DateTime.UtcNow, Guid.Parse("e9be1d47-2707-4dfc-b2a9-e62648c3a04e"));

            timesheetRepository.Verify(x => x.Add(It.IsAny <TimesheetEntity>()), Times.AtLeastOnce());
            Assert.IsNotNull(result.Response);

            var targetDatesToSave = userTimesheetsToSave.Select(x => x.TimesheetDate);
            var savedTimesheets   = result.Response as IEnumerable <TimesheetDTO>;
            var savedTargetDates  = savedTimesheets.Select(x => x.TimesheetDate);

            // Ensure whether all Timesheets saved.
            Assert.IsTrue(savedTargetDates.All(savedTargetDate => targetDatesToSave.Contains(savedTargetDate)));
        }
        public async Task CreateProject_WithValidModel_ShouldReturnValidProject()
        {
            // ARRANGE
            var projectDTO = new ProjectDTO
            {
                BillableHours    = 50,
                NonBillableHours = 10,
                ClientName       = "Samuel,",
                StartDate        = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1),
                EndDate          = new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(1).Month, 28),
                Id      = Guid.Parse("1eec371f-edbe-4ad1-be1d-d4cd3515541e"),
                Title   = "Project 1",
                Members = new List <MemberDTO>
                {
                    new MemberDTO
                    {
                        Id         = Guid.NewGuid(),
                        IsBillable = true,
                        ProjectId  = Guid.NewGuid(),
                        UserId     = Guid.Parse("1ce072c1-1b87-4912-bb60-307698e6874e"),
                    },
                },
                Tasks = new List <TaskDTO>
                {
                    new TaskDTO
                    {
                        Id        = Guid.NewGuid(),
                        ProjectId = Guid.NewGuid(),
                        Title     = "TaskEntity",
                    },
                },
            };

            this.repositoryAccessors.Setup(repositoryAccessor => repositoryAccessor.ProjectRepository).Returns(() => this.projectRepository.Object);
            this.repositoryAccessors.Setup(accessor => accessor.Context).Returns(FakeTimesheetContext.GetFakeTimesheetContext());

            this.projectRepository
            .Setup(projectRepo => projectRepo.CreateProject(It.IsAny <Project>()))
            .Returns(this.project);
            this.userService
            .Setup(service => service.GetMyReporteesAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(TestData.Reportees.AsEnumerable()));
            this.timesheetContext
            .Setup(context => context.SaveChangesAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(1));

            var managerId = Guid.NewGuid();

            // ACT
            var result = await this.projectHelper.CreateProjectAsync(projectDTO, managerId);

            // ASSERT
            Assert.AreEqual(this.project.ClientName, result.ClientName);
            this.projectRepository.Verify(projectRepo => projectRepo.CreateProject(It.IsAny <Project>()), Times.AtLeastOnce());
        }
        public async Task CreateTasks_WhenFailureAtDatabase_ShouldReturnFalse()
        {
            // ARRANGE
            this.repositoryAccessors.Setup(repositoryAccessor => repositoryAccessor.TaskRepository).Returns(() => this.taskRepository.Object);
            this.taskRepository.Setup(taskRepo => taskRepo.CreateTasksAsync(It.IsAny <IEnumerable <TaskEntity> >())).Returns(Task.FromResult(true));
            this.repositoryAccessors.Setup(accessor => accessor.Context).Returns(FakeTimesheetContext.GetFakeTimesheetContext());
            this.repositoryAccessors
            .Setup(repositoryAccessor => repositoryAccessor.SaveChangesAsync())
            .Returns(Task.FromResult(0));

            // ACT
            var isAdded = await this.projectHelper.AddProjectTasksAsync(Guid.NewGuid(), TestData.TaskDTOs);

            // ASSERT
            Assert.IsFalse(isAdded);
            this.taskRepository.Verify(taskRepo => taskRepo.CreateTasksAsync(It.IsAny <IEnumerable <TaskEntity> >()), Times.AtLeastOnce());
        }
        public async Task ApproveOrRejectTimesheets_WhenFailureAtDatabase_ShouldRetunFalse()
        {
            // ARRANGE
            this.repositoryAccessors.Setup(repositoryAccessor => repositoryAccessor.TimesheetRepository).Returns(() => this.timesheetRepository.Object);
            this.repositoryAccessors.Setup(x => x.Context).Returns(FakeTimesheetContext.GetFakeTimesheetContext());
            this.repositoryAccessors
            .Setup(accessor => accessor.SaveChangesAsync())
            .Returns(Task.FromResult(0));

            var managerId = Guid.NewGuid();

            // ACT
            var result = await this.timesheetHelper.ApproveOrRejectTimesheetsAsync(TestData.SubmittedTimesheets, TestData.RequestApprovalDTOs, TimesheetStatus.Approved);

            // ASSERT
            Assert.IsFalse(result);
            this.timesheetRepository.Verify(timesheetRepo => timesheetRepo.Update(It.IsAny <List <TimesheetEntity> >()), Times.AtLeastOnce());
        }
        public async Task AddExistingUsers_WithCorrectModel_ShouldReturnTrue()
        {
            // ARRANGE
            this.repositoryAccessors.Setup(repositoryAccessor => repositoryAccessor.MemberRepository).Returns(() => this.memberRepository.Object);
            this.repositoryAccessors.Setup(accessor => accessor.Context).Returns(FakeTimesheetContext.GetFakeTimesheetContext());
            this.memberRepository
            .Setup(memberRepo => memberRepo.GetAllMembers(It.IsAny <Guid>()))
            .Returns(TestData.Members.ToList());
            this.memberRepository
            .Setup(memberRepo => memberRepo.UpdateMembers(It.IsAny <List <Member> >()));
            this.repositoryAccessors
            .Setup(repositoryAccessor => repositoryAccessor.SaveChangesAsync())
            .Returns(Task.FromResult(TestData.Members.Count()));

            // ACT
            var resultResponse = await this.projectHelper.AddProjectMembersAsync(Guid.NewGuid(), TestData.ExistingMembers);

            // ASSERT
            Assert.IsTrue(resultResponse);
            this.memberRepository.Verify(memberRepo => memberRepo.UpdateMembers(It.IsAny <IEnumerable <Member> >()), Times.AtLeastOnce());
        }
        public async Task AddProjectMembers_WhenFailureAtDatabase_ShouldReturnFalse()
        {
            // ARRANGE
            this.repositoryAccessors.Setup(repositoryAccessor => repositoryAccessor.MemberRepository).Returns(() => this.memberRepository.Object);
            this.repositoryAccessors.Setup(accessor => accessor.Context).Returns(FakeTimesheetContext.GetFakeTimesheetContext());
            this.memberRepository
            .Setup(memberRepo => memberRepo.GetAllMembers(It.IsAny <Guid>()))
            .Returns(TestData.Members.ToList());
            this.memberRepository
            .Setup(memberRepo => memberRepo.AddUsersAsync(It.IsAny <List <Member> >()))
            .Returns(Task.FromResult(true));
            this.repositoryAccessors
            .Setup(repositoryAccessor => repositoryAccessor.SaveChangesAsync())
            .Returns(Task.FromResult(0));

            // ACT
            var resultResponse = await this.projectHelper.AddProjectMembersAsync(Guid.NewGuid(), TestData.MembersDTO);

            // ASSERT
            Assert.IsFalse(resultResponse);
            this.memberRepository.Verify(memberRepo => memberRepo.AddUsersAsync(It.IsAny <IEnumerable <Member> >()), Times.AtLeastOnce());
        }
        public async Task UpdateProject_WhenFailureAtDatabase_ShouldReturnFalse()
        {
            // ARRANGE
            this.repositoryAccessors.Setup(repositoryAccessor => repositoryAccessor.ProjectRepository).Returns(() => this.projectRepository.Object);
            this.repositoryAccessors.Setup(accessor => accessor.Context).Returns(FakeTimesheetContext.GetFakeTimesheetContext());
            this.projectRepository
            .Setup(projectRepo => projectRepo.GetProjectByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()))
            .Returns(Task.FromResult(this.project));
            this.repositoryAccessors
            .Setup(repositoryAccessor => repositoryAccessor.SaveChangesAsync())
            .Returns(Task.FromResult(0));

            var managerId = Guid.NewGuid();

            // ACT
            var result = await this.projectHelper.UpdateProjectAsync(TestData.ProjectUpdateDTO, managerId);

            // ASSERT
            Assert.IsFalse(result);
            this.projectRepository.Verify(projectRepo => projectRepo.GetProjectByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.AtLeastOnce());
            this.projectRepository.Verify(projectRepo => projectRepo.Update(It.IsAny <Project>()), Times.AtLeastOnce());
        }
        public async Task DeleteTasks_WhenFailureAtDatabase_ShouldReturnFalse()
        {
            // ARRANGE
            this.repositoryAccessors.Setup(repositoryAccessor => repositoryAccessor.TaskRepository).Returns(() => this.taskRepository.Object);
            this.repositoryAccessors.Setup(accessor => accessor.Context).Returns(FakeTimesheetContext.GetFakeTimesheetContext());
            this.taskRepository
            .Setup(taskRepo => taskRepo.FindAsync(It.IsAny <Expression <Func <TaskEntity, bool> > >()))
            .Returns(Task.FromResult(TestData.Tasks as IEnumerable <TaskEntity>));
            this.taskRepository
            .Setup(taskRepo => taskRepo.UpdateTasks(It.IsAny <List <TaskEntity> >()));
            this.repositoryAccessors
            .Setup(repositoryAccessor => repositoryAccessor.SaveChangesAsync())
            .Returns(Task.FromResult(0));

            var projectId = Guid.NewGuid();

            // ACT
            var operationResult = await this.projectHelper.DeleteProjectTasksAsync(TestData.Tasks);

            // ASSERT
            Assert.IsFalse(operationResult);
            this.taskRepository.Verify(taskRepo => taskRepo.UpdateTasks(It.IsAny <List <TaskEntity> >()), Times.AtLeastOnce());
        }
        public async Task DeleteMembersFromProject_WithCorrectModel_ShouldReturnTrue()
        {
            // ARRANGE
            this.repositoryAccessors.Setup(repositoryAccessor => repositoryAccessor.MemberRepository).Returns(() => this.memberRepository.Object);
            this.repositoryAccessors.Setup(accessor => accessor.Context).Returns(FakeTimesheetContext.GetFakeTimesheetContext());

            this.memberRepository
            .Setup(memberRepo => memberRepo.FindAsync(It.IsAny <Expression <Func <Member, bool> > >()))
            .Returns(Task.FromResult(TestData.Members.AsEnumerable()));
            this.memberRepository
            .Setup(memberRepo => memberRepo.UpdateMembers(It.IsAny <List <Member> >()));
            this.repositoryAccessors
            .Setup(repositoryAccessor => repositoryAccessor.SaveChangesAsync())
            .Returns(Task.FromResult(TestData.Members.Count()));

            var projectId = Guid.NewGuid();

            // ACT
            var operationResult = await this.projectHelper.DeleteProjectMembersAsync(TestData.Members);

            // ASSERT
            Assert.IsTrue(operationResult);
            this.memberRepository.Verify(memberRepo => memberRepo.UpdateMembers(It.IsAny <List <Member> >()), Times.AtLeastOnce());
        }