Exemplo n.º 1
0
        public async Task GetValues_CorrectLabels()
        {
            // Arrange
            var testCat1 = new Category("Ausgehen");
            var testCat2 = new Category("Rent");
            var testCat3 = new Category("Food");
            var testCat4 = new Category("Income");

            var account     = new Account("test");
            var paymentList = new List <Payment>
            {
                new Payment(DateTime.Today, 90, PaymentType.Expense, account, category: testCat1),
                new Payment(DateTime.Today, 90, PaymentType.Expense, account, category: testCat2),
                new Payment(DateTime.Today, 10, PaymentType.Expense, account, category: testCat3),
                new Payment(DateTime.Today, 100, PaymentType.Income, account, category: testCat4)
            };

            context.Payments.AddRange(paymentList);
            context.SaveChanges();

            // Act
            CategorySummaryModel result = await new GetCategorySummaryQuery.GetCategorySummaryQueryHandler(context).Handle(new GetCategorySummaryQuery
            {
                StartDate = DateTime.Today.AddDays(-3),
                EndDate   = DateTime.Today.AddDays(3)
            }, default);

            // Assert
            result.CategoryOverviewItems[0].Label.ShouldEqual(testCat1.Name);
            result.CategoryOverviewItems[1].Label.ShouldEqual(testCat2.Name);
            result.CategoryOverviewItems[2].Label.ShouldEqual(testCat3.Name);
            result.CategoryOverviewItems[3].Label.ShouldEqual(testCat4.Name);
        }
Exemplo n.º 2
0
        public async Task GetValues_NoCategory_CorrectLabel()
        {
            // Arrange
            var account = new Account("test");

            var paymentList = new List <Payment>
            {
                new Payment(DateTime.Today, 60, PaymentType.Expense, account)
            };

            context.Payments.AddRange(paymentList);
            context.SaveChanges();

            // Act
            CategorySummaryModel result =
                await new GetCategorySummaryQuery.GetCategorySummaryQueryHandler(contextAdapterMock.Object)
                .Handle(new GetCategorySummaryQuery
            {
                StartDate = DateTime.Today.AddDays(-3),
                EndDate   = DateTime.Today.AddDays(3)
            },
                        default);

            // Assert
            result.CategoryOverviewItems[0].Label.Should().Be(Strings.NoCategoryLabel);
        }
Exemplo n.º 3
0
        public async Task GetValues_CorrectPercentage()
        {
            // Arrange
            var testCat1 = new Category("Ausgehen");
            var testCat2 = new Category("Ausgehen");
            var testCat3 = new Category("Income");

            var account = new Account("test");

            var paymentList = new List <Payment>
            {
                new Payment(DateTime.Today, 60, PaymentType.Expense, account, category: testCat1),
                new Payment(DateTime.Today, 90, PaymentType.Expense, account, category: testCat2),
                new Payment(DateTime.Today, 100, PaymentType.Income, account, category: testCat3)
            };

            context.Payments.AddRange(paymentList);
            context.SaveChanges();

            // Act
            CategorySummaryModel result =
                await new GetCategorySummaryQuery.GetCategorySummaryQueryHandler(contextAdapterMock.Object)
                .Handle(new GetCategorySummaryQuery
            {
                StartDate = DateTime.Today.AddDays(-3),
                EndDate   = DateTime.Today.AddDays(3)
            },
                        default);

            // Assert
            result.CategoryOverviewItems[0].Percentage.Should().Be(60);
            result.CategoryOverviewItems[1].Percentage.Should().Be(40);
            result.CategoryOverviewItems[2].Percentage.Should().Be(100);
        }
Exemplo n.º 4
0
        public IActionResult CategorySummary(string url)
        {
            int pageSize = 6;

            if (!string.IsNullOrWhiteSpace(url))
            {
                var categoryToBeSummarized = _CategoryService.GetByUrl(url);

                if (categoryToBeSummarized != null)
                {
                    int[] categoryId = { categoryToBeSummarized.CategoryId };

                    var categorySummaryModel = new CategorySummaryModel()
                    {
                        Category    = categoryToBeSummarized,
                        Experiences = _ExperienceService.ExperienceListByFilters(categoryId, "", "", 1, pageSize),
                        Locations   = _LocationService.GetLocationsByCategoryId(categoryToBeSummarized.CategoryId)
                    };



                    return(View(categorySummaryModel));
                }

                return(NotFound());
            }


            return(NotFound());
        }
Exemplo n.º 5
0
        private List <CategorySummaryModel> GetExpensesByCategory(DateTime start, DateTime end)
        {
            var categorySummary = from pc in _context.Set <PurchaseCategory>()
                                  join e in _context.Set <Expense>()
                                  on pc.ID equals e.CategoryID      //into joined
                                  where e.TimeStamp.Date >= start && e.TimeStamp.Date <= end
                                  select new { pc.ID, pc.Name, e.Sum } into qr
            group qr by new { qr.ID, qr.Name } into gg
                     select new { gg.Key, Sum = gg.Sum(x => x.Sum) };

            List <CategorySummaryModel> categories = new List <CategorySummaryModel>();

            foreach (var item in categorySummary)
            {
                CategorySummaryModel psm = new CategorySummaryModel
                {
                    ID   = item.Key.ID,
                    Name = item.Key.Name,
                    Sum  = item.Sum
                };
                categories.Add(psm);
            }

            return(categories);
        }
Exemplo n.º 6
0
        public async Task <List <CategorySummaryModel> > MapCategorySummaryModelAsync(IEnumerable <Category> categories, int thumbSize)
        {
            Guard.NotNull(categories, nameof(categories));

            var fileIds = categories
                          .Select(x => x.MediaFileId ?? 0)
                          .Where(x => x != 0)
                          .Distinct()
                          .ToArray();

            var files = (await _mediaService.GetFilesByIdsAsync(fileIds)).ToDictionarySafe(x => x.Id);

            return(await categories
                   .SelectAsync(async c =>
            {
                var name = c.GetLocalized(y => y.Name);
                var model = new CategorySummaryModel
                {
                    Id = c.Id,
                    Name = name
                };

                _services.DisplayControl.Announce(c);

                // Generate URL.
                if (c.ExternalLink.HasValue())
                {
                    var link = await _linkResolver.ResolveAsync(c.ExternalLink);
                    if (link.Status == LinkStatus.Ok)
                    {
                        model.Url = link.Link;
                    }
                }

                if (model.Url.IsEmpty())
                {
                    model.Url = _urlHelper.RouteUrl(nameof(Category), new { SeName = c.GetActiveSlug() });
                }

                files.TryGetValue(c.MediaFileId ?? 0, out var file);

                model.Image = new ImageModel
                {
                    File = file,
                    ThumbSize = thumbSize,
                    Title = file?.File?.GetLocalized(x => x.Title)?.Value.NullEmpty() ?? string.Format(T("Media.Category.ImageLinkTitleFormat"), name),
                    Alt = file?.File?.GetLocalized(x => x.Alt)?.Value.NullEmpty() ?? string.Format(T("Media.Category.ImageAlternateTextFormat"), name),
                    NoFallback = _catalogSettings.HideCategoryDefaultPictures
                };

                _services.DisplayControl.Announce(file?.File);

                return model;
            })
                   .AsyncToList());
        }