예제 #1
0
        public void SetUp()
        {
            _memberSelectorMock = MockRepository.GenerateStrictMock <IMemberSelector>();

            _name       = "TypeName";
            _namespace  = "MyNamespace";
            _attributes = (TypeAttributes)7;

            _customType = new TestableCustomType(
                _name,
                _namespace,
                _attributes,
                genericTypeDefinition: null,
                typeArguments: Type.EmptyTypes)
            {
                NestedTypes  = new[] { ReflectionObjectMother.GetSomeType() },
                Interfaces   = new[] { typeof(IDisposable) },
                Fields       = new[] { ReflectionObjectMother.GetSomeField() },
                Constructors = new[] { ReflectionObjectMother.GetSomeConstructor() },
                Methods      = new[] { ReflectionObjectMother.GetSomeMethod() },
                Properties   = new[] { ReflectionObjectMother.GetSomeProperty() },
                Events       = new[] { ReflectionObjectMother.GetSomeEvent() }
            };
            _customType.SetMemberSelector(_memberSelectorMock);

            _typeArgument = ReflectionObjectMother.GetSomeType();
            _genericTypeUnderlyingDefinition = typeof(IList <>);
            _genericType = CustomTypeObjectMother.Create(
                name: "GenericType`1", genericTypeDefinition: _genericTypeUnderlyingDefinition, typeArguments: new[] { _typeArgument });

            _typeParameter         = ReflectionObjectMother.GetSomeGenericParameter();
            _genericTypeDefinition = CustomTypeObjectMother.Create(name: "GenericTypeDefinition`1", typeArguments: new[] { _typeParameter });
        }
예제 #2
0
        public void SelectSingleProperty()
        {
            var properties =
                new[]
            {
                CreatePropertyStub("Property1", accessors: new[] { CreateMethodStub() }),
                CreatePropertyStub("Property2", accessors: new[] { CreateMethodStub(attributes: MethodAttributes.Assembly) }),
                CreatePropertyStub("Property2", accessors: new[] { CreateMethodStub(attributes: MethodAttributes.Public) })
            };
            var bindingFlags = (BindingFlags)1;
            var propertyType = ReflectionObjectMother.GetSomeType();
            var indexerTypes = new[] { ReflectionObjectMother.GetSomeOtherType() };
            var modifiers    = new[] { new ParameterModifier(2) };

            _bindingFlagsEvaluatorMock.Expect(mock => mock.HasRightAttributes(MethodAttributes.Assembly, bindingFlags)).Return(true);
            _bindingFlagsEvaluatorMock.Expect(mock => mock.HasRightAttributes(MethodAttributes.Public, bindingFlags)).Return(true);

            var binderMock = MockRepository.GenerateStrictMock <Binder>();
            var fakeResult = ReflectionObjectMother.GetSomeProperty();

            binderMock.Expect(mock => mock.SelectProperty(bindingFlags, new[] { properties[1], properties[2] }, propertyType, indexerTypes, modifiers))
            .Return(fakeResult);

            var result = _selector.SelectSingleProperty(
                properties, binderMock, bindingFlags, "Property2", _someDeclaringType, propertyType, indexerTypes, modifiers);

            _bindingFlagsEvaluatorMock.VerifyAllExpectations();
            binderMock.VerifyAllExpectations();
            Assert.That(result, Is.SameAs(fakeResult));
        }
