public static void MaterializeCreatesListFromValidJson()
        {
            const string expectedKey = "some key";

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

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

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

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

            Assert.Single(actualList);

            var statisticalRow = Assert.IsType <AggregateStatisticalRow>(actualList[0]);

            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)));
        }
        public static void MaterializeCreatesEmptyListIfFacetsIsEmpty()
        {
            var materializer = new ListTermlessFacetsElasticMaterializer(defaultMaterializer, typeof(SampleClass), "");

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

            var actualList = Assert.IsType<List<SampleClass>>(actual);
            Assert.Empty(actualList);
        }
        public void MaterializeWithNoFacetsReturnsBlankList()
        {
            var materializer = new ListTermlessFacetsElasticMaterializer(r => r, typeof(SampleClass), typeof(string));
            var response = new ElasticResponse { facets = new JObject() };

            var actual = materializer.Materialize(response);

            var actualList = Assert.IsType<List<SampleClass>>(actual);
            Assert.Empty(actualList);
        }
        public static void MaterializeCreatesEmptyListIfFacetsIsEmpty()
        {
            var materializer = new ListTermlessFacetsElasticMaterializer(defaultMaterializer, typeof(SampleClass), "");

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

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

            Assert.Empty(actualList);
        }
Ejemplo n.º 5
0
        public void MaterializeWithNoFacetsReturnsBlankList()
        {
            var materializer = new ListTermlessFacetsElasticMaterializer(r => r, typeof(SampleClass), typeof(string));
            var response     = new ElasticResponse {
                facets = new JObject()
            };

            var actual = materializer.Materialize(response);

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

            Assert.Empty(actualList);
        }
        public static void MaterializeCreatesListFromValidJson()
        {
            const string expectedKey = "some key";

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

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

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

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

            var statisticalRow = Assert.IsType<AggregateStatisticalRow>(actualList[0]);
            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)));
        }
        public static void Materialize_GuardClauses()
        {
            var materializer = new ListTermlessFacetsElasticMaterializer(defaultMaterializer, typeof(SampleClass), "");

            Assert.Throws <ArgumentNullException>(() => materializer.Materialize(null));
        }
        public static void Materialize_GuardClauses()
        {
            var materializer = new ListTermlessFacetsElasticMaterializer(defaultMaterializer, typeof(SampleClass), "");

            Assert.Throws<ArgumentNullException>(() => materializer.Materialize(null));
        }
        public void MaterializeThrowsArgumentNullExceptionWhenElasticResponseIsNull()
        {
            var materializer = new ListTermlessFacetsElasticMaterializer(r => r, typeof(SampleClass), typeof(string));

            Assert.Throws<ArgumentNullException>(() => materializer.Materialize(null));
        }
Ejemplo n.º 10
0
        public void MaterializeThrowsArgumentNullExceptionWhenElasticResponseIsNull()
        {
            var materializer = new ListTermlessFacetsElasticMaterializer(r => r, typeof(SampleClass), typeof(string));

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