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 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 void DeleteDatesOfExposureOlderThan14DaysAndReturnNewList_ReturnsEmptyListWhenNothingIsSavedYet( string locale) { Thread.CurrentThread.CurrentCulture = new CultureInfo(locale); SystemTime.ResetDateTime(); SecureStorageService.Delete(SecureStorageKeys.DAILY_SUMMARIES_OVER_THRESHOLD_TIMESTAMP_KEY); List <DateTime> validDates = ExposureDetectedHelper.DeleteDatesOfExposureOlderThan14DaysAndReturnNewList(); Assert.Empty(validDates); }
public void DeleteDatesOfExposureOlderThan14DaysAndReturnNewList_DeletesNoDaysOlderThan14DaysOld(string locale) { Thread.CurrentThread.CurrentCulture = new CultureInfo(locale); SystemTime.ResetDateTime(); SecureStorageService.Delete(SecureStorageKeys.DAILY_SUMMARIES_OVER_THRESHOLD_TIMESTAMP_KEY); List <DateTime> previouslySavedDates = createListOfDateTimesUpToXDaysInThePast(14); SecureStorageService.SaveValue( SecureStorageKeys.DAILY_SUMMARIES_OVER_THRESHOLD_TIMESTAMP_KEY, JsonConvert.SerializeObject(previouslySavedDates)); List <DateTime> validDates = ExposureDetectedHelper.DeleteDatesOfExposureOlderThan14DaysAndReturnNewList(); Assert.Equal(14, validDates.Count); }