JazSharp icon indicating copy to clipboard operation
JazSharp copied to clipboard

Spies do not catch calls made via an interface

Open lukesdm opened this issue 4 years ago • 0 comments

Describe<Adder>(() =>
            {
                // Expected behaviour
                It("appends to history", () => 
                {
                    OperationHistory history = new OperationHistory();
                    Spy historySpy = Jaz.SpyOn(history, nameof(history.Append));
                    var adder = new Adder(history);

                    adder.Add(-1, 1);

                    Expect(historySpy).ToHaveBeenCalled();
                });
            });

OperationHistory implements IOperationHistory. If Adder uses IoC (with an injected IOperationHistory rather than OperationHistory), the spy will not work:

Expected spy to have been called, but it wasn't.

See attached. LM.JazSharp.Examples-2.zip

lukesdm avatar Oct 01 '19 19:10 lukesdm