コード例 #1
0
        public void StoreMany()
        {
            var collection = new JsonDataCollection <int, TestDataStruct>(TempFilePath);

            collection.Add(
                s => s.Id,
                new List <TestDataStruct>
            {
                new TestDataStruct {
                    Id = 1, B = true, C = "Test1"
                },
                new TestDataStruct {
                    Id = 2, B = false, C = "Test2"
                }
            }
                );
            collection.Commit();

            collection.Clear();
            Assert.Empty(collection.All);
            collection.Refresh();

            Assert.Equal("Test1", collection[1].C);
            Assert.Equal("Test2", collection[2].C);
        }
コード例 #2
0
        public void StoreOne()
        {
            var collection = new JsonDataCollection <int, TestDataStruct>(TempFilePath);
            var obj        = new TestDataStruct {
                Id = 1, B = true, C = "Test"
            };

            collection[obj.Id] = obj;
            collection.Commit();

            collection.Clear();
            Assert.Empty(collection.All);
            collection.Refresh();

            Assert.Single(collection.All);
            var obj2 = collection[obj.Id];

            Assert.Equal(obj.B, obj2.B);
            Assert.Equal(obj.C, obj2.C);
        }