Exemplo n.º 1
0
        public static void Materialize_GuardClauses()
        {
            var materializer = new ListTermFacetsElasticMaterializer(defaultMaterializer, typeof(SampleClass),
                                                                     typeof(string));

            Assert.Throws <ArgumentNullException>(() => materializer.Materialize(null));
        }
Exemplo n.º 2
0
        public static void ManyMaterializesJsonIntoAggregateFields()
        {
            // Materializer should be able to handle inefficient terms + terms_stats combination
            var facets = JObject.Parse(
                "{ \"GroupKey\": { \"_type\": \"terms\", \"terms\" : [ " +
                "{ \"term\": \"suppliers/7\", \"count\": 5 }, " +
                "{ \"term\": \"suppliers/8\", \"count\": 4 } ] }, " +
                " \"unitsInStock\": { \"_type\" : \"terms_stats\", \"terms\" : [ " +
                "{ \"term\": \"suppliers/7\", \"count\": 5, \"max\": 42.0 }, " +
                "{ \"term\": \"suppliers/8\", \"count\": 4, \"max\": 40.0 } ] } }");

            var materializer = new ListTermFacetsElasticMaterializer(defaultMaterializer, typeof(AggregateRow), typeof(string));

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

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

            Assert.Equal(2, actualList.Count);
            Assert.All(actualList, a => Assert.IsType <AggregateTermRow>(a));

            var testItems = actualList.OfType <AggregateTermRow>().OrderBy(r => r.Key).ToArray();

            Assert.Equal("suppliers/7", testItems[0].Key);
            Assert.Equal(3, testItems[0].Fields.Count);
            Assert.Single(testItems[0].Fields, f => f.Name == "GroupKey" && f.Operation == "count" && f.Token.ToObject <int>() == 5);
            Assert.Single(testItems[0].Fields, f => f.Name == "unitsInStock" && f.Operation == "max" && Math.Abs(f.Token.ToObject <double>() - 42.0d) < 0.01);

            Assert.Equal("suppliers/8", testItems[1].Key);
            Assert.Equal(3, testItems[1].Fields.Count);
            Assert.Single(testItems[1].Fields, f => f.Name == "GroupKey" && f.Operation == "count" && f.Token.ToObject <int>() == 4);
            Assert.Single(testItems[1].Fields, f => f.Name == "unitsInStock" && f.Operation == "max" && Math.Abs(f.Token.ToObject <double>() - 40.0d) < 0.01);
        }
