Exemplo n.º 1
0
        public async Task Can_inherit_from_parent_with_repo()
        {
            Helpers.WriteCodeOwners(
                Path.Combine(_workingDirectory.Directory, "CODEOWNERS"),
                new CodeOwnerConfig().AddEntry("*", entry => entry.AddUser("user1")));
            Helpers.WriteCodeOwners(
                Path.Combine(_workingDirectory.Directory, "test1", "CODEOWNERS"),
                new CodeOwnerConfig()
                .AddEntry("test2.pdf", entry => entry.AddUser("user2"))
                .AddEntry("test2.txt", entry => entry.AddUser("user3")));

            Repository.Init(_workingDirectory.Directory);
            var author = new Signature("Paul Knopf", "*****@*****.**", DateTimeOffset.Now);

            using (var repo = new Repository(_workingDirectory.Directory))
            {
                Commands.Stage(repo, "*");
                var commit   = repo.Commit("First commit", author, author);
                var provider = new RepositoryFileSystemProvider(commit);

                var result = await _codeOwnersBuilder.GetOwners(provider, "/test1/test2.txt");

                Assert.Equal(new List <string> {
                    "user1", "user3"
                }, result);
            }
        }
Exemplo n.º 2
0
        public void Can_view_repository()
        {
            File.WriteAllText(Path.Combine(_workingDirectory.Directory, "test1.txt"), "test");
            Directory.CreateDirectory(Path.Combine(_workingDirectory.Directory, "test2"));
            File.WriteAllText(Path.Combine(_workingDirectory.Directory, "test2", "test3.txt"), "test");
            Directory.CreateDirectory(Path.Combine(_workingDirectory.Directory, "test2", "test4"));
            File.WriteAllText(Path.Combine(_workingDirectory.Directory, "test2", "test4", "test5.txt"), "test");

            var commit = Commit();

            var provider = new RepositoryFileSystemProvider(commit);

            foreach (var contents in provider.GetDirectoryContents("/"))
            {
                switch (contents.Name)
                {
                case "test1.txt":
                    contents.Exists.ShouldBeTrue();
                    contents.IsDirectory.ShouldBeFalse();
                    contents.PhysicalPath.ShouldBeEqualTo("/test1.txt");
                    break;

                case "test2":
                    contents.Exists.ShouldBeEqualTo(true);
                    contents.IsDirectory.ShouldBeTrue();
                    //contents.PhysicalPath.ShouldBeEqualTo("/test2");
                    break;

                default:
                    Assert.True(false, $"Unexpected name {contents.Name}");
                    break;
                }
            }

            foreach (var contents in provider.GetDirectoryContents("/test2"))
            {
                switch (contents.Name)
                {
                case "test3.txt":
                    contents.Exists.ShouldBeTrue();
                    contents.IsDirectory.ShouldBeFalse();
                    break;

                case "test4":
                    contents.Exists.ShouldBeTrue();
                    contents.IsDirectory.ShouldBeTrue();
                    break;

                default:
                    Assert.True(false, $"Unexpected name {contents.Name}");
                    break;
                }
            }

            foreach (var contents in provider.GetDirectoryContents("/test2/test4"))
            {
                switch (contents.Name)
                {
                case "test5.txt":
                    contents.Exists.ShouldBeTrue();
                    contents.IsDirectory.ShouldBeFalse();
                    break;

                default:
                    Assert.True(false, $"Unexpected name {contents.Name}");
                    break;
                }
            }

            var info = provider.GetFileInfo("/test1.txt");

            info.Exists.ShouldBeTrue();
            info.IsDirectory.ShouldBeFalse();
            info.Name.ShouldBeEqualTo("test1.txt");

            info = provider.GetFileInfo("/test2");
            info.Exists.ShouldBeFalse();

            info = provider.GetFileInfo("/test2/test3.txt");
            info.Exists.ShouldBeTrue();
            info.IsDirectory.ShouldBeFalse();
            info.Name.ShouldBeEqualTo("test3.txt");

            info = provider.GetFileInfo("/test/test4");
            info.Exists.ShouldBeFalse();

            info = provider.GetFileInfo("/test2/test4/test5.txt");
            info.Exists.ShouldBeTrue();
            info.IsDirectory.ShouldBeFalse();
            info.Name.ShouldBeEqualTo("test5.txt");
        }