/// <summary> /// Process the textfiles /// </summary> private async void ProcessFiles() { var validationResult = await Validate(); if (!validationResult) { return; } var status = await textfileProcessingService.ProcessFiles(SourcePath, DestinationPath, DestinationType); if (status == TextfileProcessingStatus.NoFiles) { _ = await IDialogCoordinator.ShowMessageAsync(this, "Error", "The source folder does not contain text files. Please reselect and try again"); return; } else if (status == TextfileProcessingStatus.Done) { _ = await IDialogCoordinator.ShowMessageAsync(this, "Success", "All the text files have been processed successfully"); return; } else if (status == TextfileProcessingStatus.PartialSuccess) { _ = await IDialogCoordinator.ShowMessageAsync(this, "Partial Success", "The text files were processed with some issue. It is recommended to rerun the process once issues are fixed"); return; } }
public void ProcessFilesTest() { //This is all the correct parameter AppSettings appSettings = new AppSettings(); appSettings.Username = "******"; appSettings.Password = "******"; appSettings.ServerURL = "http://127.0.0.1:5000"; SettingsService settingsService = new SettingsService(); settingsService.SaveSettings(appSettings); TextfileProcessingService textfileProcessingService = new TextfileProcessingService(); string input = "E://downloads//Source"; string target = "E://downloads//res"; Assert.IsTrue(textfileProcessingService.ProcessFiles(input, null, DestinationLocationType.Server).Result == TextfileProcessingStatus.Done); //this is the wrong password after changing the password should save the appSetting to make sure this fucntion can get the wrong password //so that it can work correctly in local but go wrong in server appSettings.Password = "******"; settingsService.SaveSettings(appSettings); Assert.IsTrue(textfileProcessingService.ProcessFiles(input, null, DestinationLocationType.Server).Result == TextfileProcessingStatus.Error); Assert.IsTrue(textfileProcessingService.ProcessFiles(input, target, DestinationLocationType.Both).Result == TextfileProcessingStatus.PartialSuccess); //in this case change the password to the correct again the funcion will append"/metadata/import"automatically. // AS a result the target URL in the next case will be:127.0.0.1:5000/metadata/import/metadata/import, whichi is a wrong one appSettings.Password = "******"; appSettings.ServerURL = "http://127.0.0.1:5000/metadata/import"; settingsService.SaveSettings(appSettings); Assert.IsTrue(textfileProcessingService.ProcessFiles(input, null, DestinationLocationType.Server).Result == TextfileProcessingStatus.Error); //In this case I will send a non-exist path appSettings.Password = "******"; appSettings.ServerURL = "http://127.0.0.1:5000"; settingsService.SaveSettings(appSettings); input = "E://downloads//12345"; Assert.IsTrue(textfileProcessingService.ProcessFiles(input, null, DestinationLocationType.Server).Result == TextfileProcessingStatus.Error); //= In this case I will use a exsiting folder but no file input = "E://downloads//res"; Assert.IsTrue(textfileProcessingService.ProcessFiles(input, null, DestinationLocationType.Server).Result == TextfileProcessingStatus.NoFiles); //in this case I use a folder with one file contains error. input = "E://downloads//SourceWithError"; Assert.IsTrue(textfileProcessingService.ProcessFiles(input, null, DestinationLocationType.Server).Result == TextfileProcessingStatus.Error); }