public void GetAllXXX_UsesAllBindingFlagsToRetrieveMembers()
        {
            var fields     = _baseTypeConstraint.GetFields(c_allMembers);
            var methods    = _baseTypeConstraint.GetMethods(c_allMembers);
            var properties = _baseTypeConstraint.GetProperties(c_allMembers);
            var events     = _baseTypeConstraint.GetEvents(c_allMembers);

            var baseMemberSelectorMock = MockRepository.GenerateStrictMock <IMemberSelector>();
            var baseTypeConstraint     = CustomTypeObjectMother.Create(
                baseMemberSelectorMock, fields: fields, methods: methods, properties: properties, events: events);

            baseMemberSelectorMock.Expect(mock => mock.SelectFields(fields, c_allMembers, baseTypeConstraint)).Return(fields);
            // Note: GetMethods is optimized for retrieving all the methods; so there is no memberSelectorMock call.
            baseMemberSelectorMock.Expect(mock => mock.SelectProperties(properties, c_allMembers, baseTypeConstraint)).Return(properties);
            baseMemberSelectorMock.Expect(mock => mock.SelectEvents(events, c_allMembers, baseTypeConstraint)).Return(events);

            var parameter = MutableGenericParameterObjectMother.Create(constraints: new[] { baseTypeConstraint, _interfaceConstraint });

            Assert.That(parameter.GetAllFields(), Is.EqualTo(fields));
            Assert.That(parameter.GetAllMethods(), Is.EqualTo(methods));
            Assert.That(parameter.GetAllProperties(), Is.EqualTo(properties));
            Assert.That(parameter.GetAllEvents(), Is.EqualTo(events));

            baseMemberSelectorMock.AssertWasNotCalled(
                mock => mock.SelectMethods(Arg <IEnumerable <ConstructorInfo> > .Is.Anything, Arg <BindingFlags> .Is.Anything, Arg <Type> .Is.Anything));
            baseMemberSelectorMock.VerifyAllExpectations();
        }
示例#2
0
        public void FullName_NestedType()
        {
            var enclosingType = CustomTypeObjectMother.Create(declaringType: typeof(object), name: "EnclosingType");

            _customType.CallSetDeclaringType(enclosingType);
            Assert.That(_customType.FullName, Is.EqualTo("MyNamespace.Object+EnclosingType+TypeName"));
        }
示例#3
0
        public void GetAllXXX_UsesAllBindingFlagsToRetrieveMembers()
        {
            var fields     = _baseTypeConstraint.GetFields(c_allMembers);
            var methods    = _baseTypeConstraint.GetMethods(c_allMembers);
            var properties = _baseTypeConstraint.GetProperties(c_allMembers);
            var events     = _baseTypeConstraint.GetEvents(c_allMembers);

            var baseMemberSelectorMock = new Mock <IMemberSelector> (MockBehavior.Strict);
            var baseTypeConstraint     = CustomTypeObjectMother.Create(
                baseMemberSelectorMock.Object, fields: fields, methods: methods, properties: properties, events: events);

            baseMemberSelectorMock.Setup(mock => mock.SelectFields(fields, c_allMembers, baseTypeConstraint)).Returns(fields).Verifiable();
            // Note: GetMethods is optimized for retrieving all the methods; so there is no memberSelectorMock call.
            baseMemberSelectorMock.Setup(mock => mock.SelectProperties(properties, c_allMembers, baseTypeConstraint)).Returns(properties).Verifiable();
            baseMemberSelectorMock.Setup(mock => mock.SelectEvents(events, c_allMembers, baseTypeConstraint)).Returns(events).Verifiable();

            var parameter = MutableGenericParameterObjectMother.Create(constraints: new[] { baseTypeConstraint, _interfaceConstraint });

            Assert.That(parameter.GetAllFields(), Is.EqualTo(fields));
            Assert.That(parameter.GetAllMethods(), Is.EqualTo(methods));
            Assert.That(parameter.GetAllProperties(), Is.EqualTo(properties));
            Assert.That(parameter.GetAllEvents(), Is.EqualTo(events));

            baseMemberSelectorMock.Verify(mock => mock.SelectMethods(It.IsAny <IEnumerable <ConstructorInfo> >(), It.IsAny <BindingFlags>(), It.IsAny <Type>()), Times.Never());
            baseMemberSelectorMock.Verify();
        }
