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"); }
public void event_after_successful_module_loading_is_published() { NomadKernel kernel = SetupMockedKernel(); // subscribe for message in kernel bool hasBeenLoaded = false; kernel.EventAggregator.Subscribe<NomadAllModulesLoadedMessage>( (message) => { Assert.AreEqual(3,message.ModuleInfos.Count()); hasBeenLoaded = true; }); // compile module for event aggregation const string dir = @"Modules\Kernel\AllModulesLoadedAwarenessTestModules\"; const string awareModuleName = "AllModulesLoadedEventAwareModule.dll"; const string module1Name = "SimpleModule1.dll"; const string module2Name = "SimpleModule2.dll"; const string keyFile = @"newkey.xml"; CompileSimpleModules(dir, keyFile, module1Name, module2Name); var compiler = new ModuleCompiler { OutputDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dir) }; compiler.OutputName = Path.Combine(compiler.OutputDirectory, awareModuleName); string modulePath = compiler.GenerateModuleFromCode( @"..\Source\Nomad.Tests\FunctionalTests\Data\Kernel\AllModulesLoadedEventAwareModule.cs"); KeysGeneratorProgram.Main(new[] {keyFile}); compiler.GenerateManifestForModule(modulePath, keyFile); var directoryDiscovery = new DirectoryModuleDiscovery(dir, SearchOption.TopDirectoryOnly); // loading modules 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"}, carrier.List.ToArray()); Assert.IsTrue(hasBeenLoaded); }
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"); }
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")); }
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); }
public void 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); }
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 }); }