예제 #1
0
        public void VerifyThatInvalidIdentifierNamesAreParsed()
        {
            var environment = new IntegrationTestEnvironment();
            var asset       = environment.GetTestAsset("CILProject.dll", "net451");
            var assembly    = Assembly.LoadFrom(asset);
            var types       = assembly.GetTypes();

            foreach (var type in types)
            {
                var methods = type.GetMethods();

                foreach (var method in methods)
                {
                    if (method.DeclaringType != type)
                    {
                        continue;
                    }

                    ManagedNameHelper.GetManagedName(method, out var typeName, out var methodName);
                    var methodInfo = ManagedNameHelper.GetMethod(assembly, typeName, methodName);
                    ManagedNameHelper.GetManagedName(methodInfo, out var typeName2, out var methodName2);

                    Assert.IsTrue(method == methodInfo);
                    Assert.AreEqual(typeName, typeName2, $"Type parse roundtrip test failed: {method} ({typeName} != {typeName2})");
                    Assert.AreEqual(methodName, methodName2, $"Method parse roundtrip test failed: {method} ({methodName} != {methodName2})");
                }
            }
        }
예제 #2
0
        internal TestMethod(MethodBase method, string name, string fullClassName, string assemblyName, bool isAsync)
            : this(name, fullClassName, assemblyName, isAsync)
        {
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }

            ManagedNameHelper.GetManagedName(method, out var managedType, out var managedMethod, out var hierarchyValues);
            this.ManagedTypeName   = managedType;
            this.ManagedMethodName = managedMethod;
            this.hierarchy         = new ReadOnlyCollection <string>(hierarchyValues);
        }
예제 #3
0
        public TestMethod(MethodBase method, string name, string fullClassName, string assemblyName, bool isAsync)
            : this(name, fullClassName, assemblyName, isAsync)
        {
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }

            ManagedNameHelper.GetManagedName(method, out var managedType, out var managedMethod);

            this.ManagedType   = managedType;
            this.ManagedMethod = managedMethod;
        }
예제 #4
0
        internal TestMethod(MethodBase method, string name, string fullClassName, string assemblyName, bool isAsync)
            : this(name, fullClassName, assemblyName, isAsync)
        {
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }

            ManagedNameHelper.GetManagedName(method, out var managedType, out var managedMethod);

            // ManagedNameHelpers currently does not support spaces in method names.
            // If there are spaces in the method name, we'll use the legacy way to find the method.
            if (!managedMethod.Contains(" "))
            {
                this.ManagedTypeName   = managedType;
                this.ManagedMethodName = managedMethod;
            }
        }
예제 #5
0
        private void VerifyRoundTripFromMethodInfo(
            MethodInfo methodInfo,
            string expectedManagedTypeName,
            string expectedManagedMethodName)
        {
            // Generate the fqn for the Reflection MethodInfo
            ManagedNameHelper.GetManagedName(methodInfo, out var managedTypeName, out var managedMethodName);

            Assert.AreEqual(expectedManagedTypeName, managedTypeName);
            Assert.AreEqual(expectedManagedMethodName, managedMethodName);

            // Lookup the Reflection MethodInfo using fullTypeName and fullMethodName
            var roundTrippedMethodInfo = ManagedNameHelper.GetMethod(
                Assembly.GetExecutingAssembly(),
                managedTypeName,
                managedMethodName);

            Assert.AreEqual(methodInfo.MetadataToken, roundTrippedMethodInfo.MetadataToken);
        }
예제 #6
0
        private MethodInfo GetMethodInfoUsingManagedNameHelper(TestMethod testMethod, TestClassInfo testClassInfo)
        {
            MethodInfo testMethodInfo = null;
            var        methodBase     = ManagedNameHelper.GetMethod(testClassInfo.Parent.Assembly, testMethod.ManagedTypeName, testMethod.ManagedMethodName);

            if (methodBase is MethodInfo mi)
            {
                testMethodInfo = mi;
            }
            else if (methodBase != null)
            {
                var parameters = methodBase.GetParameters().Select(i => i.ParameterType).ToArray();
                testMethodInfo = methodBase.DeclaringType.GetRuntimeMethod(methodBase.Name, parameters);
            }

            testMethodInfo = testMethodInfo?.HasCorrectTestMethodSignature(true) ?? false
                           ? testMethodInfo
                           : null;

            return(testMethodInfo);
        }