예제 #1
0
        public async Task <IActionResult> SendPushReminders()
        {
            try
            {
                var reminders = await _notificationService.GetActivePushReminders();

                if (reminders.Count > 0)
                {
                    var client = new PushClient();

                    var notificationList = new List <PushMessage>();

                    foreach (var reminder in reminders)
                    {
                        notificationList.Add(new PushMessage(reminder.Token, title: "Reminder", body: reminder.Message));
                    }
                    try
                    {
                        var response = await client.PublishMultiple(notificationList);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        return(Json(new { sent = reminders.Count, error = ex.Message }));
                    }
                }

                return(Json(new { sent = reminders.Count, error = "" }));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(BadRequest());
            }
        }
        public async Task PublishMultiple_ShouldThrowArgumentNullExceptionWhenPushMessageIsEmpty()
        {
            var pushClient = new PushClient();

            await Assert.ThrowsAsync <ArgumentNullException>(async() => await pushClient.PublishMultiple(null));
        }