public void GetPropertyPathReturnsNullIfSubjectIsNoObject()
        {
            var str = "Hello world";

            Assert.Null(ObjectAccess.ObjectPropertyByPath(str, "property2"));
            Assert.Null(ObjectAccess.ObjectPropertyByPath(str, "0"));
        }
 public void GetPropertyPathCanGetPropertiesOfAnObject()
 {
     Assert.Equal("inner value", ObjectAccess.ObjectPropertyByPath(dummyObject2, "nestedClass.innerValue"));
     Assert.Equal("value 1", ObjectAccess.ObjectPropertyByPath(dummyObject2, "nestedDictionary.key1"));
     Assert.Equal("value1", ObjectAccess.ObjectPropertyByPath(dummyObject2, "nestedDictionary.1.0"));
     Assert.Equal("baz", ObjectAccess.ObjectPropertyByPath(dummyObject2, "nestedList.2"));
     Assert.Equal("ab", ObjectAccess.ObjectPropertyByPath(dummyObject2, "nestedArray.0"));
 }
        public void GetProeprtyPathReturnsNullIfSubjectOnPathIsNoObject()
        {
            var subject = new Dictionary <string, object>()
            {
                { "foo", "Hello World" }
            };

            Assert.Null(ObjectAccess.ObjectPropertyByPath(subject, "foo.bar"));
        }
Example #4
0
 /// <summary>
 /// Get all items' "position" property and index the item keys accordingly. From that index the sorted keys will be composed later.
 /// </summary>
 protected void IndexKeys()
 {
     foreach (var kvp in this.KeyAlias)
     {
         var sKey  = kvp.Key;
         var oKey  = kvp.Value;
         var value = this.Subject[sKey];
         if (value == null)
         {
             continue;
         }
         var positionValue = ObjectAccess.ObjectPropertyByPath(value, PositionalPropertyPath);
         var position      = positionValue == null ? null : positionValue.ToString();
         if (position != null && position.StartsWith("start"))
         {
             if (IndexStartKey(sKey, position))
             {
                 continue;
             }
         }
         else if (position != null && position.StartsWith("end"))
         {
             if (IndexEndKey(sKey, position))
             {
                 continue;
             }
         }
         else if (position != null && position.StartsWith("after"))
         {
             if (IndexAfterKey(sKey, position))
             {
                 continue;
             }
         }
         else if (position != null && position.StartsWith("before"))
         {
             if (IndexBeforeKey(sKey, position))
             {
                 continue;
             }
         }
         else
         {
             IndexMiddleKey(sKey, position, oKey);
             continue;
         }
         // invalid keyword-key
         IndexMiddleKey(sKey, null, oKey);
     }
 }
 public void GetPropertyPathReturnsNullForNonExistingPropertyPath()
 {
     Assert.Null(ObjectAccess.ObjectPropertyByPath(dummyObject2, "nestedClass.foo"));
 }