예제 #3
0
        public void GetPropertyImpl(Binder inputBinder, Binder expectedBinder)
        {
            Assert.That(_customType.Properties, Is.Not.Null.And.Not.Empty);
            var name             = "some name";
            var bindingAttr      = BindingFlags.NonPublic;
            var returnTypeOrNull = ReflectionObjectMother.GetSomeType();
            var typesOrNull      = new[] { ReflectionObjectMother.GetSomeType() };
            var modifiersOrNull  = new[] { new ParameterModifier(1) };

            var fakeResult = ReflectionObjectMother.GetSomeProperty();

            _memberSelectorMock
            .Setup(
                mock => mock.SelectSingleProperty(
                    _customType.Properties,
                    expectedBinder,
                    bindingAttr,
                    name,
                    _customType,
                    returnTypeOrNull,
                    typesOrNull,
                    modifiersOrNull))
            .Returns(fakeResult)
            .Verifiable();

            var arguments = new object[] { name, bindingAttr, inputBinder, returnTypeOrNull, typesOrNull, modifiersOrNull };
            var result    = (PropertyInfo)PrivateInvoke.InvokeNonPublicMethod(_customType, "GetPropertyImpl", arguments);

            _memberSelectorMock.Verify();
            Assert.That(result, Is.SameAs(fakeResult));
        }
        public void GetCustomAttributeData()
        {
            var member          = ReflectionObjectMother.GetSomeProperty();
            var customAttribute = CustomAttributeDeclarationObjectMother.Create();
            var parameter       = CustomParameterInfoObjectMother.Create(customAttributes: new ICustomAttributeData[] { customAttribute });

            var wrapper = new PropertyParameterInfoWrapper(member, parameter);

            Assert.That(wrapper.GetCustomAttributeData(), Is.EqualTo(new[] { customAttribute }));
        }
예제 #5
0
        public void GetProperties()
        {
            Assert.That(_customType.Properties, Is.Not.Null.And.Not.Empty);
            var bindingAttr = BindingFlags.NonPublic;
            var fakeResult  = new[] { ReflectionObjectMother.GetSomeProperty() };

            _memberSelectorMock.Expect(mock => mock.SelectProperties(_customType.Properties, bindingAttr, _customType)).Return(fakeResult);

            var result = _customType.GetProperties(bindingAttr);

            _memberSelectorMock.VerifyAllExpectations();
            Assert.That(result, Is.EqualTo(fakeResult));
        }
        public void Initialization()
        {
            var parameter = ReflectionObjectMother.GetSomeParameter();
            var member    = ReflectionObjectMother.GetSomeProperty();

            var wrapper = new PropertyParameterInfoWrapper(member, parameter);

            Assert.That(wrapper.Member, Is.SameAs(member));
            Assert.That(wrapper.Position, Is.EqualTo(parameter.Position));
            Assert.That(wrapper.Name, Is.EqualTo(parameter.Name));
            Assert.That(wrapper.ParameterType, Is.SameAs(parameter.ParameterType));
            Assert.That(wrapper.Attributes, Is.EqualTo(parameter.Attributes));
        }
예제 #7
0
        public void SelectSingleProperty()
        {
            var properties =
                new[]
            {
                CreatePropertyStub("Property1", accessors: new[] { CreateMethodStub() }),
                CreatePropertyStub("Property2", accessors: new[] { CreateMethodStub(attributes: MethodAttributes.Assembly) }),
                CreatePropertyStub("Property2", accessors: new[] { CreateMethodStub(attributes: MethodAttributes.Public) })
            };
            var bindingFlags = (BindingFlags)1;
            var propertyType = ReflectionObjectMother.GetSomeType();
            var indexerTypes = new[] { ReflectionObjectMother.GetSomeOtherType() };
            var modifiers    = new[] { new ParameterModifier(2) };

            _bindingFlagsEvaluatorMock.Setup(mock => mock.HasRightAttributes(MethodAttributes.Assembly, bindingFlags)).Returns(true).Verifiable();
            _bindingFlagsEvaluatorMock.Setup(mock => mock.HasRightAttributes(MethodAttributes.Public, bindingFlags)).Returns(true).Verifiable();

            var binderMock = new Mock <Binder> (MockBehavior.Strict);
            var fakeResult = ReflectionObjectMother.GetSomeProperty();

            binderMock
            .Setup(
                mock => mock.SelectProperty(
                    bindingFlags,
                    It.Is <PropertyInfo[]> (param => param.SequenceEqual(new[] { properties[1], properties[2] })),
                    propertyType,
                    indexerTypes,
                    modifiers))
            .Returns(fakeResult)
            .Verifiable();

            var result = _selector.SelectSingleProperty(
                properties, binderMock.Object, bindingFlags, "Property2", _someDeclaringType, propertyType, indexerTypes, modifiers);

            _bindingFlagsEvaluatorMock.Verify();
            binderMock.Verify();
            Assert.That(result, Is.SameAs(fakeResult));
        }