Exemple #1
0
        public void FirstThrowsInvalidOperationExceptionGivenNoResults()
        {
            var response     = MaterializerTestHelper.CreateSampleResponse(0);
            var materializer = new ElasticOneHitMaterializer(o => o, typeof(Hit), throwIfMoreThanOne: false, defaultIfNone: false);

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

            var actual = materializer.Materialize(response);

            Assert.Same(response.hits.hits[0], actual);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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);
        }