Exemplo n.º 1
0
        /// <summary>
        /// Creates the <see cref="T:Prism.Modularity.IModuleCatalog"/> used by Prism.
        /// </summary>
        /// <remarks>
        /// The base implementation returns a new ModuleCatalog.
        /// </remarks>
        protected override IModuleCatalog CreateModuleCatalog()
        {
            var directoryModuleCatalog = new DirectoryModuleCatalog();
            directoryModuleCatalog.ModulePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\modules\";

            return directoryModuleCatalog;
        }
        public void ShouldReturnAListOfModuleInfo()
        {
            CompilerHelper.CompileFile(@"Prism.Wpf.Tests.Mocks.Modules.MockModuleA.cs",
                                       ModulesDirectory1 + @"\MockModuleA.dll");


            DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
            catalog.ModulePath = ModulesDirectory1;
            catalog.Load();

            ModuleInfo[] modules = catalog.Modules.ToArray();

            Assert.IsNotNull(modules);
            Assert.AreEqual(1, modules.Length);
            Assert.IsNotNull(modules[0].Ref);
            StringAssert.StartsWith(modules[0].Ref, "file://");
            Assert.IsTrue(modules[0].Ref.Contains(@"MockModuleA.dll"));
            Assert.IsNotNull(modules[0].ModuleType);
            StringAssert.Contains(modules[0].ModuleType, "Prism.Wpf.Tests.Mocks.Modules.MockModuleA");
        }
 public ModuleInfo[] DoEnumeration(string path)
 {
     DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
     catalog.ModulePath = path;
     catalog.Load();
     return catalog.Modules.ToArray();
 }
        public void ShouldIgnoreAbstractClassesThatImplementIModule()
        {
            CompilerHelper.CleanUpDirectory(ModulesDirectory1);
            CompilerHelper.CompileFile(@"Prism.Wpf.Tests.Mocks.Modules.MockAbstractModule.cs",
                                     ModulesDirectory1 + @"\MockAbstractModule.dll");

            string filename = typeof(DirectoryModuleCatalog).Assembly.Location;
            string destinationFileName = Path.Combine(ModulesDirectory1, Path.GetFileName(filename));
            File.Copy(filename, destinationFileName);

            DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
            catalog.ModulePath = ModulesDirectory1;
            catalog.Load();

            ModuleInfo[] modules = catalog.Modules.ToArray();
            Assert.AreEqual(1, modules.Length);
            Assert.AreEqual("MockInheritingModule", modules[0].ModuleName);

            CompilerHelper.CleanUpDirectory(ModulesDirectory1);
        }
        public void ShouldNotFailWhenAlreadyLoadedAssembliesAreAlsoFoundOnTargetDirectory()
        {
            CompilerHelper.CompileFile(@"Prism.Wpf.Tests.Mocks.Modules.MockModuleA.cs",
                                       ModulesDirectory1 + @"\MockModuleA.dll");

            string filename = typeof(DirectoryModuleCatalog).Assembly.Location;
            string destinationFileName = Path.Combine(ModulesDirectory1, Path.GetFileName(filename));
            File.Copy(filename, destinationFileName);

            DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
            catalog.ModulePath = ModulesDirectory1;
            catalog.Load();

            ModuleInfo[] modules = catalog.Modules.ToArray();
            Assert.AreEqual(1, modules.Length);
        }
        public void ShouldLoadAssemblyEvenIfIsExposingTypesFromAnAssemblyInTheGac()
        {
            CompilerHelper.CompileFile(@"Prism.Wpf.Tests.Mocks.Modules.MockExposingTypeFromGacAssemblyModule.cs",
                                       ModulesDirectory4 + @"\MockExposingTypeFromGacAssemblyModule.dll", @"System.Transactions.dll");

            DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
            catalog.ModulePath = ModulesDirectory4;
            catalog.Load();

            ModuleInfo[] modules = catalog.Modules.ToArray();

            Assert.AreEqual(1, modules.Count());
        }
