protected override void Run(IMethodCallContext ctx) { around_b = true; if (ctx.CallMessage.MethodName != "Reset") Proceed(); around_a = true; }
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. "); }
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. "); }
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; }
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; }
protected override void Run(IMethodCallContext ctx) { around_b = true; if (ctx.CallMessage.MethodName != "Reset") { Proceed(); } around_a = true; }
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; }
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; }
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()); }
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)); }
public void SetContext(IMethodCallContext ctx) { _ctx = ctx; }
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)); }
protected override void Run(IMethodCallContext ctx) { executed = true; }
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); }
protected abstract void Run(IMethodCallContext ctx);