public async void ListWorkDeveloperAsync(bool withFilter)
        {
            var project = EntitiesFactory.NewProject(developerIds: new[] { SessionDeveloper.Id }).Save();
            var query   = new DeveloperWorkSearchClientDto {
                Page = 1, Limit = 1, ProjectId = withFilter ? (Guid?)project.Id : null
            };

            EntitiesFactory.NewWork(Guid.NewGuid(), project.DeveloperProjects.Single().Id).Save();
            EntitiesFactory.NewWork(Guid.NewGuid(), project.DeveloperProjects.Single().Id).Save();

            var(status, result) = await Request.GetAsync <ResultTest <IEnumerable <DeveloperWorkListDto> > >(new Uri($"{Uri}/{SessionDeveloper.Id}/works"), query);

            var workList = result.Data;

            Assert.Equal(Status.Success, status);
            Assert.NotEmpty(workList);
            Assert.True(result.TotalRows > 0);
            Assert.True(workList.Count() == query.Limit);
            Assert.All(workList, work =>
            {
                Assert.True(work.Hours > 0);
                Assert.NotEmpty(work.Comment);
                Assert.NotNull(work.Project);
                if (withFilter)
                {
                    Assert.Equal(project.Id, work.Project.Id);
                    Assert.Equal(project.Title, work.Project.Title);
                }
            });
        }
