예제 #1
0
        private void PrepareModulesTestDirectories(string testPath, string moduleAPath, string moduleBPath)
        {
            if (Directory.Exists(testPath))
            {
                Directory.Delete(testPath, true);
            }
            Directory.CreateDirectory(testPath);

            // compile modules into a.dll / b.dll
            var compiler = new ModuleCompiler();


            compiler.OutputDirectory = moduleAPath;
            compiler.OutputName      = Path.Combine(moduleAPath, "a.dll");
            compiler.GenerateModuleFromCode(
                @"..\Source\Nomad.Tests\FunctionalTests\Data\SimplestModulePossible1.cs");

            compiler.OutputDirectory = moduleBPath;
            compiler.OutputName      = Path.Combine(moduleBPath, "b.dll");
            compiler.GenerateModuleFromCode(
                @"..\Source\Nomad.Tests\FunctionalTests\Data\SimplestModulePossible1.cs");

            // generate manifests
            var builder = new ManifestBuilder(@"TEST_ISSUER", KeyFile, @"a.dll", moduleAPath);

            builder.CreateAndPublish();
            builder = new ManifestBuilder(@"TEST_ISSUER", KeyFile, @"b.dll", moduleBPath);
            builder.CreateAndPublish();

            // add spoiling module (assembly without manifest)
            File.Copy(Path.Combine(moduleAPath, @"a.dll"), Path.Combine(testPath, "c.dll"));
        }
예제 #2
0
        protected void PrepareSharedLibrary()
        {
            RuntimePath = RUNTIME_LOCATION + GetCurrentClassName() + @"\" + GetCurrentMethodName();

            // remove the directory if it is there already
            if (Directory.Exists(RuntimePath))
            {
                Directory.Delete(RuntimePath, true);
            }

            string sharedModuleSrc = GetSourceCodePath(typeof(DistributableMessage));
            string sharedRegistry  = GetSourceCodePath(typeof(DistributedMessageRegistry));

            Compiler.OutputDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, RuntimePath);
            _sharedDll = Compiler.GenerateModuleFromCode(new[] { sharedModuleSrc, sharedRegistry });
        }
예제 #3
0
        public void setup()
        {
            _keyFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                        @"FunctionalTests\Signing\KeyDir\manifest-key.xml");
            _moduleDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                            @"FunctionalTests\Signing\Module");
            _assemblyName = "sample_module.dll";
            _assemblyPath = Path.Combine(_moduleDirectory, _assemblyName);
            _manifestPath = _assemblyPath + ModuleManifest.ManifestFileNameSuffix;
            _issuerName   = "test-issuer";
            if (File.Exists(_keyFileName))
            {
                File.Delete(_keyFileName);
            }

            KeysGenerator.KeysGeneratorProgram.Main(new[] { _keyFileName });

            // creating sample assembly, cause the manifest generator requires full-fledgged assembly not imposter
            var compiler = new ModuleCompiler
            {
                OutputDirectory = _moduleDirectory,
                OutputName      = _assemblyPath
            };

            compiler.GenerateModuleFromCode(ModuleCompiler.DefaultSimpleModuleSource);

            // test creating the manifests
            ManifestCreatorProgram.Main(new[]
            {
                "rsa",
                _keyFileName, _moduleDirectory,
                _assemblyName, _issuerName
            });
        }
예제 #4
0
        public void setup()
        {
            //FIXME what is this for ?
            Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture("en-US");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

            _privateKeyFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                               @"res\pki\SignedByCA.pfx");
            Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                         @"res\pki\NomadFakeCa.cer");
            _assemblyName    = "sample_module.dll";
            _moduleDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                            @"FunctionalTests\Signing\Module");

            _assemblyPath = Path.Combine(_moduleDirectory, _assemblyName);
            _manifestPath = _assemblyPath + ModuleManifest.ManifestFileNameSuffix;
            _issuerName   = "test-issuer";

            _manifestSignature = _manifestPath + ModuleManifest.ManifestSignatureFileNameSuffix;

            // create fully fledgged assembly
            var compiler = new ModuleCompiler
            {
                OutputDirectory = _moduleDirectory,
                OutputName      = _assemblyPath
            };

            compiler.GenerateModuleFromCode(ModuleCompiler.DefaultSimpleModuleSource);

            CreateSignature(_privateKeyFileName, "abc123");
        }
