private void AssertSentFailed(NotificationTest test, NotificationAccount <Guid> account, PushNotification expectedNotification, NotificationErrorCode expectedErrorCode) { NotificationSendFailure notificationSendFailure = test.RaisedEvents.OfType <NotificationSendFailure>().SingleOrDefault(); notificationSendFailure.Should().NotBeNull(); notificationSendFailure.AccountId.ShouldBeEquivalentTo(account.AccountId.ToString()); notificationSendFailure.Description.Should().NotBeNull(); notificationSendFailure.ErrorCode.ShouldBeEquivalentTo(expectedErrorCode); if (expectedErrorCode == NotificationErrorCode.RouteFailure) { notificationSendFailure.EndpointName.ShouldBeEquivalentTo(Constants.PushNotificationEndPoint); } else { notificationSendFailure.EndpointName.Should().BeNull(); } if (account.MobileDevices != null && account.MobileDevices.Any()) { notificationSendFailure.Destination.ShouldBeEquivalentTo(account.MobileDevices.Single().DeviceId); } else { notificationSendFailure.Destination.Should().BeNull(); } this.AssertNotification((PushNotification)notificationSendFailure.Notification, expectedNotification); }
private void AssertSentSuccessful(NotificationTest test, NotificationAccount <Guid> account, PushNotification expectedNotification) { PushNotification sentNotification = (PushNotification)test.GetSentNotification(); this.AssertNotification(sentNotification, expectedNotification); this.AssertNotificationSentEventRaised(test, account, expectedNotification); }
private void AssertNotificationScheduledSuccessful(NotificationTest test, NotificationAccount <Guid> account, Notification expectedNotification, DateTimeOffset expectedDeliveryDateTime) { ScheduledNotification <Guid> scheduledNotification = test.GetScheduledNotification(); scheduledNotification.AccountId.ShouldBeEquivalentTo(account.AccountId); scheduledNotification.DeliveryDateTime.ShouldBeEquivalentTo(expectedDeliveryDateTime); this.AssertNotificationScheduledEventRaised(test, account, expectedNotification, expectedDeliveryDateTime); }
private void AssertNotificationScheduledEventRaised(NotificationTest test, NotificationAccount <Guid> account, Notification expectedNotification, DateTimeOffset expectedDeliveryDateTime) { NotificationScheduled notificationScheduled = test.RaisedEvents.OfType <NotificationScheduled>().SingleOrDefault(); notificationScheduled.Should().NotBeNull(); notificationScheduled.AccountId.ShouldBeEquivalentTo(account.AccountId.ToString()); notificationScheduled.DeliveryDateTime.ShouldBeEquivalentTo(expectedDeliveryDateTime); notificationScheduled.Notification.Should().BeSameAs(expectedNotification); }
public void SendVersionedPushNotificationToDeviceWithoutWithInvalidVersionTest() { NotificationTest test = new NotificationTest(); PushNotificationChannel channel = new PushNotificationChannel(this.CreateMobileServiceClient(), test.EventPublisher); PushNotification notification = this.CreateNotification(new Version(1, 0, 0)); NotificationAccount <Guid> account = test.AddNotificationAccount(Guid.NewGuid(), mobileAppVersion: "Invalid"); channel.SendAsync(account, notification).Wait(); this.AssertSentFailed(test, account, notification, NotificationErrorCode.VersionMismatch); }
public void SendPushNotificationForAnOutdatedVersionOfTheApplicationTest() { NotificationTest test = new NotificationTest(); PushNotificationChannel channel = new PushNotificationChannel(this.CreateMobileServiceClient(), test.EventPublisher); PushNotification notification = this.CreateNotification(new Version(1, 0, 0), new Version(1, 0, 2)); NotificationAccount <Guid> account = test.AddNotificationAccount(Guid.NewGuid(), mobileAppVersion: "1.0.3"); channel.SendAsync(account, notification).Wait(); this.AssertSentFailed(test, account, notification, NotificationErrorCode.VersionMismatch); }
public void SendPushNotificationWithOnlyMinimumAppVersionSpecifiedTest() { NotificationTest test = new NotificationTest(); PushNotificationChannel channel = new PushNotificationChannel(this.CreateMobileServiceClient(), test.EventPublisher); PushNotification notification = this.CreateNotification(new Version(1, 0, 0)); NotificationAccount <Guid> account = test.AddNotificationAccount(Guid.NewGuid(), mobileAppVersion: "1.0.3"); channel.SendAsync(account, notification).Wait(); this.AssertSentSuccessful(test, account, notification); }
public void SendPushNotificationForAccountWithoutMobileDeviceTest() { NotificationTest test = new NotificationTest(); PushNotificationChannel channel = new PushNotificationChannel(this.CreateMobileServiceClient(), test.EventPublisher); PushNotification notification = this.CreateNotification(); NotificationAccount <Guid> account = test.AddNotificationAccount(Guid.NewGuid(), "*****@*****.**", "Joe", null, (MobileDevice)null); channel.SendAsync(account, notification).Wait(); this.AssertSentFailed(test, account, notification, NotificationErrorCode.MobileDeviceNotRegistered); }
private NotificationScheduler <Guid> CreateScheduler(NotificationTest test, out INotificationChannel channel) { channel = Substitute.For <INotificationChannel>(); NotificationChannelFactory factory = new NotificationChannelFactory(); factory.RegisterChannel <PushNotification>(channel); return (new NotificationScheduler <Guid>( new NotificationQueue(factory), new NotificationAccountManager <Guid>(test.NotificationAccountRepository), test.NotificationRepository, test.EventPublisher)); }
public void SendInvalidEndPointPushNotificationTest() { NotificationTest test = new NotificationTest(); IMobilePushNotificationServiceClient mobileServiceClient = this.CreateMobileServiceClient(); PushNotificationChannel channel = new PushNotificationChannel(mobileServiceClient, test.EventPublisher); PushNotification notification = this.CreateNotification(); NotificationAccount <Guid> account = test.AddNotificationAccount(); this.PushNotificationShouldFailAtEndPoint(mobileServiceClient); channel.SendAsync(account, notification).Wait(); this.AssertSentFailed(test, account, notification, NotificationErrorCode.RouteFailure); }
public void SchedulePushNotificationWithoutTimeZoneTest() { NotificationTest test = new NotificationTest(); NotificationScheduler <Guid> scheduler = this.CreateScheduler(test); PushNotification notification = this.CreateNotification(); NotificationAccount <Guid> account = test.AddNotificationAccount(Guid.NewGuid(), timeZone: null); DateTime deliveryDate = DateTime.UtcNow.AddDays(1); scheduler.Schedule(account.AccountId, notification, deliveryDate); DateTimeOffset expectedDeliveryDate = deliveryDate.ToDateTimeOffset("US/Eastern"); this.AssertNotificationScheduledSuccessful(test, account, notification, expectedDeliveryDate); }
public void SendOverDueNotificationTest() { NotificationTest test = new NotificationTest(); INotificationChannel channel; NotificationScheduler <Guid> scheduler = this.CreateScheduler(test, out channel); DateTime deliveryDate = DateTime.UtcNow; NotificationAccount <Guid> account = test.AddNotificationAccount(Guid.NewGuid(), "US/Pacific"); PushNotification notificationToSend = this.CreateNotification(); test.NotificationRepository.GetScheduledNotifications(Arg.Any <DateTime>()).Returns(new[] { new ScheduledNotification <Guid>(account.AccountId, notificationToSend, DateTime.UtcNow) }); scheduler.SendScheduledNotifications(DateTime.UtcNow.AddDays(1)).Wait(); channel.Received().SendAsync(account, notificationToSend); test.NotificationRepository.Received().DeleteScheduledNotification(notificationToSend.Id); }
private void AssertNotificationSentEventRaised(NotificationTest test, NotificationAccount <Guid> account, PushNotification expectedNotification) { NotificationSent notificationSent = test.RaisedEvents.OfType <NotificationSent>().SingleOrDefault(); notificationSent.Should().NotBeNull(); notificationSent.AccountId.ShouldBeEquivalentTo(account.AccountId.ToString()); notificationSent.Notification.NotificationType.ShouldBeEquivalentTo(NotificationType.Push); string expectedDeviceId = null; if (account.MobileDevices != null && account.MobileDevices.Any()) { MobileDevice device = account.MobileDevices.Single(); expectedDeviceId = device.DeviceId; } notificationSent.Destination.ShouldBeEquivalentTo(expectedDeviceId); notificationSent.EndpointName.ShouldBeEquivalentTo(Constants.PushNotificationEndPoint); this.AssertNotification((PushNotification)notificationSent.Notification, expectedNotification); }
private NotificationScheduler <Guid> CreateScheduler(NotificationTest test) { INotificationChannel channel; return(this.CreateScheduler(test, out channel)); }