public void CustomAggregator() { CustomAggregatorsBarrier.Run(delegate { CustomAggregators.RegisterAggregator("comma", typeof(CommaAggregator <>)); var data = new[] { new Group { items = new Tuple <int>[] { Tuple.Create(1), Tuple.Create(5) } }, new Group { items = new Tuple <int>[] { Tuple.Create(7) } }, new Group { items = new Tuple <int>[] { } } }; var calculator = new AggregateCalculator <Tuple <int> >(data, new DefaultAccessor <Tuple <int> >(), new[] { new SummaryInfo { Selector = "Item1", SummaryType = "comma" } }, new[] { new SummaryInfo { Selector = "Item1", SummaryType = "comma" } } ); var totals = calculator.Run(); Assert.Equal("1,5,7", totals[0]); Assert.Equal("1,5", data[0].summary[0]); Assert.Equal("7", data[1].summary[0]); Assert.Equal(string.Empty, data[2].summary[0]); }); }
public void ShouldCreateRegisteredAggregator() { CustomAggregatorsBarrier.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); }); }
public void ShouldSupportMultipleAggregatorRegistrations() { CustomAggregatorsBarrier.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); }); }
public void ShouldNotReturnUnexistingAggregator() { CustomAggregatorsBarrier.Run(delegate { Assert.Null(CustomAggregators.CreateAggregator("custom", new DefaultAccessor <int>())); }); }