Exemplo n.º 1
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.");
        }
Exemplo n.º 2
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.");
        }
Exemplo n.º 3
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.");
        }