public void ShouldBeTrueWhenRemoteConfigHasNeverBeenFetched() { DateTimeOffset?nullDateTimeOffset = null; KeyValueStorage.GetDateTimeOffset(LastFetchAtKey).Returns(nullDateTimeOffset); UpdateRemoteConfigCacheService = new UpdateRemoteConfigCacheService(TimeService, KeyValueStorage, FetchRemoteConfigService); var needsToUpdateStoredRemoteConfigData = UpdateRemoteConfigCacheService.NeedsToUpdateStoredRemoteConfigData(); Assert.IsTrue(needsToUpdateStoredRemoteConfigData); }
public void ShouldEmitWhenSubscribedTo() { var testScheduler = new TestScheduler(); var observer = testScheduler.CreateObserver <Unit>(); UpdateRemoteConfigCacheService = new UpdateRemoteConfigCacheService(TimeService, KeyValueStorage, FetchRemoteConfigService); UpdateRemoteConfigCacheService.RemoteConfigChanged .Subscribe(observer); testScheduler.Start(); observer.Messages.Should().HaveCount(1); }
public void ShouldNotUpdateTheCacheWhenFetchingFails() { var mockFetchRemoteConfigService = new MockFetchRemoteConfigService(false, true); UpdateRemoteConfigCacheService = new UpdateRemoteConfigCacheService(TimeService, KeyValueStorage, mockFetchRemoteConfigService); UpdateRemoteConfigCacheService.FetchAndStoreRemoteConfigData(); KeyValueStorage.DidNotReceive().SetInt(RatingViewDelayParameter, Arg.Any <int>()); KeyValueStorage.DidNotReceive().SetString(RatingViewTriggerParameter, Arg.Any <string>()); KeyValueStorage.DidNotReceive().SetBool(RegisterPushNotificationsTokenWithServerParameter, Arg.Any <bool>()); KeyValueStorage.DidNotReceive().SetBool(HandlePushNotificationsParameter, Arg.Any <bool>()); }
public void ShouldBeFalseWhenRemoteConfigHasBeenFetchedLessThan12HoursAndHalfAgo() { var now = new DateTimeOffset(2019, 1, 1, 12, 0, 0, TimeSpan.Zero); TimeService.CurrentDateTime.Returns(now); var thirteenHoursAgo = now.AddHours(-11); KeyValueStorage.GetDateTimeOffset(LastFetchAtKey).Returns(thirteenHoursAgo); UpdateRemoteConfigCacheService = new UpdateRemoteConfigCacheService(TimeService, KeyValueStorage, FetchRemoteConfigService); var needsToUpdateStoredRemoteConfigData = UpdateRemoteConfigCacheService.NeedsToUpdateStoredRemoteConfigData(); Assert.IsFalse(needsToUpdateStoredRemoteConfigData); }
public void ShouldEmitWhenFetchAndStoreRemoteConfigDataSucceeds() { var testScheduler = new TestScheduler(); var observer = testScheduler.CreateObserver <Unit>(); var mockFetchRemoteConfigService = new MockFetchRemoteConfigService(shouldSucceed: true); UpdateRemoteConfigCacheService = new UpdateRemoteConfigCacheService(TimeService, KeyValueStorage, mockFetchRemoteConfigService); UpdateRemoteConfigCacheService.RemoteConfigChanged.Subscribe(observer); UpdateRemoteConfigCacheService.FetchAndStoreRemoteConfigData(); testScheduler.Start(); observer.Messages.Should().HaveCount(2); }
public void ShouldUpdateTheCacheWhenFetchingSucceeds(int ratingViewDayCount, RatingViewCriterion ratingViewCriterion, bool registerPushes, bool handlePushes) { var expectedRatingViewConfiguration = new RatingViewConfiguration(ratingViewDayCount, ratingViewCriterion); var expectedPushNotificationsConfiguration = new PushNotificationsConfiguration(registerPushes, handlePushes); var mockFetchRemoteConfigService = new MockFetchRemoteConfigService( true, ratingViewConfigurationToReturn: expectedRatingViewConfiguration, pushNotificationsConfigurationReturn: expectedPushNotificationsConfiguration); UpdateRemoteConfigCacheService = new UpdateRemoteConfigCacheService(TimeService, KeyValueStorage, mockFetchRemoteConfigService); UpdateRemoteConfigCacheService.FetchAndStoreRemoteConfigData(); KeyValueStorage.Received().SetInt(RatingViewDelayParameter, ratingViewDayCount); KeyValueStorage.Received().SetString(RatingViewTriggerParameter, ratingViewCriterion.ToString()); KeyValueStorage.Received().SetBool(RegisterPushNotificationsTokenWithServerParameter, registerPushes); KeyValueStorage.Received().SetBool(HandlePushNotificationsParameter, handlePushes); }