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

            Assert.That.Throws <NotSupportedException>(
                () => mock.AddBehavior(m => "?", () => { }),
                ExpressionType.Constant,
                "identify a mockable member");
        }
Beispiel #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.");
        }
Beispiel #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.");
        }