Ejemplo n.º 1
0
        public void PublishNotificationShouldDelegateToNotificationsManagerWithCorrectParameters()
        {
            var notifications = new Notification[] { new AppleNotification("notifierName", "message", "chime") };
            INotificationRecipients recipients = new NotificationRecipients().AddUserWithName("username");
            var schedulerSettings = new NotificationSchedulerSettings {
                DeliverAt = DateTime.Now.AddDays(1)
            };

            _client.PublishNotification(notifications, recipients, schedulerSettings);

            _notificationsManager.Received(1).PublishNotification(notifications, recipients, schedulerSettings);
        }
Ejemplo n.º 2
0
        public void PublishNotificationPostsByBuildingQueryAndPayload()
        {
            IRestResponse restResponse = Helpers.SetUpRestResponse(HttpStatusCode.OK);

            _request.ExecuteJsonRequest(Arg.Any <string>(), Arg.Any <Method>(), Arg.Any <object>())
            .Returns(restResponse);

            var recipients = Substitute.For <INotificationRecipients>();

            recipients.BuildQuery().Returns("query");

            var appleNotification  = new AppleNotification("appleNotifierName", "appleTestMessge", "chime");
            var googleNotification = new AndroidNotification("googleNotifierName", "androidTestMessage");

            var deliverAt = DateTime.Now.AddDays(1);
            var expireAt  = DateTime.Now.AddDays(2);

            var schedulerSettings = new NotificationSchedulerSettings {
                DeliverAt = deliverAt, ExpireAt = expireAt
            };

            //call PublishNotification
            _notificationsManager.PublishNotification(new Notification[] { appleNotification, googleNotification }, recipients, schedulerSettings);

            //assert
            recipients.Received(1).BuildQuery();

            Func <NotificationPayload, bool> validatePayload = p =>
            {
                bool isValid = true;
                isValid &= p.DeliverAt == deliverAt.ToUnixTime();
                isValid &= p.ExpireAt == expireAt.ToUnixTime();

                var applePayload = p.Payloads["appleNotifierName"].GetReflectedProperty("aps");
                isValid &= (string)applePayload.GetReflectedProperty("alert") == "appleTestMessge";
                isValid &= (string)applePayload.GetReflectedProperty("sound") == "chime";

                var googlePayload = p.Payloads["googleNotifierName"].GetReflectedProperty("data");
                isValid &= (string)googlePayload == "androidTestMessage";

                return(isValid);
            };

            _request.Received(1).ExecuteJsonRequest("query", Method.POST,
                                                    Arg.Is <NotificationPayload>(
                                                        p => validatePayload(p)));
        }
Ejemplo n.º 3
0
        public void ShouldPublishNotifications()
        {
            //Set up
            const string appleNotifierName  = "apple_notifier";
            const string googleNotifierName = "google_notifier";
            const string username           = "******";
            const string appleTestMessge    = "test message for Apple";
            const string androidTestMessage = "test message for Android";

            var client = InitializeClientAndLogin(AuthType.Organization);

            CreateAppleNotifier(client, appleNotifierName);
            CreateAndroidNotifier(client, googleNotifierName);
            CreateUser(username, client);

            //Setup Notifications
            var appleNotification  = new AppleNotification(appleNotifierName, appleTestMessge, "chime");
            var googleNotification = new AndroidNotification(googleNotifierName, androidTestMessage);
            //Setup recipients and scheduling
            INotificationRecipients recipients = new NotificationRecipients().AddUserWithName(username);
            var schedulerSettings = new NotificationSchedulerSettings {
                DeliverAt = DateTime.Now.AddDays(1)
            };

            client.PublishNotification(new Notification[] { appleNotification, googleNotification }, recipients, schedulerSettings);

            //Assert
            UsergridCollection <dynamic> entities = client.GetEntities <dynamic>("notifications", query: "order by created desc");
            dynamic notification = entities.FirstOrDefault();

            Assert.IsNotNull(notification);
            Assert.IsNotNull(notification.uuid);
            Assert.AreEqual(appleTestMessge, notification.payloads.apple_notifier.aps.alert.Value);
            Assert.AreEqual("chime", notification.payloads.apple_notifier.aps.sound.Value);
            Assert.AreEqual(androidTestMessage, notification.payloads.google_notifier.data.Value);

            //Cancel notification and assert it is canceled
            client.CancelNotification(notification.uuid.Value);
            dynamic entity = client.GetEntity <dynamic>("notifications", notification.uuid.Value);

            Assert.AreEqual(entity.state.Value, "CANCELED");
        }
Ejemplo n.º 4
0
        public void PublishNotification(IEnumerable <Notification> notifications, INotificationRecipients recipients, NotificationSchedulerSettings schedulerSettings = null)
        {
            var payload = new NotificationPayload();

            foreach (Notification notification in notifications)
            {
                payload.Payloads.Add(notification.NotifierIdentifier, notification.GetPayload());
            }

            if (schedulerSettings != null)
            {
                if (schedulerSettings.DeliverAt != DateTime.MinValue)
                {
                    payload.DeliverAt = schedulerSettings.DeliverAt.ToUnixTime();
                }
                if (schedulerSettings.ExpireAt != DateTime.MinValue)
                {
                    payload.ExpireAt = schedulerSettings.ExpireAt.ToUnixTime();
                }
            }

            string query = recipients.BuildQuery();

            IRestResponse response = Request.ExecuteJsonRequest(query, Method.POST, payload);

            ValidateResponse(response);
        }
Ejemplo n.º 5
0
 public void PublishNotification(IEnumerable <Notification> notifications, INotificationRecipients recipients, NotificationSchedulerSettings schedulerSettings = null)
 {
     NotificationsManager.PublishNotification(notifications, recipients, schedulerSettings);
 }