コード例 #1
0
 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));
 }
コード例 #2
0
 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);
 }
コード例 #3
0
 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)));
 }
コード例 #4
0
        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);
        }
コード例 #5
0
        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)));
              }
        }
コード例 #6
0
 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));
       }
 }
コード例 #7
0
 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)));
       }
 }
コード例 #8
0
 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)));
       }
 }
コード例 #9
0
        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));
              }
        }
コード例 #10
0
        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));
        }
コード例 #11
0
        public void CreateShouldThrowIfMissingRequiredSettings()
        {
            MockAssemblyRepository repository = new MockAssemblyRepository();
              IPluginCreator tested = PluginCreator.GetCreator();
              PluginDescriptor descriptor = MockPluginDescriptor.For<MockPlugin2>();

              DoAssert.Throws<PluginSettingException>(() => tested.Create(descriptor, repository, null));
        }