<commit_before>﻿using System.Linq;
using System.Reflection.Emit;
using AsmResolver.DotNet.Signatures.Types;
using AsmResolver.DotNet.TestCases.Methods;
using AsmResolver.PE.DotNet.Cil;
using Xunit;

namespace AsmResolver.DotNet.Tests
{
    public class DynamicMethodDefinitionTest
    {
        [Fact]
        public void ReadDynamicMethod()
        {
            var module = ModuleDefinition.FromFile(typeof(TDynamicMethod).Assembly.Location);

            DynamicMethod generateDynamicMethod = TDynamicMethod.GenerateDynamicMethod();

            var dynamicMethodDefinition = new DynamicMethodDefinition(module, generateDynamicMethod);

            Assert.NotNull(dynamicMethodDefinition);

            Assert.NotEmpty(dynamicMethodDefinition.CilMethodBody.Instructions);
            
            Assert.Equal(dynamicMethodDefinition.CilMethodBody.Instructions.Select(q=>q.OpCode),new CilOpCode[]
            {
                CilOpCodes.Ldarg_0, 
                CilOpCodes.Call,
                CilOpCodes.Ldarg_1,
                CilOpCodes.Ret
            });
            Assert.Equal(dynamicMethodDefinition.Parameters.Select(q=>q.ParameterType),new TypeSignature[]
            {
                module.CorLibTypeFactory.String,
                module.CorLibTypeFactory.Int32
            });
        }
    }
}<commit_msg>Unit Tests<commit_after>﻿using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using AsmResolver.DotNet.Signatures.Types;
using AsmResolver.DotNet.TestCases.Methods;
using AsmResolver.PE.DotNet.Cil;
using Xunit;

namespace AsmResolver.DotNet.Tests
{
    public class DynamicMethodDefinitionTest
    {
        [Fact]
        public void ReadDynamicMethod()
        {
            var module = ModuleDefinition.FromFile(typeof(TDynamicMethod).Assembly.Location);

            DynamicMethod generateDynamicMethod = TDynamicMethod.GenerateDynamicMethod();

            var dynamicMethodDefinition = new DynamicMethodDefinition(module, generateDynamicMethod);

            Assert.NotNull(dynamicMethodDefinition);

            Assert.NotEmpty(dynamicMethodDefinition.CilMethodBody.Instructions);
            
            Assert.Equal(dynamicMethodDefinition.CilMethodBody.Instructions.Select(q=>q.OpCode),new CilOpCode[]
            {
                CilOpCodes.Ldarg_0, 
                CilOpCodes.Call,
                CilOpCodes.Ldarg_1,
                CilOpCodes.Ret
            });
            Assert.Equal(dynamicMethodDefinition.Parameters.Select(q=>q.ParameterType),new TypeSignature[]
            {
                module.CorLibTypeFactory.String,
                module.CorLibTypeFactory.Int32
            });
        }
        
        [Fact]
        public void RTDynamicMethod()
        {
            var module = ModuleDefinition.FromFile(typeof(TDynamicMethod).Assembly.Location);

            DynamicMethod generateDynamicMethod = TDynamicMethod.GenerateDynamicMethod();

            var RTDynamicMethod = generateDynamicMethod.GetType().GetField("m_dynMethod", (BindingFlags) (-1))?.GetValue(generateDynamicMethod); 
            
            var dynamicMethodDefinition = new DynamicMethodDefinition(module, RTDynamicMethod);

            Assert.NotNull(dynamicMethodDefinition);

            Assert.NotEmpty(dynamicMethodDefinition.CilMethodBody.Instructions);
            
            Assert.Equal(dynamicMethodDefinition.CilMethodBody.Instructions.Select(q=>q.OpCode),new CilOpCode[]
            {
                CilOpCodes.Ldarg_0, 
                CilOpCodes.Call,
                CilOpCodes.Ldarg_1,
                CilOpCodes.Ret
            });
            Assert.Equal(dynamicMethodDefinition.Parameters.Select(q=>q.ParameterType),new TypeSignature[]
            {
                module.CorLibTypeFactory.String,
                module.CorLibTypeFactory.Int32
            });
        }
    }
}
{'fraction_non_alphanumeric': 0.08225556130367305, 'fraction_numerical': 0.003362648732540093, 'mean_word_length': 2.330749354005168, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '2367959', 'n_tokens_mistral': 1012, 'n_tokens_neox': 981, 'n_words': 123}