Ejemplo n.º 1
0
 protected override void Run(IMethodCallContext ctx)
 {
     around_b = true;
     if (ctx.CallMessage.MethodName != "Reset")
         Proceed();
     around_a = true;
 }
Ejemplo n.º 2
0
            public void When_Method_Has_One_Parameters_Can_Stub_With_Dynamic_Value()
            {
                IMethodCallContext context = default;

                // Arrange
                var proxy = _builder.InterceptAndStub(theMethodCalled: nameof(IAfterExecutionMethodSignatures.HasOneParameter), dynamicValueProvider: callContext =>
                {
                    context = callContext;
                    return(35);
                })
                            .Build();

                // Act
                var result = proxy.HasOneParameter(65);

                // Assert
                result.Should().Be(35, because: "that is the stubbed value");
                _originalImplementation.Message.Should().Be(null, because: "the method was stubbed and not executed. ");

                context.Args.Length.Should().Be(1, because: "this method has one parameter. ");
                ((int)context.Args[0]).Should().Be(65, because: "that is the value passed in. ");

                context.Parameters.Count.Should().Be(1, because: "this method has one parameter. ");
                ((int)context.Parameters["theInt"]).Should().Be(65, because: "this method has one parameter. ");
            }
Ejemplo n.º 3
0
            public void When_Method_Has_Two_Parameters_Can_Stub_With_Dynamic_Value()
            {
                IMethodCallContext context = default;

                // Arrange
                var proxy = _builder.InterceptAndStub(theMethodCalled: nameof(IAfterExecutionMethodSignatures.HasTwoParameters), dynamicValueProvider: callContext =>
                {
                    context = callContext;
                    return(14);
                })
                            .Build();

                // Act
                var result = proxy.HasTwoParameters(theString: "theS", theInt: 98);

                // Assert
                result.Should().Be(14, because: "that is the stubbed value");
                _originalImplementation.Message.Should().Be(null, because: "the method was stubbed and not executed. ");

                context.Args.Length.Should().Be(2, because: "this method has two parameters. ");
                ((string)context.Args[0]).Should().Be("theS", because: "that is the value passed in. ");
                ((int)context.Args[1]).Should().Be(98, because: "that is the value passed in. ");

                context.Parameters.Count.Should().Be(2, because: "this method has two parameters. ");
                ((int)context.Parameters["theInt"]).Should().Be(98, because: "this is the argument passed in. ");
                ((string)context.Parameters["theString"]).Should().Be("theS", because: "this is the argument passed in. ");
            }
Ejemplo n.º 4
0
 public static void ThrowAspectExecuteError(IMethodCallContext ctx, Exception ex)
 {
     AspectException ae = new AspectException("Exception while executing aspect, check inner exception for detail.", ex);
     if (ctx.ReturnMessage != null && ctx.ReturnMessage.Exception != null)
         ae.OriginalException = ctx.ReturnMessage.Exception;
     throw ae;
 }
Ejemplo n.º 5
0
 public static void ThrowWeaveException(IMethodCallContext ctx, Exception inner)
 {
     WeaveException we = new WeaveException(string.Format("Weave error at [{0}][{1}.{2}].", ctx.Position, ctx.CallMessage.MethodBase.ReflectedType.Name, ctx.CallMessage.MethodName), inner);
     if (ctx.ReturnMessage != null && ctx.ReturnMessage.Exception != null)
         we.OriginalException = ctx.ReturnMessage.Exception;
     throw we;
 }
Ejemplo n.º 6
0
 protected override void Run(IMethodCallContext ctx)
 {
     around_b = true;
     if (ctx.CallMessage.MethodName != "Reset")
     {
         Proceed();
     }
     around_a = true;
 }
Ejemplo n.º 7
0
        public static void ThrowAspectExecuteError(IMethodCallContext ctx, Exception ex)
        {
            AspectException ae = new AspectException("Exception while executing aspect, check inner exception for detail.", ex);

            if (ctx.ReturnMessage != null && ctx.ReturnMessage.Exception != null)
            {
                ae.OriginalException = ctx.ReturnMessage.Exception;
            }
            throw ae;
        }
Ejemplo n.º 8
0
        public static void ThrowWeaveException(IMethodCallContext ctx, Exception inner)
        {
            WeaveException we = new WeaveException(string.Format("Weave error at [{0}][{1}.{2}].", ctx.Position, ctx.CallMessage.MethodBase.ReflectedType.Name, ctx.CallMessage.MethodName), inner);

            if (ctx.ReturnMessage != null && ctx.ReturnMessage.Exception != null)
            {
                we.OriginalException = ctx.ReturnMessage.Exception;
            }
            throw we;
        }
Ejemplo n.º 9
0
        public string[] GetAdvisorNames(IMethodCallContext ctx)
        {
            List <string> names = new List <string>();

            foreach (var defination in _jointPointDefinations)
            {
                if (defination.Match(ctx))
                {
                    names.Add(defination.AdvisorName);
                }
            }
            return(names.ToArray());
        }
Ejemplo n.º 10
0
        internal bool Match(IMethodCallContext ctx)
        {
            if (_position != ctx.Position)
            {
                return(false);
            }

            MethodInfo method = ctx.CallMessage.MethodBase as MethodInfo;

            if (method == null)
            {
                ExceptionHelper.ThrowNotMethodInfo(method);
            }
            return(Match(method));
        }
Ejemplo n.º 11
0
 public void SetContext(IMethodCallContext ctx)
 {
     _ctx = ctx;
 }
Ejemplo n.º 12
0
 public static void ThrowInvalidProceed(IMethodCallContext ctx)
 {
     throw new WeaveException(string.Format("Calling Proceed() is not valid on [{0}][{1}.{2}].", ctx.Position, ctx.CallMessage.MethodBase.ReflectedType.Name, ctx.CallMessage.MethodName));
 }
Ejemplo n.º 13
0
 public static void ThrowInvalidProceed(IMethodCallContext ctx)
 {
     throw new WeaveException(string.Format("Calling Proceed() is not valid on [{0}][{1}.{2}].", ctx.Position, ctx.CallMessage.MethodBase.ReflectedType.Name, ctx.CallMessage.MethodName));
 }
Ejemplo n.º 14
0
 protected override void Run(IMethodCallContext ctx)
 {
     executed = true;
 }
Ejemplo n.º 15
0
 protected override void Run(IMethodCallContext ctx)
 {
     executed = true;
 }
Ejemplo n.º 16
0
        internal bool Match(IMethodCallContext ctx)
        {
            if (_position != ctx.Position)
                return false;

            MethodInfo method = ctx.CallMessage.MethodBase as MethodInfo;
            if (method == null)
                ExceptionHelper.ThrowNotMethodInfo(method);
            return Match(method);
        }
Ejemplo n.º 17
0
 protected abstract void Run(IMethodCallContext ctx);
Ejemplo n.º 18
0
 public void SetContext(IMethodCallContext ctx)
 {
     _ctx = ctx;
 }
Ejemplo n.º 19
0
 protected abstract void Run(IMethodCallContext ctx);