Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
        public void GetDictionaryValueOrDefaultReturnsNullIfKeyNotFoundForReferenceType()
        {
            var dictionary = new Dictionary <string, JToken>();

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

            Assert.Null(actual);
        }
Exemplo n.º 3
0
        public void GetDictionaryValueOrDefaultReturnsDefaultObjectIfKeyNotFoundForValueType()
        {
            var dictionary = new Dictionary <string, JToken>();

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

            Assert.Equal(0, actual);
        }
Exemplo n.º 4
0
        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());
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
 public void Rebind_GuardClauses()
 {
     Assert.Throws <ArgumentNullException>(() => MemberProjectionExpressionVisitor.Rebind(typeof(Sample), null, Expression.Constant(1)));
     Assert.Throws <ArgumentNullException>(() => MemberProjectionExpressionVisitor.Rebind(typeof(Sample), validMapping, null));
 }
Exemplo n.º 10
0
        public void GetDictionaryValueOrDefaultReturnsDefaultObjectIfDictionaryIsNull()
        {
            var actual = (DateTime)MemberProjectionExpressionVisitor.GetDictionaryValueOrDefault(null, "Any", typeof(DateTime));

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