Ejemplo n.º 1
0
        public async Task ToMarkdownCommentAsync_Successful()
        {
            // Arrange
            gitRepoHelpers.AddUntrackedFileToRepoWithNumLines("fake.cs", 2);
            gitRepoHelpers.AddUntrackedFileToRepoWithNumLines("fake2.cs", 4);
            gitRepoHelpers.CommitFilesToRepo();
            gitRepoHelpers.AddUntrackedFileToRepoWithNumLines("fake.cs", 5);
            gitRepoHelpers.AddUntrackedFileToRepoWithNumLines("fake2.cs", 2);
            var quantifierInput = new QuantifierInput();

            quantifierInput.Changes.AddRange(gitEngine.GetGitChanges(gitRepoHelpers.RepoPath));
            var quantifyClient = new QuantifyClient(string.Empty);

            // Act
            var quantifierResult = await quantifyClient.Compute(quantifierInput);

            var comment = await quantifierResult.ToMarkdownCommentAsync(
                RepositoryLink,
                ContextFileLink,
                PullRequestLink,
                AuthorName);

            // Assert
            Assert.True(!string.IsNullOrWhiteSpace(comment));
            Assert.StartsWith("### Pull Request Quantified", comment);
        }
Ejemplo n.º 2
0
        public async Task Quantify_NoChanges_ReturnsZeroCounts()
        {
            // Arrange
            var prQuantifier    = new PullRequestQuantifier(context);
            var quantifierInput = new QuantifierInput();

            quantifierInput.Changes.AddRange(gitEngine.GetGitChanges(gitRepoHelpers.RepoPath));

            // Act
            var quantifierResult = await prQuantifier.Quantify(quantifierInput);

            // Assert
            Assert.Equal("No Changes", quantifierResult.Label);
            Assert.Equal(0, quantifierResult.QuantifiedLinesAdded);
            Assert.Equal(0, quantifierResult.QuantifiedLinesDeleted);
        }
        private QuantifierInput GetChanges(string repoPath)
        {
            var quantifierInput = new QuantifierInput();

            quantifierInput.Changes.AddRange(gitEngine.GetGitChanges(repoPath));

            return(quantifierInput);
        }
Ejemplo n.º 4
0
        public void GetGitChanges_NoChangesNoExceptions()
        {
            // Setup
            IGitEngine gitEngine = new GitEngine();

            // Act, Assert
            var exception = Record.Exception(() => gitEngine.GetGitChanges(Environment.CurrentDirectory));

            Assert.Null(exception);
        }
Ejemplo n.º 5
0
        public async Task ToMarkdownCommentAsync_Successful()
        {
            // Arrange
            var quantifierInput = new QuantifierInput();

            quantifierInput.Changes.AddRange(gitEngine.GetGitChanges(gitRepoHelpers.RepoPath));
            var quantifyClient = new QuantifyClient(string.Empty);

            // Act
            var quantifierResult = await quantifyClient.Compute(quantifierInput);

            var comment = await quantifierResult.ToMarkdownCommentAsync(
                RepositoryLink,
                ContextFileLink,
                PullRequestLink,
                AuthorName);

            // Assert
            Assert.True(!string.IsNullOrWhiteSpace(comment));
            Assert.StartsWith("### ![](https://img.shields.io/static/v1?label=Quantified&message=Extra%20Small&color=green)", comment);
        }
Ejemplo n.º 6
0
        public async Task QuantifyClient_UsingDefaultContext()
        {
            // Arrange
            gitRepoHelpers.AddUntrackedFileToRepoWithNumLines("fake.cs", 2);
            gitRepoHelpers.AddUntrackedFileToRepoWithNumLines("fake2.cs", 4);
            gitRepoHelpers.CommitFilesToRepo();
            gitRepoHelpers.AddUntrackedFileToRepoWithNumLines("fake.cs", 5);
            gitRepoHelpers.AddUntrackedFileToRepoWithNumLines("fake2.cs", 2);
            var quantifierInput = new QuantifierInput();

            quantifierInput.Changes.AddRange(gitEngine.GetGitChanges(gitRepoHelpers.RepoPath));
            var quantifyClient = new QuantifyClient(string.Empty);

            // Act
            var quantifierResult = await quantifyClient.Compute(quantifierInput);

            // Assert
            Assert.True(!string.IsNullOrEmpty(quantifierResult.Label));
            Assert.Equal(3, quantifierResult.QuantifiedLinesAdded);
            Assert.Equal(2, quantifierResult.QuantifiedLinesDeleted);
            Assert.Equal(1, (int)quantifierResult.PercentileAddition);
            Assert.Equal(0, (int)quantifierResult.PercentileDeletion);
            Assert.Equal(2, (int)quantifierResult.FormulaPercentile);
        }
Ejemplo n.º 7
0
        public void GetGitChanges_ChangedModifiedRenamedFiles()
        {
            // Arrange
            IGitEngine gitEngine = new GitEngine();

            gitRepoHelpers.AddUntrackedFileToRepoWithNumLines("fakeRename.cs", 2);
            gitRepoHelpers.CommitFilesToRepo();
            gitRepoHelpers.RenameFile("fakeRename.cs", "fakeRename1.cs");

            // Act
            var gitChanges = gitEngine.GetGitChanges(gitRepoHelpers.RepoPath).ToArray();

            // Assert
            Assert.Single(gitChanges);
            Assert.Equal(2, gitChanges[0].AbsoluteLinesDeleted);
            Assert.Equal(GitChangeType.Renamed, gitChanges[0].ChangeType);
        }
Ejemplo n.º 8
0
        public void GetGitChanges_ChangedTrackedFiles()
        {
            // Arrange
            IGitEngine gitEngine = new GitEngine();

            gitRepoHelpers.AddUntrackedFileToRepoWithNumLines("fake.cs", 2);
            gitRepoHelpers.AddUntrackedFileToRepoWithNumLines("fake2.cs", 4);
            gitRepoHelpers.CommitFilesToRepo();
            gitRepoHelpers.AddUntrackedFileToRepoWithNumLines("fake.cs", 5);
            gitRepoHelpers.AddUntrackedFileToRepoWithNumLines("fake2.cs", 2);

            // Act
            var gitChanges = gitEngine.GetGitChanges(gitRepoHelpers.RepoPath).ToArray();

            // Assert
            Assert.NotEmpty(gitChanges);
            Assert.Equal(2, gitChanges.Length);
            Assert.Equal(3, gitChanges[0].AbsoluteLinesAdded);
            Assert.Equal(2, gitChanges[1].AbsoluteLinesDeleted);
        }