Beispiel #1
0
        public void TestAllObjectsParsed()
        {
            StorableNode        parent;
            List <IStorable>    storables = null, changed = null;
            List <object>       objects = new List <object> ();
            TestObject1         obj1    = CreateObject1(objects);
            ObjectChangedParser parser  = new ObjectChangedParser();

            Assert.IsTrue(parser.ParseInternal(out parent, obj1, Serializer.JsonSettings));
            Assert.IsTrue(parent.ParseTree(ref storables, ref changed));
            Assert.AreEqual(objects.Count, parser.parsedCount);
            Assert.AreEqual(0, changed.Count);
            Assert.AreEqual(57, storables.Count);
            obj1.Storable.IsChanged           = true;
            obj1.StorableList [2].IsChanged   = true;
            obj1.StorableDict ["1"].IsChanged = true;
            storables = null;
            changed   = null;
            Assert.IsTrue(parser.ParseInternal(out parent, obj1, Serializer.JsonSettings, false));
            Assert.IsTrue(parent.ParseTree(ref storables, ref changed));
            Assert.AreEqual(3, changed.Count);
            Assert.AreEqual(57, storables.Count);
            obj1.NotStorableList [1].IsChanged = true;
            storables = null;
            changed   = null;
            Assert.IsTrue(parser.ParseInternal(out parent, obj1, Serializer.JsonSettings));
            Assert.IsTrue(parent.ParseTree(ref storables, ref changed));
            Assert.AreEqual(4, changed.Count);
            Assert.AreEqual(57, storables.Count);
        }
Beispiel #2
0
        public void TestParsedAndReset()
        {
            StorableNode        parent;
            List <IStorable>    storables = null, changed = null;
            ObjectChangedParser parser = new ObjectChangedParser();
            TestObject1         obj1   = new TestObject1();

            obj1.IsChanged = true;

            Assert.IsTrue(parser.ParseInternal(out parent, obj1, Serializer.JsonSettings));
            Assert.IsTrue(parent.ParseTree(ref storables, ref changed));
            Assert.AreEqual(1, parser.parsedCount);
            Assert.AreEqual(1, changed.Count);
            Assert.AreEqual(1, storables.Count);
            Assert.IsFalse(obj1.IsChanged);

            obj1.IsChanged = true;
            storables      = null;
            changed        = null;
            Assert.IsTrue(parser.ParseInternal(out parent, obj1, Serializer.JsonSettings, false));
            Assert.IsTrue(parent.ParseTree(ref storables, ref changed));
            Assert.AreEqual(1, parser.parsedCount);
            Assert.AreEqual(1, changed.Count);
            Assert.AreEqual(1, storables.Count);
            Assert.IsTrue(obj1.IsChanged);
        }
        public void TestIsChangedResetted()
        {
            LMTeam t, t1;
            ObjectChangedParser parser;
            List <IStorable>    storables = null, changed = null;
            StorableNode        parent = null;

            parser = new ObjectChangedParser();
            t      = LMTeam.DefaultTemplate(10);
            storage.Store(t);

            // After loading an object
            t1 = DocumentsSerializer.LoadObject(typeof(LMTeam), t.ID, db) as LMTeam;
            Assert.IsTrue(parser.ParseInternal(out parent, t1, Serializer.JsonSettings));
            Assert.IsTrue(parent.ParseTree(ref storables, ref changed));
            Assert.AreEqual(0, changed.Count);
            Assert.NotNull(t1.DocumentID);

            // After filling an object
            t1            = new LMTeam();
            t1.ID         = t.ID;
            t1.DocumentID = t.ID.ToString();
            t1.IsChanged  = true;
            DocumentsSerializer.FillObject(t1, db);
            Assert.IsTrue(parser.ParseInternal(out parent, t1, Serializer.JsonSettings));
            Assert.IsTrue(parent.ParseTree(ref storables, ref changed));
            Assert.AreEqual(0, changed.Count);
        }
Beispiel #4
0
        //Check for specific LongoMatch objects
        public static void CheckSerialization <T> (T obj, bool ignoreIsChanged = false)
        {
            List <IStorable> children, changed;

            if (!ignoreIsChanged)
            {
                Assert.IsInstanceOf <IChanged> (obj);
            }
            var stream = new MemoryStream();

            Serializer.Instance.Save(obj, stream, SerializationType.Json);
            stream.Seek(0, SeekOrigin.Begin);
            var jsonString = new StreamReader(stream).ReadToEnd();

            if (debugLine)
            {
                Console.WriteLine(jsonString);
            }
            stream.Seek(0, SeekOrigin.Begin);

            var newobj = Serializer.Instance.Load <T> (stream, SerializationType.Json);

            if (!ignoreIsChanged)
            {
                ObjectChangedParser parser = new ObjectChangedParser();
                if (obj is IStorable)
                {
                    StorableNode parentNode;
                    Assert.IsTrue(parser.ParseInternal(out parentNode, newobj as IStorable, Serializer.JsonSettings));
                    Assert.IsFalse(parentNode.HasChanges());
                }
                else
                {
                    Assert.IsFalse((newobj as IChanged).IsChanged);
                }
            }

            stream = new MemoryStream();
            Serializer.Instance.Save(newobj, stream, SerializationType.Json);
            stream.Seek(0, SeekOrigin.Begin);
            var newJsonString = new StreamReader(stream).ReadToEnd();

            if (debugLine)
            {
                Console.WriteLine(newJsonString);
            }
            Assert.AreEqual(jsonString, newJsonString);
        }
