Exemplo n.º 1
0
        public void Bind_Tries_To_Bind_Only_Property()
        {
            var instance = new SimpleObject();
            A.CallTo(() => resolveDependencies.Resolve(typeof (SimpleObject))).Returns(instance);

            modelBinder.Bind(typeof (SimpleObject), bindingContext);

            A.CallTo(() => propertyBinder.Bind(instance, instance.GetType().GetProperty("Test"), bindingContext)).MustHaveHappened(Repeated.Exactly.Once);
        }
Exemplo n.º 2
0
        public void Bind_Returns_Null_When_No_Property_Is_Bound()
        {
            var instance = new SimpleObject();
            A.CallTo(() => resolveDependencies.Resolve(typeof(SimpleObject))).Returns(instance);
            A.CallTo(() => propertyBinder.Bind(instance, instance.GetType().GetProperty("Test"), bindingContext)).Returns(false);

            var result = modelBinder.Bind(typeof (SimpleObject), bindingContext);

            Assert.IsNull(result);
        }
        public void TestSimpleUpdate()
        {
            var so = new SimpleObject {
                ValueOne = 1, ValueTwo = 2
            };
            var clone = (SimpleObject)CopyUtils.CloneObjectTest(so);

            clone.ValueTwo = 3;

            Assert.AreNotSame(so, clone);
            Assert.AreSame(so.GetType(), clone.GetType());
            Assert.AreEqual(so.ValueOne, clone.ValueOne);
            Assert.AreNotEqual(so.ValueTwo, clone.ValueTwo);

            CopyUtils.UpdateFromClone(so, clone);

            Assert.AreNotSame(so, clone);
            Assert.AreSame(so.GetType(), clone.GetType());
            Assert.AreEqual(so.ValueOne, clone.ValueOne);
            Assert.AreEqual(so.ValueTwo, clone.ValueTwo);
        }
Exemplo n.º 4
0
    public static void CheckReadableModelIncludesInstances()
    {
        var model = new SimpleObject {
            a      = 1,
            b      = 2,
            nested = new SimpleObject {
                a = 3,
                b = 4
            }
        };

        Dictionary <string, object> readable = SavedObjectDelta.ReadableModel(new SavedObject(model).state);

        Assert.AreEqual(7, readable.Count);
        Assert.AreEqual(model.GetType(), readable["GetType()"]);
        Assert.AreEqual(model.a, readable["a"]);
        Assert.AreEqual(model.b, readable["b"]);
        Assert.AreEqual(model.nested.GetType(), readable["nested:GetType()"]);
        Assert.AreEqual(model.nested.a, readable["nested:a"]);
        Assert.AreEqual(model.nested.b, readable["nested:b"]);
        Assert.AreEqual(model.nested.nested, readable["nested:nested"]);
    }
Exemplo n.º 5
0
    public static void RunFieldPropertyTest()
    {
        var obj = new SimpleObject {
            a      = 1,
            b      = 2,
            nested = new SimpleObject {
                a = 3,
                b = 4
            }
        };
        Dictionary <ObjectDataPath[], object> model         = new SavedObject(obj).state;
        Dictionary <string, object>           readableModel = SavedObjectDelta.ReadableModel(model);

        Assert.AreEqual(7, readableModel.Count);
        Assert.AreEqual(obj.GetType(), readableModel["GetType()"]);
        Assert.AreEqual(1, readableModel["a"]);
        Assert.AreEqual(2, readableModel["b"]);
        Assert.AreEqual(obj.nested.GetType(), readableModel["nested:GetType()"]);
        Assert.AreEqual(3, readableModel["nested:a"]);
        Assert.AreEqual(4, readableModel["nested:b"]);
        Assert.AreEqual(null, readableModel["nested:nested"]);
    }
Exemplo n.º 6
0
    public static void CycleTest()
    {
        // TODO: This needs to be fixed. The cyclic object should appear in the
        //       dict.
        Debug.LogError("Fix CycleTest to include cycled object");

        var obj = new SimpleObject();

        obj.a      = 1;
        obj.b      = 2;
        obj.nested = obj;

        Dictionary <ObjectDataPath[], object> model         = new SavedObject(obj).state;
        Dictionary <string, object>           readableModel = SavedObjectDelta.ReadableModel(model);

        Assert.AreEqual(3, readableModel.Count);
        Assert.AreEqual(obj.GetType(), readableModel["GetType()"]);
        Assert.AreEqual(obj.a, readableModel["a"]);
        Assert.AreEqual(obj.b, readableModel["b"]);
        //Assert.AreEqual(obj.nested, readableModel["nested"]);

        // Also test vectors, which are cyclic on normalized
        new SavedObject(new Vector3(1, 1, 1));
    }
