public void RebindCollectsSinglePropertyFieldName() { var source = new FakeQuery <Sample>(new FakeQueryProvider()).Select(s => s.Name); var rebound = MemberProjectionExpressionVisitor.Rebind(typeof(Sample), validMapping, source.Expression); Assert.Contains("name", rebound.Collected); Assert.Equal(1, rebound.Collected.Count()); }
public void GetDictionaryValueOrDefaultReturnsNullIfKeyNotFoundForReferenceType() { var dictionary = new Dictionary <string, JToken>(); var actual = (Sample)MemberProjectionExpressionVisitor.GetDictionaryValueOrDefault(dictionary, "Any", typeof(Sample)); Assert.Null(actual); }
public void GetDictionaryValueOrDefaultReturnsDefaultObjectIfKeyNotFoundForValueType() { var dictionary = new Dictionary <string, JToken>(); var actual = (int)MemberProjectionExpressionVisitor.GetDictionaryValueOrDefault(dictionary, "Any", typeof(int)); Assert.Equal(0, actual); }
public void RebindCollectsTupleCreateProjectionPropertiesFieldNames() { var source = new FakeQuery <Sample>(new FakeQueryProvider()).Select(s => Tuple.Create(s.Name, s.Id, ElasticFields.Score)); var rebound = MemberProjectionExpressionVisitor.Rebind(typeof(Sample), validMapping, source.Expression); Assert.Contains("name", rebound.Collected); Assert.Contains("id", rebound.Collected); Assert.Contains("_score", rebound.Collected); Assert.Equal(3, rebound.Collected.Count()); }
public void RebindCollectsAnonymousProjectionPropertiesFieldNames() { var source = new FakeQuery <Sample>(new FakeQueryProvider()).Select(s => new { s.Name, s.Id, score = ElasticFields.Score }); var rebound = MemberProjectionExpressionVisitor.Rebind("prefix", validMapping, source.Expression); Assert.Contains("prefix.name", rebound.Collected); Assert.Contains("prefix.id", rebound.Collected); Assert.Contains("_score", rebound.Collected); Assert.Equal(3, rebound.Collected.Count()); }
public void GetDictionaryValueOrDefaultReturnsSingleItemInArrayFromDictionaryKeyFound() { const string expected = "Cameron"; var dictionary = new Dictionary <string, JToken> { { "fields", JToken.Parse("[ \"" + expected + "\" ]") } }; var actual = MemberProjectionExpressionVisitor.GetDictionaryValueOrDefault(dictionary, "fields", typeof(string)); Assert.Equal(expected, actual); }
public void GetDictionaryValueOrDefaultReturnsArrayIfArrayDesiredFromDictionaryKeyFound() { var expected = new[] { "Cameron" }; var dictionary = new Dictionary <string, JToken> { { "fields", JToken.Parse("[ \"" + expected[0] + "\" ]") } }; var actual = MemberProjectionExpressionVisitor.GetDictionaryValueOrDefault(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 = new Dictionary <string, JToken> { { key, JToken.FromObject(expected) } }; var actual = (Sample)MemberProjectionExpressionVisitor.GetDictionaryValueOrDefault(dictionary, key, typeof(Sample)); Assert.Equal(expected.Id, actual.Id); Assert.Equal(expected.Name, actual.Name); }
public void Rebind_GuardClauses() { Assert.Throws <ArgumentNullException>(() => MemberProjectionExpressionVisitor.Rebind(typeof(Sample), null, Expression.Constant(1))); Assert.Throws <ArgumentNullException>(() => MemberProjectionExpressionVisitor.Rebind(typeof(Sample), validMapping, null)); }
public void GetDictionaryValueOrDefaultReturnsDefaultObjectIfDictionaryIsNull() { var actual = (DateTime)MemberProjectionExpressionVisitor.GetDictionaryValueOrDefault(null, "Any", typeof(DateTime)); Assert.Equal(default(DateTime), actual); }