Пример #1
0
        public void GetAllMethods()
        {
            var result = _constrainedParameter.GetAllMethods();

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

            Assert.That(result, Has.Member(method));
            Assert.That(result, Is.EquivalentTo(typeof(DomainType).GetMethods(c_allMembers)));
        }
Пример #2
0
        public void GetPointcut_StrongContext_ParameterIndex()
        {
            var advice = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType obj) => obj.ParameterIndex(ref _dummy));

            var pointcut = CheckPointcut <ArgumentIndexPointcut> (advice);

            Assert.That(pointcut.ArgumentType, Is.EqualTo(typeof(string)));
            Assert.That(pointcut.Index, Is.EqualTo(1));
        }
Пример #3
0
        public void Create_NonGenericMethod()
        {
            var method    = NormalizingMemberInfoFromExpressionUtility.GetMethod((object obj) => obj.Equals(null));
            var signature = MethodSignature.Create(method);

            Assert.That(signature.ReturnType, Is.SameAs(typeof(bool)));
            Assert.That(signature.GenericParameterCount, Is.EqualTo(0));
            Assert.That(signature.ParameterTypes, Is.EqualTo(new[] { typeof(object) }));
        }
Пример #4
0
        public void IsShadowed_BaseTypeMethod_NotShadowedByItself()
        {
            var baseDefinition      = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainTypeBase obj) => obj.BaseTypeMethod());
            var shadowingCandidates = GetDeclaredMethods(typeof(DomainTypeBase));

            var result = _finder.IsShadowed(baseDefinition, shadowingCandidates);

            Assert.That(result, Is.False);
        }
Пример #5
0
        public void FieldConstant()
        {
            var template = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType o) => o.FieldConstant());
            var field    = NormalizingMemberInfoFromExpressionUtility.GetField(() => Type.EmptyTypes);

            var instance = ReturnMemberInfoViaConstantExpression(template, field);

            Assert.That(instance.FieldConstant(), Is.EqualTo(field));
        }
Пример #6
0
        public void IsShadowed_VirtualMethodShadowingBaseMethod_NonMatchingSignature()
        {
            var baseDefinition      = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainTypeBase obj) => obj.VirtualMethodShadowingBaseMethod(7));
            var shadowingCandidates = GetDeclaredMethods(typeof(DomainType));

            var result = _finder.IsShadowed(baseDefinition, shadowingCandidates);

            Assert.That(result, Is.False);
        }
Пример #7
0
        public void MethodPointcut()
        {
            var trueMethod  = NormalizingMemberInfoFromExpressionUtility.GetMethod(() => DomainAspect.TruePointcutMethod());
            var falseMethod = NormalizingMemberInfoFromExpressionUtility.GetMethod(() => DomainAspect.FalsePointcutMethod());
            var joinPoint   = ObjectMother.GetJoinPoint();

            CheckMatches(new MethodPointcut(trueMethod), joinPoint);
            CheckMatchesNot(new MethodPointcut(falseMethod), joinPoint);
        }
Пример #8
0
        public void TypeConstant()
        {
            var template = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType o) => o.TypeConstant());
            var type     = typeof(int);

            var instance = ReturnMemberInfoViaConstantExpression(template, type);

            Assert.That(instance.TypeConstant(), Is.SameAs(type));
        }
Пример #9
0
        public void IsShadowed_OverridingShadowingMethod()
        {
            var baseDefinition      = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainTypeBaseBase obj) => obj.OverridingShadowingMethod());
            var shadowingCandidates = GetDeclaredMethods(typeof(DomainType));

            var result = _finder.IsShadowed(baseDefinition, shadowingCandidates);

            Assert.That(result, Is.True);
        }
Пример #10
0
        public void AddExplicitBaseDefinition_UnrelatedMethod()
        {
            var unrelatedMethodDefinition = NormalizingMemberInfoFromExpressionUtility.GetMethod((UnrelatedType obj) => obj.VirtualMethod());

            Assert.That(
                () => _virtualMethod.AddExplicitBaseDefinition(unrelatedMethodDefinition),
                Throws.ArgumentException
                .With.ArgumentExceptionMessageEqualTo("The overridden method must be from the same type hierarchy.", "overriddenMethodBaseDefinition"));
        }
Пример #11
0
        public void AddExplicitBaseDefinition_CannotAddExplicitBaseDefinition()
        {
            var overriddenMethodDefinition = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType obj) => obj.VirtualMethod());

            Assert.That(
                () => _method.AddExplicitBaseDefinition(overriddenMethodDefinition),
                Throws.InstanceOf <NotSupportedException>()
                .With.Message.EqualTo("Cannot add an explicit base definition to the non-virtual method 'NonVirtualMethod'."));
        }
