Exemplo n.º 1
0
        public void WriteNode()
        {
            string userName = "******";
            var    user     = new User(userName);
            string path     = Path.Join("root", "git", "users", userName);
            var    project  = new Document("project", user);
            var    node     = new Document("node", user);

            node.Children    = new ObservableCollection <Document>();
            node.Index       = 3;
            node.Repo        = "http://git";
            node.IndexLeaves = true;
            node.IndexNodes  = false;
            node.Content     = "Lorem ipsum";
            using (var configuration = new MoqSystemConfiguration(null)) {
                var    storage = configuration.Services.GetService <GitStorage>();
                string directoryDocumentPath = Path.Combine(path, project.Name, node.Name, GitStorage.DirectoryDocumentName);
                storage.WriteDocument(node, directoryDocumentPath, true);
                //configuration.Moq.Verify(m => m.CreateNode(It.Is<string>(o => o == Path.Combine(path, project.Name, node.Name))), Times.Exactly(1));
                configuration.Moq.Verify(m => m.WriteLeaf(
                                             It.Is <string>(o => o == directoryDocumentPath),
                                             It.Is <string>(o => o == $"---\r\nid: {node.Id}\r\nrepo: {node.Repo}\r\nindex.leaves: True\r\n---\r\n{node.Content}")),
                                         Times.Once);
            }
        }
Exemplo n.º 2
0
        public void GetOrder()
        {
            var documents = new List <Document> {
                new Document("A", null)
                {
                    Id = "1", Index = 0, Children = new ObservableCollection <Document>()
                },
                new Document("B", null)
                {
                    Id = "2", Index = 0, Children = new ObservableCollection <Document>()
                },
                new Document("A", null)
                {
                    Id = "3", Index = 0, IsLeaf = true
                },
                new Document("B", null)
                {
                    Id = "4", Index = 0, IsLeaf = true
                },
                new Document("C", null)
                {
                    Id = "5", Index = 1, Children = new ObservableCollection <Document>()
                },
                new Document("C", null)
                {
                    Id = "6", Index = 1, IsLeaf = true
                },
                new Document("C", null)
                {
                    Id = "7", Index = 2, Children = new ObservableCollection <Document>()
                },
                new Document("D", null)
                {
                    Id = "8", Index = 2, Children = new ObservableCollection <Document>()
                },
                new Document("C", null)
                {
                    Id = "9", Index = 3, Children = new ObservableCollection <Document>()
                }
            };

            using (var configuration = new MoqSystemConfiguration(null)) {
                var storage = configuration.Services.GetService <GitStorage>();
                foreach (var order in Permutate(documents))
                {
                    int i = 1;
                    Assert.Collection(storage.OrderDocuments(documents),
                                      l => Assert.Equal(i++, int.Parse(l.Id)),
                                      l => Assert.Equal(i++, int.Parse(l.Id)),
                                      l => Assert.Equal(i++, int.Parse(l.Id)),
                                      l => Assert.Equal(i++, int.Parse(l.Id)),
                                      l => Assert.Equal(i++, int.Parse(l.Id)),
                                      l => Assert.Equal(i++, int.Parse(l.Id)),
                                      l => Assert.Equal(i++, int.Parse(l.Id)),
                                      l => Assert.Equal(i++, int.Parse(l.Id)),
                                      l => Assert.Equal(i++, int.Parse(l.Id))
                                      );
                }
            }
        }
Exemplo n.º 3
0
        public void EmptyProject()
        {
            string path = "path";
            Func <string, string>          getPath = o => Path.Join(path, o);
            Action <Mock <SystemService> > setup   = m => {
                m.Setup(m => m.GetLeaves(It.IsAny <string>())).Returns(new string[] {
                    getPath("file1"),
                    getPath("file2")
                });
                m.Setup(m => m.GetNodes(It.IsAny <string>())).Returns(new string[] {
                    getPath(".git"),
                    getPath("directory1"),
                    getPath("directory2")
                });
            };

            using (var configuration = new MoqSystemConfiguration(setup)) {
                configuration.Services.GetService <GitStorage>().EmptyProject("path");
                configuration.Moq.Verify(m => m.DeleteNode(It.IsAny <string>(), It.Is <bool>(o => o == true)), Times.Exactly(2));
                configuration.Moq.Verify(m => m.DeleteNode(It.Is <string>(o => o == getPath("directory1")), It.Is <bool>(o => o == true)), Times.Once);
                configuration.Moq.Verify(m => m.DeleteNode(It.Is <string>(o => o == getPath(".git")), It.Is <bool>(o => o == true)), Times.Never);
                configuration.Moq.Verify(m => m.DeleteLeaf(It.IsAny <string>()), Times.Exactly(2));
                configuration.Moq.Verify(m => m.DeleteLeaf(It.Is <string>(o => o == getPath("file1"))), Times.Once);
            }
        }
