Exemplo n.º 1
0
            public void GroupByMetadataKey()
            {
                // Given
                List <int>  groupKey = new List <int>();
                Engine      engine   = new Engine();
                CountModule count    = new CountModule("A")
                {
                    AdditionalOutputs = 7
                };

                Core.Modules.Metadata.Meta meta = new Core.Modules.Metadata.Meta("GroupMetadata", (d, c) => new[] { d.Get <int>("A") % 3, 3 });
                GroupByMany groupByMany         = new GroupByMany("GroupMetadata", count, meta);
                Execute     gatherData          = new Execute((d, c) =>
                {
                    groupKey.Add(d.Get <int>(Keys.GroupKey));
                    return(null);
                }, false);

                engine.Pipelines.Add(groupByMany, gatherData);

                // When
                engine.Execute();

                // Then
                CollectionAssert.AreEquivalent(new[] { 0, 1, 2, 3 }, groupKey);
            }
Exemplo n.º 2
0
            public void ExcludesDocumentsThatDontMatchPredicate()
            {
                // Given
                List <int>  groupKey = new List <int>();
                Engine      engine   = new Engine();
                CountModule count    = new CountModule("A")
                {
                    AdditionalOutputs = 7
                };
                GroupByMany groupByMany = new GroupByMany((d, c) => new[] { d.Get <int>("A") % 3, 3 }, count)
                                          .Where((d, c) => d.Get <int>("A") % 3 != 0);
                Execute gatherData = new Execute((d, c) =>
                {
                    groupKey.Add(d.Get <int>(Keys.GroupKey));
                    return(null);
                }, false);

                engine.Pipelines.Add(groupByMany, gatherData);

                // When
                engine.Execute();

                // Then
                CollectionAssert.AreEquivalent(new[] { 1, 2, 3 }, groupKey);
            }
Exemplo n.º 3
0
            public void SetsDocumentsInMetadata()
            {
                // Given
                List <IList <string> > content = new List <IList <string> >();
                Engine      engine             = new Engine();
                CountModule count = new CountModule("A")
                {
                    AdditionalOutputs = 7
                };
                GroupByMany groupByMany = new GroupByMany((d, c) => new[] { d.Get <int>("A") % 3, 3 }, count);
                OrderBy     orderBy     = new OrderBy((d, c) => d.Get <int>(Keys.GroupKey));
                Execute     gatherData  = new Execute((d, c) =>
                {
                    content.Add(d.Get <IList <IDocument> >(Keys.GroupDocuments).Select(x => x.Content).ToList());
                    return(null);
                }, false);

                engine.Pipelines.Add(groupByMany, orderBy, gatherData);

                // When
                engine.Execute();

                // Then
                Assert.AreEqual(4, content.Count);
                CollectionAssert.AreEquivalent(new[] { "3", "6" }, content[0]);
                CollectionAssert.AreEquivalent(new[] { "1", "4", "7" }, content[1]);
                CollectionAssert.AreEquivalent(new[] { "2", "5", "8" }, content[2]);
                CollectionAssert.AreEquivalent(new[] { "1", "2", "3", "4", "5", "6", "7", "8" }, content[3]);
            }
Exemplo n.º 4
0
            public void SetsDocumentsInMetadata()
            {
                // Given
                List<IList<string>> content = new List<IList<string>>();
                Engine engine = new Engine();
                CountModule count = new CountModule("A")
                {
                    AdditionalOutputs = 7
                };
                GroupByMany groupByMany = new GroupByMany((d, c) => new[] { d.Get<int>("A") % 3, 3 }, count);
                OrderBy orderBy = new OrderBy((d, c) => d.Get<int>(Keys.GroupKey));
                Execute gatherData = new Execute((d, c) =>
                {
                    content.Add(d.Get<IList<IDocument>>(Keys.GroupDocuments).Select(x => x.Content).ToList());
                    return null;
                });
                engine.Pipelines.Add(groupByMany, orderBy, gatherData);

                // When
                engine.Execute();

                // Then
                Assert.AreEqual(4, content.Count);
                CollectionAssert.AreEquivalent(new[] {"3", "6"}, content[0]);
                CollectionAssert.AreEquivalent(new[] {"1", "4", "7"}, content[1]);
                CollectionAssert.AreEquivalent(new[] {"2", "5", "8"}, content[2]);
                CollectionAssert.AreEquivalent(new[] { "1", "2", "3", "4", "5", "6", "7", "8" }, content[3]);
            }
