Example #1
0
 public static void Run(Action action)
 {
     lock (SYNC) {
         try {
             action();
         } finally {
             CustomAggregators.Clear();
         }
     }
 }
 public void ShouldCreateRegisteredAggregator()
 {
     try {
         CustomAggregators.RegisterAggregator(AggregateName.SUM, typeof(SumAggregator <>));
         var aggregator = CustomAggregators.CreateAggregator(AggregateName.SUM, new DefaultAccessor <int>());
         Assert.NotNull(aggregator);
         Assert.IsType <SumAggregator <int> >(aggregator);
     } finally {
         CustomAggregators.Clear();
     }
 }
 public void ShouldSupportMultipleAggregatorRegistrations()
 {
     try {
         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);
     } finally {
         CustomAggregators.Clear();
     }
 }
Example #4
0
 public static void Run(Action action)
 {
     lock (SYNC) {
         try {
             action();
         } finally {
             CustomAggregators.Clear();
             CustomAccessorCompilers.Clear();
             DataSourceLoadOptionsBase.StringToLowerDefault = null;
         }
     }
 }
        public void CustomAggregator()
        {
            try {
                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]);
            } finally {
                CustomAggregators.Clear();
            }
        }