Exemplo n.º 1
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            DynamicTypeWrapper dynamicTypeWrapper = value as DynamicTypeWrapper;

            if (dynamicTypeWrapper != null)
            {
                serializer.Serialize(writer, dynamicTypeWrapper.Values);
            }
        }
        public void CanSetProperty()
        {
            var expectedValue = "TestValue";
            var propName = "TestProp";
            var wrapper = new DynamicTypeWrapper();
            wrapper.SetPropertyValue(propName, expectedValue);

            var actual = wrapper.GetPropertyValue(propName);

            Assert.Equal(expectedValue, actual);
        }
        public void GetHashCodeEqualForEqualWrappers()
        {
            var expectedValue = "TestValue";
            var propName = "TestProp";
            var wrapper = new DynamicTypeWrapper();
            wrapper.SetPropertyValue(propName, expectedValue);

            var wrapper2 = new DynamicTypeWrapper();
            wrapper2.SetPropertyValue(propName, expectedValue);

            Assert.Equal(wrapper.GetHashCode(), wrapper2.GetHashCode());
        }
        public void CanEqualWrappers()
        {
            var expectedValue = "TestValue";
            var propName = "TestProp";
            var wrapper = new DynamicTypeWrapper();
            wrapper.SetPropertyValue(propName, expectedValue);

            var wrapper2 = new DynamicTypeWrapper();
            wrapper2.SetPropertyValue(propName, expectedValue);

            Assert.Equal(wrapper, wrapper2);
        }
        public void CanTryGetProperty()
        {
            var expectedValue = "TestValue";
            var propName = "TestProp";
            var wrapper = new DynamicTypeWrapper();
            wrapper.SetPropertyValue(propName, expectedValue);

            object actual;
            Assert.True(wrapper.TryGetPropertyValue(propName, out actual));

            Assert.Equal(expectedValue, actual);
        }
        private object GetValue(DynamicTypeWrapper wrapper, string path)
        {
            var parts = path.Split('/');
            foreach (var part in parts)
            {
                object value;
                wrapper.TryGetPropertyValue(part, out value);
                wrapper = value as DynamicTypeWrapper;
                if (wrapper == null)
                {
                    return value;
                }
            }

            Assert.False(true, "Property " + path + " not found");
            return null;
        }