Example #1
0
        public void MockThrowsWhenAddingBehaviorForNonMember()
        {
            // Set up.
            var mock = new MockStub();

            Assert.That.Throws <NotSupportedException>(
                () => mock.AddBehavior(m => "?", () => { }),
                ExpressionType.Constant,
                "identify a mockable member");
        }
Example #2
0
        public void MockRunsReplacedBehaviorReturningData()
        {
            // Set up.
            var          mock     = new MockStub();
            const string Question = "Well do ya?";

            // Add custom behavior to see if it executes.
            mock.SetBehavior(m => m.GetMessage(), () => Question);

            Assert.AreEqual(
                Question, mock.GetMessage(), "Expected custom behavior to run.");
        }
Example #3
0
        public void MockRunsReplacedBehavior()
        {
            // Set up.
            var mock = new MockStub();

            // Add custom behavior to see if it executes.
            var calls = 0;

            mock.SetBehavior(m => m.ShowMessage(), () => calls++);

            mock.ShowMessage();

            Assert.AreEqual(1, calls, "Expected custom behavior to run.");
        }
Example #4
0
        public void MockRunsAddedBehavior()
        {
            // Set up.
            var mock = new MockStub();

            // Hook this up to see if the default behavior runs.
            var defaultCalls = 0;

            mock.ShowingMessage += delegate { defaultCalls++; };

            // Add custom behavior to see if it executes.
            var calls = 0;

            mock.AddBehavior(m => m.ShowMessage(), () => calls++);

            mock.ShowMessage();

            Assert.AreEqual(1, defaultCalls, "Expected default behavior to run.");
            Assert.AreEqual(1, calls, "Expected custom behavior to run.");
        }
Example #5
0
        public void MockRunsAddedBehaviorReturningData()
        {
            // Set up.
            var mock = new MockStub();

            // Hook this up to see if the default behavior runs.
            var defaultCalls = 0;

            mock.ShowingMessage += delegate { defaultCalls++; };

            // Add custom behavior to see if it executes.
            var calls = 0;

            mock.AddBehavior(m => m.GetMessage(), () => calls++);

            // Note this is not the method we modified, but it calls the one we
            // did. This allows us to verify that the default behavior runs.
            mock.ShowMessage();

            Assert.AreEqual(1, defaultCalls, "Expected default behavior to run.");
            Assert.AreEqual(1, calls, "Expected custom behavior to run.");
        }