public void Test() { var tddHandler = new TDDHandler(); const string strValue = "test"; NullValueSettings.NullValue = null; NullValueSettings.NormalValue = strValue; NullValueSettings.SecureNullValue = null; NullValueSettings.SecureNormalValue = strValue; NullValueSettings.SaveSettings(); NullValueSettings.NullValue = strValue; NullValueSettings.NormalValue = null; NullValueSettings.SecureNullValue = strValue; NullValueSettings.SecureNormalValue = null; NullValueSettings.LoadSettings(); Assert.IsTrue(strValue == NullValueSettings.NormalValue); Assert.IsNull(NullValueSettings.NullValue); Assert.IsTrue(strValue == NullValueSettings.SecureNormalValue); Assert.IsNull(NullValueSettings.SecureNullValue); tddHandler.CheckErrors(); }
public void Test() { var tddHandler = new TDDHandler(); var settings = MethodSerializerSettings.Instance; CleanUpSettingsParams(settings); MethodSerializerSettings.LoadSettings(); Compare(settings.m_SettingWasLoaded1, settings.m_SettingWasLoaded2, settings); Compare(!settings.m_SettingWasSynchronized1, !settings.m_SettingWasSynchronized2, settings); CleanUpSettingsParams(settings); MethodSerializerSettings.SaveSettings(); Compare(settings.m_SettingWasSaved1, settings.m_SettingWasSaved2, settings); Compare(settings.m_SettingWasSynchronized1, settings.m_SettingWasSynchronized2, settings); CleanUpSettingsParams(settings); MethodSerializerSettings.DeleteSettings(); Compare(settings.m_SettingWasDeleted1, settings.m_SettingWasDeleted2, settings); Compare(settings.m_SettingWasSynchronized1, settings.m_SettingWasSynchronized2, settings); tddHandler.CheckErrors(); }
public void Test() { var tddHandler = new TDDHandler(); var refSettings = new DifferentTypesLocalSettings(); var refSettingsPlugin = refSettings.GetObjectPlugin <IJSONSettingsPlugin>(); var refSettingsDSPlugin = refSettings.GetObjectPlugin <ILocalDynamicSettingsPlugin>(); for (int i = 0, iCount = 10; i < iCount; i++) { var settingName = String.Format("item{0}", i); refSettingsDSPlugin.SetSetting(settingName, i); } var refJsonSettings = refSettingsPlugin.SaveSettingsToJSON(); var loadedSettings = new DifferentTypesLocalSettings(); var loadedSettingsPlugin = loadedSettings.GetObjectPlugin <IJSONSettingsPlugin>(); loadedSettingsPlugin.LoadSettingsFromJSON(refJsonSettings); DifferentTypesTest.CompareSettings(loadedSettings, refSettings); CompareDynamicSettings(loadedSettings, refSettings); tddHandler.CheckErrors(); }
public void TestAddAndSetFunctions() { var tddHandler = new TDDHandler(); var settings1_1 = new DynamicSettings1(); var plugin1_1 = settings1_1.GetObjectPlugin <ILocalDynamicSettingsPlugin>(); var dsn = "name1"; var rand = new MyRandom(); var randStringValue = rand.NextString(10); var randDecimalValue = rand.NextDecimal(); plugin1_1.SetSetting(dsn, randStringValue); var storedStringValue = plugin1_1.GetSetting <string>(dsn); Assert.AreEqual(randStringValue, storedStringValue); plugin1_1.SetSetting(dsn, randDecimalValue); var storedDecimalValue = plugin1_1.GetSetting <Decimal>(dsn); Assert.AreEqual(randDecimalValue, storedDecimalValue); tddHandler.CheckErrors(); }
public void Test() { var tddHandler = new TDDHandler(); const String stringValue = "external string value"; const Int32 int32Value = 12345; const String stringKeyName = "v2.string"; const String intKeyName = "v2.int"; var classPrefs = new NSUserDefaults(); classPrefs.SetString(stringValue, stringKeyName); ExternalUserDefaultsClassSerializer.SetMyUserDefaults(classPrefs); var fieldPrefs = new NSUserDefaults(); fieldPrefs.SetInt(int32Value, intKeyName); ExternalUserDefaultsFieldSerializer.SetMyUserDefaults(fieldPrefs); ExternalUserDefaultsSettings.IntValue = 0; ExternalUserDefaultsSettings.StringValue = String.Empty; ExternalUserDefaultsSettings.LoadSettings(); Assert.AreEqual(ExternalUserDefaultsSettings.IntValue, int32Value); Assert.AreEqual(ExternalUserDefaultsSettings.StringValue, stringValue); tddHandler.CheckErrors(); }
public void TestCustomAndComplexObjectsAsSettings() { var tddHandler = new TDDHandler(); var settings1_1 = new DynamicSettings1(); var plugin1_1 = settings1_1.GetObjectPlugin <ILocalDynamicSettingsPlugin>(); var rand = new MyRandom(); var fooList = new List <Foo>(); for (int i = 0; i < 10; i++) { var foo = new Foo(); foo.Value = rand.NextInt32(); fooList.Add(foo); } var dsn1 = "name1"; plugin1_1.SetSetting(dsn1, fooList); plugin1_1.SaveSettings(); var settings1_2 = new DynamicSettings1(); var plugin1_2 = settings1_2.GetObjectPlugin <ILocalDynamicSettingsPlugin>(); plugin1_2.LoadSettings(); var loadedFooList = plugin1_2.GetSetting <List <Foo> >(dsn1); Assert.AreEqual(fooList, loadedFooList); tddHandler.CheckErrors(); }
public void TestContainsFunction() { var tddHandler = new TDDHandler(); var settings1_1 = new DynamicSettings1(); var plugin1_1 = settings1_1.GetObjectPlugin <ILocalDynamicSettingsPlugin>(); var dsn1 = "name1"; plugin1_1.SetSetting(dsn1, true); var dsn_contains1 = plugin1_1.Contains(dsn1); Assert.IsTrue(dsn_contains1); var dsn2 = "incorrect_name1"; var dsn_contains2 = plugin1_1.Contains(dsn2); Assert.IsFalse(dsn_contains2); plugin1_1.DeleteSetting(dsn1); var dsn_contains3 = plugin1_1.Contains(dsn1); Assert.IsFalse(dsn_contains3); tddHandler.CheckErrors(); }
public void Test() { var tddHandler = new TDDHandler(); String refString = "Test"; DateTime refDateTime = DateTime.Now; Int32 refInt32 = 10; NotLoadedValuesSettings.DeleteSettings(); NotLoadedValuesSettings.StringValue = refString; NotLoadedValuesSettings.DateTimeValue = refDateTime; NotLoadedValuesSettings.Int32Value = refInt32; NotLoadedValuesSettings.SecureStringValue = refString; NotLoadedValuesSettings.SecureDateTimeValue = refDateTime; NotLoadedValuesSettings.SecureInt32Value = refInt32; NotLoadedValuesSettings.LoadSettings(); Assert.AreEqual(refString, NotLoadedValuesSettings.StringValue); Assert.AreEqual(refDateTime, NotLoadedValuesSettings.DateTimeValue); Assert.AreEqual(refInt32, NotLoadedValuesSettings.Int32Value); Assert.AreEqual(refString, NotLoadedValuesSettings.SecureStringValue); Assert.AreEqual(refDateTime, NotLoadedValuesSettings.SecureDateTimeValue); Assert.AreEqual(refInt32, NotLoadedValuesSettings.SecureInt32Value); tddHandler.CheckErrors(); }
public void Test() { var tddHandler = new TDDHandler(); Random rand = new MyRandom(); var randInt1 = rand.NextInt32(); var randInt2 = rand.NextInt32(); var randInt3 = rand.NextInt32(); var randInt4 = rand.NextInt32(); // init values DifferentMemberTypesLocalSettings.m_staticField = randInt1; DifferentMemberTypesLocalSettings.StaticProperty = randInt2; DifferentMemberTypesLocalSettings.Instance.m_memberField = randInt3; DifferentMemberTypesLocalSettings.Instance.MemberProperty = randInt4; DifferentMemberTypesLocalSettings.SaveSettings(); // randomize values DifferentMemberTypesLocalSettings.m_staticField = rand.NextInt32(); DifferentMemberTypesLocalSettings.StaticProperty = rand.NextInt32(); DifferentMemberTypesLocalSettings.Instance.m_memberField = rand.NextInt32(); DifferentMemberTypesLocalSettings.Instance.MemberProperty = rand.NextInt32(); DifferentMemberTypesLocalSettings.LoadSettings(); // check results Assert.True(DifferentMemberTypesLocalSettings.m_staticField == randInt1); Assert.True(DifferentMemberTypesLocalSettings.StaticProperty == randInt2); Assert.True(DifferentMemberTypesLocalSettings.Instance.m_memberField == randInt3); Assert.True(DifferentMemberTypesLocalSettings.Instance.MemberProperty == randInt4); tddHandler.CheckErrors(); }
public void Test() { var tddHandler = new TDDHandler(); var settings = new DifferentTypesLocalSettings(); settings.DeleteObjectSettings(); Assert.IsFalse(settings.ContainsObjectSetting(s => s.m_Boolean)); settings.SaveObjectSettings(); Assert.IsTrue(settings.ContainsObjectSetting(s => s.m_Boolean)); Assert.IsTrue(DifferentTypesLocalSettings.ContainsObjectSetting(settings, (DifferentTypesLocalSettings s) => s.m_Boolean)); // static settings CollectionsSettings.DeleteSettings(); Assert.IsFalse(CollectionsSettings.ContainsSetting(s => CollectionsSettings.IntList)); CollectionsSettings.SaveSettings(); Assert.IsTrue(CollectionsSettings.ContainsSetting(s => CollectionsSettings.IntList)); tddHandler.CheckErrors(); }
public void SecureTest() { var tddHandler = new TDDHandler(); const string secureKey = "v2.secureFoo"; const string secureValue = "SecureFooStringValue"; ActionsTestSettings.SecureFooString = secureValue; ActionsTestSettings.SaveSettings(); string loadedSecureValue = ActionsTest.GetSecureStringValue(secureKey); Assert.AreEqual(ActionsTestSettings.SecureFooString, loadedSecureValue); Assert.AreEqual(secureValue, loadedSecureValue); ActionsTestSettings.SecureFooString = null; ActionsTestSettings.LoadSettings(); Assert.AreEqual(ActionsTestSettings.SecureFooString, secureValue); ActionsTestSettings.DeleteSettings(); string loadedNullSecureValue = ActionsTest.GetSecureStringValue(secureKey); Assert.IsNull(loadedNullSecureValue); Assert.IsNull(ActionsTestSettings.SecureFooString); tddHandler.CheckErrors(); }
public void LocalTest() { var tddHandler = new TDDHandler(); const string key = "v2.foo"; const string value = "FooStringValue"; ActionsTestSettings.LocalFooString = value; ActionsTestSettings.SaveSettings(); string loadedValue = GetLocalStringValue(key); Assert.AreEqual(loadedValue, value); ActionsTestSettings.LocalFooString = null; ActionsTestSettings.LoadSettings(); Assert.AreEqual(ActionsTestSettings.LocalFooString, value); ActionsTestSettings.DeleteSettings(); string loadedNullNSUserDefaultsValue = GetLocalStringValue(key); Assert.IsNull(loadedNullNSUserDefaultsValue); Assert.IsNull(ActionsTestSettings.LocalFooString); tddHandler.CheckErrors(); }
public void SecureTest() { var tddHandler = new TDDHandler(); Test(ref DateTimeSettings.SecureDateTime, DateTime.Now); Test(ref DateTimeSettings.SecureDateTime, DateTime.UtcNow); tddHandler.CheckErrors(); }
public void LocalTest() { var tddHandler = new TDDHandler(); var savedSettings = new DifferentTypesLocalSettings(); savedSettings.SaveObjectSettings(); var loadedSettings = new DifferentTypesLocalSettings(); loadedSettings.LoadObjectSettings(); CompareSettings(loadedSettings, savedSettings); tddHandler.CheckErrors(); }
public void TestDynamicSettingsOrder() { var tddHandler = new TDDHandler(); var settings1_1 = new DynamicSettings1(); var plugin1_1 = settings1_1.GetObjectPlugin <ILocalDynamicSettingsPlugin>(); const int settingsCount = 10; for (int i = 0; i < settingsCount; i++) { var settingName = String.Format("setting{0}", i); plugin1_1.SetSetting(settingName, i); } plugin1_1.SaveSettings(); var settings1_2 = new DynamicSettings1(); var plugin1_2 = settings1_2.GetObjectPlugin <ILocalDynamicSettingsPlugin>(); plugin1_2.LoadSettings(); int whileIndex = 0; using (var e1 = plugin1_1.GetEnumerator()) using (var e2 = plugin1_2.GetEnumerator()) { while (e1.MoveNext() && e2.MoveNext()) { // compare settings names Assert.AreEqual(e1.Current, e2.Current); var dynamicValue1_1 = plugin1_1.GetSetting <int>(e1.Current); var dynamicValue1_2 = plugin1_2.GetSetting <int>(e2.Current); // compare settings values Assert.AreEqual(dynamicValue1_1, dynamicValue1_2); whileIndex++; } } Assert.AreEqual(plugin1_1.Count, whileIndex); Assert.AreEqual(plugin1_2.Count, whileIndex); tddHandler.CheckErrors(); }
public void Test() { var tddHandler = new TDDHandler(); const string token = "cee39cf0f58b252d7add72db41ab209371bf3dd291cdae4c997ebfdd1c645472f2aa293b6221ff527d2f24d0780a4be813e8cc9f2c093097debbb213d8ecff1287685e8de2cc4200add6bb601b3e0328c9c96224e25da0fcb8cf5a16f24360ca3f0111cd4cb1535ebf8b9ab4140a6248"; Issue2Settings.UserToken = token; Issue2Settings.SaveSettings(); Issue2Settings.UserToken = null; Issue2Settings.LoadSettings(); Assert.AreEqual(token, Issue2Settings.UserToken); tddHandler.CheckErrors(); }
public void TestDefaultValues() { var tddHandler = new TDDHandler(); var settings1_1 = new DynamicSettings1(); var plugin1_1 = settings1_1.GetObjectPlugin <ILocalDynamicSettingsPlugin>(); // try to get setting with no default value const string settingName = "setting"; Assert.Throws <KeyNotFoundException>(() => { plugin1_1.GetSetting <string>(settingName); }); // set default value const string settingDefaultValue = "default value"; plugin1_1.SetDefaultSettings(new Dictionary <string, object>() { { settingName, settingDefaultValue }, }); var setting = plugin1_1.GetSetting <string>(settingName); Assert.AreEqual(settingDefaultValue, setting); // set setting value and try to get it const string settingValue = "value"; plugin1_1.SetSetting(settingName, settingValue); setting = plugin1_1.GetSetting <string>(settingName); Assert.AreEqual(settingValue, setting); plugin1_1.DeleteSetting(settingName); // reset defaults plugin1_1.SetDefaultSettings(null); Assert.Throws <KeyNotFoundException>(() => { plugin1_1.GetSetting <string>(settingName); }); tddHandler.CheckErrors(); }
public void TestRandomValues() { var tddHandler = new TDDHandler(); var settings1_1 = new DynamicSettings1(); var plugin1_1 = settings1_1.GetObjectPlugin <ILocalDynamicSettingsPlugin>(); var dsn1 = "name1"; var dsn2 = "name2"; var rand = new MyRandom(); var randValue = rand.NextDouble(); var randEnumValue = (EEnumValues)rand.Next((int)EEnumValues.Ten); plugin1_1.SetSetting(dsn1, randValue); plugin1_1.SetSetting(dsn2, randEnumValue); var storedValue1 = plugin1_1.GetSetting <double>(dsn1); Assert.AreEqual(randValue, storedValue1); var storedEnum1 = plugin1_1.GetSetting <EEnumValues>(dsn2); Assert.AreEqual(randEnumValue, storedEnum1); plugin1_1.SaveSettings(); var settings1_2 = new DynamicSettings1(); var plugin1_2 = settings1_2.GetObjectPlugin <ILocalDynamicSettingsPlugin>(); plugin1_2.LoadSettings(); var storedValue2 = plugin1_2.GetSetting <double>(dsn1); Assert.AreEqual(randValue, storedValue2); var storedEnum2 = plugin1_2.GetSetting <EEnumValues>(dsn2); Assert.AreEqual(randEnumValue, storedEnum2); tddHandler.CheckErrors(); }
public void TestInterferenceBetweenDifferentSettingsClasses() { var tddHandler = new TDDHandler(); var settings1_1 = new DynamicSettings1(); var plugin1_1 = settings1_1.GetObjectPlugin <ILocalDynamicSettingsPlugin>(); plugin1_1.SetSetting("test", 0); plugin1_1.SaveSettings(); var settings2_1 = new DynamicSettings2(); var plugin2_1 = settings2_1.GetObjectPlugin <ILocalDynamicSettingsPlugin>(); plugin2_1.LoadSettings(); Assert.IsTrue(plugin1_1.Count == 1); Assert.IsTrue(plugin2_1.Count == 0); tddHandler.CheckErrors(); }
public void TestAddAndGetFunctions() { var tddHandler = new TDDHandler(); var settings1_1 = new DynamicSettings1(); var plugin1_1 = settings1_1.GetObjectPlugin <ILocalDynamicSettingsPlugin>(); const int settingsCount = 100; const string settingNameFormat = "setting{0}"; for (int i = 0; i < settingsCount; i++) { var settingName = String.Format(settingNameFormat, i); plugin1_1.SetSetting(settingName, i); } plugin1_1.SaveSettings(); var settings1_2 = new DynamicSettings1(); var plugin1_2 = settings1_2.GetObjectPlugin <ILocalDynamicSettingsPlugin>(); plugin1_2.LoadSettings(); int index1_2 = 0; foreach (var settingName in plugin1_2) { var dynamicValue1_1 = plugin1_1.GetSetting <int>(settingName); var dynamicValue1_2 = plugin1_2.GetSetting <int>(settingName); Assert.AreEqual(dynamicValue1_1, index1_2); Assert.AreEqual(dynamicValue1_1, dynamicValue1_2); index1_2++; } Assert.AreEqual(index1_2, settingsCount); Assert.AreEqual(index1_2, plugin1_2.Count); tddHandler.CheckErrors(); }
public void DefaultValueTest() { var tddHandler = new TDDHandler(); // this local DateTime value was specified in the settings DateTime localDateTime = DateTime.ParseExact(DateTimeSettings.DefaultDateTimeLocalStringValue, "o", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind); // this UTC DateTime value was specified in the settings DateTime utcDateTime = DateTime.ParseExact(DateTimeSettings.DefaultDateTimeUtcStringValue, "o", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind); DateTimeSettings.DeleteSetting(s => DateTimeSettings.DateTimeLocalValue); DateTimeSettings.DeleteSetting(s => DateTimeSettings.DateTimeUtcValue); // after delete operation all fields has defaul values Assert.AreEqual(DateTimeKind.Local, DateTimeSettings.DateTimeLocalValue.Kind); Assert.AreEqual(localDateTime, DateTimeSettings.DateTimeLocalValue); Assert.AreEqual(DateTimeKind.Utc, DateTimeSettings.DateTimeUtcValue.Kind); Assert.AreEqual(utcDateTime, DateTimeSettings.DateTimeUtcValue); // Invalidate value DateTimeSettings.DateTimeLocalValue = new DateTime(); // Load from default value DateTimeSettings.LoadSetting(s => DateTimeSettings.DateTimeLocalValue); // Check consistency Assert.AreEqual(DateTimeKind.Local, DateTimeSettings.DateTimeLocalValue.Kind); Assert.AreEqual(localDateTime, DateTimeSettings.DateTimeLocalValue); // Invalidate value DateTimeSettings.DateTimeUtcValue = new DateTime(); // Load from default value DateTimeSettings.LoadSetting(s => DateTimeSettings.DateTimeUtcValue); // Check consistency Assert.AreEqual(DateTimeKind.Utc, DateTimeSettings.DateTimeUtcValue.Kind); Assert.AreEqual(utcDateTime, DateTimeSettings.DateTimeUtcValue); tddHandler.CheckErrors(); }
public void Test() { var tddHandler = new TDDHandler(); CustomObjectSettings.FooClassInstance = new FooClass(); CustomObjectSettings.SecureFooClassInstance = new FooClass(); Random rand = new MyRandom(); Int32 fooValue = rand.NextInt32(); Int32 secureFooValue = rand.NextInt32(); CustomObjectSettings.FooClassInstance.IntValue = fooValue; CustomObjectSettings.SecureFooClassInstance.IntValue = secureFooValue; FooEnum fooEnumValue = (FooEnum)rand.Next((Int32)FooEnum.One, (Int32)FooEnum.Ten); FooEnum secureFooEnumValue = (FooEnum)rand.Next((Int32)FooEnum.One, (Int32)FooEnum.Ten); CustomObjectSettings.FooEnumValue = fooEnumValue; CustomObjectSettings.SecureFooEnumValue = secureFooEnumValue; CustomObjectSettings.SaveSettings(); CustomObjectSettings.FooClassInstance = null; CustomObjectSettings.SecureFooClassInstance = null; CustomObjectSettings.FooEnumValue = FooEnum.Zero; CustomObjectSettings.SecureFooEnumValue = FooEnum.Zero; CustomObjectSettings.LoadSettings(); Assert.IsNotNull(CustomObjectSettings.FooClassInstance); Assert.IsTrue(typeof(FooClass) == CustomObjectSettings.FooClassInstance.GetType()); Assert.AreEqual(CustomObjectSettings.FooClassInstance.IntValue, fooValue); Assert.AreEqual(CustomObjectSettings.FooEnumValue, fooEnumValue); Assert.IsNotNull(CustomObjectSettings.SecureFooClassInstance); Assert.IsTrue(typeof(FooClass) == CustomObjectSettings.SecureFooClassInstance.GetType()); Assert.AreEqual(CustomObjectSettings.SecureFooClassInstance.IntValue, secureFooValue); Assert.AreEqual(CustomObjectSettings.SecureFooEnumValue, secureFooEnumValue); tddHandler.CheckErrors(); }
public void Test() { var logHandler = new TDDHandler(); const String stringKeyName = "v2.string"; const String intKeyName = "v2.int"; const String stringValue = "external string value"; const Int32 intValue = 12345; Context classContext = Application.Context; Context fieldContext = Application.Context; ISharedPreferences classPrefs = classContext.GetSharedPreferences("classPrefs", FileCreationMode.Private); ISharedPreferences fieldPrefs = fieldContext.GetSharedPreferences("fieldPrefs", FileCreationMode.Private); var classPrefsEditor = classPrefs.Edit(); classPrefsEditor.PutString(stringKeyName, stringValue); classPrefsEditor.Commit(); var fieldPrefsEditor = fieldPrefs.Edit(); fieldPrefsEditor.PutInt(intKeyName, intValue); fieldPrefsEditor.Commit(); ExternalSharedPreferencesClassSerializer.SetMySharedPreferences(classPrefs); ExternalSharedPreferencesFieldSerializer.SetMySharedPreferences(fieldPrefs); ExternalSharedPreferencesSettings.IntValue = 0; ExternalSharedPreferencesSettings.StringValue = String.Empty; ExternalSharedPreferencesSettings.LoadSettings(); Assert.AreEqual(ExternalSharedPreferencesSettings.IntValue, intValue); Assert.AreEqual(ExternalSharedPreferencesSettings.StringValue, stringValue); logHandler.CheckErrors(); }
public void Test() { var tddHandler = new TDDHandler(); DefaultValueSettings.DeleteSettings(); DefaultValueSettings.LoadSetting(s => DefaultValueSettings.IntValue); Assert.AreEqual(DefaultValueSettings.DefailtIntValue, DefaultValueSettings.IntValue); DefaultValueSettings.LoadSetting(s => DefaultValueSettings.EnumValue); Assert.AreEqual(DefaultValueSettings.DefailtEnumValue, DefaultValueSettings.EnumValue); DefaultValueSettings.LoadSetting(s => DefaultValueSettings.StringValue); Assert.AreEqual(DefaultValueSettings.DefailtStringValue, DefaultValueSettings.StringValue); DefaultValueSettings.LoadSetting(s => DefaultValueSettings.NullValue); Assert.IsNull(DefaultValueSettings.NullValue); DefaultValueSettings.LoadSetting(s => DefaultValueSettings.NullableValue); Assert.IsNull(DefaultValueSettings.NullableValue); const string notSetValue = "not set test"; DefaultValueSettings.ValueNotSet = notSetValue; DefaultValueSettings.LoadSetting(s => DefaultValueSettings.ValueNotSet); Assert.AreEqual(notSetValue, DefaultValueSettings.ValueNotSet); DefaultValueSettings.LoadSetting(s => DefaultValueSettings.IncorrectDefaultValueType); Assert.AreEqual(GetTypeDefaultValue(DefaultValueSettings.IncorrectDefaultValueType), DefaultValueSettings.IncorrectDefaultValueType); DefaultValueSettings.TypeDefaultValue = 123; DefaultValueSettings.LoadSetting(s => DefaultValueSettings.TypeDefaultValue); Assert.AreEqual(GetTypeDefaultValue(DefaultValueSettings.TypeDefaultValue), DefaultValueSettings.TypeDefaultValue); tddHandler.CheckErrors(); }
public void TestEnumValues() { var tddHandler = new TDDHandler(); var settings1_1 = new DynamicSettings1(); var plugin1_1 = settings1_1.GetObjectPlugin <ILocalDynamicSettingsPlugin>(); var dsn = "test"; var enumValue = EEnumValues.One; plugin1_1.SetSetting(dsn, enumValue); plugin1_1.SaveSettings(); var settings1_2 = new DynamicSettings1(); var plugin1_2 = settings1_2.GetObjectPlugin <ILocalDynamicSettingsPlugin>(); plugin1_2.LoadSettings(); var loadedEnumvalue = plugin1_2.GetSetting <EEnumValues>(dsn); Assert.AreEqual(enumValue, loadedEnumvalue); tddHandler.CheckErrors(); }
//------------------------------------------------------------------------------ void Test(String func) { var tddHandler = new TDDHandler(); { // library serializer LibrarySerializer.s_CreationCount = 0; SettingsConfiguration.Serializer = new LibrarySerializer(); Invoke(typeof(SimpleSettings), func); Assert.IsTrue(LibrarySerializer.s_CreationCount == 1); } { // class serializer over library serializer LibrarySerializer.s_CreationCount = 0; ClassSerializer.s_CreationCount = 0; Invoke(typeof(ClassSerializerSettings), func); Assert.IsTrue(LibrarySerializer.s_CreationCount == 0); Assert.IsTrue(ClassSerializer.s_CreationCount == 1); } { // field serializer over class and library serializers LibrarySerializer.s_CreationCount = 0; ClassSerializer.s_CreationCount = 0; FieldSerializer.s_CreationCount = 0; Invoke(typeof(FieldSerializerSettings), func); Assert.IsTrue(LibrarySerializer.s_CreationCount == 0); Assert.IsTrue(ClassSerializer.s_CreationCount == 0); Assert.IsTrue(FieldSerializer.s_CreationCount == 1); } { // field and class serializer over library serializer LibrarySerializer.s_CreationCount = 0; ClassSerializer.s_CreationCount = 0; FieldSerializer.s_CreationCount = 0; Invoke(typeof(CompoundSerializerSettings), func); Assert.IsTrue(LibrarySerializer.s_CreationCount == 0); Assert.IsTrue(ClassSerializer.s_CreationCount == 1); Assert.IsTrue(FieldSerializer.s_CreationCount == 1); } { // field and library serializers FieldSerializer.s_CreationCount = 0; LibrarySerializer.s_CreationCount = 0; // recreate for apropriate s_CreationCount value SettingsConfiguration.Serializer = new LibrarySerializer(); Invoke(typeof(FieldAndLibrarySerializerSettings), func); Assert.IsTrue(FieldSerializer.s_CreationCount == 1); Assert.IsTrue(LibrarySerializer.s_CreationCount == 1); } tddHandler.CheckErrors(); }
public void Test() { var tddHandler = new TDDHandler(); const Int32 iterations = 10000; InitializeCollections(iterations); for (Int32 i = 0; i < iterations; i++) { CollectionsSettings.IntList.Add(i); CollectionsSettings.Int2StringDictionary.Add(i, i.ToString()); CollectionsSettings.IntSet.Add(i); CollectionsSettings.SecureIntList.Add(i); CollectionsSettings.SecureInt2StringDictionary.Add(i, i.ToString()); CollectionsSettings.SecureIntSet.Add(i); } CollectionsSettings.SaveSettings(); // reset existing values InitializeCollections(iterations); CollectionsSettings.LoadSettings(); // Check collections size Assert.AreEqual(CollectionsSettings.IntList.Count, iterations); Assert.AreEqual(CollectionsSettings.Int2StringDictionary.Count, iterations); Assert.AreEqual(CollectionsSettings.IntSet.Count, iterations); Assert.AreEqual(CollectionsSettings.SecureIntList.Count, iterations); Assert.AreEqual(CollectionsSettings.SecureInt2StringDictionary.Count, iterations); Assert.AreEqual(CollectionsSettings.SecureIntSet.Count, iterations); for (Int32 i = 0; i < iterations; i++) { // Check list Assert.AreEqual(CollectionsSettings.IntList[i], i); // Check dictionary string strValue; CollectionsSettings.Int2StringDictionary.TryGetValue(i, out strValue); Assert.IsTrue(strValue == i.ToString()); // Check hash set Assert.IsTrue(CollectionsSettings.IntSet.Contains(i)); // Check secure list Assert.AreEqual(CollectionsSettings.SecureIntList[i], i); // Check secure dictionary string secureStrValue; CollectionsSettings.SecureInt2StringDictionary.TryGetValue(i, out secureStrValue); Assert.IsTrue(secureStrValue == i.ToString()); // Check secure hash set Assert.IsTrue(CollectionsSettings.SecureIntSet.Contains(i)); tddHandler.CheckErrors(); } }
//------------------------------------------------------------------------------ void Test(string func, TDDData.SerializerActions action) { var tddHandler = new TDDHandler(); { // library serializer SettingsConfiguration.Serializer = new LibrarySerializer(); Invoke(typeof(SimpleSettings), func); Type librarySerializerType = typeof(LibrarySerializer); var serializerTypes = new List <String>() { librarySerializerType.FullName, librarySerializerType.FullName, }; if (IsSyncAction(action)) { serializerTypes.Add(librarySerializerType.FullName); } var actions = new List <TDDData.SerializerActions>() { action, action }; if (IsSyncAction(action)) { actions.Add(TDDData.SerializerActions.Synchronize); } var securityFlags = new List <bool>() { false, true }; if (IsSyncAction(action)) { securityFlags.Add(false); } CheckSerializerTypeUsage(serializerTypes); CheckSerializerActionUsage(actions); CheckActionSecurityUsage(securityFlags); } { // class serializer over library serializer Invoke(typeof(ClassSerializerSettings), func); Type classSerializerType = typeof(ClassSerializer); var serializerTypes = new List <String>() { classSerializerType.FullName, classSerializerType.FullName, }; if (IsSyncAction(action)) { serializerTypes.Add(classSerializerType.FullName); } var actions = new List <TDDData.SerializerActions>() { action, action }; if (IsSyncAction(action)) { actions.Add(TDDData.SerializerActions.Synchronize); } var securityFlags = new List <bool>() { false, true }; if (IsSyncAction(action)) { securityFlags.Add(false); } CheckSerializerTypeUsage(serializerTypes); CheckSerializerActionUsage(actions); CheckActionSecurityUsage(securityFlags); } { // field serializer over class and library serializers Invoke(typeof(FieldSerializerSettings), func); Type fieldSerializerType = typeof(FieldSerializer); var serializerTypes = new List <String>() { fieldSerializerType.FullName, fieldSerializerType.FullName, }; if (IsSyncAction(action)) { serializerTypes.Add(fieldSerializerType.FullName); } var actions = new List <TDDData.SerializerActions>() { action, action }; if (IsSyncAction(action)) { actions.Add(TDDData.SerializerActions.Synchronize); } var securityFlags = new List <bool>() { false, true }; if (IsSyncAction(action)) { securityFlags.Add(false); } CheckSerializerTypeUsage(serializerTypes); CheckSerializerActionUsage(actions); CheckActionSecurityUsage(securityFlags); } { // field and class serializer over library serializer Invoke(typeof(CompoundSerializerSettings), func); Type fieldSerializerType = typeof(FieldSerializer); Type classSerializerType = typeof(ClassSerializer); var serializerTypes = new List <String>() { classSerializerType.FullName, classSerializerType.FullName, fieldSerializerType.FullName, fieldSerializerType.FullName, }; if (IsSyncAction(action)) { serializerTypes.Add(classSerializerType.FullName); serializerTypes.Add(fieldSerializerType.FullName); } var actions = new List <TDDData.SerializerActions>() { action, action, action, action }; if (IsSyncAction(action)) { actions.Add(TDDData.SerializerActions.Synchronize); actions.Add(TDDData.SerializerActions.Synchronize); } var securityFlags = new List <bool>() { false, true, false, true }; if (IsSyncAction(action)) { securityFlags.Add(false); securityFlags.Add(false); } CheckSerializerTypeUsage(serializerTypes); CheckSerializerActionUsage(actions); CheckActionSecurityUsage(securityFlags); } { // field and library serializers Invoke(typeof(FieldAndLibrarySerializerSettings), func); Type fieldSerializerType = typeof(FieldSerializer); Type librarySerializerType = typeof(LibrarySerializer); var serializerTypes = new List <String>() { fieldSerializerType.FullName, librarySerializerType.FullName, fieldSerializerType.FullName, librarySerializerType.FullName, }; if (IsSyncAction(action)) { serializerTypes.Add(fieldSerializerType.FullName); serializerTypes.Add(librarySerializerType.FullName); } var actions = new List <TDDData.SerializerActions>() { action, action, action, action }; if (IsSyncAction(action)) { actions.Add(TDDData.SerializerActions.Synchronize); actions.Add(TDDData.SerializerActions.Synchronize); } var securityFlags = new List <bool>() { false, false, true, true }; if (IsSyncAction(action)) { securityFlags.Add(false); securityFlags.Add(false); } CheckSerializerTypeUsage(serializerTypes); CheckSerializerActionUsage(actions); CheckActionSecurityUsage(securityFlags); } { // built in serializers SettingsConfiguration.Serializer = null; Invoke(typeof(SimpleSettings), func); var serializerTypes = new List <String>() { "Advexp.ISettingsSerializerImpl", "Advexp.ISettingsSerializerImpl", }; if (IsSyncAction(action)) { serializerTypes.Add("Advexp.ISettingsSerializerImpl"); } var actions = new List <TDDData.SerializerActions>() { action, action }; if (IsSyncAction(action)) { actions.Add(TDDData.SerializerActions.Synchronize); } var securityFlags = new List <bool>() { false, true }; if (IsSyncAction(action)) { securityFlags.Add(false); } CheckSerializerTypeUsage(serializerTypes); CheckSerializerActionUsage(actions); CheckActionSecurityUsage(securityFlags); } tddHandler.CheckErrors(); }
public void TestDynamicSettingsCustomOrder() { var tddHandler = new TDDHandler(); //============================== var settings1_1 = new DynamicSettings1(); var plugin1_1 = settings1_1.GetObjectPlugin <ILocalDynamicSettingsPlugin>(); const int settingsCount = 50; const string settingNameFormat = "setting{0}"; var settingsOrder = new List <string>(); for (int i = 0; i < settingsCount; i++) { var settingName = String.Format(settingNameFormat, i); plugin1_1.SetSetting(settingName, i); settingsOrder.Add(settingName); } plugin1_1.SaveSettings(); var settings1_2 = new DynamicSettings1(); var plugin1_2 = settings1_2.GetObjectPlugin <ILocalDynamicSettingsPlugin>(); plugin1_2.LoadSettings(); // set custom filter settingsOrder.Shuffle(); plugin1_2.SetSettingsOrder(settingsOrder); int index = 0; foreach (var ds in plugin1_2) { Assert.AreEqual(settingsOrder[index], ds); index++; } //============================== // save and restore settings in the new instance // check settings custom order settingsOrder.Shuffle(); plugin1_2.SetSettingsOrder(settingsOrder); plugin1_2.SaveSettings(); var settings1_3 = new DynamicSettings1(); var plugin1_3 = settings1_3.GetObjectPlugin <ILocalDynamicSettingsPlugin>(); plugin1_3.LoadSettings(); // compare with custom order CompareDynamicSettings(plugin1_2, plugin1_3); plugin1_2.SetSettingsOrder(null); plugin1_3.SetSettingsOrder(null); // compare with default order CompareDynamicSettings(plugin1_2, plugin1_3); //============================== // set empty custom filter plugin1_2.SetSettingsOrder(new List <string>()); Assert.AreEqual(0, plugin1_2.Count); //============================== // reset custom filter plugin1_2.SetSettingsOrder(null); index = 0; foreach (var ds in plugin1_2) { Assert.AreEqual(String.Format(settingNameFormat, index), ds); index++; } //============================== // add new dynamic setting when custom filter was set const string newDynamicSettingName = "new"; plugin1_2.SetSettingsOrder(settingsOrder); plugin1_2.SetSetting(newDynamicSettingName, 1); index = 0; foreach (var ds in plugin1_2) { if (index < settingsOrder.Count) { Assert.AreEqual(settingsOrder[index], ds); index++; } else { Assert.AreEqual(newDynamicSettingName, ds); } } //============================== // delete existing dynamic setting when custom filter was set var rng = new MyRandom(); var randomTargetIndex = rng.Next(settingsCount); var targetSettingName = String.Format(settingNameFormat, randomTargetIndex); plugin1_2.SetSettingsOrder(settingsOrder); var preCount = plugin1_2.Count; plugin1_2.DeleteSetting(targetSettingName); settingsOrder.Remove(targetSettingName); Assert.AreEqual(preCount - 1, plugin1_2.Count); Assert.AreEqual(settingsOrder.Count, plugin1_2.Count); index = 0; foreach (var ds in plugin1_2) { Assert.AreEqual(settingsOrder[index], ds); index++; } tddHandler.CheckErrors(); }