public TenantAppConfigurationSection(IAppConfigurationRoot root, string key, string tenant) { if (string.IsNullOrEmpty(tenant)) { throw new ArgumentException("Cannot be null or empty.", nameof(tenant)); } this.root = root; this.tenant = tenant; string tenantKey, globalKey; if (tenant == key) { tenantKey = tenant; globalKey = null; } else if (key.StartsWith($"{tenant}{AppConfigurationPath.KeyDelimiter}", StringComparison.OrdinalIgnoreCase)) { tenantKey = key; globalKey = key.Substring(tenant.Length + 1); } else { tenantKey = AppConfigurationPath.Combine(tenant, key); globalKey = key; } tenantSection = root.GetSection(tenantKey); globalSection = globalKey == null ? null : root.GetSection(globalKey); Path = tenantKey; Value = tenantSection.Exists() ? tenantSection.Value : globalSection?.Value; }
public void GetSection_WithNotPresentSection_ReturnsEmptySection() { var configManager = new ConfigurationManagerFixture() .WithAppSetting("Section:Key", "Value1") .Build(); var appConfig = new AppConfiguration(configManager); IAppConfigurationSection section = appConfig.GetSection("SectionNotPresent"); bool actual = section.Exists(); Assert.That(actual, Is.False); }