示例#1
0
        public void GetDictionaryValueOrDefaultReturnsNullIfKeyNotFoundForReferenceType()
        {
            var dictionary = JObject.FromObject(new Dictionary <string, JToken>());

            var actual = (Sample)MemberProjectionExpressionVisitor.GetKeyedValueOrDefault(dictionary, "Any", typeof(Sample));

            Assert.Null(actual);
        }
示例#2
0
        public void GetDictionaryValueOrDefaultReturnsDefaultObjectIfKeyNotFoundForValueType()
        {
            var dictionary = JObject.FromObject(new Dictionary <string, JToken>());

            var actual = (int)MemberProjectionExpressionVisitor.GetKeyedValueOrDefault(dictionary, "Any", typeof(int));

            Assert.Equal(0, actual);
        }
示例#3
0
        public void GetDictionaryValueOrDefaultReturnsArrayIfArrayDesiredFromDictionaryKeyFound()
        {
            var expected   = new[] { "Cameron" };
            var dictionary = JObject.FromObject(new Dictionary <string, JToken> {
                { "fields", JToken.Parse("[ \"" + expected[0] + "\" ]") }
            });

            var actual = MemberProjectionExpressionVisitor.GetKeyedValueOrDefault(dictionary, "fields", expected.GetType());

            Assert.IsType(expected.GetType(), actual);
            Assert.Equal(expected, actual);
        }
示例#4
0
        public void GetDictionaryValueOrDefaultReturnsSimpleTokenFromDictionaryKeyFound()
        {
            var expected = new Sample {
                Id = "T-900", Name = "Cameron"
            };
            const string key        = "Summer";
            var          dictionary = JObject.FromObject(new Dictionary <string, JToken> {
                { key, JToken.FromObject(expected) }
            });

            var actual = (Sample)MemberProjectionExpressionVisitor.GetKeyedValueOrDefault(dictionary, key, typeof(Sample));

            Assert.Equal(expected.Id, actual.Id);
            Assert.Equal(expected.Name, actual.Name);
        }
示例#5
0
        public void GetDictionaryValueOrDefaultReturnsDefaultObjectIfObjectIsNull()
        {
            var actual = (DateTime)MemberProjectionExpressionVisitor.GetKeyedValueOrDefault(null, "Any", typeof(DateTime));

            Assert.Equal(default(DateTime), actual);
        }