public void GivenThatFoldersAreCorrectAndPluginAndMetadataExists_WhenLoadPluginsIsCalled_TheReturnedListContainsOnePluginContainer()
        {
            const string folderContainingPlugins = "folderContainingPlugins";
            const string pluginFile = "pluginFile";
            const string metadataFile = "metadataFile";

            var settings = new ReflectionBasedPluginLoaderSettings("dummyPath", "dummyPluginpattern", "dummyMetadataPattern");
            var directoryStub = MockRepository.GenerateStub<DirectoryBase>();
            directoryStub.Stub(x => x.Exists(settings.PluginsPath)).Return(true);
            directoryStub.Stub(x => x.EnumerateDirectories(settings.PluginsPath))
                .Return(new[] { folderContainingPlugins });
            directoryStub.Stub(
                x =>
                    x.EnumerateFiles(folderContainingPlugins, settings.PluginFileSearchPattern,
                        SearchOption.TopDirectoryOnly))
                .Return(new[] { pluginFile });
            directoryStub.Stub(
                x =>
                    x.EnumerateFiles(folderContainingPlugins, settings.PluginMetadataSearchPattern,
                        SearchOption.TopDirectoryOnly))
                .Return(new[] { metadataFile });

            var plugin = new DummyPlugin();
            var metadata = new YarpPluginMetadata("id", "name", "author", "description", "version", "category",
                "website");

            var assemblyLoaderStub = MockRepository.GenerateStub<IAssemblyLoader>();
            assemblyLoaderStub.Stub(x => x.LoadFile(pluginFile)).Return(null);
            var activatorStub = MockRepository.GenerateStub<IYarpActivator>();
            activatorStub.Stub(x => x.CreateInstance<IYarpPlugin>(null)).IgnoreArguments().Return(plugin);
            var serializerStub = MockRepository.GenerateStub<IYarpSerializer>();
            serializerStub.Stub(x => x.Deserialize<YarpPluginMetadata>("")).IgnoreArguments().Return(metadata);
            var fileStub = MockRepository.GenerateStub<FileBase>();
            fileStub.Stub(x => x.ReadAllText("")).IgnoreArguments().Return("someFileData");

            var sut = CreateSut(settings, activator: activatorStub, loader: assemblyLoaderStub, directory: directoryStub, file:fileStub,
                serializer:serializerStub);

            var loadedPlugins = sut.LoadPlugins().ToList();
            var loadedMetadata = loadedPlugins[0].Metadata;
            var loadedPlugin = loadedPlugins[0].Plugin;

            loadedPlugin.Activate();
            loadedPlugin.Deactivate();

            Assert.AreEqual(1, loadedPlugins.Count);
            Assert.IsTrue(ArePluginMetadatasEqual(metadata, loadedMetadata));
            Assert.IsTrue(plugin.HasBeenActivated);
            Assert.IsTrue(plugin.HasBeenDeactivated);
        }
Beispiel #2
0
            public void ResolvePlugin_WhenWellFormed_ReturnsPluginObject()
            {
                var registry = new Registry();
                var handlerFactory = MockRepository.GenerateMock<IHandlerFactory>();
                var plugin = registry.RegisterPlugin(new PluginRegistration("pluginId", new TypeName(typeof(DummyPlugin)), new DirectoryInfo(@"C:\"))
                {
                    PluginHandlerFactory = handlerFactory,
                    PluginProperties = { { "Name", "Value" } }
                });
                var handler = MockRepository.GenerateMock<IHandler>();
                var pluginInstance = new DummyPlugin();

                handlerFactory.Expect(x => x.CreateHandler(null, null, null, null))
                    .Constraints(Is.NotNull(), Is.Equal(typeof(IPlugin)), Is.Equal(typeof(DummyPlugin)), Is.Equal(new PropertySet() { { "Name", "Value" } }))
                    .Return(handler);
                handler.Expect(x => x.Activate()).Return(pluginInstance);

                var result = (DummyPlugin) plugin.ResolvePlugin();

                handlerFactory.VerifyAllExpectations();
                handler.VerifyAllExpectations();
                Assert.AreSame(pluginInstance, result);
            }