Beispiel #5
0
        public void TestParsedWithDependencyCycles()
        {
            StorableNode     parent;
            List <IStorable> storables = null, changed = null;
            TestObject2      obj2 = new TestObject2();

            obj2.Storable          = new TestObject4();
            obj2.Storable.DepCycle = obj2;
            ObjectChangedParser parser = new ObjectChangedParser();

            Assert.IsTrue(parser.ParseInternal(out parent, obj2, Serializer.JsonSettings));
            Assert.IsTrue(parent.ParseTree(ref storables, ref changed));
            Assert.AreEqual(2, parser.parsedCount);
            Assert.AreEqual(0, changed.Count);
            Assert.AreEqual(2, storables.Count);
        }
Beispiel #6
0
        public void TestParsed()
        {
            StorableNode     parent;
            List <IStorable> storables = null, changed = null;
            TestObject1      obj1 = new TestObject1();

            obj1.Storable = new TestObject2();
            obj1.Ignored  = new TestObject2();
            ObjectChangedParser parser = new ObjectChangedParser();

            Assert.IsTrue(parser.ParseInternal(out parent, obj1, Serializer.JsonSettings));
            Assert.IsTrue(parent.ParseTree(ref storables, ref changed));
            Assert.AreEqual(2, parser.parsedCount);
            Assert.AreEqual(0, changed.Count);
            Assert.AreEqual(2, storables.Count);
        }
 public void TestParsedWithDependencyCycles()
 {
     StorableNode parent;
     List<IStorable> storables = null, changed = null;
     TestObject2 obj2 = new TestObject2 ();
     obj2.Storable = new TestObject4 ();
     obj2.Storable.DepCycle = obj2;
     ObjectChangedParser parser = new ObjectChangedParser ();
     Assert.IsTrue (parser.ParseInternal (out parent, obj2, Serializer.JsonSettings));
     Assert.IsTrue (parent.ParseTree (ref storables, ref changed));
     Assert.AreEqual (2, parser.parsedCount);
     Assert.AreEqual (0, changed.Count);
     Assert.AreEqual (2, storables.Count);
 }
 public void TestParsedAndResetstorables()
 {
     StorableNode parent;
     List<IStorable> storables = null, changed = null;
     ObjectChangedParser parser = new ObjectChangedParser ();
     TestObject1 obj1 = new TestObject1 ();
     obj1.Storable = new TestObject2 ();
     obj1.Ignored = new TestObject2 ();
     obj1.IsChanged = true;
     obj1.Storable.IsChanged = true;
     Assert.IsTrue (parser.ParseInternal (out parent, obj1, Serializer.JsonSettings));
     Assert.IsTrue (parent.ParseTree (ref storables, ref changed));
     Assert.AreEqual (2, parser.parsedCount);
     Assert.AreEqual (2, changed.Count);
     Assert.AreEqual (2, storables.Count);
     storables = null;
     changed = null;
     Assert.IsTrue (parser.ParseInternal (out parent, obj1, Serializer.JsonSettings));
     Assert.IsTrue (parent.ParseTree (ref storables, ref changed));
     Assert.AreEqual (2, parser.parsedCount);
     Assert.AreEqual (0, changed.Count);
     Assert.AreEqual (2, storables.Count);
 }
 public void TestAllObjectsParsed()
 {
     StorableNode parent;
     List<IStorable> storables = null, changed = null;
     List<object> objects = new List<object> ();
     TestObject1 obj1 = CreateObject1 (objects);
     ObjectChangedParser parser = new ObjectChangedParser ();
     Assert.IsTrue (parser.ParseInternal (out parent, obj1, Serializer.JsonSettings));
     Assert.IsTrue (parent.ParseTree (ref storables, ref changed));
     Assert.AreEqual (objects.Count, parser.parsedCount);
     Assert.AreEqual (0, changed.Count);
     Assert.AreEqual (57, storables.Count);
     obj1.Storable.IsChanged = true;
     obj1.StorableList [2].IsChanged = true;
     obj1.StorableDict ["1"].IsChanged = true;
     storables = null;
     changed = null;
     Assert.IsTrue (parser.ParseInternal (out parent, obj1, Serializer.JsonSettings, false));
     Assert.IsTrue (parent.ParseTree (ref storables, ref changed));
     Assert.AreEqual (3, changed.Count);
     Assert.AreEqual (57, storables.Count);
     obj1.NotStorableList [1].IsChanged = true;
     storables = null;
     changed = null;
     Assert.IsTrue (parser.ParseInternal (out parent, obj1, Serializer.JsonSettings));
     Assert.IsTrue (parent.ParseTree (ref storables, ref changed));
     Assert.AreEqual (4, changed.Count);
     Assert.AreEqual (57, storables.Count);
 }