コード例 #1
0
        public void ChangeTrackerWithAddedElementsRemovedOverSeveralSynchronizations()
        {
            var storage = new InMemoryStorageEngine();
            var os      = ObjectStore2.New(storage);

            var ctw = new ChangeTrackerWrapper();

            os.Roots.Entangle(ctw);

            ctw.ChangeTracker.Append(1);
            ctw.ChangeTracker.Append(2);
            ctw.ChangeTracker.Append(3);
            ctw.ChangeTracker.Prepend(0);

            os.Persist();

            os  = ObjectStore2.Load(storage);
            ctw = os.Roots.Find <ChangeTrackerWrapper>();

            ctw.ValuesFromHead().SequenceEqual(new[] { 0, 1, 2, 3 }).ShouldBeTrue();
            ctw.ValuesFromTail().SequenceEqual(new[] { 3, 2, 1, 0 }).ShouldBeTrue();

            ctw.ChangeTracker.Head.Next.Remove();

            os.Persist();

            os  = ObjectStore2.Load(storage);
            ctw = os.Roots.Find <ChangeTrackerWrapper>();

            ctw.ValuesFromHead().SequenceEqual(new[] { 0, 2, 3 }).ShouldBeTrue();
            ctw.ValuesFromTail().SequenceEqual(new[] { 3, 2, 0 }).ShouldBeTrue();
        }
コード例 #2
0
        public void AddAndRemoveNonReferencingElementsFromCList()
        {
            var storage = new InMemoryStorageEngine();
            var os      = ObjectStore2.New(storage);

            var cList = new CList <string>();

            cList.Add("hello");
            cList.Add("world");
            cList.Add("from here");

            os.Roots.Entangle(cList);
            os.Persist();

            os    = ObjectStore2.Load(storage);
            cList = os.Roots.Find <CList <string> >();
            cList.Count.ShouldBe(3);
            cList[0].ShouldBe("hello");
            cList[1].ShouldBe("world");
            cList[2].ShouldBe("from here");

            cList.Remove(0);

            os.Persist();

            os    = ObjectStore2.Load(storage);
            cList = os.Roots.Find <CList <string> >();
            cList.Count.ShouldBe(2);
            cList[0].ShouldBe("world");
            cList[1].ShouldBe("from here");
            cList.Remove(1);

            os.Persist();

            os    = ObjectStore2.Load(storage);
            cList = os.Roots.Find <CList <string> >();
            cList.Count.ShouldBe(1);
            cList[0].ShouldBe("world");
            cList.Add("hello");

            os.Persist();

            os    = ObjectStore2.Load(storage);
            cList = os.Roots.Find <CList <string> >();
            cList.Count.ShouldBe(2);
            cList[0].ShouldBe("world");
            cList[1].ShouldBe("hello");

            cList.Remove(0);
            cList.Remove(0);

            os.Persist();

            os    = ObjectStore2.Load(storage);
            cList = os.Roots.Find <CList <string> >();
            cList.Count.ShouldBe(0);
        }
コード例 #3
0
        public void AddAndRemovedEntriesFromDictionary()
        {
            var storage = new InMemoryStorageEngine();
            var os      = ObjectStore2.New(storage);
            var s       = new CSet <Person>();

            os.Roots.Entangle(s);

            var peter = new Person {
                Name = "Peter"
            };
            var ole = new Person {
                Name = "Ole", Relationship = peter
            };

            s.Add(peter);
            s.Add(ole);

            os.Persist();

            os = ObjectStore2.Load(storage);
            s  = os.Roots.Find <CSet <Person> >();

            s.Count.ShouldBe(2);
            peter = s.Single(p => p.Name == "Peter");
            ole   = s.Single(p => p.Name == "Ole");

            ole.Relationship.ShouldBe(peter);

            s.Remove(ole);
            os.Persist();

            os = ObjectStore2.Load(storage);
            s  = os.Roots.Find <CSet <Person> >();

            s.Count.ShouldBe(1);
            peter = s.Single(p => p.Name == "Peter");
            s.Add(peter);

            s.Count.ShouldBe(1);

            os.Persist();
            os = ObjectStore2.Load(storage);
            s  = os.Roots.Find <CSet <Person> >();

            s.Count.ShouldBe(1);
            peter = s.Single(p => p.Name == "Peter");
            s.Remove(peter);

            os.Persist();

            os = ObjectStore2.Load(storage);
            s  = os.Roots.Find <CSet <Person> >();
            s.Count.ShouldBe(0);
        }
