コード例 #1
0
 public void ShouldCreateRegisteredAggregator()
 {
     StaticBarrier.Run(delegate {
         CustomAggregators.RegisterAggregator(AggregateName.SUM, typeof(SumAggregator <>));
         var aggregator = CustomAggregators.CreateAggregator(AggregateName.SUM, new DefaultAccessor <int>());
         Assert.NotNull(aggregator);
         Assert.IsType <SumAggregator <int> >(aggregator);
     });
 }
コード例 #2
0
 public void ShouldSupportMultipleAggregatorRegistrations()
 {
     StaticBarrier.Run(delegate {
         CustomAggregators.RegisterAggregator("any", typeof(SumAggregator <>));
         CustomAggregators.RegisterAggregator("any", typeof(MinAggregator <>));
         var aggregator = CustomAggregators.CreateAggregator("any", new DefaultAccessor <int>());
         Assert.NotNull(aggregator);
         Assert.IsType <MinAggregator <int> >(aggregator);
     });
 }
コード例 #3
0
 public void GlobalSwitch()
 {
     StaticBarrier.Run(delegate {
         var options = new SampleLoadOptions {
             Filter = new[] { "this", "contains", "A" }
         };
         DataSourceLoadOptionsBase.StringToLowerDefault = false;
         DataSourceLoader.Load(new[] { "" }, options).data.Cast <object>().ToArray();
         Assert.DoesNotContain(options.ExpressionLog, line => line.Contains("ToLower"));
     });
 }
コード例 #4
0
        public void CustomAggregator()
        {
            StaticBarrier.Run(delegate {
                CustomAggregators.RegisterAggregator("totalSales", typeof(TotalSalesAggregator <>));

                var data = new[] {
                    new Group {
                        items = new[] {
                            new CustomAggregatorDataItem {
                                UnitPrice = 4.04M, Quantity = 5, Discount = 0.10M
                            },
                            new CustomAggregatorDataItem {
                                UnitPrice = 10.10M, Quantity = 2, Discount = 0.20M
                            }
                        }
                    },
                    new Group {
                        items = new[] {
                            new CustomAggregatorDataItem {
                                UnitPrice = 15.15M, Quantity = 4, Discount = 0.30M
                            }
                        }
                    },
                    new Group {
                        items = new CustomAggregatorDataItem[] { }
                    }
                };

                var calculator = new AggregateCalculator <CustomAggregatorDataItem>(data, new DefaultAccessor <CustomAggregatorDataItem>(),
                                                                                    new[] { new SummaryInfo {
                                                                                                Selector = "this", SummaryType = "totalSales"
                                                                                            } },
                                                                                    new[] { new SummaryInfo {
                                                                                                Selector = "this", SummaryType = "totalSales"
                                                                                            } }
                                                                                    );

                var totals = calculator.Run();

                Assert.Equal(76.76M, totals[0]);
                Assert.Equal(34.34M, data[0].summary[0]);
                Assert.Equal(42.42M, data[1].summary[0]);
                Assert.Equal(0M, data[2].summary[0]);
            });
        }
コード例 #5
0
 public void ShouldNotReturnUnexistingAggregator()
 {
     StaticBarrier.Run(delegate {
         Assert.Null(CustomAggregators.CreateAggregator("custom", new DefaultAccessor <int>()));
     });
 }