예제 #5
0
        public void discovers_all_proper_modules_with_manifests_ignores_others_assemblies()
        {
            // make another folder
            string testPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                           @"IntegrationTests\DirectoryModuleDiscovery2\");

            if (Directory.Exists(testPath))
            {
                Directory.Delete(testPath, true);
            }
            Directory.CreateDirectory(testPath);

            // compile modules into a.dll / b.dll
            var compiler = new ModuleCompiler();

            compiler.OutputDirectory = testPath;

            compiler.OutputName = Path.Combine(testPath, "a.dll");
            compiler.GenerateModuleFromCode(
                @"..\Source\Nomad.Tests\FunctionalTests\Data\SimplestModulePossible1.cs");

            compiler.OutputName = Path.Combine(testPath, "b.dll");
            compiler.GenerateModuleFromCode(
                @"..\Source\Nomad.Tests\FunctionalTests\Data\SimplestModulePossible1.cs");

            // generate manifests
            var builder = new ManifestBuilder(@"TEST_ISSUER", KeyFile, @"a.dll", testPath);

            builder.CreateAndPublish();
            builder = new ManifestBuilder(@"TEST_ISSUER", KeyFile, @"b.dll", testPath);
            builder.CreateAndPublish();

            // add spoiling module (assembly without manifest)
            File.Copy(Path.Combine(testPath, @"a.dll"), Path.Combine(testPath, "c.dll"));

            var expectedModules = new[]
            {
                new ModuleInfo(Path.Combine(testPath, "a.dll")),
                new ModuleInfo(Path.Combine(testPath, "b.dll")),
            };

            var discovery = new Nomad.Modules.Discovery.DirectoryModuleDiscovery(testPath, SearchOption.TopDirectoryOnly);

            Assert.That(discovery.GetModules().ToArray(), Is.EquivalentTo(expectedModules),
                        "Discovered modules differ from expected");
        }
예제 #6
0
        public void event_all_modules_loaded_is_catched_upon_every_success()
        {
            NomadKernel kernel = SetupMockedKernel();

            // subscribe kernel for event
            bool hasBeenLoaded = false;

            kernel.EventAggregator.Subscribe <NomadAllModulesLoadedMessage>((message) =>
            {
                Assert.AreNotEqual(0, message.ModuleInfos.Count());
                hasBeenLoaded = true;
            });

            //  compiling simple modules
            const string dir         = @"Modules\Kernel\SimpleAllModulesLoadedAwarenessTestModules\Simple\";
            const string fileName    = "AllModulesLoadedEventAwareModule.dll";
            const string module1Name = "SimpleModule1.dll";
            const string module2Name = "SimpleModule2.dll";
            const string keyFile     = @"newkey.xml";

            CompileSimpleModules(dir, keyFile, module1Name, module2Name);

            // compiling aware module
            var compiler = new ModuleCompiler
            {
                OutputDirectory =
                    Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                 @"Modules\Kernel\SimpleAllModulesLoadedAwarenessTestModules\Aware\")
            };

            compiler.OutputName = Path.Combine(compiler.OutputDirectory, fileName);

            string modulePath = compiler.GenerateModuleFromCode(
                @"..\Source\Nomad.Tests\FunctionalTests\Data\Kernel\AllModulesLoadedEventAwareModule.cs");

            KeysGeneratorProgram.Main(new[] { keyFile });
            compiler.GenerateManifestForModule(modulePath, keyFile);
            // set up module which subscribes for event

            // loading aware module
            IModuleDiscovery setUpDiscovery = SetUpDiscovery(new ModuleInfo(modulePath));

            Assert.DoesNotThrow(() => kernel.LoadModules(setUpDiscovery));

            // loading simple modules
            var directoryDiscovery = new DirectoryModuleDiscovery(dir, SearchOption.TopDirectoryOnly);

            Assert.DoesNotThrow(() => kernel.LoadModules(directoryDiscovery));

            //verify the method being called in a module.
            var carrier = (MessageCarrier)kernel.ModuleAppDomain.CreateInstanceAndUnwrap(
                typeof(MessageCarrier).Assembly.FullName, typeof(MessageCarrier).FullName);

            Assert.AreEqual(
                new[] { "AllModulesLoadedEventAwareModule", "AllModulesLoadedEventAwareModule" },
                carrier.List.ToArray());
            Assert.IsTrue(hasBeenLoaded);
        }