Exemplo n.º 4
0
 public void GetIndexPrefix()
 {
     using (var configuration = new MoqSystemConfiguration(o => { })) {
         Assert.Equal("03.", configuration.Services.GetService <GitStorage>().GetIndexPrefix(new Document("name", null)
         {
             Index = 3
         }));
     }
 }
Exemplo n.º 5
0
        public void ReadProjectText()
        {
            var project = new Document("name", null);
            var setup   = SetupMetadataReading(out string id, out string text, out string repo);

            using (var configuration = new MoqSystemConfiguration(setup)) {
                configuration.Services.GetService <GitStorage>().ReadDocument(project, null);
                Assert.Equal(text, project.Content);
            }
        }
Exemplo n.º 6
0
        public void GetDirectoryNameNoIndex()
        {
            string name = "03.Document.md";
            string path = Path.Join("A", "B", name);

            using (var configuration = new MoqSystemConfiguration(o => { })) {
                var storage = configuration.Services.GetService <GitStorage>();
                Assert.Equal(name, storage.GetDocumentName(path, false, false, out int index));
                Assert.Equal(0, index);
            }
        }
Exemplo n.º 7
0
        public void GetMetadataSimpleProject()
        {
            var document  = new Document("name", null);
            var metadatas = Document.Metadatas.Where(o => o.Get(document) != null);

            Assert.Single(metadatas);
            Assert.Equal("id", metadatas.Single().Id);
            using (var configuration = new MoqSystemConfiguration(o => { })) {
                Assert.False(configuration.Services.GetService <GitStorage>().NeedsDirectoryDocument(document));
            }
        }
Exemplo n.º 8
0
        public void GetLeafNameWithIndex()
        {
            string name = "03.Document.md";
            string path = Path.Join("A", "B", name);

            using (var configuration = new MoqSystemConfiguration(o => { })) {
                var storage = configuration.Services.GetService <GitStorage>();
                Assert.Equal("Document", storage.GetDocumentName(path, true, true, out int index));
                Assert.Equal(3, index);
            }
        }
Exemplo n.º 9
0
        public void GetProjectName()
        {
            string name = "01.Project.md";
            string path = Path.Join("Storage", "Git", "Users", name);

            using (var configuration = new MoqSystemConfiguration(o => { })) {
                var storage = configuration.Services.GetService <GitStorage>();
                Assert.Equal(name, storage.GetDocumentName(path, false, false, out int index));
                Assert.Equal(0, index);
            }
        }
Exemplo n.º 10
0
        public void ReadProjectMetadata()
        {
            var project = new Document("name", null);
            var setup   = SetupMetadataReading(out string id, out string text, out string repo);

            using (var configuration = new MoqSystemConfiguration(setup)) {
                configuration.Services.GetService <GitStorage>().ReadMetadata(project, null);
                Assert.Equal(id, project.Id);
                Assert.Equal(repo, project.Repo);
                Assert.True(project.IndexLeaves);
                Assert.False(project.IndexNodes);
            }
        }
Exemplo n.º 11
0
        public void GetMetadataIndexNodesDocument()
        {
            var project = new Document("name", null);

            project.IndexNodes = true; // No automatic inheritance
            var document  = project.CreateDocument("name");
            var metadatas = Document.Metadatas.Where(o => o.Get(document) != null);

            Assert.Single(metadatas);
            Assert.Equal("id", metadatas.Single().Id);
            Assert.Null(Document.Metadatas.Single(o => o.Id == "index.nodes").Get(document));
            using (var configuration = new MoqSystemConfiguration(o => { })) {
                Assert.False(configuration.Services.GetService <GitStorage>().NeedsDirectoryDocument(document));
            }
        }
Exemplo n.º 12
0
        public void GetNotIndexedNodeDocumentPath()
        {
            string path   = "path";
            var    parent = new Document("parent", null);

            parent.IndexNodes  = false;
            parent.IndexLeaves = true;
            var document = new Document("document", null, parent)
            {
                Index = 3, Children = new ObservableCollection <Document>()
            };

            using (var configuration = new MoqSystemConfiguration(o => { })) {
                Assert.Equal(Path.Join(path, "document"), configuration.Services.GetService <GitStorage>().GetDocumentPath(parent, document, path));
            }
        }
