public void CreateRequiresPluginDescriptor() { IAssemblyRepository repository = new MockAssemblyRepository(); Dictionary<string, object> settings = new Dictionary<string,object>(); IPluginCreator tested = PluginCreator.GetCreator(); DoAssert.Throws<ArgumentNullException>(() => tested.Create(null, repository, settings)); }
public void CreateShouldCreatePluginInstance() { IAssemblyRepository repository = new MockAssemblyRepository(); IPluginCreator tested = PluginCreator.GetCreator(); PluginDescriptor descriptor = MockPluginDescriptor.For<MockPlugin1>(); object plugin = tested.Create(descriptor, repository, null); Assert.IsNotNull(plugin); }
public void CreateShouldLogCatchedPluginExceptionAsError() { MockAssemblyRepository repository = new MockAssemblyRepository(); IPluginCreator tested = PluginCreator.GetCreator(); MockLog mocklog = new MockLog((ILogWriter)tested); PluginDescriptor descriptor = MockPluginDescriptor.For<MockPlugin2>(); Exception ex = DoAssert.Throws<PluginSettingException>(() => tested.Create(descriptor, repository, null)); Assert.IsTrue(mocklog.Any(x => x.Level == MockLog.Level.Error && x.Message.Contains(ex.Message))); }
public void CreateShouldApplySettings() { MockAssemblyRepository repository = new MockAssemblyRepository(); IPluginCreator tested = PluginCreator.GetCreator(); PluginDescriptor descriptor = MockPluginDescriptor.For<MockPlugin2>(); Dictionary<string, object> settings = new Dictionary<string, object>() { { "NamedSetting", 42} }; MockPlugin2 plugin = tested.Create(descriptor, repository, settings) as MockPlugin2; Assert.AreEqual(42, plugin.Setting); }
public void CreateShouldLogCatchedExceptionAsError() { using (MockDomain domain = new MockDomain()) { MockAssemblyRepository repository = new MockAssemblyRepository(); QualifiedName fakeName = new QualifiedName( typeof(string).FullName.Replace("mscorlib", "NonExistingAssemblyName"), typeof(string).Assembly.FullName.Replace("mscorlib", "NonExistingAssemblyName")); IPluginCreator tested = PluginCreator.GetCreator(domain); MockLog mocklog = new MockLog((ILogWriter)tested); PluginDescriptor descriptor = MockPluginDescriptor.For(fakeName); Exception ex = DoAssert.Throws<PluginException>(() => tested.Create(descriptor, repository, null)); Assert.IsTrue(mocklog.Any(x => x.Level == MockLog.Level.Error && x.Message.Contains(ex.Message))); } }
public void CreateShouldResolveMissingAssemblies() { using (MockDomain domain = new MockDomain()) { MockAssemblyRepository repository = new MockAssemblyRepository(); IPluginCreator tested = PluginCreator.GetCreator(domain); PluginDescriptor descriptor = MockPluginDescriptor.For<MockPlugin1>(); object instance = tested.Create(descriptor, repository, null); Assert.IsNotNull(instance); Assert.IsTrue(repository.Fetched.Keys.Contains(typeof(MockPlugin1).Assembly.FullName)); } }
public void ShouldLogInfoMessageWhenPluginIsCreated() { using (MockDomain domain = new MockDomain()) { MockAssemblyRepository repository = new MockAssemblyRepository(); var creator = PluginCreator.GetCreator(domain); MockLog mocklog = new MockLog(creator as ILogWriter); var descriptor = MockPluginDescriptor.For<MockPlugin1>(); creator.Create(descriptor, repository, null); Assert.IsTrue(mocklog.Any(x => x.Level == MockLog.Level.Info && x.Message.Contains(typeof(MockPlugin1).FullName))); } }
public void ShouldLogInfoEventWithDomainNameOnNewPluginCreator() { using (MockDomain domain = new MockDomain()) { MockAssemblyRepository repository = new MockAssemblyRepository(); MockLog mocklog = new MockLog(typeof(PluginCreator)); var mockLogFactory = new Mock<ILoggerFactory>(); mockLogFactory.Setup(x => x.GetLog(typeof(PluginCreator).FullName)).Returns(mocklog); PluginCreator.GetCreator(domain, mockLogFactory.Object); Assert.IsTrue(mocklog.Any(x => x.Level == MockLog.Level.Info && x.Message.Contains(domain.Domain.FriendlyName))); } }
public void CreateShouldThrowOnUnresolvedAssembly() { using (MockDomain domain = new MockDomain()) { MockAssemblyRepository repository = new MockAssemblyRepository(); IPluginCreator tested = PluginCreator.GetCreator(domain); QualifiedName fakeName = new QualifiedName( typeof(string).FullName.Replace("mscorlib", "NonExistingAssemblyName"), typeof(string).Assembly.FullName.Replace("mscorlib", "NonExistingAssemblyName")); PluginDescriptor descriptor = MockPluginDescriptor.For(fakeName); PluginException ex = DoAssert.Throws<PluginException>(() => tested.Create(descriptor, repository, null)); Assert.IsNotNull(ex.InnerException); Assert.IsInstanceOfType(ex.InnerException, typeof(FileNotFoundException)); } }
public void CreateShouldThrowIfSettingIsWrongType() { MockAssemblyRepository repository = new MockAssemblyRepository(); IPluginCreator tested = PluginCreator.GetCreator(); PluginDescriptor descriptor = MockPluginDescriptor.For<MockPlugin2>(); Dictionary<string, object> settings = new Dictionary<string, object>() { { "NamedSetting", "not int" } }; DoAssert.Throws<PluginSettingException>(() => tested.Create(descriptor, repository, settings)); }
public void CreateShouldThrowIfMissingRequiredSettings() { MockAssemblyRepository repository = new MockAssemblyRepository(); IPluginCreator tested = PluginCreator.GetCreator(); PluginDescriptor descriptor = MockPluginDescriptor.For<MockPlugin2>(); DoAssert.Throws<PluginSettingException>(() => tested.Create(descriptor, repository, null)); }