예제 #7
0
        exception_during_module_loading_is_changed_into_event_visible_from_module_and_kernel()
        {
            // set up configuration of kernel with mocks
            NomadKernel kernel = SetupMockedKernel();

            // set up listener for kernel side
            bool hasBeenCalled = false;

            kernel.EventAggregator.Subscribe <NomadAllModulesLoadedMessage>(
                (message) => hasBeenCalled = true);

            //  compile module for event aggregation
            const string dir      = @"Modules\Kernel\Event\";
            const string fileName = "EventAwareModule.dll";
            const string keyFile  = @"newkey.xml";

            var compiler = new ModuleCompiler
            {
                OutputDirectory =
                    Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dir)
            };

            compiler.OutputName = Path.Combine(compiler.OutputDirectory, fileName);

            string modulePath = compiler.GenerateModuleFromCode(
                @"..\Source\Nomad.Tests\FunctionalTests\Data\Kernel\EventAwareModule.cs");

            KeysGeneratorProgram.Main(new[] { keyFile });
            compiler.GenerateManifestForModule(modulePath, keyFile);

            // set up module which subscribes for event
            IModuleDiscovery setUpDiscovery = SetUpDiscovery(new ModuleInfo(modulePath));

            kernel.LoadModules(setUpDiscovery);

            // set up the discovery mock
            IModuleDiscovery nonExistingDiscovery =
                SetUpDiscovery(new ModuleInfo("NonExistingModule.dll"));

            // perform test
            Assert.Throws <NomadCouldNotLoadModuleException>(
                () => kernel.LoadModules(nonExistingDiscovery),
                "Exception should  be thrown in kernel domain.");

            //verify the method being called in a module.
            var carrier = (MessageCarrier)kernel.ModuleAppDomain.CreateInstanceAndUnwrap(
                typeof(MessageCarrier).Assembly.FullName, typeof(MessageCarrier).FullName);

            Assert.AreEqual(new[] { "EventAwareModule" }, carrier.List.ToArray());
            Assert.IsTrue(hasBeenCalled);
        }
예제 #8
0
        private static void CompileSimpleModules(string dir, string keyFile,
                                                 string simpleModule1Name, string simpleModule2Name)
        {
            var compiler = new ModuleCompiler
            {
                OutputDirectory =
                    Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dir)
            };

            KeysGeneratorProgram.Main(new[] { keyFile });

            // generating not subcribed modules
            compiler.OutputName = Path.Combine(compiler.OutputDirectory, simpleModule1Name);
            string module1Path =
                compiler.GenerateModuleFromCode(ModuleCompiler.DefaultSimpleModuleSource);

            compiler.GenerateManifestForModule(module1Path, keyFile);

            compiler.OutputName = Path.Combine(compiler.OutputDirectory, simpleModule2Name);
            string module2Path =
                compiler.GenerateModuleFromCode(ModuleCompiler.DefaultSimpleModuleSourceAlternative);

            compiler.GenerateManifestForModule(module2Path, keyFile);
        }