示例#4
0
        public void Initialization_TypeArguments()
        {
            var elementType = CustomTypeObjectMother.Create(typeArguments: new[] { ReflectionObjectMother.GetSomeType() });
            var type        = ArrayTypeBaseObjectMother.Create(elementType);

            Assert.That(type.GetGenericArguments(), Is.Empty);
        }
        public void SetUp()
        {
            _declaringType = CustomTypeObjectMother.Create();
            _attributes    = (MethodAttributes)7 | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName;

            _constructor = new TestableCustomConstructorInfo(_declaringType, _attributes);
        }
示例#6
0
        public void SetUp()
        {
            _elementType = CustomTypeObjectMother.Create();
            _rank        = 2;

            _type = new MultiDimensionalArrayType(_elementType, _rank);
        }
示例#7
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 });
        }
示例#8
0
        public void GetTypeCodeFast()
        {
            var runtimeType = ReflectionObjectMother.GetSomeType();
            var customType  = CustomTypeObjectMother.Create();

            Assert.That(runtimeType.GetTypePipeTypeCode(), Is.EqualTo(Type.GetTypeCode(runtimeType)));
            Assert.That(customType.GetTypePipeTypeCode(), Is.EqualTo(TypeCode.Object));
        }
示例#9
0
        public void IsRuntimeType()
        {
            var runtimeType = ReflectionObjectMother.GetSomeType();
            var customType  = CustomTypeObjectMother.Create();

            Assert.That(runtimeType.IsRuntimeType(), Is.True);
            Assert.That(customType.IsRuntimeType(), Is.False);
        }
示例#10
0
        public void IsAssignableFromFast_CustomType_OnLeftSide()
        {
            var customType = CustomTypeObjectMother.Create();

            Assert.That(customType.IsTypePipeAssignableFrom(customType), Is.True);
            Assert.That(customType.IsTypePipeAssignableFrom(customType.BaseType), Is.False);
            Assert.That(customType.IsTypePipeAssignableFrom(typeof(object)), Is.False);
        }
示例#11
0
        public void SetUp()
        {
            _declaringType = CustomTypeObjectMother.Create();
            _attributes    = (MethodAttributes)7 | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName;
            _parameters    = ParameterDeclarationObjectMother.CreateMultiple(2);

            _constructor = new ConstructorOnCustomType(_declaringType, _attributes, _parameters);
        }
示例#12
0
        public void SetUp()
        {
            var customAttributes = new[] { CustomAttributeDeclarationObjectMother.Create() };

            _elementType = CustomTypeObjectMother.Create(
                name: "Abc", @namespace: "MyNs", typeArguments: new[] { typeof(int) }, customAttributeDatas: customAttributes);

            _type = new ByRefType(_elementType);
        }
示例#13
0
        public void SetUp()
        {
            _declaringType = CustomTypeObjectMother.Create();
            _name          = "abc";
            _type          = ReflectionObjectMother.GetSomeType();
            _attributes    = (FieldAttributes)7;

            _field = new TestableCustomFieldInfo(_declaringType, _name, _type, _attributes);
        }
