Exemplo n.º 1
0
        public void InvokeInstanceMethodThrowsWhenInstanceIsNull()
        {
            MethodInvocationSpec spec = new MethodInvocationSpec(typeof(NonGenericClass), NonGenericClassEmptyMethodInfo,
                                                                 EmptyArray <KeyValuePair <ISlotInfo, object> > .Instance, NullConverter.Instance);

            Assert.Throws <ArgumentNullException>(delegate { spec.Invoke(null); });
        }
Exemplo n.º 2
0
        public void InvokeInstanceMethodThrowsWhenInstanceIsOfWrongType()
        {
            GenericClass <int>             instance   = new GenericClass <int>();
            Dictionary <ISlotInfo, object> slotValues = new Dictionary <ISlotInfo, object>();

            MethodInvocationSpec spec = new MethodInvocationSpec(typeof(NonGenericClass), NonGenericClassEmptyMethodInfo, slotValues, NullConverter.Instance);

            Assert.Throws <TargetException>(delegate { spec.Invoke(instance); });
        }
Exemplo n.º 3
0
        public void InvokeThrowsUnwrappedException()
        {
            ITypeInfo   type   = Reflector.Wrap(typeof(NonGenericClass));
            IMethodInfo method = type.GetMethod("StaticMethodThatThrows", PublicStatic);
            Dictionary <ISlotInfo, object> slotValues = new Dictionary <ISlotInfo, object>();

            MethodInvocationSpec spec = new MethodInvocationSpec(typeof(NonGenericClass), method, slotValues, NullConverter.Instance);

            Assert.Throws <InvalidOperationException>(delegate { spec.Invoke(null); });
        }
Exemplo n.º 4
0
        public void InvokeStaticMethodWithGenericMethodInstantiation()
        {
            ITypeInfo   type   = Reflector.Wrap(typeof(GenericClass <int>));
            IMethodInfo method = Reflector.Wrap(type.GetMethod("StaticMethod", PublicStatic).Resolve(true).MakeGenericMethod(typeof(int)));
            Dictionary <ISlotInfo, object> slotValues = new Dictionary <ISlotInfo, object>();

            slotValues.Add(method.Parameters[0], 1);

            MethodInvocationSpec spec = new MethodInvocationSpec(typeof(GenericClass <int>), method, slotValues, NullConverter.Instance);

            spec.Invoke(null);
            Assert.AreEqual(typeof(int), GenericClass <int> .staticMethodTypeValue);
            Assert.AreEqual(1, GenericClass <int> .staticMethodParamValue);
        }
Exemplo n.º 5
0
        public void InvokeInstanceMethodWithGenericMethodOnGenericTypeDefn()
        {
            ITypeInfo   type   = Reflector.Wrap(typeof(GenericClass <>));
            IMethodInfo method = type.GetMethod("InstanceMethod", PublicInstance);
            Dictionary <ISlotInfo, object> slotValues = new Dictionary <ISlotInfo, object>();

            slotValues.Add((IGenericParameterInfo)method.GenericArguments[0], typeof(int));
            slotValues.Add(method.Parameters[0], 1);

            GenericClass <int>   instance = new GenericClass <int>();
            MethodInvocationSpec spec     = new MethodInvocationSpec(typeof(GenericClass <int>), method, slotValues, NullConverter.Instance);

            spec.Invoke(instance);
            Assert.AreEqual(typeof(int), instance.instanceMethodTypeValue);
            Assert.AreEqual(1, instance.instanceMethodParamValue);
        }
        public object InvokeFixtureMethod(IMethodInfo method, IEnumerable <KeyValuePair <ISlotInfo, object> > slotValues)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }
            if (slotValues == null)
            {
                throw new ArgumentNullException("slotValues");
            }
            if (fixtureType == null)
            {
                throw new InvalidOperationException("This method cannot be used when FixtureType is null.");
            }

            var spec = new MethodInvocationSpec(fixtureType, method, slotValues, Converter);

            return(spec.Invoke(fixtureInstance));
        }