public async Task Campus_GetMenuAsync_ShouldReturnNullWhenInputIsInvalid(string url) { //Act var result = await Campus.GetMenuAsync(url); //Assert Assert.Null(result); }
public void Campus_GetMenuAsync_ShouldContainMoreThan18Characters() { //Act var result = Campus .GetMenuAsync("https://www.pxl.be/Pub/Studenten/Voorzieningen-Student/Catering/Weekmenu-Campus-Elfde-Linie.html") .Result; //Assert Assert.NotNull(result); Assert.True(result.Length > 155); }
public static async Task SendNotificationAsync([TimerTrigger("0 */1 8-20 * * 1-5")] TimerInfo myTimer, ILogger log) { if (Environment.GetEnvironmentVariable("ENVIRONMENT") == "dev") { return; } await Task.Delay(100); var currentHour = DateTime.Now.Hour; var currentMinute = DateTime.Now.Minute; var table = await Table.GetTableAsync("catering"); var subscriptions = await table.ExecuteQuerySegmentedAsync( new TableQuery <Subscription>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "subscription")), new TableContinuationToken()); var notificationSettings = subscriptions .Where(s => s.CurrentSubscription != null) .Where(s => s.CurrentSubscription.NotificationSettings.ContainsKey(DateTime.Now.DayOfWeek)) .Select(s => new { Settings = s.CurrentSubscription.NotificationSettings[DateTime.Now.DayOfWeek], s.Email }) .Where(ns => ns.Settings.Value.Hour == currentHour && ns.Settings.Value.Minute == currentMinute) .GroupBy(ns => ns.Settings.Key) .ToDictionary(g => g.Key, g => g.AsEnumerable()); if (notificationSettings.ContainsKey(Subscription.UserSubscription.Campus.ElfdeLinie)) { var settings = notificationSettings[Subscription.UserSubscription.Campus.ElfdeLinie].ToList(); if (!settings.Any()) { return; } string menu = await Campus.GetMenuAsync( "https://www.pxl.be/Pub/Studenten/Voorzieningen-Student/Catering/Weekmenu-Campus-Elfde-Linie.html"); if (menu == string.Empty) { return; } log.LogInformation($"Mails sent at {DateTime.Today.Day}-{DateTime.Today.Month}-{DateTime.Today.Year}"); await Mail.SendMailAsync(settings.Select(ns => ns.Email).ToList(), $"PXL Menu {DateTime.Today.Day}-{DateTime.Today.Month}-{DateTime.Today.Year}", menu); } }