public InstanceMethodSpec() { Describe("An Instance Action", () => { var subject = new TestSubject(); It("should call through by default.", () => { subject.Iterate(3); Expect(subject.Value).ToBe(3); }); It("should do nothing if spied on.", () => { Jaz.SpyOn(subject, nameof(subject.Iterate)); subject.Iterate(3); Expect(subject.Value).ToBeDefault(); }); It("should call through as configured.", () => { Jaz.SpyOn(subject, nameof(subject.Iterate)).And.CallThrough(); subject.Iterate(3); Expect(subject.Value).ToBe(3); }); It("should throw an exception as configured.", () => { var exception = new TestException(); Jaz.SpyOn(subject, nameof(subject.Iterate)).And.Throw(exception); var thrown = Expect(() => subject.Iterate(3)).ToThrow <TestException>(); Expect(thrown).ToBe(exception); }); }); Describe("An Instance Function", () => { var subject = new TestSubject(); It("should call through by default.", () => { var result = subject.Add5(3); Expect(result).ToBe(8); }); It("should do nothing if spied on.", () => { Jaz.SpyOn(subject, nameof(subject.Add5)); var result = subject.Add5(3); Expect(result).ToBeDefault(); }); It("should return the configured value.", () => { Jaz.SpyOn(subject, nameof(subject.Add5)).And.ReturnValue(1); var result = subject.Add5(3); Expect(result).ToBe(1); }); It("should return the configured values in sequence.", () => { Jaz.SpyOn(subject, nameof(subject.Add5)).And.ReturnValues(1, 2, 3, 4); var result = subject.Add5(3); Expect(result).ToBe(1); result = subject.Add5(3); Expect(result).ToBe(2); result = subject.Add5(3); Expect(result).ToBe(3); result = subject.Add5(3); Expect(result).ToBe(4); }); It("should call through as configured.", () => { Jaz.SpyOn(subject, nameof(subject.Add5)).And.CallThrough(); var result = subject.Add5(3); Expect(result).ToBe(8); }); It("should throw an exception as configured.", () => { var exception = new TestException(); Jaz.SpyOn(subject, nameof(subject.Add5)).And.Throw(exception); var thrown = Expect(() => subject.Add5(3)).ToThrow <TestException>(); Expect(thrown).ToBe(exception); }); }); }
public StaticMethodSpec() { Describe("A static action", () => { BeforeEach(() => { TestSubject.Value = 0; }); It("should call through by default.", () => { TestSubject.Iterate(3); Expect(TestSubject.Value).ToBe(3); }); It("should do nothing if spied on.", () => { Jaz.SpyOn(typeof(TestSubject), nameof(TestSubject.Iterate)); TestSubject.Iterate(3); Expect(TestSubject.Value).ToBeDefault(); }); It("should call through as configured.", () => { Jaz.SpyOn(typeof(TestSubject), nameof(TestSubject.Iterate)).And.CallThrough(); TestSubject.Iterate(3); Expect(TestSubject.Value).ToBe(3); }); It("should throw an exception as configured.", () => { var exception = new TestException(); Jaz.SpyOn(typeof(TestSubject), nameof(TestSubject.Iterate)).And.Throw(exception); var thrown = Expect(() => TestSubject.Iterate(3)).ToThrow <TestException>(); Expect(thrown).ToBe(exception); }); // the only non-generic spy entry point Describe("with no parameters", () => { It("should call through by default.", () => { TestSubject.Increment(); Expect(TestSubject.Value).ToBe(1); }); It("should do nothing if spied on.", () => { Jaz.SpyOn(typeof(TestSubject), nameof(TestSubject.Increment)); TestSubject.Increment(); Expect(TestSubject.Value).ToBeDefault(); }); It("should call through as configured.", () => { Jaz.SpyOn(typeof(TestSubject), nameof(TestSubject.Increment)).And.CallThrough(); TestSubject.Increment(); Expect(TestSubject.Value).ToBe(1); }); It("should throw an exception as configured.", () => { var exception = new TestException(); Jaz.SpyOn(typeof(TestSubject), nameof(TestSubject.Increment)).And.Throw(exception); var thrown = Expect(() => TestSubject.Increment()).ToThrow <TestException>(); Expect(thrown).ToBe(exception); }); }); }); Describe("A static function", () => { It("should call through by default.", () => { var result = TestSubject.Add5(3); Expect(result).ToBe(8); }); It("should do nothing if spied on.", () => { Jaz.SpyOn(typeof(TestSubject), nameof(TestSubject.Add5)); var result = TestSubject.Add5(3); Expect(result).ToBeDefault(); }); It("should return the configured value.", () => { Jaz.SpyOn(typeof(TestSubject), nameof(TestSubject.Add5)).And.ReturnValue(1); var result = TestSubject.Add5(3); Expect(result).ToBe(1); }); It("should return the configured values in sequence.", () => { Jaz.SpyOn(typeof(TestSubject), nameof(TestSubject.Add5)).And.ReturnValues(1, 2, 3, 4); var result = TestSubject.Add5(3); Expect(result).ToBe(1); result = TestSubject.Add5(3); Expect(result).ToBe(2); result = TestSubject.Add5(3); Expect(result).ToBe(3); result = TestSubject.Add5(3); Expect(result).ToBe(4); }); It("should call through as configured.", () => { Jaz.SpyOn(typeof(TestSubject), nameof(TestSubject.Add5)).And.CallThrough(); var result = TestSubject.Add5(3); Expect(result).ToBe(8); }); It("should throw an exception as configured.", () => { var exception = new TestException(); Jaz.SpyOn(typeof(TestSubject), nameof(TestSubject.Add5)).And.Throw(exception); var thrown = Expect(() => TestSubject.Add5(3)).ToThrow <TestException>(); Expect(thrown).ToBe(exception); }); }); }
public GenericInstanceMethodSpec() { Describe("A generic instance action", () => { var subject = new TestSubject(); It("should call through by default.", () => { subject.Iterate(3); Expect(subject.Value).ToBe(3); }); It("should do nothing if spied on.", () => { Jaz.SpyOn(subject, nameof(subject.Iterate)); subject.Iterate(3); Expect(subject.Value).ToBeDefault(); }); It("should call through as configured.", () => { Jaz.SpyOn(subject, nameof(subject.Iterate)).And.CallThrough(); subject.Iterate(3); Expect(subject.Value).ToBe(3); }); It("should throw an exception as configured.", () => { var exception = new TestException(); Jaz.SpyOn(subject, nameof(subject.Iterate)).And.Throw(exception); var thrown = Expect(() => subject.Iterate(3)).ToThrow <TestException>(); Expect(thrown).ToBe(exception); }); }); Describe("A generic instance function", () => { var subject = new TestSubject(); It("should call through by default.", () => { var result = subject.Add5(3); Expect(result).ToBe(8); }); It("should do nothing if spied on.", () => { Jaz.SpyOn(subject, nameof(subject.Add5)); var result = subject.Add5(3); Expect(result).ToBeDefault(); }); It("should return the configured value.", () => { Jaz.SpyOn(subject, nameof(subject.Add5)).And.ReturnValue(1); var result = subject.Add5(3); Expect(result).ToBe(1); }); It("should return the configured values in sequence.", () => { Jaz.SpyOn(subject, nameof(subject.Add5)).And.ReturnValues(1, 2, 3, 4); var result = subject.Add5(3); Expect(result).ToBe(1); result = subject.Add5(3); Expect(result).ToBe(2); result = subject.Add5(3); Expect(result).ToBe(3); result = subject.Add5(3); Expect(result).ToBe(4); }); It("should call through as configured.", () => { Jaz.SpyOn(subject, nameof(subject.Add5)).And.CallThrough(); var result = subject.Add5(3); Expect(result).ToBe(8); }); It("should throw an exception as configured.", () => { var exception = new TestException(); Jaz.SpyOn(subject, nameof(subject.Add5)).And.Throw(exception); var thrown = Expect(() => subject.Add5(3)).ToThrow <TestException>(); Expect(thrown).ToBe(exception); }); It("should support calling a generic method from a generic method.", () => { var testSubject = new TestSubject(); var result = testSubject.CallFunc(() => 5); Expect(result).ToBe(5); }); It("should support calling a generic method from a generic class.", () => { var testSubject = new TestSubject <int>(); var result = testSubject.CallFunc(() => 5); Expect(result).ToBe(5); }); It("should support calling a generic class from a generic method.", () => { var testSubject = new TestSubject(); var result = testSubject.CallFunc2(() => 5); Expect(result).ToBe(5); }); It("should support calling a method on a nested class in a generic class.", () => { var testSubject = new TestSubject <int> .TestSubjectChild(); var result = testSubject.CallFunc(() => 5); Expect(result).ToBe(5); }); }); }