Exemple #1
0
        public static async Task <System.Collections.Generic.List <Models.CalendarEntry> > GetCalendars(TokenEntity msaToken, TokenEntity googleToken,
                                                                                                        ILogger logger)
        {
            var start  = DateTime.Now.Date.AddDays(-7);
            var end    = DateTime.Now.Date.AddDays(Constants.CalendarWeeks * 7);
            var events = new System.Collections.Generic.List <CalendarEntry>();

            try
            {
                var holidays = new System.Collections.Generic.List <CalendarEntry>();

                // combine public and school holidays
                var publicHolidaysService = new PublicHolidaysService();
                var schoolHolidaysService = new SchoolHolidaysService();

                holidays.AddRange(await publicHolidaysService.GetEvents(start, end));
                holidays.AddRange(await schoolHolidaysService.GetEvents(start, end, logger));
                var deduplicatedHolidays = holidays.GroupBy(x => x.Date).Select(y => y.First()).ToList <CalendarEntry>();
                events.AddRange(deduplicatedHolidays);

                var googleCalendarService = new GoogleCalendarService(
                    googleToken,
                    calendarId: Util.GetEnvironmentVariable("GOOGLE_CALENDAR_ID"),
                    timeZone: Util.GetEnvironmentVariable("CALENDAR_TIMEZONE"));
                var googleEvents = await googleCalendarService.GetEvents(start, end, isPrimary : true);

                events.AddRange(googleEvents);

                var outlookCalendarService = new OutlookCalendarService(msaToken,
                                                                        timeZone: Util.GetEnvironmentVariable("CALENDAR_TIMEZONE"));
                var outlookEvents = await outlookCalendarService.GetEvents(start, end, isSecondary : true);

                events.AddRange(outlookEvents);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(events);
        }
Exemple #2
0
        public async Task TestOutlookCalendarService1Week()
        {
            // arrange
            var service = new OutlookCalendarService(
                msaToken: new TokenEntity()
            {
                TokenType   = "bearer",
                AccessToken = TestContext.Parameters["OUTLOOK_TEST_TOKEN"]
            }
                );

            var start = new DateTime(2019, 4, 22);
            var end   = new DateTime(2019, 5, 25);

            // act
            var result = await service.GetEvents(start, end);

            // assert
            Assert.IsNotNull(result);
            Assert.Greater(result.Count, 0);
        }