Пример #12
0
        public void NewDelegate_StaticMethod()
        {
            var delegateType = typeof(Action);
            var staticMethod = NormalizingMemberInfoFromExpressionUtility.GetMethod(() => StaticMethod());

            var result = Expression.NewDelegate(delegateType, null, staticMethod);

            Assert.That(result.Target, Is.Null);
        }
        public void GetMemberSignature_Method()
        {
            var method = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType obj) => obj.Method());

            var result = MemberSignatureProvider.GetMemberSignature(method);

            Assert.That(result, Is.TypeOf <MethodSignature> ());
            Assert.That(result.ToString(), Is.EqualTo("System.Double()"));
        }
        public void SetUp()
        {
            _interceptedMethod = NormalizingMemberInfoFromExpressionUtility.GetMethod((object o) => o.Equals(null));
            _propertyName      = "abc";

            _interceptor = new WrappingAccessorInterceptor(_interceptedMethod, _propertyName);

            _proxyType = MutableTypeObjectMother.Create();
        }
Пример #15
0
        public void GetPointcut_AttributeProvider_StrongContext()
        {
            var advice = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType obj) => obj.AttributeAndContext(ref _dummy));

            var pointcut = CheckPointcut <AllPointcut> (advice);

            Assert.That(pointcut.Pointcuts, Has.Length.EqualTo(2));
            Assert.That(pointcut.Pointcuts, Has.Some.TypeOf <TypePointcut>());
            Assert.That(pointcut.Pointcuts, Has.Some.TypeOf <MemberNamePointcut>());
        }
Пример #16
0
        public void AddExplicitBaseDefinition_IncompatibleSignatures()
        {
            var differentSignatureMethodDefinition =
                NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType obj) => obj.VirtualMethodWithDifferentSignature(7));

            Assert.That(
                () => _virtualMethod.AddExplicitBaseDefinition(differentSignatureMethodDefinition),
                Throws.ArgumentException
                .With.ArgumentExceptionMessageEqualTo("Method signatures must be equal.", "overriddenMethodBaseDefinition"));
        }
Пример #17
0
        public void GetBaseDefinition()
        {
            var baseMethod     = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType obj) => obj.OverridingMethod());
            var rootDefinition = baseMethod.GetBaseDefinition();

            Assert.That(rootDefinition, Is.Not.EqualTo(baseMethod));
            var method = MutableMethodInfoObjectMother.Create(baseMethod: baseMethod);

            Assert.That(method.GetBaseDefinition(), Is.SameAs(rootDefinition));
        }
Пример #18
0
        public void InterfaceMethod_AlreadyExplicitlyImplemented()
        {
            var method = NormalizingMemberInfoFromExpressionUtility.GetMethod((IDomainInterface obj) => obj.ExplicitlyImplemented());

            var type = AssembleType <DomainType> (p => p.AddExplicitOverride(method, ctx => Expression.Constant("new explicit impl")));

            var instance = Activator.CreateInstance(type);

            Assert.That(((IDomainInterface)instance).ExplicitlyImplemented(), Is.EqualTo("new explicit impl"));
        }
        public void GetOrCreateOverride_UnrelatedDeclaringType()
        {
            var method = NormalizingMemberInfoFromExpressionUtility.GetMethod((IDisposable obj) => obj.Dispose());

            Assert.That(
                () => _factory.GetOrCreateOverride(_mutableType, method, out _isNewlyCreated),
                Throws.ArgumentException
                .With.ArgumentExceptionMessageEqualTo(
                    "Method is declared by type 'IDisposable' outside of the proxy base class hierarchy.", "overriddenMethod"));
        }
Пример #20
0
        public void GetBaseMethod_OverridingOverriddenMethod()
        {
            var method = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType obj) => obj.OverridingOverriddenMethod());

            var result = _finder.GetBaseMethod(method);

            var expectedMethod = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainTypeBase obj) => obj.OverridingOverriddenMethod());

            Assert.That(result, Is.EqualTo(expectedMethod));
        }