Exemplo n.º 7
0
 protected override IModuleCatalog CreateModuleCatalog()
 {
     var moduleCatalog = new DirectoryModuleCatalog();
     moduleCatalog.ModulePath = @".\Modules";
     return moduleCatalog;
 }
        public void ShouldDefaultInitializationModeToWhenAvailable()
        {
            CompilerHelper.CompileFile(@"Prism.Wpf.Tests.Mocks.Modules.MockModuleA.cs",
                                       ModulesDirectory1 + @"\MockModuleA.dll");

            DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
            catalog.ModulePath = ModulesDirectory1;
            catalog.Load();

            ModuleInfo[] modules = catalog.Modules.ToArray();

            Assert.IsNotNull(modules);
            Assert.AreEqual(InitializationMode.WhenAvailable, modules[0].InitializationMode);
        }
        public void ShouldGetOnDemandFromAttribute()
        {
            CompilerHelper.CompileFile(@"Prism.Wpf.Tests.Mocks.Modules.MockAttributedModule.cs",
                                       ModulesDirectory3 + @"\MockAttributedModule.dll");

            DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
            catalog.ModulePath = ModulesDirectory3;
            catalog.Load();

            ModuleInfo[] modules = catalog.Modules.ToArray();

            Assert.AreEqual(1, modules.Length);
            Assert.AreEqual(InitializationMode.OnDemand, modules[0].InitializationMode);

        }
        public void ShouldGetDependantModulesFromAttribute()
        {
            CompilerHelper.CompileFile(@"Prism.Wpf.Tests.Mocks.Modules.MockDependencyModule.cs",
                                       ModulesDirectory3 + @"\DependencyModule.dll");

            CompilerHelper.CompileFile(@"Prism.Wpf.Tests.Mocks.Modules.MockDependantModule.cs",
                                       ModulesDirectory3 + @"\DependantModule.dll");

            DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
            catalog.ModulePath = ModulesDirectory3;
            catalog.Load();

            ModuleInfo[] modules = catalog.Modules.ToArray();

            Assert.AreEqual(2, modules.Length);
            var dependantModule = modules.First(module => module.ModuleName == "DependantModule");
            var dependencyModule = modules.First(module => module.ModuleName == "DependencyModule");
            Assert.IsNotNull(dependantModule);
            Assert.IsNotNull(dependencyModule);
            Assert.IsNotNull(dependantModule.DependsOn);
            Assert.AreEqual(1, dependantModule.DependsOn.Count);
            Assert.AreEqual(dependencyModule.ModuleName, dependantModule.DependsOn[0]);
        }
        public void UseClassNameAsModuleNameWhenNotSpecifiedInAttribute()
        {
            CompilerHelper.CompileFile(@"Prism.Wpf.Tests.Mocks.Modules.MockModuleA.cs",
                                       ModulesDirectory1 + @"\MockModuleA.dll");

            DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
            catalog.ModulePath = ModulesDirectory1;
            catalog.Load();

            ModuleInfo[] modules = catalog.Modules.ToArray();

            Assert.IsNotNull(modules);
            Assert.AreEqual("MockModuleA", modules[0].ModuleName);
        }
        public void ShouldGetModuleNameFromAttribute()
        {
            CompilerHelper.CompileFile(@"Prism.Wpf.Tests.Mocks.Modules.MockAttributedModule.cs",
                                       ModulesDirectory2 + @"\MockAttributedModule.dll");


            DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
            catalog.ModulePath = ModulesDirectory2;
            catalog.Load();

            ModuleInfo[] modules = catalog.Modules.ToArray();

            Assert.AreEqual(1, modules.Length);
            Assert.AreEqual("TestModule", modules[0].ModuleName);
        }
        public void LoadsValidAssembliesWhenInvalidDllsArePresent()
        {
            CompilerHelper.CompileFile(@"Prism.Wpf.Tests.Mocks.Modules.MockModuleA.cs",
                                       InvalidModulesDirectory + @"\MockModuleA.dll");

            DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
            catalog.ModulePath = InvalidModulesDirectory;
            try
            {
                catalog.Load();
            }
            catch (Exception)
            {
                Assert.Fail("Should not have thrown.");
            }

            ModuleInfo[] modules = catalog.Modules.ToArray();

            Assert.IsNotNull(modules);
            Assert.AreEqual(1, modules.Length);
            Assert.IsNotNull(modules[0].Ref);
            StringAssert.StartsWith(modules[0].Ref, "file://");
            Assert.IsTrue(modules[0].Ref.Contains(@"MockModuleA.dll"));
            Assert.IsNotNull(modules[0].ModuleType);
            StringAssert.Contains(modules[0].ModuleType, "Prism.Wpf.Tests.Mocks.Modules.MockModuleA");
        }
