diff --git a/Covid19Radar/Covid19Radar.Android/MainApplication.cs b/Covid19Radar/Covid19Radar.Android/MainApplication.cs index 678188d62..8bdd98e10 100644 --- a/Covid19Radar/Covid19Radar.Android/MainApplication.cs +++ b/Covid19Radar/Covid19Radar.Android/MainApplication.cs @@ -58,6 +58,9 @@ private Lazy _loggerService private Lazy _exposureConfigurationRepository = new Lazy(() => ContainerLocator.Current.Resolve()); + private Lazy _userDataRepository + = new Lazy(() => ContainerLocator.Current.Resolve()); + public MainApplication(IntPtr handle, JniHandleOwnership transfer) : base(handle, transfer) { } @@ -93,22 +96,25 @@ public override void OnCreate() private void ScheduleBackgroundTasks() { - try - { - _exposureDetectionBackgroundService.Value.Schedule(); - } - catch (Exception exception) - { - _loggerService.Value.Exception("Failed to schedule ExposureDetectionBackgroundService", exception); - } - - try - { - _dataMaintainanceService.Value.Schedule(); - } - catch (Exception exception) + if (_userDataRepository.Value.IsAllAgreed()) { - _loggerService.Value.Exception("Failed to schedule DataMaintainanceBackgroundService", exception); + try + { + _exposureDetectionBackgroundService.Value.Schedule(); + } + catch (Exception exception) + { + _loggerService.Value.Exception("Failed to schedule ExposureDetectionBackgroundService", exception); + } + + try + { + _dataMaintainanceService.Value.Schedule(); + } + catch (Exception exception) + { + _loggerService.Value.Exception("Failed to schedule DataMaintainanceBackgroundService", exception); + } } } diff --git a/Covid19Radar/Covid19Radar.Android/Services/DataMaintainanceBackgroundService.cs b/Covid19Radar/Covid19Radar.Android/Services/DataMaintainanceBackgroundService.cs index a6220ef6b..42a8d625d 100644 --- a/Covid19Radar/Covid19Radar.Android/Services/DataMaintainanceBackgroundService.cs +++ b/Covid19Radar/Covid19Radar.Android/Services/DataMaintainanceBackgroundService.cs @@ -59,6 +59,12 @@ private PeriodicWorkRequest CreatePeriodicWorkRequest() return workRequestBuilder.Build(); } + public override void Cancel() + { + WorkManager workManager = WorkManager.GetInstance(Platform.AppContext); + workManager.CancelUniqueWork(CURRENT_WORK_NAME); + } + [Preserve] public class BackgroundWorker : Worker { diff --git a/Covid19Radar/Covid19Radar.Android/Services/EventLogSubmissionBackgroundService.cs b/Covid19Radar/Covid19Radar.Android/Services/EventLogSubmissionBackgroundService.cs index 26a25c629..0901166b4 100644 --- a/Covid19Radar/Covid19Radar.Android/Services/EventLogSubmissionBackgroundService.cs +++ b/Covid19Radar/Covid19Radar.Android/Services/EventLogSubmissionBackgroundService.cs @@ -63,6 +63,12 @@ private PeriodicWorkRequest CreatePeriodicWorkRequest() return workRequestBuilder.Build(); } + public override void Cancel() + { + WorkManager workManager = WorkManager.GetInstance(Platform.AppContext); + workManager.CancelUniqueWork(CURRENT_WORK_NAME); + } + [Preserve] public class BackgroundWorker : Worker { diff --git a/Covid19Radar/Covid19Radar.Android/Services/ExposureDetectionBackgroundService.cs b/Covid19Radar/Covid19Radar.Android/Services/ExposureDetectionBackgroundService.cs index 18c21d9be..19f652cfd 100644 --- a/Covid19Radar/Covid19Radar.Android/Services/ExposureDetectionBackgroundService.cs +++ b/Covid19Radar/Covid19Radar.Android/Services/ExposureDetectionBackgroundService.cs @@ -82,6 +82,12 @@ private static PeriodicWorkRequest CreatePeriodicWorkRequest() .SetBackoffCriteria(BackoffPolicy.Linear, BACKOFF_DELAY_IN_MINUTES, TimeUnit.Minutes); return workRequestBuilder.Build(); } + + public override void Cancel() + { + WorkManager workManager = WorkManager.GetInstance(Platform.AppContext); + workManager.CancelUniqueWork(CURRENT_WORK_NAME); + } } [Preserve] diff --git a/Covid19Radar/Covid19Radar.Android/Services/Migration/MigrationProcessService.cs b/Covid19Radar/Covid19Radar.Android/Services/Migration/MigrationProcessService.cs index 909259eb8..03c11be57 100644 --- a/Covid19Radar/Covid19Radar.Android/Services/Migration/MigrationProcessService.cs +++ b/Covid19Radar/Covid19Radar.Android/Services/Migration/MigrationProcessService.cs @@ -6,6 +6,7 @@ using Android.App; using Android.Content; using AndroidX.Work; +using Covid19Radar.Repository; using Covid19Radar.Services; using Covid19Radar.Services.Logs; using Covid19Radar.Services.Migration; @@ -75,18 +76,21 @@ public class MigrationProccessService : IMigrationProcessService private readonly AbsEventLogSubmissionBackgroundService _eventLogSubmissionBackgroundService; private readonly ILoggerService _loggerService; + private readonly IUserDataRepository _userDataRepository; public MigrationProccessService( AbsExposureDetectionBackgroundService exposureDetectionBackgroundService, AbsDataMaintainanceBackgroundService dataMaintainanceBackgroundService, AbsEventLogSubmissionBackgroundService eventLogSubmissionBackgroundService, - ILoggerService loggerService + ILoggerService loggerService, + IUserDataRepository userDataRepository ) { _exposureDetectionBackgroundService = exposureDetectionBackgroundService; _dataMaintainanceBackgroundService = dataMaintainanceBackgroundService; _eventLogSubmissionBackgroundService = eventLogSubmissionBackgroundService; _loggerService = loggerService; + _userDataRepository = userDataRepository; } public async Task SetupAsync() @@ -97,7 +101,8 @@ public async Task SetupAsync() _exposureDetectionBackgroundService, _dataMaintainanceBackgroundService, _eventLogSubmissionBackgroundService, - _loggerService + _loggerService, + _userDataRepository ).ExecuteAsync(); _loggerService.EndMethod(); diff --git a/Covid19Radar/Covid19Radar.Android/Services/Migration/WorkManagerMigrator.cs b/Covid19Radar/Covid19Radar.Android/Services/Migration/WorkManagerMigrator.cs index d9b5d2864..1f05f190f 100644 --- a/Covid19Radar/Covid19Radar.Android/Services/Migration/WorkManagerMigrator.cs +++ b/Covid19Radar/Covid19Radar.Android/Services/Migration/WorkManagerMigrator.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using AndroidX.Work; +using Covid19Radar.Repository; using Covid19Radar.Services; using Covid19Radar.Services.Logs; @@ -23,18 +24,21 @@ internal class WorkManagerMigrator private readonly AbsEventLogSubmissionBackgroundService _eventLogSubmissionBackgroundService; private readonly ILoggerService _loggerService; + private readonly IUserDataRepository _userDataRepository; public WorkManagerMigrator( AbsExposureDetectionBackgroundService exposureDetectionBackgroundService, AbsDataMaintainanceBackgroundService dataMaintainanceBackgroundService, AbsEventLogSubmissionBackgroundService eventLogSubmissionBackgroundService, - ILoggerService loggerService + ILoggerService loggerService, + IUserDataRepository userDataRepository ) { _exposureDetectionBackgroundService = exposureDetectionBackgroundService; _dataMaintainanceBackgroundService = dataMaintainanceBackgroundService; _eventLogSubmissionBackgroundService = eventLogSubmissionBackgroundService; _loggerService = loggerService; + _userDataRepository = userDataRepository; } internal Task ExecuteAsync() @@ -44,8 +48,11 @@ internal Task ExecuteAsync() var workManager = WorkManager.GetInstance(Xamarin.Essentials.Platform.AppContext); CancelOldWorks(workManager, OldWorkNames, _loggerService); - _exposureDetectionBackgroundService.Schedule(); - _dataMaintainanceBackgroundService.Schedule(); + if (_userDataRepository.IsAllAgreed()) + { + _exposureDetectionBackgroundService.Schedule(); + _dataMaintainanceBackgroundService.Schedule(); + } _loggerService.EndMethod(); diff --git a/Covid19Radar/Covid19Radar.iOS/AppDelegate.cs b/Covid19Radar/Covid19Radar.iOS/AppDelegate.cs index f53fc6fc3..c5a305a72 100644 --- a/Covid19Radar/Covid19Radar.iOS/AppDelegate.cs +++ b/Covid19Radar/Covid19Radar.iOS/AppDelegate.cs @@ -57,6 +57,9 @@ private Lazy _loggerService private Lazy _exposureConfigurationRepository = new Lazy(() => ContainerLocator.Current.Resolve()); + private Lazy _userDataRepositiry + = new Lazy(() => ContainerLocator.Current.Resolve()); + private App? AppInstance { get @@ -128,22 +131,25 @@ private void ScheduleBackgroundTasks() { _loggerService.Value.StartMethod(); - try + if (_userDataRepositiry.Value.IsAllAgreed()) { - _exposureDetectionBackgroundService.Value.Schedule(); - } - catch (Exception exception) - { - _loggerService.Value.Exception("Failed to schedule ExposureDetectionBackgroundService", exception); - } + try + { + _exposureDetectionBackgroundService.Value.Schedule(); + } + catch (Exception exception) + { + _loggerService.Value.Exception("Failed to schedule ExposureDetectionBackgroundService", exception); + } - try - { - _dataMaintainanceBackgroundService.Value.Schedule(); - } - catch (Exception exception) - { - _loggerService.Value.Exception("Failed to schedule DataMaintainanceBackgroundService", exception); + try + { + _dataMaintainanceBackgroundService.Value.Schedule(); + } + catch (Exception exception) + { + _loggerService.Value.Exception("Failed to schedule DataMaintainanceBackgroundService", exception); + } } _loggerService.Value.EndMethod(); diff --git a/Covid19Radar/Covid19Radar.iOS/Services/DataMaintainanceBackgroundService.cs b/Covid19Radar/Covid19Radar.iOS/Services/DataMaintainanceBackgroundService.cs index 3ecf88170..a44a764d4 100644 --- a/Covid19Radar/Covid19Radar.iOS/Services/DataMaintainanceBackgroundService.cs +++ b/Covid19Radar/Covid19Radar.iOS/Services/DataMaintainanceBackgroundService.cs @@ -107,6 +107,11 @@ private void ScheduleBgTask() LoggerService.EndMethod(); } } + + public override void Cancel() + { + BGTaskScheduler.Shared.Cancel(BGTASK_IDENTIFIER); + } } } diff --git a/Covid19Radar/Covid19Radar.iOS/Services/EventLogSubmissionBackgroundService.cs b/Covid19Radar/Covid19Radar.iOS/Services/EventLogSubmissionBackgroundService.cs index caec569f6..8e573d640 100644 --- a/Covid19Radar/Covid19Radar.iOS/Services/EventLogSubmissionBackgroundService.cs +++ b/Covid19Radar/Covid19Radar.iOS/Services/EventLogSubmissionBackgroundService.cs @@ -119,6 +119,11 @@ private void ScheduleBgTask() _loggerService.EndMethod(); } } + + public override void Cancel() + { + BGTaskScheduler.Shared.Cancel(BGTASK_IDENTIFIER); + } } } diff --git a/Covid19Radar/Covid19Radar.iOS/Services/ExposureDetectionBackgroundService.cs b/Covid19Radar/Covid19Radar.iOS/Services/ExposureDetectionBackgroundService.cs index 0bb267762..cf69d7dc3 100644 --- a/Covid19Radar/Covid19Radar.iOS/Services/ExposureDetectionBackgroundService.cs +++ b/Covid19Radar/Covid19Radar.iOS/Services/ExposureDetectionBackgroundService.cs @@ -129,5 +129,9 @@ private void ScheduleBgTask() } } + public override void Cancel() + { + BGTaskScheduler.Shared.Cancel(BGTASK_IDENTIFIER); + } } } diff --git a/Covid19Radar/Covid19Radar/Services/AbsDataMaintainanceBackgroundService.cs b/Covid19Radar/Covid19Radar/Services/AbsDataMaintainanceBackgroundService.cs index 360993e37..44469f46c 100644 --- a/Covid19Radar/Covid19Radar/Services/AbsDataMaintainanceBackgroundService.cs +++ b/Covid19Radar/Covid19Radar/Services/AbsDataMaintainanceBackgroundService.cs @@ -24,6 +24,7 @@ protected AbsDataMaintainanceBackgroundService( } public abstract void Schedule(); + public abstract void Cancel(); public void Execute() { diff --git a/Covid19Radar/Covid19Radar/Services/AbsEventLogSubmissionBackgroundService.cs b/Covid19Radar/Covid19Radar/Services/AbsEventLogSubmissionBackgroundService.cs index 07a31c74b..af5cfe9af 100644 --- a/Covid19Radar/Covid19Radar/Services/AbsEventLogSubmissionBackgroundService.cs +++ b/Covid19Radar/Covid19Radar/Services/AbsEventLogSubmissionBackgroundService.cs @@ -7,5 +7,6 @@ namespace Covid19Radar.Services public abstract class AbsEventLogSubmissionBackgroundService : IBackgroundService { public abstract void Schedule(); + public abstract void Cancel(); } } diff --git a/Covid19Radar/Covid19Radar/Services/AbsExposureDetectionBackgroundService.cs b/Covid19Radar/Covid19Radar/Services/AbsExposureDetectionBackgroundService.cs index eaf6819a2..ba508e654 100644 --- a/Covid19Radar/Covid19Radar/Services/AbsExposureDetectionBackgroundService.cs +++ b/Covid19Radar/Covid19Radar/Services/AbsExposureDetectionBackgroundService.cs @@ -56,6 +56,7 @@ ILocalNotificationService localNotificationService } public abstract void Schedule(); + public abstract void Cancel(); public virtual async Task ExposureDetectionAsync(CancellationTokenSource cancellationTokenSource = null) { diff --git a/Covid19Radar/Covid19Radar/Services/IBackgroundService.cs b/Covid19Radar/Covid19Radar/Services/IBackgroundService.cs index 6d1adb902..2b7cc5872 100644 --- a/Covid19Radar/Covid19Radar/Services/IBackgroundService.cs +++ b/Covid19Radar/Covid19Radar/Services/IBackgroundService.cs @@ -7,5 +7,6 @@ namespace Covid19Radar.Services public interface IBackgroundService { public abstract void Schedule(); + public abstract void Cancel(); } } diff --git a/Covid19Radar/Covid19Radar/Services/Logs/LogFileService.cs b/Covid19Radar/Covid19Radar/Services/Logs/LogFileService.cs index b8bcede72..915aef37a 100644 --- a/Covid19Radar/Covid19Radar/Services/Logs/LogFileService.cs +++ b/Covid19Radar/Covid19Radar/Services/Logs/LogFileService.cs @@ -166,19 +166,14 @@ public void Rotate() public bool DeleteLogsDir() { - loggerService.StartMethod(); try { var logsDirPath = logPathService.LogsDirPath; Directory.Delete(logsDirPath, true); - loggerService.Info("Deleted all log files."); - loggerService.EndMethod(); return true; } - catch (Exception ex) + catch { - loggerService.Exception("Failed to Delete all log files.", ex); - loggerService.EndMethod(); return false; } } diff --git a/Covid19Radar/Covid19Radar/ViewModels/EndOfService/TerminationOfUsePageViewModel.cs b/Covid19Radar/Covid19Radar/ViewModels/EndOfService/TerminationOfUsePageViewModel.cs index 8e6af329f..9d67cf191 100644 --- a/Covid19Radar/Covid19Radar/ViewModels/EndOfService/TerminationOfUsePageViewModel.cs +++ b/Covid19Radar/Covid19Radar/ViewModels/EndOfService/TerminationOfUsePageViewModel.cs @@ -2,6 +2,12 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. using System; +using System.Threading.Tasks; +using Acr.UserDialogs; +using Chino; +using Covid19Radar.Repository; +using Covid19Radar.Resources; +using Covid19Radar.Services; using Covid19Radar.Services.Logs; using Prism.Navigation; using Xamarin.CommunityToolkit.ObjectModel; @@ -11,32 +17,98 @@ namespace Covid19Radar.ViewModels.EndOfService public class TerminationOfUsePageViewModel : ViewModelBase { private readonly ILoggerService _loggerService; + private readonly ILogFileService _logFileService; + private readonly IUserDataRepository _userDataRepository; + private readonly IEventLogRepository _eventLogRepository; + private readonly ISendEventLogStateRepository _sendEventLogStateRepository; + private readonly IExposureDataRepository _exposureDataRepository; + private readonly IExposureConfigurationRepository _exposureConfigurationRepository; + + private readonly AbsExposureNotificationApiService _absExposureNotificationApiService; + private readonly AbsExposureDetectionBackgroundService _absExposureDetectionBackgroundService; + private readonly AbsDataMaintainanceBackgroundService _absDataMaintainanceBackgroundService; public TerminationOfUsePageViewModel( INavigationService navigationService, - ILoggerService loggerService + ILoggerService loggerService, + ILogFileService logFileService, + IUserDataRepository userDataRepository, + IEventLogRepository eventLogRepository, + ISendEventLogStateRepository sendEventLogStateRepository, + IExposureDataRepository exposureDataRepository, + IExposureConfigurationRepository exposureConfigurationRepository, + AbsExposureNotificationApiService absExposureNotificationApiService, + AbsExposureDetectionBackgroundService absExposureDetectionBackgroundService, + AbsDataMaintainanceBackgroundService absDataMaintainanceBackgroundService ) : base(navigationService) { _loggerService = loggerService; + _logFileService = logFileService; + _userDataRepository = userDataRepository; + _eventLogRepository = eventLogRepository; + _sendEventLogStateRepository = sendEventLogStateRepository; + _exposureDataRepository = exposureDataRepository; + _exposureConfigurationRepository = exposureConfigurationRepository; + + _absExposureNotificationApiService = absExposureNotificationApiService; + _absExposureDetectionBackgroundService = absExposureDetectionBackgroundService; + _absDataMaintainanceBackgroundService = absDataMaintainanceBackgroundService; } public IAsyncCommand OnTerminationButton => new AsyncCommand(async () => { - _loggerService.StartMethod(); - try { + UserDialogs.Instance.ShowLoading(AppResources.LoadingTextDeleting); + + // Stop exposure notifications + await StopExposureNotificationAsync(); + + // Cancel background tasks. + _absExposureDetectionBackgroundService.Cancel(); + _absDataMaintainanceBackgroundService.Cancel(); + + // Reset All Data and Optout + await _exposureDataRepository.RemoveDailySummariesAsync(); + await _exposureDataRepository.RemoveExposureWindowsAsync(); + _exposureDataRepository.RemoveExposureInformation(); + await _userDataRepository.RemoveLastProcessDiagnosisKeyTimestampAsync(); + await _exposureConfigurationRepository.RemoveExposureConfigurationAsync(); + + _userDataRepository.RemoveStartDate(); + _userDataRepository.RemoveAllUpdateDate(); + _userDataRepository.RemoveAllExposureNotificationStatus(); + + _sendEventLogStateRepository.RemoveAll(); + await _eventLogRepository.RemoveAllAsync(); + + _ = _logFileService.DeleteLogsDir(); + + UserDialogs.Instance.HideLoading(); } catch (Exception ex) { _loggerService.Exception("Failed termination of use", ex); } + }); + + private async Task StopExposureNotificationAsync() + { + _loggerService.StartMethod(); + + try + { + _ = await _absExposureNotificationApiService.StopExposureNotificationAsync(); + } + catch (ENException exception) + { + _loggerService.Exception("ENException", exception); + } finally { _loggerService.EndMethod(); } - }); - + } } } diff --git a/Covid19Radar/Tests/Covid19Radar.UnitTests/Covid19Radar.UnitTests.csproj b/Covid19Radar/Tests/Covid19Radar.UnitTests/Covid19Radar.UnitTests.csproj index 0b659f034..d166a353e 100644 --- a/Covid19Radar/Tests/Covid19Radar.UnitTests/Covid19Radar.UnitTests.csproj +++ b/Covid19Radar/Tests/Covid19Radar.UnitTests/Covid19Radar.UnitTests.csproj @@ -47,6 +47,7 @@ + @@ -60,6 +61,7 @@ + diff --git a/Covid19Radar/Tests/Covid19Radar.UnitTests/Services/AbsExposureDetectionBackgroundServiceTests.cs b/Covid19Radar/Tests/Covid19Radar.UnitTests/Services/AbsExposureDetectionBackgroundServiceTests.cs index cfad4047c..5c2330946 100644 --- a/Covid19Radar/Tests/Covid19Radar.UnitTests/Services/AbsExposureDetectionBackgroundServiceTests.cs +++ b/Covid19Radar/Tests/Covid19Radar.UnitTests/Services/AbsExposureDetectionBackgroundServiceTests.cs @@ -537,12 +537,16 @@ ILocalNotificationService localNotificationService } - public override void Schedule() { throw new NotImplementedException(); } + public override void Cancel() + { + throw new NotImplementedException(); + } + public override async Task ShowEndOfServiceNotificationAync(CancellationTokenSource cancellationTokenSource = null) { await Task.CompletedTask; diff --git a/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/EndOfService/TerminationOfUsePageViewModelTests.cs b/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/EndOfService/TerminationOfUsePageViewModelTests.cs new file mode 100644 index 000000000..71557aca1 --- /dev/null +++ b/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/EndOfService/TerminationOfUsePageViewModelTests.cs @@ -0,0 +1,120 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Acr.UserDialogs; +using Chino; +using Covid19Radar.Common; +using Covid19Radar.Repository; +using Covid19Radar.Services; +using Covid19Radar.Services.Logs; +using Covid19Radar.ViewModels.EndOfService; +using Moq; +using Prism.Navigation; +using Xunit; + +namespace Covid19Radar.UnitTests.ViewModels.EndOfService +{ + public class TerminationOfUsePageViewModelTests : IDisposable + { + private readonly MockRepository _mockRepository; + private readonly Mock _mockNavigationService; + private readonly Mock _mockLoggerService; + private readonly Mock _mockLogFileService; + private readonly Mock _mockUserDataRepository; + private readonly Mock _mockEventLogRepository; + private readonly Mock _mockSendEventLogStateRepository; + private readonly Mock _mockExposureDataRepository; + private readonly Mock _mockExposureConfigurationRepository; + + private readonly Mock _mockAbsExposureNotificationApiService; + private readonly Mock _mockAbsExposureDetectionBackgroundService; + private readonly Mock _mockAbsDataMaintainanceBackgroundService; + + private readonly Mock _mockUserDialogs; + + public TerminationOfUsePageViewModelTests() + { + _mockRepository = new MockRepository(MockBehavior.Default); + _mockNavigationService = _mockRepository.Create(); + _mockLoggerService = _mockRepository.Create(); + _mockLogFileService = _mockRepository.Create(); + _mockUserDataRepository = _mockRepository.Create(); + _mockEventLogRepository = _mockRepository.Create(); + _mockSendEventLogStateRepository = _mockRepository.Create(); + _mockExposureDataRepository = _mockRepository.Create(); + _mockExposureConfigurationRepository = _mockRepository.Create(); + + _mockAbsExposureNotificationApiService = new Mock(_mockLoggerService.Object); + _mockAbsExposureDetectionBackgroundService = new Mock( + _mockRepository.Create().Object, + _mockAbsExposureNotificationApiService.Object, + _mockExposureConfigurationRepository.Object, + _mockLoggerService.Object, + _mockUserDataRepository.Object, + _mockRepository.Create().Object, + _mockRepository.Create().Object, + _mockRepository.Create().Object, + _mockRepository.Create().Object); + _mockAbsDataMaintainanceBackgroundService = new Mock( + _mockLoggerService.Object, + _mockLogFileService.Object); + + _mockUserDialogs = _mockRepository.Create(); + UserDialogs.Instance = _mockUserDialogs.Object; + } + + public void Dispose() + { + UserDialogs.Instance = null; + } + + private TerminationOfUsePageViewModel CreateViewModel() + { + return new TerminationOfUsePageViewModel( + _mockNavigationService.Object, + _mockLoggerService.Object, + _mockLogFileService.Object, + _mockUserDataRepository.Object, + _mockEventLogRepository.Object, + _mockSendEventLogStateRepository.Object, + _mockExposureDataRepository.Object, + _mockExposureConfigurationRepository.Object, + _mockAbsExposureNotificationApiService.Object, + _mockAbsExposureDetectionBackgroundService.Object, + _mockAbsDataMaintainanceBackgroundService.Object + ); + } + + [Fact] + public async Task OnTerminationButtonTests() + { + TerminationOfUsePageViewModel unitUnderTest = CreateViewModel(); + await unitUnderTest.OnTerminationButton.ExecuteAsync(); + + _mockUserDialogs.Verify(x => x.ShowLoading(It.IsAny(), null), Times.Once()); + _mockUserDialogs.Verify(x => x.HideLoading(), Times.Once()); + + //_mockAbsExposureNotificationApiService.Verify(x => x.StopExposureNotificationAsync(), Times.Once()); + _mockAbsExposureDetectionBackgroundService.Verify(x => x.Cancel(), Times.Once()); + _mockAbsDataMaintainanceBackgroundService.Verify(x => x.Cancel(), Times.Once()); + + _mockExposureDataRepository.Verify(x => x.RemoveDailySummariesAsync(), Times.Once()); + _mockExposureDataRepository.Verify(x => x.RemoveExposureWindowsAsync(), Times.Once()); + _mockExposureDataRepository.Verify(x => x.RemoveExposureInformation(), Times.Once()); + _mockUserDataRepository.Verify(x => x.RemoveLastProcessDiagnosisKeyTimestampAsync(), Times.Once()); + _mockUserDataRepository.Verify(x => x.RemoveStartDate(), Times.Once()); + _mockUserDataRepository.Verify(x => x.RemoveAllUpdateDate(), Times.Once()); + _mockUserDataRepository.Verify(x => x.RemoveAllExposureNotificationStatus(), Times.Once()); + _mockExposureConfigurationRepository.Verify(x => x.RemoveExposureConfigurationAsync(), Times.Once()); + _mockSendEventLogStateRepository.Verify(x => x.RemoveAll(), Times.Once()); + _mockEventLogRepository.Verify(x => x.RemoveAllAsync(), Times.Once()); + _mockLogFileService.Verify(x => x.DeleteLogsDir(), Times.Once()); + } + } +} +