Exemplo n.º 1
0
        public void GetCustomAttributes_Inheritance_BehavesLikeReflection()
        {
            var type        = typeof(DomainType);
            var mutableType = MutableTypeObjectMother.Create(type);

            CheckAttributeInheritance(mutableType, type);

            var method        = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType obj) => obj.Method());
            var mutableMethod = mutableType.GetOrAddOverride(method);

            CheckAttributeInheritance(mutableMethod, method);

            var property         = NormalizingMemberInfoFromExpressionUtility.GetProperty((DomainType obj) => obj.Property);
            var mutableGetMethod = mutableType.GetOrAddOverride(property.GetGetMethod());
            var mutableSetMethod = mutableType.GetOrAddOverride(property.GetSetMethod());
            var mutableProperty  = mutableType.AddProperty(property.Name, property.Attributes, mutableGetMethod, mutableSetMethod);

            CheckAttributeInheritance(mutableProperty, property);

            var event_              = typeof(DomainType).GetEvent("Event");
            var mutableAddMethod    = mutableType.GetOrAddOverride(event_.GetAddMethod());
            var mutableRemoveMethod = mutableType.GetOrAddOverride(event_.GetRemoveMethod());
            var mutableEvent        = mutableType.AddEvent(event_.Name, event_.Attributes, mutableAddMethod, mutableRemoveMethod);

            CheckAttributeInheritance(mutableEvent, event_);
        }
Exemplo n.º 2
0
        public void ExistingInterface_ExistingMethod_Explicit()
        {
            var implementation = GetExplicitImplementation(typeof(OtherDomainType), _existingInterfaceMethod);
            var proxyType      = MutableTypeObjectMother.Create(typeof(OtherDomainType));

            CheckGetInterfaceMap(proxyType, _existingInterfaceMethod, implementation);
        }
Exemplo n.º 3
0
        public void SetUp()
        {
            _mutableType = MutableTypeObjectMother.Create(typeof(DomainType));

            _existingInterfaceMethod   = NormalizingMemberInfoFromExpressionUtility.GetMethod((IExistingInterface obj) => obj.MethodOnExistingInterface());
            _addedInterfaceMethod      = NormalizingMemberInfoFromExpressionUtility.GetMethod((IAddedInterface obj) => obj.MethodOnAddedInterface());
            _otherAddedInterfaceMethod = NormalizingMemberInfoFromExpressionUtility.GetMethod((IOtherAddedInterface obj) => obj.MethodOnOtherAddedInterface());
        }
        public void SetUp()
        {
            _genericTypeDefinition = typeof(GenericType <,>);
            _typeArg1 = MutableTypeObjectMother.Create(typeof(object));
            _typeArg2 = MutableTypeObjectMother.Create(typeof(MakeTypePipeGenericTypeTest));

            _instantiation = _genericTypeDefinition.MakeTypePipeGenericType(_typeArg1, _typeArg2);
        }
Exemplo n.º 5
0
        public void SetUp()
        {
            _genericMethodDefinition = NormalizingMemberInfoFromExpressionUtility.GetGenericMethodDefinition(() => GenericMethod <Dev.T, Dev.T> (null));
            _typeArg1 = MutableTypeObjectMother.Create(typeof(object));
            _typeArg2 = MutableTypeObjectMother.Create(typeof(Exception));

            _instantiation = _genericMethodDefinition.MakeTypePipeGenericMethod(_typeArg1, _typeArg2);
        }
Exemplo n.º 6
0
        public void AddedInterface_ExistingMethod()
        {
            var proxyType = MutableTypeObjectMother.Create(typeof(OtherDomainType));

            proxyType.AddInterface(typeof(IAddedInterface));
            var implementation = proxyType.GetMethod("MethodOnAddedInterface");

            CheckGetInterfaceMap(proxyType, _addedInterfaceMethod, implementation);
        }
Exemplo n.º 7
0
        public void Equals_Object()
        {
            var proxyType = MutableTypeObjectMother.Create(typeof(DomainType));

            Assert.That(_mutableType.Equals((object)_mutableType), Is.True);
            Assert.That(_mutableType.Equals((object)proxyType), Is.False);
            Assert.That(_mutableType.Equals((object)typeof(DomainType)), Is.False);
            Assert.That(typeof(DomainType).Equals((object)_mutableType), Is.False);
        }
