public void testSavingString() { var storage = SimpleStorage.EditGroup(Guid.NewGuid().ToString()); storage.Put("test-key", "22"); Assert.That("22", Is.EqualTo(storage.Get("test-key"))); }
public void TestStoringAndLoading() { var list = new JsonPersistingList <TestItem>(key); list.Add(new TestItem("A")); Assert.True(SimpleStorage.EditGroup(key).HasKey("A")); Assert.AreEqual("{\"Id\":\"A\",\"Value\":\"a\"}", SimpleStorage.EditGroup(key).Get("A")); list = new JsonPersistingList <TestItem>(key); Assert.AreEqual(1, list.Count); Assert.AreEqual("A", list.First().Id); }
public void TestStoringAndLoading() { var list = new JsonPersistingList <IdentifiableForTesting>(editGroup); list.Add(new IdentifiableForTesting("test")); Assert.True(SimpleStorage.EditGroup(editGroup).HasKey("test")); Assert.AreEqual("{\"Id\":\"test\"}", SimpleStorage.EditGroup(editGroup).Get("test")); list = new JsonPersistingList <IdentifiableForTesting>(editGroup); Assert.AreEqual(1, list.Count); Assert.AreEqual("test", list.First().Id); }
public void StoredKeys_HasEntries_FromAllEditGroups() { var firstStorage = SimpleStorage.EditGroup("firstEditGroup"); firstStorage.Put("firstKey", "firstValue"); var secondStorage = SimpleStorage.EditGroup("secondEditGroup"); secondStorage.Put("secondKey", "secondValue"); var entries = DesktopSimpleStorage.StoredKeys; Assert.That(entries, Has.Count.EqualTo(2)); Assert.That(entries.Contains("firstEditGroup_firstKey")); Assert.That(entries.Contains("secondEditGroup_secondKey")); }
public void TestSkippingNonDeserializableEntries() { var list = new JsonPersistingList <TestItem>(key); list.Add(new TestItem("1")); list.Add(new TestItem("2")); list.Add(new TestItem("3")); var storage = SimpleStorage.EditGroup(key); storage.Put("2", "some bad data"); list = new JsonPersistingList <TestItem>(key); Assert.AreEqual(2, list.Count); Assert.AreEqual("1", list.First().Id); Assert.AreEqual("3", list.Skip(1).First().Id); }
public void TestIteratingOverListWithBrokenItems() { var list = BuildTestList(); var storage = SimpleStorage.EditGroup(editGroup); storage.Put("2", "break data with id 2"); list = new PersistentList <TestItem>(editGroup); int count = 0; foreach (var a in list) { Assert.AreEqual(a.Id, (++count + (count > 1 ? 1 : 0)).ToString()); } Assert.AreEqual(2, count); Assert.AreEqual(2, list.Count); Assert.IsFalse(storage.HasKey("2"), "The broken object should automatically be removed"); Assert.AreEqual(2, storage.Get <List <string> >("ids").Count, "The internal object index should automatically remove the broken id"); }
public PersistentList(string editGroup, Func <T, string> serialize = null, Func <string, T> deserialize = null) { try { storage = SimpleStorage.EditGroup(editGroup); ids = storage.Get <List <string> >(idListKey) ?? new List <string>(); var broken = new List <string>(); foreach (var i in ids) { T item = default(T); try { item = deserialize == null?storage.Get <T>(i) : deserialize(storage.Get(i)); } catch (Exception e) { Console.WriteLine(e.Message); } if (item == null) { broken.Add(i); continue; } items.Add(item); } if (broken.Count > 0) { foreach (var id in broken) { storage.Delete(id); ids.Remove(id); storage.Put(idListKey, ids); } } CustomSerializer = serialize; } catch (Exception e) { Console.WriteLine(e.Message); } }
public Setting(string key, string title) { Key = key; this.Title = title; storage = SimpleStorage.EditGroup("settings"); Tapped += delegate { RendererTapAction(); }; var view = new StackLayout(); view.Padding = 8; view.Spacing = 0; view.Children.Add(new Label { Text = title, Font = Font.SystemFontOfSize(NamedSize.Large), HorizontalOptions = LayoutOptions.FillAndExpand, }); Description = new Label(); view.Children.Add(Description); View = view; }
public void SetUp() { storage = SimpleStorage.EditGroup(Guid.NewGuid().ToString()); }
public PersistentStrings(string groupName) { storage = SimpleStorage.EditGroup(groupName); list = storage.Get <List <string> >(key) ?? new List <string>(); }