Exemplo n.º 7
0
        public void TestNodeConstruction()
        {
            var obj = new SimpleObject(1, 2, 3, 4)
            {
                Name           = "Test",
                MemberToIgnore = int.MaxValue,
                SubObject      = new SimpleObject(5, 6, 7, 8),
                Collection     =
                {
                    "List Item",
                    22.5,
                    Guid.NewGuid(),
                    new List <string> {
                        "one",         "two","three"
                    },
                    new SimpleObject(9, 10, 11, 12),
                },
                Dictionary =
                {
                    { "Item1", "List Item"    },
                    { "Item2",           22.5 },
                    { "Item3", Guid.NewGuid() },
                    { "Item4", new List <string> {
                          "one", "two", "three"
                      } },
                    { "Item5", new SimpleObject(9, 10, 11, 12)},
                },
            };

            var container = new ModelContainer();
            var node      = (ModelNode)container.GetOrCreateModelNode(obj, obj.GetType());

            Helper.PrintModelContainerContent(container, node);
            // Run the consistency check to verify construction.
            Helper.ConsistencyCheck(container, obj);
        }
Exemplo n.º 8
0
        public void TestNodeConstruction()
        {
            var simpleObject = new SimpleObject(1, 2, 3, 4)
            {
                Name = "Test", MemberToIgnore = int.MaxValue, SubObject = new SimpleObject(5, 6, 7, 8)
            };

            simpleObject.Collection.Add("List Item");
            simpleObject.Collection.Add(22.5);
            simpleObject.Collection.Add(Guid.NewGuid());
            simpleObject.Collection.Add(new List <string> {
                "one", "two", "three"
            });
            simpleObject.Collection.Add(new SimpleObject(9, 10, 11, 12));
            simpleObject.Dictionary.Add("Item1", "List Item");
            simpleObject.Dictionary.Add("Item2", 22.5);
            simpleObject.Dictionary.Add("Item3", Guid.NewGuid());
            simpleObject.Dictionary.Add("Item4", new List <string> {
                "one", "two", "three"
            });
            simpleObject.Dictionary.Add("Item5", new SimpleObject(9, 10, 11, 12));
            var container = new ModelContainer();
            var node      = (ModelNode)container.GetOrCreateModelNode(simpleObject, simpleObject.GetType());

            Console.WriteLine(node.PrintHierarchy());

            var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder);

            visitor.Check(node, simpleObject, typeof(SimpleObject), true);

            foreach (var viewModel in container.Models)
            {
                visitor.Check((ModelNode)viewModel, viewModel.Content.Value, viewModel.Content.Type, true);
                Console.WriteLine(viewModel.PrintHierarchy());
            }
        }
        public void TestSimpleUpdate() {
            var so = new SimpleObject {ValueOne = 1, ValueTwo = 2};
            var clone = (SimpleObject) CopyUtils.CloneObjectTest(so);
            clone.ValueTwo = 3;

            Assert.AreNotSame(so, clone);
            Assert.AreSame(so.GetType(), clone.GetType());
            Assert.AreEqual(so.ValueOne, clone.ValueOne);
            Assert.AreNotEqual(so.ValueTwo, clone.ValueTwo);

            CopyUtils.UpdateFromClone(so, clone);

            Assert.AreNotSame(so, clone);
            Assert.AreSame(so.GetType(), clone.GetType());
            Assert.AreEqual(so.ValueOne, clone.ValueOne);
            Assert.AreEqual(so.ValueTwo, clone.ValueTwo);
        }
Exemplo n.º 10
0
        public void TestNodeConstruction()
        {
            var simpleObject = new SimpleObject(1, 2, 3, 4) { Name = "Test", MemberToIgnore = int.MaxValue, SubObject = new SimpleObject(5, 6, 7, 8) };
            simpleObject.Collection.Add("List Item");
            simpleObject.Collection.Add(22.5);
            simpleObject.Collection.Add(Guid.NewGuid());
            simpleObject.Collection.Add(new List<string> { "one", "two", "three" });
            simpleObject.Collection.Add(new SimpleObject(9, 10, 11, 12));
            simpleObject.Dictionary.Add("Item1", "List Item");
            simpleObject.Dictionary.Add("Item2", 22.5);
            simpleObject.Dictionary.Add("Item3", Guid.NewGuid());
            simpleObject.Dictionary.Add("Item4", new List<string> { "one", "two", "three" });
            simpleObject.Dictionary.Add("Item5", new SimpleObject(9, 10, 11, 12));
            var container = new ModelContainer();
            var node = (ModelNode)container.GetOrCreateModelNode(simpleObject, simpleObject.GetType());
            Console.WriteLine(node.PrintHierarchy());

            var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder);
            visitor.Check(node, simpleObject, typeof(SimpleObject), true);

            foreach (var viewModel in container.Models)
            {
                visitor.Check((ModelNode)viewModel, viewModel.Content.Value, viewModel.Content.Type, true);
                Console.WriteLine(viewModel.PrintHierarchy());
            }
        }
