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); }
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); }
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); }
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); }
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); }
private string json(PushNotificationsToken token) => $"{{\"fcm_registration_token\": \"{token}\"}}";
public Task Unsubscribe(PushNotificationsToken token) => SendRequest(endPoints.Unsubscribe, AuthHeader, json(token));
public void StoreRegisteredToken(PushNotificationsToken token, DateTimeOffset now) { keyValueStorage.SetString(previouslyRegisteredTokenKey, token.ToString()); keyValueStorage.SetDateTimeOffset(dateOfRegisteringPreviousTokenKey, now); }
public IObservable <Unit> Unsubscribe(PushNotificationsToken token) => SendRequest(endPoints.Unsubscribe, AuthHeader, json(token)).SelectUnit();