Materialize() public method

Materialize a single object from the response using the projector or return a default value based on the element type.
public Materialize ( ElasticLinq.Response.Model.ElasticResponse response ) : object
response ElasticLinq.Response.Model.ElasticResponse The to materialize facets from.
return object
コード例 #1
0
        public static void MaterializeCreatesDefaultValueIfFacetsIsEmpty()
        {
            var materializer = new TermlessFacetElasticMaterializer(defaultMaterializer, typeof(SampleClass), "");

            var actual = materializer.Materialize(new ElasticResponse { facets = new JObject() });

            Assert.Null(actual);
        }
コード例 #2
0
        public static void ManyMaterializesDefaultValueGivenNoValidFacets()
        {
            var facets = JObject.Parse(
                "{ \"GroupKey\": { \"_type\": \"term_filter\", \"count\": 77 }," +
                " \"unitsInStock\": { \"_type\": \"term_stats\", \"count\": 77, \"total\": 3119.0, \"max\": 125.0 } }");

            var materializer = new TermlessFacetElasticMaterializer(a => a.GetValue("", "", typeof(int)), typeof(int), null);

            var actual = materializer.Materialize(new ElasticResponse { facets = facets });

            Assert.Equal(default(int), actual);
        }
コード例 #3
0
        public static void ManyMaterializesJsonIntoAggregateFields()
        {
            const string expectedKey = "some key";

            // Materializer should be able to handle inefficient filter + statistical combination
            var facets = JObject.Parse(
                "{ \"GroupKey\": { \"_type\": \"filter\", \"count\": 77 }," +
                " \"unitsInStock\": { \"_type\": \"statistical\", \"count\": 77, \"total\": 3119.0, \"max\": 125.0 } }");

            var materializer = new TermlessFacetElasticMaterializer(defaultMaterializer, typeof(AggregateRow), expectedKey);

            var actual = materializer.Materialize(new ElasticResponse { facets = facets });

            var statisticalRow = Assert.IsType<AggregateStatisticalRow>(actual);
            Assert.Equal(expectedKey, statisticalRow.Key);
            Assert.Equal(77, statisticalRow.GetValue("GroupKey", "count", typeof(int)));
            Assert.Equal(3119.0d, statisticalRow.GetValue("unitsInStock", "total", typeof(double)));
            Assert.Equal(125.0d, statisticalRow.GetValue("unitsInStock", "max", typeof(double)));
        }
コード例 #4
0
        public static void Materialize_GuardClauses()
        {
            var materializer = new TermlessFacetElasticMaterializer(defaultMaterializer, typeof(SampleClass), "");

            Assert.Throws<ArgumentNullException>(() => materializer.Materialize(null));
        }