コード例 #1
0
        public void CallIsReplaced()
        {
            var dummy = new MethodReplacement();
            Action<string> replacement = s => dummy.Call("Intercepted.");

            InterceptorRegistry.AddInterceptor(
                new CompoundInterceptor(new AlwaysMatches(),
                    new InsteadOfCall(() => replacement)
                ));

            var mocked = new CodeUnderTest();
            mocked.CallsConsoleWriteLine();

            Assert.AreEqual("Intercepted.", dummy.ReplacementArg1);
        }
コード例 #2
0
        public void MethodWithMatchingOverloadIsIntercepted()
        {
            var dummy = new MethodReplacement();
            Action<string> replacement = s => dummy.Call("Intercepted.");

            InterceptorRegistry.AddInterceptor(
                new CompoundInterceptor(new AllOverloadsMatch(VoidMethod.Of(Console.WriteLine)),
                    new InvokeCallSafe(() => replacement)
                ));

            var mocked = new CodeUnderTest();
            mocked.CallsConsoleWriteLineFormatStingOverload();

            Assert.AreEqual("Intercepted.", dummy.ReplacementArg1);
        }