/// <summary> /// Schedule a notification on the scheduled date. If there is extra /// notification info then include that in the notification. /// </summary> /// <param name="scheduledDate">The date and time you want the notification to appear.</param> private void ScheduleNotification(DateTime scheduledDate) { string notificationId; // Setup the date and the messages. const string title = "Scheduled Now"; var message = $"Created: {DateTime.Now:G}, Scheduled: {scheduledDate:G}"; // Check if the extra info should be included when sending the notification // then schedule the notification. if (IncludeExtraInfo) { var extraInfo = new Dictionary <string, string> { { "ExtraInfoOne", ExtraInfoOne }, { "ExtraInfoTwo", ExtraInfoTwo } }; notificationId = _notificationScheduler.Create(title, message, scheduledDate, extraInfo); } else { notificationId = _notificationScheduler.Create(title, message, scheduledDate); } // Keep track of this scheduled notification. ScheduledNotificationRepository.NotificationScheduled(notificationId, title, message, scheduledDate, ExtraInfoOne, ExtraInfoTwo); // Add to the list of notifications. ScheduledNotifications.Add(new MainPageViewModelScheduledNotification { Text = notificationId }); }
public void CreateNotification() { // Expected values. var expectedTitle = "Test Notification"; var expectedMessage = DateTime.Now.Ticks.ToString(); var expectedScheduledDate = DateTime.Now.AddHours(1); var expectedExtraInfo = new Dictionary <string, string>() { { "First Info", "First Value" }, { "Second Info", "Second Value" } }; // Create the notification. var notificationId = _schedulerToTest.Create(expectedTitle, expectedMessage, expectedScheduledDate, expectedExtraInfo); // See if we can find it and make sure all the values are set correctly. var foundNotification = _schedulerToTest.Find(notificationId); Assert.That(foundNotification, Is.Not.Null); Assert.That(foundNotification.Title, Is.EqualTo(expectedTitle)); Assert.That(foundNotification.Message, Is.EqualTo(expectedMessage)); var foundExtraInfo = foundNotification.ExtraInfo; Assert.That(foundExtraInfo, Is.Not.Null); Assert.AreEqual(expectedExtraInfo.Count, foundExtraInfo.Count); foreach (var ei in expectedExtraInfo) { Assert.That(foundExtraInfo.ContainsKey(ei.Key)); Assert.That(foundExtraInfo[ei.Key], Is.EqualTo(ei.Value)); } }
public void NotificationCanceled() { // Schedule a notifiaction. var notificationId = _schedulerToTest.Create("Test Notification", "Test notification message.", DateTime.Now.AddHours(1)); // Cancel it. _schedulerToTest.Cancel(notificationId); // Try to find it. Shouldn't find it because it has been cancelled. Assert.That(() => _schedulerToTest.Find(notificationId), Is.Null); }
public void NotificationExists() { // Create the notifiaction to find. const string expectedNotificationTitle = "Test Notification"; const string expectedNotificationMessage = "This is a test notification."; var expectedNotificationId = _schedulerToTest.Create(expectedNotificationTitle, expectedNotificationMessage, DateTime.Now.AddHours(1)); // Try to find it. var resultNotification = _schedulerToTest.Find(expectedNotificationId); Assert.That(resultNotification, Is.Not.Null); Assert.That(resultNotification.Title, Is.EqualTo(expectedNotificationTitle)); Assert.That(resultNotification.Message, Is.EqualTo(expectedNotificationMessage)); }