private ICommentSource GetXmlCommentFile(DocumentedAssembly current)
        {
            XmlCommentFile commentFile = new XmlCommentFile(current.XmlFileName, new FileSystem());

            commentFile.Load();
            return(commentFile);
        }
예제 #2
0
        public void WhenFilenameIsEmptyString_Exists_IsFalse()
        {
            XmlCommentFile commentFile = CreateXmlCommentFile(string.Empty);

            bool result = commentFile.Exists();

            Assert.AreEqual(false, result);
        }
예제 #3
0
        public void WhenNotLoaded_IsLoaded_IsFalse()
        {
            XmlCommentFile commentFile = CreateXmlCommentFile("test.xml");

            bool result = commentFile.IsLoaded;

            Assert.AreEqual(false, result);
        }
예제 #4
0
        public void WhenFileDoesntExist_Exists_IsFalse()
        {
            XmlCommentFile commentFile = CreateXmlCommentFile("doesnt_exist.dll");

            _fileSystem.Setup(p => p.FileExists(It.IsAny <string>())).Returns(false);

            bool result = commentFile.Exists();

            Assert.AreEqual(false, result);
        }
예제 #5
0
        public void WhenFileExists_Exists_IsTrue()
        {
            XmlCommentFile commentFile = CreateXmlCommentFile("exists.dll");

            _fileSystem.Setup(p => p.FileExists("exists.dll")).Returns(true);

            bool result = commentFile.Exists();

            Assert.AreEqual(true, result);
        }
예제 #6
0
        public void WhenExistsIsFalse_Load_IsNotCalled()
        {
            XmlCommentFile commentFile = CreateXmlCommentFile(string.Empty);

            _fileSystem.Setup(p => p.FileExists(It.IsAny <string>())).Returns(false);

            commentFile.Load();

            _fileSystem.Verify(p => p.ReadAllBytes(It.IsAny <string>()), Times.Never());
        }
예제 #7
0
        public void WhenFileExists_Load_IsCalled()
        {
            XmlCommentFile commentFile = CreateXmlCommentFile("exists.xml");

            _fileSystem.Setup(p => p.FileExists(It.IsAny <string>())).Returns(true);

            commentFile.Load();

            _fileSystem.Verify(p => p.ReadAllBytes(It.IsAny <string>()), Times.Exactly(1));
        }
예제 #8
0
        public void WhenPassedNull_GetComment_ReturnsEmpty()
        {
            XmlCommentFile commentFile = CreateXmlCommentFile("myfile.xml");

            SetFileExistsAndLoadXml(commentFile);

            XmlCodeComment result = commentFile.GetComment(null);

            Assert.AreSame(XmlCodeComment.Empty, result);
        }
예제 #9
0
        public void WhenCRefValid_GetSummary_ReturnsSummary()
        {
            XmlCommentFile commentFile = CreateXmlCommentFile("Myfile.xml");
            CRefPath       crefPath    = CRefPath.Parse("T:Namespace.MyType");

            SetFileExistsAndLoadXml(commentFile);

            XmlCodeComment result = commentFile.GetSummary(crefPath);

            Assert.AreEqual("Summary text", result.Elements[0].Text);
        }
예제 #10
0
        public void WhenCRefValidButNoData_GetComment_ReturnsEmpty()
        {
            XmlCommentFile commentFile = CreateXmlCommentFile("myfile.xml");

            SetFileExistsAndLoadXml(commentFile);
            CRefPath crefPath = CRefPath.Parse("T:Nowhere.DoesntExist");

            XmlCodeComment result = commentFile.GetComment(crefPath);

            Assert.AreSame(XmlCodeComment.Empty, result);
        }
예제 #11
0
        public void WhenNotLoaded_GetComment_ReturnsEmpty()
        {
            XmlCommentFile commentFile = CreateXmlCommentFile("myfile.xml");

            _fileSystem.Setup(p => p.FileExists(It.IsAny <string>())).Returns(true);
            CRefPath crefPath = CRefPath.Parse("T:Namespace.TypeName");

            XmlCodeComment result = commentFile.GetComment(crefPath);

            Assert.AreSame(XmlCodeComment.Empty, result);
        }
예제 #12
0
        public void WhenLoaded_IsLoaded_IsTrue()
        {
            XmlCommentFile commentFile = CreateXmlCommentFile("test.xml");

            _fileSystem.Setup(p => p.FileExists(It.IsAny <string>())).Returns(true);
            commentFile.Load();

            bool result = commentFile.IsLoaded;

            Assert.AreEqual(true, result);
        }