コード例 #4
0
        public void AddAndRemovedEntriesFromDictionary()
        {
            var storage = new InMemoryStorageEngine();
            var os      = ObjectStore2.New(storage);
            var d       = new CDictionary <string, Person>();

            os.Roots.Entangle(d);

            d["101020"] = new Person {
                Name = "Peter"
            };
            d["311209"] = new Person {
                Name = "Ole", Relationship = d["101020"]
            };

            os.Persist();

            os = ObjectStore2.Load(storage);
            d  = os.Roots.Find <CDictionary <string, Person> >();

            d.Count.ShouldBe(2);
            d["101020"].Name.ShouldBe("Peter");
            d["101020"].Relationship.ShouldBeNull();

            d["311209"].Name.ShouldBe("Ole");
            d["311209"].Relationship.Name.ShouldBe("Peter");

            d.Remove("311209");

            os.Persist();
            os = ObjectStore2.Load(storage);
            d  = os.Roots.Find <CDictionary <string, Person> >();

            d.Count.ShouldBe(1);
            d["101020"].Name.ShouldBe("Peter");
            d["101020"].Relationship.ShouldBeNull();
            d["311209"] = d["101020"];

            os.Persist();
            os = ObjectStore2.Load(storage);
            d  = os.Roots.Find <CDictionary <string, Person> >();

            d.Count.ShouldBe(2);
            d["101020"].ShouldBe(d["311209"]);

            d.Remove("101020");
            d.Remove("311209");

            os.Persist();
            os = ObjectStore2.Load(storage);
            d  = os.Roots.Find <CDictionary <string, Person> >();

            d.Count.ShouldBe(0);
        }
コード例 #5
0
        public void EnqueueAndDequeueFromCQueue()
        {
            var storage = new InMemoryStorageEngine();
            var os      = ObjectStore2.New(storage);

            var cQueue = new CQueue <string>();

            cQueue.Enqueue("hello");
            cQueue.Enqueue("world");
            cQueue.Enqueue("from here");

            os.Roots.Entangle(cQueue);

            os.Persist();
            os     = ObjectStore2.Load(storage);
            cQueue = os.Roots.Find <CQueue <string> >();

            cQueue.Count.ShouldBe(3);

            var dequeued = cQueue.Dequeue();

            dequeued.ShouldBe("hello");

            os.Persist();


            os     = ObjectStore2.Load(storage);
            cQueue = os.Roots.Find <CQueue <string> >();

            cQueue.Count.ShouldBe(2);

            cQueue.Dequeue().ShouldBe("world");
            cQueue.Dequeue().ShouldBe("from here");

            cQueue.Enqueue("hello");

            os.Persist();

            os     = ObjectStore2.Load(storage);
            cQueue = os.Roots.Find <CQueue <string> >();

            cQueue.Count.ShouldBe(1);
            cQueue.Dequeue().ShouldBe("hello");

            os.Persist();

            os     = ObjectStore2.Load(storage);
            cQueue = os.Roots.Find <CQueue <string> >();
            cQueue.Count.ShouldBe(0);
        }
コード例 #6
0
        public void ChangeTrackerWithNoChangesCanBePersistedAndLoadedAgain()
        {
            var storage = new InMemoryStorageEngine();
            var os      = ObjectStore2.New(storage);

            var ctw = new ChangeTrackerWrapper();

            os.Roots.Entangle(ctw);

            os.Persist();

            os  = ObjectStore2.Load(storage);
            ctw = os.Roots.Find <ChangeTrackerWrapper>();

            ctw.ValuesFromHead().Count().ShouldBe(0);
            ctw.ValuesFromTail().Count().ShouldBe(0);
        }
コード例 #7
0
        public void SerializeAndDeserializeSimpleDisplayClass()
        {
            var storageEngine = new InMemoryStorageEngine();
            var os            = ObjectStore2.New(storageEngine);

            var wrapper = new Wrapper()
            {
                Text = "World"
            };
            var greeter = wrapper.Greeter("Hello");

            os.Roots.Entangle(greeter);
            os.Persist();

            os      = ObjectStore2.Load(storageEngine);
            greeter = os.Roots.Find <Func <string> >();
            greeter().ShouldBe("Hello World");
        }
