示例#1
0
        public void when_reading_list_then_can_access_type_header_and_items()
        {
            var list = DocReader.Read(assembly).Traverse().OfType <List>().Single();

            Assert.Equal(ListType.Table, list.Type);
            Assert.NotNull(list.Header);
            Assert.Equal(1, list.Items.Count());
        }
示例#2
0
        public void when_reading_assembly_then_can_access_source_document()
        {
            var xmlFile = Path.ChangeExtension(assembly.Location, ".xml");
            var members = DocReader.Read(assembly);

            Assert.NotNull(members.Xml);
            Assert.Equal(xmlFile, new Uri(members.Xml.BaseUri).LocalPath);
        }
示例#3
0
        public void when_reading_assembly_then_succeeds()
        {
            var clr = new FileInfo(@"DemoProject.dll").FullName;

            var countClr = new CountingVisitor("NuDoq-net");

            DocReader.Read(Assembly.LoadFrom(clr)).Accept(countClr);
        }
示例#4
0
        public void when_xml_not_found_alongside_assembly_then_throws()
        {
            var clr  = new FileInfo(@"..\..\..\Demo\DemoProject\bin\DemoProject.dll").FullName;
            var temp = Path.GetTempFileName();

            File.Copy(clr, temp, true);

            Assert.Throws <FileNotFoundException>(() => DocReader.Read(Assembly.LoadFrom(temp)).Traverse().Count());
        }
示例#5
0
        public void when_reading_extension_method_then_provides_typed_member()
        {
            var typed = DocReader.Read(assembly)
                        .Elements
                        .OfType <ExtensionMethod>()
                        .FirstOrDefault();

            Assert.NotNull(typed);
            Assert.NotNull(typed.Info);
        }
示例#6
0
        public void when_reading_out_element_then_can_read_parameter_doc()
        {
            var member = DocReader.Read(Assembly.GetExecutingAssembly());
            var method = member.Elements.OfType <Method>()
                         .FirstOrDefault(m => m.Info?.DeclaringType == typeof(CustomXml) && m.Info?.Name == nameof(CustomXml.Out));

            Assert.NotNull(method);
            Assert.Equal("p1", method.Elements.OfType <Param>().First().Name);
            Assert.Equal("out", method.Elements.OfType <Param>().First().Elements.OfType <Text>().First().Content);
        }
示例#7
0
        public void when_documenting_generic_method_on_generic_type_then_sets_info()
        {
            var map = new MemberIdMap();

            map.Add(typeof(SampleGeneric <,>));
            var typeId = map.FindId(typeof(SampleGeneric <,>).GetMethods()[0]);
            var member = DocReader.Read(assembly).Elements.OfType <Method>().Where(c => c.Id == typeId).FirstOrDefault();

            Assert.NotNull(member);
            Assert.NotNull(member.Info);
        }
示例#8
0
        public void when_reading_indexer_property_then_succeeds()
        {
            var member = DocReader.Read(Assembly.GetExecutingAssembly(), new ReaderOptions {
                KeepNewLinesInText = true
            });
            var method = member.Elements.OfType <Property>()
                         .FirstOrDefault(m => m.Info?.DeclaringType == typeof(CustomXml) && ((PropertyInfo)m.Info !).GetIndexParameters().Length > 0);

            Assert.NotNull(method);
            Assert.Equal("indexed", method.ToText());
        }
