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)); }
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); }
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 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 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); }