Exemplo n.º 14
0
        protected override void ConfigureModuleCatalog()
        {
            // Module A is defined in the code.
            Type moduleAType = typeof(ModuleA);
            ModuleCatalog.AddModule(new ModuleInfo(moduleAType.Name, moduleAType.AssemblyQualifiedName));

            // Module C is defined in the code.
            Type moduleCType = typeof(ModuleC);
            ModuleCatalog.AddModule(new ModuleInfo()
            {
                ModuleName = moduleCType.Name,
                ModuleType = moduleCType.AssemblyQualifiedName,
                InitializationMode = InitializationMode.OnDemand
            });

            // Module B and Module D are copied to a directory as part of a post-build step.
            // These modules are not referenced in the project and are discovered by inspecting a directory.
            // Both projects have a post-build step to copy themselves into that directory.
            DirectoryModuleCatalog directoryCatalog = new DirectoryModuleCatalog() { ModulePath = @".\DirectoryModules" };
            ((AggregateModuleCatalog)ModuleCatalog).AddCatalog(directoryCatalog);

            // Module E and Module F are defined in configuration.
            ConfigurationModuleCatalog configurationCatalog = new ConfigurationModuleCatalog();
            ((AggregateModuleCatalog)ModuleCatalog).AddCatalog(configurationCatalog);

        }
 public void EmptyPathThrows()
 {
     DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
     catalog.Load();
 }
        public void ShouldNotLoadAssembliesInCurrentAppDomain()
        {
            CompilerHelper.CompileFile(@"Prism.Wpf.Tests.Mocks.Modules.MockModuleA.cs",
                                       ModulesDirectory4 + @"\MockModuleA.dll");

            DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
            catalog.ModulePath = ModulesDirectory4;
            catalog.Load();

            ModuleInfo[] modules = catalog.Modules.ToArray();

            // filtering out dynamic assemblies due to using a dynamic mocking framework.
            Assembly loadedAssembly = AppDomain.CurrentDomain.GetAssemblies().Where(assembly => !assembly.IsDynamic)
                .Where(assembly => assembly.Location.Equals(modules[0].Ref, StringComparison.InvariantCultureIgnoreCase))
                .FirstOrDefault();
            Assert.IsNull(loadedAssembly);
        }
 public void NonExistentPathThrows()
 {
     DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
     catalog.ModulePath = "NonExistentPath";
     catalog.Load();
 }
        public void ShouldNotGetModuleInfoForAnAssemblyAlreadyLoadedInTheMainDomain()
        {
            var assemblyPath = Assembly.GetCallingAssembly().Location;
            DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
            catalog.ModulePath = ModulesDirectory5;
            catalog.Load();

            ModuleInfo[] modules = catalog.Modules.ToArray();

            Assert.AreEqual(0, modules.Length);
        }
 public void ShouldNotThrowWithNonValidDotNetAssembly()
 {
     DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
     catalog.ModulePath = InvalidModulesDirectory;
     try
     {
         catalog.Load();
     }
     catch (Exception)
     {
         Assert.Fail("Should not have thrown.");
     }
     
     ModuleInfo[] modules = catalog.Modules.ToArray();
     Assert.IsNotNull(modules);
     Assert.AreEqual(0, modules.Length);
 }
        public void ShouldLoadAssemblyEvenIfTheyAreReferencingEachOther()
        {
            CompilerHelper.CompileFile(@"Prism.Wpf.Tests.Mocks.Modules.MockModuleA.cs",
                                       ModulesDirectory4 + @"\MockModuleZZZ.dll");

            CompilerHelper.CompileFile(@"Prism.Wpf.Tests.Mocks.Modules.MockModuleReferencingOtherModule.cs",
                                       ModulesDirectory4 + @"\MockModuleReferencingOtherModule.dll", ModulesDirectory4 + @"\MockModuleZZZ.dll");

            DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
            catalog.ModulePath = ModulesDirectory4;
            catalog.Load();

            ModuleInfo[] modules = catalog.Modules.ToArray();

            Assert.AreEqual(2, modules.Count());
        }
Exemplo n.º 21
0
 protected override void ConfigureModuleCatalog() {
     base.ConfigureModuleCatalog();
     var mc = new DirectoryModuleCatalog();
     mc.ModulePath = System.IO.Path.Combine(System.Environment.CurrentDirectory, "Module");
     ModuleCatalog = mc;
 }
        protected override void ConfigureModuleCatalog()
        {
            base.ConfigureModuleCatalog();




            //Configuration Modules Declaration
            ConfigurationModuleCatalog configurationCatalog = new ConfigurationModuleCatalog();
            ((AggregateModuleCatalog)ModuleCatalog).AddCatalog(configurationCatalog);

            var erpmodtype = typeof(ErpApplicationModule);
            ModuleCatalog.AddModule(new ModuleInfo(erpmodtype.Name, erpmodtype.AssemblyQualifiedName));
#if DEBUG
            RegisterModule rm = delegate (Type t)
              {

                  ModuleCatalog.AddModule(new ModuleInfo(t.Name, t.AssemblyQualifiedName));
              };
            rm(typeof(QuotationModule));
            rm(typeof(ArticleModule));
            rm(typeof(OneDCutModule));
#else
            //Directory Modules dll 
            DirectoryModuleCatalog directoryCatalog = new DirectoryModuleCatalog() { ModulePath = @".\modules" };
            ((AggregateModuleCatalog)ModuleCatalog).AddCatalog(directoryCatalog);
#endif
            //this.ModuleManager= ServiceLocator.Current.GetInstance<IModuleManager>();
        }