public YarpPluginContainer(IYarpPlugin plugin, YarpPluginMetadata metadata)
 {
     if (plugin == null) throw new ArgumentNullException(nameof(plugin));
     if (metadata == null) throw new ArgumentNullException(nameof(metadata));
     Plugin = plugin;
     Metadata = metadata;
 }
        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);
        }
 private bool ArePluginMetadatasEqual(YarpPluginMetadata first, YarpPluginMetadata second)
 {
     return first.Id.Equals(second.Id) &&
         first.Name.Equals(second.Name) &&
         first.Author.Equals(second.Author) &&
         first.Description.Equals(second.Description) &&
         first.Version.Equals(second.Version) &&
         first.Category.Equals(second.Category) &&
         first.Website.Equals(second.Website);
 }