예제 #13
0
        public void WhenCRefInvalid_GetSummary_ReturnsEmpty()
        {
            XmlCommentFile commentFile = CreateXmlCommentFile("myfile.xml");

            SetFileExistsAndLoadXml(commentFile);
            CRefPath crefPath = CRefPath.Parse("T:Nothing");

            XmlCodeComment result = commentFile.GetSummary(crefPath);

            Assert.AreSame(XmlCodeComment.Empty, result);
        }
예제 #14
0
        public void WhenCRefIsValid_GetComment_GetsCorrectComment()
        {
            XmlCommentFile commentFile = CreateXmlCommentFile("myfile.xml");

            SetFileExistsAndLoadXml(commentFile);
            CRefPath crefPath = CRefPath.Parse("T:Namespace.MyType");

            XmlCodeComment result = commentFile.GetComment(crefPath);

            Assert.AreNotSame(XmlCodeComment.Empty, result);
            Assert.AreEqual(1, result.Elements.Count);
        }
예제 #15
0
        public void WhenCRefIsErrorPath_GetComment_ReturnsEmpty()
        {
            XmlCommentFile commentFile = CreateXmlCommentFile("myfile.xml");

            SetFileExistsAndLoadXml(commentFile);
            CRefPath crefPath = new CRefPath();

            crefPath.PathType = CRefTypes.Error;

            XmlCodeComment result = commentFile.GetComment(crefPath);

            Assert.AreSame(XmlCodeComment.Empty, result);
        }
예제 #16
0
        protected override Entry GenerateDocumentForAssembly(DocumentMap map, DocumentedAssembly current, ref int fileCounter)
        {
            AssemblyDef assembly = AssemblyDef.Create(current.FileName);

            current.LoadedAssembly = assembly;

            XmlCommentFile commentFile = new XmlCommentFile(current.XmlFileName, new FileSystem());

            commentFile.Load();
            ICommentSource xmlComments = commentFile; // not nice having to call load then cast we wil have to fix this


            Entry assemblyEntry = this.EntryCreator.Create(assembly, System.IO.Path.GetFileName(current.FileName), xmlComments);

            current.UniqueId           = assembly.UniqueId = fileCounter++;
            assemblyEntry.Key          = assembly.GetGloballyUniqueId();
            assemblyEntry.IsSearchable = false;

            // Add the namespaces to the document map
            Dictionary <string, List <TypeDef> > typesInNamespaces = assembly.GetTypesInNamespaces();

            foreach (KeyValuePair <string, List <TypeDef> > currentNamespace in typesInNamespaces)
            {
                if (string.IsNullOrEmpty(currentNamespace.Key) || currentNamespace.Value.Count == 0)
                {
                    continue;
                }
                string namespaceSubKey = this.BuildSubkey(currentNamespace);

                Entry namespaceEntry = this.FindByKey(map, assemblyEntry.Key, namespaceSubKey, false);
                if (namespaceEntry == null)
                {
                    namespaceEntry              = this.EntryCreator.Create(currentNamespace, currentNamespace.Key, xmlComments, assemblyEntry);
                    namespaceEntry.Key          = assemblyEntry.Key;
                    namespaceEntry.SubKey       = namespaceSubKey;
                    namespaceEntry.IsSearchable = false;
                }

                // Add the types from that namespace to its map
                foreach (TypeDef currentType in currentNamespace.Value)
                {
                    if (currentType.Name.StartsWith("<"))
                    {
                        continue;
                    }
                    PreEntryAddedEventArgs e = new PreEntryAddedEventArgs(currentType);
                    this.OnPreEntryAdded(e);
                    if (!e.Filter)
                    {
                        Entry typeEntry = this.EntryCreator.Create(currentType, currentType.GetDisplayName(false), xmlComments, namespaceEntry);
                        typeEntry.Key          = currentType.GetGloballyUniqueId();
                        typeEntry.IsSearchable = true;

                        // For some elements we will not want to load the child objects
                        // this is currently for System.Enum derived values.
                        if (
                            currentType.InheritsFrom != null && currentType.InheritsFrom.GetFullyQualifiedName() == "System.Enum" ||
                            currentType.IsDelegate)
                        {
                            // Ignore children
                        }
                        else
                        {
                            this.GenerateTypeMap(currentType, typeEntry, xmlComments);
                            typeEntry.Children.Sort();
                        }

                        namespaceEntry.Children.Add(typeEntry);
                    }
                }
                if (namespaceEntry.Children.Count > 0)
                {
                    assemblyEntry.Children.Add(namespaceEntry);
                    namespaceEntry.Children.Sort();
                }
            }

            assemblyEntry.Children.Sort();

            return(assemblyEntry);
        }
