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));
        }
Пример #2
0
        internal static DateTime?GetNextOccurrence(this DateTime dateTime, EventFrequency frequency)
        {
            switch (frequency)
            {
            case EventFrequency.Daily:
                return(dateTime.AddDays(1));

            case EventFrequency.Weekly:
                return(dateTime.AddDays(7));

            case EventFrequency.BiWeekly:
                return(dateTime.AddDays(14));

            case EventFrequency.Monthly:
                return(dateTime.AddMonths(1));

            case EventFrequency.BiMonthly:
                return(dateTime.AddMonths(2));

            case EventFrequency.Annually:
                return(dateTime.AddYears(1));

            case EventFrequency.BiAnnually:
                return(dateTime.AddYears(2));

            default:
                return(null);
            }
        }
Пример #3
0
        public int GetEventOccurences(EventFrequency freq, DateTime startDate, DateTime endDate)
        {
            double diff = 0;

            switch (freq)
            {
            case EventFrequency.None:
                diff = 0;
                break;

            case EventFrequency.Daily:
                diff = endDate.Subtract(startDate).Days;
                break;

            case EventFrequency.Weekly:
                diff = endDate.Subtract(startDate).Days / 7;
                break;

            case EventFrequency.Fortnightly:
                diff = endDate.Subtract(startDate).Days / 14;
                break;

            case EventFrequency.Monthly:
            case EventFrequency.MonthlyDate:
            case EventFrequency.MonthlyDay:
                var temp = startDate;
                do
                {
                    temp = temp.AddMonths(1);
                    diff++;
                } while (temp <= endDate && diff < 1000);

                return((int)diff);

            case EventFrequency.Yearly:
                var tempYears = startDate;
                do
                {
                    tempYears = tempYears.AddYears(1);
                    diff++;
                } while (tempYears <= endDate && diff < 1000);

                return((int)diff);
            }

            return((int)Math.Floor(diff) + 1); // Add 1 for the initial occurence;
        }
Пример #4
0
        public void  ShowReturnCorrectEndDateForReoccurringEvents(int daysHence, EventFrequency freq, int occurences)
        {
            // Arrange
            var date = new DateTime(2017, 12, 25);

            _mockTimeProvider.Setup(o => o.Today()).Returns(date);

            var dateCalculator = new DateCalculator(_mockTimeProvider.Object);

            var testEvent = new Event {
                EventFrequency = freq, Occurences = occurences, EventDate = date
            };

            // Act
            var enddate = dateCalculator.GetEventEndDate(testEvent);

            // Assert
            enddate.Should().Be(testEvent.EventDate.AddDays(daysHence));
        }
Пример #5
0
        public IEnumerable <DiaryEventModel> CreateSeries(EventFrequency frequency, DateTime endDate)
        {
            var series = new List <DiaryEventModel>();

            series.Add(this);

            DateTime?nextStartTime = StartTime.GetNextOccurrence(frequency);
            TimeSpan duration      = EndTime - StartTime;

            while (nextStartTime.HasValue && nextStartTime <= endDate)
            {
                var newEvent = (DiaryEventModel)Clone();
                newEvent.StartTime = nextStartTime.Value;
                newEvent.EndTime   = nextStartTime.Value.Add(duration);
                series.Add(newEvent);

                nextStartTime = nextStartTime.Value.GetNextOccurrence(frequency);
            }

            return(series);
        }
        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));
        }
Пример #7
0
 public Event(string title, string slug, string teaser, string imageUrl, string description, string fee,
              string location, string submittedBy, DateTime eventDate, string startTime, string endTime,
              int occurences, EventFrequency frequency, List <Crumb> breadcrumbs, string thumbnailImageUrl,
              List <Document> documents, List <string> categories, MapPosition mapPosition, bool featured,
              string bookingInformation, DateTime?updatedAt, List <string> tags, Group group, List <Alert> alerts, List <EventCategory> eventCategories, bool?free, bool?paid, string accessibleTransportLink, string metaDescription)
 {
     Title                   = title;
     Slug                    = slug;
     Teaser                  = teaser;
     Description             = description;
     Fee                     = fee;
     Location                = location;
     SubmittedBy             = submittedBy;
     EventDate               = eventDate;
     StartTime               = startTime;
     EndTime                 = endTime;
     Occurences              = occurences;
     EventFrequency          = frequency;
     Breadcrumbs             = breadcrumbs;
     ThumbnailImageUrl       = thumbnailImageUrl;
     ImageUrl                = imageUrl;
     Documents               = documents;
     Categories              = categories.Select(s => s).ToList();
     MapPosition             = mapPosition;
     BookingInformation      = bookingInformation;
     Featured                = featured;
     UpdatedAt               = updatedAt;
     Tags                    = tags.Select(s => s.ToLower()).ToList();
     Group                   = group;
     Alerts                  = alerts;
     EventCategories         = eventCategories;
     Paid                    = paid;
     Free                    = free;
     Coord                   = MapPosition == null ? null : new GeoCoordinate(MapPosition.Lat, MapPosition.Lon);
     AccessibleTransportLink = accessibleTransportLink;
     MetaDescription         = metaDescription;
 }
Пример #8
0
        public void GetEventOccurences_ShowReturnCorrectCountOfEventOccurences(int daysHence, EventFrequency freq, int occurences)
        {
            // Arrange
            var date = new DateTime(2017, 12, 25);

            _mockTimeProvider.Setup(o => o.Today()).Returns(date);

            var dateCalculator = new DateCalculator(_mockTimeProvider.Object);

            var testEvent = new Event {
                EventFrequency = freq, Occurences = occurences, EventDate = date
            };

            // Act
            var result = dateCalculator.GetEventOccurences(testEvent.EventFrequency, testEvent.EventDate, testEvent.EventDate.AddDays(daysHence));

            // Assert
            result.Should().Be(occurences);
        }
 public ContentfulEventBuilder Frequency(EventFrequency frequency)
 {
     _eventFrequency = frequency;
     return(this);
 }