示例#14
0
        public void SetUp()
        {
            _genericTypeDefinition = typeof(DeclaringType <> .GenericType <>);
            _outerCustomType       = CustomTypeObjectMother.Create();
            _customType            = CustomTypeObjectMother.Create();
            _typeArguments         = new Type[] { _outerCustomType, _customType };
            _instantiationInfo     = new TypeInstantiationInfo(_genericTypeDefinition, _typeArguments);

            _instantiation = new TypeInstantiation(_instantiationInfo, new TypeInstantiationContext());
        }
        public void ToDebugString()
        {
            var declaringType = CustomTypeObjectMother.Create(name: "Abc");
            var ctor          = CustomConstructorInfoObjectMother.Create(
                declaringType, parameters: new ParameterInfo[] { CustomParameterInfoObjectMother.Create(type: typeof(int)) });

            var expected = "TestableCustomConstructor = \"Void .ctor(Int32)\", DeclaringType = \"Abc\"";

            Assert.That(ctor.ToDebugString(), Is.EqualTo(expected));
        }
示例#16
0
        public void Sort_BaseType_MutableTypeArgument()
        {
            var typeArg     = MutableTypeObjectMother.Create();
            var baseType    = CustomTypeObjectMother.Create(typeArguments: new[] { typeArg });
            var derivedType = MutableTypeObjectMother.Create(baseType: baseType);

            var result = _sorter.Sort(new[] { derivedType, typeArg }.AsOneTime());

            Assert.That(result, Is.EqualTo(new[] { typeArg, derivedType }));
        }
示例#17
0
        public void ToDebugString()
        {
            var declaringType = CustomTypeObjectMother.Create(name: "MyType");
            var name          = "MyEvent";
            var event_        = CustomEventInfoObjectMother.Create(declaringType, name, addMethod: _publicAddMethod, removeMethod: _publicRemoveMethod);

            var expected = "TestableCustomEvent = \"MyEventDelegate MyEvent\", DeclaringType = \"MyType\"";

            Assert.That(event_.ToDebugString(), Is.EqualTo(expected));
        }
        public void SetUp()
        {
            _genericMethodDefinition = NormalizingMemberInfoFromExpressionUtility.GetGenericMethodDefinition(() => GenericMethod <Dev.T> (null));

            _customType  = CustomTypeObjectMother.Create();
            _runtimeType = ReflectionObjectMother.GetSomeType();

            _infoWithCustomType  = new MethodInstantiationInfo(_genericMethodDefinition, new[] { _customType }.AsOneTime());
            _infoWithRuntimeType = new MethodInstantiationInfo(_genericMethodDefinition, new[] { _runtimeType });
        }
示例#19
0
        public void IsAssignableFromFast_CustomType_OnRightSide_CustomBaseTypeAndInterfaces()
        {
            var customBaseType      = CustomTypeObjectMother.Create();
            var customInterfaceType = CustomTypeObjectMother.Create();
            var customType          = CustomTypeObjectMother.Create(baseType: customBaseType, interfaces: new[] { customInterfaceType });

            Assert.That(customType.IsTypePipeAssignableFrom(customType), Is.True);
            Assert.That(customBaseType.IsTypePipeAssignableFrom(customType), Is.True);
            Assert.That(customInterfaceType.IsTypePipeAssignableFrom(customType), Is.True);
        }
        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);
        }
示例#21
0
        public void SetUp()
        {
            var customAttributes = new[] { CustomAttributeDeclarationObjectMother.Create() };

            _elementType = CustomTypeObjectMother.Create(name: "Abc", @namespace: "MyNs", customAttributeDatas: customAttributes);
            _rank        = 2;

            _type = new TestableArrayTypeBase(_elementType, _rank);

            _realArrayTypeForComparison = typeof(string[]);
        }
示例#22
0
        public void Equals()
        {
            var customType1 = CustomTypeObjectMother.Create(name: "Proxy");
            var customType2 = CustomTypeObjectMother.Create(name: "Proxy");

            // Equals compares references and does not use the UnderlyingSystemType property.
            Assert.That(customType1.Equals((object)customType1), Is.True);
            Assert.That(customType1.Equals((object)customType2), Is.False);
            Assert.That(customType1.Equals(customType1), Is.True);
            Assert.That(customType1.Equals(customType2), Is.False);
        }
