Example #1
0
        public static IHost CreateTestHostWithoutServer()
        {
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appSettings.json")
                                .Build();

            var palaceSection  = configuration.GetSection("Palace");
            var palaceSettings = new Palace.Configuration.PalaceSettings();

            palaceSection.Bind(palaceSettings);
            palaceSettings.Initialize();

            var builder = Host.CreateDefaultBuilder()
                          .ConfigureServices(services =>
            {
                services.AddSingleton(palaceSettings);
                services.AddTransient <Palace.Services.IStarter, Palace.Services.Starter>();
                services.AddTransient <Palace.Services.IMicroServicesOrchestrator, Palace.Services.MicroServicesOrchestrator>();
                services.AddSingleton <Palace.Services.MicroServicesCollectionManager>();

                services.AddLogging();
                services.AddMemoryCache();

                services.AddHttpClient();
                services.AddHttpClient("PalaceServer", configure =>
                {
                    configure.DefaultRequestHeaders.Add("Authorization", $"Basic {palaceSettings.ApiKey}");
                    configure.DefaultRequestHeaders.UserAgent.ParseAdd($"Palace/1.0.0.0 ({System.Environment.OSVersion}; {System.Environment.MachineName}; {palaceSettings.HostName})");
                });
            });

            var host = builder.Build();

            return(host);
        }
Example #2
0
        public static IHost CreateTestHostWithServer(Action <Palace.Configuration.PalaceSettings> config = null)
        {
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appSettings.json")
                                .Build();

            var palaceSection  = configuration.GetSection("Palace");
            var palaceSettings = new Palace.Configuration.PalaceSettings();

            palaceSection.Bind(palaceSettings);

            if (config != null)
            {
                config.Invoke(palaceSettings);
            }

            palaceSettings.Initialize();

            var builder = Host.CreateDefaultBuilder()
                          .ConfigureServices(services =>
            {
                services.AddSingleton(palaceSettings);
                services.AddTransient <Palace.Services.IStarter, Palace.Services.Starter>();
                services.AddTransient <Palace.Services.IMicroServicesOrchestrator, Palace.Services.MicroServicesOrchestrator>();
                services.AddSingleton <Palace.Services.MicroServicesCollectionManager>();

                services.AddLogging();
                services.AddMemoryCache();

                services.AddTransient <PalaceServerApplication>();
                services.AddSingleton <IHttpClientFactory, MockHttpClientFactory>();
            });

            var host = builder.Build();

            return(host);
        }