예제 #17
0
        protected override Entry GenerateDocumentForAssembly(DocumentMap map, DocumentedAssembly current, ref int fileCounter)
        {
            AssemblyDef assembly = AssemblyDef.Create(current.FileName);

            current.LoadedAssembly = assembly;

            XmlCommentFile commentFile = new XmlCommentFile(current.XmlFileName, new FileSystem());

            commentFile.Load();
            ICommentSource xmlComments = commentFile; // TODO: calling load then casting is not nice

            Entry assemblyEntry = this.EntryCreator.Create(assembly, System.IO.Path.GetFileName(current.FileName), xmlComments);

            current.UniqueId           = assembly.UniqueId = fileCounter++;
            assemblyEntry.Key          = assembly.GetGloballyUniqueId();
            assemblyEntry.IsSearchable = false;
            Entry namespaceEntry = null;

            // Add the namespaces to the document map
            Dictionary <string, List <TypeDef> > typesInNamespaces = assembly.GetTypesInNamespaces();

            foreach (KeyValuePair <string, List <TypeDef> > currentNamespace in typesInNamespaces)
            {
                if (string.IsNullOrEmpty(currentNamespace.Key) || currentNamespace.Value.Count == 0)
                {
                    continue;
                }
                string namespaceSubKey = this.BuildSubkey(currentNamespace);

                namespaceEntry = Find(map, namespaceSubKey);
                if (namespaceEntry == null)
                {
                    namespaceEntry              = this.EntryCreator.Create(currentNamespace, currentNamespace.Key, xmlComments);
                    namespaceEntry.Key          = assemblyEntry.Key;
                    namespaceEntry.SubKey       = namespaceSubKey;
                    namespaceEntry.IsSearchable = false;
                }

                // Add the types from that namespace to its map
                foreach (TypeDef currentType in currentNamespace.Value)
                {
                    if (currentType.Name.StartsWith("<"))
                    {
                        continue;
                    }
                    PreEntryAddedEventArgs e = new PreEntryAddedEventArgs(currentType);
                    this.OnPreEntryAdded(e);
                    if (!e.Filter)
                    {
                        Entry typeEntry = this.EntryCreator.Create(currentType, currentType.GetDisplayName(false), xmlComments, namespaceEntry);
                        typeEntry.Key          = currentType.GetGloballyUniqueId();
                        typeEntry.IsSearchable = true;

                        // For some elements we will not want to load the child objects
                        // this is currently for System.Enum derived values.
                        if (
                            currentType.InheritsFrom != null && currentType.InheritsFrom.GetFullyQualifiedName() == "System.Enum" ||
                            currentType.IsDelegate)
                        {
                            // Ignore children
                        }
                        else
                        {
                            this.GenerateTypeMap(currentType, typeEntry, xmlComments);
                            typeEntry.Children.Sort();
                        }

                        namespaceEntry.Children.Add(typeEntry);
                    }
                }
                if (namespaceEntry.Children.Count > 0)
                {
                    namespaceEntry.Children.Sort();
                    // we still need to add here otherwise we get duplicate namespaces.
                    assemblyEntry.Children.Add(namespaceEntry);
                    if (!map.Contains(namespaceEntry))
                    {
                        map.Add(namespaceEntry);
                    }
                    else
                    {
                        // update the type list is the contianing namespace
                        KeyValuePair <string, List <TypeDef> > original = (KeyValuePair <string, List <TypeDef> >)namespaceEntry.Item;
                        original.Value.AddRange(currentNamespace.Value);
                    }
                }
            }

            map.Sort();

            // we are not interested in assemblies being used here so make them childless
            return(this.EntryCreator.Create(null, string.Empty, null));
        }
예제 #18
0
 private void SetFileExistsAndLoadXml(XmlCommentFile commentFile)
 {
     _fileSystem.Setup(p => p.FileExists(It.IsAny <string>())).Returns(true);
     commentFile.Load();
 }