Exemplo n.º 5
0
            public void GroupByMetadataKeyWithMissingMetadata()
            {
                // Given
                List <int>  groupKey = new List <int>();
                Engine      engine   = new Engine();
                CountModule count    = new CountModule("A")
                {
                    AdditionalOutputs = 7
                };
                Execute meta = new Execute((d, c) =>
                {
                    int groupMetadata = d.Get <int>("A") % 3;
                    return(groupMetadata == 0 ? d : c.GetDocument(d, new MetadataItems {
                        { "GroupMetadata", new[] { groupMetadata, 3 } }
                    }));
                }, false);
                GroupByMany groupByMany = new GroupByMany("GroupMetadata", count, meta);
                Execute     gatherData  = new Execute((d, c) =>
                {
                    groupKey.Add(d.Get <int>(Keys.GroupKey));
                    return(null);
                }, false);

                engine.Pipelines.Add(groupByMany, gatherData);

                // When
                engine.Execute();

                // Then
                CollectionAssert.AreEquivalent(new[] { 1, 2, 3 }, groupKey);
            }
            public void CaseInsensitiveStringComparer()
            {
                // Given
                List <object> groupKey = new List <object>();
                Engine        engine   = new Engine();
                Execute       meta     = new Execute(
                    (d, c) => new IDocument[]
                {
                    c.GetDocument(d, new MetadataItems {
                        { "Tag", new[] { "A", "b" } }
                    }),
                    c.GetDocument(d, new MetadataItems {
                        { "Tag", new[] { "B" } }
                    }),
                    c.GetDocument(d, new MetadataItems {
                        { "Tag", "C" }
                    }),
                    c.GetDocument(d, new MetadataItems {
                        { "Tag", new[] { "c" } }
                    }),
                    c.GetDocument(d, new MetadataItems {
                        { "Tag", new[] { 1 } }
                    }),
                    c.GetDocument(d, new MetadataItems {
                        { "Tag", "1" }
                    })
                }, false);
                GroupByMany groupByMany = new GroupByMany("Tag", meta).WithComparer(StringComparer.OrdinalIgnoreCase);
                Execute     gatherData  = new Execute(
                    (d, c) =>
                {
                    groupKey.Add(d.Get(Keys.GroupKey));
                    return(null);
                }, false);

                engine.Pipelines.Add(groupByMany, gatherData);

                // When
                engine.Execute();

                // Then
                CollectionAssert.AreEquivalent(new object[] { "A", "b", "C", 1 }, groupKey);
            }
Exemplo n.º 7
0
            public void SetsCorrectMetadata()
            {
                // Given
                List<int> groupKey = new List<int>();
                Engine engine = new Engine();
                CountModule count = new CountModule("A")
                {
                    AdditionalOutputs = 7
                };
                GroupByMany groupByMany = new GroupByMany((d, c) => new [] { d.Get<int>("A")%3, 3 }, count);
                Execute gatherData = new Execute((d, c) =>
                {
                    groupKey.Add(d.Get<int>(Keys.GroupKey));
                    return d;
                });
                engine.Pipelines.Add(groupByMany, gatherData);

                // When
                engine.Execute();

                // Then
                CollectionAssert.AreEquivalent(new[] {0, 1, 2, 3}, groupKey);
            }
Exemplo n.º 8
0
            public void SetsCorrectMetadata()
            {
                // Given
                List <int>  groupKey = new List <int>();
                Engine      engine   = new Engine();
                CountModule count    = new CountModule("A")
                {
                    AdditionalOutputs = 7
                };
                GroupByMany groupByMany = new GroupByMany((d, c) => new [] { d.Get <int>("A") % 3, 3 }, count);
                Execute     gatherData  = new Execute((d, c) =>
                {
                    groupKey.Add(d.Get <int>(Keys.GroupKey));
                    return(d);
                });

                engine.Pipelines.Add(groupByMany, gatherData);

                // When
                engine.Execute();

                // Then
                CollectionAssert.AreEquivalent(new[] { 0, 1, 2, 3 }, groupKey);
            }
Exemplo n.º 9
0
            public void ExcludesDocumentsThatDontMatchPredicate()
            {
                // Given
                List<int> groupKey = new List<int>();
                Engine engine = new Engine();
                CountModule count = new CountModule("A")
                {
                    AdditionalOutputs = 7
                };
                GroupByMany groupByMany = new GroupByMany((d, c) => new[] { d.Get<int>("A") % 3, 3 }, count)
                    .Where((d, c) => d.Get<int>("A") % 3 != 0);
                Execute gatherData = new Execute((d, c) =>
                {
                    groupKey.Add(d.Get<int>(Keys.GroupKey));
                    return null;
                });
                engine.Pipelines.Add(groupByMany, gatherData);

                // When
                engine.Execute();

                // Then
                CollectionAssert.AreEquivalent(new[] { 1, 2, 3 }, groupKey);
            }
Exemplo n.º 10
0
            public void GroupByMetadataKeyWithMissingMetadata()
            {
                // Given
                List<int> groupKey = new List<int>();
                Engine engine = new Engine();
                CountModule count = new CountModule("A")
                {
                    AdditionalOutputs = 7
                };
                Execute meta = new Execute((d, c) =>
                {
                    int groupMetadata = d.Get<int>("A") % 3;
                    return groupMetadata == 0 ? d : c.GetDocument(d, new MetadataItems { {"GroupMetadata", new[] { groupMetadata, 3 } } });
                });
                GroupByMany groupByMany = new GroupByMany("GroupMetadata", count, meta);
                Execute gatherData = new Execute((d, c) =>
                {
                    groupKey.Add(d.Get<int>(Keys.GroupKey));
                    return null;
                });
                engine.Pipelines.Add(groupByMany, gatherData);

                // When
                engine.Execute();

                // Then
                CollectionAssert.AreEquivalent(new[] { 1, 2, 3 }, groupKey);
            }