示例#1
0
        public IMethodReturn Invoke(IMethodInvocation invocation, GetNextBehavior getNext)
        {
            if (invocation.MethodBase.DeclaringType == typeof(IMocked))
            {
                return(invocation.CreateValueReturn(this));
            }

            CallContext <IMethodInvocation> .SetData(nameof(IMethodInvocation), invocation);

            Invocations.Add(invocation);

            if (Behaviors.Count == 0)
            {
                return(getNext().Invoke(invocation, getNext));
            }

            // This is the only added functionality of this behavior, to first match
            // applicable InvokeBehaviors and execute them in sequence.
            var applicableBehaviors = Behaviors.Where(behavior => behavior.AppliesTo(invocation)).ToArray();

            if (applicableBehaviors.Length == 0)
            {
                return(getNext().Invoke(invocation, getNext));
            }

            var index = 0;

            return(applicableBehaviors[0].Invoke(invocation, () =>
            {
                ++index;
                return (index < applicableBehaviors.Length) ?
                applicableBehaviors[index].Invoke :
                getNext();
            }));
        }
            public void Handle(UserContextMessageBase message)
            {
                Invocations.Add(GetType());

                Console.WriteLine("Processing UserContextMessageBase");

                MessageContext.GetCurrent().Items[UserContextKey] = message.UserContext;
            }
            public void Handle(SimpleMessage message)
            {
                Invocations.Add(GetType());

                var userContext = (UserContext)MessageContext.GetCurrent().Items[UserContextHandler.UserContextKey];

                // allow to use the _context to process this message
                Console.WriteLine("Received SimpleMessage {0} - context: {1}", message.Data, userContext.UserId);
            }
示例#4
0
        /// <summary>
        /// Performs an invocation on the mock.
        /// </summary>
        /// <remarks>
        /// Whether or not a behavior matches the invocation, the actual invocation
        /// is always recorded.
        /// </remarks>
        public virtual void Invoke(IInvocation invocation)
        {
            Invocations.Add(invocation);

            var behavior = Behaviors.FirstOrDefault(x => x.AppliesTo(invocation));

            if (behavior != null)
            {
                behavior.ExecuteFor(invocation);
            }
        }
示例#5
0
        public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
        {
            switch (syntaxNode)
            {
            case InvocationExpressionSyntax invocation:
                Invocations.Add(invocation);
                break;

            case VariableDeclarationSyntax variableDeclarationSyntax:
                VariableDeclarations.Add(variableDeclarationSyntax);
                break;
            }
        }
示例#6
0
 public static bool AlwaysTrue()
 {
     Invocations.Add(null);
     return true;
 }
示例#7
0
 public static bool AlwaysTrue(object[] input)
 {
     Invocations.Add(input);
     return true;
 }
示例#8
0
 public void BringToFront()
 {
     Invocations.Add(new MethodInvocation(nameof(BringToFront)));
 }