Example #1
0
        public MainWindow()
        {
            InitializeComponent();

            AppDomain.CurrentDomain.UnhandledException += (s, e) => { MessageBox.Show(e.ExceptionObject.ToString()); };

            NotificationClient.NotificationClosed         += NotificationClient_NotificationClosed;
            NotificationClient.NotificationCreated        += NotificationClient_NotificationCreated;
            NotificationClient.NotificationActionOccurred += NotificationClient_NotificationActionOccurred;
            toggleButtons(false);

            NotificationClient.OnInitComplete += async() =>
            {
                toggleButtons(true);

                //var status = await NotificationClient.GetProviderStatusAsync();

                //Dispatcher.Invoke(() =>
                //{
                //    bodyContentTypeSelector.SelectedIndex = 0;

                //    connected.Content = !status.Connected ? "Failed to connect." : "Connected";
                //    if(status.Connected)
                //    {
                //        version.Content = $"(v.{status.Version})";
                //    }
                //});
            };

            NotificationClient.Initialize();
        }
Example #2
0
        public void CreateNotification_CreateNotification_ReturnsOptions()
        {
            var are = new AutoResetEvent(false);

            string id = Guid.NewGuid().ToString();

            var options = new NotificationOptions
            {
                Title    = id,
                Body     = id,
                Icon     = id,
                Category = id,
                Buttons  = new ButtonOptions[] { }
            };

            NotificationClient.OnInitComplete += async() =>
            {
                var notification = await NotificationClient.CreateNotificationAsync(id, options);

                Assert.AreEqual(id, notification.Id);
                are.Set();
            };

            NotificationClient.Initialize(uri);
            are.WaitOne();
        }
Example #3
0
        public async Task CreateNotification_CreateExpiringNotificationWithHandler_CallsNotificationActionEventHandler()
        {
            var are = new AutoResetEvent(false);

            string id = Guid.NewGuid().ToString();

            var options = new NotificationOptions
            {
                Title    = id,
                Body     = id,
                Icon     = id,
                Category = id,
                Expires  = DateTime.Now.AddSeconds(10),
                Buttons  = new ButtonOptions[] { },
                OnNotificationExpired = new Dictionary <string, object>
                {
                    { "foo", "bar" }
                }
            };

            NotificationClient.OnInitComplete += () =>
            {
                are.Set();
            };

            NotificationClient.NotificationActionOccurred += (@event) =>
            {
                Assert.AreEqual(ActionTriggers.Expire, @event.ActionTrigger);
                Assert.IsTrue(@event.NotificationActionResult.ContainsKey("foo"));
                Assert.AreEqual("bar", @event.NotificationActionResult["foo"]);
                are.Set();
            };

            NotificationClient.Initialize(uri);
            are.WaitOne();
            await NotificationClient.CreateNotificationAsync(id, options);

            are.WaitOne();
        }
Example #4
0
        public async Task ClearNotification_ClearingCreatedNotification_TriggersClosedEvent()
        {
            var are = new AutoResetEvent(false);

            string id = Guid.NewGuid().ToString();

            var options = new NotificationOptions
            {
                Title    = id,
                Body     = id,
                Icon     = id,
                Category = id,
                Buttons  = new ButtonOptions[] { }
            };

            NotificationClient.OnInitComplete += () =>
            {
                are.Set();
            };

            NotificationClient.NotificationClosed += (@event) =>
            {
                Assert.AreEqual(id, @event.NotificationOptions.Id);
                are.Set();
            };

            NotificationClient.NotificationCreated += async(@event) =>
            {
                Assert.AreEqual(id, @event.NotificationOptions.Id);
                await NotificationClient.ClearNotificationAsync(id);
            };

            NotificationClient.Initialize(uri);
            are.WaitOne();
            await NotificationClient.CreateNotificationAsync(id, options);

            are.WaitOne();
        }
Example #5
0
        public MainWindow()
        {
            InitializeComponent();

            AppDomain.CurrentDomain.UnhandledException += (s, e) => { MessageBox.Show(e.ExceptionObject.ToString()); };

            NotificationClient.NotificationClosed         += NotificationClient_NotificationClosed;
            NotificationClient.NotificationCreated        += NotificationClient_NotificationCreated;
            NotificationClient.NotificationActionOccurred += NotificationClient_NotificationActionOccurred;

            NotificationClient.OnInitComplete += () =>
            {
                toggleButtons(true);

                Dispatcher.Invoke(() =>
                {
                    bodyContentTypeSelector.SelectedIndex = 0;
                });
            };

            NotificationClient.Initialize();
            toggleButtons(false);
        }
Example #6
0
        public async Task CreateNotification_CreateNotificationWithoutBody_ThrowsException()
        {
            var are = new AutoResetEvent(false);

            string id = Guid.NewGuid().ToString();

            var options = new NotificationOptions
            {
                Title    = id,
                Icon     = id,
                Category = id,
                Buttons  = new ButtonOptions[] { }
            };

            NotificationClient.OnInitComplete += () =>
            {
                are.Set();
            };

            NotificationClient.Initialize(uri);
            are.WaitOne();
            await NotificationClient.CreateNotificationAsync(id, options);
        }
Example #7
0
 public void Initialize_NullInitCompleteHandler_ExceptionThrown()
 {
     Assert.ThrowsException <InvalidOperationException>(() => { NotificationClient.Initialize(uri); });
 }