コード例 #1
0
        public void DiscardingValue()
        {
            using (CaptureConsole) {
                // create the plugin object:
                var plugin = new ThePluginImplementation();

                // create the host's duck typed version of the plugin:
                var duckTypedPlugin = plugin.As <IPluginInterfaceDiscardingValue>();

                // create the host's actual implementation of the request
                var request = new HostImplementationOfRequest();

                // the host should call the method on the plugin:
                duckTypedPlugin.DoSomething("sample call 3", request);

                Ensure("sample call 3", "ducktyped object where host's interface was void (and implementation didn't) failed to call correctly");
            }
        }
コード例 #2
0
        public void ExceptionHandlingWithoutHandler()
        {
            using (CaptureConsole) {
                // create the plugin object:
                var plugin = new BadImplementation();

                // create the host's duck typed version of the plugin:
                var duckTypedPlugin = plugin.As <IPluginInterface>();

                // create the host's actual implementation of the request
                var request = new HostImplementationOfRequest();

                // the host should call the method on the plugin:
                var result = duckTypedPlugin.DoSomething("sample call 2", request);

                Assert.Equal(null, result);
                Ensure("BadImplementationCalled", "The method failed to get called, up to the point of the exception.");
            }
        }
コード例 #3
0
        public void CreateDuckTypedBindingForMethodWithDuckTypedParameters()
        {
            using (CaptureConsole) {
                // create the plugin object:
                var plugin = new ThePluginImplementation();

                // create the host's duck typed version of the plugin:
                var duckTypedPlugin = plugin.As <IPluginInterface>();

                // create the host's actual implementation of the request
                var request = new HostImplementationOfRequest();

                // the host should call the method on the plugin:
                var result = duckTypedPlugin.DoSomething("sample call 1", request);

                Ensure("sample call 1", "The method didn't get called.");

                Assert.True("Success".Equals(result));
            }
        }
コード例 #4
0
        public void ExceptionWithHandler()
        {
            using (CaptureConsole) {
                // create the plugin object:
                var plugin = new BadImplementationwithHandler();

                // create the host's duck typed version of the plugin:
                var duckTypedPlugin = plugin.As <IPluginInterfaceWithHandler>();

                // create the host's actual implementation of the request
                var request = new HostImplementationOfRequest();

                // the host should call the method on the plugin:
                var result = duckTypedPlugin.DoSomething("try this", request);

                // result from a duck typed object throwing an exception should be null.
                Assert.Null(result);

                Ensure("BadImplementationwithHandlerCalled", "The method should get called, up to the point of the exception.");

                Ensure("UnhandledExceptionCalled", "When we specify an OnUnhandledException method in the host interface, and the client implements it, we should make sure it gets called.");
            }
        }
コード例 #5
0
        public void CreateDuckTypedBindingForMethodWithDuckTypedParameters()
        {
            using (CaptureConsole) {
                // create the plugin object:
                var plugin = new ThePluginImplementation();

                // create the host's duck typed version of the plugin:
                var duckTypedPlugin = plugin.As<IPluginInterface>();

                // create the host's actual implementation of the request
                var request = new HostImplementationOfRequest();

                // the host should call the method on the plugin:
                var result = duckTypedPlugin.DoSomething("sample call 1", request);

                Ensure("sample call 1", "The method didn't get called.");

                Assert.True("Success".Equals(result));
            }
        }
コード例 #6
0
        public void ExceptionWithHandler()
        {
            using (CaptureConsole) {
                // create the plugin object:
                var plugin = new BadImplementationwithHandler();

                // create the host's duck typed version of the plugin:
                var duckTypedPlugin = plugin.As<IPluginInterfaceWithHandler>();

                // create the host's actual implementation of the request
                var request = new HostImplementationOfRequest();

                // the host should call the method on the plugin:
                var result = duckTypedPlugin.DoSomething("try this", request);

                // result from a duck typed object throwing an exception should be null.
                Assert.Null(result);

                Ensure("BadImplementationwithHandlerCalled", "The method should get called, up to the point of the exception.");

                Ensure("UnhandledExceptionCalled", "When we specify an OnUnhandledException method in the host interface, and the client implements it, we should make sure it gets called.");
            }
        }
コード例 #7
0
        public void ExceptionHandlingWithoutHandler()
        {
            using (CaptureConsole) {
                // create the plugin object:
                var plugin = new BadImplementation();

                // create the host's duck typed version of the plugin:
                var duckTypedPlugin = plugin.As<IPluginInterface>();

                // create the host's actual implementation of the request
                var request = new HostImplementationOfRequest();

                // the host should call the method on the plugin:
                var result = duckTypedPlugin.DoSomething("sample call 2", request);

                Assert.Equal(null, result);
                Ensure("BadImplementationCalled", "The method failed to get called, up to the point of the exception.");
            }
        }
コード例 #8
0
        public void DiscardingValue()
        {
            using (CaptureConsole) {
                // create the plugin object:
                var plugin = new ThePluginImplementation();

                // create the host's duck typed version of the plugin:
                var duckTypedPlugin = plugin.As<IPluginInterfaceDiscardingValue>();

                // create the host's actual implementation of the request
                var request = new HostImplementationOfRequest();

                // the host should call the method on the plugin:
                duckTypedPlugin.DoSomething("sample call 3", request);

                Ensure("sample call 3", "ducktyped object where host's interface was void (and implementation didn't) failed to call correctly");
            }
        }