public void ServiceRegistrations_AvailableAfterSealing()
        {
            var config = new BootConfiguration();

            config.Seal();
            Assert.NotNull(config.ServiceRegistrations);
        }
        public void DoesNotContainEntryPointAssembly_WhenSuppressed()
        {
            var config = new BootConfiguration();

            config.SuppressLoadingEntryPointAssembly().Seal();
            Assert.False(config.Assemblies.Any(ass => ass.FullName.StartsWith("dotnet-test-xunit")));
        }
        public void ContainsPancakesAssembly_ByDefault()
        {
            var config = new BootConfiguration();

            config.Seal();
            Assert.Collection(config.Assemblies, item => Assert.NotNull(item), item => Assert.True(item.FullName.StartsWith("Pancakes")));
        }
Esempio n. 4
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        private void RunMicroservice()
        {
            try
            {
                LogImportant($"run > {_microserviceFolderPath}");

                var bootConfig = BootConfiguration.LoadFromFiles(_microserviceFilePath, _environmentFilePath);
                bootConfig.ConfigsDirectory = _microserviceFolderPath;

                if (_noPublish)
                {
                    MapAssemblyLocationsFromSources(bootConfig);
                }

                using (var host = new MicroserviceHost(bootConfig, new MicroserviceHostLoggerMock()))
                {
                    host.Configure();
                    host.LoadAndActivate();

                    LogSuccess("Microservice is up.");
                    LogSuccess("Press ENTER to go down.");

                    Console.ReadLine();

                    host.DeactivateAndUnload();
                }
            }
            catch (Exception ex)
            {
                ReportFatalError(ex);
            }
        }
Esempio n. 5
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public override void Execute()
        {
            File.Copy(
                Path.Combine(_sourceFolderPath, BootConfiguration.MicroserviceConfigFileName),
                Path.Combine(_publishFolderPath, BootConfiguration.MicroserviceConfigFileName),
                overwrite: true);

            File.Copy(
                _environmentFilePath,
                Path.Combine(_publishFolderPath, BootConfiguration.EnvironmentConfigFileName),
                overwrite: true);

            var bootConfig = BootConfiguration.LoadFromDirectory(_publishFolderPath);

            //TODO: the following code assumes that NWheels and the application reside in the same solution,
            //      which obviously will not be the case with real users.
            //      the full implementation of this command should bring NWheels assemblies from NuGet

            DotNetPublish(bootConfig.MicroserviceConfig.InjectionAdapter.Assembly);

            if (!_suppressPublishCli)
            {
                DotNetPublish("NWheels.Cli");
            }

            var allModules = bootConfig.MicroserviceConfig.FrameworkModules.Concat(bootConfig.MicroserviceConfig.ApplicationModules);

            foreach (var module in allModules)
            {
                DotNetPublish(module.Assembly);
            }
        }
        public void WillNotReaddAssemblies_AtSeal_WhenAlreadyAdded()
        {
            var config = new BootConfiguration();

            config.LoadAssembly(typeof(BootConfiguration).GetTypeInfo().Assembly);
            config.Seal();
            Assert.True(config.Assemblies.Count() == 2);
        }
Esempio n. 7
0
        public void CallingBoot_SetsBootConfiguration()
        {
            var kernel        = new Kernel();
            var configuration = new BootConfiguration().Seal();

            kernel.Boot(configuration);
            Assert.Equal(configuration, kernel.BootConfiguration);
        }
        public void Sealing_MarksHasBeenSealed()
        {
            var config = new BootConfiguration();

            Assert.False(config.Sealed);
            config.Seal();
            Assert.True(config.Sealed);
        }
Esempio n. 9
0
        public void AttemptingToBootNonSealedConfig_ThrowsException()
        {
            var kernel    = new Kernel();
            var config    = new BootConfiguration();
            var exception = Assert.Throws <BootException>(() => kernel.Boot(config));

            Assert.Equal(CoreErrorCodes.CannotBootNonSealedConfig, exception.ErrorCode);
        }
Esempio n. 10
0
        public void SetsVerbosity()
        {
            var config = new BootConfiguration();

            Assert.False(config.Verbose);
            config.BeVerbose();
            Assert.True(config.Verbose);
        }
Esempio n. 11
0
        public void ContainsEntryPointAssembly_ByDefault()
        {
            var config = new BootConfiguration();

            config.Seal();
            Assert.Collection(config.Assemblies,
                              item => Assert.True(item.FullName.StartsWith("dotnet-test-xunit")),
                              item => Assert.NotNull(item)); // we don't care about this item for this test.
        }
Esempio n. 12
0
        public void PostSealing_ContainsValidServiceRegistrations()
        {
            var config = new BootConfiguration();

            config.LoadAssembly(typeof(TestServiceRegistration).GetTypeInfo().Assembly);
            config.Seal();

            Assert.True(config.ServiceRegistrations.Any(sr => sr.GetType() == typeof(TestServiceRegistration)));
        }
Esempio n. 13
0
        public void IntialState()
        {
            var config = new BootConfiguration();

            Assert.NotNull(config.Assemblies);
            Assert.Null(config.SanityChecks);
            Assert.Null(config.ServiceRegistrations);
            Assert.Null(config.Commands);
        }
Esempio n. 14
0
        public void PostSealing_ContainsValidSanityChecks()
        {
            var config = new BootConfiguration();

            config.LoadAssembly(typeof(SanityCheck).GetTypeInfo().Assembly);
            config.Seal();

            Assert.True(config.SanityChecks.Any(s => s == typeof(SanityCheck)));
        }