コード例 #8
0
        public void AddAndRemoveElementsFromList()
        {
            var storage = new InMemoryStorageEngine();
            var os      = ObjectStore2.New(storage);
            var wrapper = new Wrapper();

            os.Roots.Entangle(wrapper);

            os.Persist();
            os      = ObjectStore2.Load(storage);
            wrapper = os.Roots.Find <Wrapper>();

            wrapper.List.Count.ShouldBe(0);

            wrapper.List.Add("hello");
            wrapper.List.Add("world");

            os.Persist();
            os      = ObjectStore2.Load(storage);
            wrapper = os.Roots.Find <Wrapper>();

            wrapper.List.Count.ShouldBe(2);
            wrapper.List[0].ShouldBe("hello");
            wrapper.List[1].ShouldBe("world");

            wrapper.List.RemoveAt(0);

            os.Persist();
            os      = ObjectStore2.Load(storage);
            wrapper = os.Roots.Find <Wrapper>();

            wrapper.List.Count.ShouldBe(1);
            wrapper.List[0].ShouldBe("world");

            wrapper.List.Clear();

            os.Persist();
            os      = ObjectStore2.Load(storage);
            wrapper = os.Roots.Find <Wrapper>();

            wrapper.List.Count.ShouldBe(0);
        }
コード例 #9
0
        public void ChangeTrackerWithNodeChangedAndRemovedBeforePersisted()
        {
            var storage = new InMemoryStorageEngine();
            var os      = ObjectStore2.New(storage);

            var ctw = new ChangeTrackerWrapper();

            os.Roots.Entangle(ctw);

            ctw.ChangeTracker.Append(1);
            ctw.ChangeTracker.Append(2);
            ctw.ChangeTracker.Head.Remove();

            os.Persist();

            os  = ObjectStore2.Load(storage);
            ctw = os.Roots.Find <ChangeTrackerWrapper>();
            ctw.ChangeTracker.Head.Value.ShouldBe(2);
            ctw.ChangeTracker.Tail.Value.ShouldBe(2);
        }
コード例 #10
0
        public void CanSerializeAndDeserializeActionWithOneParameters()
        {
            _messages = new List <string>();

            Action <string> a = Say;

            var storageEngine = new InMemoryStorageEngine();
            var os            = ObjectStore2.New(storageEngine);

            os.Roots.Entangle(a);

            os.Persist();

            os = ObjectStore2.Load(storageEngine);
            a  = os.Roots.Find <Action <string> >();
            a("hello world");

            _messages.Count.ShouldBe(1);
            _messages[0].ShouldBe("hello world");
        }
コード例 #11
0
        public void SerializeAndDeserializeExceptions()
        {
            var storageEngine = new InMemoryStorageEngine();
            var os            = ObjectStore2.New(storageEngine);

            var innerException = new InvalidCastException("cast was not possible");
            var outerException = new ArgumentException("argument was wrong", innerException);

            os.Roots.Entangle(outerException);

            os.Persist();

            os = ObjectStore2.Load(storageEngine);
            var e = os.Roots.Find <ArgumentException>();

            e.Message.ShouldBe("argument was wrong");
            var ei = (InvalidCastException)e.InnerException;

            ei.Message.ShouldBe("cast was not possible");
        }
コード例 #12
0
        public void ChangeTrackerWithSetNodeValueSurvivesPersistence()
        {
            var storage = new InMemoryStorageEngine();
            var os      = ObjectStore2.New(storage);

            var ctw = new ChangeTrackerWrapper();

            os.Roots.Entangle(ctw);

            ctw.ChangeTracker.Append(1);
            ctw.ChangeTracker.Append(2);
            os.Persist();

            os  = ObjectStore2.Load(storage);
            ctw = os.Roots.Find <ChangeTrackerWrapper>();

            ctw.ChangeTracker.Head.Value = 3;
            os.Persist();

            os  = ObjectStore2.Load(storage);
            ctw = os.Roots.Find <ChangeTrackerWrapper>();
            ctw.ValuesFromHead().SequenceEqual(new[] { 3, 2 }).ShouldBeTrue();
        }
        public void SerializeAndDeserializeTaskAndAwaitableSuccessfully()
        {
            var storage = new InMemoryStorageEngine();
            var os      = ObjectStore2.New(storage);

            var awaitable = new CAwaitable2 <string>();
            var wrapper   = new Wrapper();

            os.Roots.Entangle(awaitable);
            os.Roots.Entangle(wrapper);

            _ = wrapper.Do(awaitable);

            os.Persist();

            os        = ObjectStore2.Load(storage);
            awaitable = os.Roots.Find <CAwaitable2 <string> >();
            wrapper   = os.Roots.Find <Wrapper>();

            wrapper.State.ShouldBeNull();
            awaitable.SignalCompletion("hello world");

            wrapper.State.ShouldBe("hello world");
        }