public void GetDictionaryValueOrDefaultReturnsNullIfKeyNotFoundForReferenceType() { var dictionary = JObject.FromObject(new Dictionary <string, JToken>()); var actual = (Sample)MemberProjectionExpressionVisitor.GetKeyedValueOrDefault(dictionary, "Any", typeof(Sample)); Assert.Null(actual); }
public void GetDictionaryValueOrDefaultReturnsDefaultObjectIfKeyNotFoundForValueType() { var dictionary = JObject.FromObject(new Dictionary <string, JToken>()); var actual = (int)MemberProjectionExpressionVisitor.GetKeyedValueOrDefault(dictionary, "Any", typeof(int)); Assert.Equal(0, actual); }
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); }
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); }
public void GetDictionaryValueOrDefaultReturnsDefaultObjectIfObjectIsNull() { var actual = (DateTime)MemberProjectionExpressionVisitor.GetKeyedValueOrDefault(null, "Any", typeof(DateTime)); Assert.Equal(default(DateTime), actual); }