Esempio n. 1
0
        static TResult?Returns <TResult>(Delegate value, ExecuteMockDelegate behavior)
        {
            var setup = MockContext.CurrentSetup;

            if (setup != null)
            {
                // TODO: Is this even necessary given that IntelliSense gives us
                // the right compiler safety already?
                setup.Invocation.EnsureCompatible(value);

                var mock = setup.Invocation.Target.AsMock();
                mock.Invocations.Remove(setup.Invocation);
                var mockBehavior = mock.GetPipeline(setup);

                mockBehavior.Behaviors.Add(new AnonymousMockBehavior(behavior, "Returns(() => ...)"));
            }

            return(default);
Esempio n. 2
0
 /// <summary>
 /// Creates an instance of the invokable behavior with the given
 /// delegate and friendly display name.
 /// </summary>
 /// <remarks>
 /// Use this constructor overload whenever constructing the display
 /// name is somewhat expensive.
 /// </remarks>
 public AnonymousMockBehavior(ExecuteMockDelegate invoke, Lazy <string> displayName)
 {
     behavior         = invoke;
     this.displayName = displayName;
 }
Esempio n. 3
0
 /// <summary>
 /// Creates an instance of the invokable behavior with the given
 /// delegate and friendly display name.
 /// </summary>
 public AnonymousMockBehavior(ExecuteMockDelegate invoke, string displayName)
     : this(invoke, new Lazy <string>(() => displayName))
 {
 }
Esempio n. 4
0
 /// <summary>
 /// Creates an <see cref="IMockBehavior"/> for the given delegate behavior.
 /// </summary>
 /// <param name="behavior">The behavior to execute.</param>
 /// <param name="displayName">A friendly display name for the behavior.</param>
 public static IMockBehavior Create(ExecuteMockDelegate behavior, Lazy <string> displayName)
 => new AnonymousMockBehavior(behavior, displayName);