Example #1
0
        private void Run()
        {
            try
            {
                if (OutputPath != null)
                {
                    if (!Directory.Exists(OutputPath))
                    {
                        Directory.CreateDirectory(OutputPath);
                    }
                }

                using (var assembly = new AssemblyReflector(AssemblyFileName, _logger))
                {
                    var publicApiReferenceFileName = Path.GetFileNameWithoutExtension(AssemblyFileName) + ".html";
                    var publicApiSlashdocFileName  = Path.GetFileNameWithoutExtension(AssemblyFileName) + ".xml";
                    if (OutputPath != null)
                    {
                        publicApiReferenceFileName = Path.Combine(OutputPath, publicApiReferenceFileName);
                        publicApiSlashdocFileName  = Path.Combine(OutputPath, publicApiSlashdocFileName);
                    }

                    var slashdocFileName = Path.ChangeExtension(AssemblyFileName, ".xml");
                    var slashdoc         = new SlashdocDictionary();
                    if (File.Exists(slashdocFileName))
                    {
                        using (var slashdocStream = new FileStream(slashdocFileName, FileMode.Open, FileAccess.Read))
                        {
                            SlashdocProcessor.WritePublicApiSlashdoc(assembly, slashdocStream, publicApiSlashdocFileName);
                        }

                        using (var slashdocStream = new FileStream(slashdocFileName, FileMode.Open, FileAccess.Read))
                        {
                            slashdoc = SlashdocReader.Parse(slashdocStream);
                        }
                    }
                    else
                    {
                        _logger.LogWarning(string.Format(CultureInfo.InvariantCulture, "Could not open slashdoc file '{0}'.", slashdocFileName));
                    }

                    var language = new CSharpSignatureProvider();
                    var title    = string.Format(CultureInfo.InvariantCulture, "{0} public API reference", assembly.SimpleName);
                    using (var apiReferenceWriter = new ApiReferenceHtmlWriter(publicApiReferenceFileName, title, slashdoc, language, _logger))
                    {
                        apiReferenceWriter.EnableMissingSummaryWarnings = EnableMissingSummaryWarnings;
                        apiReferenceWriter.DescribeAssembly(assembly);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }
        }
        public void ShouldLookTypesByName()
        {
            using (var assembly = new AssemblyReflector(@"NuDocTests.exe", new Mock<ILog>().Object))
            {
                Assert.That(assembly.LookupType("System.Guid"), Is.Null, "Lookup of a type which isn't in the assembly returns null.");

                var class1 = assembly.LookupType("TestData.Xyz.Foo.TestClass");
                Assert.That(class1, Is.Not.Null, "TestClass lookup succeeds.");

                var genericClass = assembly.LookupType("TestData.Xyz.Foo.TestGeneric`2");
                Assert.That(genericClass, Is.Not.Null, "Generic class lookup succeeds.");
            }
        }
        public void ShouldGenerateSlashdocForPublicTypesAndMembersOnly()
        {
            var fileName = @"slashdoc.xml";

            File.Delete(fileName);

            using (var assembly = new AssemblyReflector(@"NuDocTests.exe", new Mock<ILog>().Object))
            {
                using (var slashdocStream = new FileStream(@"NuDocTests.xml", FileMode.Open, FileAccess.Read))
                {
                    SlashdocProcessor.WritePublicApiSlashdoc(assembly, slashdocStream, fileName);
                }
            }

            using (var xmlReader = XmlReader.Create(new FileStream(fileName, FileMode.Open, FileAccess.Read)))
            {
                var doc = new XPathDocument(xmlReader);
                var navigator = doc.CreateNavigator();
                Assert.That(navigator.SelectSingleNode("/doc"), Is.Not.Null);
                Assert.That(navigator.SelectSingleNode("/doc/assembly/name/text()").Value, Is.EqualTo("NuDocTests"), "assembly name is preserved.");

                Assert.That(
                    InnerXmlWithoutWhitespace(navigator.SelectSingleNode("/doc/members/member[@name='T:TestData.Xyz.Foo.SlashdocTestClass']")),
                    Is.EqualTo("<summary>Aclass.</summary>"),
                    "slashdoc for the public type SlashdocTestClass is preserved.");
                Assert.That(
                    InnerXmlWithoutWhitespace(navigator.SelectSingleNode("/doc/members/member[@name='M:TestData.Xyz.Foo.SlashdocTestClass.DoSomething(System.DateTime)']")),
                    Is.EqualTo("<summary>IfIcouldonlyrememberwhat.</summary><paramname=\"when\">Andwhen.</param>"),
                    "slashdoc for the public member SlashdocTestClass.DoSomething is preserved.");
                Assert.That(
                    navigator.SelectSingleNode("/doc/members/member[@name='M:TestData.Xyz.Foo.SlashdocTestClass.PrivateMethod']"),
                    Is.Null,
                    "slashdoc for the private member SlashdocTestClass.PrivateMethod is NOT preserved.");

                Assert.That(
                    navigator.SelectSingleNode("/doc/members/member[@name='T:TestData.Xyz.Foo.InternalClass']"),
                    Is.Null,
                    "slashdoc for the non-public type InternalClass is NOT preserved.");

                Assert.That(navigator.SelectSingleNode("/doc/members/member[@name='T:No.Such.Type']"), Is.Null);
            }
        }
Example #4
0
        private void Run()
        {
            try
            {
                if (OutputPath != null)
                {
                    if (!Directory.Exists(OutputPath))
                    {
                        Directory.CreateDirectory(OutputPath);
                    }
                }

                using (var assembly = new AssemblyReflector(AssemblyFileName, _logger))
                {
                    var publicApiReferenceFileName = Path.GetFileNameWithoutExtension(AssemblyFileName) + ".html";
                    var publicApiSlashdocFileName = Path.GetFileNameWithoutExtension(AssemblyFileName) + ".xml";
                    if (OutputPath != null)
                    {
                        publicApiReferenceFileName = Path.Combine(OutputPath, publicApiReferenceFileName);
                        publicApiSlashdocFileName = Path.Combine(OutputPath, publicApiSlashdocFileName);
                    }

                    var slashdocFileName = Path.ChangeExtension(AssemblyFileName, ".xml");
                    var slashdoc = new SlashdocDictionary();
                    if (File.Exists(slashdocFileName))
                    {
                        using (var slashdocStream = new FileStream(slashdocFileName, FileMode.Open, FileAccess.Read))
                        {
                            SlashdocProcessor.WritePublicApiSlashdoc(assembly, slashdocStream, publicApiSlashdocFileName);
                        }

                        using (var slashdocStream = new FileStream(slashdocFileName, FileMode.Open, FileAccess.Read))
                        {
                            slashdoc = SlashdocReader.Parse(slashdocStream);
                        }
                    }
                    else
                    {
                        _logger.LogWarning(string.Format(CultureInfo.InvariantCulture, "Could not open slashdoc file '{0}'.", slashdocFileName));
                    }

                    var language = new CSharpSignatureProvider();
                    var title = string.Format(CultureInfo.InvariantCulture, "{0} public API reference", assembly.SimpleName);
                    using (var apiReferenceWriter = new ApiReferenceHtmlWriter(publicApiReferenceFileName, title, slashdoc, language, _logger))
                    {
                        apiReferenceWriter.EnableMissingSummaryWarnings = EnableMissingSummaryWarnings;
                        apiReferenceWriter.DescribeAssembly(assembly);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }
        }