public void Initialization()
        {
            var parameter = ReflectionObjectMother.GetSomeParameter();
            var method    = CustomMethodInfoObjectMother.Create(_declaringType, parameters: new[] { parameter });

            var instantiation = new MethodOnTypeInstantiation(_declaringType, method);

            Assert.That(instantiation.DeclaringType, Is.SameAs(_declaringType));
            Assert.That(instantiation.Name, Is.EqualTo(method.Name));
            Assert.That(instantiation.Attributes, Is.EqualTo(method.Attributes));
            Assert.That(instantiation.IsGenericMethod, Is.False);
            Assert.That(() => instantiation.GetGenericMethodDefinition(), Throws.InvalidOperationException);
            Assert.That(instantiation.GetGenericArguments(), Is.Empty);
            Assert.That(instantiation.MethodOnGenericType, Is.SameAs(method));

            var returnParameter = instantiation.ReturnParameter;

            Assertion.IsNotNull(returnParameter);
            Assert.That(returnParameter, Is.TypeOf <MemberParameterOnInstantiation>());
            Assert.That(returnParameter.Member, Is.SameAs(instantiation));
            Assert.That(returnParameter.As <MemberParameterOnInstantiation>().MemberParameterOnGenericDefinition, Is.SameAs(method.ReturnParameter));

            var memberParameter = instantiation.GetParameters().Single();

            Assert.That(memberParameter, Is.TypeOf <MemberParameterOnInstantiation>());
            Assert.That(memberParameter.Member, Is.SameAs(instantiation));
            Assert.That(memberParameter.As <MemberParameterOnInstantiation>().MemberParameterOnGenericDefinition, Is.SameAs(parameter));
        }
        public void GetAccessors()
        {
            var nonPublicSetMethod = CustomMethodInfoObjectMother.Create(attributes: MethodAttributes.Private, parameters: new[] { _indexParameter, _valueParameter });
            var property           = CustomPropertyInfoObjectMother.Create(getMethod: _getMethod, setMethod: nonPublicSetMethod);

            Assert.That(property.GetAccessors(true), Is.EquivalentTo(new[] { _getMethod, nonPublicSetMethod }));
            Assert.That(property.GetAccessors(false), Is.EquivalentTo(new[] { _getMethod }));
        }
Esempio n. 3
0
        public void CallingConvention()
        {
            var instanceMethod = CustomMethodInfoObjectMother.Create(attributes: 0);
            var staticMethod   = CustomMethodInfoObjectMother.Create(attributes: MethodAttributes.Static);

            Assert.That(instanceMethod.CallingConvention, Is.EqualTo(CallingConventions.Standard | CallingConventions.HasThis));
            Assert.That(staticMethod.CallingConvention, Is.EqualTo(CallingConventions.Standard));
        }
        public void GetCustomAttributeData()
        {
            var customAttributes    = new[] { CustomAttributeDeclarationObjectMother.Create() };
            var method              = CustomMethodInfoObjectMother.Create(customAttributes: customAttributes);
            var methodInstantiation = new MethodOnTypeInstantiation(_declaringType, method);

            Assert.That(methodInstantiation.GetCustomAttributeData(), Is.EqualTo(customAttributes));
        }
        public void GetCustomAttributeData()
        {
            var customAttributes        = new[] { CustomAttributeDeclarationObjectMother.Create() };
            var genericMethodDefinition = CustomMethodInfoObjectMother.Create(typeArguments: new[] { _typeArgument }, customAttributes: customAttributes);
            var instantiation           = MethodInstantiationObjectMother.Create(genericMethodDefinition);

            Assert.That(instantiation.GetCustomAttributeData(), Is.EqualTo(customAttributes));
        }
