public void StoreAll_Test() { var prefs = new TestDataClassPlayerPrefs(); SetAllTestDataDifferentValues(); SetPrefsDataValues(prefs); Assert.AreNotEqual(TestData[TestDataClassMember.IntProperty].Value, TestData[TestDataClassMember.IntProperty].Get()); Assert.AreNotEqual(TestData[TestDataClassMember.FloatProperty].Value, TestData[TestDataClassMember.FloatProperty].Get()); Assert.AreNotEqual(TestData[TestDataClassMember.StringProperty].Value, TestData[TestDataClassMember.StringProperty].Get()); Assert.AreNotEqual(TestData[TestDataClassMember.BoolProperty].Value, TestData[TestDataClassMember.BoolProperty].Get()); Assert.AreNotEqual(TestData[TestDataClassMember.IntField].Value, TestData[TestDataClassMember.IntField].Get()); Assert.AreNotEqual(TestData[TestDataClassMember.FloatField].Value, TestData[TestDataClassMember.FloatField].Get()); Assert.AreNotEqual(TestData[TestDataClassMember.StringField].Value, TestData[TestDataClassMember.StringField].Get()); Assert.AreNotEqual(TestData[TestDataClassMember.BoolField].Value, TestData[TestDataClassMember.BoolField].Get()); prefs.StoreAll(); Assert.AreEqual(TestData[TestDataClassMember.IntProperty].Value, TestData[TestDataClassMember.IntProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.FloatProperty].Value, TestData[TestDataClassMember.FloatProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.StringProperty].Value, TestData[TestDataClassMember.StringProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.BoolProperty].Value, TestData[TestDataClassMember.BoolProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.IntField].Value, TestData[TestDataClassMember.IntField].Get()); Assert.AreEqual(TestData[TestDataClassMember.FloatField].Value, TestData[TestDataClassMember.FloatField].Get()); Assert.AreEqual(TestData[TestDataClassMember.StringField].Value, TestData[TestDataClassMember.StringField].Get()); Assert.AreEqual(TestData[TestDataClassMember.BoolField].Value, TestData[TestDataClassMember.BoolField].Get()); }
public void LoadAll_Test() { var prefs = new TestDataClassPlayerPrefs(); SetAllTestDataValues(); SetPrefsDataDifferentValues(prefs); Assert.AreNotEqual(TestData[TestDataClassMember.IntProperty].Value, prefs.Data.IntProperty); Assert.AreNotEqual(TestData[TestDataClassMember.FloatProperty].Value, prefs.Data.FloatProperty); Assert.AreNotEqual(TestData[TestDataClassMember.StringProperty].Value, prefs.Data.StringProperty); Assert.AreNotEqual(TestData[TestDataClassMember.BoolProperty].Value, prefs.Data.BoolProperty ? 1 : 0); Assert.AreNotEqual(TestData[TestDataClassMember.IntField].Value, prefs.Data.IntField); Assert.AreNotEqual(TestData[TestDataClassMember.FloatField].Value, prefs.Data.FloatField); Assert.AreNotEqual(TestData[TestDataClassMember.StringField].Value, prefs.Data.StringField); Assert.AreNotEqual(TestData[TestDataClassMember.BoolField].Value, prefs.Data.BoolField ? 1 : 0); prefs.LoadAll(); Assert.AreEqual(TestData[TestDataClassMember.IntProperty].Value, prefs.Data.IntProperty); Assert.AreEqual(TestData[TestDataClassMember.FloatProperty].Value, prefs.Data.FloatProperty); Assert.AreEqual(TestData[TestDataClassMember.StringProperty].Value, prefs.Data.StringProperty); Assert.AreEqual(TestData[TestDataClassMember.BoolProperty].Value, prefs.Data.BoolProperty ? 1 : 0); Assert.AreEqual(TestData[TestDataClassMember.IntField].Value, prefs.Data.IntField); Assert.AreEqual(TestData[TestDataClassMember.FloatField].Value, prefs.Data.FloatField); Assert.AreEqual(TestData[TestDataClassMember.StringField].Value, prefs.Data.StringField); Assert.AreEqual(TestData[TestDataClassMember.BoolField].Value, prefs.Data.BoolField ? 1 : 0); }
public void DefaultValue_Test() { Assert.AreEqual(999, TestDataClassPlayerPrefs.Get(x => x.IntProperty)); Assert.AreEqual(999.0f, TestDataClassPlayerPrefs.Get(x => x.FloatProperty)); Assert.AreEqual(nameof(TestDataClass.StringProperty), TestDataClassPlayerPrefs.Get(x => x.StringProperty)); Assert.AreEqual(true, TestDataClassPlayerPrefs.Get(x => x.BoolProperty)); Assert.AreEqual(-999, TestDataClassPlayerPrefs.Get(x => x.IntField)); Assert.AreEqual(-999.0f, TestDataClassPlayerPrefs.Get(x => x.FloatField)); Assert.AreEqual(true, TestDataClassPlayerPrefs.Get(x => x.BoolField)); }
private void SetPrefsDataValues(TestDataClassPlayerPrefs prefs) { prefs.Data.IntProperty = (int)TestData[TestDataClassMember.IntProperty].Value; prefs.Data.FloatProperty = (float)TestData[TestDataClassMember.FloatProperty].Value; prefs.Data.StringProperty = (string)TestData[TestDataClassMember.StringProperty].Value; prefs.Data.BoolProperty = (int)TestData[TestDataClassMember.BoolProperty].Value != 0; prefs.Data.IntField = (int)TestData[TestDataClassMember.IntField].Value; prefs.Data.FloatField = (float)TestData[TestDataClassMember.FloatField].Value; prefs.Data.StringField = (string)TestData[TestDataClassMember.StringField].Value; prefs.Data.BoolField = (int)TestData[TestDataClassMember.BoolField].Value != 0; }
public void Get_Test() { SetAllTestDataValues(); Assert.AreEqual(TestData[TestDataClassMember.IntProperty].Value, TestDataClassPlayerPrefs.Get(x => x.IntProperty)); Assert.AreEqual(TestData[TestDataClassMember.FloatProperty].Value, TestDataClassPlayerPrefs.Get(x => x.FloatProperty)); Assert.AreEqual(TestData[TestDataClassMember.StringProperty].Value, TestDataClassPlayerPrefs.Get(x => x.StringProperty)); Assert.AreEqual(TestData[TestDataClassMember.BoolProperty].Value, TestDataClassPlayerPrefs.Get(x => x.BoolProperty) ? 1 : 0); Assert.AreEqual(TestData[TestDataClassMember.IntField].Value, TestDataClassPlayerPrefs.Get(x => x.IntField)); Assert.AreEqual(TestData[TestDataClassMember.FloatField].Value, TestDataClassPlayerPrefs.Get(x => x.FloatField)); Assert.AreEqual(TestData[TestDataClassMember.StringField].Value, TestDataClassPlayerPrefs.Get(x => x.StringField)); Assert.AreEqual(TestData[TestDataClassMember.BoolField].Value, TestDataClassPlayerPrefs.Get(x => x.BoolField) ? 1 : 0); }
public void Set_Test() { TestDataClassPlayerPrefs.Set(x => x.IntProperty, TestData[TestDataClassMember.IntProperty].Value); TestDataClassPlayerPrefs.Set(x => x.FloatProperty, TestData[TestDataClassMember.FloatProperty].Value); TestDataClassPlayerPrefs.Set(x => x.StringProperty, TestData[TestDataClassMember.StringProperty].Value); TestDataClassPlayerPrefs.Set(x => x.BoolProperty, (int)TestData[TestDataClassMember.BoolProperty].Value != 0); TestDataClassPlayerPrefs.Set(x => x.IntField, TestData[TestDataClassMember.IntField].Value); TestDataClassPlayerPrefs.Set(x => x.FloatField, TestData[TestDataClassMember.FloatField].Value); TestDataClassPlayerPrefs.Set(x => x.StringField, TestData[TestDataClassMember.StringField].Value); TestDataClassPlayerPrefs.Set(x => x.BoolField, (int)TestData[TestDataClassMember.BoolProperty].Value != 0); Assert.AreEqual(TestData[TestDataClassMember.IntProperty].Value, TestData[TestDataClassMember.IntProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.FloatProperty].Value, TestData[TestDataClassMember.FloatProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.StringProperty].Value, TestData[TestDataClassMember.StringProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.BoolProperty].Value, TestData[TestDataClassMember.BoolProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.IntField].Value, TestData[TestDataClassMember.IntField].Get()); Assert.AreEqual(TestData[TestDataClassMember.FloatField].Value, TestData[TestDataClassMember.FloatField].Get()); Assert.AreEqual(TestData[TestDataClassMember.StringField].Value, TestData[TestDataClassMember.StringField].Get()); Assert.AreEqual(TestData[TestDataClassMember.BoolField].Value, TestData[TestDataClassMember.BoolField].Get()); }
public void DeleteAll_Test() { string nonDeletedPrefsKey = nameof(nonDeletedPrefsKey); string nonDeletedPrefsValue = Guid.NewGuid().ToString(); PlayerPrefs.SetString(nonDeletedPrefsKey, nonDeletedPrefsValue); SetAllTestDataValues(); Assert.AreEqual(TestData[TestDataClassMember.IntProperty].Value, TestData[TestDataClassMember.IntProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.FloatProperty].Value, TestData[TestDataClassMember.FloatProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.StringProperty].Value, TestData[TestDataClassMember.StringProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.BoolProperty].Value, TestData[TestDataClassMember.BoolProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.IntField].Value, TestData[TestDataClassMember.IntField].Get()); Assert.AreEqual(TestData[TestDataClassMember.FloatField].Value, TestData[TestDataClassMember.FloatField].Get()); Assert.AreEqual(TestData[TestDataClassMember.StringField].Value, TestData[TestDataClassMember.StringField].Get()); Assert.AreEqual(TestData[TestDataClassMember.BoolField].Value, TestData[TestDataClassMember.BoolField].Get()); Assert.AreEqual(nonDeletedPrefsValue, PlayerPrefs.GetString(nonDeletedPrefsKey, null)); TestDataClassPlayerPrefs.DeleteAll(); DefaultValue_Test(); Assert.AreEqual(nonDeletedPrefsValue, PlayerPrefs.GetString(nonDeletedPrefsKey, null)); }
public void Delete_Test() { SetAllTestDataValues(); TestDataClassPlayerPrefs.Delete(x => x.IntProperty); Assert.AreNotEqual(TestData[TestDataClassMember.IntProperty].Value, TestData[TestDataClassMember.IntProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.FloatProperty].Value, TestData[TestDataClassMember.FloatProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.StringProperty].Value, TestData[TestDataClassMember.StringProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.BoolProperty].Value, TestData[TestDataClassMember.BoolProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.IntField].Value, TestData[TestDataClassMember.IntField].Get()); Assert.AreEqual(TestData[TestDataClassMember.FloatField].Value, TestData[TestDataClassMember.FloatField].Get()); Assert.AreEqual(TestData[TestDataClassMember.StringField].Value, TestData[TestDataClassMember.StringField].Get()); Assert.AreEqual(TestData[TestDataClassMember.BoolField].Value, TestData[TestDataClassMember.BoolField].Get()); SetAllTestDataValues(); TestDataClassPlayerPrefs.Delete(x => x.FloatProperty); Assert.AreEqual(TestData[TestDataClassMember.IntProperty].Value, TestData[TestDataClassMember.IntProperty].Get()); Assert.AreNotEqual(TestData[TestDataClassMember.FloatProperty].Value, TestData[TestDataClassMember.FloatProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.StringProperty].Value, TestData[TestDataClassMember.StringProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.BoolProperty].Value, TestData[TestDataClassMember.BoolProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.IntField].Value, TestData[TestDataClassMember.IntField].Get()); Assert.AreEqual(TestData[TestDataClassMember.FloatField].Value, TestData[TestDataClassMember.FloatField].Get()); Assert.AreEqual(TestData[TestDataClassMember.StringField].Value, TestData[TestDataClassMember.StringField].Get()); Assert.AreEqual(TestData[TestDataClassMember.BoolField].Value, TestData[TestDataClassMember.BoolField].Get()); SetAllTestDataValues(); TestDataClassPlayerPrefs.Delete(x => x.StringProperty); Assert.AreEqual(TestData[TestDataClassMember.IntProperty].Value, TestData[TestDataClassMember.IntProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.FloatProperty].Value, TestData[TestDataClassMember.FloatProperty].Get()); Assert.AreNotEqual(TestData[TestDataClassMember.StringProperty].Value, TestData[TestDataClassMember.StringProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.BoolProperty].Value, TestData[TestDataClassMember.BoolProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.IntField].Value, TestData[TestDataClassMember.IntField].Get()); Assert.AreEqual(TestData[TestDataClassMember.FloatField].Value, TestData[TestDataClassMember.FloatField].Get()); Assert.AreEqual(TestData[TestDataClassMember.StringField].Value, TestData[TestDataClassMember.StringField].Get()); Assert.AreEqual(TestData[TestDataClassMember.BoolField].Value, TestData[TestDataClassMember.BoolField].Get()); SetAllTestDataValues(); TestDataClassPlayerPrefs.Delete(x => x.BoolProperty); Assert.AreEqual(TestData[TestDataClassMember.IntProperty].Value, TestData[TestDataClassMember.IntProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.FloatProperty].Value, TestData[TestDataClassMember.FloatProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.StringProperty].Value, TestData[TestDataClassMember.StringProperty].Get()); Assert.AreNotEqual(TestData[TestDataClassMember.BoolProperty].Value, TestData[TestDataClassMember.BoolProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.IntField].Value, TestData[TestDataClassMember.IntField].Get()); Assert.AreEqual(TestData[TestDataClassMember.FloatField].Value, TestData[TestDataClassMember.FloatField].Get()); Assert.AreEqual(TestData[TestDataClassMember.StringField].Value, TestData[TestDataClassMember.StringField].Get()); Assert.AreEqual(TestData[TestDataClassMember.BoolField].Value, TestData[TestDataClassMember.BoolField].Get()); SetAllTestDataValues(); TestDataClassPlayerPrefs.Delete(x => x.IntField); Assert.AreEqual(TestData[TestDataClassMember.IntProperty].Value, TestData[TestDataClassMember.IntProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.FloatProperty].Value, TestData[TestDataClassMember.FloatProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.StringProperty].Value, TestData[TestDataClassMember.StringProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.BoolProperty].Value, TestData[TestDataClassMember.BoolProperty].Get()); Assert.AreNotEqual(TestData[TestDataClassMember.IntField].Value, TestData[TestDataClassMember.IntField].Get()); Assert.AreEqual(TestData[TestDataClassMember.FloatField].Value, TestData[TestDataClassMember.FloatField].Get()); Assert.AreEqual(TestData[TestDataClassMember.StringField].Value, TestData[TestDataClassMember.StringField].Get()); Assert.AreEqual(TestData[TestDataClassMember.BoolField].Value, TestData[TestDataClassMember.BoolField].Get()); SetAllTestDataValues(); TestDataClassPlayerPrefs.Delete(x => x.FloatField); Assert.AreEqual(TestData[TestDataClassMember.IntProperty].Value, TestData[TestDataClassMember.IntProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.FloatProperty].Value, TestData[TestDataClassMember.FloatProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.StringProperty].Value, TestData[TestDataClassMember.StringProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.BoolProperty].Value, TestData[TestDataClassMember.BoolProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.IntField].Value, TestData[TestDataClassMember.IntField].Get()); Assert.AreNotEqual(TestData[TestDataClassMember.FloatField].Value, TestData[TestDataClassMember.FloatField].Get()); Assert.AreEqual(TestData[TestDataClassMember.StringField].Value, TestData[TestDataClassMember.StringField].Get()); Assert.AreEqual(TestData[TestDataClassMember.BoolField].Value, TestData[TestDataClassMember.BoolField].Get()); SetAllTestDataValues(); TestDataClassPlayerPrefs.Delete(x => x.StringField); Assert.AreEqual(TestData[TestDataClassMember.IntProperty].Value, TestData[TestDataClassMember.IntProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.FloatProperty].Value, TestData[TestDataClassMember.FloatProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.StringProperty].Value, TestData[TestDataClassMember.StringProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.BoolProperty].Value, TestData[TestDataClassMember.BoolProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.IntField].Value, TestData[TestDataClassMember.IntField].Get()); Assert.AreEqual(TestData[TestDataClassMember.FloatField].Value, TestData[TestDataClassMember.FloatField].Get()); Assert.AreNotEqual(TestData[TestDataClassMember.StringField].Value, TestData[TestDataClassMember.StringField].Get()); Assert.AreEqual(TestData[TestDataClassMember.BoolField].Value, TestData[TestDataClassMember.BoolField].Get()); SetAllTestDataValues(); TestDataClassPlayerPrefs.Delete(x => x.BoolField); Assert.AreEqual(TestData[TestDataClassMember.IntProperty].Value, TestData[TestDataClassMember.IntProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.FloatProperty].Value, TestData[TestDataClassMember.FloatProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.StringProperty].Value, TestData[TestDataClassMember.StringProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.BoolProperty].Value, TestData[TestDataClassMember.BoolProperty].Get()); Assert.AreEqual(TestData[TestDataClassMember.IntField].Value, TestData[TestDataClassMember.IntField].Get()); Assert.AreEqual(TestData[TestDataClassMember.FloatField].Value, TestData[TestDataClassMember.FloatField].Get()); Assert.AreEqual(TestData[TestDataClassMember.StringField].Value, TestData[TestDataClassMember.StringField].Get()); Assert.AreNotEqual(TestData[TestDataClassMember.BoolField].Value, TestData[TestDataClassMember.BoolField].Get()); }