示例#23
0
        public void SetUp()
        {
            _declaringType = CustomTypeObjectMother.Create();
            _name          = "Method";
            _attributes    = (MethodAttributes)7;
            _typeArguments = new[] { ReflectionObjectMother.GetSomeType() };
            _returnType    = ReflectionObjectMother.GetSomeType();
            _parameters    = ParameterDeclarationObjectMother.CreateMultiple(2);

            _method = new MethodOnCustomType(_declaringType, _name, _attributes, _typeArguments, _returnType, _parameters);
        }
示例#24
0
        public new void GetHashCode()
        {
            var customType = CustomTypeObjectMother.Create(name: "Proxy");

            var result = customType.GetHashCode();

            var otherCustomType = CustomTypeObjectMother.Create(name: "Proxy");

            // This test is safe because the hash code is the object reference.
            Assert.That(result, Is.Not.EqualTo(otherCustomType.GetHashCode()));
        }
示例#25
0
        public void Sort_GetInterfaces_MutableTypeArgument()
        {
            var typeArg    = MutableTypeObjectMother.Create();
            var interface_ = CustomTypeObjectMother.Create(attributes: TypeAttributes.Interface, typeArguments: new[] { typeArg });
            var type       = MutableTypeObjectMother.Create();

            type.AddInterface(interface_);

            var result = _sorter.Sort(new[] { type, typeArg });

            Assert.That(result, Is.EqualTo(new[] { typeArg, type }));
        }
示例#26
0
        public void MakeTypePipeGenericMethod_MakesGenericMethodWithCustomTypeArgument()
        {
            var genericMethodDefinition = NormalizingMemberInfoFromExpressionUtility.GetGenericMethodDefinition(() => Method <Dev.T, Dev.T>());
            var runtimeType             = ReflectionObjectMother.GetSomeType();
            var customType = CustomTypeObjectMother.Create();

            var result = genericMethodDefinition.MakeTypePipeGenericMethod(runtimeType, customType);

            Assert.That(result.IsGenericMethod, Is.True);
            Assert.That(result.IsGenericMethodDefinition, Is.False);
            Assert.That(result.GetGenericArguments(), Is.EqualTo(new[] { runtimeType, customType }));
        }
        public void Instantiate_CustomGenericTypeDefinition()
        {
            var typeParameter = ReflectionObjectMother.GetSomeGenericParameter();
            var customGenericTypeDefinition = CustomTypeObjectMother.Create(typeArguments: new[] { typeParameter });
            var instantiationInfo           = new TypeInstantiationInfo(customGenericTypeDefinition, new[] { _customType });

            var result = _context.Instantiate(instantiationInfo);

            Assert.That(result, Is.TypeOf <TypeInstantiation>());
            Assert.That(result.GetGenericTypeDefinition(), Is.SameAs(customGenericTypeDefinition));
            Assert.That(result.GetGenericArguments(), Is.EqualTo(new[] { _customType }));
        }
示例#28
0
        public void MakeTypePipeGenericType_MakesGenericTypeWithCustomTypeArgument()
        {
            var genericTypeDefinition = typeof(Dictionary <,>);
            var runtimeType           = ReflectionObjectMother.GetSomeType();
            var customType            = CustomTypeObjectMother.Create();

            var result = genericTypeDefinition.MakeTypePipeGenericType(runtimeType, customType);

            Assert.That(result.IsGenericType, Is.True);
            Assert.That(result.IsGenericTypeDefinition, Is.False);
            Assert.That(result.GetGenericArguments(), Is.EqualTo(new[] { runtimeType, customType }));
        }
        public void SetUp()
        {
            _context = new TypeInstantiationContext();

            _genericTypeDefinition = typeof(List <>);
            _customType            = CustomTypeObjectMother.Create();
            _info = new TypeInstantiationInfo(_genericTypeDefinition, new[] { _customType }.AsOneTime());

            _parameter             = typeof(GenericType <>).GetGenericArguments().Single();
            _argument              = ReflectionObjectMother.GetSomeType();
            _parametersToArguments = new Dictionary <Type, Type> {
                { _parameter, _argument }
            };
        }
        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);
        }