Example #1
0
 public async Task GetSettingsInvalidTypeShouldThrow(
     TestAspNetCoreSettingsSource source,
     SettingsServiceBuilder serviceBuilder)
 {
     var service = serviceBuilder.WithSource(source).Build();
     await Assert.ThrowsAsync <AutofacSettingsConversionException>(
         () => service.GetSettings <InvalidSettings>());
 }
        public async Task GetSettingValueExistingShouldReturnValue(
            TestAppConfigSettingsSource source,
            SettingsServiceBuilder serviceBuilder)
        {
            var service      = serviceBuilder.WithSource(source).Build();
            var settingValue = await service.GetSettingValue("Logging:Enabled", false);

            Assert.True(settingValue);
        }
        public async Task GetSettingsExistingAsObjectShouldReturnObject(
            TestAppConfigSettingsSource source,
            SettingsServiceBuilder serviceBuilder)
        {
            var service = serviceBuilder.WithSource(source).Build();
            var expectedLoggingSettings = new { Enabled = true, IncludeDetail = true };
            var loggingSettings         = await service.GetSettings(typeof(LoggingSettings));

            loggingSettings.Should().BeEquivalentTo(expectedLoggingSettings);
        }
        public async Task GetSettingValueNotExistingShouldReturnDefault(
            TestAppConfigSettingsSource source,
            SettingsServiceBuilder serviceBuilder,
            string defaultValue)
        {
            var service      = serviceBuilder.WithSource(source).Build();
            var settingValue = await service.GetSettingValue("UnexistingSetting", defaultValue);

            Assert.Equal(defaultValue, settingValue);
        }
Example #5
0
        public async Task GetSettingsEmptyStringShouldReturnEmptyString(
            TestAspNetCoreSettingsSource source,
            SettingsServiceBuilder serviceBuilder,
            string defaultValue)
        {
            var service  = serviceBuilder.WithSource(source).Build();
            var settings = await service.GetSettings <ApiSettings>();

            Assert.Equal(string.Empty, settings.Path);
        }
Example #6
0
        public async Task GetSettingNullShouldReturnDefaultSetting(
            TestAspNetCoreSettingsSource source,
            SettingsServiceBuilder serviceBuilder,
            string defaultValue)
        {
            var service = serviceBuilder.WithSource(source).Build();
            var setting = await service.GetSettingValue("Api:Foo", defaultValue);

            Assert.Equal(defaultValue, setting);
        }
        public async Task GetSettingsExistingShouldReturnPopulatedType(
            TestAppConfigSettingsSource source,
            SettingsServiceBuilder serviceBuilder)
        {
            var service = serviceBuilder.WithSource(source).Build();
            var expectedLoggingSettings = new LoggingSettings {
                Enabled = true, IncludeDetail = true
            };
            var loggingSettings = await service.GetSettings <LoggingSettings>();

            loggingSettings.Should().BeEquivalentTo(expectedLoggingSettings);
        }
        public void AutofacSettingsSourceReturnsExpectedSettings(
            TestAspNetCoreSettingsSource source,
            SettingsServiceBuilder serviceBuilder)
        {
            var service = serviceBuilder.WithSource(source).Build();

            var builder = new ContainerBuilder();

            builder.RegisterSource(
                new AutofacSettingsRegistrationSource(service));

            var container               = builder.Build();
            var loggingSettings         = container.Resolve <LoggingSettings>();
            var expectedLoggingSettings = new LoggingSettings
            {
                Enabled       = true,
                IncludeDetail = true,
            };

            loggingSettings.Should().BeEquivalentTo(expectedLoggingSettings);
        }