Exemplo n.º 13
0
        public void GetIndexedLeafDocumentPath()
        {
            string path   = "path";
            var    parent = new Document("parent", null);

            parent.IndexNodes  = false;
            parent.IndexLeaves = true;
            var document = new Document("document", null, parent)
            {
                Index = 3, IsLeaf = true
            };

            using (var configuration = new MoqSystemConfiguration(o => { })) {
                Assert.Equal(Path.Join(path, "03.document.md"), configuration.Services.GetService <GitStorage>().GetDocumentPath(parent, document, path));
            }
        }
Exemplo n.º 14
0
        public void GeNodes()
        {
            string path = Path.Join("A", "B");
            Func <string, string>          getPath = o => Path.Join(path, o);
            Action <Mock <SystemService> > setup   = m => {
                m.Setup(m => m.GetNodes(It.Is <string>(s => s == path), "*", SearchOption.TopDirectoryOnly)).Returns(new string[] {
                    getPath(".git"),
                    getPath("directory1"),
                    getPath("directory2")
                });
            };

            using (var configuration = new MoqSystemConfiguration(setup)) {
                var nodes = configuration.Services.GetService <GitStorage>().GetNodes(path);
                Assert.Collection(nodes, l => Assert.Equal(getPath("directory1"), l), l => Assert.Equal(getPath("directory2"), l));
            }
        }
Exemplo n.º 15
0
        public void GetMetadataIndexLeavesProject()
        {
            var project = new Document("name", null);

            project.IndexLeaves = true;
            var metadatas = Document.Metadatas.Where(o => o.Get(project) != null);

            Assert.Equal(2, metadatas.Count());
            var keys = metadatas.Select(o => o.Id);

            Assert.Contains("id", keys);
            Assert.Contains("index.leaves", keys);
            Assert.Equal(true.ToString(), metadatas.Single(o => o.Id == "index.leaves").Get(project));
            using (var configuration = new MoqSystemConfiguration(o => { })) {
                Assert.True(configuration.Services.GetService <GitStorage>().NeedsDirectoryDocument(project));
            }
        }
Exemplo n.º 16
0
        public void LoadFile()
        {
            var user    = new User("Kevin");
            var project = new Document("name", null);

            project.IndexLeaves = true;
            var setupReading = SetupMetadataReading(out string id, out string text, out string repo);
            Action <Mock <SystemService> > setupNaming = m => m.Setup(o => o.GetName(It.IsAny <string>())).Returns("03.leaf.md");

            using (var configuration = new MoqSystemConfiguration(setupReading, setupNaming)) {
                var leaf = configuration.Services.GetService <GitStorage>().LoadFile(user, project, null, true);
                Assert.Equal("leaf", leaf.Name);
                Assert.Equal(3, leaf.Index);
                Assert.Equal(id, leaf.Id);
                Assert.Equal(text, leaf.Content);
                Assert.True(leaf.IsLeaf);
            }
        }
Exemplo n.º 17
0
        public void WriteNoMetadataNoTextNode()
        {
            string userName = "******";
            var    user     = new User(userName);
            string path     = Path.Join("root", "git", "users", userName);
            var    project  = new Document("project", user);
            var    node     = new Document("node", user);

            node.Children = new ObservableCollection <Document>();
            node.Index    = 3;
            using (var configuration = new MoqSystemConfiguration(null)) {
                var    storage = configuration.Services.GetService <GitStorage>();
                string directoryDocumentPath = Path.Combine(path, project.Name, node.Name, GitStorage.DirectoryDocumentName);
                storage.WriteDocument(node, directoryDocumentPath, true);
                //configuration.Moq.Verify(m => m.CreateNode(It.Is<string>(o => o == Path.Combine(path, project.Name, node.Name))), Times.Exactly(1));
                configuration.Moq.Verify(m => m.WriteLeaf(It.IsAny <string>(), It.IsAny <string>()), Times.Never());
            }
        }