Exemplo n.º 11
0
        public void TestNodeConstruction()
        {
            var obj = new SimpleObject(1, 2, 3, 4)
            {
                Name = "Test",
                MemberToIgnore = int.MaxValue,
                SubObject = new SimpleObject(5, 6, 7, 8),
                Collection = 
                {
                    "List Item",
                    22.5,
                    Guid.NewGuid(),
                    new List<string> { "one", "two", "three" },
                    new SimpleObject(9, 10, 11, 12),
                },
                Dictionary =
                {
                    { "Item1", "List Item" },
                    { "Item2", 22.5 },
                    { "Item3", Guid.NewGuid() },
                    { "Item4", new List<string> { "one", "two", "three" } },
                    { "Item5", new SimpleObject(9, 10, 11, 12) },
                },
            };

            var container = new ModelContainer();
            var node = (ModelNode)container.GetOrCreateModelNode(obj, obj.GetType());
            Helper.PrintModelContainerContent(container, node);
            // Run the consistency check to verify construction.
            Helper.ConsistencyCheck(container, obj);
        }
Exemplo n.º 12
0
    public static void CheckReadableModelIncludesInstances()
    {
        var model = new SimpleObject {
            a = 1,
            b = 2,
            nested = new SimpleObject {
                a = 3,
                b = 4
            }
        };

        Dictionary<string, object> readable = SavedObjectDelta.ReadableModel(new SavedObject(model).state);
        Assert.AreEqual(7, readable.Count);
        Assert.AreEqual(model.GetType(), readable["GetType()"]);
        Assert.AreEqual(model.a, readable["a"]);
        Assert.AreEqual(model.b, readable["b"]);
        Assert.AreEqual(model.nested.GetType(), readable["nested:GetType()"]);
        Assert.AreEqual(model.nested.a, readable["nested:a"]);
        Assert.AreEqual(model.nested.b, readable["nested:b"]);
        Assert.AreEqual(model.nested.nested, readable["nested:nested"]);
    }
Exemplo n.º 13
0
    public static void RunFieldPropertyTest()
    {
        var obj = new SimpleObject {
            a = 1,
            b = 2,
            nested = new SimpleObject {
                a = 3,
                b = 4
            }
        };
        Dictionary<ObjectDataPath[], object> model = new SavedObject(obj).state;
        Dictionary<string, object> readableModel = SavedObjectDelta.ReadableModel(model);

        Assert.AreEqual(7, readableModel.Count);
        Assert.AreEqual(obj.GetType(), readableModel["GetType()"]);
        Assert.AreEqual(1, readableModel["a"]);
        Assert.AreEqual(2, readableModel["b"]);
        Assert.AreEqual(obj.nested.GetType(), readableModel["nested:GetType()"]);
        Assert.AreEqual(3, readableModel["nested:a"]);
        Assert.AreEqual(4, readableModel["nested:b"]);
        Assert.AreEqual(null, readableModel["nested:nested"]);
    }
Exemplo n.º 14
0
    public static void CycleTest()
    {
        // TODO: This needs to be fixed. The cyclic object should appear in the
        //       dict.
        Debug.LogError("Fix CycleTest to include cycled object");

        var obj = new SimpleObject();
        obj.a = 1;
        obj.b = 2;
        obj.nested = obj;

        Dictionary<ObjectDataPath[], object> model = new SavedObject(obj).state;
        Dictionary<string, object> readableModel = SavedObjectDelta.ReadableModel(model);

        Assert.AreEqual(3, readableModel.Count);
        Assert.AreEqual(obj.GetType(), readableModel["GetType()"]);
        Assert.AreEqual(obj.a, readableModel["a"]);
        Assert.AreEqual(obj.b, readableModel["b"]);
        //Assert.AreEqual(obj.nested, readableModel["nested"]);

        // Also test vectors, which are cyclic on normalized
        new SavedObject(new Vector3(1, 1, 1));
    }
Exemplo n.º 15
0
        public void ReadMultipleWithObjectsNotInOrder_Ok(object first, object second, object third)
        {
            second = new SimpleObject() { Name = "testName", Description = "testDescription" };

            var outputStream = new MemoryStream();
            var objectSerializer = Serializer.CreateSerializer(outputStream);
            objectSerializer.Write("prop1", first.GetType(), first);
            objectSerializer.Write("prop2", second.GetType(), second);
            objectSerializer.Write("prop3", third.GetType(), third);

            var deserializer = CreateDeserializer(outputStream);

            object val;
            deserializer.TryRead("prop2", second.GetType(), out val);
            var obj = Assert.IsType<SimpleObject>(val);
            Assert.Equal((second as SimpleObject).Name, obj.Name);
            Assert.Equal((second as SimpleObject).Description, obj.Description);

            deserializer.TryRead("prop1", first.GetType(), out val);
            Assert.Equal(first, val);

            deserializer.TryRead("prop3", third.GetType(), out val);
            Assert.Equal(third, val);
        }
        public void TestSimpleClone() {
            var so = new SimpleObject {ValueOne = 1, ValueTwo = 2};
            SimpleObject clone = (SimpleObject) CopyUtils.CloneObjectTest(so);

            NAssert.AreNotSame(so, clone);
            NAssert.AreSame(so.GetType(), clone.GetType());
            NAssert.AreEqual(so.ValueOne, clone.ValueOne);
            NAssert.AreEqual(so.ValueTwo, clone.ValueTwo);
        }