Example #1
0
        public void ObjectChanger_ChangeObject_NoChangeInformation()
        {
            var changer = new ObjectChanger();
            var objectToChange = this.testFieldObject.CreateCopy();

            changer.ChangeObject(objectToChange, null, null);

            var expected = this.testFieldObject.CreateCopy();

            this.AssertSimpleFieldEqual(expected, objectToChange);
        }
Example #2
0
        public void ObjectChanger_ChangeObject_SingleValidField()
        {
            var changer = new ObjectChanger();
            var objectToChange = this.testFieldObject.CreateCopy();

            var fieldsToChange = new Dictionary<string, JToken>
            {
                {"boolField", JToken.FromObject(false)}
            };

            changer.ChangeObject(objectToChange, fieldsToChange, null);

            var expected = this.testFieldObject.CreateCopy();
            expected.boolField = false;
            
            this.AssertSimpleFieldEqual(expected, objectToChange);
        }
Example #3
0
        public void ObjectChanger_ChangeObject_ChangeMultipleFields()
        {
            var changer = new ObjectChanger();
            var objectToChange = this.testFieldObject.CreateCopy();
            var fieldsToChange = new Dictionary<string, JToken>
            {
                {"boolField", JToken.FromObject(false)},
                {"integerField", JToken.FromObject(123456)},
                {"stringField", JToken.FromObject("foobar")},
                {"floatField", JToken.FromObject(125.6f)}
            };

            changer.ChangeObject(objectToChange, fieldsToChange, null);

            var expected = this.testFieldObject.CreateCopy();
            expected.boolField = false;
            expected.integerField = 123456;
            expected.stringField = "foobar";
            expected.floatField = 125.6f;

            this.AssertSimpleFieldEqual(expected, objectToChange);
        }
Example #4
0
        public void ObjectChanger_ChangeObject_InvalidName()
        {
            var changer = new ObjectChanger();
            var objectToChange = this.testComplexObject.CreateCopy();
            var fieldsToClear = new String[] { "INVALID"};

            changer.ChangeObject(objectToChange, null, fieldsToClear);

            var expected = this.testComplexObject.CreateCopy();

            this.AssertComplexObjectEqual(expected, objectToChange);
        }
Example #5
0
        public void ObjectChanger_ChangeObject_ClearedFieldsCaseSensitive()
        {
            var changer = new ObjectChanger();
            var objectToChange = this.testComplexObject.CreateCopy();
            var fieldsToClear = new String[] { "TestField", "Testboolean", "Nestedobject" };

            changer.ChangeObject(objectToChange, null, fieldsToClear);

            var expected = this.testComplexObject.CreateCopy();

            this.AssertComplexObjectEqual(expected, objectToChange);
        }
Example #6
0
        public void ObjectChanger_ChangeObject_ClearedFieldsReturnedToDefault()
        {
            var changer = new ObjectChanger();
            var objectToChange = this.testComplexObject.CreateCopy();
            var fieldsToClear = new String[] {"testField", "TestBoolean", "NestedObject"};

            changer.ChangeObject(objectToChange, null, fieldsToClear);

            var expected = this.testComplexObject.CreateCopy();
            expected.NestedObject = null;
            expected.testField = default(float);
            expected.TestBoolean = default(bool);

            this.AssertComplexObjectEqual(expected, objectToChange);
        }
Example #7
0
        public void ObjectChanger_ChangeObject_ChangeNestedObject()
        {
            var changer = new ObjectChanger();
            var objectToChange = this.testComplexObject.CreateCopy();
            var propertiesToChange = new Dictionary<string, JToken>
            {
                {"NestedObject", JToken.FromObject(new NestedObject() { testfield = "foobar", TestProperty = 1000})}
            };

            changer.ChangeObject(objectToChange, propertiesToChange, null);

            var expected = this.testComplexObject.CreateCopy();
            expected.NestedObject.testfield = "foobar";
            expected.NestedObject.TestProperty = 1000;

            this.AssertComplexObjectEqual(expected, objectToChange);
        }
Example #8
0
        public void ObjectChanger_ChangeObject_ChangePropertyAndField()
        {
            var changer = new ObjectChanger();
            var objectToChange = this.testComplexObject.CreateCopy();
            var propertiesToChange = new Dictionary<string, JToken>
            {
                {"testField", 3.14f},
                {"TestBoolean", false}
            };

            changer.ChangeObject(objectToChange, propertiesToChange, null);

            var expected = this.testComplexObject.CreateCopy();
            expected.testField = 3.14f;
            expected.TestBoolean = false;

            this.AssertComplexObjectEqual(expected, objectToChange);
        }
Example #9
0
        public void ObjectChanger_ChangeObject_FieldNameIsCaseSensitive()
        {
            var changer = new ObjectChanger();
            var objectToChange = this.testFieldObject.CreateCopy();

            var fieldsToChange = new Dictionary<string, JToken>
            {
                {"BoolField", JToken.FromObject(false)}
            };

            changer.ChangeObject(objectToChange, fieldsToChange, null);

            var expected = this.testFieldObject.CreateCopy();
            
            this.AssertSimpleFieldEqual(expected, objectToChange);
        }
Example #10
0
        public void ObjectChanger_ChangeObject_PrivateSetMethod()
        {
            var changer = new ObjectChanger();
            var objectToChange = this.testPropertyObject.CreateCopy();
            var propertiesToChange = new Dictionary<string, JToken>
            {
                {"PrivateSetProperty", false}
            };

            changer.ChangeObject(objectToChange, propertiesToChange, null);

            var expected = this.testPropertyObject.CreateCopy(privateSetProperty:false);

            this.AssertSimplePropertyEqual(expected, objectToChange);
        }
