public void ShouldBeAbleToLoadSeveralAssembliesIntoSameDomain()
        {
            AssemblyReflectionManager tested = new AssemblyReflectionManager();

            Assert.IsTrue(tested.LoadAssembly(GetType().Assembly.Location));
            Assert.IsTrue(tested.LoadAssembly(tested.GetType().Assembly.Location));
        }
        public void ShouldNotBeAbleToLoadSameAssemblyTwiceIntoSameDomain()
        {
            AssemblyReflectionManager tested = new AssemblyReflectionManager();

            Assert.IsTrue(tested.LoadAssembly(GetType().Assembly.Location));
            Assert.IsFalse(tested.LoadAssembly(GetType().Assembly.Location));
        }
示例#3
0
        private void btnAssemblyReflection_Click(object sender, RoutedEventArgs e)
        {
            var assemblyPath = txtAssemblyPath.Text;
            var manager      = new AssemblyReflectionManager();
            var success      = manager.LoadAssembly(assemblyPath, "VNCReflectionDomain");

            var results = manager.Reflect(assemblyPath, (a) =>
            {
                var names = new List <String>();
                var types = a.GetTypes();

                foreach (var t in types)
                {
                    names.Add(t.Name);
                }

                return(names);
            });

            txtOutput.Clear();

            foreach (var name in results)
            {
                txtOutput.Text += (System.Environment.NewLine + name.ToString());
            }

            manager.UnloadAssembly(assemblyPath);
        }
        public void ShouldLogToInfoNumberOfAddedPluginsForAssembly()
        {
            var             path               = GetType().Assembly.Location;
            var             pattern            = new Regex(@"^Found \d+ plugins in .+$");
            var             mockAssemblySource = new Mock <IAssemblySource>();
            PluginExtractor tested             = new PluginExtractor(mockAssemblySource.Object);
            MockLog         log = new MockLog(tested);

            using (AssemblyReflectionManager manager = new AssemblyReflectionManager())
            {
                manager.LoadAssembly(path);
                mockAssemblySource.Raise(x => x.AssemblyAdded += null, new AssemblyAddedEventArgs(path, manager));
            }
            Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Info && pattern.IsMatch(x.Message) && x.Message.Contains(path)));
        }
        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 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);
            }
        }
