示例#1
0
            public async Task OrdersThenByInAscendingOrder()
            {
                // Given
                List <string> content = new List <string>();
                CountModule   count   = new CountModule("A")
                {
                    AdditionalOutputs   = 4,
                    EnsureInputDocument = true
                };
                CountModule count2 = new CountModule("B")
                {
                    AdditionalOutputs = 1
                };
                OrderDocuments orderBy = new OrderDocuments(Config.FromDocument <int>("A"))
                                         .ThenBy(Config.FromDocument(d => d.GetInt("B")));
                ForEachDocument gatherData = new ExecuteConfig(
                    Config.FromDocument(async d =>
                {
                    content.Add(await d.GetContentStringAsync());
                    return((IDocument)null);
                })).ForEachDocument();

                // When
                await ExecuteAsync(count, count2, orderBy, gatherData);

                // Then
                Assert.AreEqual(10, content.Count); // (4+1) * (21+1)
                CollectionAssert.AreEqual(new[] { "11", "12", "23", "24", "35", "36", "47", "48", "59", "510" }, content);
            }
示例#2
0
            public async Task OrdersByIndexThenOrderByDefault()
            {
                // Given
                TestDocument a = new TestDocument
                {
                    { "Index", 2 },
                    { "Order", 1 }
                };
                TestDocument b = new TestDocument
                {
                    { "Index", 1 },
                    { "Order", 2 }
                };
                TestDocument c = new TestDocument
                {
                    { "Index", 1 },
                    { "Order", 1 }
                };
                OrderDocuments order = new OrderDocuments();

                // When
                IReadOnlyList <IDocument> results = await ExecuteAsync(new[] { a, b, c }, order);

                // Then
                results.ShouldBe(new[] { c, b, a });
            }
示例#3
0
            public async Task OrdersInDescendingOrder()
            {
                // Given
                List <string> content = new List <string>();
                CountModule   count   = new CountModule("A")
                {
                    AdditionalOutputs   = 4,
                    EnsureInputDocument = true
                };
                CountModule count2 = new CountModule("A")
                {
                    AdditionalOutputs   = 2,
                    EnsureInputDocument = true
                };
                ConcatDocuments concat     = new ConcatDocuments(count2);
                OrderDocuments  orderBy    = new OrderDocuments(Config.FromDocument <int>("A")).Descending();
                ForEachDocument gatherData = new ExecuteConfig(
                    Config.FromDocument(async d =>
                {
                    content.Add(await d.GetContentStringAsync());
                    return((IDocument)null);
                })).ForEachDocument();

                // When
                await ExecuteAsync(count, concat, orderBy, gatherData);

                // Then
                content.Count.ShouldBe(20);
                content.ShouldBe(new[] { "515", "514", "513", "412", "411", "410", "39", "38", "37", "26", "5", "25", "4", "24", "3", "13", "2", "12", "1", "11" });
            }
            public async Task SetsDocumentsInMetadata()
            {
                // Given
                List <IList <string> > content = new List <IList <string> >();
                CountModule            count   = new CountModule("A")
                {
                    AdditionalOutputs   = 7,
                    EnsureInputDocument = true
                };
                GroupDocuments  groupByMany = new GroupDocuments(Config.FromDocument(d => new[] { d.GetInt("A") % 3, 3 }));
                OrderDocuments  orderBy     = new OrderDocuments(Config.FromDocument <int>(Keys.GroupKey));
                ForEachDocument gatherData  = new ExecuteConfig(
                    Config.FromDocument(async d =>
                {
                    List <string> groupContent = await d.GetChildren()
                                                 .ToAsyncEnumerable()
                                                 .SelectAwait(async x => await x.GetContentStringAsync())
                                                 .ToListAsync();
                    content.Add(groupContent.ToList());
                    return((object)null);
                })).ForEachDocument();

                // When
                IReadOnlyList <IDocument> results = await ExecuteAsync(count, groupByMany, orderBy, gatherData);

                // 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]);
            }
示例#5
0
            public async Task OrdersUsingCommonTypeConversion()
            {
                // Given
                TestDocument a = new TestDocument
                {
                    { "Foo", "1/1/2010" }
                };
                TestDocument c = new TestDocument
                {
                    { "Foo", new DateTime(2009, 1, 1) }
                };
                OrderDocuments order = new OrderDocuments("Foo");

                // When
                IReadOnlyList <IDocument> results = await ExecuteAsync(new[] { a, c }, order);

                // Then
                results.ShouldBe(new[] { c, a });
            }
示例#6
0
            public async Task OrdersUsingMetadataKey()
            {
                // Given
                TestDocument a = new TestDocument
                {
                    { "Foo", 5 }
                };
                TestDocument b = new TestDocument();
                TestDocument c = new TestDocument
                {
                    { "Foo", 1 }
                };
                OrderDocuments order = new OrderDocuments("Foo");

                // When
                IReadOnlyList <IDocument> results = await ExecuteAsync(new[] { a, b, c }, order);

                // Then
                results.ShouldBe(new[] { b, c, a });
            }
示例#7
0
            public async Task OrdersUsingTypedComparison()
            {
                // Given
                TestDocument a = new TestDocument
                {
                    { "Foo", 5 }
                };
                TestDocument b = new TestDocument();
                TestDocument c = new TestDocument
                {
                    { "Foo", "1" }
                };
                OrderDocuments order = new OrderDocuments(Config.FromDocument(x => x.Get("Foo")))
                                       .WithComparison <int>((x, y) => Comparer <int> .Default.Compare(x, y));

                // When
                IReadOnlyList <IDocument> results = await ExecuteAsync(new[] { a, b, c }, order);

                // Then
                results.ShouldBe(new[] { b, c, a });
            }
示例#8
0
            public async Task OrdersByIndexAsIntByDefault()
            {
                // Given
                TestDocument a = new TestDocument
                {
                    { "Index", "1" }
                };
                TestDocument b = new TestDocument
                {
                    { "Index", "10" }
                };
                TestDocument c = new TestDocument
                {
                    { "Index", "2" }
                };
                OrderDocuments order = new OrderDocuments();

                // When
                IReadOnlyList <IDocument> results = await ExecuteAsync(new[] { a, b, c }, order);

                // Then
                results.ShouldBe(new[] { a, c, b });
            }