Example #11
0
        public void ObjectChanger_ChangeObject_ReadOnlyProperty()
        {
            var changer = new ObjectChanger();
            var objectToChange = this.testPropertyObject.CreateCopy();
            var propertiesToChange = new Dictionary<string, JToken>
            {
                {"ReadOnlyProperty", "ReadOnlyValue"}
            };

            changer.ChangeObject(objectToChange, propertiesToChange, null);

            var expected = this.testPropertyObject.CreateCopy();

            this.AssertSimplePropertyEqual(expected, objectToChange);
        }
Example #12
0
        public void ObjectChanger_ChangeObject_PropertiesMatchedByJsonPropertyAttribute()
        {
            var changer = new ObjectChanger();
            var objectToChange = this.testPropertyObject.CreateCopy();
            var propertiesToChange = new Dictionary<string, JToken>
            {
                {"foobar", JToken.FromObject(1337)}
            };

            changer.ChangeObject(objectToChange, propertiesToChange, null);

            var expected = this.testPropertyObject.CreateCopy();
            expected.ActualNameInJsonAttribute = 1337;

            this.AssertSimplePropertyEqual(expected, objectToChange);
        }
Example #13
0
        public void ObjectChanger_ChangeObject_PropertiesCaseSensitive()
        {
            var changer = new ObjectChanger();
            var objectToChange = this.testPropertyObject.CreateCopy();
            var propertiesToChange = new Dictionary<string, JToken>
            {
                {"stringProperty", JToken.FromObject("foobar")}
            };

            changer.ChangeObject(objectToChange, propertiesToChange, null);

            var expected = this.testPropertyObject.CreateCopy();

            this.AssertSimplePropertyEqual(expected, objectToChange);
        }
Example #14
0
        public void ObjectChanger_ChangeObject_InvalidPropertiesIgnored()
        {
            var changer = new ObjectChanger();
            var objectToChange = this.testPropertyObject.CreateCopy();
            var propertiesToChange = new Dictionary<string, JToken>
            {
                {"StringProperty", JToken.FromObject("foobar")}
            };

            changer.ChangeObject(objectToChange, propertiesToChange, null);

            var expected = this.testPropertyObject.CreateCopy();
            expected.StringProperty = "foobar";

            AssertSimplePropertyEqual(expected, objectToChange);
        }
Example #15
0
        public void ObjectChanger_ChangeObject_ChangeMultipleProperties()
        {
            var changer = new ObjectChanger();
            var objectToChange = this.testPropertyObject.CreateCopy();
            var propertiesToChange = new Dictionary<string, JToken>
            {
                {"StringProperty", JToken.FromObject("foobar")},
                {"BoolProperty", JToken.FromObject(false)},
                {"FloatProperty", JToken.FromObject(3.14f)},
                {"IntegerProperty",  JToken.FromObject(1000)}
            };

            changer.ChangeObject(objectToChange, propertiesToChange, null);

            var expected = this.testPropertyObject.CreateCopy();
            expected.StringProperty = "foobar";
            expected.BoolProperty = false;
            expected.FloatProperty = 3.14f;
            expected.IntegerProperty = 1000;

            this.AssertSimplePropertyEqual(expected, objectToChange);
        }
Example #16
0
        public void ObjectChanger_ChangeObject_FieldMatchedByJsonPropertyAttribute()
        {
            var changer = new ObjectChanger();
            var objectToChange = this.testFieldObject.CreateCopy();
            var fieldsToChange = new Dictionary<string, JToken>
            {
                {"NAMEINATTRIBUTE", "abcdefg"}
            };

            changer.ChangeObject(objectToChange, fieldsToChange, null);

            var expected = this.testFieldObject.CreateCopy();
            expected.actualFieldNameIsInAttribute = "abcdefg";

            this.AssertSimpleFieldEqual(expected, objectToChange);
        }
Example #17
0
        public void ObjectChanger_ChangeObject_InvokesPropertyChanged()
        {
            var changer = new ObjectChanger();
            var objectToChange = this.testPropertyObject.CreateCopy();
            var propertiesToChange = new Dictionary<string, JToken>
            {
                {"PropertyWithPropertyChanged", 3.14f}
            };

            bool propertyChangedInvoked = false;
            objectToChange.PropertyChanged += (sender, args) =>
            {
                Assert.AreEqual("PropertyWithPropertyChanged", args.PropertyName);
                propertyChangedInvoked = true;
            };

            changer.ChangeObject(objectToChange, propertiesToChange, null);

            var expected = this.testPropertyObject.CreateCopy(propertyWithPropertyChanged:3.14f);

            this.AssertSimplePropertyEqual(expected, objectToChange);
            Assert.IsTrue(propertyChangedInvoked);
        }
Example #18
0
        public void ObjectChanger_ChangeObject_InvalidFieldsIgnored()
        {
            var changer = new ObjectChanger();
            var objectToChange = this.testFieldObject.CreateCopy();
            var fieldsToChange = new Dictionary<string, JToken>
            {
                {"invalidField1", JToken.FromObject(34234)},
                {"invalidField2", JToken.FromObject("this is a test. this is only a test")},
                {"stringField", JToken.FromObject("foobar")},
                {"floatField", JToken.FromObject(125.6f)}
            };

            changer.ChangeObject(objectToChange, fieldsToChange, null);

            var expected = this.testFieldObject.CreateCopy();
            expected.stringField = "foobar";
            expected.floatField = 125.6f;

            this.AssertSimpleFieldEqual(expected, objectToChange);
        }