示例#7
0
        private void btnDomainReflection_Click(object sender, RoutedEventArgs e)
        {
            var assemblyPath = txtAssemblyPath.Text;
            var manager      = new AssemblyReflectionManager();
            var success      = manager.LoadAssembly(assemblyPath, "VNCReflectionDomain");

            var results = manager.GetTypeInformation(assemblyPath);

            txtOutput.Clear();

            foreach (TypeInformation info in results)
            {
                txtOutput.Text += (System.Environment.NewLine + info.FullName);
            }

            manager.UnloadAssembly(assemblyPath);
        }
        public void OnAssemblyRemovedShouldRaisePluginLostForEachPluginInAssembly()
        {
            MockAssemblySource mockSource = new MockAssemblySource();
              PluginExtractor tested = new PluginExtractor(mockSource);

              List<PluginDescriptor> plugins = new List<PluginDescriptor>();
              tested.PluginAdded += (s, e) => plugins.Add(e.Plugin);
              tested.PluginRemoved += (s, e) => plugins.Remove(e.Plugin);

              using (AssemblyReflectionManager manager = new AssemblyReflectionManager())
              {
            string assemblyPath = GetType().Assembly.Location;
            manager.LoadAssembly(assemblyPath);
            mockSource.RaiseAssemblyAdded(new AssemblyAddedEventArgs(assemblyPath, manager));

            AssemblyRemovedEventArgs args = new AssemblyRemovedEventArgs(assemblyPath);
            mockSource.RaiseAssemblyRemoved(args);
              }

              Assert.AreEqual(0, plugins.Count);
        }
        public void PluginDescriptorShouldContainSpecifiedName()
        {
            MockAssemblySource mockSource = new MockAssemblySource();
            PluginExtractor    tested     = new PluginExtractor(mockSource);

            List <PluginDescriptor> plugins = new List <PluginDescriptor>();

            tested.PluginAdded   += (s, e) => plugins.Add(e.Plugin);
            tested.PluginRemoved += (s, e) => plugins.Remove(e.Plugin);

            using (AssemblyReflectionManager manager = new AssemblyReflectionManager())
            {
                string assemblyPath = GetType().Assembly.Location;
                manager.LoadAssembly(assemblyPath);
                mockSource.RaiseAssemblyAdded(new AssemblyAddedEventArgs(assemblyPath, manager));
            }

            PluginDescriptor plugin = plugins.First(x => x.QualifiedName == typeof(MockPlugin2));

            Assert.AreEqual("MockPlugin2", plugin.Name);
        }
        public void OnAssemblyRemovedShouldRaisePluginLostForEachPluginInAssembly()
        {
            MockAssemblySource mockSource = new MockAssemblySource();
            PluginExtractor    tested     = new PluginExtractor(mockSource);

            List <PluginDescriptor> plugins = new List <PluginDescriptor>();

            tested.PluginAdded   += (s, e) => plugins.Add(e.Plugin);
            tested.PluginRemoved += (s, e) => plugins.Remove(e.Plugin);

            using (AssemblyReflectionManager manager = new AssemblyReflectionManager())
            {
                string assemblyPath = GetType().Assembly.Location;
                manager.LoadAssembly(assemblyPath);
                mockSource.RaiseAssemblyAdded(new AssemblyAddedEventArgs(assemblyPath, manager));

                AssemblyRemovedEventArgs args = new AssemblyRemovedEventArgs(assemblyPath);
                mockSource.RaiseAssemblyRemoved(args);
            }

            Assert.AreEqual(0, plugins.Count);
        }
        public void PluginDescriptorShouldContainPluginSettings()
        {
            MockAssemblySource mockSource = new MockAssemblySource();
            PluginExtractor    tested     = new PluginExtractor(mockSource);

            List <PluginDescriptor> plugins = new List <PluginDescriptor>();

            tested.PluginAdded   += (s, e) => plugins.Add(e.Plugin);
            tested.PluginRemoved += (s, e) => plugins.Remove(e.Plugin);

            using (AssemblyReflectionManager manager = new AssemblyReflectionManager())
            {
                string assemblyPath = GetType().Assembly.Location;
                manager.LoadAssembly(assemblyPath);
                mockSource.RaiseAssemblyAdded(new AssemblyAddedEventArgs(assemblyPath, manager));
            }

            PluginDescriptor plugin = plugins.First(x => x.QualifiedName == typeof(MockPlugin1));

            Assert.AreEqual(2, plugin.Settings.Count);
            Assert.IsTrue(plugin.Settings.Any(x => x.Name == "Setting" && x.SettingType == typeof(int)));
            Assert.IsTrue(plugin.Settings.Any(x => x.Name == "AnotherSetting" && x.SettingType == typeof(string)));
        }
        public void PluginDescriptorShouldContainDerivedClasses()
        {
            MockAssemblySource mockSource = new MockAssemblySource();
            PluginExtractor    tested     = new PluginExtractor(mockSource);

            List <PluginDescriptor> plugins = new List <PluginDescriptor>();

            tested.PluginAdded   += (s, e) => plugins.Add(e.Plugin);
            tested.PluginRemoved += (s, e) => plugins.Remove(e.Plugin);

            using (AssemblyReflectionManager manager = new AssemblyReflectionManager())
            {
                string assemblyPath = GetType().Assembly.Location;
                manager.LoadAssembly(assemblyPath);
                mockSource.RaiseAssemblyAdded(new AssemblyAddedEventArgs(assemblyPath, manager));
            }

            PluginDescriptor plugin = plugins.First(x => x.QualifiedName == typeof(MockPlugin1));

            Assert.AreEqual(3, plugin.Derives.Count);
            Assert.IsTrue(plugin.Derives.Any(x => x == typeof(MockPluginBase)));
            Assert.IsTrue(plugin.Derives.Any(x => x == typeof(MarshalByRefObject)));
            Assert.IsTrue(plugin.Derives.Any(x => x == typeof(object)));
        }
 public void ShouldLogToInfoNumberOfLostPluginsForAssembly()
 {
     var path = GetType().Assembly.Location;
       var pattern = new Regex(@"^Lost \d+ plugins when .+ was removed$");
       var mockAssemblySource = new Mock<IAssemblySource>();
       PluginExtractor tested = new PluginExtractor(mockAssemblySource.Object);
       MockLog log = new MockLog(tested);
       using (AssemblyReflectionManager manager = new AssemblyReflectionManager())
       {
     manager.LoadAssembly(path);
     mockAssemblySource.Raise(x => x.AssemblyAdded += null, new AssemblyAddedEventArgs(path, manager));
     mockAssemblySource.Raise(x => x.AssemblyRemoved += null, new AssemblyRemovedEventArgs(path));
       }
       Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Info && pattern.IsMatch(x.Message) && x.Message.Contains(path)));
 }
        public void PluginDescriptorShouldContainPluginSettings()
        {
            MockAssemblySource mockSource = new MockAssemblySource();
              PluginExtractor tested = new PluginExtractor(mockSource);

              List<PluginDescriptor> plugins = new List<PluginDescriptor>();
              tested.PluginAdded += (s, e) => plugins.Add(e.Plugin);
              tested.PluginRemoved += (s, e) => plugins.Remove(e.Plugin);

              using (AssemblyReflectionManager manager = new AssemblyReflectionManager())
              {
            string assemblyPath = GetType().Assembly.Location;
            manager.LoadAssembly(assemblyPath);
            mockSource.RaiseAssemblyAdded(new AssemblyAddedEventArgs(assemblyPath, manager));
              }

              PluginDescriptor plugin = plugins.First(x => x.QualifiedName == typeof(MockPlugin1));

              Assert.AreEqual(2, plugin.Settings.Count);
              Assert.IsTrue(plugin.Settings.Any(x => x.Name == "Setting" && x.SettingType == typeof(int)));
              Assert.IsTrue(plugin.Settings.Any(x => x.Name == "AnotherSetting" && x.SettingType == typeof(string)));
        }
        public void PluginDescriptorShouldContainDerivedClasses()
        {
            MockAssemblySource mockSource = new MockAssemblySource();
              PluginExtractor tested = new PluginExtractor(mockSource);

              List<PluginDescriptor> plugins = new List<PluginDescriptor>();
              tested.PluginAdded += (s, e) => plugins.Add(e.Plugin);
              tested.PluginRemoved += (s, e) => plugins.Remove(e.Plugin);

              using (AssemblyReflectionManager manager = new AssemblyReflectionManager())
              {
            string assemblyPath = GetType().Assembly.Location;
            manager.LoadAssembly(assemblyPath);
            mockSource.RaiseAssemblyAdded(new AssemblyAddedEventArgs(assemblyPath, manager));
              }

              PluginDescriptor plugin = plugins.First(x => x.QualifiedName == typeof(MockPlugin1));
              Assert.AreEqual(3, plugin.Derives.Count);
              Assert.IsTrue(plugin.Derives.Any(x => x == typeof(MockPluginBase)));
              Assert.IsTrue(plugin.Derives.Any(x => x == typeof(MarshalByRefObject)));
              Assert.IsTrue(plugin.Derives.Any(x => x == typeof(object)));
        }
 public void ShouldBeAbleToLoadSeveralAssembliesIntoSameDomain()
 {
     AssemblyReflectionManager tested = new AssemblyReflectionManager();
       Assert.IsTrue(tested.LoadAssembly(GetType().Assembly.Location));
       Assert.IsTrue(tested.LoadAssembly(tested.GetType().Assembly.Location));
 }
        public void ShouldThrowFileNotFoundOnLoadOfNonExistingAssembly()
        {
            AssemblyReflectionManager tested = new AssemblyReflectionManager();

            DoAssert.Throws <FileNotFoundException>(() => tested.LoadAssembly("ShouldThrowFileNotFoundOnLoadOfNonExistingAssembly.dll"));
        }
 public void ReflectShouldThrowArgumentExceptionOnUnknownAssembly()
 {
     AssemblyReflectionManager tested = new AssemblyReflectionManager();
       DoAssert.Throws<ArgumentException>(() => tested.Reflect(GetType().Assembly.Location, a => a.FullName));
 }
 public void ShouldBeAbleToLoadExistingAssembly()
 {
     AssemblyReflectionManager tested = new AssemblyReflectionManager();
       Assert.IsTrue(tested.LoadAssembly(GetType().Assembly.Location));
 }
        public void ShouldBeAbleToLoadExistingAssembly()
        {
            AssemblyReflectionManager tested = new AssemblyReflectionManager();

            Assert.IsTrue(tested.LoadAssembly(GetType().Assembly.Location));
        }
        public bool Add(string assemblyPath)
        {
            if (assemblyPath == null)
            throw new ArgumentNullException("assemblyPath");

              FileInfo assemblyFile = new FileInfo(assemblyPath);
              if (!assemblyFile.Exists)
            throw new FileNotFoundException();

              try
              {
            using (AssemblyReflectionManager reflectionManager = new AssemblyReflectionManager())
            {
              lock (this.assemblyPaths)
              {
            if (this.pathAssembly.ContainsKey(assemblyPath))
              throw new ArgumentException(Resources.AssemblyAlreadyAdded);

            if (reflectionManager.LoadAssembly(assemblyFile.FullName))
            {
              var assemblyName = reflectionManager.Reflect(assemblyFile.FullName, assembly => assembly.FullName);
              AddPathToName(assemblyName, assemblyFile.FullName);

              this.log.Info(Resources.AssemblyAdded, assemblyFile.FullName);

              if (this.AssemblyAdded != null)
                this.AssemblyAdded(this, new AssemblyAddedEventArgs(assemblyFile.FullName, reflectionManager));

              return true;
            }
              }
            }
              }
              catch (BadImageFormatException) { }
              catch (FileLoadException) { }

              return false;
        }
 public void ShouldThrowFileNotFoundOnLoadOfNonExistingAssembly()
 {
     AssemblyReflectionManager tested = new AssemblyReflectionManager();
       DoAssert.Throws<FileNotFoundException>(() => tested.LoadAssembly("ShouldThrowFileNotFoundOnLoadOfNonExistingAssembly.dll"));
 }
        public void PluginDescriptorShouldContainDefaultName()
        {
            MockAssemblySource mockSource = new MockAssemblySource();
              PluginExtractor tested = new PluginExtractor(mockSource);

              List<PluginDescriptor> plugins = new List<PluginDescriptor>();
              tested.PluginAdded += (s, e) => plugins.Add(e.Plugin);
              tested.PluginRemoved += (s, e) => plugins.Remove(e.Plugin);

              using (AssemblyReflectionManager manager = new AssemblyReflectionManager())
              {
            string assemblyPath = GetType().Assembly.Location;
            manager.LoadAssembly(assemblyPath);
            mockSource.RaiseAssemblyAdded(new AssemblyAddedEventArgs(assemblyPath, manager));
              }

              var expected = typeof(MockPlugin1).FullName;
              PluginDescriptor plugin = plugins.First(x => x.QualifiedName == typeof(MockPlugin1));

              Assert.AreEqual(expected, plugin.Name);
        }
 public void ReflectRequiresArgumentFunc()
 {
     AssemblyReflectionManager tested = new AssemblyReflectionManager();
       DoAssert.Throws<ArgumentNullException>(() => tested.Reflect<int>(GetType().Assembly.Location, null));
 }
        public void ReflectRequiresArgumentAssembly()
        {
            AssemblyReflectionManager tested = new AssemblyReflectionManager();

            DoAssert.Throws <ArgumentNullException>(() => tested.Reflect(null, a => a.FullName));
        }
        public void ReflectRequiresArgumentFunc()
        {
            AssemblyReflectionManager tested = new AssemblyReflectionManager();

            DoAssert.Throws <ArgumentNullException>(() => tested.Reflect <int>(GetType().Assembly.Location, null));
        }
 public void ReflectRequiresArgumentAssembly()
 {
     AssemblyReflectionManager tested = new AssemblyReflectionManager();
       DoAssert.Throws<ArgumentNullException>(() => tested.Reflect(null, a => a.FullName));
 }
        public void ReflectShouldThrowArgumentExceptionOnUnknownAssembly()
        {
            AssemblyReflectionManager tested = new AssemblyReflectionManager();

            DoAssert.Throws <ArgumentException>(() => tested.Reflect(GetType().Assembly.Location, a => a.FullName));
        }
 public void Test()
 {
     AssemblyReflectionManager manager = new AssemblyReflectionManager();
 }
 public void ShouldNotBeAbleToLoadSameAssemblyTwiceIntoSameDomain()
 {
     AssemblyReflectionManager tested = new AssemblyReflectionManager();
       Assert.IsTrue(tested.LoadAssembly(GetType().Assembly.Location));
       Assert.IsFalse(tested.LoadAssembly(GetType().Assembly.Location));
 }