public void SettingGlobalSettingsSetChangeNotification() { AmbientService <IAmbientSettingsSet> pretendGlobalSettings = new AmbientService <IAmbientSettingsSet>(); string testSettingKey = nameof(SettingGlobalSettingsSetChangeNotification); string defaultValue = "defaultValue"; string overrideValue = "overrideSettingsSetValue"; Dictionary <string, string> overrides = new Dictionary <string, string>() { { testSettingKey, overrideValue } }; string notificationNewValue = ""; AmbientSetting <string> testSetting = new AmbientSetting <string>(pretendGlobalSettings, testSettingKey, "", s => { notificationNewValue = s; return(s); }, defaultValue); Assert.AreEqual(defaultValue, testSetting.Value); AmbientSettingsOverride pretendGlobalSettingsImplementation = new AmbientSettingsOverride(overrides, nameof(SettingGlobalSettingsSetChangeNotification), null, pretendGlobalSettings); pretendGlobalSettings.Global = pretendGlobalSettingsImplementation; Assert.AreEqual(overrideValue, testSetting.Value); Assert.AreEqual(overrideValue, notificationNewValue); IMutableAmbientSettingsSet globalSettingsSet = pretendGlobalSettings.Global as IMutableAmbientSettingsSet; if (globalSettingsSet != null) { string valueChangeValue = "valueChange"; globalSettingsSet.ChangeSetting(testSettingKey, valueChangeValue); Assert.AreEqual(valueChangeValue, testSetting.Value); Assert.AreEqual(valueChangeValue, notificationNewValue); } overrides = new Dictionary <string, string>() { { testSettingKey, overrideValue } }; AmbientSettingsOverride pretendGlobalSettingsSet2 = new AmbientSettingsOverride(overrides, nameof(SettingGlobalSettingsSetChangeNotification), null, pretendGlobalSettings); pretendGlobalSettings.Global = pretendGlobalSettingsSet2; Assert.AreEqual(overrideValue, testSetting.Value); overrides[testSettingKey] = null; AmbientSettingsOverride pretendGlobalSettingsSet3 = new AmbientSettingsOverride(overrides, nameof(SettingGlobalSettingsSetChangeNotification), null, pretendGlobalSettings); pretendGlobalSettings.Global = pretendGlobalSettingsSet3; Assert.AreEqual(defaultValue, testSetting.Value); }
public AmbientSettingsOverride(Dictionary <string, string> overrideSettings, string name, IAmbientSettingsSet fallback = null, AmbientService <IAmbientSettingsSet> settings = null) { _overrideRawSettings = new ConcurrentDictionary <string, string>(overrideSettings); _overrideTypedSettings = new ConcurrentDictionary <string, object>(); foreach (string key in overrideSettings.Keys) { IAmbientSettingInfo ps = SettingsRegistry.DefaultRegistry.TryGetSetting(key); if (ps != null) { _overrideTypedSettings[key] = ps.Convert(this, overrideSettings[key]); } } _name = name; _fallbackSettings = fallback ?? settings?.Local; _weakSettingRegistered = new LazyUnsubscribeWeakEventListenerProxy <AmbientSettingsOverride, object, IAmbientSettingInfo>( this, NewSettingRegistered, wvc => SettingsRegistry.DefaultRegistry.SettingRegistered -= wvc.WeakEventHandler); SettingsRegistry.DefaultRegistry.SettingRegistered += _weakSettingRegistered.WeakEventHandler; }
public void NonInterfaceType() { AmbientService <DefaultTest> defaultTest = Ambient.GetService <DefaultTest>(); DefaultTest test = defaultTest.Global; }
static SetupApplication() { AmbientService <IAmbientSettingsSet> SettingsSet = Ambient.GetService <IAmbientSettingsSet>(); SettingsSet.Global = new AppConfigAmbientSettings(); }