Esempio n. 6
0
        public void IsRunetimeMethodInfo()
        {
            var runtimeMethod = ReflectionObjectMother.GetSomeMethod();
            var customMethod  = CustomMethodInfoObjectMother.Create();

            Assert.That(runtimeMethod.IsRuntimeMethodInfo(), Is.True);
            Assert.That(customMethod.IsRuntimeMethodInfo(), Is.False);
        }
        public new void ToString()
        {
            var type            = ReflectionObjectMother.GetSomeType();
            var returnParameter = CustomParameterInfoObjectMother.Create(type: type);
            var method          = CustomMethodInfoObjectMother.Create(returnParameter: returnParameter);
            var name            = "MyProperty";
            var property        = CustomPropertyInfoObjectMother.Create(name: name, getMethod: method);

            Assert.That(property.ToString(), Is.EqualTo(type.Name + " MyProperty"));
        }
        public void SetUp()
        {
            _typeParameter           = MutableGenericParameterObjectMother.Create();
            _parameter               = CustomParameterInfoObjectMother.Create();
            _genericMethodDefinition = CustomMethodInfoObjectMother.Create(parameters: new[] { _parameter }, typeArguments: new[] { _typeParameter });
            _typeArgument            = CustomTypeObjectMother.Create();

            var info = new MethodInstantiationInfo(_genericMethodDefinition, new[] { _typeArgument });

            _instantiation = new MethodInstantiation(info);
        }
        public void Instantiate_CustomGenericMethodDefinition()
        {
            var typeParameter = ReflectionObjectMother.GetSomeGenericParameter();
            var customGenericMethodDefinition = CustomMethodInfoObjectMother.Create(typeArguments: new[] { typeParameter });
            var instantiationInfo             = new MethodInstantiationInfo(customGenericMethodDefinition, new[] { _runtimeType });

            var result = instantiationInfo.Instantiate();

            Assert.That(result, Is.TypeOf <MethodInstantiation>());
            Assert.That(result.GetGenericMethodDefinition(), Is.EqualTo(instantiationInfo.GenericMethodDefinition));
            Assert.That(result.GetGenericArguments(), Is.EqualTo(instantiationInfo.TypeArguments));
        }
Esempio n. 10
0
        public void ToDebugString()
        {
            var method = CustomMethodInfoObjectMother.Create(
                declaringType: MutableTypeObjectMother.Create(name: "AbcProxy"),
                name: "Xxx",
                returnParameter: CustomParameterInfoObjectMother.Create(position: -1, type: typeof(void)),
                parameters: new[] { CustomParameterInfoObjectMother.Create(type: typeof(int)) });

            var expected = "TestableCustomMethod = \"Void Xxx(Int32)\", DeclaringType = \"AbcProxy\"";

            Assert.That(method.ToDebugString(), Is.EqualTo(expected));
        }
Esempio n. 11
0
        public new void ToString()
        {
            var parameters =
                new[]
            {
                CustomParameterInfoObjectMother.Create(type: typeof(int)),
                CustomParameterInfoObjectMother.Create(type: typeof(string).MakeByRefType())
            };
            var returnParameter = CustomParameterInfoObjectMother.Create(type: typeof(string));
            var method          = CustomMethodInfoObjectMother.Create(name: "Xxx", returnParameter: returnParameter, parameters: parameters);

            Assert.That(method.ToString(), Is.EqualTo("String Xxx(Int32, String&)"));
        }
Esempio n. 12
0
        public void SetUp()
        {
            _declaringType  = CustomTypeObjectMother.Create();
            _type           = ReflectionObjectMother.GetSomeType();
            _valueParameter = CustomParameterInfoObjectMother.Create(type: _type);
            var indexParameterType = ReflectionObjectMother.GetSomeOtherType();

            _indexParameter = CustomParameterInfoObjectMother.Create(type: indexParameterType);
            _getMethod      = CustomMethodInfoObjectMother.Create(attributes: MethodAttributes.Public, parameters: new[] { _indexParameter }, returnParameter: _valueParameter);
            _setMethod      = CustomMethodInfoObjectMother.Create(attributes: MethodAttributes.Public, parameters: new[] { _indexParameter, _valueParameter });

            _readOnlyProperty  = CustomPropertyInfoObjectMother.Create(getMethod: _getMethod);
            _writeOnlyProperty = CustomPropertyInfoObjectMother.Create(setMethod: _setMethod);
        }
        public void Initialization_FromGenericMethodDefinition()
        {
            var typeArguments = new[] { ReflectionObjectMother.GetSomeType() };
            var method        = CustomMethodInfoObjectMother.Create(_declaringType, typeArguments: typeArguments);

            Assert.That(method.IsGenericMethodDefinition, Is.True);

            var instantiation = new MethodOnTypeInstantiation(_declaringType, method);

            Assert.That(instantiation.IsGenericMethod, Is.True);
            Assert.That(instantiation.IsGenericMethodDefinition, Is.True);
            Assert.That(instantiation.GetGenericMethodDefinition(), Is.SameAs(instantiation));
            Assert.That(instantiation.GetGenericArguments(), Is.EqualTo(typeArguments));
        }