Esempio n. 15
0
        private void TestPostBootCheckWithAcion(Action <BootConfiguration> action)
        {
            var config = new BootConfiguration();

            config.Seal();
            var exception = Assert.Throws <ErrorCodeInvalidOperationException>(() => action(config));

            Assert.Equal(CoreErrorCodes.CannotConfigurePostBoot, exception.ErrorCode);
        }
Esempio n. 16
0
        public void PostSealing_ContainsValidCommands()
        {
            var config = new BootConfiguration();

            config.LoadAssembly(typeof(TestCommand).GetTypeInfo().Assembly);
            config.Seal();

            Assert.True(config.Commands.Any(s => s == typeof(TestCommand)));
        }
Esempio n. 17
0
        public void CanSetOutput()
        {
            var written = string.Empty;
            var output  = new Action <string>(s => written = s);
            var config  = new BootConfiguration();

            config.WithOutput(output);
            config.Output("hello");
            Assert.Equal("hello", written);
        }
Esempio n. 18
0
        public void ThrowsBootException_WhenSanityCheckFails()
        {
            var kernel        = new Kernel();
            var configuration = new BootConfiguration(AssemblyCollectionMockBuilder.GetWithFailingSanityCheck());

            configuration.Seal();
            var exception = Assert.Throws <BootException>(() => kernel.Boot(configuration));

            Assert.Equal(CoreErrorCodes.InsaneKernel, exception.ErrorCode);
        }
Esempio n. 19
0
        public void CanAddAssembly()
        {
            var config = new BootConfiguration();

            var assembly = typeof(SanityCheck).GetTypeInfo().Assembly;

            config.LoadAssembly(assembly);

            Assert.Collection(config.Assemblies, item => Assert.Same(item, assembly));
        }
Esempio n. 20
0
        public void RegistersCommandsFromBootConfiguration()
        {
            var kernel        = new Kernel();
            var configuration = new BootConfiguration(AssemblyCollectionMockBuilder.GetWithEasyCommand());

            configuration.WithOutput(this.output.WriteLine);
            configuration.Seal();

            kernel.Boot(configuration);

            var registry = kernel.ServiceLocator.GetService <ICommandRegistry>();

            Assert.True(registry.IsRegistered("Test"));
        }
Esempio n. 21
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        private void MapAssemblyLocationsFromSources(BootConfiguration bootConfig)
        {
            bootConfig.AssemblyMap = new AssemblyLocationMap();

            var solutionFolderPath = Directory.GetParent(bootConfig.ConfigsDirectory).FullName;
            var allProjectNames    = Enumerable.Empty <string>()
                                     .Append(bootConfig.MicroserviceConfig.InjectionAdapter.Assembly)
                                     .Concat(bootConfig.MicroserviceConfig.FrameworkModules.Select(m => m.Assembly))
                                     .Concat(bootConfig.MicroserviceConfig.ApplicationModules.Select(m => m.Assembly));

            List <string> allProjectFilePaths = new List <string>();
            Dictionary <string, string> projectOutputAssemblyLocations   = new Dictionary <string, string>();
            Dictionary <string, string> projectTargetFrameworkByFilePath = new Dictionary <string, string>();

            foreach (var projectName in allProjectNames)
            {
                if (TryFindProjectBinaryFolder(
                        projectName,
                        solutionFolderPath,
                        out string projectFilePath,
                        out string binaryFolderPath,
                        out string outputAssemblyFilePath,
                        out string projectTargetFramework))
                {
                    allProjectFilePaths.Add(projectFilePath);
                    projectTargetFrameworkByFilePath[projectFilePath] = projectTargetFramework;

                    bootConfig.AssemblyMap.AddDirectory(binaryFolderPath);

                    if (!string.IsNullOrEmpty(outputAssemblyFilePath))
                    {
                        projectOutputAssemblyLocations[projectName] = outputAssemblyFilePath;
                    }
                }
            }

            var dependencyAssemblyLocations = MapDependencyAssemblyLocations(allProjectFilePaths, projectTargetFrameworkByFilePath);

            bootConfig.AssemblyMap.AddLocations(dependencyAssemblyLocations);
            bootConfig.AssemblyMap.AddLocations(projectOutputAssemblyLocations);
            bootConfig.AssemblyMap.AddDirectory(AppContext.BaseDirectory);
        }
        public OemMessageHandler(Device device, BootConfiguration config, ILogger logger, string appVersion)
        {
            _version      = $"OEM-Access:v{appVersion}";
            _deviceSerial = device.SerialNumber;
            _config       = config;
            _logger       = logger;
            _psk          = Convert.FromBase64String(device.SharedKey);

            // Check if certificate validation is required.
            if (config.Boot.CertificateValidation == BootEncryptionMode.EncryptionOnly)
            {
                try
                {
                    ServerCertificateCustomValidationCallback = (sender, certificate, chain, errors) => true;
                }
                catch (NotImplementedException)
                {
                    _logger.LogWarning("HttpClientHandler.ServerCertificateCustomValidationCallback is not implemented on this version of Mono");
                }
            }
        }
Esempio n. 23
0
 public MicroserviceHostBuilder(string name)
 {
     BootConfig = new BootConfiguration();
     BootConfig.MicroserviceConfig.
 }