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 }); }
public void SetGenericParameterConstraints_GenericParameter() { var genericParameter = ReflectionObjectMother.GetSomeGenericParameter(); Assert.That(genericParameter.IsClass, Is.True); _parameter.SetGenericParameterConstraints(new[] { genericParameter }); Assert.That(_parameter.BaseType, Is.SameAs(typeof(object))); }
public void SetUp() { _declaringType = MutableTypeObjectMother.Create(); _isStatic = BooleanObjectMother.GetRandomBoolean(); _parameters = new[] { Expression.Parameter(typeof(string)) }; _genericParameters = new[] { ReflectionObjectMother.GetSomeGenericParameter() }; _returnType = ReflectionObjectMother.GetSomeType(); _baseMethod = ReflectionObjectMother.GetSomeMethod(); _context = new TestableMethodBodyContextBase( _declaringType, _isStatic, _parameters.AsOneTime(), _genericParameters.AsOneTime(), _returnType, _baseMethod); }
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)); }
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 GetEmittableXXX_RuntimeInfos() { var type = ReflectionObjectMother.GetSomeType(); var genericParameter = ReflectionObjectMother.GetSomeGenericParameter(); var field = ReflectionObjectMother.GetSomeField(); var ctor = ReflectionObjectMother.GetSomeConstructor(); var method = ReflectionObjectMother.GetSomeMethod(); Assert.That(_provider.GetEmittableType(type), Is.SameAs(type)); Assert.That(_provider.GetEmittableType(genericParameter), Is.SameAs(genericParameter)); Assert.That(_provider.GetEmittableField(field), Is.SameAs(field)); Assert.That(_provider.GetEmittableConstructor(ctor), Is.SameAs(ctor)); Assert.That(_provider.GetEmittableMethod(method), Is.SameAs(method)); }
public void SetUp() { _declaringType = MutableTypeObjectMother.Create(); _isStatic = BooleanObjectMother.GetRandomBoolean(); _parameters = new[] { Expression.Parameter(typeof(int)), Expression.Parameter(typeof(object)) }; _baseMethod = ReflectionObjectMother.GetSomeMethod(); _genericParameters = new[] { ReflectionObjectMother.GetSomeGenericParameter() }; _returnType = ReflectionObjectMother.GetSomeType(); _previousBody = Expression.Block(_parameters[0], _parameters[1]); _context = new MethodBodyModificationContext( _declaringType, _isStatic, _parameters.AsOneTime(), _genericParameters.AsOneTime(), _returnType, _baseMethod, _previousBody); _contextWithoutPreviousBody = new MethodBodyModificationContext( _declaringType, _isStatic, _parameters, _genericParameters, _returnType, _baseMethod, null); }
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 GetEmittableXXX_Mutable() { var emittableType = ReflectionObjectMother.GetSomeType(); var emittableGenericParameter = ReflectionObjectMother.GetSomeGenericParameter(); var emittableField = ReflectionObjectMother.GetSomeField(); var emittableConstructor = ReflectionObjectMother.GetSomeConstructor(); var emittableMethod = ReflectionObjectMother.GetSomeMethod(); _provider.AddMapping(_mutableType, emittableType); _provider.AddMapping(_mutableGenericParameter, emittableGenericParameter); _provider.AddMapping(_mutableField, emittableField); _provider.AddMapping(_mutableConstructor, emittableConstructor); _provider.AddMapping(_mutableMethod, emittableMethod); Assert.That(_provider.GetEmittableType(_mutableType), Is.SameAs(emittableType)); Assert.That(_provider.GetEmittableType(_mutableGenericParameter), Is.SameAs(emittableGenericParameter)); Assert.That(_provider.GetEmittableField(_mutableField), Is.SameAs(emittableField)); Assert.That(_provider.GetEmittableConstructor(_mutableConstructor), Is.SameAs(emittableConstructor)); Assert.That(_provider.GetEmittableMethod(_mutableMethod), Is.SameAs(emittableMethod)); }
public void DelegatingMembers() { var mappedType = MutableTypeObjectMother.Create(); var mappedGenericParameter = MutableGenericParameterObjectMother.Create(); var mappedField = MutableFieldInfoObjectMother.Create(); var mappedConstructor = MutableConstructorInfoObjectMother.Create(); var mappedMethod = MutableMethodInfoObjectMother.Create(); var emittableType = ReflectionObjectMother.GetSomeType(); var emittableGenericParameter = ReflectionObjectMother.GetSomeGenericParameter(); var emittableField = ReflectionObjectMother.GetSomeField(); var emittableConstructor = ReflectionObjectMother.GetSomeConstructor(); var emittableMethod = ReflectionObjectMother.GetSomeMethod(); var helper = new DecoratorTestHelper <IEmittableOperandProvider> (_decorator, _innerMock); helper.CheckDelegation(d => d.AddMapping(mappedType, emittableType)); helper.CheckDelegation(d => d.AddMapping(mappedGenericParameter, emittableGenericParameter)); helper.CheckDelegation(d => d.AddMapping(mappedField, emittableField)); helper.CheckDelegation(d => d.AddMapping(mappedConstructor, emittableConstructor)); helper.CheckDelegation(d => d.AddMapping(mappedMethod, emittableMethod)); }
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); }