public void ShouldReturnThreeEventsIfTheGroupIsReferencedByThree()
        {
            // Arrange
            var anEvent = new ContentfulEventBuilder().Slug("slug-1").Featured(false).EventDate(new DateTime(2017, 09, 01)).Build();

            anEvent.Group.Slug = "zumba-fitness";
            var anotherEvent = new ContentfulEventBuilder().Slug("slug-2").Featured(false).EventDate(new DateTime(2017, 09, 01)).Build();

            anotherEvent.Group.Slug = "zumba-fitness";
            var aThirdEvent = new ContentfulEventBuilder().Slug("slug-3").Featured(false).EventDate(new DateTime(2017, 09, 15)).Build();

            aThirdEvent.Group.Slug = "zumba-fitness";
            var events = new List <ContentfulEvent> {
                anEvent, anotherEvent, aThirdEvent
            };

            _cacheWrapper.Setup(o => o.GetFromCacheOrDirectlyAsync(It.Is <string>(s => s == "event-all"), It.IsAny <Func <Task <IList <ContentfulEvent> > > >(), It.Is <int>(s => s == 60))).ReturnsAsync(events);

            var group      = new GroupBuilder().Slug("zumba-fitness").Build();
            var othergroup = new GroupBuilder().Slug("kersal-rugby").Build();

            _groupFactory.Setup(g => g.ToModel(It.Is <ContentfulGroup>(o => o.Slug == "zumba-fitness"))).Returns(group);
            _groupFactory.Setup(g => g.ToModel(It.Is <ContentfulGroup>(o => o.Slug != "zumba-fitness"))).Returns(othergroup);

            // Act
            var processedEvents = AsyncTestHelper.Resolve(_repository.GetLinkedEvents <Group>("zumba-fitness"));

            // Assert
            processedEvents.Count.Should().Be(3);
            processedEvents[0].Slug.Should().Be("slug-1");
        }
        public void ShouldGetAllEventsWithTheirYearlyReccuringParts()
        {
            const int            occurences = 3;
            const EventFrequency frequency  = EventFrequency.Yearly;

            _mockTimeProvider.Setup(o => o.Now()).Returns(new DateTime(2016, 08, 08));

            var anEvent =
                new ContentfulEventBuilder().EventDate(new DateTime(2017, 04, 01))
                .Frequency(frequency)
                .Occurrences(occurences)
                .Build();
            var events = new List <ContentfulEvent> {
                anEvent
            };

            _cacheWrapper.Setup(o => o.GetFromCacheOrDirectlyAsync(It.Is <string>(s => s == "event-all"), It.IsAny <Func <Task <IList <ContentfulEvent> > > >(), It.Is <int>(s => s == 60))).ReturnsAsync(events);

            var response = AsyncTestHelper.Resolve(_repository.Get(null, null, null, 0, null, null, null, 0, 0));


            var eventCalender = response.Get <EventCalender>();

            eventCalender.Events.Count.Should().Be(occurences);
            eventCalender.Events[0].EventDate.Should().Be(new DateTime(2017, 04, 01));
            eventCalender.Events[1].EventDate.Should().Be(new DateTime(2018, 04, 01));
            eventCalender.Events[2].EventDate.Should().Be(new DateTime(2019, 04, 01));
        }
        public void ShouldGetEventsWithinDateRange()
        {
            // Arrange
            var dateFrom = new DateTime(2016, 07, 28);
            var dateTo   = new DateTime(2017, 02, 15);

            _mockTimeProvider.Setup(o => o.Now()).Returns(new DateTime(2017, 08, 08));
            var anEvent      = new ContentfulEventBuilder().EventDate(new DateTime(2016, 09, 01)).Build();
            var anotherEvent = new ContentfulEventBuilder().EventDate(new DateTime(2017, 04, 01)).Build();

            var events = new List <ContentfulEvent> {
                anEvent, anotherEvent
            };

            _cacheWrapper.Setup(o => o.GetFromCacheOrDirectlyAsync(It.Is <string>(s => s == "event-all"), It.IsAny <Func <Task <IList <ContentfulEvent> > > >(), It.Is <int>(s => s == 60))).ReturnsAsync(events);

            // Act
            var response = AsyncTestHelper.Resolve(_repository.Get(dateFrom, dateTo, null, 0, null, null, null, 0, 0));

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            var eventCalender = response.Get <EventCalender>();

            eventCalender.Events.Should().HaveCount(1);
        }
        public void ShouldGetEventForACategoryAndDate()
        {
            // Arrange
            var dateFrom = new DateTime(2016, 07, 28);
            var dateTo   = new DateTime(2017, 02, 15);

            _mockTimeProvider.Setup(o => o.Now()).Returns(new DateTime(2017, 08, 08));
            var contentfulCategory1 = new ContentfulEventCategory {
                Name = "Category 1", Slug = "category-1"
            };
            var contentfulCategory2 = new ContentfulEventCategory {
                Name = "Category 2", Slug = "category-2"
            };
            var contentfulCategory3 = new ContentfulEventCategory {
                Name = "Category 3", Slug = "category-3"
            };

            var event1 =
                new ContentfulEventBuilder().EventCategoryList(new List <ContentfulEventCategory>()
            {
                contentfulCategory1
            })
                .EventDate(new DateTime(2017, 08, 01))
                .Build();
            var event2 =
                new ContentfulEventBuilder().EventCategoryList(new List <ContentfulEventCategory>()
            {
                contentfulCategory2
            })
                .EventDate(new DateTime(2016, 08, 01))
                .Build();
            var event3 =
                new ContentfulEventBuilder().EventCategoryList(new List <ContentfulEventCategory>()
            {
                contentfulCategory3
            })
                .EventDate(new DateTime(2016, 08, 01))
                .Build();

            var events = new List <ContentfulEvent> {
                event1, event2, event3
            };

            _eventCategoryFactory.Setup(o => o.ToModel(contentfulCategory1)).Returns(new EventCategory("Category 1", "category-1", "icon1"));
            _eventCategoryFactory.Setup(o => o.ToModel(contentfulCategory2)).Returns(new EventCategory("Category 2", "category-2", "icon2"));
            _eventCategoryFactory.Setup(o => o.ToModel(contentfulCategory3)).Returns(new EventCategory("Category 3", "category-3", "icon3"));

            _cacheWrapper.Setup(o => o.GetFromCacheOrDirectlyAsync(It.Is <string>(s => s == "event-all"), It.IsAny <Func <Task <IList <ContentfulEvent> > > >(), It.Is <int>(s => s == 60))).ReturnsAsync(events);

            // Act
            var response = AsyncTestHelper.Resolve(_repository.Get(dateFrom, dateTo, "Category 3", 0, null, null, null, 0, 0));

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            var eventCalender = response.Get <EventCalender>();

            eventCalender.Events.Should().HaveCount(1);
        }
        public void ItReturnsBreadcrumbs()
        {
            // Arrange
            const string slug        = "unit-test-showcase-crumbs";
            var          crumb       = new Crumb("title", "slug", "type");
            var          collection  = new ContentfulCollection <ContentfulShowcase>();
            var          rawShowcase = new ContentfulShowcaseBuilder().Slug(slug)
                                       .Breadcrumbs(new List <ContentfulReference>()
            {
                new ContentfulReference()
                {
                    Title = crumb.Title, Slug = crumb.Title, Sys = new SystemProperties()
                    {
                        Type = "Entry"
                    }
                },
            })
                                       .Build();

            collection.Items = new List <ContentfulShowcase> {
                rawShowcase
            };

            var builder = new QueryBuilder <ContentfulShowcase>().ContentTypeIs("showcase").FieldEquals("fields.slug", slug).Include(3);

            _contentfulClient.Setup(o => o.GetEntries(It.Is <QueryBuilder <ContentfulShowcase> >(q => q.Build() == builder.Build()), It.IsAny <CancellationToken>()))
            .ReturnsAsync(collection);

            _crumbFactory.Setup(o => o.ToModel(It.IsAny <ContentfulReference>())).Returns(crumb);

            var rawEvent = new ContentfulEventBuilder().Slug(slug).EventDate(new DateTime(2017, 4, 1)).Build();
            var events   = new List <ContentfulEvent> {
                rawEvent
            };

            _cacheWrapper.Setup(o => o.GetFromCacheOrDirectlyAsync(It.Is <string>(s => s == "event-all"), It.IsAny <Func <Task <IList <ContentfulEvent> > > >(), It.Is <int>(s => s == 60))).ReturnsAsync(events);
            var modelledEvent = new Event("title", "event-slug", "", "", "", "", "", "", DateTime.MaxValue, "", "", 1, EventFrequency.None, null, "", null, new List <string>(), null, false, "", DateTime.MinValue, new List <string>(), null, null, new List <EventCategory> {
                new EventCategory("event", "slug", "icon")
            }, null, null, null, null);

            _eventFactory.Setup(e => e.ToModel(It.IsAny <ContentfulEvent>())).Returns(modelledEvent);

            // Act
            var response = AsyncTestHelper.Resolve(_repository.GetShowcases(slug));

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            var showcase = response.Get <Showcase>();

            showcase.Breadcrumbs.First().Should().Be(crumb);
        }