Exemplo n.º 3
0
        public static void CanMaterializeDateTimeKeys()
        {
            var facets = JObject.Parse(
                "{ \"GroupKey\": { \"_type\": \"terms\", \"terms\" : [ " +
                "{ \"term\": 1428394929000, \"count\": 5 }, " +
                "{ \"term\": 1428456720000, \"count\": 4 } ] } }");

            var materializer = new ListTermFacetsElasticMaterializer(defaultMaterializer, typeof(AggregateRow), typeof(DateTime));

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

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

            Assert.Equal(2, actualList.Count);
            Assert.All(actualList, a => Assert.IsType <AggregateTermRow>(a));

            var testItems = actualList.OfType <AggregateTermRow>().OrderBy(r => r.Key).ToArray();

            Assert.Equal(new DateTime(2015, 04, 07, 08, 22, 09, DateTimeKind.Utc), testItems[0].Key);
            Assert.Equal(1, testItems[0].Fields.Count);
            Assert.Single(testItems[0].Fields, f => f.Name == "GroupKey" && f.Operation == "count" && f.Token.ToObject <int>() == 5);

            Assert.Equal(new DateTime(2015, 04, 08, 01, 32, 00, DateTimeKind.Utc), testItems[1].Key);
            Assert.Equal(1, testItems[1].Fields.Count);
            Assert.Single(testItems[1].Fields, f => f.Name == "GroupKey" && f.Operation == "count" && f.Token.ToObject <int>() == 4);
        }
        public static void ManyMaterializesJsonIntoAggregateFields()
        {
            // Materializer should be able to handle inefficient terms + terms_stats combination
            var facets = JObject.Parse(
                "{ \"GroupKey\": { \"_type\": \"terms\", \"terms\" : [ " +
                    "{ \"term\": \"suppliers/7\", \"count\": 5 }, " +
                    "{ \"term\": \"suppliers/8\", \"count\": 4 } ] }, " +
                " \"unitsInStock\": { \"_type\" : \"terms_stats\", \"terms\" : [ " +
                    "{ \"term\": \"suppliers/7\", \"count\": 5, \"max\": 42.0 }, " +
                    "{ \"term\": \"suppliers/8\", \"count\": 4, \"max\": 40.0 } ] } }");

            var materializer = new ListTermFacetsElasticMaterializer(defaultMaterializer, typeof(AggregateRow), typeof(string));

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

            var actualList = Assert.IsType<List<AggregateRow>>(actual);
            Assert.Equal(2, actualList.Count);
            Assert.All(actualList, a => Assert.IsType<AggregateTermRow>(a));

            var testItems = actualList.OfType<AggregateTermRow>().OrderBy(r => r.Key).ToArray();
            Assert.Equal("suppliers/7", testItems[0].Key);
            Assert.Equal(3, testItems[0].Fields.Count);
            Assert.Single(testItems[0].Fields, f => f.Name == "GroupKey" && f.Operation == "count" && f.Token.ToObject<int>() == 5);
            Assert.Single(testItems[0].Fields, f => f.Name == "unitsInStock" && f.Operation == "max" && Math.Abs(f.Token.ToObject<double>() - 42.0d) < 0.01);

            Assert.Equal("suppliers/8", testItems[1].Key);
            Assert.Equal(3, testItems[1].Fields.Count);
            Assert.Single(testItems[1].Fields, f => f.Name == "GroupKey" && f.Operation == "count" && f.Token.ToObject<int>() == 4);
            Assert.Single(testItems[1].Fields, f => f.Name == "unitsInStock" && f.Operation == "max" && Math.Abs(f.Token.ToObject<double>() - 40.0d) < 0.01);
        }
        public static void Materialize_GuardClauses()
        {
            var materializer = new ListTermFacetsElasticMaterializer(defaultMaterializer, typeof(SampleClass),
                typeof(string));

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

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

            var actualList = Assert.IsType<List<SampleClass>>(actual);
            Assert.Empty(actualList);
        }
Exemplo n.º 7
0
        public static void MaterializeCreatesEmptyListIfFacetsIsEmpty()
        {
            var materializer = new ListTermFacetsElasticMaterializer(defaultMaterializer, typeof(SampleClass),
                                                                     typeof(string));

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

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

            Assert.Empty(actualList);
        }
        public static void CanMaterializeDateTimeKeys()
        {
            var facets = JObject.Parse(
                "{ \"GroupKey\": { \"_type\": \"terms\", \"terms\" : [ " +
                    "{ \"term\": 1428394929000, \"count\": 5 }, " +
                    "{ \"term\": 1428456720000, \"count\": 4 } ] } }");

            var materializer = new ListTermFacetsElasticMaterializer(defaultMaterializer, typeof(AggregateRow), typeof(DateTime));

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

            var actualList = Assert.IsType<List<AggregateRow>>(actual);
            Assert.Equal(2, actualList.Count);
            Assert.All(actualList, a => Assert.IsType<AggregateTermRow>(a));

            var testItems = actualList.OfType<AggregateTermRow>().OrderBy(r => r.Key).ToArray();
            Assert.Equal(new DateTime(2015,04,07,08,22,09, DateTimeKind.Utc), testItems[0].Key);
            Assert.Equal(1, testItems[0].Fields.Count);
            Assert.Single(testItems[0].Fields, f => f.Name == "GroupKey" && f.Operation == "count" && f.Token.ToObject<int>() == 5);

            Assert.Equal(new DateTime(2015, 04, 08, 01, 32, 00, DateTimeKind.Utc), testItems[1].Key);
            Assert.Equal(1, testItems[1].Fields.Count);
            Assert.Single(testItems[1].Fields, f => f.Name == "GroupKey" && f.Operation == "count" && f.Token.ToObject<int>() == 4);
        }