From 835a8757cef98ce84184f1767de25f17f7919c96 Mon Sep 17 00:00:00 2001 From: ARIYAMA Keiji Date: Sat, 15 Jan 2022 16:30:21 +0900 Subject: [PATCH 1/6] 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 2/6] 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 3/6] 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 be6c987579654f3806d7dcf540828eeec5f0fb5e Mon Sep 17 00:00:00 2001 From: ARIYAMA Keiji Date: Sat, 15 Jan 2022 19:22:36 +0900 Subject: [PATCH 4/6] Fix upload failed. --- Covid19Radar/Covid19Radar/Services/Logs/ILogUploadService.cs | 2 +- Covid19Radar/Covid19Radar/Services/Logs/LogUploadService.cs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Covid19Radar/Covid19Radar/Services/Logs/ILogUploadService.cs b/Covid19Radar/Covid19Radar/Services/Logs/ILogUploadService.cs index bb2010c44..e97013624 100644 --- a/Covid19Radar/Covid19Radar/Services/Logs/ILogUploadService.cs +++ b/Covid19Radar/Covid19Radar/Services/Logs/ILogUploadService.cs @@ -8,6 +8,6 @@ namespace Covid19Radar.Services.Logs { public interface ILogUploadService { - Task UploadAsync(string zipFileName); + Task UploadAsync(string zipFilePath); } } diff --git a/Covid19Radar/Covid19Radar/Services/Logs/LogUploadService.cs b/Covid19Radar/Covid19Radar/Services/Logs/LogUploadService.cs index 7400ae530..ef0df8e9b 100644 --- a/Covid19Radar/Covid19Radar/Services/Logs/LogUploadService.cs +++ b/Covid19Radar/Covid19Radar/Services/Logs/LogUploadService.cs @@ -28,7 +28,7 @@ public LogUploadService( this.storageService = storageService; } - public async Task UploadAsync(string zipFileName) + public async Task UploadAsync(string zipFilePath) { loggerService.StartMethod(); @@ -49,7 +49,6 @@ public async Task UploadAsync(string zipFileName) // Upload to storage. var logTmpPath = logPathService.LogUploadingTmpPath; - var logZipPath = Path.Combine(logTmpPath, zipFileName); var setting = AppSettings.Instance; var endpoint = setting.LogStorageEndpoint; @@ -57,7 +56,7 @@ public async Task UploadAsync(string zipFileName) var accountName = setting.LogStorageAccountName; var sasToken = logStorageSasResponse.Result.SasToken; - var uploadResult = await storageService.UploadAsync(endpoint, uploadPath, accountName, sasToken, logZipPath); + var uploadResult = await storageService.UploadAsync(endpoint, uploadPath, accountName, sasToken, zipFilePath); if (!uploadResult) { throw new Exception("Failed to upload to storage."); From 9f4894f636900dcb3bfd576224048c56ee086324 Mon Sep 17 00:00:00 2001 From: ARIYAMA Keiji Date: Sat, 15 Jan 2022 20:18:19 +0900 Subject: [PATCH 5/6] Fix tests. --- .../Services/Logs/LogUploadServiceTests.cs | 15 ++-- .../HelpPage/InqueryPageViewModelTests.cs | 51 +++++++++++++ .../SendLogConfirmationPageViewModelTests.cs | 73 ++++--------------- 3 files changed, 73 insertions(+), 66 deletions(-) diff --git a/Covid19Radar/Tests/Covid19Radar.UnitTests/Services/Logs/LogUploadServiceTests.cs b/Covid19Radar/Tests/Covid19Radar.UnitTests/Services/Logs/LogUploadServiceTests.cs index 590525b2d..f396ff885 100644 --- a/Covid19Radar/Tests/Covid19Radar.UnitTests/Services/Logs/LogUploadServiceTests.cs +++ b/Covid19Radar/Tests/Covid19Radar.UnitTests/Services/Logs/LogUploadServiceTests.cs @@ -46,17 +46,18 @@ public async void UploadAsyncTests_Success() var testZipFileName = "zip-file.zip"; var testTmpPath = Path.Combine("log", "tmp", "path"); var testSasToken = "test-sas-token"; + var testZipFilePath = Path.Combine(testTmpPath, testZipFileName); mockHttpDataService.Setup(x => x.GetLogStorageSas()).ReturnsAsync(new ApiResponse(200, new LogStorageSas { SasToken = testSasToken })); mockLogPathService.Setup(x => x.LogUploadingTmpPath).Returns(testTmpPath); - mockStorageService.Setup(x => x.UploadAsync("https://LOG_STORAGE_URL_BASE/", "LOG_STORAGE_CONTAINER_NAME", "LOG_STORAGE_ACCOUNT_NAME", testSasToken, Path.Combine(testTmpPath, testZipFileName))).ReturnsAsync(true); + mockStorageService.Setup(x => x.UploadAsync("https://LOG_STORAGE_URL_BASE/", "LOG_STORAGE_CONTAINER_NAME", "LOG_STORAGE_ACCOUNT_NAME", testSasToken, testZipFilePath)).ReturnsAsync(true); - var result = await unitUnderTest.UploadAsync(testZipFileName); + var result = await unitUnderTest.UploadAsync(testZipFilePath); Assert.True(result); mockHttpDataService.Verify(x => x.GetLogStorageSas(), Times.Once()); - mockStorageService.Verify(x => x.UploadAsync("https://LOG_STORAGE_URL_BASE/", "LOG_STORAGE_CONTAINER_NAME", "LOG_STORAGE_ACCOUNT_NAME", testSasToken, Path.Combine(testTmpPath, testZipFileName)), Times.Once()); + mockStorageService.Verify(x => x.UploadAsync("https://LOG_STORAGE_URL_BASE/", "LOG_STORAGE_CONTAINER_NAME", "LOG_STORAGE_ACCOUNT_NAME", testSasToken, testZipFilePath), Times.Once()); } [Theory] @@ -86,13 +87,14 @@ public async void UploadAsyncTests_UploadAsyncFailure() var testZipFileName = "zip-file.zip"; var testTmpPath = Path.Combine("log", "tmp", "path"); var testSasToken = "test-sas-token"; + var testZipFilePath = Path.Combine(testTmpPath, testZipFileName); mockHttpDataService.Setup(x => x.GetLogStorageSas()).ReturnsAsync(new ApiResponse(200, new LogStorageSas { SasToken = testSasToken })); mockLogPathService.Setup(x => x.LogUploadingTmpPath).Returns(testTmpPath); mockStorageService.Setup(x => x.UploadAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(false); - var result = await unitUnderTest.UploadAsync(testZipFileName); + var result = await unitUnderTest.UploadAsync(testZipFilePath); Assert.False(result); mockHttpDataService.Verify(x => x.GetLogStorageSas(), Times.Once()); @@ -107,11 +109,12 @@ public async void UploadAsyncTests_UnexpectedError() var testZipFileName = "zip-file.zip"; var testTmpPath = Path.Combine("log", "tmp", "path"); var testSasToken = "test-sas-token"; + var testZipFilePath = Path.Combine(testTmpPath, testZipFileName); mockHttpDataService.Setup(x => x.GetLogStorageSas()).ReturnsAsync(new ApiResponse(200, new LogStorageSas { SasToken = testSasToken })); - mockStorageService.Setup(x => x.UploadAsync("https://LOG_STORAGE_URL_BASE/", "LOG_STORAGE_CONTAINER_NAME", "LOG_STORAGE_ACCOUNT_NAME", testSasToken, Path.Combine(testTmpPath, testZipFileName))).ReturnsAsync(false); + mockStorageService.Setup(x => x.UploadAsync("https://LOG_STORAGE_URL_BASE/", "LOG_STORAGE_CONTAINER_NAME", "LOG_STORAGE_ACCOUNT_NAME", testSasToken, testZipFilePath)).ReturnsAsync(false); - var result = await unitUnderTest.UploadAsync(testZipFileName); + var result = await unitUnderTest.UploadAsync(testZipFilePath); Assert.False(result); } diff --git a/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/InqueryPageViewModelTests.cs b/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/InqueryPageViewModelTests.cs index 73122ca18..89c745d5e 100644 --- a/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/InqueryPageViewModelTests.cs +++ b/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/InqueryPageViewModelTests.cs @@ -90,6 +90,57 @@ public void OnClickSendLogCommandTests() mockNavigationService.Verify(x => x.NavigateAsync("SendLogConfirmationPage", It.IsAny()), Times.Once()); } + [Fact] + public void OnClickSendLogCommand_CreateZipSuccess() + { + var testLogId = "test-log-id"; + mockLogFileService.Setup(x => x.CreateLogId()).Returns(testLogId); + + var testZipFileName = "test-zip-file-name"; + mockLogFileService.Setup(x => x.CreateZipFileName(testLogId)).Returns(testZipFileName); + var testPublicZipFileName = "test-public-zip-file-name"; + mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(testPublicZipFileName); + + var unitUnderTest = CreateViewModel(); + unitUnderTest.Initialize(new NavigationParameters()); + + unitUnderTest.OnClickSendLogCommand.Execute(null); + + mockLogFileService.Verify(x => x.CreateLogId(), 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()); + mockUserDialogs.Verify(x => x.AlertAsync(It.IsAny(), It.IsAny(), It.IsAny(), null), Times.Never()); + + mockNavigationService.Verify(x => x.NavigateAsync(It.IsAny()), Times.Never()); + } + + [Fact] + public void OnClickSendLogCommand_CreateZipFailure() + { + var testLogId = "test-log-id"; + mockLogFileService.Setup(x => x.CreateLogId()).Returns(testLogId); + + var testZipFileName = "test-zip-file-name"; + mockLogFileService.Setup(x => x.CreateZipFileName(testLogId)).Returns(testZipFileName); + mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(null); + + var unitUnderTest = CreateViewModel(); + unitUnderTest.Initialize(new NavigationParameters()); + + unitUnderTest.OnClickSendLogCommand.Execute(null); + + mockLogFileService.Verify(x => x.CreateLogId(), 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()); + mockUserDialogs.Verify(x => x.AlertAsync(It.IsAny(), It.IsAny(), "OK", null), Times.Once()); + } + [Fact] public void OnClickEmailCommandTests_Success() { diff --git a/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/SendLogConfirmationPageViewModelTests.cs b/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/SendLogConfirmationPageViewModelTests.cs index 2021683b6..f06cb0973 100644 --- a/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/SendLogConfirmationPageViewModelTests.cs +++ b/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/SendLogConfirmationPageViewModelTests.cs @@ -5,6 +5,7 @@ using Acr.UserDialogs; using Covid19Radar.Services.Logs; using Covid19Radar.ViewModels; +using Covid19Radar.Views; using Moq; using Prism.Navigation; using Xamarin.Forms; @@ -46,56 +47,6 @@ private SendLogConfirmationPageViewModel CreateViewModel() return vm; } - [Fact] - public void InitializeTests_CreateZipSuccess() - { - var testLogId = "test-log-id"; - mockLogFileService.Setup(x => x.CreateLogId()).Returns(testLogId); - - var testZipFileName = "test-zip-file-name"; - mockLogFileService.Setup(x => x.CreateZipFileName(testLogId)).Returns(testZipFileName); - var testPublicZipFileName = "test-public-zip-file-name"; - mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(testPublicZipFileName); - - var unitUnderTest = CreateViewModel(); - unitUnderTest.Initialize(new NavigationParameters()); - - mockLogFileService.Verify(x => x.CreateLogId(), 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()); - mockUserDialogs.Verify(x => x.AlertAsync(It.IsAny(), It.IsAny(), It.IsAny(), null), Times.Never()); - - mockNavigationService.Verify(x => x.NavigateAsync(It.IsAny()), Times.Never()); - } - - [Fact] - public void InitializeTests_CreateZipFailure() - { - var testLogId = "test-log-id"; - mockLogFileService.Setup(x => x.CreateLogId()).Returns(testLogId); - - var testZipFileName = "test-zip-file-name"; - mockLogFileService.Setup(x => x.CreateZipFileName(testLogId)).Returns(testZipFileName); - var testPublicZipFileName = "test-public-zip-file-name"; - mockLogFileService.Setup(x => x.CreateZipFile(testZipFileName)).Returns(testPublicZipFileName); - - var unitUnderTest = CreateViewModel(); - unitUnderTest.Initialize(new NavigationParameters()); - - mockLogFileService.Verify(x => x.CreateLogId(), 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()); - mockUserDialogs.Verify(x => x.AlertAsync(It.IsAny(), It.IsAny(), "OK", null), Times.Once()); - - mockNavigationService.Verify(x => x.GoBackAsync(), Times.Once()); - } - [Fact] public void OnClickConfirmLogCommandTests_Success() { @@ -110,7 +61,7 @@ public void OnClickConfirmLogCommandTests_Success() mockLogFileService.Setup(x => x.CopyLogUploadingFileToPublicPath(testZipFileName)).Returns(testPublicZipFilePath); var unitUnderTest = CreateViewModel(); - unitUnderTest.Initialize(new NavigationParameters()); + unitUnderTest.Initialize(SendLogConfirmationPage.BuildNavigationParams(testLogId, testPublicZipFilePath)); mockUserDialogs.Invocations.Clear(); mockLogFileService.Invocations.Clear(); @@ -158,19 +109,19 @@ public void OnClickSendLogCommandTests_Success() mockLogFileService.Setup(x => x.DeleteAllLogUploadingFiles()).Returns(true); var unitUnderTest = CreateViewModel(); - unitUnderTest.Initialize(new NavigationParameters()); + unitUnderTest.Initialize(SendLogConfirmationPage.BuildNavigationParams(testLogId, testPublicZipFilePath)); mockUserDialogs.Invocations.Clear(); mockLogFileService.Invocations.Clear(); - mockLogUploadService.Setup(x => x.UploadAsync(testZipFileName)).ReturnsAsync(true); + mockLogUploadService.Setup(x => x.UploadAsync(testPublicZipFilePath)).ReturnsAsync(true); unitUnderTest.OnClickSendLogCommand.Execute(null); mockUserDialogs.Verify(x => x.ShowLoading(It.IsAny(), null), Times.Once()); mockUserDialogs.Verify(x => x.HideLoading(), Times.Once()); mockUserDialogs.Verify(x => x.AlertAsync(It.IsAny(), It.IsAny(), It.IsAny(), null), Times.Never()); - mockLogUploadService.Verify(x => x.UploadAsync(testZipFileName), Times.Once()); + mockLogUploadService.Verify(x => x.UploadAsync(testPublicZipFilePath), Times.Once()); mockLogFileService.Verify(x => x.DeleteAllLogUploadingFiles(), Times.Once()); var expectedParameters = new NavigationParameters { { "logId", testLogId } }; mockNavigationService.Verify(x => x.NavigateAsync("SendLogCompletePage?useModalNavigation=true/", expectedParameters), Times.Once()); @@ -190,19 +141,19 @@ public void OnClickSendLogCommandTests_Failure() mockLogFileService.Setup(x => x.CopyLogUploadingFileToPublicPath(testZipFileName)).Returns(testPublicZipFilePath); var unitUnderTest = CreateViewModel(); - unitUnderTest.Initialize(new NavigationParameters()); + unitUnderTest.Initialize(SendLogConfirmationPage.BuildNavigationParams(testLogId, testPublicZipFileName)); mockUserDialogs.Invocations.Clear(); mockLogFileService.Invocations.Clear(); - mockLogUploadService.Setup(x => x.UploadAsync(testZipFileName)).ReturnsAsync(false); + mockLogUploadService.Setup(x => x.UploadAsync(testPublicZipFileName)).ReturnsAsync(false); unitUnderTest.OnClickSendLogCommand.Execute(null); mockUserDialogs.Verify(x => x.ShowLoading(It.IsAny(), null), Times.Once()); mockUserDialogs.Verify(x => x.HideLoading(), Times.Once()); mockUserDialogs.Verify(x => x.AlertAsync(It.IsAny(), It.IsAny(), "OK", null), Times.Once()); - mockLogUploadService.Verify(x => x.UploadAsync(testZipFileName), Times.Once()); + mockLogUploadService.Verify(x => x.UploadAsync(testPublicZipFileName), Times.Once()); mockLogFileService.Verify(x => x.DeleteAllLogUploadingFiles(), Times.Never()); mockNavigationService.Verify(x => x.NavigateAsync(It.IsAny(), It.IsAny()), Times.Never()); } @@ -222,19 +173,21 @@ public void OnClickSendLogCommandTests_DeleteLogFalure() mockLogFileService.Setup(x => x.DeleteAllLogUploadingFiles()).Returns(false); var unitUnderTest = CreateViewModel(); - unitUnderTest.Initialize(new NavigationParameters()); + unitUnderTest.Initialize( + SendLogConfirmationPage.BuildNavigationParams(testLogId, testPublicZipFilePath) + ); mockUserDialogs.Invocations.Clear(); mockLogFileService.Invocations.Clear(); - mockLogUploadService.Setup(x => x.UploadAsync(testZipFileName)).ReturnsAsync(true); + mockLogUploadService.Setup(x => x.UploadAsync(testPublicZipFilePath)).ReturnsAsync(true); unitUnderTest.OnClickSendLogCommand.Execute(null); mockUserDialogs.Verify(x => x.ShowLoading(It.IsAny(), null), Times.Once()); mockUserDialogs.Verify(x => x.HideLoading(), Times.Once()); mockUserDialogs.Verify(x => x.AlertAsync(It.IsAny(), It.IsAny(), It.IsAny(), null), Times.Never()); - mockLogUploadService.Verify(x => x.UploadAsync(testZipFileName), Times.Once()); + mockLogUploadService.Verify(x => x.UploadAsync(testPublicZipFilePath), Times.Once()); mockLogFileService.Verify(x => x.DeleteAllLogUploadingFiles(), Times.Once()); var expectedParameters = new NavigationParameters { { "logId", testLogId } }; mockNavigationService.Verify(x => x.NavigateAsync("SendLogCompletePage?useModalNavigation=true/", expectedParameters), Times.Once()); From 3e03ccb01a36bcba85445a1d7d14b303c57a2645 Mon Sep 17 00:00:00 2001 From: ARIYAMA Keiji Date: Tue, 1 Mar 2022 12:07:44 +0900 Subject: [PATCH 6/6] Fix test. --- .../HelpPage/SendLogConfirmationPageViewModelTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/SendLogConfirmationPageViewModelTests.cs b/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/SendLogConfirmationPageViewModelTests.cs index c1a5e2c75..c4ed0e1fe 100644 --- a/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/SendLogConfirmationPageViewModelTests.cs +++ b/Covid19Radar/Tests/Covid19Radar.UnitTests/ViewModels/HelpPage/SendLogConfirmationPageViewModelTests.cs @@ -152,7 +152,7 @@ public void OnClickSendLogCommandTests_Failure() mockLogFileService.Setup(x => x.CopyLogUploadingFileToPublicPath(testZipFileName)).Returns(testPublicZipFilePath); var unitUnderTest = CreateViewModel(); - unitUnderTest.Initialize(SendLogConfirmationPage.BuildNavigationParams(testLogId, testPublicZipFileName)); + unitUnderTest.Initialize(SendLogConfirmationPage.BuildNavigationParams(testLogId, testPublicZipFilePath)); mockUserDialogs.Invocations.Clear(); mockLogFileService.Invocations.Clear();