Beispiel #2
0
        public async void DeleteWorkTest(
            Status expectedStatus
            )
        {
            var developer = EntitiesFactory.NewDeveloper().Save();
            var project   = EntitiesFactory.NewProject(developerIds: new[] { developer.Id }).Save();

            var work = EntitiesFactory.NewWork(Guid.NewGuid(), project.DeveloperProjects.Single().Id).Get();

            _workRepository.Setup(d => d.ExistAsync(work.Id))
            .ReturnsAsync(expectedStatus != Status.NotFund);
            _workRepository.Setup(d => d.GetByIdAsync(work.Id))
            .ReturnsAsync(work);
            _mockyRepository.Setup(m => m.SendNotificationAsync(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(new Result <bool>(expectedStatus != Status.Error));

            var service = new WorkService(
                _workRepository.Object,
                _developerRepository.Object,
                _projectRepository.Object,
                _mockyRepository.Object
                );
            var result = await service.DeleteWorkAsync(work.Id);

            Assert.Equal(expectedStatus, result.Status);
            if (expectedStatus == Status.Success)
            {
                _workRepository.Verify(d => d.DeleteAsync(work), Times.Once);
                _mockyRepository.Verify(d => d.SendNotificationAsync(It.IsAny <string>(), It.IsAny <string>()), Times.Once);
            }
        }
Beispiel #3
0
        public async void UpdateProjectWorkAsync()
        {
            var project = EntitiesFactory.NewProject(developerIds: new[] { SessionDeveloper.Id }).Save();
            var work    = EntitiesFactory.NewWork(Guid.NewGuid(), project.DeveloperProjects.Single().Id).Save();
            var workDto = new WorkClientDto
            {
                Id        = work.Id,
                StartTime = DateTime.Now.AddHours(-3),
                EndTime   = DateTime.Now.AddHours(-1),
                Comment   = RandomHelper.RandomString(105),
                Hours     = 30
            };

            var(status, result) = await Request.PutAsync <ResultTest>(new Uri($"{Uri}/{project.Id}/works/{work.Id}"), workDto);

            var workDb = await DbContext.Works
                         .Include(w => w.DeveloperProject)
                         .FirstAsync(w => w.Id == workDto.Id);

            await DbContext.Entry(workDb).ReloadAsync();

            Assert.Equal(Status.Success, status);
            Assert.NotNull(workDb.DeveloperProject);
            Assert.Equal(project.Id, workDb.DeveloperProject.ProjectId);
            Assert.Equal(SessionDeveloper.Id, workDb.DeveloperProject.DeveloperId);
            Assert.Equal(workDto.StartTime, workDb.StartTime, TimeSpan.FromSeconds(5));
            Assert.Equal(workDto.EndTime, workDb.EndTime, TimeSpan.FromSeconds(5));
            Assert.Equal(workDto.Comment, workDb.Comment);
            Assert.Equal(workDto.Hours, workDb.Hours);
        }
        public async void DeveloperRankingAsync()
        {
            var projectsToRemove   = DbContext.Projects.ToArray();
            var developersToRemove = DbContext.Developers.Where(d => d.Id != SessionDeveloper.Id).ToArray();

            DbContext.Developers.RemoveRange(developersToRemove);
            DbContext.Projects.RemoveRange(projectsToRemove);

            var developerFirstPosition  = EntitiesFactory.NewDeveloper().Save();
            var developerSecondPosition = EntitiesFactory.NewDeveloper().Save();
            var project = EntitiesFactory.NewProject(
                developerIds: new[] { developerFirstPosition.Id, developerSecondPosition.Id }
                ).Save();
            var query = new DeveloperRankingSearchDto {
                ProjectId = project.Id, StartTime = default
            };

            EntitiesFactory.NewWork(
                hours: 10,
                id: Guid.NewGuid(),
                developerProjectId: project.DeveloperProjects
                .First(dp => dp.DeveloperId == developerFirstPosition.Id).Id
                ).Save();
            EntitiesFactory.NewWork(
                hours: 20,
                id: Guid.NewGuid(),
                developerProjectId: project.DeveloperProjects
                .First(dp => dp.DeveloperId == developerFirstPosition.Id).Id
                ).Save();
            EntitiesFactory.NewWork(
                hours: 12,
                id: Guid.NewGuid(),
                developerProjectId: project.DeveloperProjects
                .First(dp => dp.DeveloperId == developerSecondPosition.Id).Id
                ).Save();

            var(status, result) = await Request.GetAsync <ResultTest <IEnumerable <DeveloperRankingListDto> > >(new Uri($"{Uri}/ranking"), query);

            var developerList = result.Data;

            Assert.Equal(Status.Success, status);
            Assert.NotEmpty(developerList);
            Assert.Equal(3, developerList.Count());
            Assert.Equal(3, result.TotalRows);

            var firstPosition = developerList.ElementAt(0);

            Assert.Equal(developerFirstPosition.Id, firstPosition.Id);
            Assert.Equal(developerFirstPosition.Name, firstPosition.Name);
            Assert.Equal(15, firstPosition.AvgHours);
            Assert.Equal(30, firstPosition.SumHours);

            var secondPosition = developerList.ElementAt(1);

            Assert.Equal(developerSecondPosition.Id, secondPosition.Id);
            Assert.Equal(developerSecondPosition.Name, secondPosition.Name);
            Assert.Equal(12, secondPosition.AvgHours);
            Assert.Equal(12, secondPosition.SumHours);
        }
Beispiel #5
0
        public async void DeleteProjectWorkAsync()
        {
            var project = EntitiesFactory.NewProject(developerIds: new[] { SessionDeveloper.Id }).Save();
            var work    = EntitiesFactory.NewWork(Guid.NewGuid(), project.DeveloperProjects.Single().Id).Save();

            var(status, result) = await Request.DeleteAsync <ResultTest>(new Uri($"{Uri}/{project.Id}/works/{work.Id}"));

            var existProjectWork = await DbContext.Works.AnyAsync(d => d.Id == work.Id);

            Assert.Equal(Status.Success, status);
            Assert.True(result.Success);
            Assert.False(existProjectWork);
        }
Beispiel #6
0
        public async void UpdateWorkTest(
            Status expectedStatus,
            DateTime startTime,
            DateTime endTime
            )
        {
            var developer = EntitiesFactory.NewDeveloper().Save();
            var project   = EntitiesFactory.NewProject(developerIds: new[] { developer.Id }).Save();
            var work      = EntitiesFactory.NewWork(
                id: Guid.NewGuid(),
                developerProjectId: project.DeveloperProjects.Single().Id
                ).Get();

            var workDto = new WorkUpdateDto
            {
                Id        = work.Id,
                StartTime = startTime,
                EndTime   = endTime,
                Comment   = RandomHelper.RandomString(180),
                Hours     = 250
            };

            _workRepository.Setup(d => d.ExistAsync(workDto.Id))
            .ReturnsAsync(expectedStatus != Status.NotFund);
            _workRepository.Setup(d => d.GetByIdAsync(workDto.Id))
            .ReturnsAsync(work);
            _mockyRepository.Setup(m => m.SendNotificationAsync(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(new Result <bool>(expectedStatus != Status.Error));

            var service = new WorkService(
                _workRepository.Object,
                _developerRepository.Object,
                _projectRepository.Object,
                _mockyRepository.Object
                );
            var result = await service.UpdateWorkAsync(workDto);

            Assert.Equal(expectedStatus, result.Status);
            if (expectedStatus == Status.Success)
            {
                _workRepository.Verify(d => d.UpdateAsync(work), Times.Once);
                _mockyRepository.Verify(d => d.SendNotificationAsync(It.IsAny <string>(), It.IsAny <string>()), Times.Once);
                Assert.Equal(workDto.Comment, work.Comment);
                Assert.Equal(workDto.StartTime, work.StartTime);
                Assert.Equal(workDto.EndTime, work.EndTime);
                Assert.Equal(workDto.Hours, work.Hours);
            }
        }
Beispiel #7
0
        public async void GetProjectWorkByIdTest()
        {
            var project = EntitiesFactory.NewProject(developerIds: new[] { SessionDeveloper.Id }).Save();
            var work    = EntitiesFactory.NewWork(Guid.NewGuid(), project.DeveloperProjects.Single().Id).Save();

            var(status, result) = await Request.GetAsync <ResultTest <ProjectWorkDetailDto> >(new Uri($"{Uri}/{project.Id}/works/{work.Id}"));

            var workResult = result.Data;

            Assert.Equal(Status.Success, status);
            Assert.Equal(project.Id, workResult.Project.Id);
            Assert.Equal(project.Title, workResult.Project.Title);
            Assert.Equal(SessionDeveloper.Id, workResult.Developer.Id);
            Assert.Equal(SessionDeveloper.Name, workResult.Developer.Name);
            Assert.Equal(work.StartTime, workResult.StartTime, TimeSpan.FromSeconds(5));
            Assert.Equal(work.EndTime, workResult.EndTime, TimeSpan.FromSeconds(5));
            Assert.Equal(work.Hours, workResult.Hours);
        }