public void ShouldReturnThreeValues_WhenItIsUser1() { var userId = 1; var ids = UserSpecifics.GetTaxSubcategoryIds(userId); Assert.AreEqual(3, ids.Count); }
public void ShouldReturnEmptyList_WhenItIsNotUser1() { var userId = _fixture.Create <int>() + 1; var ids = UserSpecifics.GetTaxSubcategoryIds(userId); CollectionAssert.IsEmpty(ids); }
public List <LegacyMonthlySumPerDay> GetMonthlyAverageDailyPurchases(int userId) { var taxSubcategoryIds = UserSpecifics.GetTaxSubcategoryIds(userId); var sums = GetMonthlySubcategorySum(userId, category => category.Type == CategoryProperties.Type.Out, subcategory => !taxSubcategoryIds.Contains(subcategory.SubcategoryId)) .Select(x => new LegacyMonthlySumPerDay { Year = x.Key.Year, Month = x.Key.Month, SumPerDay = Math.Round(x.Value.Values.Sum() / DateTime.DaysInMonth(x.Key.Year, x.Key.Month), 2) }) .ToList(); return(sums); }
public List <MonthlyTypeSum> Sumup(int userId) { var taxSubcategoryIds = UserSpecifics.GetTaxSubcategoryIds(userId); var inAndOut = (from p in _context.PostingForUser(userId) join s in _context.Subcategory on p.SubcategoryId equals s.SubcategoryId join c in _context.Category on s.CategoryId equals c.CategoryId group p.Amount by new { p.Date.Year, p.Date.Month, c.Type } into g select new { g.Key.Year, g.Key.Month, g.Key.Type, Sum = g.Sum() }).ToList(); var tax = (from p in _context.PostingForUser(userId) join s in _context.Subcategory on p.SubcategoryId equals s.SubcategoryId join c in _context.Category on s.CategoryId equals c.CategoryId where c.Type == CategoryProperties.Type.Out && taxSubcategoryIds.Contains(s.SubcategoryId) group p.Amount by new { p.Date.Year, p.Date.Month } into g select new { g.Key.Year, g.Key.Month, Type = "tax", Sum = g.Sum() } ).ToList(); return(inAndOut.Union(tax).Select(x => new MonthlyTypeSum { MonthAndYear = (x.Year, x.Month), Type = x.Type, Sum = x.Sum, }).ToList());