public async void ExposureStateUpdatedAsync_DeletesOldDatesAndAddsNewDates(string locale) { Thread.CurrentThread.CurrentCulture = new CultureInfo(locale); SystemTime.ResetDateTime(); SecureStorageService.Delete(SecureStorageKeys.DAILY_SUMMARIES_OVER_THRESHOLD_TIMESTAMP_KEY); List <DateTime> previouslySavedDates = new List <DateTime>(); previouslySavedDates.Add(SystemTime.Now().AddDays(-20).Date); previouslySavedDates.Add(SystemTime.Now().AddDays(-18).Date); previouslySavedDates.Add(SystemTime.Now().AddDays(-8).Date); SecureStorageService.SaveValue( SecureStorageKeys.DAILY_SUMMARIES_OVER_THRESHOLD_TIMESTAMP_KEY, JsonConvert.SerializeObject(previouslySavedDates)); List <DateTime> datesToSave = createListOfDateTimesUpToXDaysInThePast(2); Assert.Single(ExposureDetectedHelper.DeleteDatesOfExposureOlderThan14DaysAndReturnNewList()); await ExposureDetectedHelper.UpdateDatesOfExposures(datesToSave); List <DateTime> savedDates = JsonConvert.DeserializeObject <List <DateTime> >( SecureStorageService.GetValue(SecureStorageKeys.DAILY_SUMMARIES_OVER_THRESHOLD_TIMESTAMP_KEY)); Assert.Equal(datesToSave.Count + 1, savedDates.Count); }
public async void UpdateDatesOfExposures_AddsAllNewDatesToTheOld_WhenSomeDatesAreSavedInSecureStorage( string locale) { Thread.CurrentThread.CurrentCulture = new CultureInfo(locale); SystemTime.ResetDateTime(); SecureStorageService.Delete(SecureStorageKeys.DAILY_SUMMARIES_OVER_THRESHOLD_TIMESTAMP_KEY); List <DateTime> previouslySavedDates = new List <DateTime>(); previouslySavedDates.Add(SystemTime.Now().AddDays(-10).Date); previouslySavedDates.Add(SystemTime.Now().AddDays(-8).Date); SecureStorageService.SaveValue( SecureStorageKeys.DAILY_SUMMARIES_OVER_THRESHOLD_TIMESTAMP_KEY, JsonConvert.SerializeObject(previouslySavedDates)); List <DateTime> datesToSave = createListOfDateTimesUpToXDaysInThePast(2); await ExposureDetectedHelper.UpdateDatesOfExposures(datesToSave); List <DateTime> savedDates = JsonConvert.DeserializeObject <List <DateTime> >( SecureStorageService.GetValue(SecureStorageKeys.DAILY_SUMMARIES_OVER_THRESHOLD_TIMESTAMP_KEY)); Assert.Equal(datesToSave.Count + previouslySavedDates.Count, savedDates.Count); datesToSave.Concat(previouslySavedDates).Should().BeEquivalentTo(savedDates); }
public async Task ExposureStateUpdatedAsync(IEnumerable <ExposureWindow> windows, IEnumerable <DailySummary>?summaries) { Debug.WriteLine("ExposureStateUpdatedAsync is called"); List <DateTime> validDates = ExposureDetectedHelper.DeleteDatesOfExposureOlderThan14DaysAndReturnNewList(); bool shouldSendMessage = false; List <DateTime> datesOfExposuresOverThreshold = new List <DateTime>(); foreach (DailySummary dailySummary in summaries) { if (ExposureDetectedHelper.RiskInDailySummaryAboveThreshold(dailySummary) && ExposureDetectedHelper.HasNotShownExposureNotificationForDate(dailySummary.Timestamp.Date, validDates)) { datesOfExposuresOverThreshold.Add(dailySummary.Timestamp.Date); shouldSendMessage = true; } } if (shouldSendMessage) { await MessageUtils.CreateMessage(this); await ExposureDetectedHelper.UpdateDatesOfExposures(datesOfExposuresOverThreshold); } ServiceLocator.Current.GetInstance <IDeveloperToolsService>().SaveExposureWindows(windows); ServiceLocator.Current.GetInstance <IDeveloperToolsService>().SaveLastDailySummaries(summaries); }
public async void UpdateDatesOfExposures_AddsAllNewDates_WhenNothingIsSavedYet(string locale) { Thread.CurrentThread.CurrentCulture = new CultureInfo(locale); SystemTime.ResetDateTime(); SecureStorageService.Delete(SecureStorageKeys.DAILY_SUMMARIES_OVER_THRESHOLD_TIMESTAMP_KEY); List <DateTime> datesToSave = createListOfDateTimesUpToXDaysInThePast(2); await ExposureDetectedHelper.UpdateDatesOfExposures(datesToSave); List <DateTime> savedDates = JsonConvert.DeserializeObject <List <DateTime> >( SecureStorageService.GetValue(SecureStorageKeys.DAILY_SUMMARIES_OVER_THRESHOLD_TIMESTAMP_KEY)); datesToSave.Should().BeEquivalentTo(savedDates); Assert.Equal(datesToSave.Count, savedDates.Count); }