public void WhenExpressionArgumentIsNullExceptionIsThrown() { var dummyList = new List <string>(); var countGroupBy = new CountGroupBy <string, string, Helpers.StringComparer>(dummyList.AsQueryable()); Assert.Throws <ArgumentNullException>(() => countGroupBy.GroupAndCountBy(null)); }
public void WhenQueryableArgumentIsEmptyListThenEmptyCountyByListIsReturned() { var dummyList = new List <string>(); var countGroupBy = new CountGroupBy <string, string, Helpers.StringComparer>(dummyList.AsQueryable()); var actual = countGroupBy.GroupAndCountBy(x => x).ToList(); Assert.Equal(new List <CountBy <string> >(), actual); }
public async Task <ICommandResult> ExecuteAsync(CreateBagsCountByBagTypesCommand command) { var bags = await SearchRepository.SearchItemsAsync(); var queryablebags = bags.AsQueryable(); var countGroupByIRef = new CountGroupBy <Bag, RefValue, RefValueComparer>(queryablebags); var bagsCountByBagType = countGroupByIRef.GroupAndCountBy(x => x.BagType); var dashboard = new Dashboard <IEnumerable <CountBy <RefValue> > >(DashBoardTypes.BagsCountByBagTypes.Key.ToString(), command.User.Id, DashBoardTypes.BagsCountByBagTypes, bagsCountByBagType); await UpsertRepository.UpsertItemAsync(dashboard.Id, dashboard); return(new OkResult()); }
public void WhenQueryableArgumentListHasTwoDifferentItemsThenListWithTwoCountByOfWithCountOfOneIsReturned() { var dummyList = new List <string> { "one", "two" }; var countGroupBy = new CountGroupBy <string, string, Helpers.StringComparer>(dummyList.AsQueryable()); var actual = countGroupBy.GroupAndCountBy(x => x); Assert.Equal(new List <CountBy <string> > { new CountBy <string>("one", 1), new CountBy <string>("two", 1) }, actual, new CountByComparer <string>()); }
public async Task <ICommandResult> ExecuteAsync(CreateBagsCountByInsertDateCommand command) { var bags = await SearchRepository.SearchItemsAsync(); var queryablebags = bags.AsQueryable(); var countGroupByLocalDate = new CountGroupBy <Bag, NodaTime.LocalDate, LocalDateComparer>(queryablebags); var bagsCountByLocalDate = countGroupByLocalDate.GroupAndCountBy(x => x.InsertDate.With(NodaTime.DateAdjusters.StartOfMonth)) .OrderByDescending(x => x.Value); var dashboard = new Dashboard <IEnumerable <CountBy <NodaTime.LocalDate> > >(DashBoardTypes.BagsCountByPeriod.Key.ToString(), command.User.Id, DashBoardTypes.BagsCountByPeriod, bagsCountByLocalDate); await UpsertRepository.UpsertItemAsync(dashboard.Id, dashboard); return(new OkResult()); }
public async Task <ICommandResult> ExecuteAsync(CreateTotalBagsCountByInsertDateCommand command) { var bags = await SearchRepository.SearchItemsAsync(); var queryablebags = bags.AsQueryable(); var countGroupBy = new CountGroupBy <Bag, NodaTime.LocalDate, LocalDateComparer>(queryablebags); var bagsCountByInsertDate = countGroupBy.GroupAndCountBy(x => x.InsertDate.With(NodaTime.DateAdjusters.StartOfMonth)) .OrderBy(x => x.Value); var firstCountBy = bagsCountByInsertDate.First(); var firstPeriod = firstCountBy.Value.With(NodaTime.DateAdjusters.StartOfMonth).PlusMonths(-1); var totalBagsCountByPeriods = bagsCountByInsertDate.ToList().Scan((state, item) => { return(new CountBy <NodaTime.LocalDate>(item.Value, item.Count + state.Count)); }, new CountBy <NodaTime.LocalDate>(firstPeriod, 0)); var dashboard = new Dashboard <IEnumerable <CountBy <NodaTime.LocalDate> > >(DashBoardTypes.TotalBagsCountByPeriod.Key.ToString(), command.User.Id, DashBoardTypes.BagsCountByPeriod, totalBagsCountByPeriods); await UpsertRepository.UpsertItemAsync(dashboard.Id, dashboard); return(new OkResult()); }