Ejemplo n.º 1
0
        private static IHostBuilder CreateHostBuilder() => new HostBuilder()
        .ConfigureAppConfiguration(
            (_, config) =>
        {
            config.AddJsonFile("appsettings.json", false, false);
            config.AddEnvironmentVariables(prefix: "EDR_");
        }
            )
        .ConfigureServices(
            (context, services) =>
        {
            var fs = new FileSystem();

            services.AddSingleton <IFileSystem>(fs);

            services.AddConnectorManager(context.Configuration);

            services.AddSingleton <ConnectorCommand>();
            services.AddSingleton <RunCommand>();
            services.AddSingleton <StepsCommand>();
            services.AddSingleton <ValidateCommand>();
            services.AddSingleton <EDRMethods>();

            var sclSettings = SCLSettings.CreateFromIConfiguration(context.Configuration);

            services.AddSingleton(sclSettings);
        }
            )
        .ConfigureLogging(
            (context, logging) =>
        {
            logging.ClearProviders();
            logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);

            var nlogConfig =
                new NLogLoggingConfiguration(context.Configuration.GetSection("nlog"));

            LogManager.Configuration = nlogConfig;
            logging.AddNLog(nlogConfig);
        }
            );
Ejemplo n.º 2
0
        public void TestCreateFromIConfiguration()
        {
            var myConfiguration = new Dictionary <string, string>
            {
                { "Key1", "Value1" },
                { "Nested:Key1", "NestedValue1" },
                { "Nested:Key2:0", "alpha" },
                { "Nested:Key2:1", "beta" },
                { "Nested:Key2:2", "gamma" },
            };

            IConfiguration configuration = new ConfigurationBuilder()
                                           .AddInMemoryCollection(myConfiguration)
                                           .Build();

            var settings = SCLSettings.CreateFromIConfiguration(configuration);

            var key1 = settings.Entity.TryGetValue("Key1");

            key1.ShouldHaveValue();

            key1.Value.GetPrimitiveString().Should().Be("Value1");

            var nestedKey1 = settings.Entity.TryGetValue(new EntityPropertyKey("Nested.Key1"));

            nestedKey1.ShouldHaveValue();

            nestedKey1.Value.GetPrimitiveString().Should().Be("NestedValue1");

            var nestedKey2 = settings.Entity.TryGetValue(new EntityPropertyKey("Nested.Key2"));

            nestedKey2.ShouldHaveValue();

            nestedKey2.Value.Should().BeOfType <EntityValue.NestedList>("Value should be a list");

            (nestedKey2.Value as EntityValue.NestedList) !.Value.Select(x => x.GetPrimitiveString())
            .Should()
            .BeEquivalentTo(new object[] { "alpha", "beta", "gamma" });
        }