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 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));
        }
Пример #3
0
        public void SetUp()
        {
            _declaringType = TypeInstantiationObjectMother.Create();
            _originalEvent = GetType().GetEvent("Event");
            _addMethod     = MethodOnTypeInstantiationObjectMother.Create(_declaringType, GetType().GetMethod("add_Event"));
            _removeMethod  = MethodOnTypeInstantiationObjectMother.Create(_declaringType, GetType().GetMethod("remove_Event"));
            _raiseMethod   = MethodOnTypeInstantiationObjectMother.Create(_declaringType, GetType().GetMethod("RaiseMethod"));

            _event = new EventOnTypeInstantiation(_declaringType, _originalEvent, _addMethod, _removeMethod, _raiseMethod);
        }
        public void SetUp()
        {
            _indexParameter = CustomParameterInfoObjectMother.Create();

            _declaringType    = TypeInstantiationObjectMother.Create();
            _getMethod        = MethodOnTypeInstantiationObjectMother.Create(_declaringType, typeof(GenericType <>).GetMethod("get_Item"));
            _setMethod        = MethodOnTypeInstantiationObjectMother.Create(_declaringType, typeof(GenericType <>).GetMethod("set_Item"));
            _originalProperty = CustomPropertyInfoObjectMother.Create(
                indexParameters: new[] { _indexParameter }, getMethod: _getMethod, setMethod: _setMethod);

            _property = new PropertyOnTypeInstantiation(_declaringType, _originalProperty, _getMethod, _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));
        }