Sellorio / JazSharp

Jasmine inspired mocking and unit testing framework for C#.
Apache License 2.0
65 stars 4 forks source link

Spies do not catch calls made via an interface #20

Open lukesdm opened 5 years ago

lukesdm commented 5 years ago
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