Esempio n. 6
0
        public void ToModel_ShouldReturnLinkList()
        {
            // Arrange
            _callToActionFactory
            .Setup(_ => _.ToModel(It.IsAny <ContentfulCallToActionBanner>()))
            .Returns(new CallToActionBanner());
            _eventFactory
            .Setup(_ => _.ToModel(It.IsAny <ContentfulEvent>()))
            .Returns(new EventBuilder().Build());

            var model = new ContentfulCommsHomepage
            {
                WhatsOnInStockportEvent = new ContentfulEventBuilder().Build(),
                MetaDescription         = "meta description",
                CallToActionBanner      = new ContentfulCallToActionBanner(),
                UsefulLinksText         = new() { "Test Link" },
                UsefulLinksURL          = new() { "https://www.stockport.gov.uk/" },
                TwitterFeedHeader       = "twiiter",
                InstagramFeedTitle      = "instagram header",
                FacebookFeedTitle       = "facebook",
                Title            = "title",
                InstagramLink    = "instagram link",
                LatestNewsHeader = "latest news",
                Sys = new SystemProperties()
            };

            // Act
            var result = _factory.ToModel(model);

            // Assert
            Assert.NotNull(result);
            Assert.NotNull(result.WhatsOnInStockportEvent);
            Assert.NotNull(result.CallToActionBanner);
            Assert.NotNull(result.UsefulLinks);
            Assert.Equal("twiiter", result.TwitterFeedHeader);
            Assert.Equal("meta description", result.MetaDescription);
            Assert.Equal("instagram header", result.InstagramFeedTitle);
            Assert.Equal("facebook", result.FacebookFeedTitle);
            Assert.Equal("title", result.Title);
            Assert.Equal("instagram link", result.InstagramLink);
            Assert.Equal("latest news", result.LatestNewsHeader);
        }
    }
        public void ShouldGetNoFeaturedEventsBecauseNonExist()
        {
            var anEvent      = new ContentfulEventBuilder().Featured(false).EventDate(new DateTime(2017, 09, 01)).Build();
            var anotherEvent = new ContentfulEventBuilder().Featured(false).EventDate(new DateTime(2017, 10, 10)).Build();
            var aThirdEvent  = new ContentfulEventBuilder().Featured(false).EventDate(new DateTime(2017, 09, 15)).Build();
            var events       = new List <ContentfulEvent> {
                anEvent, anotherEvent, aThirdEvent
            };

            _mockTimeProvider.Setup(o => o.Now()).Returns(new DateTime(2017, 08, 08));
            _cacheWrapper.Setup(o => o.GetFromCacheOrDirectlyAsync(It.Is <string>(s => s == "event-all"), It.IsAny <Func <Task <IList <ContentfulEvent> > > >(), It.Is <int>(s => s == 60))).ReturnsAsync(events);

            var response = AsyncTestHelper.Resolve(_repository.Get(null, null, null, 2, true, null, null, 0, 0));

            response.StatusCode.Should().Be(HttpStatusCode.OK);
            var eventsCalendar = response.Get <EventCalender>();

            eventsCalendar.Events[0].Featured.Should().BeFalse();
            eventsCalendar.Events[1].Featured.Should().BeFalse();
        }
        public void ShouldGetOneEventForACategory()
        {
            // Arrange
            var contentfulCategory1 = new ContentfulEventCategory {
                Name = "Category 1", Slug = "category-1"
            };
            var contentfulCategory2 = new ContentfulEventCategory {
                Name = "Category 2", Slug = "category-2"
            };
            var category1 = new EventCategory("Category 1", "category-1", "icon1");
            var category2 = new EventCategory("Category 2", "category-2", "icon2");
            var anEvent   =
                new ContentfulEventBuilder().EventCategoryList(new List <ContentfulEventCategory>()
            {
                contentfulCategory1, contentfulCategory2
            }).Build();
            var anotherEvent = new ContentfulEventBuilder().EventCategoryList(new List <ContentfulEventCategory>()
            {
                new ContentfulEventCategory {
                    Name = "Category 2", Slug = "category-2"
                }
            }).Build();
            var events = new List <ContentfulEvent> {
                anEvent, anotherEvent
            };

            _eventCategoryFactory.Setup(o => o.ToModel(contentfulCategory1)).Returns(category1);
            _eventCategoryFactory.Setup(o => o.ToModel(contentfulCategory2)).Returns(category2);

            _cacheWrapper.Setup(o => o.GetFromCacheOrDirectlyAsync(It.Is <string>(s => s == "event-all"), It.IsAny <Func <Task <IList <ContentfulEvent> > > >(), It.Is <int>(s => s == 60))).ReturnsAsync(events);

            // Act
            var response = AsyncTestHelper.Resolve(_repository.Get(null, null, "category 1", 0, null, null, null, 0, 0));

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            var eventCalender = response.Get <EventCalender>();

            eventCalender.Events.Should().HaveCount(1);
        }
        public void GetReoccuringEventsNextEventOnly()
        {
            // Arrange - mock reoccurring event, starting in the past that passes today
            _mockTimeProvider.Setup(o => o.Now()).Returns(new DateTime(2017, 07, 01));
            var rawEvent = new ContentfulEventBuilder().EventCategory(new List <string>()
            {
                "category"
            }).EventDate(new DateTime(2017, 06, 01)).Occurrences(10).Frequency(EventFrequency.Weekly).Build();
            var events = new List <ContentfulEvent> {
                rawEvent
            };

            _eventCategoryFactory.Setup(o => o.ToModel(It.IsAny <ContentfulEventCategory>())).Returns(new EventCategory("category", "category", "icon"));

            _cacheWrapper.Setup(o => o.GetFromCacheOrDirectlyAsync(It.Is <string>(s => s == "event-all"), It.IsAny <Func <Task <IList <ContentfulEvent> > > >(), It.Is <int>(s => s == 60))).ReturnsAsync(events);

            // Act - return events using a method which checks occurances
            var result = AsyncTestHelper.Resolve(_repository.GetEventsByCategory("category", true));

            // Assert - Check event date is first date that occurs in the future
            result[0].EventDate.Should().Be(new DateTime(2017, 07, 06));
        }
        public void ShouldGetLinkEventsForAGroup()
        {
            var anEvent      = new ContentfulEventBuilder().Slug("slug-1").Featured(false).EventDate(new DateTime(2017, 09, 01)).Build();
            var anotherEvent = new ContentfulEventBuilder().Slug("slug-2").Featured(false).EventDate(new DateTime(2017, 09, 01)).Build();
            var aThirdEvent  = new ContentfulEventBuilder().Slug("slug-3").Featured(false).EventDate(new DateTime(2017, 09, 15)).Build();
            var events       = new List <ContentfulEvent> {
                anEvent, anotherEvent, aThirdEvent
            };

            _cacheWrapper.Setup(o => o.GetFromCacheOrDirectlyAsync(It.Is <string>(s => s == "event-all"), It.IsAny <Func <Task <IList <ContentfulEvent> > > >(), It.Is <int>(s => s == 60))).ReturnsAsync(events);

            var group = new GroupBuilder().Slug("zumba-fitness").Build();

            _groupFactory.Setup(g => g.ToModel(It.IsAny <ContentfulGroup>())).Returns(group);

            _mockTimeProvider.Setup(o => o.Now()).Returns(new DateTime(2017, 08, 08));

            var response = AsyncTestHelper.Resolve(_repository.GetLinkedEvents <Group>("zumba-fitness"));

            response[0].Title.Should().Be("title");
            response[1].Description.Should().Be("description");
        }
        public void GetsParticularReccuringEventFromASlug()
        {
            const string         slug       = "event-of-the-century";
            const int            occurences = 3;
            const EventFrequency frequency  = EventFrequency.Daily;

            _mockTimeProvider.Setup(o => o.Now()).Returns(new DateTime(2016, 08, 02));

            var anEvent =
                new ContentfulEventBuilder().EventDate(new DateTime(2017, 04, 01)).Slug(slug)
                .Frequency(frequency)
                .Occurrences(occurences)
                .Build();
            var anotherEvent = new ContentfulEventBuilder().Slug("slug-2").Featured(false).EventDate(new DateTime(2017, 09, 01)).Build();
            var aThirdEvent  = new ContentfulEventBuilder().Slug("slug-3").Featured(false).EventDate(new DateTime(2017, 09, 15)).Build();
            var events       = new List <ContentfulEvent> {
                anEvent, anotherEvent, aThirdEvent
            };

            var collection = new ContentfulCollection <ContentfulEvent>();

            collection.Items = new List <ContentfulEvent> {
                anEvent
            };


            _cacheWrapper.Setup(o => o.GetFromCacheOrDirectlyAsync(It.Is <string>(s => s == "event-all"), It.IsAny <Func <Task <IList <ContentfulEvent> > > >(), It.Is <int>(s => s == 60))).ReturnsAsync(events);

            var builder = new QueryBuilder <ContentfulEvent>().ContentTypeIs("events").FieldEquals("fields.slug", slug).Include(2);

            _contentfulClient.Setup(o => o.GetEntries(It.Is <QueryBuilder <ContentfulEvent> >(q => q.Build() == builder.Build()), It.IsAny <CancellationToken>()))
            .ReturnsAsync(collection);

            var response  = AsyncTestHelper.Resolve(_repository.GetEvent(slug, new DateTime(2017, 04, 02)));
            var eventItem = response.Get <Event>();

            eventItem.EventDate.Should().Be(new DateTime(2017, 04, 02));
        }
        public void ShouldGetEventsIfContainingGroupIsNotArchived()
        {
            _mockTimeProvider.Setup(o => o.Now()).Returns(new DateTime(2016, 08, 08));
            var anEvent       = new ContentfulEventBuilder().EventDate(new DateTime(2016, 09, 08)).Build();
            var anotherEvent  = new ContentfulEventBuilder().EventDate(new DateTime(2016, 10, 08)).Build();
            var archivedvents = new ContentfulEventBuilder().EventDate(new DateTime(2016, 10, 08)).Build();

            archivedvents.Group.DateHiddenFrom = DateTime.Now.AddDays(-2);
            archivedvents.Group.DateHiddenTo   = DateTime.Now.AddDays(2);
            var events = new List <ContentfulEvent> {
                anEvent, anotherEvent, archivedvents
            };

            var newsListCollection = new ContentfulCollection <ContentfulEvent>();

            newsListCollection.Items = new List <ContentfulEvent>
            {
                anEvent,
                anotherEvent,
                archivedvents
            };

            var builder = new QueryBuilder <CancellationToken>().ContentTypeIs("events").Include(2).Limit(ContentfulQueryValues.LIMIT_MAX);

            _contentfulClient.Setup(o => o.GetEntries <ContentfulEvent>(
                                        It.Is <string>(q => q.Contains(new QueryBuilder <ContentfulEvent>().ContentTypeIs("events").Include(2).Build())),
                                        It.IsAny <CancellationToken>())).ReturnsAsync(newsListCollection);

            var contentfulEvents = AsyncTestHelper.Resolve(_repository.GetAllEvents());

            contentfulEvents.Count.Should().Be(2);
            contentfulEvents.First()
            .Should().BeEquivalentTo(anEvent);

            contentfulEvents.Last()
            .Should().BeEquivalentTo(anotherEvent);
        }
        public void GetsASingleEventItemFromASlug()
        {
            // Arrange
            const string slug = "event-of-the-century";

            _mockTimeProvider.Setup(o => o.Now()).Returns(new DateTime(2016, 08, 02));

            var rawEvent = new ContentfulEventBuilder().Slug(slug).EventDate(new DateTime(2017, 4, 1)).Build();

            var events = new List <ContentfulEvent> {
                rawEvent
            };

            _cacheWrapper.Setup(o => o.GetFromCacheOrDirectlyAsync(It.Is <string>(s => s == "event-all"), It.IsAny <Func <Task <IList <ContentfulEvent> > > >(), It.Is <int>(s => s == 60))).ReturnsAsync(events);

            // Act
            var response = AsyncTestHelper.Resolve(_repository.GetEvent(slug, new DateTime(2017, 4, 1)));

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            var eventItem = response.Get <Event>();

            eventItem.Slug.Should().Be(slug);
        }
