Example #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");
            }
        }
Example #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.");
            }
        }
Example #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));
            }
        }
Example #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.");
            }
        }
        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));
            }
        }
        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.");
            }
        }
        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.");
            }
        }
        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");
            }
        }