<commit_before><commit_msg>Basic method id tests.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using static Utility;

namespace DotNetApis.Cecil.UnitTests
{
    public class IdMethodTests
    {
        [Fact]
        public void Basic_InTopLevelType()
        {
            var code = @"public class SampleClass { public void SampleMethod() { } }";
            var assembly = Compile(code).Dll;
            var type = assembly.Modules.SelectMany(x => x.Types).Single(x => x.Name == "SampleClass");
            var method = type.Methods.Single(x => x.Name == "SampleMethod");
            Assert.Equal("M:SampleClass.SampleMethod", method.XmldocIdentifier());
            Assert.Equal("SampleClass/SampleMethod()", method.DnaId());
            var name = method.MemberFriendlyName();
            Assert.Equal("SampleMethod", name.SimpleName);
            Assert.Equal("SampleClass.SampleMethod", name.QualifiedName);
            Assert.Equal("SampleClass.SampleMethod", name.FullyQualifiedName);
        }

        [Fact]
        public void Basic_InNamespacedType()
        {
            var code = @"namespace MyNamespace { public class SampleClass { public void SampleMethod() { } } }";
            var assembly = Compile(code).Dll;
            var type = assembly.Modules.SelectMany(x => x.Types).Single(x => x.Name == "SampleClass");
            var method = type.Methods.Single(x => x.Name == "SampleMethod");
            Assert.Equal("M:MyNamespace.SampleClass.SampleMethod", method.XmldocIdentifier());
            Assert.Equal("MyNamespace.SampleClass/SampleMethod()", method.DnaId());
            var name = method.MemberFriendlyName();
            Assert.Equal("SampleMethod", name.SimpleName);
            Assert.Equal("SampleClass.SampleMethod", name.QualifiedName);
            Assert.Equal("MyNamespace.SampleClass.SampleMethod", name.FullyQualifiedName);
        }

        [Fact]
        public void Nested()
        {
            var code = @"public class OuterClass { public class SampleClass { public void SampleMethod() { } } }";
            var assembly = Compile(code).Dll;
            var outer = assembly.Modules.SelectMany(x => x.Types).Single(x => x.Name == "OuterClass");
            var type = outer.NestedTypes.Single(x => x.Name == "SampleClass");
            var method = type.Methods.Single(x => x.Name == "SampleMethod");
            Assert.Equal("M:OuterClass.SampleClass.SampleMethod", method.XmldocIdentifier());
            Assert.Equal("OuterClass/SampleClass/SampleMethod()", method.DnaId());
            var name = method.MemberFriendlyName();
            Assert.Equal("SampleMethod", name.SimpleName);
            Assert.Equal("OuterClass.SampleClass.SampleMethod", name.QualifiedName);
            Assert.Equal("OuterClass.SampleClass.SampleMethod", name.FullyQualifiedName);
        }

        [Fact]
        public void Nested_InNamespace()
        {
            var code = @"namespace Ns { public class OuterClass { public class SampleClass { public void SampleMethod() { } } } }";
            var assembly = Compile(code).Dll;
            var outer = assembly.Modules.SelectMany(x => x.Types).Single(x => x.Name == "OuterClass");
            var type = outer.NestedTypes.Single(x => x.Name == "SampleClass");
            var method = type.Methods.Single(x => x.Name == "SampleMethod");
            Assert.Equal("M:Ns.OuterClass.SampleClass.SampleMethod", method.XmldocIdentifier());
            Assert.Equal("Ns.OuterClass/SampleClass/SampleMethod()", method.DnaId());
            var name = method.MemberFriendlyName();
            Assert.Equal("SampleMethod", name.SimpleName);
            Assert.Equal("OuterClass.SampleClass.SampleMethod", name.QualifiedName);
            Assert.Equal("Ns.OuterClass.SampleClass.SampleMethod", name.FullyQualifiedName);
        }

