public static void ConstructorDefaultsToConstantExpressionIfNotSpecified() { var context = new TestableElasticContext(); var query = new TestableElasticQuery <FakeClass>(context); Assert.IsType <ConstantExpression>(query.Expression); }
public static void ExplicitGetEnumeratorCapturesQueryOnContext() { var context = new TestableElasticContext(); var dummy = ((IEnumerable) new TestableElasticQuery <FakeClass>(context).Where(f => f.Name == "a")).GetEnumerator(); Assert.Equal(1, context.Requests.Count); }
public static void ConstructorDefaultsToConstantExpressionIfNotSpecified() { var context = new TestableElasticContext(); var query = new TestableElasticQuery<FakeClass>(context); Assert.IsType<ConstantExpression>(query.Expression); }
public void QueryOfTReturnsTestableQueryOfT() { var context = new TestableElasticContext(); var query = context.Query<FakeClass>(); Assert.IsType<TestableElasticQuery<FakeClass>>(query); }
public void QueryOfTReturnsTestableQueryOfT() { var context = new TestableElasticContext(); var query = context.Query <FakeClass>(); Assert.IsType <TestableElasticQuery <FakeClass> >(query); }
public static void ExplicitGetEnumeratorCapturesQueryOnContext() { var context = new TestableElasticContext(); var dummy = ((IEnumerable) new TestableElasticQuery<FakeClass>(context).Where(f => f.Name == "a")).GetEnumerator(); Assert.Equal(1, context.Requests.Count); }
public static void CustomTypes_Terms() { var context = new TestableElasticContext(); var identifiers = new[] { new Identifier("vALue1"), new Identifier("ValuE2") }; var queryInfo = context.Query<ClassWithIdentifier>().Where(x => identifiers.Contains(x.id)).ToQueryInfo(); // Also verifies that any value which gets JSON converted into a string gets lower-cased Assert.Equal(@"{""query"":{""filtered"":{""filter"":{""terms"":{""id"":[""value1!!"",""value2!!""]}}}}}", queryInfo.Query); }
public static void ImplicitGetEnumeratorCapturesQueryOnContext() { const string expectedBody = "requestwascaptured"; var context = new TestableElasticContext(); var dummy = new TestableElasticQuery<FakeClass>(context).Where(f => f.Name == expectedBody).ToArray(); Assert.Equal(1, context.Requests.Count); Assert.Contains(expectedBody, context.Requests[0].Query); }
public static void ImplicitGetEnumeratorCapturesQueryOnContext() { const string expectedBody = "requestwascaptured"; var context = new TestableElasticContext(); var dummy = new TestableElasticQuery <FakeClass>(context).Where(f => f.Name == expectedBody).ToArray(); Assert.Equal(1, context.Requests.Count); Assert.Contains(expectedBody, context.Requests[0].Query); }
public static void CustomTypes_Term() { var context = new TestableElasticContext(new MyCustomMapping()); var helloIdentifier = new Identifier("Hello"); var queryInfo = context.Query<ClassWithIdentifier>().Where(x => x.id == helloIdentifier).ToQueryInfo(); // Also verifies that any value which gets JSON converted into a string gets lower-cased Assert.Equal(@"{""query"":{""filtered"":{""filter"":{""term"":{""docWrapper.classWithIdentifier.id"":""hello!!""}}}}}", queryInfo.Query); }
public void ConstructorWithNoArgsSetsDefaultProperties() { var context = new TestableElasticContext(); Assert.NotNull(context.Connection); Assert.NotNull(context.Mapping); Assert.NotNull(context.Provider); Assert.NotNull(context.Requests); Assert.Equal(NullLog.Instance, context.Log); Assert.NotNull(context.RetryPolicy); }
public void CreateQueryOfTCreatesTestableElasticQueryOfTWithGivenExpression() { var expectedContext = new TestableElasticContext(); var expectedExpression = Expression.Constant("weebl"); var provider = new TestableElasticQueryProvider(expectedContext); var query = provider.CreateQuery<Sample>(expectedExpression); Assert.IsType<TestableElasticQuery<Sample>>(query); Assert.Same(expectedExpression, query.Expression); }
public void CreateQueryOfTCreatesTestableElasticQueryOfTWithGivenExpression() { var expectedContext = new TestableElasticContext(); var expectedExpression = Expression.Constant("weebl"); var provider = new TestableElasticQueryProvider(expectedContext); var query = provider.CreateQuery <Sample>(expectedExpression); Assert.IsType <TestableElasticQuery <Sample> >(query); Assert.Same(expectedExpression, query.Expression); }
public static void ConstructorWithAllArgSetsCorrectProperties() { var expectedExpression = Expression.Constant("oh hai"); var context = new TestableElasticContext(); var query = new TestableElasticQuery <FakeClass>(context, expectedExpression); Assert.Equal(context, query.Context); Assert.Equal(typeof(FakeClass), query.ElementType); Assert.Equal(context.Provider, query.Provider); Assert.Equal(expectedExpression, query.Expression); }
public void ExecuteOfTCompilesAndDynamicallyInvokesExpression() { const string expectedResult = "IwasEvaluated"; var expression = Expression.Constant(expectedResult); var expectedContext = new TestableElasticContext(); var provider = new TestableElasticQueryProvider(expectedContext); var actual = provider.Execute<string>(expression); Assert.Same(expectedResult, actual); }
public void ExecuteOfTCompilesAndDynamicallyInvokesExpression() { const string expectedResult = "IwasEvaluated"; var expression = Expression.Constant(expectedResult); var expectedContext = new TestableElasticContext(); var provider = new TestableElasticQueryProvider(expectedContext); var actual = provider.Execute <string>(expression); Assert.Same(expectedResult, actual); }
public static void ConstructorWithAllArgSetsCorrectProperties() { var expectedExpression = Expression.Constant("oh hai"); var context = new TestableElasticContext(); var query = new TestableElasticQuery<FakeClass>(context, expectedExpression); Assert.Equal(context, query.Context); Assert.Equal(typeof(FakeClass), query.ElementType); Assert.Equal(context.Provider, query.Provider); Assert.Equal(expectedExpression, query.Expression); }
public void SetDataWithArraySetsData() { var expected = new List<string> { "A", "B", "C" }; var context = new TestableElasticContext(); context.SetData(expected.ToArray()); var actual = context.Data<string>().ToList(); Assert.Equal(expected.Count, actual.Count); foreach (var item in expected) Assert.Contains(item, actual); }
public void ConstructorWithAllArgsSetsPropertiesFromParameters() { var expectedMapping = new ElasticMapping(); var expectedLog = new SpyLog(); const int expectedAttempts = 5; var expectedTimeout = TimeSpan.FromSeconds(21.3); var context = new TestableElasticContext(expectedMapping, expectedLog, expectedAttempts, expectedTimeout); Assert.NotNull(context.Connection); Assert.Equal(expectedMapping, context.Mapping); Assert.NotNull(context.Provider); Assert.NotNull(context.Requests); Assert.Equal(expectedLog, context.Log); var retryPolicy = Assert.IsType<RetryPolicy>(context.RetryPolicy); Assert.Equal(expectedAttempts, retryPolicy.MaxAttempts); }
public void ExecuteDefaultsElasticFieldsInsteadOfThrowing() { var expected = new List <string> { "A", "B", "C" }; var context = new TestableElasticContext(); context.SetData(expected.ToArray()); var actual = context.Query <string>().Select(d => Tuple.Create(ElasticFields.Id, ElasticFields.Score, d)).ToList(); Assert.Equal(expected.Count, actual.Count); foreach (var item in expected) { Assert.Single(actual, a => a.Item3 == item && a.Item2 == default(double) && a.Item1 == default(string)); } }
public void ConstructorWithAllArgsSetsPropertiesFromParameters() { var expectedMapping = new ElasticMapping(); var expectedLog = new SpyLog(); const int expectedAttempts = 5; var expectedTimeout = TimeSpan.FromSeconds(21.3); var context = new TestableElasticContext(expectedMapping, expectedLog, expectedAttempts, expectedTimeout); Assert.NotNull(context.Connection); Assert.Equal(expectedMapping, context.Mapping); Assert.NotNull(context.Provider); Assert.NotNull(context.Requests); Assert.Equal(expectedLog, context.Log); var retryPolicy = Assert.IsType <RetryPolicy>(context.RetryPolicy); Assert.Equal(expectedAttempts, retryPolicy.MaxAttempts); }
public void SetDataWithArraySetsData() { var expected = new List <string> { "A", "B", "C" }; var context = new TestableElasticContext(); context.SetData(expected.ToArray()); var actual = context.Data <string>().ToList(); Assert.Equal(expected.Count, actual.Count); foreach (var item in actual) { Assert.Contains(item, actual); } }
public void ExecuteDefaultsElasticFieldsInsteadOfThrowing() { var expected = new List<string> { "A", "B", "C" }; var context = new TestableElasticContext(); context.SetData(expected.ToArray()); var actual = context.Query<string>().Select(d => Tuple.Create(ElasticFields.Id, ElasticFields.Score, d)).ToList(); Assert.Equal(expected.Count, actual.Count); foreach (var item in expected) Assert.Single(actual, a => a.Item3 == item && a.Item2 == default(double) && a.Item1 == default(string)); }