Beispiel #1
0
        private async void DownloadCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            var docs = await callback.GetAvailableDocumentsAsync();

            var documentsWindow = new DocumentsWindow(docs);

            documentsWindow.Closed += documentsWindow_Closed;

            documentsWindow.Show();
        }
        public void Use_documents_window_to_obtain_cumulative_and_maximum_quantity_for_each_year_example_should_work()
        {
            RequireServer.Check().Supports(Feature.SetWindowFields);
            var collection = Setup();

            var aggregate = collection
                            .Aggregate()
                            .SetWindowFields(
                partitionBy: x => x.OrderDate.Year,
                sortBy: Builders <CakeSales> .Sort.Ascending(x => x.OrderDate),
                output: p => new
            {
                CumulativeQuantityForYear = p.Sum(x => x.Quantity, DocumentsWindow.Create(DocumentsWindow.Unbounded, DocumentsWindow.Current)),
                MaximumQuantityForYear    = p.Max(x => x.Quantity, DocumentsWindow.Create(DocumentsWindow.Unbounded, DocumentsWindow.Unbounded)),
            });

            var stages         = Linq3TestHelpers.Translate(collection, aggregate);
            var expectedStages = new[]
            {
                @"
                {
                    $setWindowFields : {
                        partitionBy : { $year : '$OrderDate' } ,
                        sortBy : { OrderDate : 1 },
                        output : {
                            CumulativeQuantityForYear : {
                                $sum : '$Quantity',
                                window : {
                                    documents : ['unbounded', 'current']
                                }
                            },
                            MaximumQuantityForYear : {
                                $max : '$Quantity',
                                window : {
                                    documents : ['unbounded', 'unbounded']
                                }
                            }
                        }
                    }
                }
                "
            };

            Linq3TestHelpers.AssertStages(stages, expectedStages);

            var results = aggregate.ToList();

            results.Count.Should().Be(6);
            results[0].Should().BeEquivalentTo("{ _id : 5, Type : 'strawberry', OrderDate : ISODate('2019-01-08T06:12:03Z'), State : 'WA', Price : 43.00, Quantity : 134, CumulativeQuantityForYear : 134, MaximumQuantityForYear : 162 }");
            results[1].Should().BeEquivalentTo("{ _id : 4, Type : 'strawberry', OrderDate : ISODate('2019-05-18T16:09:01Z'), State : 'CA', Price : 41.00, Quantity : 162, CumulativeQuantityForYear : 296, MaximumQuantityForYear : 162 }");
            results[2].Should().BeEquivalentTo("{ _id : 3, Type : 'vanilla', OrderDate : ISODate('2020-02-08T13:13:23Z'), State : 'WA', Price : 13.00, Quantity : 104, CumulativeQuantityForYear : 104, MaximumQuantityForYear : 120 }");
            results[3].Should().BeEquivalentTo("{ _id : 0, Type : 'chocolate', OrderDate : ISODate('2020-05-18T14:10:30Z'), State : 'CA', Price : 13.00, Quantity : 120, CumulativeQuantityForYear : 224, MaximumQuantityForYear : 120 }");
            results[4].Should().BeEquivalentTo("{ _id : 2, Type : 'vanilla', OrderDate : ISODate('2021-01-11T06:31:15Z'), State : 'CA', Price : 12.00, Quantity : 145, CumulativeQuantityForYear : 145, MaximumQuantityForYear : 145 }");
            results[5].Should().BeEquivalentTo("{ _id : 1, Type : 'chocolate', OrderDate : ISODate('2021-03-20T11:30:05Z'), State : 'WA', Price : 14.00, Quantity : 140, CumulativeQuantityForYear : 285, MaximumQuantityForYear : 145 }");
        }
        public void Use_documents_window_to_obtain_moving_average_quantity_for_each_year_example_should_work()
        {
            RequireServer.Check().Supports(Feature.SetWindowFields);
            var collection = Setup();

            var aggregate = collection
                            .Aggregate()
                            .SetWindowFields(
                partitionBy: x => x.OrderDate.Year,
                sortBy: Builders <CakeSales> .Sort.Ascending(x => x.OrderDate),
                output: p => new { AverageQuantity = p.Average(x => x.Quantity, DocumentsWindow.Create(-1, 0)) });

            var stages         = Linq3TestHelpers.Translate(collection, aggregate);
            var expectedStages = new[]
            {
                @"
                {
                    $setWindowFields : {
                        partitionBy : { $year : '$OrderDate' } ,
                        sortBy : { OrderDate : 1 },
                        output : {
                            AverageQuantity : {
                                $avg : '$Quantity',
                                window : {
                                    documents : [-1, 0]
                                }
                            }
                        }
                    }
                }
                "
            };

            Linq3TestHelpers.AssertStages(stages, expectedStages);

            var results = aggregate.ToList();

            results.Count.Should().Be(6);
            results[0].Should().Be("{ _id : 5, Type : 'strawberry', OrderDate : ISODate('2019-01-08T06:12:03Z'), State : 'WA', Price : 43.00, Quantity : 134, AverageQuantity : 134.0 }");
            results[1].Should().Be("{ _id : 4, Type : 'strawberry', OrderDate : ISODate('2019-05-18T16:09:01Z'), State : 'CA', Price : 41.00, Quantity : 162, AverageQuantity : 148.0 }");
            results[2].Should().Be("{ _id : 3, Type : 'vanilla', OrderDate : ISODate('2020-02-08T13:13:23Z'), State : 'WA', Price : 13.00, Quantity : 104, AverageQuantity : 104.0 }");
            results[3].Should().Be("{ _id : 0, Type : 'chocolate', OrderDate : ISODate('2020-05-18T14:10:30Z'), State : 'CA', Price : 13.00, Quantity : 120, AverageQuantity : 112.0 }");
            results[4].Should().Be("{ _id : 2, Type : 'vanilla', OrderDate : ISODate('2021-01-11T06:31:15Z'), State : 'CA', Price : 12.00, Quantity : 145, AverageQuantity : 145.0 }");
            results[5].Should().Be("{ _id : 1, Type : 'chocolate', OrderDate : ISODate('2021-03-20T11:30:05Z'), State : 'WA', Price : 14.00, Quantity : 140, AverageQuantity : 142.5 }");
        }