Example #1
0
        public async Task GetDetails_RecentEvents()
        {
            void AssertContainsEvent(TagDetailsContract details, ReleaseEvent releaseEvent)
            {
                details.Stats.Events.Any(e => e.Id == releaseEvent.Id).Should().BeTrue("Contains " + releaseEvent);
            }

            var standaloneEvent = CreateEntry.ReleaseEvent("Miku party");
            var otherEvent      = CreateEntry.ReleaseEvent("Magical Mirai");
            var eventSeries     = CreateEntry.EventSeries("VocaTRAVers");
            var seriesUsage     = _repository.Save(new EventSeriesTagUsage(eventSeries, _tag));

            eventSeries.Tags.Usages.Add(seriesUsage);
            _tag.AllEventSeriesTagUsages.Add(seriesUsage);
            var oldSeriesEvent = CreateEntry.ReleaseEvent("VocaTRAVers 1", date: DateTime.Now.AddDays(-30));

            oldSeriesEvent.SetSeries(eventSeries);
            var recentSeriesEvent = CreateEntry.ReleaseEvent("VocaTRAVers 2", date: DateTime.Now);

            recentSeriesEvent.SetSeries(eventSeries);
            _repository.Save(standaloneEvent, otherEvent, oldSeriesEvent, recentSeriesEvent);
            _repository.Save(eventSeries);
            _repository.Save(CreateTagUsage(_tag, standaloneEvent), CreateTagUsage(_tag, oldSeriesEvent), CreateTagUsage(_tag, recentSeriesEvent));

            var result = await _queries.GetDetailsAsync(_tag.Id);

            result.Stats.EventCount.Should().Be(2, "EventCount");
            result.Stats.Events.Length.Should().Be(2, "Events.Length");
            result.Stats.EventSeriesCount.Should().Be(1, "EventSeriesCount");
            result.Stats.EventSeries.Length.Should().Be(1, "EventSeries.Length");
            AssertContainsEvent(result, standaloneEvent);
            AssertContainsEvent(result, recentSeriesEvent);
            result.Stats.EventSeries.Any(e => e.Id == eventSeries.Id).Should().BeTrue("Contains " + eventSeries);
        }
Example #2
0
        public async Task <ActionResult> DetailsById(int id = InvalidId, string slug = null)
        {
            if (id == InvalidId)
            {
                return(NoId());
            }

            // TODO: write test for null slug
            slug ??= string.Empty;

            var tagName = await _queries.LoadTagAsync(id, t => t.UrlSlug ?? string.Empty);

            if (slug != tagName)
            {
                return(RedirectToActionPermanent("DetailsById", new { id, slug = tagName }));
            }

            var contract = await _queries.GetDetailsAsync(id);

            var prop = PageProperties;

            var thumbUrl = Url.ImageThumb(contract.Thumb, ImageSize.Original);

            if (!string.IsNullOrEmpty(thumbUrl))
            {
                PageProperties.OpenGraph.Image = thumbUrl;
            }

            prop.Description = _markdownParser.GetPlainText(contract.Description.EnglishOrOriginal);

            return(RenderDetails(contract));
        }