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 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 })); }
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 })); }
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 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 IsAssignableFromFast_CustomType_OnRightSide() { var customType = CustomTypeObjectMother.Create(baseType: typeof(List <int>), interfaces: new[] { typeof(IDisposable) }); Assert.That(customType.IsTypePipeAssignableFrom(customType), Is.True); Assert.That(typeof(List <int>).IsTypePipeAssignableFrom(customType), Is.True); Assert.That(typeof(object).IsTypePipeAssignableFrom(customType), Is.True); Assert.That(typeof(IDisposable).IsTypePipeAssignableFrom(customType), Is.True); var unrelatedType = ReflectionObjectMother.GetSomeType(); Assert.That(unrelatedType.IsTypePipeAssignableFrom(customType), Is.False); }
public void SetUp() { _publicAddMethod = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType o) => o.PublicAddMethod(null)); _publicRemoveMethod = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType o) => o.PublicRemoveMethod(null)); _publicRaiseMethod = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType o) => o.PublicRaiseMethod("", 7)); _nonPublicAddMethod = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType o) => o.NonPublicAddMethod(null)); _nonPublicRemoveMethod = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType o) => o.NonPublicRemoveMethod(null)); _nonPublicRaiseMethod = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType o) => o.NonPublicRaiseMethod("", 7)); _declaringType = CustomTypeObjectMother.Create(); _name = "Event"; _attributes = (EventAttributes)7; _event = new TestableCustomEventInfo(_declaringType, _name, _attributes, _publicAddMethod, _publicRemoveMethod, _publicRaiseMethod); }
public void Initialization_MemberInitializationIsLazy_AndUsesAllBindingFlagsToRetrieveMembers() { var bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static; var nestedTypes = _genericTypeDefinition.GetNestedTypes(bindingFlags); var fields = _genericTypeDefinition.GetFields(bindingFlags); var ctors = _genericTypeDefinition.GetConstructors(bindingFlags); var methods = _genericTypeDefinition.GetMethods(bindingFlags); var properties = _genericTypeDefinition.GetProperties(bindingFlags); var events = _genericTypeDefinition.GetEvents(bindingFlags); var memberSelectorMock = new Mock <IMemberSelector> (MockBehavior.Strict); var typeParameters = new[] { ReflectionObjectMother.GetSomeType() }; var genericTypeDefinition = CustomTypeObjectMother.Create(memberSelectorMock.Object, typeArguments: typeParameters, nestedTypes: nestedTypes, fields: fields, constructors: ctors, methods: methods, properties: properties, events: events); // TODO 5816 //memberSelectorMock.Setup (mock => mock.SelectTypes (nestedTypes, bindingFlags)).Returns (nestedTypes); memberSelectorMock.Setup(mock => mock.SelectFields(fields, bindingFlags, genericTypeDefinition)).Returns(fields).Verifiable(); memberSelectorMock.Setup(mock => mock.SelectMethods(ctors, bindingFlags, genericTypeDefinition)).Returns(ctors).Verifiable(); // Note: GetMethods is optimized for retrieving all the methods; so there is no memberSelectorMock call. memberSelectorMock.Setup(mock => mock.SelectProperties(properties, bindingFlags, genericTypeDefinition)).Returns(properties).Verifiable(); memberSelectorMock.Setup(mock => mock.SelectEvents(events, bindingFlags, genericTypeDefinition)).Returns(events).Verifiable(); var typeArguments = new[] { ReflectionObjectMother.GetSomeType() }; var info = new TypeInstantiationInfo(genericTypeDefinition, typeArguments); var typeInstantiation = new TypeInstantiation(info, new TypeInstantiationContext()); // Evaluation is lazy. memberSelectorMock.Verify(mock => mock.SelectTypes(nestedTypes, bindingFlags), Times.Never()); memberSelectorMock.Verify(mock => mock.SelectFields(fields, bindingFlags, genericTypeDefinition), Times.Never()); memberSelectorMock.Verify(mock => mock.SelectMethods(ctors, bindingFlags, genericTypeDefinition), Times.Never()); // Note: GetMethods is optimized for retrieving all the methods; so there is no memberSelectorMock call. memberSelectorMock.Verify(mock => mock.SelectProperties(properties, bindingFlags, genericTypeDefinition), Times.Never()); memberSelectorMock.Verify(mock => mock.SelectEvents(events, bindingFlags, genericTypeDefinition), Times.Never()); // Trigger instantiation. // TODO 5816 //Dev.Null = typeInstantiation.GetNestedTypes(); Dev.Null = typeInstantiation.GetFields(); Dev.Null = typeInstantiation.GetConstructors(); Dev.Null = typeInstantiation.GetMethods(); Dev.Null = typeInstantiation.GetProperties(); Dev.Null = typeInstantiation.GetEvents(); memberSelectorMock.Verify(); }
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); }
public void Equals_Object() { var type1 = ArrayTypeBaseObjectMother.Create(CustomTypeObjectMother.Create(), _rank); var type2 = ArrayTypeBaseObjectMother.Create(_elementType, 3); var type3 = ArrayTypeBaseObjectMother.Create(_elementType, _rank); Assert.That(_type.Equals((object)null), Is.False); Assert.That(_type.Equals(new object()), Is.False); Assert.That(_type.Equals((object)type1), Is.False); Assert.That(_type.Equals((object)type2), Is.False); Assert.That(_type.Equals((object)type3), Is.True); var multiDimensionalArrayOfRank1 = MultiDimensionalArrayTypeObjectMother.Create(_elementType, 1); var vector = VectorTypeObjectMother.Create(_elementType); Assert.That(multiDimensionalArrayOfRank1.Equals((object)vector), Is.False); }
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)); }
public void Equals_Type() { var type1 = ArrayTypeBaseObjectMother.Create(CustomTypeObjectMother.Create(), _rank); var type2 = ArrayTypeBaseObjectMother.Create(_elementType, 3); var type3 = ArrayTypeBaseObjectMother.Create(_elementType, _rank); // ReSharper disable CheckForReferenceEqualityInstead.1 Assert.That(_type.Equals(null), Is.False); // ReSharper restore CheckForReferenceEqualityInstead.1 Assert.That(_type.Equals(type1), Is.False); Assert.That(_type.Equals(type2), Is.False); Assert.That(_type.Equals(type3), Is.True); var multiDimensionalArrayOfRank1 = MultiDimensionalArrayTypeObjectMother.Create(_elementType, 1); var vector = VectorTypeObjectMother.Create(_elementType); Assert.That(multiDimensionalArrayOfRank1.Equals(vector), Is.False); }
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 }); }
public void SetUp() { _elementType = CustomTypeObjectMother.Create(); _type = new VectorType(_elementType); }
public void FullName_NullNamespace() { var customType = CustomTypeObjectMother.Create(name: "MyName", @namespace: null); Assert.That(customType.FullName, Is.EqualTo("MyName")); }