        [Fact]
        public void SingleGenericParameter()
        {
            var code = @"public class SampleClass { public void SampleMethod<TFirst>() { } }";
            var assembly = Compile(code).Dll;
            var type = assembly.Modules.SelectMany(x => x.Types).Single(x => x.Name == "SampleClass");
            var method = type.Methods.Single(x => x.Name == "SampleMethod");
            Assert.Equal("M:SampleClass.SampleMethod``1", method.XmldocIdentifier());
            Assert.Equal("SampleClass/SampleMethod''1()", method.DnaId());
            var name = method.MemberFriendlyName();
            Assert.Equal("SampleMethod<TFirst>", name.SimpleName);
            Assert.Equal("SampleClass.SampleMethod<TFirst>", name.QualifiedName);
            Assert.Equal("SampleClass.SampleMethod<TFirst>", name.FullyQualifiedName);
        }

        [Fact]
        public void Nested_GenericParameters()
        {
            var code = @"public class OuterClass<TFirst, TSecond> { public class SampleClass<TThird> { public void SampleMethod<TFourth>() { } } }";
            var assembly = Compile(code).Dll;
            var outer = assembly.Modules.SelectMany(x => x.Types).Single(x => x.Name == "OuterClass`2");
            var type = outer.NestedTypes.Single(x => x.Name == "SampleClass`1");
            var method = type.Methods.Single(x => x.Name == "SampleMethod");
            Assert.Equal("M:OuterClass`2.SampleClass`1.SampleMethod``1", method.XmldocIdentifier());
            Assert.Equal("OuterClass'2/SampleClass'1/SampleMethod''1()", method.DnaId());
            var name = method.MemberFriendlyName();
            Assert.Equal("SampleMethod<TFourth>", name.SimpleName);
            Assert.Equal("OuterClass<TFirst,TSecond>.SampleClass<TThird>.SampleMethod<TFourth>", name.QualifiedName);
            Assert.Equal("OuterClass<TFirst,TSecond>.SampleClass<TThird>.SampleMethod<TFourth>", name.FullyQualifiedName);
        }

        [Fact]
        public void Nested_GenericParameters_InNamespace()
        {
            var code = @"namespace Ns { public class OuterClass<TFirst, TSecond> { public class SampleClass<TThird> { public void SampleMethod<TFourth>() { } } } }";
            var assembly = Compile(code).Dll;
            var outer = assembly.Modules.SelectMany(x => x.Types).Single(x => x.Name == "OuterClass`2");
            var type = outer.NestedTypes.Single(x => x.Name == "SampleClass`1");
            var method = type.Methods.Single(x => x.Name == "SampleMethod");
            Assert.Equal("M:Ns.OuterClass`2.SampleClass`1.SampleMethod``1", method.XmldocIdentifier());
            Assert.Equal("Ns.OuterClass'2/SampleClass'1/SampleMethod''1()", method.DnaId());
            var name = method.MemberFriendlyName();
            Assert.Equal("SampleMethod<TFourth>", name.SimpleName);
            Assert.Equal("OuterClass<TFirst,TSecond>.SampleClass<TThird>.SampleMethod<TFourth>", name.QualifiedName);
            Assert.Equal("Ns.OuterClass<TFirst,TSecond>.SampleClass<TThird>.SampleMethod<TFourth>", name.FullyQualifiedName);
        }

        [Fact]
        public void Nested_GenericParametersOnlyOnDeclaringType()
        {
            var code = @"public class SampleClass<TFirst> { public void SampleMethod() { } }";
            var assembly = Compile(code).Dll;
            var type = assembly.Modules.SelectMany(x => x.Types).Single(x => x.Name == "SampleClass`1");
            var method = type.Methods.Single(x => x.Name == "SampleMethod");
            Assert.Equal("M:SampleClass`1.SampleMethod", method.XmldocIdentifier());
            Assert.Equal("SampleClass'1/SampleMethod()", method.DnaId());
            var name = method.MemberFriendlyName();
            Assert.Equal("SampleMethod", name.SimpleName);
            Assert.Equal("SampleClass<TFirst>.SampleMethod", name.QualifiedName);
            Assert.Equal("SampleClass<TFirst>.SampleMethod", name.FullyQualifiedName);
        }
    }
}
{'fraction_non_alphanumeric': 0.13809341988036147, 'fraction_numerical': 0.002672775868652157, 'mean_word_length': 2.8238442822384426, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5445632', 'n_tokens_mistral': 2179, 'n_tokens_neox': 2164, 'n_words': 375}