Пример #21
0
        public void GetMostDerivedOverride_ShadowingOverridenMethod()
        {
            var baseDefinition = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainTypeBaseBase obj) => obj.ShadowingOverridenMethod());

            var result = _finder.GetMostDerivedOverride(baseDefinition, _typeToStartSearch);

            var expected = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainTypeBase obj) => obj.ShadowingOverridenMethod());

            Assert.That(result, Is.EqualTo(expected));
        }
        public void NonVirtualBase_ReImplement_BaseNonAccessible()
        {
            var interfaceMethod = NormalizingMemberInfoFromExpressionUtility.GetMethod((IMyInterface o) => o.Method3());

            Assert.That(
                () => AssembleType <DomainType> (p => p.GetOrAddImplementation(interfaceMethod).SetBody(ctx => null)),
                Throws.InstanceOf <NotSupportedException>()
                .With.Message.EqualTo(
                    "Cannot re-implement interface method 'Method3' because its base implementation on 'DomainType' is not accessible."));
        }
        public void Modify_Explicit_ExistingOnBase()
        {
            var interfaceMethod = NormalizingMemberInfoFromExpressionUtility.GetMethod((IBaseInterface obj) => obj.ExplicitlyImplemented());

            Assert.That(
                () => AssembleType <DomainType> (p => p.GetOrAddImplementation(interfaceMethod)),
                Throws.InstanceOf <NotSupportedException>()
                .With.Message.EqualTo(
                    "Cannot re-implement interface method 'ExplicitlyImplemented' because its base implementation on 'DomainTypeBase' is not accessible."));
        }
Пример #24
0
        public void TrampolineMethods_MemberInfoEqualityComparer()
        {
            var method1 = NormalizingMemberInfoFromExpressionUtility.GetMethod((object obj) => obj.ToString());
            var method2 = typeof(CodeGenerationContextTest).GetMethod("ToString");

            Assert.That(method1, Is.Not.SameAs(method2));

            _context.TrampolineMethods.Add(method1, null);
            Assert.That(_context.TrampolineMethods.ContainsKey(method2), Is.True);
        }
Пример #25
0
        public void IsGenericMethodInstantiation()
        {
            var nonGenericMethod        = ReflectionObjectMother.GetSomeNonGenericMethod();
            var genericMethodDefinition = NormalizingMemberInfoFromExpressionUtility.GetGenericMethodDefinition(() => Method <Dev.T, Dev.T>());
            var methodInstantiation     = NormalizingMemberInfoFromExpressionUtility.GetMethod(() => Method <int, string>());

            Assert.That(nonGenericMethod.IsGenericMethodInstantiation(), Is.False);
            Assert.That(genericMethodDefinition.IsGenericMethodInstantiation(), Is.False);
            Assert.That(methodInstantiation.IsGenericMethodInstantiation(), Is.True);
        }
Пример #26
0
        public void GetAttributeFlagsImpl_AbstractCache_Updated_WhenAddingNonAbstractExplicitOverride()
        {
            var proxyType = MutableTypeObjectMother.Create(baseType: typeof(AbstractTypeBase));

            Assert.That(proxyType.IsAbstract, Is.True);

            proxyType.AddExplicitOverride(
                NormalizingMemberInfoFromExpressionUtility.GetMethod((AbstractTypeBase t) => t.AbstractMethod1()),
                c => Expression.Default(c.ReturnType));
            Assert.That(proxyType.IsAbstract, Is.False);
        }
        public void Modify_Implicit()
        {
            var interfaceMethod = NormalizingMemberInfoFromExpressionUtility.GetMethod((IDomainInterface obj) => obj.Method());
            var type            = AssembleType <DomainType> (
                p => p.GetOrAddImplementation(interfaceMethod)
                .SetBody(ctx => ExpressionHelper.StringConcat(ctx.PreviousBody, Expression.Constant(" modified"))));

            var instance = (IDomainInterface)Activator.CreateInstance(type);

            Assert.That(instance.Method(), Is.EqualTo("DomainType.Method modified"));
        }
Пример #28
0
        public void SetUp()
        {
            _interceptedMethod = NormalizingMemberInfoFromExpressionUtility.GetMethod((object o) => o.Equals(null));
            _propertyName      = "abc";
            _propertyType      = typeof(int);

            _interceptorPartialMock = MockRepository.GeneratePartialMock <ImplementingAccessorInterceptorBase> (
                _interceptedMethod, _propertyName, _propertyType);

            _proxyType = MutableTypeObjectMother.Create(typeof(DomainObject));
        }
        public void Proceed()
        {
            var instance = new DomainType();
            var method   = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType obj) => obj.Method(""));

            var invocation = new FuncContext <DomainType, string, int> (method, instance, "arg", instance.Method);

            invocation.Arg1 = "7";
            invocation.Proceed();
            Assert.That(invocation.ReturnValue, Is.EqualTo(7));
        }
        public void Initialization()
        {
            var instance = new DomainType();
            var method   = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType obj) => obj.Method(""));

            var invocation = new FuncContext <DomainType, string, int> (method, instance, "arg", instance.Method);

            Assert.That(invocation.Instance, Is.SameAs(instance));
            Assert.That(invocation.MemberInfo, Is.SameAs(method));
            Assert.That(invocation.Arg1, Is.EqualTo("arg"));
        }