public async Task SHOULD_trace_extracted_notification()
        {
            //Arrange
            _target = DeviceTarget.iOS("pnsHandle");

            //Act
            await Sut.SendNotificationToTargetAsync(_pushNotification, _target, MockNotificationHub.Object);

            //Assert
            MockAnalyticsService.VerifyTrace("Native push notification extracted");
            MockAnalyticsService.VerifyTraceProperty(_iosNotification.GetType().Name, _iosNotification);
        }
        public async Task SHOULD_extract_notification_for_target_platform_and_send_to_target_pnsHandle()
        {
            //Arrange
            _target = DeviceTarget.iOS("pnsHandle");

            //Act
            await Sut.SendNotificationToTargetAsync(_pushNotification, _target, MockNotificationHub.Object);

            //Assert
            MockNativeNotificationExtractor.Mock.Verify(x => x.ExtractNotification(RuntimePlatform.iOS, _pushNotification));
            MockNotificationHubClientProxy.Mock.Verify(x => x.SendDirectNotificationAsync(_iosNotification, It.Is <List <string> >(y =>
                                                                                                                                   y[0] == "pnsHandle")));
        }
        public override void SetUp()
        {
            base.SetUp();
            _iosNotification = new AppleNotification("{}");
            MockNativeNotificationExtractor.Where_ExtractNotification_returns(new NativeNotification(_iosNotification));

            _pushNotification = new PushNotificationMockBuilder()
                                .With(x => x.Name, "TestNotificationType")
                                .With(x => x.Title, "News Alert")
                                .With(x => x.Body, "The lockdown is only in your mind")
                                .With(x => x.DataProperties, new Dictionary <string, object>
            {
                { "FavouriteColour", "Red" },
                { "FavouriteBand", "The Beatles" },
                { "Id", _id },
            }).Object;

            _target = DeviceTarget.Android("pnsHandle");
        }
Beispiel #4
0
        private static IPushNotificationsServerService Setup(BasePushRunnerHub hub)
        {
            var services = new ServiceCollection();

            services.AddSingleton <IBuildConfig>(BuildConfig.Debug);

            services.AddPushNotificationsServer();
            services.RegisterConsoleLoggerService(new ConsoleTraceListener());
            NotificationHubPath = hub.NotificationHubName;
            DeviceId            = hub.DeviceId;
            PnsHandle           = hub.PnsHandle;
            ConnectionString    = hub.NotificationHubConnectionString;
            Platform            = hub.Platform;
            UserId = hub.UserId;
            Target = hub.DeviceTarget;
            Hub    = hub;

            Client = new NotificationHubClientProxy(BuildConfig.Debug);
            Client.Initialize(Hub);

            return(services.BuildServiceProvider().GetRequiredService <IPushNotificationsServerService>());
        }
        public async Task <Response> SendNotificationToTargetAsync(IPushNotification pushNotification, IDeviceTarget deviceTarget, IPushNotificationsHub hub)
        {
            _analyticsService.TraceVerbose(this, "Send push notification to device", new Dictionary <string, object>
            {
                { nameof(PushNotification), pushNotification }, { nameof(DeviceTarget), deviceTarget }
            });

            try
            {
                _hubClientProxy.Initialize(hub);

                var nativeNotificationResult = _nativeNotificationExtractor.ExtractNotification(deviceTarget.Platform, pushNotification);
                if (nativeNotificationResult.IsFailure)
                {
                    return(Response.Failure(nativeNotificationResult.Error));
                }

                var notification = nativeNotificationResult.Value.Notification;
                var devices      = new List <string> {
                    deviceTarget.PushNotificationServicesHandle
                };
                _analyticsService.Trace(this, "Native push notification extracted", LogSeverity.Verbose, notification.ToObjectDictionary());

                await _hubClientProxy.SendDirectNotificationAsync(notification, devices);

                return(Response.Success());
            }
            catch (Exception e)
            {
                return(_analyticsService.LogExceptionResponse(this, e, PushErrors.FailedToSendNotification));
            }
        }