public void JsonSettingsTests()
        {
            var settings = new JsonSerializerSettings()
            {
                TypeNameHandling = TypeNameHandling.Auto
            };
            var list = new JsonPersistingList <JsonTestItem>("types", settings);

            list.Add(new JsonTestItem("A", "Value", new JsonTestContent("Content")));

            list = new JsonPersistingList <JsonTestItem>("types", settings);
            Assert.That(list[0].Id, Is.EqualTo("A"));
            Assert.That(list[0].Value, Is.EqualTo("Value"));
            Assert.That((list[0].Content as JsonTestContent).Value, Is.EqualTo("Content"));
            list.Clear();

            var list2 = new JsonPersistingList <TestItem>("types2", settings, typeof(TestItem));

            list2.Add(new JsonTestItem("B", "Value2", new JsonTestContent("Content2")));

            list2 = new JsonPersistingList <TestItem>("types2", settings, typeof(TestItem));
            Assert.That(list2[0].Id, Is.EqualTo("B"));
            Assert.That(list2[0].Value, Is.EqualTo("Value2"));
            Assert.That(((list2[0] as JsonTestItem).Content as JsonTestContent).Value, Is.EqualTo("Content2"));
            list2.Clear();
        }
        public void CRUDTests()
        {
            var collection = new JsonPersistingList <TestItem>(key)
            {
                new TestItem("A"),
                new TestItem("B"),
                new TestItem("C"),
            };

            Assert.That(CollectionString, Is.EqualTo("Aa Bb Cc"));

            collection.Add(new TestItem("D"));
            Assert.That(CollectionString, Is.EqualTo("Aa Bb Cc Dd"));

            collection.Insert(2, new TestItem("E"));
            Assert.That(CollectionString, Is.EqualTo("Aa Bb Ee Cc Dd"));

            collection.Remove("C");
            Assert.That(CollectionString, Is.EqualTo("Aa Bb Ee Dd"));

            Assert.Throws(typeof(ArgumentOutOfRangeException), () => collection.Remove("C"));

            collection.Update(new TestItem("E", "q"));
            Assert.That(CollectionString, Is.EqualTo("Aa Bb Eq Dd"));

            collection.Add(new List <TestItem> {
                new TestItem("X"), new TestItem("Y"), new TestItem("Z")
            });
            Assert.That(CollectionString, Is.EqualTo("Aa Bb Eq Dd Xx Yy Zz"));

            collection.Add(new TestItem("x"), new TestItem("y"), new TestItem("z"));
            Assert.That(CollectionString, Is.EqualTo("Aa Bb Eq Dd Xx Yy Zz xx yy zz"));

            Assert.Throws(typeof(ApplicationException), () => collection.Add(new TestItem("X", "1"), new TestItem("W", "2")));

            collection.Clear();
            Assert.That(CollectionString, Is.EqualTo(""));
        }
 protected override void ClearItems()
 {
     persistence.Clear();
     base.ClearItems();
 }