Example #1
0
        public void ShouldNotChangeValue()
        {
            var array = new ArrayOfStructureField("userinfo", "User information");

            array.AddIntoStructure(new StringField("username", "User name"));
            array.AddIntoStructure(new IntegerField("timeout", "Timeout"));

            var element = new Dictionary <string, object>
            {
                { "username", "yashar" },
                { "timeout", "20" }
            };

            array.InsertValue(element, false);

            element["timeout"] = 20;

            var changed = false;
            var errors  = array.UpdateValue(0, element, out changed, false);
            var lst     = array.GetValues();

            Assert.Empty(errors);
            Assert.Equal(20, (int)lst.First()["timeout"]);
            Assert.Equal("yashar", (string)lst.First()["username"]);
            Assert.False(changed);
        }
Example #2
0
        public void ShouldAddValueWithError()
        {
            var array = new ArrayOfStructureField("userinfo", "User information");

            array.AddIntoStructure(new StringField("username", "User name"));
            array.AddIntoStructure(new IntegerField("timeout", "Timeout"));

            var element = new Dictionary <string, object>
            {
                { "username", "yashar" },
                { "timeout", "test" }
            };

            var errors = array.InsertValue(element, false);

            var lst = array.GetValues();

            Assert.Empty(lst);
            Assert.NotEmpty(errors);
        }
Example #3
0
        public void ShouldAddValueSuccessfully()
        {
            var array = new ArrayOfStructureField("userinfo", "User information");

            array.AddIntoStructure(new StringField("username", "User name"));
            array.AddIntoStructure(new IntegerField("timeout", "Timeout"));

            var element = new Dictionary <string, object>
            {
                { "username", "yashar" },
                { "timeout", 300 }
            };

            var errors = array.InsertValue(element);

            var lst = array.GetValues();

            Assert.NotEmpty(lst);
            Assert.Empty(errors);
            Assert.False(string.IsNullOrEmpty(lst.First()["username"].ToString()));
            Assert.True((int)lst.First()["timeout"] == 300);
        }