public MvvmCustomNotification(object viewModel, CustomNotifier notifier, Window window, int duration) { this.notifier = notifier; this.window = window; this.duration = duration; this.notification = new CustomNotification(viewModel, notifier); }
public void ResultsTest() { CustomNotification toast; Task <NotificationResult> task; var notifier = new CustomNotifier(); toast = new CustomNotification(null, notifier); task = notifier.ShowAsync(toast, 1); WaitWithDispatcher(task); Assert.AreEqual(NotificationResult.TimedOut, task.Result); toast = new CustomNotification(null, notifier); task = notifier.ShowAsync(toast, 1); toast.Activate(); WaitWithDispatcher(task); Assert.AreEqual(NotificationResult.Activated, task.Result); toast = new CustomNotification(null, notifier); task = notifier.ShowAsync(toast, 1); toast.Dismiss(); WaitWithDispatcher(task); Assert.AreEqual(NotificationResult.UserCanceled, task.Result); toast = new CustomNotification(null, notifier); task = notifier.ShowAsync(toast, 1); toast.Hide(); WaitWithDispatcher(task); Assert.AreEqual(NotificationResult.ApplicationHidden, task.Result); var tasks = Enumerable.Range(0, 10).Select(_ => notifier.ShowAsync(new CustomNotification(null, notifier), 1)).ToList(); tasks.ToList().ForEach(WaitWithDispatcher); tasks.ToList().ForEach(t => Assert.AreEqual(NotificationResult.TimedOut, t.Result)); }
public void BasicResolutionChangedHandlingTest() { var testScreen = new TestScreen { bounds = new Rect(0, 0, 1000, 500) }; var notifier = new CustomNotifier(testScreen); notifier.UpdatePositioner(NotificationPosition.BottomRight, 2); var toasts = Enumerable.Range(0, 3).Select(_ => new CustomNotification(null, notifier)).ToList(); var tasks = toasts.Select(toast => notifier.ShowAsync(toast, 1)).ToList(); var pos = CustomNotifier.positioner; var ps = pos.Items.Select(i => pos.GetItemPosition(i)).ToList(); Assert.AreEqual(new Point(615, 390), ps[0]); Assert.AreEqual(new Point(615, 290), ps[1]); testScreen.bounds = new Rect(0, 0, 800, 600); testScreen.Changed(); pos = CustomNotifier.positioner; ps = pos.Items.Select(i => pos.GetItemPosition(i)).ToList(); Assert.AreEqual(new Point(415, 490), ps[0]); Assert.AreEqual(new Point(415, 390), ps[1]); tasks.ToList().ForEach(WaitWithDispatcher); tasks.ToList().ForEach(t => Assert.AreEqual(NotificationResult.TimedOut, t.Result)); }
public void ResettingTimerOfHiddenNotificationTest() { var customNotifier = new CustomNotifier(new TestScreen()); var toast = new CustomNotification(null, customNotifier); customNotifier.ShowAsync(toast); customNotifier.Hide(toast); customNotifier.ResetTimer(toast); customNotifier.StopTimer(toast); }
public void ShowingTooManyToastsTest() { var notifier = new CustomNotifier(); notifier.UpdatePositioner(NotificationPosition.TopRight, 100); var tasks = Enumerable.Range(0, 100).Select(_ => notifier.ShowAsync(new CustomNotification(null, notifier), 1)).ToList(); tasks.ToList().ForEach(WaitWithDispatcher); tasks.ToList().ForEach(t => Assert.AreEqual(NotificationResult.TimedOut, t.Result)); }
public void CustomNotificationTemplateSelectorTest() { var customNotifier = new CustomNotifier(new TestScreen { bounds = new Rect(0, 0, 1000, 500) }); var selector = new TestTemplateSelector(); customNotifier.ContentTemplateSelector = selector; var toast = new CustomNotification(null, customNotifier); WaitWithDispatcher(customNotifier.ShowAsync(toast, 1)); Assert.IsTrue(selector.Called); }
public void RemovePostponedNotificationTest() { var notifier = new CustomNotifier(); notifier.UpdatePositioner(NotificationPosition.TopRight, 1); var toasts = Enumerable.Range(0, 3).Select(_ => new CustomNotification(null, notifier)).ToList(); var tasks = toasts.Select(toast => notifier.ShowAsync(toast, 1)).ToList(); toasts[2].Hide(); tasks.ToList().ForEach(WaitWithDispatcher); Assert.AreEqual(NotificationResult.TimedOut, tasks[0].Result); Assert.AreEqual(NotificationResult.TimedOut, tasks[1].Result); Assert.AreEqual(NotificationResult.ApplicationHidden, tasks[2].Result); }
public void NotificationsArentLostOnPositionerUpdateTest() { var testScreen = new TestScreen { bounds = new Rect(0, 0, 1000, 500) }; var notifier1 = new CustomNotifier(testScreen); var notifier2 = new CustomNotifier(testScreen); var positioner = CustomNotifier.positioner; notifier1.UpdatePositioner(NotificationPosition.BottomRight, 5); var toasts1 = Enumerable.Range(0, 1).Select(_ => new CustomNotification(null, notifier1)).ToList(); var toasts2 = Enumerable.Range(0, 1).Select(_ => new CustomNotification(null, notifier2)).ToList(); var tasks1 = toasts1.Select(toast => notifier1.ShowAsync(toast, 1)).ToList(); var tasks2 = toasts2.Select(toast => notifier2.ShowAsync(toast, 1)).ToList(); tasks1.Union(tasks2).ToList().ForEach(WaitWithDispatcher); tasks1.Union(tasks2).ToList().ForEach(t => Assert.AreEqual(NotificationResult.TimedOut, t.Result)); }
public void UpdatingPositionerTest() { CustomNotification toast; Task <NotificationResult> task; var notifier = new CustomNotifier(); var tasks = Enumerable.Range(0, 5).Select(_ => notifier.ShowAsync(new CustomNotification(null, notifier), 1)).ToList(); tasks.ToList().ForEach(WaitWithDispatcher); tasks.ToList().ForEach(t => Assert.AreEqual(NotificationResult.TimedOut, t.Result)); toast = new CustomNotification(null, notifier); task = notifier.ShowAsync(toast, 1); notifier.UpdatePositioner(NotificationPosition.TopRight, 2); WaitWithDispatcher(task); Assert.AreEqual(NotificationResult.TimedOut, task.Result); tasks = Enumerable.Range(0, 10).Select(_ => notifier.ShowAsync(new CustomNotification(null, notifier), 1)).ToList(); notifier.UpdatePositioner(NotificationPosition.TopRight, 2); tasks.ToList().ForEach(WaitWithDispatcher); tasks.ToList().ForEach(t => Assert.AreEqual(NotificationResult.TimedOut, t.Result)); }
public void ResolutionChangingTest() { var testScreen = new TestScreen { bounds = new Rect(0, 0, 1000, 500) }; var notifier = new CustomNotifier(testScreen); notifier.UpdatePositioner(NotificationPosition.BottomRight, 2); var toasts = Enumerable.Range(0, 3).Select(_ => new CustomNotification(null, notifier)).ToList(); var tasks = toasts.Select(toast => notifier.ShowAsync(toast, 1)).ToList(); Assert.AreEqual(2, CustomNotifier.positioner.Items.Count(i => i != null)); testScreen.bounds = new Rect(0, 0, 800, 600); testScreen.Changed(); Assert.AreEqual(2, CustomNotifier.positioner.Items.Count(i => i != null)); tasks.ToList().ForEach(WaitWithDispatcher); }
public void UpdatePositionerTest() { var testScreen = new TestScreen { bounds = new Rect(0, 0, 800, 600) }; var notifier = new CustomNotifier(testScreen); var pos = CustomNotifier.positioner; var toast = new CustomNotification(null, notifier); var task = notifier.ShowAsync(toast, 1); var p1 = CustomNotifier.positioner.GetItemPosition(CustomNotifier.positioner.Items[0]); Assert.AreEqual(415, p1.X); Assert.AreEqual(20, p1.Y); notifier.UpdatePositioner(NotificationPosition.BottomRight, 3); p1 = CustomNotifier.positioner.GetItemPosition(CustomNotifier.positioner.Items[0]); Assert.AreEqual(415, p1.X); Assert.AreEqual(490, p1.Y); WaitWithDispatcher(task); }
public void RemovePostponedNotificationTest() { var notifier = new CustomNotifier(); notifier.UpdatePositioner(NotificationPosition.TopRight, 1); var toasts = Enumerable.Range(0, 3).Select(_ => new CustomNotification(null, notifier)).ToList(); var tasks = toasts.Select(toast => notifier.ShowAsync(toast, 1)).ToList(); toasts[2].Hide(); tasks.ToList().ForEach(WaitWithDispatcher); Assert.AreEqual(NotificationResult.TimedOut, tasks[0].Result); Assert.AreEqual(NotificationResult.TimedOut, tasks[1].Result); Assert.AreEqual(NotificationResult.ApplicationHidden, tasks[2].Result); }
public void ShowingTooManyToastsTest() { var notifier = new CustomNotifier(); notifier.UpdatePositioner(NotificationPosition.TopRight, 100); var tasks = Enumerable.Range(0, 100).Select(_ => notifier.ShowAsync(new CustomNotification(null, notifier), 1)).ToList(); tasks.ToList().ForEach(WaitWithDispatcher); tasks.ToList().ForEach(t => Assert.AreEqual(NotificationResult.TimedOut, t.Result)); }
public void UpdatingPositionerTest() { CustomNotification toast; Task<NotificationResult> task; var notifier = new CustomNotifier(); var tasks = Enumerable.Range(0, 5).Select(_ => notifier.ShowAsync(new CustomNotification(null, notifier), 1)).ToList(); tasks.ToList().ForEach(WaitWithDispatcher); tasks.ToList().ForEach(t => Assert.AreEqual(NotificationResult.TimedOut, t.Result)); toast = new CustomNotification(null, notifier); task = notifier.ShowAsync(toast, 1); notifier.UpdatePositioner(NotificationPosition.TopRight, 2); WaitWithDispatcher(task); Assert.AreEqual(NotificationResult.TimedOut, task.Result); tasks = Enumerable.Range(0, 10).Select(_ => notifier.ShowAsync(new CustomNotification(null, notifier), 1)).ToList(); notifier.UpdatePositioner(NotificationPosition.TopRight, 2); tasks.ToList().ForEach(WaitWithDispatcher); tasks.ToList().ForEach(t => Assert.AreEqual(NotificationResult.TimedOut, t.Result)); }
public void ResultsTest() { CustomNotification toast; Task<NotificationResult> task; var notifier = new CustomNotifier(); toast = new CustomNotification(null, notifier); task = notifier.ShowAsync(toast, 1); WaitWithDispatcher(task); Assert.AreEqual(NotificationResult.TimedOut, task.Result); toast = new CustomNotification(null, notifier); task = notifier.ShowAsync(toast, 1); toast.Activate(); WaitWithDispatcher(task); Assert.AreEqual(NotificationResult.Activated, task.Result); toast = new CustomNotification(null, notifier); task = notifier.ShowAsync(toast, 1); toast.Dismiss(); WaitWithDispatcher(task); Assert.AreEqual(NotificationResult.UserCanceled, task.Result); toast = new CustomNotification(null, notifier); task = notifier.ShowAsync(toast, 1); toast.Hide(); WaitWithDispatcher(task); Assert.AreEqual(NotificationResult.ApplicationHidden, task.Result); var tasks = Enumerable.Range(0, 10).Select(_ => notifier.ShowAsync(new CustomNotification(null, notifier), 1)).ToList(); tasks.ToList().ForEach(WaitWithDispatcher); tasks.ToList().ForEach(t => Assert.AreEqual(NotificationResult.TimedOut, t.Result)); }
public void ResettingTimerOfHiddenNotificationTest() { var customNotifier = new CustomNotifier(new TestScreen()); var toast = new CustomNotification(null, customNotifier); customNotifier.ShowAsync(toast); customNotifier.Hide(toast); customNotifier.ResetTimer(toast); customNotifier.StopTimer(toast); }
public void CustomNotificationTemplateSelectorTest() { var customNotifier = new CustomNotifier(new TestScreen { bounds = new Rect(0, 0, 1000, 500) }); var selector = new TestTemplateSelector(); customNotifier.ContentTemplateSelector = selector; var toast = new CustomNotification(null, customNotifier); WaitWithDispatcher(customNotifier.ShowAsync(toast, 1)); Assert.IsTrue(selector.Called); }
public MvvmCustomNotification(object viewModel, CustomNotifier notifier, int duration) { this.notifier = notifier; this.duration = duration; this.notification = new CustomNotification(viewModel, notifier); }
public CustomNotification(object viewModel, CustomNotifier notifier) { ViewModel = viewModel; this.notifier = notifier; }
public void UpdatePositionerTest() { var testScreen = new TestScreen { bounds = new System.Drawing.Rectangle(0, 0, 800, 600) }; var notifier = new CustomNotifier(testScreen); var pos = CustomNotifier.positioner; var toast = new CustomNotification(null, notifier); var task = notifier.ShowAsync(toast, 1); var p1 = CustomNotifier.positioner.GetItemPosition(CustomNotifier.positioner.Items[0]); Assert.AreEqual(415, p1.X); Assert.AreEqual(20, p1.Y); notifier.UpdatePositioner(NotificationPosition.BottomRight, 3); p1 = CustomNotifier.positioner.GetItemPosition(CustomNotifier.positioner.Items[0]); Assert.AreEqual(415, p1.X); Assert.AreEqual(490, p1.Y); WaitWithDispatcher(task); }
void UpdateCustomNotifierPositioner() { CustomNotifier.UpdatePositioner(CustomNotificationPosition, CustomNotificationVisibleMaxCount); }
public WpfPredefinedToastNotification(WpfPredefinedToastNotificationContent content, CustomNotifier notifier) { this.toast = new CustomNotification(content.ViewModel, notifier); this.content = content; this.notifier = notifier; this.notifier.ContentTemplate = NotificationServiceTemplatesHelper.PredefinedToastTemplate; }
public void BasicResolutionChangedHandlingTest() { var testScreen = new TestScreen { bounds = new System.Drawing.Rectangle(0, 0, 1000, 500) }; var notifier = new CustomNotifier(testScreen); notifier.UpdatePositioner(NotificationPosition.BottomRight, 2); var toasts = Enumerable.Range(0, 3).Select(_ => new CustomNotification(null, notifier)).ToList(); var tasks = toasts.Select(toast => notifier.ShowAsync(toast, 1)).ToList(); var pos = CustomNotifier.positioner; var ps = pos.Items.Select(i => pos.GetItemPosition(i)).ToList(); Assert.AreEqual(new Point(615, 390), ps[0]); Assert.AreEqual(new Point(615, 290), ps[1]); testScreen.bounds = new System.Drawing.Rectangle(0, 0, 800, 600); testScreen.Changed(); pos = CustomNotifier.positioner; ps = pos.Items.Select(i => pos.GetItemPosition(i)).ToList(); Assert.AreEqual(new Point(415, 490), ps[0]); Assert.AreEqual(new Point(415, 390), ps[1]); tasks.ToList().ForEach(WaitWithDispatcher); tasks.ToList().ForEach(t => Assert.AreEqual(NotificationResult.TimedOut, t.Result)); }
public void NotificationsArentLostOnPositionerUpdateTest() { var testScreen = new TestScreen { bounds = new System.Drawing.Rectangle(0, 0, 1000, 500) }; var notifier1 = new CustomNotifier(testScreen); var notifier2 = new CustomNotifier(testScreen); var positioner = CustomNotifier.positioner; notifier1.UpdatePositioner(NotificationPosition.BottomRight, 5); var toasts1 = Enumerable.Range(0, 1).Select(_ => new CustomNotification(null, notifier1)).ToList(); var toasts2 = Enumerable.Range(0, 1).Select(_ => new CustomNotification(null, notifier2)).ToList(); var tasks1 = toasts1.Select(toast => notifier1.ShowAsync(toast, 1)).ToList(); var tasks2 = toasts2.Select(toast => notifier2.ShowAsync(toast, 1)).ToList(); tasks1.Union(tasks2).ToList().ForEach(WaitWithDispatcher); tasks1.Union(tasks2).ToList().ForEach(t => Assert.AreEqual(NotificationResult.TimedOut, t.Result)); }
public WpfToastNotificationFactory() { this.notifier = new CustomNotifier(); this.notifier.UpdatePositioner(NotificationPosition.TopRight, 3); }
public void ResolutionChangingTest() { var testScreen = new TestScreen { bounds = new System.Drawing.Rectangle(0, 0, 1000, 500) }; var notifier = new CustomNotifier(testScreen); notifier.UpdatePositioner(NotificationPosition.BottomRight, 2); var toasts = Enumerable.Range(0, 3).Select(_ => new CustomNotification(null, notifier)).ToList(); var tasks = toasts.Select(toast => notifier.ShowAsync(toast, 1)).ToList(); Assert.AreEqual(2, CustomNotifier.positioner.Items.Count(i => i != null)); testScreen.bounds = new System.Drawing.Rectangle(0, 0, 800, 600); testScreen.Changed(); Assert.AreEqual(2, CustomNotifier.positioner.Items.Count(i => i != null)); tasks.ToList().ForEach(WaitWithDispatcher); }
public CustomNotification(object viewModel, CustomNotifier notifier) { ViewModel = viewModel; this.notifier = notifier; }