public void SingleThrowsInvalidOperationExceptionGivenNoResults()
        {
            var response = MaterializerTestHelper.CreateSampleResponse(0);
            var materializer = new ElasticOneHitMaterializer(o => o, typeof(SampleClass), throwIfMoreThanOne: true, defaultIfNone: false);

            Assert.Throws<InvalidOperationException>(() => materializer.Materialize(response));
        }
        public void FirstOrDefaultReturnsDefaultGivenNoResults()
        {
            var response = MaterializerTestHelper.CreateSampleResponse(0);
            var materializer = new ElasticOneHitMaterializer(MaterializerTestHelper.ItemCreator, typeof(SampleClass), throwIfMoreThanOne: false, defaultIfNone: true);

            var actual = materializer.Materialize(response);

            Assert.Null(actual);
        }
        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 SingleReturnsOnlyResultGivenOneResult()
        {
            var response = MaterializerTestHelper.CreateSampleResponse(1);
            var materializer = new ElasticOneHitMaterializer(o => o, typeof(SampleClass), throwIfMoreThanOne: true, defaultIfNone: true);

            var actual = materializer.Materialize(response);

            Assert.Same(response.hits.hits[0], actual);
        }
        public void SingleOrDefaultReturnsDefaultGivenNoResultsForAValueType()
        {
            var response = MaterializerTestHelper.CreateSampleResponse(0);
            var materializer = new ElasticOneHitMaterializer(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 ElasticOneHitMaterializer(o => o, typeof(SampleClass), throwIfMoreThanOne: true, defaultIfNone: true);

            var actual = materializer.Materialize(response);

            Assert.Null(actual);
        }