diff --git a/Covid19Radar/Covid19Radar/ViewModels/HomePage/ContactedNotifyPageViewModel.cs b/Covid19Radar/Covid19Radar/ViewModels/HomePage/ContactedNotifyPageViewModel.cs index 30d4753f8..e3a782982 100644 --- a/Covid19Radar/Covid19Radar/ViewModels/HomePage/ContactedNotifyPageViewModel.cs +++ b/Covid19Radar/Covid19Radar/ViewModels/HomePage/ContactedNotifyPageViewModel.cs @@ -24,6 +24,7 @@ public class ContactedNotifyPageViewModel : ViewModelBase private readonly ILoggerService loggerService; private readonly IExposureDataRepository _exposureDataRepository; private readonly IExposureRiskCalculationService _exposureRiskCalculationService; + private readonly IExposureRiskCalculationConfigurationRepository _exposureRiskCalculationConfigurationRepository; private V1ExposureRiskCalculationConfiguration _exposureRiskCalculationConfiguration; @@ -45,12 +46,14 @@ public ContactedNotifyPageViewModel( INavigationService navigationService, ILoggerService loggerService, IExposureDataRepository exposureDataRepository, - IExposureRiskCalculationService exposureRiskCalculationService + IExposureRiskCalculationService exposureRiskCalculationService, + IExposureRiskCalculationConfigurationRepository exposureRiskCalculationConfigurationRepository ) : base(navigationService) { this.loggerService = loggerService; _exposureDataRepository = exposureDataRepository; _exposureRiskCalculationService = exposureRiskCalculationService; + _exposureRiskCalculationConfigurationRepository = exposureRiskCalculationConfigurationRepository; Title = AppResources.TitileUserStatusSettings; } @@ -65,6 +68,12 @@ public override async void Initialize(INavigationParameters parameters) _exposureRiskCalculationConfiguration = parameters.GetValue(ContactedNotifyPage.ExposureRiskCalculationConfigurationKey); + if (_exposureRiskCalculationConfiguration is null) + { + // When transitioned from a exposure notification, it is not passed as a parameter, so it is retrieved. + _exposureRiskCalculationConfiguration = + await _exposureRiskCalculationConfigurationRepository.GetExposureRiskCalculationConfigurationAsync(preferCache: true); + } var userExposureInformationList = _exposureDataRepository.GetExposureInformationList(AppConstants.TermOfExposureRecordValidityInDays); diff --git a/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HomePage/ContactedNotifyPageViewModelTests.cs b/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HomePage/ContactedNotifyPageViewModelTests.cs index 8456ec748..af6b00a63 100644 --- a/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HomePage/ContactedNotifyPageViewModelTests.cs +++ b/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HomePage/ContactedNotifyPageViewModelTests.cs @@ -29,6 +29,7 @@ public class ContactedNotifyPageViewModelTests : IDisposable private readonly Mock mockLoggerService; private readonly Mock mockExposureRiskCalculationService; private readonly Mock mockExposureDataRepository; + private readonly Mock mockExposureRiskCalculationConfigurationRepository; private readonly CultureInfo originalAppResourceCalture; private readonly CultureInfo originalThreadCalture; private readonly CultureInfo originalThreadUICalture; @@ -47,6 +48,7 @@ public ContactedNotifyPageViewModelTests() mockLoggerService = mockRepository.Create(); mockExposureRiskCalculationService = mockRepository.Create(); mockExposureDataRepository = mockRepository.Create(); + mockExposureRiskCalculationConfigurationRepository = mockRepository.Create(); } public void Dispose() @@ -63,7 +65,8 @@ private ContactedNotifyPageViewModel CreateViewModel() mockNavigationService.Object, mockLoggerService.Object, mockExposureDataRepository.Object, - mockExposureRiskCalculationService.Object + mockExposureRiskCalculationService.Object, + mockExposureRiskCalculationConfigurationRepository.Object ); } @@ -195,6 +198,51 @@ public void OnClickExposuresTest_Initialize_NoExposureInformation_NoHighRisk() Assert.Equal("2 件", contactedNotifyViewModel.ExposureCount); } + [Fact] + public void OnClickExposuresTest_Initialize_NavigationParameter_NotSet() + { + mockExposureDataRepository + .Setup(x => x.GetExposureInformationList(AppConstants.TermOfExposureRecordValidityInDays)) + .Returns(new List() + { + new UserExposureInfo(), + new UserExposureInfo() + }); + mockExposureDataRepository + .Setup(x => x.GetDailySummariesAsync(AppConstants.TermOfExposureRecordValidityInDays)) + .Returns(Task.FromResult(new List() + { + new DailySummary() + { + DateMillisSinceEpoch = 1000L * 60 * 60 * 24 * 365 + } + })); + mockExposureDataRepository + .Setup(x => x.GetExposureWindowsAsync(AppConstants.TermOfExposureRecordValidityInDays)) + .Returns(Task.FromResult(new List() + { + new ExposureWindow() + { + DateMillisSinceEpoch = 1000L * 60 * 60 * 24 * 365, + ScanInstances = new List() { + new ScanInstance() + { + SecondsSinceLastScan = 60 + } + } + } + })); + + mockExposureRiskCalculationConfigurationRepository + .Setup(x => x.GetExposureRiskCalculationConfigurationAsync(true)) + .ReturnsAsync(new V1ExposureRiskCalculationConfiguration()); + + var contactedNotifyViewModel = CreateViewModel(); + contactedNotifyViewModel.Initialize(new NavigationParameters()); + + mockExposureRiskCalculationConfigurationRepository.Verify(x => x.GetExposureRiskCalculationConfigurationAsync(true), Times.Once()); + } + [Fact] public async Task OnExposureListTest() {