예제 #1
0
        public void TestConstruction()
        {
            var        obj       = new ClassWithDictionaries();
            var        container = new ModelContainer();
            IModelNode model     = container.GetOrCreateModelNode(obj, obj.GetType());

            Console.WriteLine(model.PrintHierarchy());
            foreach (var guid in container.Guids)
            {
                var node = container.GetModelNode(guid);
                if (model != node)
                {
                    Console.WriteLine(node.PrintHierarchy());
                }
            }

            Assert.That(model.GetChild("StringIntDic").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("StringIntDic").Content.Value, Is.SameAs(obj.StringIntDic));
            Assert.That(model.GetChild("StringIntDic").Content.IsReference, Is.False);
            Assert.That(model.GetChild("StringClassDic").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("StringClassDic").Content.Value, Is.SameAs(obj.StringClassDic));
            Assert.That(model.GetChild("StringClassDic").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            var enumerator = obj.StringClassDic.GetEnumerator();

            foreach (var reference in (ReferenceEnumerable)model.GetChild("StringClassDic").Content.Reference)
            {
                enumerator.MoveNext();
                var keyValuePair = enumerator.Current;
                Assert.That(reference.Index, Is.EqualTo(keyValuePair.Key));
                Assert.That(reference.ObjectValue, Is.EqualTo(keyValuePair.Value));
            }
            //Assert.That(model.GetChild("SimpleStructList").Children.Count, Is.EqualTo(0));
            //Assert.That(model.GetChild("SimpleStructList").Content.Value, Is.SameAs(obj.SimpleStructList));
            //Assert.That(model.GetChild("SimpleStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            //Assert.That(model.GetChild("NestedStructList").Children.Count, Is.EqualTo(0));
            //Assert.That(model.GetChild("NestedStructList").Content.Value, Is.SameAs(obj.NestedStructList));
            //Assert.That(model.GetChild("NestedStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            //Assert.That(model.GetChild("ListOfSimpleStructLists").Children.Count, Is.EqualTo(0));
            //Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Value, Is.SameAs(obj.ListOfSimpleStructLists));
            //Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            //foreach (var reference in (ReferenceEnumerable)model.GetChild("ListOfSimpleStructLists").Content.Reference)
            //{
            //    Assert.That(reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            //}
            //Assert.That(model.GetChild("ListOfNestedStructLists").Children.Count, Is.EqualTo(0));
            //Assert.That(model.GetChild("ListOfNestedStructLists").Content.Value, Is.SameAs(obj.ListOfNestedStructLists));
            //Assert.That(model.GetChild("ListOfNestedStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            //foreach (var reference in (ReferenceEnumerable)model.GetChild("ListOfNestedStructLists").Content.Reference)
            //{
            //    Assert.That(reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            //}

            //Assert.That(container.GetModelNode(obj.ClassList[0]), !Is.Null);
            //Assert.That(container.Guids.Count(), Is.EqualTo(10));
        }
예제 #2
0
        public void TestPrimitiveItemUpdate()
        {
            var        obj       = new ClassWithDictionaries();
            var        container = new ModelContainer();
            IModelNode model     = container.GetOrCreateModelNode(obj, obj.GetType());

            Console.WriteLine(model.PrintHierarchy());
            ((Dictionary <string, int>)model.GetChild("StringIntDic").Content.Value)["b"] = 42;
            ((Dictionary <string, int>)model.GetChild("StringIntDic").Content.Value).Add("d", 26);
            Assert.That(obj.StringIntDic.Count, Is.EqualTo(4));
            Assert.That(obj.StringIntDic["b"], Is.EqualTo(42));
            Assert.That(obj.StringIntDic["d"], Is.EqualTo(26));
        }
예제 #3
0
        public void TestConstruction()
        {
            var obj = new ClassWithDictionaries();
            var container = new ModelContainer();
            IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType());
            Console.WriteLine(model.PrintHierarchy());
            foreach (var guid in container.Guids)
            {
                var node = container.GetModelNode(guid);
                if (model != node)
                    Console.WriteLine(node.PrintHierarchy());
            }

            Assert.That(model.GetChild("StringIntDic").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("StringIntDic").Content.Value, Is.SameAs(obj.StringIntDic));
            Assert.That(model.GetChild("StringIntDic").Content.IsReference, Is.False);
            Assert.That(model.GetChild("StringClassDic").Children.Count, Is.EqualTo(0));
            Assert.That(model.GetChild("StringClassDic").Content.Value, Is.SameAs(obj.StringClassDic));
            Assert.That(model.GetChild("StringClassDic").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            var enumerator = obj.StringClassDic.GetEnumerator();
            foreach (var reference in (ReferenceEnumerable)model.GetChild("StringClassDic").Content.Reference)
            {
                enumerator.MoveNext();
                var keyValuePair = enumerator.Current;
                Assert.That(reference.Index, Is.EqualTo(keyValuePair.Key));
                Assert.That(reference.ObjectValue, Is.EqualTo(keyValuePair.Value));
            }
            //Assert.That(model.GetChild("SimpleStructList").Children.Count, Is.EqualTo(0));
            //Assert.That(model.GetChild("SimpleStructList").Content.Value, Is.SameAs(obj.SimpleStructList));
            //Assert.That(model.GetChild("SimpleStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            //Assert.That(model.GetChild("NestedStructList").Children.Count, Is.EqualTo(0));
            //Assert.That(model.GetChild("NestedStructList").Content.Value, Is.SameAs(obj.NestedStructList));
            //Assert.That(model.GetChild("NestedStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            //Assert.That(model.GetChild("ListOfSimpleStructLists").Children.Count, Is.EqualTo(0));
            //Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Value, Is.SameAs(obj.ListOfSimpleStructLists));
            //Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            //foreach (var reference in (ReferenceEnumerable)model.GetChild("ListOfSimpleStructLists").Content.Reference)
            //{
            //    Assert.That(reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            //}
            //Assert.That(model.GetChild("ListOfNestedStructLists").Children.Count, Is.EqualTo(0));
            //Assert.That(model.GetChild("ListOfNestedStructLists").Content.Value, Is.SameAs(obj.ListOfNestedStructLists));
            //Assert.That(model.GetChild("ListOfNestedStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            //foreach (var reference in (ReferenceEnumerable)model.GetChild("ListOfNestedStructLists").Content.Reference)
            //{
            //    Assert.That(reference, Is.AssignableFrom(typeof(ReferenceEnumerable)));
            //}

            //Assert.That(container.GetModelNode(obj.ClassList[0]), !Is.Null);
            //Assert.That(container.Guids.Count(), Is.EqualTo(10));
        }
예제 #4
0
        public void TestPrimitiveItemUpdate()
        {
            var        obj       = new ClassWithDictionaries();
            var        container = new ModelContainer();
            IModelNode model     = container.GetOrCreateModelNode(obj, obj.GetType());

            Helper.PrintModelContainerContent(container, model);
            ((Dictionary <string, int>)model.GetChild("StringIntDic").Content.Value)["b"] = 42;
            ((Dictionary <string, int>)model.GetChild("StringIntDic").Content.Value).Add("d", 26);
            Assert.That(obj.StringIntDic.Count, Is.EqualTo(4));
            Assert.That(obj.StringIntDic["b"], Is.EqualTo(42));
            Assert.That(obj.StringIntDic["d"], Is.EqualTo(26));
            Helper.PrintModelContainerContent(container, model);
            Helper.ConsistencyCheck(container, obj);
        }
예제 #5
0
 public void TestPrimitiveItemUpdate()
 {
     var obj = new ClassWithDictionaries();
     var container = new ModelContainer();
     IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType());
     Helper.PrintModelContainerContent(container, model);
     ((Dictionary<string, int>)model.GetChild("StringIntDic").Content.Value)["b"] = 42;
     ((Dictionary<string, int>)model.GetChild("StringIntDic").Content.Value).Add("d", 26);
     Assert.That(obj.StringIntDic.Count, Is.EqualTo(4));
     Assert.That(obj.StringIntDic["b"], Is.EqualTo(42));
     Assert.That(obj.StringIntDic["d"], Is.EqualTo(26));
     Helper.PrintModelContainerContent(container, model);
     Helper.ConsistencyCheck(container, obj);
 }
예제 #6
0
 public void TestPrimitiveItemUpdate()
 {
     var obj = new ClassWithDictionaries();
     var container = new ModelContainer();
     IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType());
     Console.WriteLine(model.PrintHierarchy());
     ((Dictionary<string, int>)model.GetChild("StringIntDic").Content.Value)["b"] = 42;
     ((Dictionary<string, int>)model.GetChild("StringIntDic").Content.Value).Add("d", 26);
     Assert.That(obj.StringIntDic.Count, Is.EqualTo(4));
     Assert.That(obj.StringIntDic["b"], Is.EqualTo(42));
     Assert.That(obj.StringIntDic["d"], Is.EqualTo(26));
 }