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 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 async Task ExposureDetectedAsync(ExposureDetectionSummary summary, Func <Task <IEnumerable <ExposureInfo> > > getExposureInfo) { await ExposureDetectedHelper.EvaluateRiskInSummaryAndCreateMessage(summary, this); await ServiceLocator.Current.GetInstance <IDeveloperToolsService>().SaveLastExposureInfos(getExposureInfo); ExposureDetectedHelper.SaveLastSummary(summary); }
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 RiskInDailySummaryAboveThreshold_ReturnsFalseWhenBelowConfiguredLimit(string locale) { Thread.CurrentThread.CurrentCulture = new CultureInfo(locale); LocalPreferencesHelper.ScoreSumThreshold = 780; DailySummaryReport dailySummaryReport = new DailySummaryReport(0, 779, 0); DailySummary dailySummary = new DailySummary(SystemTime.Now(), dailySummaryReport, new Dictionary <ReportType, DailySummaryReport>()); bool isAboveThreshold = ExposureDetectedHelper.RiskInDailySummaryAboveThreshold(dailySummary); Assert.False(isAboveThreshold); }
public void IsAttenuationDurationOverThreshold_IgnoresAnyValueInTheHighBucket() { //Given the summary returned by EN API has 10 min in low attenuation bucket and a a lot of minutes in high attenuation bucket TimeSpan lowAttenuationDuration = TimeSpan.FromMinutes(10); TimeSpan mediumAttenuationDuration = TimeSpan.FromMinutes(0); TimeSpan highAttenuationDuration = TimeSpan.FromMinutes(9999999); ExposureDetectionSummary summary = new ExposureDetectionSummary( 3, 100, 2, new TimeSpan[] { lowAttenuationDuration, mediumAttenuationDuration, highAttenuationDuration }, 512); //When the IsAttenuationDurationOverThreshold is called bool isOverThreshold = ExposureDetectedHelper.IsAttenuationDurationOverThreshold(summary); //We will get false from the call so the message won't be shown Assert.False(isOverThreshold); }
public void IsAttenuationDurationOverThreshold_returnsTrueWhenSummaryHas10MinInLowBucketAnd10MinInMiddleBucket() { //Given the summary returned by EN API has 10 min in low attenuation bucket and 10 min in mid attenuation bucket TimeSpan lowAttenuationDuration = TimeSpan.FromMinutes(10); TimeSpan mediumAttenuationDuration = TimeSpan.FromMinutes(10); TimeSpan highAttenuationDuration = TimeSpan.FromMinutes(0); ExposureDetectionSummary summary = new ExposureDetectionSummary( 3, 100, 2, new TimeSpan[] { lowAttenuationDuration, mediumAttenuationDuration, highAttenuationDuration }, 512); //When the IsAttenuationDurationOverThreshold is called bool isOverThreshold = ExposureDetectedHelper.IsAttenuationDurationOverThreshold(summary); //We will get true from the call so the message will be shown Assert.True(isOverThreshold); }
public void IsAttenuationDurationOverThreshold_returnsFalseWhenSummaryBucketsAreBelowThresholds() { //Given the summary returned by EN API has 10 min in mid attenuation bucket and 100 min in high attenuation bucket TimeSpan lowAttenuationDuration = TimeSpan.FromMinutes(0); TimeSpan mediumAttenuationDuration = TimeSpan.FromMinutes(10); TimeSpan highAttenuationDuration = TimeSpan.FromMinutes(100); ExposureDetectionSummary summary = new ExposureDetectionSummary( 3, 100, 2, new TimeSpan[] { lowAttenuationDuration, mediumAttenuationDuration, highAttenuationDuration }, 512); //When the IsAttenuationDurationOverThreshold is called bool isOverThreshold = ExposureDetectedHelper.IsAttenuationDurationOverThreshold(summary); //We will get false from the call so the message will not be shown Assert.False(isOverThreshold); }
public void IsAttenuationDurationOverThreshold_returnsTrueWhenSummaryHas30MinOnlyInMiddleBucket(string locale) { Thread.CurrentThread.CurrentCulture = new CultureInfo(locale); //Given the summary returned by EN API has 30 min in mid attenuation bucket TimeSpan lowAttenuationDuration = TimeSpan.FromMinutes(0); TimeSpan mediumAttenuationDuration = TimeSpan.FromMinutes(30); TimeSpan highAttenuationDuration = TimeSpan.FromMinutes(0); ExposureDetectionSummary summary = new ExposureDetectionSummary( 3, 100, 2, new[] { lowAttenuationDuration, mediumAttenuationDuration, highAttenuationDuration }, 512); //When the IsAttenuationDurationOverThreshold is called bool isOverThreshold = ExposureDetectedHelper.IsAttenuationDurationOverThreshold(summary); //We will get true from the call so the message will be shown Assert.True(isOverThreshold); }
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); }
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); }
public void HasNotShownExposureNotificationForDate_ReturnsTrueIfTimeStampHasNotYetBeenSaved(string locale) { Thread.CurrentThread.CurrentCulture = new CultureInfo(locale); SystemTime.ResetDateTime(); List <DateTime> previouslySavedDates = new List <DateTime>(); previouslySavedDates.Add(SystemTime.Now().AddDays(0).Date); previouslySavedDates.Add(SystemTime.Now().AddDays(-1).Date); previouslySavedDates.Add(SystemTime.Now().AddDays(-2).Date); bool savedBefore = ExposureDetectedHelper.HasNotShownExposureNotificationForDate(SystemTime.Now().AddDays(-1), previouslySavedDates); bool neverSaved = ExposureDetectedHelper.HasNotShownExposureNotificationForDate(SystemTime.Now().AddDays(-3), previouslySavedDates); Assert.False(savedBefore); Assert.True(neverSaved); }