Ejemplo n.º 1
0
        public void GetPublicMethodWrapper_Cached()
        {
            var        classEmitter = new CustomClassEmitter(Scope, "GetPublicMethodWrapper_Cached", typeof(ClassWithProtectedMethod));
            MethodInfo emitter1     =
                classEmitter.GetPublicMethodWrapper(typeof(ClassWithProtectedMethod).GetMethod("GetSecret", _declaredInstanceBindingFlags));
            MethodInfo emitter2 =
                classEmitter.GetPublicMethodWrapper(typeof(ClassWithProtectedMethod).GetMethod("GetSecret", _declaredInstanceBindingFlags));

            Assert.That(emitter2, Is.SameAs(emitter1));

            MethodInfo emitter3 =
                classEmitter.GetPublicMethodWrapper(typeof(object).GetMethod("Finalize", _declaredInstanceBindingFlags));

            Assert.That(emitter3, Is.Not.SameAs(emitter1));

            classEmitter.BuildType();
        }
Ejemplo n.º 2
0
        public void GetPublicMethodWrapper()
        {
            var classEmitter = new CustomClassEmitter(Scope, "GetPublicMethodWrapper", typeof(ClassWithProtectedMethod));

            classEmitter.GetPublicMethodWrapper(typeof(ClassWithProtectedMethod).GetMethod("GetSecret", _declaredInstanceBindingFlags));

            object     instance      = Activator.CreateInstance(classEmitter.BuildType());
            MethodInfo publicWrapper = instance.GetType().GetMethod("__wrap__GetSecret");

            Assert.That(publicWrapper, Is.Not.Null);
            Assert.That(publicWrapper.Invoke(instance, null), Is.EqualTo("The secret is to be more provocative and interesting than anything else in [the] environment."));
        }
Ejemplo n.º 3
0
        public void GetPublicMethodWrapper_HasAttribute()
        {
            var classEmitter = new CustomClassEmitter(Scope, "GetPublicMethodWrapper_HasAttribute", typeof(ClassWithProtectedMethod));

            classEmitter.GetPublicMethodWrapper(typeof(ClassWithProtectedMethod).GetMethod("GetSecret", _declaredInstanceBindingFlags));

            object     instance      = Activator.CreateInstance(classEmitter.BuildType());
            MethodInfo publicWrapper = instance.GetType().GetMethod("__wrap__GetSecret");

            var attribute = AttributeUtility.GetCustomAttribute <GeneratedMethodWrapperAttribute> (publicWrapper, false);

            Assert.That(attribute, Is.Not.Null);
        }
Ejemplo n.º 4
0
        public void GetPublicMethodWrapper_Attribute_Properties()
        {
            var classEmitter      = new CustomClassEmitter(Scope, "GetPublicMethodWrapper_Attribute_HasRightToken", typeof(ClassWithProtectedMethod));
            var methodToBeWrapped = typeof(ClassWithProtectedMethod).GetMethod("GetSecret", _declaredInstanceBindingFlags);

            classEmitter.GetPublicMethodWrapper(methodToBeWrapped);

            Type       type          = classEmitter.BuildType();
            MethodInfo publicWrapper = type.GetMethod("__wrap__GetSecret");

            var attribute = AttributeUtility.GetCustomAttribute <GeneratedMethodWrapperAttribute> (publicWrapper, false);

            Assert.That(attribute.DeclaringType, Is.EqualTo(typeof(ClassWithProtectedMethod)));
            Assert.That(attribute.MethodName, Is.EqualTo("GetSecret"));
            Assert.That(attribute.MethodSignature, Is.EqualTo(methodToBeWrapped.ToString()));

            Assert.That(attribute.ResolveReferencedMethod(), Is.EqualTo(methodToBeWrapped));
        }