public void AddFailsIfAddingSameAssemblyTwice()
        {
            AssemblyContainer tested = new AssemblyContainer();

            tested.Add(GetType().Assembly.Location);
            DoAssert.Throws <ArgumentException>(() => tested.Add(GetType().Assembly.Location));
        }
        public void RemoveDirRequiresKnownDirectory()
        {
            AssemblyContainer tested    = new AssemblyContainer();
            IPluginDirectory  pluginDir = new MockPluginDirectory();

            DoAssert.Throws <ArgumentException>(() => tested.RemoveDir(pluginDir));
        }
Example #3
0
        public void RemovePluginSourceMustBeAddedToBeRemoved()
        {
            PluginRepository tested       = new PluginRepository();
            MockPluginSource pluginSource = new MockPluginSource();

            DoAssert.Throws <ArgumentException>(() => tested.RemovePluginSource(pluginSource));
        }
Example #4
0
        public void RaiseEventRequiresArgument()
        {
            MockFileSystemWatcher mockWatcher = new MockFileSystemWatcher();

            using (SafeEventFileSystemWatcher tested = new SafeEventFileSystemWatcher(mockWatcher))
                DoAssert.Throws <ArgumentNullException>(() => tested.RaiseEvent(null));
        }
        public void CreateRequiresAssemblyRepository()
        {
            PluginDescriptor            descriptor = MockPluginDescriptor.For <MockPlugin1>();
            Dictionary <string, object> settings   = new Dictionary <string, object>();
            IPluginCreator tested = PluginCreator.GetCreator();

            DoAssert.Throws <ArgumentNullException>(() => tested.Create(descriptor, null, settings));
        }
        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 AddDirOnlyAcceptDirectoryOnce()
        {
            AssemblyContainer tested    = new AssemblyContainer();
            IPluginDirectory  pluginDir = new MockPluginDirectory();

            tested.AddDir(pluginDir);
            DoAssert.Throws <ArgumentException>(() => tested.AddDir(pluginDir));
        }
        public void CreateShouldThrowIfMissingRequiredSettings()
        {
            MockAssemblyRepository repository = new MockAssemblyRepository();
            IPluginCreator         tested     = PluginCreator.GetCreator();
            PluginDescriptor       descriptor = MockPluginDescriptor.For <MockPlugin2>();

            DoAssert.Throws <PluginSettingException>(() => tested.Create(descriptor, repository, null));
        }
Example #9
0
        public void AddPluginSourceCanOnlyAddOnce()
        {
            PluginRepository tested       = new PluginRepository();
            MockPluginSource pluginSource = new MockPluginSource();

            tested.AddPluginSource(pluginSource);
            DoAssert.Throws <ArgumentException>(() => tested.AddPluginSource(pluginSource));
        }
Example #10
0
        public void RaseEventThrowsArgumentExceptionOnUnknownEvent()
        {
            MockFileSystemWatcher mockWatcher = new MockFileSystemWatcher();

            using (SafeEventFileSystemWatcher tested = new SafeEventFileSystemWatcher(mockWatcher))
            {
                var evt = new FileSystemEventArgs((WatcherChangeTypes)666, "", "");
                DoAssert.Throws <ArgumentException>(() => tested.RaiseEvent(evt));
            }
        }
        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 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 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 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 ShouldThrowBadImageFormatOnLoadOfInvalidAssembly()
        {
            AssemblyReflectionManager tested = new AssemblyReflectionManager();
            string fileName = Guid.NewGuid().ToString() + ".dll";

            try
            {
                using (var file = System.IO.File.CreateText(fileName))
                    file.WriteLine("not assembly data");

                DoAssert.Throws <BadImageFormatException>(() => tested.LoadAssembly(fileName));
            }
            finally
            {
                System.IO.File.Delete(fileName);
            }
        }
 public void InternalGetCreatorRequiresILoggerFactory()
 {
     DoAssert.Throws <ArgumentNullException>(() => PluginCreator.GetCreator(AppDomain.CurrentDomain, null));
 }
 public void InternalGetCreatorRequiresDomain()
 {
     DoAssert.Throws <ArgumentNullException>(() => PluginCreator.GetCreator(null, Logger.Singleton.LoggerFactory));
 }
        public void ReflectShouldThrowArgumentExceptionOnUnknownAssembly()
        {
            AssemblyReflectionManager tested = new AssemblyReflectionManager();

            DoAssert.Throws <ArgumentException>(() => tested.Reflect(GetType().Assembly.Location, a => a.FullName));
        }
        public void ShouldThrowFileNotFoundOnLoadOfNonExistingAssembly()
        {
            AssemblyReflectionManager tested = new AssemblyReflectionManager();

            DoAssert.Throws <FileNotFoundException>(() => tested.LoadAssembly("ShouldThrowFileNotFoundOnLoadOfNonExistingAssembly.dll"));
        }
Example #20
0
        public void RemovePluginSourceShouldRejectNull()
        {
            PluginRepository tested = new PluginRepository();

            DoAssert.Throws <ArgumentNullException>(() => tested.RemovePluginSource(null));
        }
        public void ProxyReflectRequiresArgumentFunc()
        {
            AssemblyReflectionProxy tested = new AssemblyReflectionProxy();

            DoAssert.Throws <ArgumentNullException>(() => tested.Reflect <int>(null));
        }
 public void ConstructionRequiresIAssemblySource()
 {
     DoAssert.Throws <ArgumentNullException>(() => new PluginExtractor(null));
 }
 public void ConstructionMustProvideVersionString()
 {
     DoAssert.Throws <ArgumentNullException>(() => new PluginVersion(null));
 }
        public void AddRequiresExistingFile()
        {
            AssemblyContainer tested = new AssemblyContainer();

            DoAssert.Throws <FileNotFoundException>(() => tested.Add(@"c:\" + Guid.NewGuid().ToString()));
        }
        public void AddRequiresArgument()
        {
            AssemblyContainer tested = new AssemblyContainer();

            DoAssert.Throws <ArgumentNullException>(() => tested.Add(null));
        }
        public void ReflectRequiresArgumentAssembly()
        {
            AssemblyReflectionManager tested = new AssemblyReflectionManager();

            DoAssert.Throws <ArgumentNullException>(() => tested.Reflect(null, a => a.FullName));
        }
 public void GetCreatorRequiresArgument()
 {
     DoAssert.Throws <ArgumentNullException>(() => PluginCreator.GetCreator(null));
 }
 public void ConstructionVersionStringMustContainDot()
 {
     DoAssert.Throws <ArgumentException>(() => new PluginVersion("55"));
 }
 public void ConstructionVersionStringMustNotContainAphaChar()
 {
     DoAssert.Throws <ArgumentException>(() => new PluginVersion("55t.66"));
 }
        public void ReflectRequiresArgumentFunc()
        {
            AssemblyReflectionManager tested = new AssemblyReflectionManager();

            DoAssert.Throws <ArgumentNullException>(() => tested.Reflect <int>(GetType().Assembly.Location, null));
        }