Ejemplo n.º 1
0
        public async Task Can_Handle_Renames(string oldPath, string oldContent, string newPath, string newContent, int expectLinesAdded)
        {
            using (var temp = new TempRepository())
            {
                var commit1      = AddCommit(temp.Repository, oldPath, oldContent.Replace('.', '\n'));
                var commit2      = AddCommit(temp.Repository, newPath, newContent.Replace('.', '\n'));
                var contentBytes = new UTF8Encoding(false).GetBytes(newContent.Replace('.', '\n'));
                var target       = new GitService(new RepositoryFacade());

                var changes = await target.CompareWith(temp.Repository, commit1.Sha, commit2.Sha, newPath, contentBytes);

                Assert.That(changes?.LinesAdded, Is.EqualTo(expectLinesAdded));
            }
        }
Ejemplo n.º 2
0
        public async Task Simple_Diff(string content1, string content2, string expectPatch)
        {
            using (var temp = new TempRepository())
            {
                var path         = "foo.txt";
                var commit1      = AddCommit(temp.Repository, path, content1.Replace('.', '\n'));
                var commit2      = AddCommit(temp.Repository, path, content2.Replace('.', '\n'));
                var contentBytes = new UTF8Encoding(false).GetBytes(content2.Replace('.', '\n'));
                var target       = new GitService(new RepositoryFacade());

                var changes = await target.CompareWith(temp.Repository, commit1.Sha, commit2.Sha, path, contentBytes);

                Assert.That(changes.Patch.Replace('\n', '.'), Contains.Substring(expectPatch));
            }
        }
        public void Path_Must_Not_Use_Windows_Directory_Separator()
        {
            using (var temp = new TempRepository())
            {
                var path         = @"dir\foo.txt";
                var oldContent   = "oldContent";
                var newContent   = "newContent";
                var commit1      = AddCommit(temp.Repository, path, oldContent);
                var commit2      = AddCommit(temp.Repository, path, newContent);
                var contentBytes = new UTF8Encoding(false).GetBytes(newContent);
                var target       = new GitService(new RepositoryFacade());

                Assert.ThrowsAsync <ArgumentException>(() =>
                                                       target.CompareWith(temp.Repository, commit1.Sha, commit2.Sha, path, contentBytes));
            }
        }
Ejemplo n.º 4
0
        public async Task Path_Can_Use_Windows_Directory_Separator()
        {
            using (var temp = new TempRepository())
            {
                var path         = @"dir\foo.txt";
                var oldContent   = "oldContent";
                var newContent   = "newContent";
                var commit1      = AddCommit(temp.Repository, path, oldContent);
                var commit2      = AddCommit(temp.Repository, path, newContent);
                var contentBytes = new UTF8Encoding(false).GetBytes(newContent);
                var target       = new GitService(new RepositoryFacade());

                var contentChanges = await target.CompareWith(temp.Repository, commit1.Sha, commit2.Sha, path, contentBytes);

                Assert.That(contentChanges.LinesAdded, Is.EqualTo(1));
                Assert.That(contentChanges.LinesDeleted, Is.EqualTo(1));
            }
        }