示例#9
0
        public void when_reading_provider_then_reads_remarks()
        {
            var map = new MemberIdMap();

            map.Add(assembly);

            var id = map.FindId(typeof(Provider));

            Assert.NotNull(id);

            var member = DocReader.Read(typeof(Provider).Assembly).Elements.OfType <Member>().FirstOrDefault(x => x.Id == id);

            Assert.NotNull(member);

            var element = member.Elements.OfType <Remarks>().FirstOrDefault();

            Assert.NotNull(element);

            var children = element.Elements.ToList();

            Assert.Equal(3, children.Count);

            Assert.IsType <Text>(children[0]);
            Assert.IsType <Example>(children[1]);
            Assert.IsType <List>(children[2]);

            Assert.Equal("Remarks.", ((Text)children[0]).Content);
            Assert.Equal("Example with code:", ((Example)children[1]).Elements.OfType <Text>().First().Content);
            Assert.Equal(@"var code = new Code();
var length = code.Length + 1;", ((Example)children[1]).Elements.OfType <Code>().First().Content);

            Assert.Equal("inline code", ((Example)children[1]).Elements.OfType <Para>().First().Elements.OfType <C>().First().Content);

            Assert.Equal("Term", ((List)children[2])
                         .Elements.OfType <ListHeader>().First()
                         .Elements.OfType <Term>().First().Elements.OfType <Text>().First().Content);
            Assert.Equal("Description", ((List)children[2])
                         .Elements.OfType <ListHeader>().First()
                         .Elements.OfType <Description>().First().Elements.OfType <Text>().First().Content);
            Assert.NotNull(((List)children[2]).Header.Term);
            Assert.NotNull(((List)children[2]).Header.Description);

            Assert.Equal("ItemTerm", ((List)children[2])
                         .Elements.OfType <Item>().First()
                         .Elements.OfType <Term>().First().Elements.OfType <Text>().First().Content);

            Assert.NotNull(((List)children[2]).Items.First().Term);
            Assert.NotNull(((List)children[2]).Items.First().Description);

            Assert.Equal("ItemDescription", ((List)children[2])
                         .Elements.OfType <Item>().First()
                         .Elements.OfType <Description>().First().Elements.OfType <Text>().First().Content);
        }
示例#10
0
        public void when_reading_element_then_can_access_xml_line_info()
        {
            var xmlFile = Path.ChangeExtension(assembly.Location, ".xml");
            var member  = DocReader.Read(xmlFile).Elements.SelectMany(x => x.Traverse()).OfType <Summary>().First();

            var lineInfo = member as IXmlLineInfo;

            Assert.NotNull(lineInfo);
            Assert.True(lineInfo.HasLineInfo());
            Assert.NotEqual(0, lineInfo.LineNumber);
            Assert.NotEqual(0, lineInfo.LinePosition);
        }
示例#11
0
        public void when_reading_weird_indenting_then_preserves_text()
        {
            var member = DocReader.Read(Assembly.GetExecutingAssembly(), new ReaderOptions {
                KeepNewLinesInText = true
            });
            var method = member.Elements.OfType <Method>()
                         .FirstOrDefault(m => m.Info?.DeclaringType == typeof(CustomXml) && m.Info?.Name == nameof(CustomXml.WeirdIndenting));

            Assert.NotNull(method);
            Assert.Equal(@"Begin
End", method.ToText());
        }
示例#12
0
 public void when_rendering_to_string_then_renders_tag_name_for_unknown_elements()
 {
     DocReader.Read(typeof(IProvider).Assembly)
     .Elements
     .SelectMany(x => x.Traverse())
     .OfType <UnknownElement>()
     .Select(x => new { Element = x, ToString = x.ToString() })
     .ToList()
     .ForEach(x => Assert.True(
                  x.ToString.Contains("<" + x.Element.Xml.Name.LocalName + ">"),
                  "Element " + x.Element.ToString() + " ToString() was expected to contain <" + x.Element.Xml.Name.LocalName + ">"));
 }
示例#13
0
        public void when_parsing_property_then_reads_value_tag()
        {
            var map = new MemberIdMap();

            map.Add(typeof(Sample));
            var typeId = map.FindId(typeof(Sample).GetProperties()[0]);
            var member = DocReader.Read(assembly).Elements.OfType <Property>().Where(c => c.Id == typeId).Single();

            var element = member.Elements.OfType <Value>().Single();

            Assert.Equal("The id of this sample.", element.ToText());
        }
示例#14
0
 public void when_rendering_to_string_then_renders_tag_name_for_known_elements()
 {
     DocReader.Read(typeof(IProvider).Assembly)
     .Elements
     .SelectMany(x => x.Traverse())
     .Where(x => !(x is Member || x is UnknownElement))
     .Select(x => new { Element = x, ToString = x.ToString() })
     .ToList()
     .ForEach(x => Assert.True(
                  x.ToString.StartsWith("<" + x.Element.GetType().Name.ToLowerInvariant() + ">"),
                  "Element " + x.Element.ToString() + " ToString() was expected to start with <" + x.Element.GetType().Name.ToLowerInvariant() + ">"));
 }
示例#15
0
        public void when_visiting_xml_then_adds_members()
        {
            var member  = DocReader.Read(Path.ChangeExtension(typeof(ProviderType).Assembly.Location, ".xml"));
            var visitor = new XmlVisitor();

            member.Accept(visitor);

            Assert.Equal("doc", visitor.Xml.Root.Name);
            Assert.Equal("members", visitor.Xml.Root.Elements().First().Name);

            //WriteXml(visitor.Xml);
        }
示例#16
0
        public void when_parsing_empty_summary_then_removes_empty_text()
        {
            var map = new MemberIdMap();

            map.Add(typeof(Provider));
            var typeId = map.FindId(typeof(Provider));
            var member = DocReader.Read(assembly).Elements.OfType <Class>().Where(c => c.Id == typeId).Single();

            var element = member.Elements.OfType <Summary>().Single();

            Assert.Empty(element.ToText());
        }
示例#17
0
        public void when_parsing_empty_code_then_removes_empty_text()
        {
            var map = new MemberIdMap();

            map.Add(typeof(IProvider));
            var typeId = map.FindId(typeof(IProvider));
            var member = DocReader.Read(assembly).Elements.OfType <Interface>().Where(c => c.Id == typeId).Single();

            var element = member.Elements.OfType <Remarks>().Single().Elements.OfType <Code>().Single();

            Assert.Equal(0, element.Content.Length);
        }
示例#18
0
        public void when_reading_unknown_element_then_can_be_empty()
        {
            var member = DocReader.Read(Assembly.GetExecutingAssembly());
            var method = member.Elements.OfType <Method>()
                         .FirstOrDefault(m => m.Info?.DeclaringType == typeof(CustomXml) && m.Info?.Name == nameof(CustomXml.Preliminary));

            Assert.NotNull(method);
            Assert.Equal("preliminary", method.Elements.OfType <UnknownElement>().First().Xml.Name.LocalName);

            Assert.Empty(method.Elements.OfType <UnknownElement>().First().Elements);
            Assert.Empty(method.Elements.OfType <UnknownElement>().First().Attributes);
        }
示例#19
0
        public void when_writing_xml_then_can_roundtrip()
        {
            var originalXml = XDocument.Load(Path.ChangeExtension(typeof(ProviderType).Assembly.Location, ".xml"));
            var member      = DocReader.Read(typeof(ProviderType).Assembly);
            var visitor     = new XmlVisitor();

            member.Accept(visitor);

            //WriteXml(originalXml.Normalize(), "C:\\Temp\\source.xml");
            //WriteXml(visitor.Xml.Normalize(), "C:\\Temp\\target.xml");

            //Assert.True(originalXml.NormalizedEquals(visitor.Xml));
        }
示例#20
0
        public void when_visiting_xml_then_adds_source_assembly()
        {
            var member  = DocReader.Read(typeof(ProviderType).Assembly);
            var visitor = new XmlVisitor();

            member.Accept(visitor);

            Assert.Equal("doc", visitor.Xml.Root.Name);
            Assert.Equal("assembly", visitor.Xml.Root.Elements().First().Name);
            Assert.Equal(typeof(ProviderType).Assembly.GetName().Name, visitor.Xml.Root.Elements().First().Elements().First().Value);

            //WriteXml(visitor.Xml);
        }
示例#21
0
        public void when_parsing_unknown_element_then_reads_inner_content()
        {
            var map = new MemberIdMap();

            map.Add(typeof(IProvider));
            var typeId = map.FindId(typeof(IProvider));
            var member = DocReader.Read(assembly).Elements.OfType <TypeDeclaration>().Where(c => c.Id == typeId).Single();

            var element = member.Elements.OfType <Summary>().Single();

            Assert.True(element.Elements.OfType <UnknownElement>().Any());
            Assert.True(element.Elements.OfType <UnknownElement>().Single().Elements.OfType <Text>().Any());
        }
示例#22
0
        public void when_reading_document_then_visits_document()
        {
            var             xmlFile    = Path.ChangeExtension(assembly.Location, ".xml");
            var             members    = DocReader.Read(xmlFile);
            DocumentMembers docMembers = null;

            members.Accept(new DelegateVisitor(new VisitorDelegates
            {
                VisitDocument = doc => docMembers = doc,
            }));

            Assert.NotNull(docMembers);
        }
示例#23
0
        public void when_rendering_typeparamref_then_renders_type_param_name()
        {
            var map = new MemberIdMap();

            map.Add(typeof(SampleGeneric <,>));
            var id = map.FindId(typeof(SampleGeneric <,>));

            var member = DocReader.Read(typeof(Sample).Assembly).Elements.OfType <Class>().Single(x => x.Id == id);

            var actual   = member.Elements.OfType <Summary>().First().ToText();
            var expected = "Sample with generic type T.";

            Assert.Equal(expected, actual);
        }
示例#24
0
        public void when_rendering_paramref_then_renders_param_name()
        {
            var map = new MemberIdMap();

            map.Add(typeof(Sample));
            var id = map.FindId(typeof(Sample).GetMethod("GetValue"));

            var member = DocReader.Read(typeof(SampleStruct).Assembly).Elements.OfType <Method>().Single(x => x.Id == id);

            var actual   = member.Elements.OfType <Summary>().First().ToText();
            var expected = "Gets the value for the given id.";

            Assert.Equal(expected, actual);
        }
示例#25
0
        public void when_reading_from_assembly_then_provides_event_info()
        {
            var map = new MemberIdMap();

            map.Add(assembly);
            var providerId = map.FindId(typeof(Provider));

            var member = DocReader.Read(assembly).Elements.OfType <Event>().FirstOrDefault();

            Assert.NotNull(member);
            Assert.NotNull(member.Info);
            Assert.Same(typeof(Provider).GetEvents()[0], member.Info);
            Assert.True(member.Kind.HasFlag(MemberKinds.Event));
        }
示例#26
0
        public void when_rendering_see_then_renders_cref()
        {
            var map = new MemberIdMap();

            map.Add(typeof(SampleExtensions));
            var id = map.FindId(typeof(SampleExtensions));

            var member = DocReader.Read(typeof(SampleExtensions).Assembly).Elements.OfType <Class>().Single(x => x.Id == id);

            var actual   = member.Elements.OfType <Summary>().First().ToText();
            var expected = "Extension class for Demo.Sample.";

            Assert.Equal(expected, actual);
        }
示例#27
0
        public void when_reading_from_assembly_then_provides_nested_type_info()
        {
            var map = new MemberIdMap();

            map.Add(assembly);
            var providerId = map.FindId(typeof(Sample.NestedType));

            var member = DocReader.Read(assembly).Elements.OfType <TypeDeclaration>().Where(c => c.Id == providerId).FirstOrDefault();

            Assert.NotNull(member);
            Assert.NotNull(member.Info);
            Assert.Same(typeof(Sample.NestedType), member.Info);
            Assert.True(member.Kind.HasFlag(MemberKinds.Type));
        }
示例#28
0
        public void when_rendering_c_then_renders_text()
        {
            var map = new MemberIdMap();

            map.Add(typeof(SampleStruct));
            var id = map.FindId(typeof(SampleStruct));

            var member = DocReader.Read(typeof(SampleStruct).Assembly).Elements.OfType <Struct>().Single(x => x.Id == id);

            var actual   = member.Elements.OfType <Summary>().First().ToText();
            var expected = "Sample struct.";

            Assert.Equal(expected, actual);
        }
示例#29
0
        public void when_documenting_generic_type_then_can_match_with_mapper()
        {
            var map = new MemberIdMap();

            map.Add(assembly);
            var typeId = map.FindId(typeof(SampleGeneric <,>));

            var member = DocReader.Read(assembly).Elements.OfType <Class>().Where(c => c.Id == typeId).FirstOrDefault();

            Assert.NotNull(member);
            Assert.NotNull(member.Info);
            Assert.Same(typeof(SampleGeneric <,>), member.Info);
            Assert.True(member.Kind.HasFlag(MemberKinds.Class));
            Assert.True(member.Kind.HasFlag(MemberKinds.Type));
        }
示例#30
0
        public void when_reading_from_assembly_then_provides_struct_info()
        {
            var map = new MemberIdMap();

            map.Add(assembly);
            var typeId = map.FindId(typeof(SampleStruct));

            var member = DocReader.Read(assembly).Elements.OfType <Struct>().Where(c => c.Id == typeId).FirstOrDefault();

            Assert.NotNull(member);
            Assert.NotNull(member.Info);
            Assert.Same(typeof(SampleStruct), member.Info);
            Assert.True(member.Kind.HasFlag(MemberKinds.Struct));
            Assert.True(member.Kind.HasFlag(MemberKinds.Type));
        }