Exemplo n.º 8
0
        public void Equals_Type()
        {
            var proxyType = MutableTypeObjectMother.Create(typeof(DomainType));

            Assert.That(_mutableType.Equals(_mutableType), Is.True);
            Assert.That(_mutableType.Equals(proxyType), Is.False);
            // ReSharper disable CheckForReferenceEqualityInstead.1
            Assert.That(_mutableType.Equals(typeof(DomainType)), Is.False);
            // ReSharper restore CheckForReferenceEqualityInstead.1
            Assert.That(() => typeof(DomainType).Equals(_mutableType), Throws.TypeOf <NotSupportedException>());
        }
        public void SetUp()
        {
            _mutableType = MutableTypeObjectMother.Create(typeof(DomainType));

            _publicField  = NormalizingMemberInfoFromExpressionUtility.GetField((DomainType obj) => obj.PublicField);
            _publicMethod = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType obj) => obj.PublicMethod(0));
            _publicMethodWithOverloadEmpty = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType obj) => obj.PublicMethodWithOverload());
            _publicMethodWithOverloadInt   = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType obj) => obj.PublicMethodWithOverload(1));
            _publicProperty = NormalizingMemberInfoFromExpressionUtility.GetProperty((DomainType obj) => obj.PublicProperty);
            _publicPropertyWithIndexParameter = typeof(DomainType).GetProperty("Item");
        }
Exemplo n.º 10
0
        private IMutableMember CreateMutableInfo(params CustomAttributeDeclaration[] customAttributes)
        {
            var member = new MutableFieldInfo(MutableTypeObjectMother.Create(GetType()), "member", typeof(int), FieldAttributes.Private);

            foreach (var customAttriubte in customAttributes)
            {
                member.AddCustomAttribute(customAttriubte);
            }

            return(member);
        }
Exemplo n.º 11
0
        public new void GetHashCode()
        {
            var proxyType = MutableTypeObjectMother.Create(typeof(DomainType));

            var result = _mutableType.GetHashCode();

            Assert.That(_mutableType.GetHashCode(), Is.EqualTo(result));
            Assert.That(proxyType.GetHashCode(), Is.Not.EqualTo(result));

            _mutableType.AddInterface(typeof(IDisposable));
            Assert.That(_mutableType.GetHashCode(), Is.EqualTo(result), "Hash code must not change.");
        }
        public void MutableReflection()
        {
            var mutableType     = MutableTypeObjectMother.Create(typeof(DomainType));
            var typeInitializer = mutableType.AddTypeInitializer(ctx => Expression.Empty());
            var field           = mutableType.AddField("_field", FieldAttributes.Private, typeof(int));
            var ctor            = mutableType.AddedConstructors.Single();
            var method          = mutableType.AddMethod(
                "Method", MethodAttributes.Public, typeof(int), new[] { new ParameterDeclaration(typeof(int)) }, ctx => Expression.Constant(7));
            var returnParameter = method.MutableReturnParameter;
            var parameter       = method.MutableParameters.Single();
            var property        = mutableType.AddProperty(
                "Property", typeof(int), new[] { new ParameterDeclaration(typeof(int)) }, MethodAttributes.Public, ctx => Expression.Default(typeof(int)), ctx => Expression.Empty());
            var event_ = mutableType.AddEvent("Event", typeof(Action), MethodAttributes.Public, ctx => Expression.Empty(), ctx => Expression.Empty());

            // TODO 4791
            // var genericParmaeter = proxyType.MutableGenericParameter.Single();
            //var nestedType = MutableType.GetNestedTypes().Single();

            AddAbcAttribute(mutableType, "class");
            AddAbcAttribute(typeInitializer, "type initializer");
            AddAbcAttribute(field, "field");
            AddAbcAttribute(ctor, "constructor");
            AddAbcAttribute(method, "method");
            AddAbcAttribute(returnParameter, "return value");
            AddAbcAttribute(parameter, "parameter");
            AddAbcAttribute(property, "property");
            AddAbcAttribute(event_, "event");

            CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(mutableType), CustomAttributeData.GetCustomAttributes(_type));
            CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(field), CustomAttributeData.GetCustomAttributes(_field));
            CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(ctor), CustomAttributeData.GetCustomAttributes(_ctor));
            CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(method), CustomAttributeData.GetCustomAttributes(_method));
            CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(returnParameter), CustomAttributeData.GetCustomAttributes(_returnParameter));
            CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(parameter), CustomAttributeData.GetCustomAttributes(_parameter));
            CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(property), CustomAttributeData.GetCustomAttributes(_property));
            CheckAbcAttribute(TypePipeCustomAttributeData.GetCustomAttributes(event_), CustomAttributeData.GetCustomAttributes(_event));
            //CheckAbcAttribute (TypePipeCustomAttributeData.GetCustomAttributes (nestedType), "nested type");
            // Generic Parameters
        }
Exemplo n.º 13
0
 public void SetUp()
 {
     _mutableType = MutableTypeObjectMother.Create(typeof(DomainType));
 }