Exemple #1
0
        public void TestMockBehaviorProperty_CanBeChangedAtRuntime()
        {
            StubITestInterface stub                    = new StubITestInterface(MockBehavior.Strict);
            ITestInterface     testInterface           = stub;
            bool wasExceptionThrownInStrictMode        = false;
            bool wasExceptionThrownInStrictMode2ndTime = false;

            // Check for exception in strict mode
            try
            {
                testInterface.DoSomething();
            }
            catch (SimpleStubsException)
            {
                wasExceptionThrownInStrictMode = true;
            }

            // Switch to loose mode, do not expect exception
            stub.MockBehavior = MockBehavior.Loose;
            testInterface.DoSomething();

            // Switch back to strict mode and check for exception
            stub.MockBehavior = MockBehavior.Strict;
            try
            {
                testInterface.DoSomething();
            }
            catch (SimpleStubsException)
            {
                wasExceptionThrownInStrictMode2ndTime = true;
            }

            Assert.AreEqual(true, wasExceptionThrownInStrictMode);
            Assert.AreEqual(true, wasExceptionThrownInStrictMode2ndTime);
        }
        //TODO do we need to specify signature always or in ambiguilty?
        private InvocationInfo DoSomethingStringInt32(InvocationInfo invocationInfo)
        {
            const int sIndex = 0;
            const int xIndex = 1;

            _realInstance.DoSomething(
                (string)invocationInfo.Arguments[sIndex].Value,
                (int)invocationInfo.Arguments[xIndex].Value);

            return(invocationInfo);
        }
Exemple #3
0
        public void TestMethod_Void_WithNoParameters_DefaultBehavior_Loose()
        {
            var            stub          = new StubITestInterface(MockBehavior.Loose);
            ITestInterface testInterface = stub;

            testInterface.DoSomething();
        }
Exemple #4
0
        public void TestMethod_Void_WithNoParameters()
        {
            var  stub = new StubITestInterface();
            bool wasDelegateCalled = false;

            stub.DoSomething(() => { wasDelegateCalled = true; });
            ITestInterface testInterface = stub;

            testInterface.DoSomething();
            Assert.IsTrue(wasDelegateCalled);
        }