Beispiel #1
0
        public ActionResult Detail(String owner, String name)
        {
            var model = RepositoryService.Get(owner, name, true, Token?.Username);

            if (model == null)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, String.Empty);
            }

            using (var git = new GitService(name))
            {
                model.DefaultBranch = git.GetHeadBranch();
            }
            return(View(model));
        }
Beispiel #2
0
        public static async Task RunAsync(
            IReadOnlyList <string> organizations,
            string githubLogin,
            string githubPassword,
            bool includePrivateRepositories,
            bool includeUngroupedRepositories)
        {
            var committerGroups = organizations.SelectMany(CrappyCommitterGroupService.Get).ToList();

            var client = GitHubClientFactory.Create(typeof(Program).Namespace, githubLogin, githubPassword);

            var repositoryService     = new RepositoryService(client);
            var ungroupedRepositories = (await Task.WhenAll(committerGroups
                                                            .SelectMany(@group => @group.RepositoryList.Select(id => id.Owner))
                                                            .Concat(organizations)
                                                            .Distinct()
                                                            .Select(owner => repositoryService.Get(owner))))
                                        .SelectMany(_ => _)
                                        .Where(repository => includePrivateRepositories || !repository.IsPrivate)
                                        .Where(repository => !committerGroups.Any(group => group.RepositoryList.Contains(repository.Id)))
                                        .ToList();

            foreach (var repository in ungroupedRepositories.OrderBy(_ => _))
            {
                log.WarnFormat("{@Repository} is not grouped.", repository);
            }

            if (includeUngroupedRepositories)
            {
                committerGroups = committerGroups
                                  .Concat(ungroupedRepositories
                                          .GroupBy(repository => repository.Id.Owner)
                                          .Select(group => new CommitterGroup(
                                                      $"{group.Key}-ungrouped", ListModule.OfSeq(group.Select(repository => repository.Id)))))
                                  .ToList();
            }

            var contributions = (await Task.WhenAll(
                                     ContributionService.Get(committerGroups, new CommitService(client)),
                                     ContributionService.Get(committerGroups, new IssueService(client)),
                                     ContributionService.Get(committerGroups, new PullRequestService(client))))
                                .SelectMany(_ => _)
                                .GroupBy(contribution => new { contribution.Group, contribution.Login })
                                .Select(group => new Contribution(group.Key.Group, group.Key.Login, group.Sum(contribution => contribution.Score)))
                                .ToList();

            TsvContributionsRepository.Save(contributions);
        }
        public void RepositoryService_Get_ByPage_Overload_Returns_PagedList_Of_Repositorys()
        {
            //Arrange
            var mockRepository = new Mock<IRepository<Repository>>();
            mockRepository.Setup(r => r.Get(It.IsAny<int>())).Returns(GetRepositorys(TestConstants.PAGE_TotalCount));
            _mockUnitOfWork.Setup(u => u.GetRepository<Repository>()).Returns(mockRepository.Object);

            _service = new RepositoryService(_mockUnitOfWork.Object);
            const int treeId = TestConstants.TREE_Id;

            //Act
            var repositorys = _service.Get(treeId, t => true, 0, TestConstants.PAGE_RecordCount);

            //Assert
            Assert.IsInstanceOf<IPagedList<Repository>>(repositorys);
            Assert.AreEqual(TestConstants.PAGE_TotalCount, repositorys.TotalCount);
            Assert.AreEqual(TestConstants.PAGE_RecordCount, repositorys.PageSize);
        }
        public void RepositoryService_Get_ByPage_Overload_Calls_Repository_Get()
        {
            //Arrange
            var mockRepository = new Mock<IRepository<Repository>>();
            _mockUnitOfWork.Setup(u => u.GetRepository<Repository>()).Returns(mockRepository.Object);

            _service = new RepositoryService(_mockUnitOfWork.Object);
            const int treeId = TestConstants.TREE_Id;

            //Act
            _service.Get(treeId, t => true, 0, TestConstants.PAGE_RecordCount);

            //Assert
            mockRepository.Verify(r => r.Get(It.IsAny<int>()));
        }
        public void RepositoryService_Get_ByPage_Overload_Throws_On_Negative_TreeId()
        {
            //Arrange
            _service = new RepositoryService(_mockUnitOfWork.Object);

            //Assert
            Assert.Throws<IndexOutOfRangeException>(() => _service.Get(-1, t => true, 0, TestConstants.PAGE_RecordCount));
        }
        public void RepositoryService_Get_Overload_Throws_On_Negative_TreeId()
        {
            //Arrange
            _service = new RepositoryService(_mockUnitOfWork.Object);

            //Assert
            Assert.Throws<IndexOutOfRangeException>(() => _service.Get(-1));
        }
        public void RepositoryService_Get_Returns_Null_On_InValid_Id()
        {
            //Arrange
            var mockRepository = new Mock<IRepository<Repository>>();
            mockRepository.Setup(r => r.Get(It.IsAny<int>())).Returns(GetRepositorys(TestConstants.PAGE_TotalCount));
            _mockUnitOfWork.Setup(u => u.GetRepository<Repository>()).Returns(mockRepository.Object);

            _service = new RepositoryService(_mockUnitOfWork.Object);
            const int id = TestConstants.ID_NotFound;

            //Act
            var individual = _service.Get(id, It.IsAny<int>());

            //Assert
            Assert.IsNull(individual);
        }
        public void RepositoryService_Get_Calls_Repository_Get()
        {
            //Arrange
            var mockRepository = new Mock<IRepository<Repository>>();
            _mockUnitOfWork.Setup(u => u.GetRepository<Repository>()).Returns(mockRepository.Object);

            _service = new RepositoryService(_mockUnitOfWork.Object);
            const int id = TestConstants.ID_Exists;

            //Act
            _service.Get(id, It.IsAny<int>());

            //Assert
            mockRepository.Verify(r => r.Get(It.IsAny<int>()));
        }
        public void RepositoryService_Get_Throws_On_Negative_Id()
        {
            //Arrange
            _service = new RepositoryService(_mockUnitOfWork.Object);

            //Assert
            Assert.Throws<IndexOutOfRangeException>(() => _service.Get(-1, It.IsAny<int>()));
        }
 private CarRegisterRepository()
 {
     personsRepository = RepositoryService.Get <PersonsRepository>();
     carsRepository    = RepositoryService.Get <CarsRepository>();
 }