Example #1
0
        public void SimpleMethodStub()
        {
            // Create a fake Death Star
            var fakeStar = new Fake<IDeathStar>();

            // Set up the fake so that a call to Shoot(Planet) always misses
            var shootCalls = fakeStar.Stub(fakeStar.Object.Shoot, (Planet planet) => "Haha, missed!");

            // give the fake Death Star to a real Vader (the class we wish to test)
            var vader = new Vader(fakeStar.Object);
            vader.GetAngry();

            // Check whether our stubbed method was indeed called. We can use plain LINQ and
            // any preferred unit testing / assertion library. No need to learn any special
            // mocking-framework assertion/verification syntax.
            shootCalls.Count.ShouldBe(2);

            // We have full access to the call history.
            shootCalls[0].Arg1.Name.ShouldBe("Alderaan");
            shootCalls[0].ReturnValue.ShouldContain("Haha,");
            shootCalls.Last().Arg1.Name.ShouldBe("Naboo");
        }
Example #2
0
        public void SimpleMethodStub()
        {
            // Create a fake Death Star
            var fakeStar = new Fake <IDeathStar>();

            // Set up the fake so that a call to Shoot(Planet) always misses
            var shootCalls = fakeStar.Stub(fakeStar.Object.Shoot, (Planet planet) => "Haha, missed!");

            // give the fake Death Star to a real Vader (the class we wish to test)
            var vader = new Vader(fakeStar.Object);

            vader.GetAngry();

            // Check whether our stubbed method was indeed called. We can use plain LINQ and
            // any preferred unit testing / assertion library. No need to learn any special
            // mocking-framework assertion/verification syntax.
            shootCalls.Count.ShouldBe(2);

            // We have full access to the call history.
            shootCalls[0].Arg1.Name.ShouldBe("Alderaan");
            shootCalls[0].ReturnValue.ShouldContain("Haha,");
            shootCalls.Last().Arg1.Name.ShouldBe("Naboo");
        }