Exemplo n.º 18
0
        public void ReadAndSetDocumentMetadata()
        {
            var project = new Document("name", null);

            project.IndexLeaves = false;
            var document = project.CreateDocument("name");
            var setup    = SetupMetadataReading(out string id, out string text, out string repo);

            using (var configuration = new MoqSystemConfiguration(setup)) {
                var storage = configuration.Services.GetService <GitStorage>();
                storage.ReadMetadata(document, null);
                Assert.Equal(id, document.Id);
                Assert.True(document.IndexLeaves);
                Assert.False(document.IndexNodes);
                storage.SetMetadata(document);
                Assert.True(document.IndexLeaves);
                Assert.False(document.IndexNodes);
            }
        }
Exemplo n.º 19
0
        public void GetLeaves()
        {
            string path = Path.Join("A", "B");
            Func <string, string>          getPath = o => Path.Join(path, o);
            Action <Mock <SystemService> > setup   = m => {
                m.Setup(m => m.GetLeaves(It.Is <string>(s => s == path))).Returns(new string[] {
                    getPath("file1.md"),
                    getPath("file2.md"),
                    getPath("invalidfile1"),
                    getPath("invalidfile2.mdr"),
                    getPath(".invalidfile3.md"),
                    getPath(".dir.md")
                });
            };

            using (var configuration = new MoqSystemConfiguration(setup)) {
                var leaves = configuration.Services.GetService <GitStorage>().GetLeaves(path);
                Assert.Collection(leaves, l => Assert.Equal(getPath("file1.md"), l), l => Assert.Equal(getPath("file2.md"), l));
            }
        }
Exemplo n.º 20
0
        public void WriteNoIndexLeaf()
        {
            string userName = "******";
            var    user     = new User(userName);
            string path     = Path.Join("root", "git", "users", userName);
            var    project  = new Document("project", user);
            var    leaf     = new Document("leaf", user);

            leaf.Index   = 3;
            leaf.IsLeaf  = true;
            leaf.Repo    = "http://git";
            leaf.Content = "Lorem ipsum";
            using (var configuration = new MoqSystemConfiguration(null)) {
                var storage = configuration.Services.GetService <GitStorage>();
                storage.WriteDocument(leaf, storage.GetDocumentPath(project, leaf, Path.Combine(path, project.Name)), true);
                configuration.Moq.Verify(m => m.WriteLeaf(
                                             It.Is <string>(o => o == Path.Combine(path, project.Name, leaf.Name + ".md")),
                                             It.Is <string>(o => o == $"---\r\nid: {leaf.Id}\r\nrepo: {leaf.Repo}\r\n---\r\n{leaf.Content}")),
                                         Times.Exactly(1));
            }
        }
Exemplo n.º 21
0
        public void LoadDirectory()
        {
            var    user    = new User("Kevin");
            var    project = new Document("name", null);
            string path    = Path.Join("path", project.Name, "directory");
            Func <string, string> getPath = o => Path.Combine(path, o);

            project.IndexNodes = true;
            var setupReading = SetupMetadataReading(out string id, out string text, out string repo);
            Action <Mock <SystemService> > setupSystem = m => {
                m.Setup(o => o.GetName(It.IsAny <string>())).Returns("03.directory");
                m.Setup(m => m.GetLeaves(It.Is <string>(s => s == path), It.Is <string>(o => o == GitStorage.DirectoryDocumentName)))
                .Returns(new string[] { Path.Combine(path, GitStorage.DirectoryDocumentName) });
            };

            using (var configuration = new MoqSystemConfiguration(setupReading, setupSystem)) {
                var gitStorage = new Mock <GitStorage>(new GitStorageSettings {
                    Local = false
                }, null, null, null, configuration.Moq.Object);
                gitStorage.Setup(o => o.GetChildren(It.IsAny <Document>(), It.Is <User>(o => o == user), path, true)).Returns(new ObservableCollection <Document> {
                    new Document("node1", user),
                    new Document("node2", user),
                    new Document("leaf1", user),
                    new Document("leaf2", user)
                });
                configuration.ServiceDescriptors.Add(new ServiceDescriptor(typeof(GitStorage), gitStorage.Object));
                var directory = configuration.Services.GetService <GitStorage>().LoadDirectory(user, project, path, true);
                configuration.Moq.Verify(m => m.ReadLeaf(It.Is <string>(o => o == Path.Combine(path, ".dir.md"))), Times.Exactly(2)); // Metadata + Text
                Assert.Equal("directory", directory.Name);
                Assert.Equal(3, directory.Index);
                Assert.Equal(id, directory.Id);
                Assert.Equal(text, directory.Content);
                Assert.False(directory.IsLeaf);
                Assert.NotNull(directory.Children);
                Assert.Equal(4, directory.Children.Count);
            }
        }