public void When_xml_docs_is_read_for_cecil_type_then_it_works() { // Arranage var assemblyPath = typeof(XmlDocsExtensionsTests).Assembly.CodeBase.Replace("file:///", string.Empty); var xmlPath = assemblyPath.Replace(".dll", ".xml"); var assembly = AssemblyDefinition.ReadAssembly(assemblyPath); var module = assembly.Modules.Last(); var type = module.GetTypes().Single(t => t.Name.Contains(nameof(MyTest))); var method = type.Methods.First(m => m.Name == nameof(MyTest.MyMethod)); var document = XmlDocs.LoadDocument(xmlPath); // Act var typeSummary = type.GetXmlDocsTag("summary", document); var constructorSummary = type.Methods.First(m => m.IsConstructor).GetXmlDocsTag("summary", document); var property = type.Properties.First().GetXmlDocsSummary(document); var methodSummary = method.GetXmlDocsTag("summary", document); var parameter = method.Parameters.Last().GetXmlDocs(document); var returnParameter = method.MethodReturnType.GetXmlDocs(document); // Assert Assert.Equal("My class.", typeSummary); Assert.Equal("My constructor.", constructorSummary); Assert.Equal("My property.", property); Assert.Equal("My method.", methodSummary); Assert.Equal("My param.", parameter); Assert.Equal("My return.", returnParameter); }
public void WhenTypeInheritsFromGenericType_ThenMethodAndPropertyWithGenericParametersResolvesCorrectXml() { // Arranage var assemblyPath = typeof(XmlDocsExtensionsTests).Assembly.CodeBase.Replace("file:///", string.Empty); var xmlPath = assemblyPath.Replace(".dll", ".xml"); var assembly = AssemblyDefinition.ReadAssembly(assemblyPath); var module = assembly.Modules.Last(); var type = module.GetTypes().Single(t => t.Name.Contains("BaseGenericClass")); var method = type.Methods.First(m => m.Name == nameof(InheritedGenericClass.SingleAsync)); var method2 = type.Methods.First(m => m.Name == nameof(InheritedGenericClass.MultiAsync)); var document = XmlDocs.LoadDocument(xmlPath); //// Act var summaryMethod = method.GetXmlDocsTag("summary", document); var summaryMethod2 = method2.GetXmlDocsTag("summary", document); var summaryProperty = type.Properties.First().GetXmlDocsSummary(document); //// Assert Assert.Equal("SingleAsync", summaryMethod); Assert.Equal("MultiAsync", summaryMethod2); Assert.Equal("Baz", summaryProperty); }