Esempio n. 14
0
        public void GetGetMethod()
        {
            var nonPublicMethod = CustomMethodInfoObjectMother.Create(attributes: MethodAttributes.Private, returnParameter: _valueParameter);
            var property1       = CustomPropertyInfoObjectMother.Create(getMethod: nonPublicMethod);
            var property2       = CustomPropertyInfoObjectMother.Create(getMethod: _getMethod);
            var property3       = CustomPropertyInfoObjectMother.Create(getMethod: null, setMethod: _setMethod);

            Assert.That(property1.GetGetMethod(true), Is.SameAs(nonPublicMethod));
            Assert.That(property1.GetGetMethod(false), Is.Null);
            Assert.That(property2.GetGetMethod(true), Is.SameAs(_getMethod));
            Assert.That(property2.GetGetMethod(false), Is.SameAs(_getMethod));
            Assert.That(property3.GetGetMethod(true), Is.Null);
            Assert.That(property3.GetGetMethod(false), Is.Null);
        }
Esempio n. 15
0
        public void ContainsGenericParameters()
        {
            Assert.That(_customMethod.ContainsGenericParameters, Is.False);
            Assert.That(_genericMethod.ContainsGenericParameters, Is.False);
            Assert.That(_genericMethodDefinition.ContainsGenericParameters, Is.True);

            var typeInstantiation = TypeInstantiationObjectMother.Create(typeof(IList <>), new[] { ReflectionObjectMother.GetSomeGenericParameter() });
            var method1           = CustomMethodInfoObjectMother.Create(
                genericMethodDefintion: _genericMethodUnderlyingDefinition, typeArguments: new[] { typeInstantiation });

            Assert.That(method1.ContainsGenericParameters, Is.True);

            var genericTypeDefinition = CustomTypeObjectMother.Create(typeArguments: new[] { ReflectionObjectMother.GetSomeGenericParameter() });
            var method2 = CustomMethodInfoObjectMother.Create(declaringType: genericTypeDefinition);

            Assert.That(method2.ContainsGenericParameters, Is.True);
        }
Esempio n. 16
0
        public void ToDebugString()
        {
            var declaringType   = CustomTypeObjectMother.Create();
            var type            = ReflectionObjectMother.GetSomeType();
            var returnParameter = CustomParameterInfoObjectMother.Create(type: type);
            var method          = CustomMethodInfoObjectMother.Create(returnParameter: returnParameter);
            var name            = "MyProperty";
            var property        = CustomPropertyInfoObjectMother.Create(declaringType, name, getMethod: method);

            // Note: ToDebugString is defined in CustomFieldInfo base class.
            Assertion.IsNotNull(property.DeclaringType);
            var declaringTypeName = property.DeclaringType.Name;
            var propertyTypeName  = property.PropertyType.Name;
            var propertyName      = property.Name;
            var expected          = "TestableCustomProperty = \"" + propertyTypeName + " " + propertyName + "\", DeclaringType = \"" + declaringTypeName + "\"";

            Assert.That(property.ToDebugString(), Is.EqualTo(expected));
        }
Esempio n. 17
0
        public void SetUp()
        {
            _declaringType   = CustomTypeObjectMother.Create();
            _name            = "abc";
            _attributes      = (MethodAttributes)7;
            _returnParameter = CustomParameterInfoObjectMother.Create();

            _customMethod = new TestableCustomMethodInfo(_declaringType, _name, _attributes, null, Type.EmptyTypes)
            {
                ReturnParameter_ = _returnParameter
            };

            _typeArgument = ReflectionObjectMother.GetSomeType();
            _genericMethodUnderlyingDefinition = ReflectionObjectMother.GetSomeGenericMethodDefinition();
            _genericMethod = CustomMethodInfoObjectMother.Create(
                genericMethodDefintion: _genericMethodUnderlyingDefinition, typeArguments: new[] { _typeArgument });

            _typeParameter           = ReflectionObjectMother.GetSomeGenericParameter();
            _genericMethodDefinition = CustomMethodInfoObjectMother.Create(typeArguments: new[] { _typeParameter });
        }