Esempio n. 14
0
        public async Task Get_ShouldReturnCommsHomepageModel_AndHasEvent()
        {
            // Arrange
            var expectedEvent = new ContentfulEventBuilder().Build();
            var commsCallback = new ContentfulCommsHomepage();

            _mockCommsHomepageFactory
            .Setup(_ => _
                   .ToModel(It.IsAny <ContentfulCommsHomepage>()))
            .Returns(new CommsHomepage(
                         string.Empty,
                         string.Empty,
                         string.Empty,
                         string.Empty,
                         string.Empty,
                         string.Empty,
                         string.Empty,
                         new List <BasicLink>(),
                         null,
                         new CallToActionBanner(),
                         string.Empty
                         ))
            .Callback <ContentfulCommsHomepage>(x => commsCallback = x);

            _mockClient
            .Setup(_ =>
                   _.GetEntries(
                       It.IsAny <QueryBuilder <ContentfulCommsHomepage> >(),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(
                new ContentfulCollection <ContentfulCommsHomepage>
            {
                Items = new List <ContentfulCommsHomepage>
                {
                    new ContentfulCommsHomepage()
                }
            });

            _mockClient
            .Setup(_ =>
                   _.GetEntries(
                       It.IsAny <QueryBuilder <ContentfulEvent> >(),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(
                new ContentfulCollection <ContentfulEvent>
            {
                Items = new List <ContentfulEvent>
                {
                    expectedEvent
                }
            });

            // Act
            var result = await _repository.Get();

            var parsedResult = result.Get <CommsHomepage>();

            // Assert
            _mockCommsHomepageFactory.Verify(_ => _.ToModel(It.IsAny <ContentfulCommsHomepage>()), Times.Once);
            _mockClient.Verify(_ => _.GetEntries(It.IsAny <QueryBuilder <ContentfulCommsHomepage> >(), It.IsAny <CancellationToken>()), Times.Once);
            _mockClient.Verify(_ => _.GetEntries(It.IsAny <QueryBuilder <ContentfulEvent> >(), It.IsAny <CancellationToken>()), Times.Once);
            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
            Assert.IsType <CommsHomepage>(parsedResult);
            Assert.NotNull(commsCallback.WhatsOnInStockportEvent);
            Assert.Same(expectedEvent, commsCallback.WhatsOnInStockportEvent);
        }