コード例 #1
0
        private bool currentTokenWasAlreadySubmittedToTheServer(PushNotificationsToken currentToken)
        {
            var previouslyRegisteredToken = pushNotificationsTokenStorage.PreviouslyRegisteredToken?.ToString();

            return(!string.IsNullOrEmpty(previouslyRegisteredToken) &&
                   previouslyRegisteredToken == currentToken.ToString());
        }
        public async Task UnsubscribesFromNotifications()
        {
            var token = new PushNotificationsToken("token");

            PushNotificationsTokenService.Token.Returns(token);
            pushNotificationsTokenStorage.PreviouslyRegisteredToken.Returns(new PushNotificationsToken("token"));

            await interactor.Execute();

            Api.PushServices.Received().Unsubscribe(token);
        }
コード例 #3
0
            public async Task CallsTheApiToSubscribeForPushNotificationsWhenNoOtherTokenHasBeenStored()
            {
                pushNotificationsTokenStorage.PreviouslyRegisteredToken.Returns(default(PushNotificationsToken));
                var expectedPushNotificationToken = new PushNotificationsToken("tokenA");

                PushNotificationsTokenService.Token.Returns(expectedPushNotificationToken);
                pushServicesApi.Subscribe(Arg.Any <PushNotificationsToken>()).Returns(Observable.Return(Unit.Default));

                (await interactor.Execute().SingleAsync()).Should().Be(Unit.Default);
                pushServicesApi.Received().Subscribe(expectedPushNotificationToken);
            }
コード例 #4
0
            public async Task StoresTheTokenWhenSucceedsToRegisterIt()
            {
                pushNotificationsTokenStorage.PreviouslyRegisteredToken.Returns(default(PushNotificationsToken));
                var expectedPushNotificationToken = new PushNotificationsToken("tokenA");

                PushNotificationsTokenService.Token.Returns(expectedPushNotificationToken);
                pushServicesApi.Subscribe(Arg.Any <PushNotificationsToken>()).Returns(Observable.Return(Unit.Default));

                (await interactor.Execute().SingleAsync()).Should().Be(Unit.Default);
                pushNotificationsTokenStorage.Received().StoreRegisteredToken(expectedPushNotificationToken, now);
            }
コード例 #5
0
            public async Task CallsTheApiToSubscribeForPushNotificationsAfterATimePeriod()
            {
                var token = new PushNotificationsToken("tokenA");

                pushNotificationsTokenStorage.PreviouslyRegisteredToken.Returns(token);
                pushNotificationsTokenStorage.DateOfRegisteringTheToken.Returns(now - TimeSpan.FromDays(10));
                PushNotificationsTokenService.Token.Returns(token);
                pushServicesApi.Subscribe(Arg.Any <PushNotificationsToken>()).Returns(Observable.Return(Unit.Default));

                (await interactor.Execute().SingleAsync()).Should().Be(Unit.Default);
                pushServicesApi.Received().Subscribe(token);
            }
コード例 #6
0
            public async Task DoesNotStoreTheTokenWhenItFailsToRegisterIt()
            {
                pushNotificationsTokenStorage.PreviouslyRegisteredToken.Returns(default(PushNotificationsToken));
                var expectedPushNotificationToken = new PushNotificationsToken("tokenA");

                PushNotificationsTokenService.Token.Returns(expectedPushNotificationToken);
                pushServicesApi.Subscribe(Arg.Any <PushNotificationsToken>()).Returns(Observable.Throw <Unit>(new Exception()));

                (await interactor.Execute().SingleAsync()).Should().Be(Unit.Default);
                pushServicesApi.Received().Subscribe(expectedPushNotificationToken);
                pushNotificationsTokenStorage.DidNotReceive().StoreRegisteredToken(expectedPushNotificationToken, Arg.Any <DateTimeOffset>());
            }
        public async Task IgnoresServerErrors()
        {
            var token = new PushNotificationsToken("token");

            PushNotificationsTokenService.Token.Returns(token);
            Api.PushServices.Unsubscribe(token).ReturnsThrowingTask(new Exception("Whatever"));

            var testScheduler = new TestScheduler();
            var observer      = testScheduler.CreateObserver <Unit>();

            interactor.Execute().Subscribe(observer);
            testScheduler.Start();

            observer.SingleEmittedValue().Should().Be(Unit.Default);
        }
コード例 #8
0
ファイル: PushServicesApi.cs プロジェクト: xleon/mobileapp
 private string json(PushNotificationsToken token)
 => $"{{\"fcm_registration_token\": \"{token}\"}}";
コード例 #9
0
ファイル: PushServicesApi.cs プロジェクト: xleon/mobileapp
 public Task Unsubscribe(PushNotificationsToken token)
 => SendRequest(endPoints.Unsubscribe, AuthHeader, json(token));
コード例 #10
0
 public void StoreRegisteredToken(PushNotificationsToken token, DateTimeOffset now)
 {
     keyValueStorage.SetString(previouslyRegisteredTokenKey, token.ToString());
     keyValueStorage.SetDateTimeOffset(dateOfRegisteringPreviousTokenKey, now);
 }
コード例 #11
0
 public IObservable <Unit> Unsubscribe(PushNotificationsToken token)
 => SendRequest(endPoints.Unsubscribe, AuthHeader, json(token)).SelectUnit();