From 835a8757cef98ce84184f1767de25f17f7919c96 Mon Sep 17 00:00:00 2001 From: ARIYAMA Keiji Date: Sat, 15 Jan 2022 16:30:21 +0900 Subject: [PATCH 01/53] WIP --- .../Services/Logs/ILogFileService.cs | 2 +- .../Services/Logs/LogFileService.cs | 13 ++- .../HelpPage/InqueryPageViewModel.cs | 101 ++++++++++++++++- .../SendLogConfirmationPageViewModel.cs | 103 ++---------------- .../HelpPage/SendLogConfirmationPage.xaml.cs | 20 ++++ 5 files changed, 138 insertions(+), 101 deletions(-) diff --git a/Covid19Radar/Covid19Radar/Services/Logs/ILogFileService.cs b/Covid19Radar/Covid19Radar/Services/Logs/ILogFileService.cs index abf8a1b55..df73a8093 100644 --- a/Covid19Radar/Covid19Radar/Services/Logs/ILogFileService.cs +++ b/Covid19Radar/Covid19Radar/Services/Logs/ILogFileService.cs @@ -10,7 +10,7 @@ public interface ILogFileService string CreateLogId(); string LogUploadingFileName(string logId); bool CreateLogUploadingFileToTmpPath(string logUploadingFileName); - bool CopyLogUploadingFileToPublicPath(string logUploadingFileName); + string CopyLogUploadingFileToPublicPath(string logPath); bool DeleteAllLogUploadingFiles(); // Log rotate diff --git a/Covid19Radar/Covid19Radar/Services/Logs/LogFileService.cs b/Covid19Radar/Covid19Radar/Services/Logs/LogFileService.cs index 807847219..75484d89f 100644 --- a/Covid19Radar/Covid19Radar/Services/Logs/LogFileService.cs +++ b/Covid19Radar/Covid19Radar/Services/Logs/LogFileService.cs @@ -74,27 +74,30 @@ public bool CreateLogUploadingFileToTmpPath(string logUploadingFileName) } } - public bool CopyLogUploadingFileToPublicPath(string logUploadingFileName) + public string CopyLogUploadingFileToPublicPath(string logPath) { loggerService.StartMethod(); try { + var logFileName = Path.GetFileName(logPath); var tmpPath = logPathService.LogUploadingTmpPath; var publicPath = logPathService.LogUploadingPublicPath; if (string.IsNullOrEmpty(tmpPath) || string.IsNullOrEmpty(publicPath)) { loggerService.EndMethod(); - return false; + return null; } - File.Copy(Path.Combine(tmpPath, logUploadingFileName), Path.Combine(publicPath, logUploadingFileName), true); + var destPath = Path.Combine(publicPath, logFileName); + File.Copy(logPath, destPath, true); loggerService.EndMethod(); - return true; + + return destPath; } catch (Exception) { loggerService.Error("Failed to copy log file"); loggerService.EndMethod(); - return false; + return null; } } diff --git a/Covid19Radar/Covid19Radar/ViewModels/HelpPage/InqueryPageViewModel.cs b/Covid19Radar/Covid19Radar/ViewModels/HelpPage/InqueryPageViewModel.cs index 9019e4fa9..3ffdf496b 100644 --- a/Covid19Radar/Covid19Radar/ViewModels/HelpPage/InqueryPageViewModel.cs +++ b/Covid19Radar/Covid19Radar/ViewModels/HelpPage/InqueryPageViewModel.cs @@ -4,6 +4,7 @@ using System; using System.Threading.Tasks; +using Acr.UserDialogs; using Covid19Radar.Resources; using Covid19Radar.Services.Logs; using Covid19Radar.Views; @@ -16,14 +17,27 @@ namespace Covid19Radar.ViewModels public class InqueryPageViewModel : ViewModelBase { private readonly ILoggerService loggerService; + private readonly ILogFileService logFileService; + private readonly ILogPathService logPathService; + + private readonly IEssentialsService essentialService; public Func BrowserOpenAsync = Browser.OpenAsync; public Func ComposeEmailAsync { get; set; } = Email.ComposeAsync; - public InqueryPageViewModel(INavigationService navigationService, ILoggerService loggerService) : base(navigationService) + public InqueryPageViewModel( + INavigationService navigationService, + ILoggerService loggerService, + ILogFileService logFileService, + ILogPathService logPathService, + IEssentialsService eseentialService + ) : base(navigationService) { Title = AppResources.InqueryPageTitle; this.loggerService = loggerService; + this.logFileService = logFileService; + this.logPathService = logPathService; + this.essentialService = eseentialService; } public Command OnClickQuestionCommand => new Command(async () => @@ -40,9 +54,76 @@ public InqueryPageViewModel(INavigationService navigationService, ILoggerService { loggerService.StartMethod(); - _ = await NavigationService.NavigateAsync(nameof(SendLogConfirmationPage)); + try + { + UserDialogs.Instance.ShowLoading(AppResources.Processing); - loggerService.EndMethod(); + var (result, logId, zipFilePath) = CreateZipFile(); + + UserDialogs.Instance.HideLoading(); + + if (!result) + { + // Failed to create ZIP file + await UserDialogs.Instance.AlertAsync( + AppResources.FailedMessageToGetOperatingInformation, + AppResources.Error, + AppResources.ButtonOk); + return; + } + + INavigationParameters navigationParameters + = SendLogConfirmationPage.BuildNavigationParams(logId, zipFilePath); + + _ = await NavigationService.NavigateAsync(nameof(SendLogConfirmationPage), navigationParameters); + } + finally + { + loggerService.EndMethod(); + } + }); + + public Command OnClickShareLogCommand => new Command(async () => + { + loggerService.StartMethod(); + + try + { + UserDialogs.Instance.ShowLoading(AppResources.Processing); + + var (result, logId, zipFilePath) = CreateZipFile(); + + UserDialogs.Instance.HideLoading(); + + if (!result) + { + // Failed to create ZIP file + await UserDialogs.Instance.AlertAsync( + AppResources.FailedMessageToGetOperatingInformation, + AppResources.Error, + AppResources.ButtonOk); + return; + } + + string sharePath = logFileService.CopyLogUploadingFileToPublicPath(zipFilePath); + + try + { + await Share.RequestAsync(new ShareFileRequest + { + File = new ShareFile(sharePath) + }); + } + catch (NotImplementedInReferenceAssemblyException exception) + { + loggerService.Exception("NotImplementedInReferenceAssemblyException", exception); + } + + } + finally + { + loggerService.EndMethod(); + } }); public Command OnClickEmailCommand => new Command(async () => @@ -73,5 +154,19 @@ await ComposeEmailAsync( loggerService.EndMethod(); }); + + public Action BeginInvokeOnMainThread { get; set; } = MainThread.BeginInvokeOnMainThread; + + private (bool, string, string) CreateZipFile() + { + string logId = logFileService.CreateLogId(); + string zipFilePath = logFileService.LogUploadingFileName(logId); + + logFileService.Rotate(); + + var result = logFileService.CreateLogUploadingFileToTmpPath(zipFilePath); + + return (result, logId, zipFilePath); + } } } diff --git a/Covid19Radar/Covid19Radar/ViewModels/HelpPage/SendLogConfirmationPageViewModel.cs b/Covid19Radar/Covid19Radar/ViewModels/HelpPage/SendLogConfirmationPageViewModel.cs index 5e5cf72d2..aede149c6 100644 --- a/Covid19Radar/Covid19Radar/ViewModels/HelpPage/SendLogConfirmationPageViewModel.cs +++ b/Covid19Radar/Covid19Radar/ViewModels/HelpPage/SendLogConfirmationPageViewModel.cs @@ -2,15 +2,11 @@ * 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.IO; -using System.Threading.Tasks; using Acr.UserDialogs; using Covid19Radar.Resources; using Covid19Radar.Services.Logs; using Covid19Radar.Views; using Prism.Navigation; -using Xamarin.Essentials; using Xamarin.Forms; namespace Covid19Radar.ViewModels @@ -22,33 +18,24 @@ public class SendLogConfirmationPageViewModel : ViewModelBase private readonly ILoggerService loggerService; private readonly ILogFileService logFileService; private readonly ILogUploadService logUploadService; - private readonly ILogPathService logPathService; - - public Action BeginInvokeOnMainThread { get; set; } = MainThread.BeginInvokeOnMainThread; - public Func TaskRun { get; set; } = Task.Run; private string LogId { get; set; } - private string ZipFileName { get; set; } + private string ZipFilePath { get; set; } public SendLogConfirmationPageViewModel( INavigationService navigationService, - ILogFileService logFileService, ILoggerService loggerService, - ILogUploadService logUploadService, - ILogPathService logPathService) : base(navigationService) + ILogUploadService logUploadService + ) : base(navigationService) { this.loggerService = loggerService; - this.logFileService = logFileService; this.logUploadService = logUploadService; - this.logPathService = logPathService; } public Command OnClickConfirmLogCommand => new Command(() => { loggerService.StartMethod(); - CopyZipFileToPublicPath(); - loggerService.EndMethod(); }); @@ -58,9 +45,9 @@ public SendLogConfirmationPageViewModel( try { // Upload log file. - UserDialogs.Instance.ShowLoading(Resources.AppResources.Sending); + UserDialogs.Instance.ShowLoading(AppResources.Sending); - var uploadResult = await logUploadService.UploadAsync(ZipFileName); + var uploadResult = await logUploadService.UploadAsync(ZipFilePath); UserDialogs.Instance.HideLoading(); @@ -68,9 +55,9 @@ public SendLogConfirmationPageViewModel( { // Failed to create ZIP file await UserDialogs.Instance.AlertAsync( - Resources.AppResources.FailedMessageToSendOperatingInformation, - Resources.AppResources.SendingError, - Resources.AppResources.ButtonOk); + AppResources.FailedMessageToSendOperatingInformation, + AppResources.SendingError, + AppResources.ButtonOk); return; } @@ -99,7 +86,9 @@ public override void Initialize(INavigationParameters parameters) loggerService.StartMethod(); base.Initialize(parameters); - CreateZipFile(); + + LogId = parameters.GetValue(SendLogConfirmationPage.LogIdKey); + ZipFilePath = parameters.GetValue(SendLogConfirmationPage.LogIdKey); loggerService.EndMethod(); } @@ -111,75 +100,5 @@ public override void Destroy() logFileService.DeleteAllLogUploadingFiles(); loggerService.EndMethod(); } - - private void CreateZipFile() - { - LogId = logFileService.CreateLogId(); - ZipFileName = logFileService.LogUploadingFileName(LogId); - - UserDialogs.Instance.ShowLoading(Resources.AppResources.Processing); - - _ = TaskRun(() => - { - logFileService.Rotate(); - - var result = logFileService.CreateLogUploadingFileToTmpPath(ZipFileName); - - BeginInvokeOnMainThread(async () => - { - UserDialogs.Instance.HideLoading(); - - if (!result) - { - // Failed to create ZIP file - await UserDialogs.Instance.AlertAsync( - Resources.AppResources.FailedMessageToGetOperatingInformation, - Resources.AppResources.Error, - Resources.AppResources.ButtonOk); - - _ = await NavigationService.GoBackAsync(); - } - }); - }); - } - - private void CopyZipFileToPublicPath() - { - - _ = TaskRun(() => - { - var result = logFileService.CopyLogUploadingFileToPublicPath(ZipFileName); - - BeginInvokeOnMainThread(async () => - { - - if (!result) - { - await UserDialogs.Instance.AlertAsync( - Resources.AppResources.FailedMessageToSaveOperatingInformation, - Resources.AppResources.Error, - Resources.AppResources.ButtonOk); - } - else - { - var publicPath = logPathService.LogUploadingPublicPath; - var logUploadingFileName = logFileService.LogUploadingFileName(LogId); - var path = Path.Combine(publicPath, logUploadingFileName); - - try - { - await Share.RequestAsync(new ShareFileRequest - { - File = new ShareFile(path) - }); - } - catch (NotImplementedInReferenceAssemblyException exception) - { - loggerService.Exception("NotImplementedInReferenceAssemblyException", exception); - } - } - }); - }); - } } } diff --git a/Covid19Radar/Covid19Radar/Views/HelpPage/SendLogConfirmationPage.xaml.cs b/Covid19Radar/Covid19Radar/Views/HelpPage/SendLogConfirmationPage.xaml.cs index bbc95ad71..d4d0d69c2 100644 --- a/Covid19Radar/Covid19Radar/Views/HelpPage/SendLogConfirmationPage.xaml.cs +++ b/Covid19Radar/Covid19Radar/Views/HelpPage/SendLogConfirmationPage.xaml.cs @@ -2,6 +2,7 @@ * 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 Prism.Navigation; using Xamarin.Forms; using Xamarin.Forms.Xaml; @@ -10,9 +11,28 @@ namespace Covid19Radar.Views [XamlCompilation(XamlCompilationOptions.Compile)] public partial class SendLogConfirmationPage : ContentPage { + public const string LogIdKey = "logIdKey"; + public const string ZipFilePathKey = "zipFilePathKey"; + public SendLogConfirmationPage() { InitializeComponent(); } + + public static INavigationParameters BuildNavigationParams( + string logIdKey, + string ZipFilePathKey, + INavigationParameters? baseParam = null + ) + { + var param = new NavigationParameters(); + param.CopyFrom(baseParam); + + param.Add(LogIdKey, logIdKey); + param.Add(ZipFilePathKey, ZipFilePathKey); + + return param; + } + } } From 2e89e167cf045928d88b3306903322e07cd54338 Mon Sep 17 00:00:00 2001 From: ARIYAMA Keiji Date: Sat, 15 Jan 2022 17:11:45 +0900 Subject: [PATCH 02/53] Create zipped-logfile at tapped "Send Operating information" button. --- .../Services/Logs/ILogFileService.cs | 4 +- .../Services/Logs/LogFileService.cs | 37 +++++++++++-------- .../HelpPage/InqueryPageViewModel.cs | 26 +++++++------ .../SendLogConfirmationPageViewModel.cs | 32 +++++++++++++++- .../HelpPage/SendLogConfirmationPage.xaml.cs | 8 ++-- .../Services/Logs/LogFileServiceTests.cs | 34 ++++++++--------- .../SendLogConfirmationPageViewModelTests.cs | 36 +++++++++--------- 7 files changed, 106 insertions(+), 71 deletions(-) diff --git a/Covid19Radar/Covid19Radar/Services/Logs/ILogFileService.cs b/Covid19Radar/Covid19Radar/Services/Logs/ILogFileService.cs index df73a8093..c88485848 100644 --- a/Covid19Radar/Covid19Radar/Services/Logs/ILogFileService.cs +++ b/Covid19Radar/Covid19Radar/Services/Logs/ILogFileService.cs @@ -8,8 +8,8 @@ public interface ILogFileService { // Log upload string CreateLogId(); - string LogUploadingFileName(string logId); - bool CreateLogUploadingFileToTmpPath(string logUploadingFileName); + string CreateZipFileName(string logId); + string CreateZipFile(string fileName); string CopyLogUploadingFileToPublicPath(string logPath); bool DeleteAllLogUploadingFiles(); diff --git a/Covid19Radar/Covid19Radar/Services/Logs/LogFileService.cs b/Covid19Radar/Covid19Radar/Services/Logs/LogFileService.cs index 75484d89f..7dd702ca8 100644 --- a/Covid19Radar/Covid19Radar/Services/Logs/LogFileService.cs +++ b/Covid19Radar/Covid19Radar/Services/Logs/LogFileService.cs @@ -13,8 +13,8 @@ public class LogFileService : ILogFileService { #region Static Fields - private static readonly string logUploadFilePrefix = "cocoa_log_"; - private static readonly string logUploadFileExtension = "zip"; + private static readonly string logFilePrefix = "cocoa_log_"; + private static readonly string logFileExtension = "zip"; #endregion @@ -45,12 +45,12 @@ IBackupAttributeService backupAttributeService public string CreateLogId() => Guid.NewGuid().ToString(); - public string LogUploadingFileName(string logId) + public string CreateZipFileName(string logId) { - return logUploadFilePrefix + logId + "." + logUploadFileExtension; + return logFilePrefix + logId + "." + logFileExtension; } - public bool CreateLogUploadingFileToTmpPath(string logUploadingFileName) + public string CreateZipFile(string fileName) { loggerService.StartMethod(); try @@ -59,18 +59,22 @@ public bool CreateLogUploadingFileToTmpPath(string logUploadingFileName) var logFiles = Directory.GetFiles(logsDirPath, logPathService.LogFileWildcardName); if (logFiles.Length == 0) { - loggerService.EndMethod(); - return false; + return null; } - ZipFile.CreateFromDirectory(logsDirPath, Path.Combine(logPathService.LogUploadingTmpPath, logUploadingFileName)); - loggerService.EndMethod(); - return true; + + var zipFilePath = Path.Combine(logPathService.LogUploadingTmpPath, fileName); + ZipFile.CreateFromDirectory(logsDirPath, zipFilePath); + + return zipFilePath; } catch (Exception) { loggerService.Error("Failed to create uploading file"); + return null; + } + finally + { loggerService.EndMethod(); - return false; } } @@ -84,21 +88,22 @@ public string CopyLogUploadingFileToPublicPath(string logPath) var publicPath = logPathService.LogUploadingPublicPath; if (string.IsNullOrEmpty(tmpPath) || string.IsNullOrEmpty(publicPath)) { - loggerService.EndMethod(); return null; } var destPath = Path.Combine(publicPath, logFileName); File.Copy(logPath, destPath, true); - loggerService.EndMethod(); return destPath; } - catch (Exception) + catch (Exception exception) { - loggerService.Error("Failed to copy log file"); - loggerService.EndMethod(); + loggerService.Exception("Failed to copy log file", exception); return null; } + finally + { + loggerService.EndMethod(); + } } public bool DeleteAllLogUploadingFiles() diff --git a/Covid19Radar/Covid19Radar/ViewModels/HelpPage/InqueryPageViewModel.cs b/Covid19Radar/Covid19Radar/ViewModels/HelpPage/InqueryPageViewModel.cs index 3ffdf496b..5aedc2ef3 100644 --- a/Covid19Radar/Covid19Radar/ViewModels/HelpPage/InqueryPageViewModel.cs +++ b/Covid19Radar/Covid19Radar/ViewModels/HelpPage/InqueryPageViewModel.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Acr.UserDialogs; using Covid19Radar.Resources; +using Covid19Radar.Services; using Covid19Radar.Services.Logs; using Covid19Radar.Views; using Prism.Navigation; @@ -58,11 +59,11 @@ IEssentialsService eseentialService { UserDialogs.Instance.ShowLoading(AppResources.Processing); - var (result, logId, zipFilePath) = CreateZipFile(); + var (logId, zipFilePath) = CreateZipFile(); UserDialogs.Instance.HideLoading(); - if (!result) + if (zipFilePath is null) { // Failed to create ZIP file await UserDialogs.Instance.AlertAsync( @@ -72,8 +73,10 @@ await UserDialogs.Instance.AlertAsync( return; } + loggerService.Info($"zipFilePath: {zipFilePath}"); + INavigationParameters navigationParameters - = SendLogConfirmationPage.BuildNavigationParams(logId, zipFilePath); + = SendLogConfirmationPage.BuildNavigationParams(logId, zipFilePath); _ = await NavigationService.NavigateAsync(nameof(SendLogConfirmationPage), navigationParameters); } @@ -91,11 +94,11 @@ INavigationParameters navigationParameters { UserDialogs.Instance.ShowLoading(AppResources.Processing); - var (result, logId, zipFilePath) = CreateZipFile(); + var (logId, zipFilePath) = CreateZipFile(); UserDialogs.Instance.HideLoading(); - if (!result) + if (zipFilePath is null) { // Failed to create ZIP file await UserDialogs.Instance.AlertAsync( @@ -105,6 +108,8 @@ await UserDialogs.Instance.AlertAsync( return; } + loggerService.Info($"zipFilePath: {zipFilePath}"); + string sharePath = logFileService.CopyLogUploadingFileToPublicPath(zipFilePath); try @@ -118,7 +123,6 @@ await Share.RequestAsync(new ShareFileRequest { loggerService.Exception("NotImplementedInReferenceAssemblyException", exception); } - } finally { @@ -155,18 +159,16 @@ await ComposeEmailAsync( loggerService.EndMethod(); }); - public Action BeginInvokeOnMainThread { get; set; } = MainThread.BeginInvokeOnMainThread; - - private (bool, string, string) CreateZipFile() + private (string, string) CreateZipFile() { string logId = logFileService.CreateLogId(); - string zipFilePath = logFileService.LogUploadingFileName(logId); + string zipFileName = logFileService.CreateZipFileName(logId); logFileService.Rotate(); - var result = logFileService.CreateLogUploadingFileToTmpPath(zipFilePath); + var zipFilePath = logFileService.CreateZipFile(zipFileName); - return (result, logId, zipFilePath); + return (logId, zipFilePath); } } } diff --git a/Covid19Radar/Covid19Radar/ViewModels/HelpPage/SendLogConfirmationPageViewModel.cs b/Covid19Radar/Covid19Radar/ViewModels/HelpPage/SendLogConfirmationPageViewModel.cs index aede149c6..1171ac488 100644 --- a/Covid19Radar/Covid19Radar/ViewModels/HelpPage/SendLogConfirmationPageViewModel.cs +++ b/Covid19Radar/Covid19Radar/ViewModels/HelpPage/SendLogConfirmationPageViewModel.cs @@ -7,6 +7,7 @@ using Covid19Radar.Services.Logs; using Covid19Radar.Views; using Prism.Navigation; +using Xamarin.Essentials; using Xamarin.Forms; namespace Covid19Radar.ViewModels @@ -25,17 +26,42 @@ public class SendLogConfirmationPageViewModel : ViewModelBase public SendLogConfirmationPageViewModel( INavigationService navigationService, ILoggerService loggerService, + ILogFileService logFileService, ILogUploadService logUploadService ) : base(navigationService) { this.loggerService = loggerService; + this.logFileService = logFileService; this.logUploadService = logUploadService; } - public Command OnClickConfirmLogCommand => new Command(() => + public Command OnClickConfirmLogCommand => new Command(async () => { loggerService.StartMethod(); + string sharePath = logFileService.CopyLogUploadingFileToPublicPath(ZipFilePath); + + if (sharePath is null) + { + await UserDialogs.Instance.AlertAsync( + AppResources.FailedMessageToSaveOperatingInformation, + AppResources.Error, + AppResources.ButtonOk); + return; + } + + try + { + await Share.RequestAsync(new ShareFileRequest + { + File = new ShareFile(sharePath) + }); + } + catch (NotImplementedInReferenceAssemblyException exception) + { + loggerService.Exception("NotImplementedInReferenceAssemblyException", exception); + } + loggerService.EndMethod(); }); @@ -88,7 +114,9 @@ public override void Initialize(INavigationParameters parameters) base.Initialize(parameters); LogId = parameters.GetValue(SendLogConfirmationPage.LogIdKey); - ZipFilePath = parameters.GetValue(SendLogConfirmationPage.LogIdKey); + ZipFilePath = parameters.GetValue(SendLogConfirmationPage.ZipFilePathKey); + + loggerService.Info($"ZipFilePath: {ZipFilePath}"); loggerService.EndMethod(); } diff --git a/Covid19Radar/Covid19Radar/Views/HelpPage/SendLogConfirmationPage.xaml.cs b/Covid19Radar/Covid19Radar/Views/HelpPage/SendLogConfirmationPage.xaml.cs index d4d0d69c2..db838b812 100644 --- a/Covid19Radar/Covid19Radar/Views/HelpPage/SendLogConfirmationPage.xaml.cs +++ b/Covid19Radar/Covid19Radar/Views/HelpPage/SendLogConfirmationPage.xaml.cs @@ -20,16 +20,16 @@ public SendLogConfirmationPage() } public static INavigationParameters BuildNavigationParams( - string logIdKey, - string ZipFilePathKey, + string logId, + string zipFilePath, INavigationParameters? baseParam = null ) { var param = new NavigationParameters(); param.CopyFrom(baseParam); - param.Add(LogIdKey, logIdKey); - param.Add(ZipFilePathKey, ZipFilePathKey); + param.Add(LogIdKey, logId); + param.Add(ZipFilePathKey, zipFilePath); return param; } diff --git a/Covid19Radar/Tests/Covid19Radar.UnitTests/Services/Logs/LogFileServiceTests.cs b/Covid19Radar/Tests/Covid19Radar.UnitTests/Services/Logs/LogFileServiceTests.cs index 36a0b2473..9eb253a12 100644 --- a/Covid19Radar/Tests/Covid19Radar.UnitTests/Services/Logs/LogFileServiceTests.cs +++ b/Covid19Radar/Tests/Covid19Radar.UnitTests/Services/Logs/LogFileServiceTests.cs @@ -35,7 +35,7 @@ public void LogUploadingFileName_Success() var logFileService = CreateDefaultLogFileService(mockILogPathService); var logId = logFileService.CreateLogId(); - var fileName = logFileService.LogUploadingFileName(logId); + var fileName = logFileService.CreateZipFileName(logId); Assert.Equal(fileName, "cocoa_log_" + logId + ".zip"); } @@ -50,8 +50,8 @@ public void CreateLogUploadingFileToTmpPath_Success() RecreateDir(tmpDirPath); var logId = logFileService.CreateLogId(); - var fileName = logFileService.LogUploadingFileName(logId); - var result = logFileService.CreateLogUploadingFileToTmpPath(fileName); + var fileName = logFileService.CreateZipFileName(logId); + var result = logFileService.CreateZipFile(fileName); Assert.True(result); var uploadingFilePath = tmpDirPath + fileName; @@ -68,8 +68,8 @@ public void CreateLogUploadingFileToTmpPath_Log_Not_Exists() RecreateDir(tmpDirPath); var logId = logFileService.CreateLogId(); - var fileName = logFileService.LogUploadingFileName(logId); - var result = logFileService.CreateLogUploadingFileToTmpPath(fileName); + var fileName = logFileService.CreateZipFileName(logId); + var result = logFileService.CreateZipFile(fileName); Assert.False(result); var uploadingFilePath = tmpDirPath + fileName; @@ -86,8 +86,8 @@ public void CreateLogUploadingFileToTmpPath_LogDir_Not_Exists() RecreateDir(tmpDirPath); var logId = logFileService.CreateLogId(); - var fileName = logFileService.LogUploadingFileName(logId); - var result = logFileService.CreateLogUploadingFileToTmpPath(fileName); + var fileName = logFileService.CreateZipFileName(logId); + var result = logFileService.CreateZipFile(fileName); Assert.False(result); var uploadingFilePath = tmpDirPath + fileName; @@ -106,8 +106,8 @@ public void CopyLogUploadingFileToPublicPath_Success() RecreateDir(tmpDirPath); var logId = logFileService.CreateLogId(); - var fileName = logFileService.LogUploadingFileName(logId); - var result = logFileService.CreateLogUploadingFileToTmpPath(fileName); + var fileName = logFileService.CreateZipFileName(logId); + var result = logFileService.CreateZipFile(fileName); Assert.True(result); result = logFileService.CopyLogUploadingFileToPublicPath(fileName); Assert.True(result); @@ -128,8 +128,8 @@ public void CopyLogUploadingFileToPublicPath_PublicDir_Not_Exists() RecreateDir(tmpDirPath); var logId = logFileService.CreateLogId(); - var fileName = logFileService.LogUploadingFileName(logId); - var result = logFileService.CreateLogUploadingFileToTmpPath(fileName); + var fileName = logFileService.CreateZipFileName(logId); + var result = logFileService.CreateZipFile(fileName); Assert.True(result); result = logFileService.CopyLogUploadingFileToPublicPath(fileName); Assert.False(result); @@ -145,7 +145,7 @@ public void CopyLogUploadingFileToPublicPath_TmpPath_Empty() var logFileService = CreateDefaultLogFileService(mockILogPathService); var logId = logFileService.CreateLogId(); - var fileName = logFileService.LogUploadingFileName(logId); + var fileName = logFileService.CreateZipFileName(logId); var result = logFileService.CopyLogUploadingFileToPublicPath(fileName); Assert.False(result); @@ -160,7 +160,7 @@ public void CopyLogUploadingFileToPublicPath_PublicPath_Empty() var logFileService = CreateDefaultLogFileService(mockILogPathService); var logId = logFileService.CreateLogId(); - var fileName = logFileService.LogUploadingFileName(logId); + var fileName = logFileService.CreateZipFileName(logId); var result = logFileService.CopyLogUploadingFileToPublicPath(fileName); Assert.False(result); @@ -179,8 +179,8 @@ public void DeleteAllLogUploadingFiles_Success() RecreateDir(tmpDirPath); var logId = logFileService.CreateLogId(); - var fileName = logFileService.LogUploadingFileName(logId); - var result = logFileService.CreateLogUploadingFileToTmpPath(fileName); + var fileName = logFileService.CreateZipFileName(logId); + var result = logFileService.CreateZipFile(fileName); Assert.True(result); result = logFileService.DeleteAllLogUploadingFiles(); @@ -211,8 +211,8 @@ public void DeleteAllLogUploadingFiles_TmpDir_Not_Exists() RecreateDir(tmpDirPath); var logId = logFileService.CreateLogId(); - var fileName = logFileService.LogUploadingFileName(logId); - var result = logFileService.CreateLogUploadingFileToTmpPath(fileName); + var fileName = logFileService.CreateZipFileName(logId); + var result = logFileService.CreateZipFile(fileName); Assert.True(result); DeleteDirIfExists(tmpDirPath); diff --git a/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/SendLogConfirmationPageViewModelTests.cs b/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/SendLogConfirmationPageViewModelTests.cs index c2312ce74..b5cc03922 100644 --- a/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/SendLogConfirmationPageViewModelTests.cs +++ b/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/SendLogConfirmationPageViewModelTests.cs @@ -61,15 +61,15 @@ public void InitializeTests_CreateZipSuccess() mockLogFileService.Setup(x => x.CreateLogId()).Returns(testLogId); var testZipFileName = "test-zip-file-name"; - mockLogFileService.Setup(x => x.LogUploadingFileName(testLogId)).Returns(testZipFileName); - mockLogFileService.Setup(x => x.CreateLogUploadingFileToTmpPath(testZipFileName)).Returns(true); + mockLogFileService.Setup(x => x.CreateZipFileName(testLogId)).Returns(testZipFileName); + mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(true); var unitUnderTest = CreateViewModel(); unitUnderTest.Initialize(new NavigationParameters()); mockLogFileService.Verify(x => x.CreateLogId(), Times.Once()); - mockLogFileService.Verify(x => x.LogUploadingFileName(testLogId), Times.Once()); - mockLogFileService.Verify(x => x.CreateLogUploadingFileToTmpPath(testZipFileName), Times.Once()); + mockLogFileService.Verify(x => x.CreateZipFileName(testLogId), Times.Once()); + mockLogFileService.Verify(x => x.CreateZipFile(testZipFileName), Times.Once()); mockUserDialogs.Verify(x => x.ShowLoading(It.IsAny(), null), Times.Once()); mockUserDialogs.Verify(x => x.HideLoading(), Times.Once()); @@ -85,15 +85,15 @@ public void InitializeTests_CreateZipFailure() mockLogFileService.Setup(x => x.CreateLogId()).Returns(testLogId); var testZipFileName = "test-zip-file-name"; - mockLogFileService.Setup(x => x.LogUploadingFileName(testLogId)).Returns(testZipFileName); - mockLogFileService.Setup(x => x.CreateLogUploadingFileToTmpPath(testZipFileName)).Returns(false); + mockLogFileService.Setup(x => x.CreateZipFileName(testLogId)).Returns(testZipFileName); + mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(false); var unitUnderTest = CreateViewModel(); unitUnderTest.Initialize(new NavigationParameters()); mockLogFileService.Verify(x => x.CreateLogId(), Times.Once()); - mockLogFileService.Verify(x => x.LogUploadingFileName(testLogId), Times.Once()); - mockLogFileService.Verify(x => x.CreateLogUploadingFileToTmpPath(testZipFileName), Times.Once()); + mockLogFileService.Verify(x => x.CreateZipFileName(testLogId), Times.Once()); + mockLogFileService.Verify(x => x.CreateZipFile(testZipFileName), Times.Once()); mockUserDialogs.Verify(x => x.ShowLoading(It.IsAny(), null), Times.Once()); mockUserDialogs.Verify(x => x.HideLoading(), Times.Once()); @@ -109,8 +109,8 @@ public void OnClickConfirmLogCommandTests_Success() mockLogFileService.Setup(x => x.CreateLogId()).Returns(testLogId); var testZipFileName = "test-zip-file-name"; - mockLogFileService.Setup(x => x.LogUploadingFileName(testLogId)).Returns(testZipFileName); - mockLogFileService.Setup(x => x.CreateLogUploadingFileToTmpPath(testZipFileName)).Returns(true); + mockLogFileService.Setup(x => x.CreateZipFileName(testLogId)).Returns(testZipFileName); + mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(true); mockLogFileService.Setup(x => x.CopyLogUploadingFileToPublicPath(testZipFileName)).Returns(true); mockLogPathService.Setup(x => x.LogUploadingPublicPath).Returns("dummy_log_uploading_public_path"); @@ -132,8 +132,8 @@ public void OnClickConfirmLogCommandTests_Failure() mockLogFileService.Setup(x => x.CreateLogId()).Returns(testLogId); var testZipFileName = "test-zip-file-name"; - mockLogFileService.Setup(x => x.LogUploadingFileName(testLogId)).Returns(testZipFileName); - mockLogFileService.Setup(x => x.CreateLogUploadingFileToTmpPath(testZipFileName)).Returns(true); + mockLogFileService.Setup(x => x.CreateZipFileName(testLogId)).Returns(testZipFileName); + mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(true); mockLogFileService.Setup(x => x.CopyLogUploadingFileToPublicPath(testZipFileName)).Returns(false); var unitUnderTest = CreateViewModel(); @@ -154,8 +154,8 @@ public void OnClickSendLogCommandTests_Success() mockLogFileService.Setup(x => x.CreateLogId()).Returns(testLogId); var testZipFileName = "test-zip-file-name"; - mockLogFileService.Setup(x => x.LogUploadingFileName(testLogId)).Returns(testZipFileName); - mockLogFileService.Setup(x => x.CreateLogUploadingFileToTmpPath(testZipFileName)).Returns(true); + mockLogFileService.Setup(x => x.CreateZipFileName(testLogId)).Returns(testZipFileName); + mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(true); mockLogFileService.Setup(x => x.CopyLogUploadingFileToPublicPath(testZipFileName)).Returns(true); mockLogFileService.Setup(x => x.DeleteAllLogUploadingFiles()).Returns(true); @@ -185,8 +185,8 @@ public void OnClickSendLogCommandTests_Failure() mockLogFileService.Setup(x => x.CreateLogId()).Returns(testLogId); var testZipFileName = "test-zip-file-name"; - mockLogFileService.Setup(x => x.LogUploadingFileName(testLogId)).Returns(testZipFileName); - mockLogFileService.Setup(x => x.CreateLogUploadingFileToTmpPath(testZipFileName)).Returns(true); + mockLogFileService.Setup(x => x.CreateZipFileName(testLogId)).Returns(testZipFileName); + mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(true); mockLogFileService.Setup(x => x.CopyLogUploadingFileToPublicPath(testZipFileName)).Returns(true); var unitUnderTest = CreateViewModel(); @@ -214,8 +214,8 @@ public void OnClickSendLogCommandTests_DeleteLogFalure() mockLogFileService.Setup(x => x.CreateLogId()).Returns(testLogId); var testZipFileName = "test-zip-file-name"; - mockLogFileService.Setup(x => x.LogUploadingFileName(testLogId)).Returns(testZipFileName); - mockLogFileService.Setup(x => x.CreateLogUploadingFileToTmpPath(testZipFileName)).Returns(true); + mockLogFileService.Setup(x => x.CreateZipFileName(testLogId)).Returns(testZipFileName); + mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(true); mockLogFileService.Setup(x => x.CopyLogUploadingFileToPublicPath(testZipFileName)).Returns(true); mockLogFileService.Setup(x => x.DeleteAllLogUploadingFiles()).Returns(false); From 251b20acbd91b22934365a7ce698031f2e562f5f Mon Sep 17 00:00:00 2001 From: ARIYAMA Keiji Date: Sat, 15 Jan 2022 18:21:43 +0900 Subject: [PATCH 03/53] Fix tests. --- .../Services/Logs/LogFileService.cs | 4 +- .../Services/Logs/LogFileServiceTests.cs | 36 +++++++------ .../HelpPage/InqueryPageViewModelTests.cs | 24 ++++++++- .../SendLogConfirmationPageViewModelTests.cs | 54 ++++++++++--------- 4 files changed, 71 insertions(+), 47 deletions(-) diff --git a/Covid19Radar/Covid19Radar/Services/Logs/LogFileService.cs b/Covid19Radar/Covid19Radar/Services/Logs/LogFileService.cs index 7dd702ca8..b8bcede72 100644 --- a/Covid19Radar/Covid19Radar/Services/Logs/LogFileService.cs +++ b/Covid19Radar/Covid19Radar/Services/Logs/LogFileService.cs @@ -67,9 +67,9 @@ public string CreateZipFile(string fileName) return zipFilePath; } - catch (Exception) + catch (Exception exception) { - loggerService.Error("Failed to create uploading file"); + loggerService.Exception("Failed to create uploading file", exception); return null; } finally diff --git a/Covid19Radar/Tests/Covid19Radar.UnitTests/Services/Logs/LogFileServiceTests.cs b/Covid19Radar/Tests/Covid19Radar.UnitTests/Services/Logs/LogFileServiceTests.cs index 9eb253a12..fd3428d4f 100644 --- a/Covid19Radar/Tests/Covid19Radar.UnitTests/Services/Logs/LogFileServiceTests.cs +++ b/Covid19Radar/Tests/Covid19Radar.UnitTests/Services/Logs/LogFileServiceTests.cs @@ -52,7 +52,7 @@ public void CreateLogUploadingFileToTmpPath_Success() var logId = logFileService.CreateLogId(); var fileName = logFileService.CreateZipFileName(logId); var result = logFileService.CreateZipFile(fileName); - Assert.True(result); + Assert.Equal(Path.Combine(tmpDirPath, fileName), result); var uploadingFilePath = tmpDirPath + fileName; Assert.True(File.Exists(uploadingFilePath)); @@ -70,7 +70,7 @@ public void CreateLogUploadingFileToTmpPath_Log_Not_Exists() var logId = logFileService.CreateLogId(); var fileName = logFileService.CreateZipFileName(logId); var result = logFileService.CreateZipFile(fileName); - Assert.False(result); + Assert.Null(result); var uploadingFilePath = tmpDirPath + fileName; Assert.False(File.Exists(uploadingFilePath)); @@ -88,7 +88,7 @@ public void CreateLogUploadingFileToTmpPath_LogDir_Not_Exists() var logId = logFileService.CreateLogId(); var fileName = logFileService.CreateZipFileName(logId); var result = logFileService.CreateZipFile(fileName); - Assert.False(result); + Assert.Null(result); var uploadingFilePath = tmpDirPath + fileName; Assert.False(File.Exists(uploadingFilePath)); @@ -108,9 +108,10 @@ public void CopyLogUploadingFileToPublicPath_Success() var logId = logFileService.CreateLogId(); var fileName = logFileService.CreateZipFileName(logId); var result = logFileService.CreateZipFile(fileName); - Assert.True(result); - result = logFileService.CopyLogUploadingFileToPublicPath(fileName); - Assert.True(result); + Assert.Equal(Path.Combine(tmpDirPath, fileName), result); + + result = logFileService.CopyLogUploadingFileToPublicPath(Path.Combine(tmpDirPath, fileName)); + Assert.Equal(Path.Combine(publicDirPath, fileName), result); var uploadingFilePath = publicDirPath + fileName; Assert.True(File.Exists(uploadingFilePath)); @@ -130,9 +131,10 @@ public void CopyLogUploadingFileToPublicPath_PublicDir_Not_Exists() var logId = logFileService.CreateLogId(); var fileName = logFileService.CreateZipFileName(logId); var result = logFileService.CreateZipFile(fileName); - Assert.True(result); - result = logFileService.CopyLogUploadingFileToPublicPath(fileName); - Assert.False(result); + Assert.Equal(result, Path.Combine(tmpDirPath, fileName)); + + result = logFileService.CopyLogUploadingFileToPublicPath(Path.Combine(tmpDirPath, fileName)); + Assert.Null(result); var uploadingFilePath = publicDirPath + fileName; Assert.False(File.Exists(uploadingFilePath)); @@ -147,7 +149,7 @@ public void CopyLogUploadingFileToPublicPath_TmpPath_Empty() var logId = logFileService.CreateLogId(); var fileName = logFileService.CreateZipFileName(logId); var result = logFileService.CopyLogUploadingFileToPublicPath(fileName); - Assert.False(result); + Assert.Null(result); var uploadingFilePath = publicDirPath + fileName; Assert.False(File.Exists(uploadingFilePath)); @@ -162,7 +164,7 @@ public void CopyLogUploadingFileToPublicPath_PublicPath_Empty() var logId = logFileService.CreateLogId(); var fileName = logFileService.CreateZipFileName(logId); var result = logFileService.CopyLogUploadingFileToPublicPath(fileName); - Assert.False(result); + Assert.Null(result); var uploadingFilePath = publicDirPath + fileName; Assert.False(File.Exists(uploadingFilePath)); @@ -181,10 +183,10 @@ public void DeleteAllLogUploadingFiles_Success() var logId = logFileService.CreateLogId(); var fileName = logFileService.CreateZipFileName(logId); var result = logFileService.CreateZipFile(fileName); - Assert.True(result); + Assert.Equal(Path.Combine(tmpDirPath, fileName), result); - result = logFileService.DeleteAllLogUploadingFiles(); - Assert.True(result); + bool deleteResult = logFileService.DeleteAllLogUploadingFiles(); + Assert.True(deleteResult); var uploadingFilePath = tmpDirPath + fileName; Assert.False(File.Exists(uploadingFilePath)); @@ -213,12 +215,12 @@ public void DeleteAllLogUploadingFiles_TmpDir_Not_Exists() var logId = logFileService.CreateLogId(); var fileName = logFileService.CreateZipFileName(logId); var result = logFileService.CreateZipFile(fileName); - Assert.True(result); + Assert.Equal(Path.Combine(tmpDirPath, fileName), result); DeleteDirIfExists(tmpDirPath); - result = logFileService.DeleteAllLogUploadingFiles(); - Assert.False(result); + bool deleteResult = logFileService.DeleteAllLogUploadingFiles(); + Assert.False(deleteResult); } [Fact] diff --git a/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/InqueryPageViewModelTests.cs b/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/InqueryPageViewModelTests.cs index b95cf2ebe..73122ca18 100644 --- a/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/InqueryPageViewModelTests.cs +++ b/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/InqueryPageViewModelTests.cs @@ -4,6 +4,8 @@ using System; using System.Threading.Tasks; +using Acr.UserDialogs; +using Covid19Radar.Services; using Covid19Radar.Services.Logs; using Covid19Radar.ViewModels; using Moq; @@ -18,6 +20,11 @@ public class InqueryPageViewModelTests private readonly MockRepository mockRepository; private readonly Mock mockNavigationService; private readonly Mock mockLoggerService; + private readonly Mock mockLogFileService; + private readonly Mock mockLogPathService; + private readonly Mock mockEssentialService; + + private readonly Mock mockUserDialogs; public InqueryPageViewModelTests() @@ -25,13 +32,23 @@ public InqueryPageViewModelTests() mockRepository = new MockRepository(MockBehavior.Default); mockNavigationService = mockRepository.Create(); mockLoggerService = mockRepository.Create(); + mockLogFileService = mockRepository.Create(); + mockLogPathService = mockRepository.Create(); + mockEssentialService = mockRepository.Create(); + + mockUserDialogs = mockRepository.Create(); + UserDialogs.Instance = mockUserDialogs.Object; } private InqueryPageViewModel CreateViewModel() { var vm = new InqueryPageViewModel( mockNavigationService.Object, - mockLoggerService.Object); + mockLoggerService.Object, + mockLogFileService.Object, + mockLogPathService.Object, + mockEssentialService.Object + ); return vm; } @@ -62,12 +79,15 @@ public void OnClickQuestionCommandTests() [Fact] public void OnClickSendLogCommandTests() { + mockLogFileService.Setup(x => x.CreateZipFile(It.IsAny())) + .Returns("dummyFile"); + var unitUnderTest = CreateViewModel(); unitUnderTest.Initialize(new NavigationParameters()); unitUnderTest.OnClickSendLogCommand.Execute(null); - mockNavigationService.Verify(x => x.NavigateAsync("SendLogConfirmationPage"), Times.Once()); + mockNavigationService.Verify(x => x.NavigateAsync("SendLogConfirmationPage", It.IsAny()), Times.Once()); } [Fact] diff --git a/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/SendLogConfirmationPageViewModelTests.cs b/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/SendLogConfirmationPageViewModelTests.cs index b5cc03922..2021683b6 100644 --- a/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/SendLogConfirmationPageViewModelTests.cs +++ b/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/SendLogConfirmationPageViewModelTests.cs @@ -2,9 +2,6 @@ * 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.IO; -using System.Threading.Tasks; using Acr.UserDialogs; using Covid19Radar.Services.Logs; using Covid19Radar.ViewModels; @@ -23,7 +20,6 @@ public class SendLogConfirmationPageViewModelTests private readonly Mock mockLogFileService; private readonly Mock mockLoggerService; private readonly Mock mockLogUploadService; - private readonly Mock mockLogPathService; public SendLogConfirmationPageViewModelTests() { @@ -36,21 +32,17 @@ public SendLogConfirmationPageViewModelTests() mockLogFileService = mockRepository.Create(); mockLoggerService = mockRepository.Create(); mockLogUploadService = mockRepository.Create(); - mockLogPathService = mockRepository.Create(); } private SendLogConfirmationPageViewModel CreateViewModel() { var vm = new SendLogConfirmationPageViewModel( mockNavigationService.Object, - mockLogFileService.Object, mockLoggerService.Object, - mockLogUploadService.Object, - mockLogPathService.Object) - { - BeginInvokeOnMainThread = new Action((a) => { a.Invoke(); }), - TaskRun = new Func((a) => { a.Invoke(); return Task.CompletedTask; }) - }; + mockLogFileService.Object, + mockLogUploadService.Object + ); + return vm; } @@ -62,7 +54,8 @@ public void InitializeTests_CreateZipSuccess() var testZipFileName = "test-zip-file-name"; mockLogFileService.Setup(x => x.CreateZipFileName(testLogId)).Returns(testZipFileName); - mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(true); + var testPublicZipFileName = "test-public-zip-file-name"; + mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(testPublicZipFileName); var unitUnderTest = CreateViewModel(); unitUnderTest.Initialize(new NavigationParameters()); @@ -86,7 +79,8 @@ public void InitializeTests_CreateZipFailure() var testZipFileName = "test-zip-file-name"; mockLogFileService.Setup(x => x.CreateZipFileName(testLogId)).Returns(testZipFileName); - mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(false); + var testPublicZipFileName = "test-public-zip-file-name"; + mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(testPublicZipFileName); var unitUnderTest = CreateViewModel(); unitUnderTest.Initialize(new NavigationParameters()); @@ -110,10 +104,10 @@ public void OnClickConfirmLogCommandTests_Success() var testZipFileName = "test-zip-file-name"; mockLogFileService.Setup(x => x.CreateZipFileName(testLogId)).Returns(testZipFileName); - mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(true); - mockLogFileService.Setup(x => x.CopyLogUploadingFileToPublicPath(testZipFileName)).Returns(true); - - mockLogPathService.Setup(x => x.LogUploadingPublicPath).Returns("dummy_log_uploading_public_path"); + var testPublicZipFileName = "test-public-zip-file-name"; + mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(testPublicZipFileName); + var testPublicZipFilePath = "test-public-zip-file-path"; + mockLogFileService.Setup(x => x.CopyLogUploadingFileToPublicPath(testZipFileName)).Returns(testPublicZipFilePath); var unitUnderTest = CreateViewModel(); unitUnderTest.Initialize(new NavigationParameters()); @@ -133,8 +127,10 @@ public void OnClickConfirmLogCommandTests_Failure() var testZipFileName = "test-zip-file-name"; mockLogFileService.Setup(x => x.CreateZipFileName(testLogId)).Returns(testZipFileName); - mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(true); - mockLogFileService.Setup(x => x.CopyLogUploadingFileToPublicPath(testZipFileName)).Returns(false); + var testPublicZipFileName = "test-public-zip-file-name"; + mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(testPublicZipFileName); + var testPublicZipFilePath = "test-public-zip-file-path"; + mockLogFileService.Setup(x => x.CopyLogUploadingFileToPublicPath(testZipFileName)).Returns(testPublicZipFilePath); var unitUnderTest = CreateViewModel(); unitUnderTest.Initialize(new NavigationParameters()); @@ -155,8 +151,10 @@ public void OnClickSendLogCommandTests_Success() var testZipFileName = "test-zip-file-name"; mockLogFileService.Setup(x => x.CreateZipFileName(testLogId)).Returns(testZipFileName); - mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(true); - mockLogFileService.Setup(x => x.CopyLogUploadingFileToPublicPath(testZipFileName)).Returns(true); + var testPublicZipFileName = "test-public-zip-file-name"; + mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(testPublicZipFileName); + var testPublicZipFilePath = "test-public-zip-file-path"; + mockLogFileService.Setup(x => x.CopyLogUploadingFileToPublicPath(testZipFileName)).Returns(testPublicZipFilePath); mockLogFileService.Setup(x => x.DeleteAllLogUploadingFiles()).Returns(true); var unitUnderTest = CreateViewModel(); @@ -186,8 +184,10 @@ public void OnClickSendLogCommandTests_Failure() var testZipFileName = "test-zip-file-name"; mockLogFileService.Setup(x => x.CreateZipFileName(testLogId)).Returns(testZipFileName); - mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(true); - mockLogFileService.Setup(x => x.CopyLogUploadingFileToPublicPath(testZipFileName)).Returns(true); + var testPublicZipFileName = "test-public-zip-file-name"; + mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(testPublicZipFileName); + var testPublicZipFilePath = "test-public-zip-file-path"; + mockLogFileService.Setup(x => x.CopyLogUploadingFileToPublicPath(testZipFileName)).Returns(testPublicZipFilePath); var unitUnderTest = CreateViewModel(); unitUnderTest.Initialize(new NavigationParameters()); @@ -215,8 +215,10 @@ public void OnClickSendLogCommandTests_DeleteLogFalure() var testZipFileName = "test-zip-file-name"; mockLogFileService.Setup(x => x.CreateZipFileName(testLogId)).Returns(testZipFileName); - mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(true); - mockLogFileService.Setup(x => x.CopyLogUploadingFileToPublicPath(testZipFileName)).Returns(true); + var testPublicZipFileName = "test-public-zip-file-name"; + mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(testPublicZipFileName); + var testPublicZipFilePath = "test-public-zip-file-path"; + mockLogFileService.Setup(x => x.CopyLogUploadingFileToPublicPath(testZipFileName)).Returns(testPublicZipFilePath); mockLogFileService.Setup(x => x.DeleteAllLogUploadingFiles()).Returns(false); var unitUnderTest = CreateViewModel(); From 1e8913c623baeb0983df176871adf4f07cfd5d11 Mon Sep 17 00:00:00 2001 From: ARIYAMA Keiji Date: Wed, 5 Jan 2022 02:38:39 +0900 Subject: [PATCH 04/53] Connect to V2DiagnosisApi. --- .../Services/DeviceCheckService.cs | 2 +- Covid19Radar/Covid19Radar/Common/AppConstants.cs | 4 ++-- .../Covid19Radar/Model/DiagnosisSubmissionParameter.cs | 10 +++++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Covid19Radar/Covid19Radar.Android/Services/DeviceCheckService.cs b/Covid19Radar/Covid19Radar.Android/Services/DeviceCheckService.cs index fccc76eec..70dade75e 100644 --- a/Covid19Radar/Covid19Radar.Android/Services/DeviceCheckService.cs +++ b/Covid19Radar/Covid19Radar.Android/Services/DeviceCheckService.cs @@ -14,7 +14,7 @@ public class DeviceCheckService : IDeviceVerifier { public Task VerifyAsync(DiagnosisSubmissionParameter submission) { - var nonce = DeviceVerifierUtils.CreateAndroidNonceV3(submission); + var nonce = DeviceVerifierUtils.CreateAndroidNonceV2(submission); return GetSafetyNetAttestationAsync(nonce); } diff --git a/Covid19Radar/Covid19Radar/Common/AppConstants.cs b/Covid19Radar/Covid19Radar/Common/AppConstants.cs index 6cc81e6ce..fa9e886b5 100644 --- a/Covid19Radar/Covid19Radar/Common/AppConstants.cs +++ b/Covid19Radar/Covid19Radar/Common/AppConstants.cs @@ -14,7 +14,7 @@ public static class AppConstants /// /// Number of days covered from the date of diagnosis or onset /// - public const int DaysToSendTek = -15; + public const int DaysToSendTek = -3; /// /// Max Error Count @@ -47,7 +47,7 @@ public static class AppConstants /// DiagnosisApi version. /// (e.g. v2, v3) /// - public const string DiagnosisApiVersionCode = "v3"; + public const string DiagnosisApiVersionCode = "v2"; /// /// Number of day(s) that ExposureConfiguration file downloaded cache. diff --git a/Covid19Radar/Covid19Radar/Model/DiagnosisSubmissionParameter.cs b/Covid19Radar/Covid19Radar/Model/DiagnosisSubmissionParameter.cs index dfe54d395..7620979b0 100644 --- a/Covid19Radar/Covid19Radar/Model/DiagnosisSubmissionParameter.cs +++ b/Covid19Radar/Covid19Radar/Model/DiagnosisSubmissionParameter.cs @@ -8,7 +8,8 @@ namespace Covid19Radar.Model { public class DiagnosisSubmissionParameter { - [JsonProperty("symptomOnsetDate")] + //[JsonProperty("symptomOnsetDate")] + [JsonIgnore] public string SymptomOnsetDate { get; set; } [JsonProperty("keys")] @@ -25,7 +26,8 @@ public class DiagnosisSubmissionParameter [JsonProperty("verificationPayload")] public string VerificationPayload { get; set; } - [JsonProperty("idempotency_key")] + //[JsonProperty("idempotency_key")] + [JsonIgnore] public string IdempotencyKey { get; set; } // Random data to obscure the size of the request network packet sniffers. @@ -40,7 +42,9 @@ public class Key public uint RollingStartNumber { get; set; } [JsonProperty("rollingPeriod")] public uint RollingPeriod { get; set; } - [JsonProperty("reportType")] + + //[JsonProperty("reportType")] + [JsonIgnore] public uint ReportType { get; set; } } } From 7756c990963638f1828dd88af0be4311533e4946 Mon Sep 17 00:00:00 2001 From: ARIYAMA Keiji Date: Sun, 9 Jan 2022 02:14:34 +0900 Subject: [PATCH 05/53] Improve Open Source Software section. --- .../Properties/AndroidManifest.xml | 8 +++ .../Resources/AppResources.Designer.cs | 30 +++++++++ .../Resources/AppResources.ja.resx | 20 ++++++ .../Covid19Radar/Resources/AppResources.resx | 20 ++++++ .../Settings/SettingsPageViewModel.cs | 9 +++ .../Views/Settings/SettingsPage.xaml | 65 +++++++++++++++---- 6 files changed, 141 insertions(+), 11 deletions(-) diff --git a/Covid19Radar/Covid19Radar.Android/Properties/AndroidManifest.xml b/Covid19Radar/Covid19Radar.Android/Properties/AndroidManifest.xml index 4ba105ac0..0c7389e44 100644 --- a/Covid19Radar/Covid19Radar.Android/Properties/AndroidManifest.xml +++ b/Covid19Radar/Covid19Radar.Android/Properties/AndroidManifest.xml @@ -29,5 +29,13 @@ + + + + + diff --git a/Covid19Radar/Covid19Radar/Resources/AppResources.Designer.cs b/Covid19Radar/Covid19Radar/Resources/AppResources.Designer.cs index eb2ce7f1c..b6931de86 100644 --- a/Covid19Radar/Covid19Radar/Resources/AppResources.Designer.cs +++ b/Covid19Radar/Covid19Radar/Resources/AppResources.Designer.cs @@ -1822,5 +1822,35 @@ public static string ExposurePageExposureDuration { return ResourceManager.GetString("ExposurePageExposureDuration", resourceCulture); } } + + public static string OpenSourceLicense { + get { + return ResourceManager.GetString("OpenSourceLicense", resourceCulture); + } + } + + public static string OpenSourceLicense_Description1 { + get { + return ResourceManager.GetString("OpenSourceLicense_Description1", resourceCulture); + } + } + + public static string OpenSourceLicense_Description2 { + get { + return ResourceManager.GetString("OpenSourceLicense_Description2", resourceCulture); + } + } + + public static string UrlGitHubRepository { + get { + return ResourceManager.GetString("UrlGitHubRepository", resourceCulture); + } + } + + public static string OpenSourceLicense_GetSourceCode { + get { + return ResourceManager.GetString("OpenSourceLicense_GetSourceCode", resourceCulture); + } + } } } diff --git a/Covid19Radar/Covid19Radar/Resources/AppResources.ja.resx b/Covid19Radar/Covid19Radar/Resources/AppResources.ja.resx index d63bb05c8..72c8f5366 100644 --- a/Covid19Radar/Covid19Radar/Resources/AppResources.ja.resx +++ b/Covid19Radar/Covid19Radar/Resources/AppResources.ja.resx @@ -1184,4 +1184,24 @@ {0:#}分間の接触 {0:#}分間の接触 + + オープンソースライセンス + オープンソースライセンス + + + COCOAはオープンソースソフトウェアです。Mozilla Public License 2.0 の条項下で提供されています。 + COCOAはオープンソースソフトウェアです。Mozilla Public License 2.0 の条項下で提供されています。 + + + COCOAのソースコードは次のURLから入手できます。 + COCOAのソースコードは次のURLから入手できます。 + + + https://github.com/cocoa-mhlw/cocoa/ + https://github.com/cocoa-mhlw/cocoa/ + + + ソースコードを入手 + ソースコードを入手 + diff --git a/Covid19Radar/Covid19Radar/Resources/AppResources.resx b/Covid19Radar/Covid19Radar/Resources/AppResources.resx index afda4e6aa..bbaf2d97c 100644 --- a/Covid19Radar/Covid19Radar/Resources/AppResources.resx +++ b/Covid19Radar/Covid19Radar/Resources/AppResources.resx @@ -1294,4 +1294,24 @@ Note: this app does not collect users’ location information. {0:#} min exposure {0:#}分間の接触 + + Open Source License + オープンソースライセンス + + + COCOA is open source software, made available to you under the Mozilla Public License 2.0 (MPL). + COCOAはオープンソースソフトウェアです。Mozilla Public License 2.0 の条項下で提供されています。 + + + The source code can download from the following URL. + COCOAのソースコードは次のURLから入手できます。 + + + https://github.com/cocoa-mhlw/cocoa/ + https://github.com/cocoa-mhlw/cocoa/ + + + Get source code + ソースコードを入手 + diff --git a/Covid19Radar/Covid19Radar/ViewModels/Settings/SettingsPageViewModel.cs b/Covid19Radar/Covid19Radar/ViewModels/Settings/SettingsPageViewModel.cs index 08be8ec64..ffca93913 100644 --- a/Covid19Radar/Covid19Radar/ViewModels/Settings/SettingsPageViewModel.cs +++ b/Covid19Radar/Covid19Radar/ViewModels/Settings/SettingsPageViewModel.cs @@ -2,6 +2,7 @@ * 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 System.Windows.Input; using Acr.UserDialogs; @@ -56,6 +57,14 @@ ICloseApplicationService closeApplicationService this.closeApplicationService = closeApplicationService; } + public Func BrowserOpenAsync = Browser.OpenAsync; + + public ICommand OpenGitHub => new Command(async () => + { + var url = AppResources.UrlGitHubRepository; + await BrowserOpenAsync(url, BrowserLaunchMode.External); + }); + public ICommand OnChangeResetData => new Command(async () => { loggerService.StartMethod(); diff --git a/Covid19Radar/Covid19Radar/Views/Settings/SettingsPage.xaml b/Covid19Radar/Covid19Radar/Views/Settings/SettingsPage.xaml index 9f2916c50..1e1b2cbfa 100644 --- a/Covid19Radar/Covid19Radar/Views/Settings/SettingsPage.xaml +++ b/Covid19Radar/Covid19Radar/Views/Settings/SettingsPage.xaml @@ -26,7 +26,9 @@ Padding="0" BackgroundColor="{StaticResource Background}" Spacing="0"> + + @@ -54,36 +56,77 @@ Text="{Binding AppVer}" /> + - + + + + +