public void HighlightMaterializerTests_Throws_If_Not_Chained()
        {
            var response     = MaterializerTestHelper.CreateSampleResponse(1);
            var materializer = new HighlightElasticMaterializer(null);

            Assert.Throws <ArgumentNullException>(() => materializer.Materialize(response));
        }
        public void FirstThrowsInvalidOperationExceptionGivenNoResults()
        {
            var response     = MaterializerTestHelper.CreateSampleResponse(0);
            var materializer = new OneHitElasticMaterializer(o => o, typeof(Hit), throwIfMoreThanOne: false, defaultIfNone: false);

            Assert.Throws <InvalidOperationException>(() => materializer.Materialize(response));
        }
Ejemplo n.º 3
0
        public void SingleThrowsInvalidOperationExceptionGivenTwoResults()
        {
            var response     = MaterializerTestHelper.CreateSampleResponse(2);
            var materializer = new ElasticOneHitMaterializer(o => o, typeof(SampleClass), throwIfMoreThanOne: true, defaultIfNone: false);

            Assert.Throws <InvalidOperationException>(() => materializer.Materialize(response));
        }
        public void FirstReturnsOnlyResultGivenOneResult()
        {
            var response     = MaterializerTestHelper.CreateSampleResponse(1);
            var materializer = new OneHitElasticMaterializer(o => o, typeof(Hit), throwIfMoreThanOne: false, defaultIfNone: true);

            var actual = materializer.Materialize(response);

            Assert.Same(response.hits.hits[0], actual);
        }
        public void FirstOrDefaultReturnsDefaultGivenNoResults()
        {
            var response     = MaterializerTestHelper.CreateSampleResponse(0);
            var materializer = new OneHitElasticMaterializer(MaterializerTestHelper.ItemCreator, typeof(SampleClass), throwIfMoreThanOne: false, defaultIfNone: true);

            var actual = materializer.Materialize(response);

            Assert.Null(actual);
        }
        public void SingleOrDefaultReturnsDefaultGivenNoResultsForAValueType()
        {
            var response     = MaterializerTestHelper.CreateSampleResponse(0);
            var materializer = new OneHitElasticMaterializer(o => o, typeof(int), throwIfMoreThanOne: true, defaultIfNone: true);

            var actual = materializer.Materialize(response);

            Assert.Equal(default(int), actual);
        }
        public void SingleOrDefaultReturnsNullGivenNoResultsForAReferenceType()
        {
            var response     = MaterializerTestHelper.CreateSampleResponse(0);
            var materializer = new OneHitElasticMaterializer(o => o, typeof(SampleClass), throwIfMoreThanOne: true, defaultIfNone: true);

            var actual = materializer.Materialize(response);

            Assert.Null(actual);
        }
Ejemplo n.º 8
0
        public void FirstReturnsFirstResultGivenTwoResults()
        {
            var response     = MaterializerTestHelper.CreateSampleResponse(2);
            var materializer = new ElasticOneHitMaterializer(o => o, typeof(SampleClass), throwIfMoreThanOne: false, defaultIfNone: false);

            var actual = materializer.Materialize(response);

            Assert.Same(response.hits.hits[0], actual);
        }
        public void HighlightMaterializerTests_Must_Recognize_Highlighted_Result()
        {
            var response     = MaterializerTestHelper.CreateSampleResponseWithHighlight(1);
            var materializer = new HighlightElasticMaterializer(new ListHitsElasticMaterializer(DefaultBySourceItemCreator, typeof(SampleClassWithHighlight)));

            var result = materializer.Materialize(response);

            var actualList  = Assert.IsAssignableFrom <IEnumerable <SampleClassWithHighlight> >(result);
            var highlighted = actualList.First().SampleField_Highlight;

            Assert.NotNull(highlighted);
        }
Ejemplo n.º 10
0
        public void ManyOfTMaterializesObjects()
        {
            var hits         = MaterializerTestHelper.CreateSampleHits(3);
            var materialized = ListHitsElasticMaterializer.Many <SampleClass>(hits, MaterializerTestHelper.ItemCreator);

            Assert.Equal(hits.Count, materialized.Count);
            var index = 0;

            foreach (var hit in hits)
            {
                Assert.Equal(hit.fields["someField"], materialized[index++].SampleField);
            }
        }
Ejemplo n.º 11
0
        public void ManyMaterializesObjects()
        {
            var response = MaterializerTestHelper.CreateSampleResponse(10);
            var expected = response.hits.hits;

            var materializer = new ListHitsElasticMaterializer(MaterializerTestHelper.ItemCreator, typeof(SampleClass));
            var actual       = materializer.Materialize(response);

            var actualList = Assert.IsType <List <SampleClass> >(actual);

            Assert.Equal(expected.Count, actualList.Count);
            var index = 0;

            foreach (var hit in expected)
            {
                Assert.Equal(hit.fields["someField"], actualList[index++].SampleField);
            }
        }