コード例 #1
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);
        }
コード例 #2
0
        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);
                }
            });
        }
コード例 #3
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);
            }
        }
コード例 #4
0
        public async void UpdateProjectTest(Status expectedStatus)
        {
            var projectDto = new ProjectUpdateDto
            {
                Id          = Guid.NewGuid(),
                Title       = RandomHelper.RandomString(),
                Description = RandomHelper.RandomString(350)
            };
            var project = EntitiesFactory.NewProject(id: projectDto.Id).Get();
            var projects = new[] { project }.AsQueryable().BuildMock();

            _projectRepository.Setup(d => d.ExistAsync(projectDto.Id))
            .ReturnsAsync(expectedStatus != Status.NotFund);
            _projectRepository.Setup(d => d.Query())
            .Returns(projects.Object);
            _projectRepository.Setup(d => d.ExistByTitleAsync(projectDto.Title, projectDto.Id))
            .ReturnsAsync(expectedStatus == Status.Conflict);

            var service = new ProjectService(_projectRepository.Object, _workRepository.Object);
            var result  = await service.UpdateProjectAsync(projectDto);

            Assert.Equal(expectedStatus, result.Status);
            if (expectedStatus == Status.Success)
            {
                _projectRepository.Verify(d => d.UpdateAsync(project), Times.Once);
                Assert.Equal(projectDto.Title, project.Title);
                Assert.Equal(projectDto.Description, project.Description);
            }
            else
            {
                _projectRepository.Verify(d => d.UpdateAsync(project), Times.Never);
            }
        }
コード例 #5
0
        public async void UpdateProjectTest()
        {
            var developer  = EntitiesFactory.NewDeveloper().Save();
            var project    = EntitiesFactory.NewProject().Save();
            var projectDto = new ProjectUpdateDto
            {
                Id           = project.Id,
                Title        = RandomHelper.RandomString(),
                Description  = RandomHelper.RandomString(490),
                DeveloperIds = new[] { developer.Id }
            };

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

            var projectDb = await DbContext.Projects
                            .Include(p => p.DeveloperProjects)
                            .SingleAsync(p => p.Id == projectDto.Id);

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

            Assert.Equal(Status.Success, status);
            Assert.True(result.Success);
            Assert.Equal(projectDto.Title, projectDb.Title);
            Assert.Equal(projectDto.Description, projectDb.Description);
            Assert.Single(projectDb.DeveloperProjects);
            Assert.Contains(projectDb.DeveloperProjects, d => d.DeveloperId == developer.Id);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        public async void DeleteProjectAsync()
        {
            var project = EntitiesFactory.NewProject().Save();

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

            var existProject = await DbContext.Projects.AnyAsync(d => d.Id == project.Id);

            Assert.Equal(Status.Success, status);
            Assert.True(result.Success);
            Assert.False(existProject);
        }
コード例 #8
0
        public async void CreateWorkTest(
            Status expectedStatus,
            DateTime startTime,
            DateTime endTime,
            bool withProject   = false,
            bool withDeveloper = false
            )
        {
            var developer = EntitiesFactory.NewDeveloper().Get();
            var project   = EntitiesFactory.NewProject(developerIds: new[] { developer.Id }).Save();

            var workDto = new WorkCreateDto
            {
                DeveloperId = developer.Id,
                ProjectId   = project.Id,
                StartTime   = startTime,
                EndTime     = endTime,
                Comment     = RandomHelper.RandomString(180),
                Hours       = 10
            };
            var worksPersisted = new List <Work>();

            _projectRepository.Setup(p => p.ExistAsync(project.Id)).ReturnsAsync(withProject);
            _projectRepository.Setup(p => p.GetDeveloperProjectIdAsync(project.Id, developer.Id))
            .ReturnsAsync(project.DeveloperProjects.Single().Id);
            _projectRepository.Setup(p => p.ExistDeveloperVinculatedAsync(project.Id, developer.Id))
            .ReturnsAsync(expectedStatus != Status.NotAllowed);
            _developerRepository.Setup(p => p.ExistAsync(developer.Id)).ReturnsAsync(withDeveloper);
            _workRepository.Setup(d => d.CreateAsync(Capture.In(worksPersisted)));
            _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.CreateWorkAsync(workDto);

            Assert.Equal(expectedStatus, result.Status);
            if (expectedStatus == Status.Success)
            {
                _workRepository.Verify(d => d.CreateAsync(It.IsAny <Work>()), Times.Once);
                _mockyRepository.Verify(d => d.SendNotificationAsync(It.IsAny <string>(), It.IsAny <string>()), Times.Once);
                var work = worksPersisted.Single();
                Assert.Equal(workDto.Comment, work.Comment);
                Assert.Equal(workDto.StartTime, work.StartTime);
                Assert.Equal(workDto.EndTime, work.EndTime);
                Assert.Equal(workDto.Hours, work.Hours);
            }
        }
コード例 #9
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);
        }
コード例 #10
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);
            }
        }
コード例 #11
0
        public async void ListProjectsTest()
        {
            EntitiesFactory.NewProject().Save();
            EntitiesFactory.NewProject().Save();
            var query = new PaginationDto {
                Page = 1, Limit = 1
            };
            var expectedTotal = await DbContext.Projects.CountAsync();

            var(status, result) = await Request.GetAsync <ResultTest <IEnumerable <ProjectListDto> > >(Uri, query);

            var projectList = result.Data;

            Assert.Equal(Status.Success, status);
            Assert.NotEmpty(projectList);
            Assert.Equal(expectedTotal, result.TotalRows);
            Assert.True(projectList.Count() == query.Limit);
        }
コード例 #12
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);
        }
コード例 #13
0
        public async void GetProjectByIdTest()
        {
            var developer = EntitiesFactory.NewDeveloper().Save();
            var project   = EntitiesFactory.NewProject(developerIds: new [] { developer.Id }).Save();

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

            var projectResult = result.Data;

            Assert.Equal(Status.Success, status);
            Assert.Equal(project.Id, projectResult.Id);
            Assert.Equal(project.Title, projectResult.Title);
            Assert.Equal(project.Description, projectResult.Description);

            var developerModel = projectResult.Developers.Single();

            Assert.Equal(developer.Id, developerModel.Id);
            Assert.Equal(developer.Name, developerModel.Name);
        }
コード例 #14
0
        public async void DeleteProjectTest(Status expectedStatus)
        {
            var project = EntitiesFactory.NewProject().Get();

            _projectRepository.Setup(d => d.ExistAsync(project.Id))
            .ReturnsAsync(expectedStatus != Status.NotFund);
            _projectRepository.Setup(d => d.GetByIdAsync(project.Id))
            .ReturnsAsync(project);

            var service = new ProjectService(_projectRepository.Object, _workRepository.Object);
            var result  = await service.DeleteProjectAsync(project.Id);

            Assert.Equal(expectedStatus, result.Status);
            if (expectedStatus == Status.Success)
            {
                _projectRepository.Verify(d => d.DeleteAsync(project), Times.Once);
            }
            else
            {
                _projectRepository.Verify(d => d.DeleteAsync(project), Times.Never);
            }
        }