public void TestFetchPersistCodeOption(StorageLocationKind kind) { var value1 = new CodeStyleOption <bool> (true, NotificationOption.Suggestion); var value2 = new CodeStyleOption <bool> (false, NotificationOption.Error); TestFetchPersist(kind, value1, value2, CodeStyleOption <bool> .Default); }
void TestFetchPersist <T> (StorageLocationKind kind, T value1, T value2, T defaultValue = default(T)) { var(preferences, persister) = Setup(); bool shouldPersist = kind != StorageLocationKind.None; using (persister) { foreach (var optionKey in GetOptionKeys(kind, defaultValue)) { string propertyName = optionKey.GetPropertyName(); shouldPersist = propertyName != null; ConfigurationProperty <T> wrap = null; if (propertyName != null) { wrap = preferences.Wrap <T> (optionKey); } // Fetch, no items. AssertFetch(optionKey, optionKey.Option.DefaultValue); // Persist with no item set AssertPersist(optionKey, value1, wrap); if (!shouldPersist) { continue; } // Fetch after persist AssertFetch(optionKey, value1); // Check if setting config property persists. wrap.Value = value2; AssertFetch(optionKey, value2); // Set null. AssertPersist(optionKey, null, wrap); AssertFetch(optionKey, defaultValue); } } void AssertFetch(OptionKey optionKey, object expectedValue) { // Check that we can grab the value and it is grabbed properly Assert.AreEqual(shouldPersist, persister.TryFetch(optionKey, out var value)); Assert.AreEqual(shouldPersist ? expectedValue : null, value); } void AssertPersist(OptionKey optionKey, object value, ConfigurationProperty <T> wrap) { // Check that it either got persisted, on an option with a roaming profile // or that it got discarded Assert.AreEqual(shouldPersist, persister.TryPersist(optionKey, value)); if (shouldPersist) { Assert.AreEqual(value, wrap.Value); } } }
protected IEnumerable <OptionKey> GetOptionKeys <T> (StorageLocationKind kind = StorageLocationKind.Roaming, T defaultValue = default(T)) { yield return(GetOption(kind, defaultValue)); if (kind != StorageLocationKind.UserProfile) { yield return(new OptionKey(GetPerLanguageOption(kind, defaultValue, LanguageNames.CSharp), LanguageNames.CSharp)); } }
public void TestToPropertyNameOption(StorageLocationKind kind) { var optionKeys = GetOptionKeys <bool> (kind); foreach (var option in optionKeys) { string expected = GetExpectedPropertyName(kind, option.Language); Assert.AreEqual(expected, option.GetPropertyName()); } }
protected PerLanguageOption <T> GetPerLanguageOption <T> (StorageLocationKind kind = StorageLocationKind.Roaming, T defaultValue = default(T), string language = null) { var option = new PerLanguageOption <T> ("feature language option", "name", defaultValue, GetLocation(kind, true)); var propName = new OptionKey(option, language).GetPropertyName(); if (propName != null) { PropertyService.Set(propName, null); } return(option); }
protected Option <T> GetOption <T> (StorageLocationKind kind = StorageLocationKind.Roaming, T defaultValue = default(T)) { var option = new Option <T> ("feature option", "name", defaultValue, GetLocation(kind)); // We need a way to mock property service in tests var propName = new OptionKey(option).GetPropertyName(); if (propName != null) { PropertyService.Set(propName, null); } return(option); }
OptionStorageLocation GetLocation(StorageLocationKind kind, bool isPerLanguage = false) { switch (kind) { case StorageLocationKind.None: return(null); case StorageLocationKind.Roaming: return(new RoamingProfileStorageLocation(isPerLanguage ? featureRoamingLanguage : featureRoaming)); case StorageLocationKind.UserProfile: return(new LocalUserProfileStorageLocation(featureUserProfile)); } throw new NotImplementedException(); }
public void TestFetchPersistNamingStyle(StorageLocationKind kind) { var defaultValue = NamingStylePreferences.Default; var value1 = new NamingStylePreferences( defaultValue.SymbolSpecifications, defaultValue.NamingStyles.WhereAsArray(x => x.Prefix == "I"), defaultValue.NamingRules ); var value2 = new NamingStylePreferences( defaultValue.SymbolSpecifications, defaultValue.NamingStyles.WhereAsArray(x => x.Prefix != "I"), defaultValue.NamingRules ); TestFetchPersist(kind, value1, value2, defaultValue); }
protected string GetExpectedPropertyName(StorageLocationKind kind, string language = null) { switch (kind) { case StorageLocationKind.None: return(null); case StorageLocationKind.Roaming: if (language == null) { return(featureRoaming); } string substituteLanguageName = language == LanguageNames.CSharp ? "CSharp" : language == LanguageNames.VisualBasic ? "VisualBasic" : language; return(featureRoamingLanguage.Replace("%LANGUAGE%", substituteLanguageName)); case StorageLocationKind.UserProfile: return(featureUserProfile); } throw new NotImplementedException(); }
public void TestFetchPersistString(StorageLocationKind kind) { TestFetchPersist(kind, "a", "b"); }