From 4e4ed00169141b1ad81d41bffb94d831998aaffd Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Berthier Date: Sun, 17 Nov 2024 21:46:36 +0100 Subject: [PATCH 01/17] Add codecov.yml --- codecov.yml | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 codecov.yml diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 00000000..8a749073 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,58 @@ +comment: + layout: "reach,diff,flags,files" + behavior: default + require_changes: no + require_base: no + +coverage: + precision: 2 + round: down + range: "70...100" + +notifications: + commit: + status: + default: + target: "https://docs.codecov.io/docs/commit-status" + threshold: 1% + paths: [] + informational: false + +parsers: + gcov: + branch_detection: + conditional: yes + loop: yes + method: yes + macro: no + +codecov: + max_report_age: off + max_path_depth: 500 + +comment_template: | + :rocket: **Code Coverage Report** for `{{ commit }}` + + - **Coverage**: {{ diff_coverage }}% ({{ coverage_change }}% change) + - **Files**: {{ total_files }} with modifications + - **Hits**: {{ hits }} / {{ lines }} lines + + {{#flags}} + {{#name}} + - Flag **{{ name }}**: {{ coverage }}% + {{/name}} + {{/flags}} + + {{#reach}} + - **Reach**: Improved {{ diff_coverage }}% compared to base. + {{/reach}} + + [View Full Report](https://codecov.io/{{ slug }}/commit/{{ commit }}) + + {{#threshold_exceeded}} + :warning: The threshold of {{ threshold }}% was exceeded by {{ diff }}%. + {{/threshold_exceeded}} + + {{#is_new}} + :green_circle: This is a **newly added test**. + {{/is_new}} From 1a09624135802c761b8510ac419fc3e44a04f4ce Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Berthier Date: Mon, 18 Nov 2024 21:42:03 +0100 Subject: [PATCH 02/17] Clean up codecov.yml --- codecov.yml | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/codecov.yml b/codecov.yml index 8a749073..ff60da91 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,8 +1,7 @@ comment: - layout: "reach,diff,flags,files" + layout: "condensed_header, condensed_files, condensed_footer" behavior: default - require_changes: no - require_base: no + require_changes: false coverage: precision: 2 @@ -29,30 +28,3 @@ parsers: codecov: max_report_age: off max_path_depth: 500 - -comment_template: | - :rocket: **Code Coverage Report** for `{{ commit }}` - - - **Coverage**: {{ diff_coverage }}% ({{ coverage_change }}% change) - - **Files**: {{ total_files }} with modifications - - **Hits**: {{ hits }} / {{ lines }} lines - - {{#flags}} - {{#name}} - - Flag **{{ name }}**: {{ coverage }}% - {{/name}} - {{/flags}} - - {{#reach}} - - **Reach**: Improved {{ diff_coverage }}% compared to base. - {{/reach}} - - [View Full Report](https://codecov.io/{{ slug }}/commit/{{ commit }}) - - {{#threshold_exceeded}} - :warning: The threshold of {{ threshold }}% was exceeded by {{ diff }}%. - {{/threshold_exceeded}} - - {{#is_new}} - :green_circle: This is a **newly added test**. - {{/is_new}} From b8e08c917b78917289b5f80d90ee59a9fe024217 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Berthier Date: Mon, 18 Nov 2024 22:00:30 +0100 Subject: [PATCH 03/17] Remove notifications section --- codecov.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/codecov.yml b/codecov.yml index ff60da91..c372260b 100644 --- a/codecov.yml +++ b/codecov.yml @@ -8,15 +8,6 @@ coverage: round: down range: "70...100" -notifications: - commit: - status: - default: - target: "https://docs.codecov.io/docs/commit-status" - threshold: 1% - paths: [] - informational: false - parsers: gcov: branch_detection: From 6dd655dd995d912cb960999fd4b33d617daf6471 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Berthier Date: Mon, 18 Nov 2024 22:12:09 +0100 Subject: [PATCH 04/17] Clean up part 2 --- codecov.yml | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/codecov.yml b/codecov.yml index c372260b..586829f1 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,21 +1,12 @@ -comment: - layout: "condensed_header, condensed_files, condensed_footer" - behavior: default - require_changes: false - coverage: precision: 2 round: down range: "70...100" -parsers: - gcov: - branch_detection: - conditional: yes - loop: yes - method: yes - macro: no +comment: + layout: "condensed_header, condensed_files, condensed_footer" + behavior: default + require_changes: false codecov: max_report_age: off - max_path_depth: 500 From f4625a9bfc851c03b4bb781b07758e0ee42aa0c5 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Berthier Date: Tue, 19 Nov 2024 22:51:32 +0100 Subject: [PATCH 05/17] Basic config --- codecov.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/codecov.yml b/codecov.yml index 586829f1..f0f6358e 100644 --- a/codecov.yml +++ b/codecov.yml @@ -2,11 +2,3 @@ coverage: precision: 2 round: down range: "70...100" - -comment: - layout: "condensed_header, condensed_files, condensed_footer" - behavior: default - require_changes: false - -codecov: - max_report_age: off From 507362d5951ae6eb869ce8f0f9b4b150fa87b598 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Berthier Date: Tue, 19 Nov 2024 23:13:36 +0100 Subject: [PATCH 06/17] Fix token --- .github/workflows/build.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b586132a..910015e4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -85,5 +85,4 @@ jobs: name: codecov-windows-latest verbose: true fail_ci_if_error: true - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + token: ${{ secrets.CODECOV_TOKEN }} From 83fdb87673224e017a46c73d859ac53463ae77aa Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Berthier Date: Tue, 19 Nov 2024 23:37:06 +0100 Subject: [PATCH 07/17] Try new version --- codecov.yml | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/codecov.yml b/codecov.yml index f0f6358e..85c9b5ca 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,4 +1,20 @@ +codecov: + require_ci_to_pass: yes + coverage: - precision: 2 - round: down - range: "70...100" + precision: 2 + round: down + range: "70..100" + +parsers: + gcov: + branch_detection: + conditional: yes + loop: yes + method: no + macro: no + +comment: + layout: "header,diff" + behavior: default + require_changes: false \ No newline at end of file From 0a1f8645f9a4a9a7b3bb017fb89cb2562d5a4d56 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Berthier Date: Wed, 20 Nov 2024 09:24:30 +0100 Subject: [PATCH 08/17] Update indent --- codecov.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/codecov.yml b/codecov.yml index 85c9b5ca..31020b21 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,20 +1,20 @@ codecov: - require_ci_to_pass: yes + require_ci_to_pass: yes coverage: - precision: 2 - round: down - range: "70..100" + precision: 2 + round: down + range: "70..100" parsers: - gcov: - branch_detection: - conditional: yes - loop: yes - method: no - macro: no + gcov: + branch_detection: + conditional: yes + loop: yes + method: no + macro: no comment: - layout: "header,diff" - behavior: default - require_changes: false \ No newline at end of file + layout: "header,diff" + behavior: default + require_changes: false \ No newline at end of file From 0a5125ff2f67665218bd588a0e9727c85485a661 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Berthier Date: Wed, 20 Nov 2024 10:08:17 +0100 Subject: [PATCH 09/17] Revert indent update --- codecov.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/codecov.yml b/codecov.yml index 31020b21..1431f246 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,20 +1,20 @@ codecov: - require_ci_to_pass: yes + require_ci_to_pass: yes coverage: - precision: 2 - round: down - range: "70..100" + precision: 2 + round: down + range: "70..100" parsers: gcov: - branch_detection: - conditional: yes - loop: yes - method: no - macro: no + branch_detection: + conditional: yes + loop: yes + method: no + macro: no comment: - layout: "header,diff" - behavior: default - require_changes: false \ No newline at end of file + layout: "header,diff" + behavior: default + require_changes: false \ No newline at end of file From 63ddb96ea2090192c375a333dac6b8afefe6a798 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Berthier Date: Wed, 20 Nov 2024 11:06:04 +0100 Subject: [PATCH 10/17] Add code coverage in Readme --- Readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Readme.md b/Readme.md index c774f5ae..df51721c 100644 --- a/Readme.md +++ b/Readme.md @@ -189,6 +189,10 @@ Improvements **WIP**. - [ReportGenerator](https://github.com/danielpalme/ReportGenerator) - [FFMpegCore](https://github.com/rosenbjerg/FFMpegCore) +## Code coverage :bar_chart: + +[![codecov](https://codecov.io/github/PABERTHIER/photo-manager/graphs/sunburst.svg?token=DILR0QRXVN)](https://codecov.io/github/PABERTHIER/photo-manager) + ## Transparency :handshake: This project has some versionned dll and rar files for its own good working. From 197b918ef734594096655cd1fdd9085caff79b36 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Berthier Date: Wed, 20 Nov 2024 19:18:19 +0100 Subject: [PATCH 11/17] Clean up lint and warnings in Domain and Tests --- PhotoManager/PhotoManager.Domain/Asset.cs | 27 +- .../AssetCreationService.cs | 2 +- .../CatalogAssetsService.cs | 2 +- .../FindDuplicatedAssetsService.cs | 18 +- PhotoManager/PhotoManager.Domain/Folder.cs | 18 +- .../Interfaces/IAssetCreationService.cs | 2 +- .../IFindDuplicatedAssetsService.cs | 2 +- .../Interfaces/ISyncAssetsService.cs | 2 +- .../ProcessStatusChangedCallback.cs | 2 +- .../SyncAssetsConfiguration.cs | 7 +- .../SyncAssetsDirectoriesDefinition.cs | 8 +- .../PhotoManager.Domain/SyncAssetsResult.cs | 4 +- .../PhotoManager.Domain/SyncAssetsService.cs | 55 +- .../AssetSettings.cs | 2 +- .../UserConfigurationSettings/HashSettings.cs | 2 +- .../UserConfigurationSettings/PathSettings.cs | 2 +- .../ProjectSettings.cs | 2 +- .../StorageSettings.cs | 6 +- .../AssetRepository.cs | 58 +- .../Database/Database.cs | 10 +- .../Database/Storage/BaseCsvStorage.cs | 6 +- .../Database/Storage/ObjectListStorage.cs | 10 +- .../StorageService.cs | 2 +- .../TablesConfig/AssetConfigs.cs | 35 +- .../UserConfigurationService.cs | 7 +- .../CatalogAssetsAsyncAsserts.cs | 4 +- .../ApplicationCatalogAssetsAsyncTests.cs | 13 +- .../Domain/AssetCreationServiceTests.cs | 7 + ...alogAssetsServiceMultipleInstancesTests.cs | 9 + .../CatalogAssetsServiceTests.cs | 13 +- .../FindDuplicatedAssetsServiceTests.cs | 269 +++++---- ...ssetsServiceThumbnailNotDuplicatesTests.cs | 406 +++++++------ ...plicatedAssetsServiceThumbnailPartTests.cs | 448 +++++++------- ...edAssetsServiceThumbnailResolutionTests.cs | 335 ++++++----- ...ndDuplicatedAssetsServiceThumbnailTests.cs | 283 ++++----- ...tedAssetsServiceThumbnailThumbnailTests.cs | 257 ++++---- .../Domain/MoveAssetsServiceTests.cs | 568 +++++++++--------- .../Domain/SyncAssetsServiceTests.cs | 366 +++++------ .../AssetRepositoryAddAssetTests.cs | 259 ++++---- .../AssetRepositoryAddFolderTests.cs | 56 +- .../AssetRepositoryBackupExistsTests.cs | 28 +- .../AssetRepositoryConcurrentAccessTests.cs | 7 +- .../AssetRepositoryContainsThumbnailTests.cs | 186 +++--- .../AssetRepositoryDeleteAssetTests.cs | 17 +- .../AssetRepositoryDeleteFolderTests.cs | 161 ++--- .../AssetRepositoryFolderExistsTests.cs | 36 +- ...AssetRepositoryFolderHasThumbnailsTests.cs | 34 +- .../AssetRepositoryGetAssetsByPathTests.cs | 352 +++++------ .../AssetRepositoryGetAssetsCounterTests.cs | 13 +- ...epositoryGetCataloguedAssetsByPathTests.cs | 83 +-- ...AssetRepositoryGetCataloguedAssetsTests.cs | 84 +-- .../AssetRepositoryGetFolderByPathTests.cs | 54 +- .../AssetRepositoryGetFoldersPathTests.cs | 10 +- .../AssetRepositoryGetFoldersTests.cs | 10 +- ...ssetRepositoryGetRecentTargetPathsTests.cs | 46 +- .../AssetRepositoryGetSubFoldersTests.cs | 46 +- ...positoryGetSyncAssetsConfigurationTests.cs | 28 +- .../AssetRepositoryHasChangesTests.cs | 32 +- .../AssetRepositoryIsAssetCataloguedTests.cs | 77 +-- .../AssetRepositoryLoadThumbnailTests.cs | 267 ++++---- .../AssetRepositorySaveCatalogTests.cs | 187 +++--- ...setRepositorySaveRecentTargetPathsTests.cs | 38 +- ...ositorySaveSyncAssetsConfigurationTests.cs | 24 +- ...RepositoryUpdateTargetPathToRecentTests.cs | 40 +- .../AssetRepositoryWriteBackupTests.cs | 48 +- .../DatabaseDeleteOldBackupsTests.cs | 32 +- .../Storage/ObjectListStorageTests.cs | 269 ++++----- .../Infrastructure/StorageServiceTests.cs | 156 +---- .../UserConfigurationServiceTests.cs | 12 +- .../ApplicationViewModelCatalogAssetsTests.cs | 13 +- ...cationViewModelNotifyCatalogChangeTests.cs | 21 +- .../Unit/Domain/AssetsComparatorTests.cs | 102 ++-- .../Unit/Domain/FolderTests.cs | 12 +- .../Domain/SyncAssetsConfigurationTests.cs | 2 +- .../DatabaseBackupExistsTests.cs | 12 +- .../DatabaseDeleteOldBackupsTests.cs | 46 +- .../DatabaseDeleteThumbnailsTests.cs | 12 +- .../DatabaseFolderHasThumbnailsTests.cs | 12 +- .../DatabaseTests/DatabaseInitializeTests.cs | 8 +- .../DatabaseTests/DatabaseReadBlobTests.cs | 28 +- .../DatabaseReadObjectListTests.cs | 232 ++++--- .../DatabaseSetDataTablePropertiesTests.cs | 42 +- .../DatabaseTests/DatabaseWriteBackupTests.cs | 16 +- .../DatabaseTests/DatabaseWriteBlobTests.cs | 34 +- .../DatabaseWriteObjectListTests.cs | 323 +++++----- .../Database/Storage/BackupStorageTests.cs | 53 +- .../Database/Storage/BlobStorageTests.cs | 35 +- .../TablesConfig/AssetConfigsTests.cs | 60 +- .../TablesConfig/FolderConfigsTests.cs | 34 +- .../TablesConfig/RecentPathsConfigsTests.cs | 20 +- ...AssetsDirectoriesDefinitionConfigsTests.cs | 22 +- .../UserConfigurationServiceTests.cs | 2 +- .../UI/Converters/FileNameConverterTests.cs | 4 +- .../UI/Converters/FileSizeConverterTests.cs | 4 +- .../UI/Converters/PixelSizeConverterTests.cs | 7 +- .../UI/Converters/TernaryConverterTests.cs | 8 +- .../ViewModels/ApplicationViewModelTests.cs | 561 ++++++++++++----- 97 files changed, 3966 insertions(+), 3720 deletions(-) diff --git a/PhotoManager/PhotoManager.Domain/Asset.cs b/PhotoManager/PhotoManager.Domain/Asset.cs index 79e782af..3d69f658 100644 --- a/PhotoManager/PhotoManager.Domain/Asset.cs +++ b/PhotoManager/PhotoManager.Domain/Asset.cs @@ -2,25 +2,24 @@ public class Asset { - // TODO: use instead Folder.FolderId ? -> if done, update tests - // TODO: property required + // TODO: compose -> one readonly struct for Pixel, for ThumbnailPixel and object for FileDateTime to begin public Guid FolderId { get; set; } - public Folder Folder { get; set; } - public string FileName { get; set; } - public long FileSize { get; set; } - public int PixelWidth { get; set; } - public int PixelHeight { get; set; } - public int ThumbnailPixelWidth { get; set; } - public int ThumbnailPixelHeight { get; set; } - public Rotation ImageRotation { get; set; } + public required Folder Folder { get; set; } + public required string FileName { get; set; } + public long FileSize { get; init; } + public int PixelWidth { get; init; } + public int PixelHeight { get; init; } + public int ThumbnailPixelWidth { get; init; } + public int ThumbnailPixelHeight { get; init; } + public Rotation ImageRotation { get; init; } public DateTime ThumbnailCreationDateTime { get; set; } - public string Hash { get; set; } + public required string Hash { get; set; } public BitmapImage? ImageData { get; set; } - public string FullPath => Folder != null ? Path.Combine(Folder.Path, FileName) : FileName; + public string FullPath => Path.Combine(Folder.Path, FileName); public DateTime FileCreationDateTime { get; set; } public DateTime FileModificationDateTime { get; set; } - public bool IsAssetCorrupted { get; set; } + public bool IsAssetCorrupted { get; init; } public string? AssetCorruptedMessage { get; set; } - public bool IsAssetRotated { get; set; } + public bool IsAssetRotated { get; init; } public string? AssetRotatedMessage { get; set; } } diff --git a/PhotoManager/PhotoManager.Domain/AssetCreationService.cs b/PhotoManager/PhotoManager.Domain/AssetCreationService.cs index cc147b2c..901b5daf 100644 --- a/PhotoManager/PhotoManager.Domain/AssetCreationService.cs +++ b/PhotoManager/PhotoManager.Domain/AssetCreationService.cs @@ -18,7 +18,7 @@ public class AssetCreationService( { // Create an asset from the video file VideoHelper.GetFirstFramePath(directoryName, fileName, userConfigurationService.PathSettings.FirstFrameVideosPath); - // The video file is not in the same path than the asset created + // The video file is not in the same path as the asset created // The asset is null because the target is not the video but the asset created previously return null; } diff --git a/PhotoManager/PhotoManager.Domain/CatalogAssetsService.cs b/PhotoManager/PhotoManager.Domain/CatalogAssetsService.cs index 1eb8c933..56c3d89f 100644 --- a/PhotoManager/PhotoManager.Domain/CatalogAssetsService.cs +++ b/PhotoManager/PhotoManager.Domain/CatalogAssetsService.cs @@ -91,7 +91,7 @@ await Task.Run(() => { // If the catalog background process is cancelled, there is a risk that it happens while saving the catalog files. // This could result in the files being damaged. - // Therefore the application saves the files before the task is completely shut down. + // Therefore, the application saves the files before the task is completely shut down. // TODO: Test if _currentFolderPath is good & SaveCatalog performed correctly Folder? currentFolder = _assetRepository.GetFolderByPath(_currentFolderPath); diff --git a/PhotoManager/PhotoManager.Domain/FindDuplicatedAssetsService.cs b/PhotoManager/PhotoManager.Domain/FindDuplicatedAssetsService.cs index d5d348be..431d782f 100644 --- a/PhotoManager/PhotoManager.Domain/FindDuplicatedAssetsService.cs +++ b/PhotoManager/PhotoManager.Domain/FindDuplicatedAssetsService.cs @@ -2,10 +2,6 @@ public class FindDuplicatedAssetsService(IAssetRepository assetRepository, IStorageService storageService, IUserConfigurationService userConfigurationService) : IFindDuplicatedAssetsService { - private readonly IAssetRepository _assetRepository = assetRepository; - private readonly IStorageService _storageService = storageService; - private readonly IUserConfigurationService _userConfigurationService = userConfigurationService; - /// /// Detects duplicated assets in the catalog. /// @@ -14,11 +10,11 @@ public class FindDuplicatedAssetsService(IAssetRepository assetRepository, IStor public List> GetDuplicatedAssets() { List> duplicatedAssetsSets = []; - List assets = new (_assetRepository.GetCataloguedAssets()); + List assets = [..assetRepository.GetCataloguedAssets()]; - if (_userConfigurationService.AssetSettings.DetectThumbnails && _userConfigurationService.HashSettings.UsingPHash) + if (userConfigurationService.AssetSettings.DetectThumbnails && userConfigurationService.HashSettings.UsingPHash) { - return GetDuplicatesBetweenOriginalAndThumbnail(assets, _userConfigurationService.HashSettings.PHashThreshold); + return GetDuplicatesBetweenOriginalAndThumbnail(assets, userConfigurationService.HashSettings.PHashThreshold); } List> assetGroups = assets.GroupBy(a => a.Hash).Where(g => g.Count() > 1).ToList(); @@ -26,12 +22,12 @@ public List> GetDuplicatedAssets() foreach (IGrouping group in assetGroups) { List duplicatedSet = [.. group]; - duplicatedSet.RemoveAll(asset => !_storageService.FileExists(asset.FullPath)); + duplicatedSet.RemoveAll(asset => !storageService.FileExists(asset.FullPath)); if (duplicatedSet.Count > 1) { duplicatedAssetsSets.Add(duplicatedSet); - _storageService.UpdateAssetsFileDateTimeProperties(duplicatedSet); + storageService.UpdateAssetsFileDateTimeProperties(duplicatedSet); } } @@ -50,7 +46,7 @@ private List> GetDuplicatesBetweenOriginalAndThumbnail(List a // Create a dictionary to store assets by their Hash values Dictionary> assetDictionary = []; - assets.RemoveAll(asset => !_storageService.FileExists(asset.FullPath)); + assets.RemoveAll(asset => !storageService.FileExists(asset.FullPath)); for (int i = 0; i < assets.Count; i++) { @@ -91,7 +87,7 @@ private List> GetDuplicatesBetweenOriginalAndThumbnail(List a { if (assetSet.Count > 1) { - _storageService.UpdateAssetsFileDateTimeProperties(assetSet); + storageService.UpdateAssetsFileDateTimeProperties(assetSet); duplicatedAssetsSets.Add(assetSet); } } diff --git a/PhotoManager/PhotoManager.Domain/Folder.cs b/PhotoManager/PhotoManager.Domain/Folder.cs index 13fa5b6d..c06bead7 100644 --- a/PhotoManager/PhotoManager.Domain/Folder.cs +++ b/PhotoManager/PhotoManager.Domain/Folder.cs @@ -3,16 +3,16 @@ public class Folder { // TODO: FolderId not null -> when a new -> new guid - public Guid FolderId { get; set; } // TODO: Rename to Id - public required string Path { get; set; } + public Guid FolderId { get; init; } // TODO: Rename to Id + public required string Path { get; init; } public string ThumbnailsFilename => FolderId + ".bin"; // TODO: BlobFileName instead -> rename all methods like this public string Name { get { - string[] pathParts = Path.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries); - string result = pathParts[^1]; + string[] pathParts = !string.IsNullOrWhiteSpace(Path) ? Path.Split(['\\'], StringSplitOptions.RemoveEmptyEntries) : []; + string result = pathParts.Length > 0 ? pathParts[^1] : string.Empty; return result; } @@ -22,7 +22,7 @@ private Folder? Parent { get { - string? parentPath = GetParentPath(); + string? parentPath = GetParentPath(Path); return parentPath != null ? new Folder { Path = parentPath } : null; } } @@ -30,13 +30,13 @@ private Folder? Parent public bool IsParentOf(Folder folder) { return !string.IsNullOrWhiteSpace(Path) - && !string.IsNullOrWhiteSpace(folder?.Parent?.Path) - && string.Compare(Path, folder?.Parent?.Path, StringComparison.OrdinalIgnoreCase) == 0; + && !string.IsNullOrWhiteSpace(folder.Parent?.Path) + && string.Compare(Path, folder.Parent?.Path, StringComparison.OrdinalIgnoreCase) == 0; } - private string? GetParentPath() + private static string? GetParentPath(string? path) { - string[]? directoriesPath = Path?.Split(System.IO.Path.DirectorySeparatorChar); + string[]? directoriesPath = path?.Split(System.IO.Path.DirectorySeparatorChar); directoriesPath = directoriesPath?.SkipLast(1).ToArray(); return directoriesPath?.Length > 0 ? System.IO.Path.Combine(directoriesPath) : null; } diff --git a/PhotoManager/PhotoManager.Domain/Interfaces/IAssetCreationService.cs b/PhotoManager/PhotoManager.Domain/Interfaces/IAssetCreationService.cs index a70a11f8..9bf4edbf 100644 --- a/PhotoManager/PhotoManager.Domain/Interfaces/IAssetCreationService.cs +++ b/PhotoManager/PhotoManager.Domain/Interfaces/IAssetCreationService.cs @@ -3,4 +3,4 @@ public interface IAssetCreationService { Asset? CreateAsset(string directoryName, string fileName, bool isVideo = false); -} \ No newline at end of file +} diff --git a/PhotoManager/PhotoManager.Domain/Interfaces/IFindDuplicatedAssetsService.cs b/PhotoManager/PhotoManager.Domain/Interfaces/IFindDuplicatedAssetsService.cs index fd7a55ee..bbec3c9f 100644 --- a/PhotoManager/PhotoManager.Domain/Interfaces/IFindDuplicatedAssetsService.cs +++ b/PhotoManager/PhotoManager.Domain/Interfaces/IFindDuplicatedAssetsService.cs @@ -3,4 +3,4 @@ public interface IFindDuplicatedAssetsService { List> GetDuplicatedAssets(); -} \ No newline at end of file +} diff --git a/PhotoManager/PhotoManager.Domain/Interfaces/ISyncAssetsService.cs b/PhotoManager/PhotoManager.Domain/Interfaces/ISyncAssetsService.cs index 9bff338f..08814fe0 100644 --- a/PhotoManager/PhotoManager.Domain/Interfaces/ISyncAssetsService.cs +++ b/PhotoManager/PhotoManager.Domain/Interfaces/ISyncAssetsService.cs @@ -3,4 +3,4 @@ public interface ISyncAssetsService { Task> ExecuteAsync(ProcessStatusChangedCallback callback); -} \ No newline at end of file +} diff --git a/PhotoManager/PhotoManager.Domain/ProcessStatusChangedCallback.cs b/PhotoManager/PhotoManager.Domain/ProcessStatusChangedCallback.cs index 8def87cc..2b5d641d 100644 --- a/PhotoManager/PhotoManager.Domain/ProcessStatusChangedCallback.cs +++ b/PhotoManager/PhotoManager.Domain/ProcessStatusChangedCallback.cs @@ -4,5 +4,5 @@ public class ProcessStatusChangedCallbackEventArgs { - public string NewStatus { get; set; } + public required string NewStatus { get; init; } } diff --git a/PhotoManager/PhotoManager.Domain/SyncAssetsConfiguration.cs b/PhotoManager/PhotoManager.Domain/SyncAssetsConfiguration.cs index f386cb2d..f8794ee4 100644 --- a/PhotoManager/PhotoManager.Domain/SyncAssetsConfiguration.cs +++ b/PhotoManager/PhotoManager.Domain/SyncAssetsConfiguration.cs @@ -2,12 +2,7 @@ public class SyncAssetsConfiguration { - public SyncAssetsConfiguration() - { - Definitions = []; - } - - public List Definitions { get; } + public List Definitions { get; } = []; // TODO: transform to fluent to have syncConfiguration.Validate().Normalize() public void Validate() // ISyncAssetsConfiguration Validate(); diff --git a/PhotoManager/PhotoManager.Domain/SyncAssetsDirectoriesDefinition.cs b/PhotoManager/PhotoManager.Domain/SyncAssetsDirectoriesDefinition.cs index 53707344..f0f4b264 100644 --- a/PhotoManager/PhotoManager.Domain/SyncAssetsDirectoriesDefinition.cs +++ b/PhotoManager/PhotoManager.Domain/SyncAssetsDirectoriesDefinition.cs @@ -6,8 +6,8 @@ public partial class SyncAssetsDirectoriesDefinition { public required string SourceDirectory { get; set; } public required string DestinationDirectory { get; set; } - public bool IncludeSubFolders { get; set; } - public bool DeleteAssetsNotInSource { get; set; } + public bool IncludeSubFolders { get; init; } + public bool DeleteAssetsNotInSource { get; init; } internal bool IsValid() { @@ -21,7 +21,7 @@ internal void Normalize() DestinationDirectory = NormalizeDirectory(DestinationDirectory); } - private string NormalizeDirectory(string directory) + private static string NormalizeDirectory(string directory) { bool isRemote = IsValidRemotePath(directory); string[] parts = directory.Split('\\', StringSplitOptions.RemoveEmptyEntries); @@ -46,6 +46,6 @@ private static bool IsValidRemotePath(string directory) [GeneratedRegex("^([A-Za-z])(:)(\\[A-Za-z0-9]*)*")] private static partial Regex LocalPathRegex(); - [GeneratedRegex("^(\\\\)(\\[A-Za-z0-9]*)*")] + [GeneratedRegex(@"^(\\)(\[A-Za-z0-9]*)*")] private static partial Regex RemotePathRegex(); } diff --git a/PhotoManager/PhotoManager.Domain/SyncAssetsResult.cs b/PhotoManager/PhotoManager.Domain/SyncAssetsResult.cs index d76dda12..845515eb 100644 --- a/PhotoManager/PhotoManager.Domain/SyncAssetsResult.cs +++ b/PhotoManager/PhotoManager.Domain/SyncAssetsResult.cs @@ -2,8 +2,8 @@ public class SyncAssetsResult { - public required string SourceDirectory { get; set; } - public required string DestinationDirectory { get; set; } + public required string SourceDirectory { get; init; } + public required string DestinationDirectory { get; init; } public int SyncedImages { get; set; } public string? Message { get; set; } } diff --git a/PhotoManager/PhotoManager.Domain/SyncAssetsService.cs b/PhotoManager/PhotoManager.Domain/SyncAssetsService.cs index 49a15f95..41594a39 100644 --- a/PhotoManager/PhotoManager.Domain/SyncAssetsService.cs +++ b/PhotoManager/PhotoManager.Domain/SyncAssetsService.cs @@ -6,17 +6,12 @@ public class SyncAssetsService( IAssetsComparator assetsComparator, IMoveAssetsService moveAssetsService) : ISyncAssetsService { - private readonly IAssetRepository _assetRepository = assetRepository; - private readonly IStorageService _storageService = storageService; - private readonly IAssetsComparator _assetsComparator = assetsComparator; - private readonly IMoveAssetsService _moveAssetsService = moveAssetsService; - public async Task> ExecuteAsync(ProcessStatusChangedCallback callback) { return await Task.Run(() => { List result = []; - SyncAssetsConfiguration configuration = _assetRepository.GetSyncAssetsConfiguration(); + SyncAssetsConfiguration configuration = assetRepository.GetSyncAssetsConfiguration(); foreach (SyncAssetsDirectoriesDefinition definition in configuration.Definitions) { @@ -46,7 +41,7 @@ private void Execute( DestinationDirectory = destinationDirectory }; - if (!_storageService.FolderExists(sourceDirectory)) + if (!storageService.FolderExists(sourceDirectory)) { syncAssetsResult.Message = $"Source directory '{sourceDirectory}' not found."; result.Add(syncAssetsResult); @@ -55,14 +50,14 @@ private void Execute( { try { - if (!_storageService.FolderExists(destinationDirectory)) + if (!storageService.FolderExists(destinationDirectory)) { - _storageService.CreateDirectory(destinationDirectory); + storageService.CreateDirectory(destinationDirectory); } - string[] sourceFileNames = _storageService.GetFileNames(sourceDirectory); - string[] destinationFileNames = _storageService.GetFileNames(destinationDirectory); - string[] newFileNames = _assetsComparator.GetNewFileNamesToSync(sourceFileNames, destinationFileNames); + string[] sourceFileNames = storageService.GetFileNames(sourceDirectory); + string[] destinationFileNames = storageService.GetFileNames(destinationDirectory); + string[] newFileNames = assetsComparator.GetNewFileNamesToSync(sourceFileNames, destinationFileNames); newFileNames = GetFilesNotAlreadyInDestinationSubDirectories(newFileNames, destinationDirectory); foreach (string newFileName in newFileNames) @@ -70,7 +65,7 @@ private void Execute( string sourceFilePath = Path.Combine(sourceDirectory, newFileName); string destinationFilePath = Path.Combine(destinationDirectory, newFileName); - if (_moveAssetsService.CopyAsset(sourceFilePath, destinationFilePath)) + if (moveAssetsService.CopyAsset(sourceFilePath, destinationFilePath)) { syncAssetsResult.SyncedImages++; callback(new ProcessStatusChangedCallbackEventArgs { NewStatus = $"'{sourceFilePath}' => '{destinationFilePath}'" }); @@ -79,12 +74,12 @@ private void Execute( if (deleteAssetsNotInSource) { - string[] deletedFileNames = _assetsComparator.GetDeletedFileNamesToSync(sourceFileNames, destinationFileNames); + string[] deletedFileNames = assetsComparator.GetDeletedFileNamesToSync(sourceFileNames, destinationFileNames); foreach (string deletedImage in deletedFileNames) { string destinationPath = Path.Combine(destinationDirectory, deletedImage); - _storageService.DeleteFile(destinationDirectory, deletedImage); + storageService.DeleteFile(destinationDirectory, deletedImage); syncAssetsResult.SyncedImages++; callback(new ProcessStatusChangedCallbackEventArgs { NewStatus = $"Deleted '{destinationPath}'" }); } @@ -101,19 +96,16 @@ private void Execute( if (includeSubFolders) { - List subdirectories = _storageService.GetSubDirectories(sourceDirectory); + List subdirectories = storageService.GetSubDirectories(sourceDirectory); - if (subdirectories != null) + for (int i = 0; i < subdirectories.Count; i++) { - foreach (DirectoryInfo subdir in subdirectories) - { - Execute(subdir.FullName, - Path.Combine(destinationDirectory, subdir.Name), - includeSubFolders, - deleteAssetsNotInSource, - callback, - result); - } + Execute(subdirectories[i].FullName, + Path.Combine(destinationDirectory, subdirectories[i].Name), + includeSubFolders, + deleteAssetsNotInSource, + callback, + result); } } } @@ -127,15 +119,12 @@ private void Execute( private string[] GetFilesNotAlreadyInDestinationSubDirectories(string[] newFileNames, string destinationDirectory) { - List destinationSubDirectories = _storageService.GetRecursiveSubDirectories(destinationDirectory); + List destinationSubDirectories = storageService.GetRecursiveSubDirectories(destinationDirectory); - if (destinationSubDirectories != null) + for (int i = 0; i < destinationSubDirectories.Count; i++) { - foreach (DirectoryInfo dir in destinationSubDirectories) - { - string[] destinationFileNames = _storageService.GetFileNames(dir.FullName); - newFileNames = _assetsComparator.GetNewFileNamesToSync(newFileNames, destinationFileNames); - } + string[] destinationFileNames = storageService.GetFileNames(destinationSubDirectories[i].FullName); + newFileNames = assetsComparator.GetNewFileNamesToSync(newFileNames, destinationFileNames); } return newFileNames; diff --git a/PhotoManager/PhotoManager.Domain/UserConfigurationSettings/AssetSettings.cs b/PhotoManager/PhotoManager.Domain/UserConfigurationSettings/AssetSettings.cs index 96c7422e..34e0a8ba 100644 --- a/PhotoManager/PhotoManager.Domain/UserConfigurationSettings/AssetSettings.cs +++ b/PhotoManager/PhotoManager.Domain/UserConfigurationSettings/AssetSettings.cs @@ -1,6 +1,6 @@ namespace PhotoManager.Domain.UserConfigurationSettings; -public record class AssetSettings( +public record AssetSettings( bool AnalyseVideos, string AssetCorruptedMessage, string AssetRotatedMessage, diff --git a/PhotoManager/PhotoManager.Domain/UserConfigurationSettings/HashSettings.cs b/PhotoManager/PhotoManager.Domain/UserConfigurationSettings/HashSettings.cs index 66982383..9473e8b3 100644 --- a/PhotoManager/PhotoManager.Domain/UserConfigurationSettings/HashSettings.cs +++ b/PhotoManager/PhotoManager.Domain/UserConfigurationSettings/HashSettings.cs @@ -1,3 +1,3 @@ namespace PhotoManager.Domain.UserConfigurationSettings; -public record class HashSettings(ushort PHashThreshold, bool UsingDHash, bool UsingMD5Hash, bool UsingPHash); +public record HashSettings(ushort PHashThreshold, bool UsingDHash, bool UsingMD5Hash, bool UsingPHash); diff --git a/PhotoManager/PhotoManager.Domain/UserConfigurationSettings/PathSettings.cs b/PhotoManager/PhotoManager.Domain/UserConfigurationSettings/PathSettings.cs index 6f35086e..36339ff9 100644 --- a/PhotoManager/PhotoManager.Domain/UserConfigurationSettings/PathSettings.cs +++ b/PhotoManager/PhotoManager.Domain/UserConfigurationSettings/PathSettings.cs @@ -1,6 +1,6 @@ namespace PhotoManager.Domain.UserConfigurationSettings; -public record class PathSettings( +public record PathSettings( string AssetsDirectory, string BackupPath, string ExemptedFolderPath, diff --git a/PhotoManager/PhotoManager.Domain/UserConfigurationSettings/ProjectSettings.cs b/PhotoManager/PhotoManager.Domain/UserConfigurationSettings/ProjectSettings.cs index d037d0f4..9c6c6e94 100644 --- a/PhotoManager/PhotoManager.Domain/UserConfigurationSettings/ProjectSettings.cs +++ b/PhotoManager/PhotoManager.Domain/UserConfigurationSettings/ProjectSettings.cs @@ -1,3 +1,3 @@ namespace PhotoManager.Domain.UserConfigurationSettings; -public record class ProjectSettings(string Name, string Owner); +public record ProjectSettings(string Name, string Owner); diff --git a/PhotoManager/PhotoManager.Domain/UserConfigurationSettings/StorageSettings.cs b/PhotoManager/PhotoManager.Domain/UserConfigurationSettings/StorageSettings.cs index 9f84b00e..f4096ca7 100644 --- a/PhotoManager/PhotoManager.Domain/UserConfigurationSettings/StorageSettings.cs +++ b/PhotoManager/PhotoManager.Domain/UserConfigurationSettings/StorageSettings.cs @@ -1,6 +1,6 @@ namespace PhotoManager.Domain.UserConfigurationSettings; -public record class StorageSettings( +public record StorageSettings( ushort BackupsToKeep, FoldersNameSettings FoldersNameSettings, char Separator, @@ -8,11 +8,11 @@ public record class StorageSettings( TablesSettings TablesSettings, ushort ThumbnailsDictionaryEntriesToKeep); -public record class FoldersNameSettings( +public record FoldersNameSettings( string Blobs, string Tables); -public record class TablesSettings( +public record TablesSettings( string AssetsTableName, string FoldersTableName, string RecentTargetPathsTableName, diff --git a/PhotoManager/PhotoManager.Infrastructure/AssetRepository.cs b/PhotoManager/PhotoManager.Infrastructure/AssetRepository.cs index a11feaa5..21d0e445 100644 --- a/PhotoManager/PhotoManager.Infrastructure/AssetRepository.cs +++ b/PhotoManager/PhotoManager.Infrastructure/AssetRepository.cs @@ -34,12 +34,12 @@ public AssetRepository(IDatabase database, IStorageService storageService, IUser _database = database; _storageService = storageService; _userConfigurationService = userConfigurationService; - assets = new List(); - folders = new List(); + assets = []; + folders = []; syncAssetsConfiguration = new SyncAssetsConfiguration(); - recentTargetPaths = new List(); + recentTargetPaths = []; recentThumbnailsQueue = new Queue(); - Thumbnails = new Dictionary>(); + Thumbnails = []; syncLock = new object(); dataDirectory = _storageService.ResolveDataDirectory(_userConfigurationService.StorageSettings.StorageVersion); Initialize(); @@ -47,7 +47,7 @@ public AssetRepository(IDatabase database, IStorageService storageService, IUser public Asset[] GetAssetsByPath(string directory) { - List assetsList = new(); // TODO: Why array at the end ? + List assetsList = []; // TODO: Why array at the end ? bool isNewFile = false; try @@ -102,7 +102,7 @@ public void AddAsset(Asset asset, byte[] thumbnailData) { Folder? folder = GetFolderById(asset.FolderId); - if (string.IsNullOrWhiteSpace(asset.Folder?.Path)) + if (string.IsNullOrWhiteSpace(asset.Folder.Path)) { return; // TODO: log.Error($"The asset could not be added, folder is null, asset.FileName: {asset.FileName}"); } @@ -128,7 +128,7 @@ public void AddAsset(Asset asset, byte[] thumbnailData) } } - public Folder AddFolder(string path) // Play this before anything else to register every folders + public Folder AddFolder(string path) // Play this before anything else to register every folder { Folder folder; @@ -149,7 +149,7 @@ public void AddAsset(Asset asset, byte[] thumbnailData) public bool FolderExists(string path) { - bool result = false; + bool result; lock (syncLock) { @@ -171,7 +171,7 @@ public Folder[] GetFolders() return result; } - // TODO: Is HashSet the right think to do ? (Because it does not preserve the order) + // TODO: Is HashSet the right thing to do ? (Because it does not preserve the order) public HashSet GetFoldersPath() { HashSet folderPaths; @@ -243,7 +243,7 @@ public void WriteBackup() public List GetCataloguedAssets() { - List? cataloguedAssets = null; + List? cataloguedAssets; lock (syncLock) { @@ -256,7 +256,7 @@ public List GetCataloguedAssets() // TODO: Improve it by having a Dict instead Dictionary> public List GetCataloguedAssetsByPath(string directory) { - List cataloguedAssets = new(); + List cataloguedAssets = []; lock (syncLock) { @@ -273,7 +273,7 @@ public List GetCataloguedAssetsByPath(string directory) public bool IsAssetCatalogued(string directoryName, string fileName) { - bool result = false; + bool result; lock (syncLock) { @@ -342,7 +342,7 @@ public void DeleteFolder(Folder folder) public bool HasChanges() { - bool result = false; + bool result; lock (syncLock) { @@ -355,7 +355,7 @@ public bool HasChanges() // TODO: Seems to be a dead method public bool ContainsThumbnail(string directoryName, string fileName) { - bool result = false; + bool result; lock (syncLock) { @@ -429,7 +429,7 @@ public void SaveSyncAssetsConfiguration(SyncAssetsConfiguration syncAssetsConfig public List GetRecentTargetPaths() { - List result = new(); + List result; lock (syncLock) { @@ -452,7 +452,7 @@ public void UpdateTargetPathToRecent(Folder destinationFolder) { lock (syncLock) { - List recentTargetPathsUpdated = new (recentTargetPaths); + List recentTargetPathsUpdated = [..recentTargetPaths]; if (recentTargetPathsUpdated.Contains(destinationFolder.Path)) { @@ -550,32 +550,32 @@ private List ReadRecentTargetPaths() return _database.ReadObjectList(_userConfigurationService.StorageSettings.TablesSettings.RecentTargetPathsTableName, RecentPathsConfigs.ReadFunc); } - private void WriteFolders(List folders) + private void WriteFolders(List foldersToWrite) { - _database.WriteObjectList(folders, _userConfigurationService.StorageSettings.TablesSettings.FoldersTableName, FolderConfigs.WriteFunc); + _database.WriteObjectList(foldersToWrite, _userConfigurationService.StorageSettings.TablesSettings.FoldersTableName, FolderConfigs.WriteFunc); } - private void WriteAssets(List assets) + private void WriteAssets(List assetsToWrite) { - _database.WriteObjectList(assets, _userConfigurationService.StorageSettings.TablesSettings.AssetsTableName, AssetConfigs.WriteFunc); + _database.WriteObjectList(assetsToWrite, _userConfigurationService.StorageSettings.TablesSettings.AssetsTableName, AssetConfigs.WriteFunc); } - private void WriteSyncAssetsDirectoriesDefinitions(List definitions) + private void WriteSyncAssetsDirectoriesDefinitions(List definitionsToWrite) { _database.WriteObjectList( - definitions, + definitionsToWrite, _userConfigurationService.StorageSettings.TablesSettings.SyncAssetsDirectoriesDefinitionsTableName, SyncAssetsDirectoriesDefinitionConfigs.WriteFunc); } - private void WriteRecentTargetPaths(List recentTargetPaths) + private void WriteRecentTargetPaths(List recentTargetPathsToWrite) { - _database.WriteObjectList(recentTargetPaths, _userConfigurationService.StorageSettings.TablesSettings.RecentTargetPathsTableName, RecentPathsConfigs.WriteFunc); + _database.WriteObjectList(recentTargetPathsToWrite, _userConfigurationService.StorageSettings.TablesSettings.RecentTargetPathsTableName, RecentPathsConfigs.WriteFunc); } private Dictionary GetThumbnails(Folder? folder, out bool isNewFile) { isNewFile = false; - Dictionary? thumbnails = new(); + Dictionary? thumbnails = []; if (folder == null) { @@ -586,7 +586,7 @@ private Dictionary GetThumbnails(Folder? folder, out bool isNewF if (thumbnails == null) { - thumbnails = new Dictionary(); + thumbnails = []; isNewFile = true; } @@ -622,7 +622,7 @@ private void SaveThumbnails(Dictionary thumbnails, string thumbn private Folder? GetFolderById(Guid folderId) { - Folder? result = null; + Folder? result; lock (syncLock) { @@ -634,7 +634,7 @@ private void SaveThumbnails(Dictionary thumbnails, string thumbn private List GetAssetsByFolderId(Guid folderId) { - List result = new(); + List result; lock (syncLock) { @@ -646,7 +646,7 @@ private List GetAssetsByFolderId(Guid folderId) private Asset? GetAssetByFolderIdAndFileName(Guid folderId, string fileName) { - Asset? asset = null; + Asset? asset; lock (syncLock) { diff --git a/PhotoManager/PhotoManager.Infrastructure/Database/Database.cs b/PhotoManager/PhotoManager.Infrastructure/Database/Database.cs index e4c5fb27..eb57d140 100644 --- a/PhotoManager/PhotoManager.Infrastructure/Database/Database.cs +++ b/PhotoManager/PhotoManager.Infrastructure/Database/Database.cs @@ -26,7 +26,7 @@ public Database(IObjectListStorage objectListStorage, IBlobStorage blobStorage, BlobsDirectory = string.Empty; BackupsDirectory = string.Empty; Diagnostics = new Diagnostics(); - DataTablePropertiesDictionary = new(); + DataTablePropertiesDictionary = []; } public void Initialize(string dataDirectory, char separator, string tablesFolderName, string blobsFolderName) @@ -36,7 +36,7 @@ public void Initialize(string dataDirectory, char separator, string tablesFolder BlobsDirectory = GetBlobsDirectory(blobsFolderName); BackupsDirectory = GetBackupsDirectory(); Separator = separator; - DataTablePropertiesDictionary = new Dictionary(); + DataTablePropertiesDictionary = []; InitializeDirectory(); } @@ -57,7 +57,7 @@ public void SetDataTableProperties(DataTableProperties dataTableProperties) throw new ArgumentNullException(nameof(ColumnProperties.ColumnName), "All column properties should have a ColumnName"); } - IGrouping? group = dataTableProperties.ColumnProperties.GroupBy(c => c.ColumnName).Where(g => g.Count() > 1).FirstOrDefault(); + IGrouping? group = dataTableProperties.ColumnProperties.GroupBy(c => c.ColumnName).FirstOrDefault(g => g.Count() > 1); if (group != null) { @@ -158,8 +158,8 @@ public bool BackupExists(DateTime backupDate) public void DeleteOldBackups(ushort backupsToKeep) { string[] filesPaths = _backupStorage.GetBackupFilesPaths(BackupsDirectory); - filesPaths = filesPaths.OrderBy(f => f).ToArray(); - List deletedBackupFilePaths = new(); + filesPaths = [.. filesPaths.OrderBy(f => f)]; + List deletedBackupFilePaths = []; for (int i = 0; i < filesPaths.Length - backupsToKeep; i++) { diff --git a/PhotoManager/PhotoManager.Infrastructure/Database/Storage/BaseCsvStorage.cs b/PhotoManager/PhotoManager.Infrastructure/Database/Storage/BaseCsvStorage.cs index 9a660d66..9b9cade6 100644 --- a/PhotoManager/PhotoManager.Infrastructure/Database/Storage/BaseCsvStorage.cs +++ b/PhotoManager/PhotoManager.Infrastructure/Database/Storage/BaseCsvStorage.cs @@ -16,16 +16,16 @@ protected string[] GetValuesFromCsvLine(string line) { string[] fields = new string[Properties!.ColumnProperties.Length]; int startIndex = 0; - int endIndex; - string quoteAndSeparator = string.Format("{0}{1}", QUOTE, Separator); + string quoteAndSeparator = $"{QUOTE}{Separator}"; for (int i = 0; i < Properties.ColumnProperties.Length; i++) { bool escapeText = EscapeText(Properties.ColumnProperties[i].ColumnName); + int endIndex; if (escapeText) { - endIndex = line.IndexOf(quoteAndSeparator, startIndex); + endIndex = line.IndexOf(quoteAndSeparator, startIndex, StringComparison.Ordinal); startIndex++; } else diff --git a/PhotoManager/PhotoManager.Infrastructure/Database/Storage/ObjectListStorage.cs b/PhotoManager/PhotoManager.Infrastructure/Database/Storage/ObjectListStorage.cs index f31c7bdc..be6dc65a 100644 --- a/PhotoManager/PhotoManager.Infrastructure/Database/Storage/ObjectListStorage.cs +++ b/PhotoManager/PhotoManager.Infrastructure/Database/Storage/ObjectListStorage.cs @@ -6,7 +6,7 @@ public class ObjectListStorage : BaseCsvStorage, IObjectListStorage { public List ReadObjectList(string dataFilePath, Func mapObjectFromCsvFields, Diagnostics diagnostics) { - List list = new(); + List list = []; if (File.Exists(dataFilePath)) { @@ -28,8 +28,7 @@ public void WriteObjectList(string dataFilePath, List list, Func GetObjectListFromCsv(string csv, Func mapObjectFromCsvFields) { - List list = new(); - bool hasRecord; + List list = []; using (StringReader reader = new (csv)) { @@ -40,10 +39,9 @@ private List GetObjectListFromCsv(string csv, Func mapObjectF return list; } + bool hasRecord; if (Properties != null) { - string[] headers = GetValuesFromCsvLine(line); - do { line = reader.ReadLine(); @@ -64,8 +62,6 @@ private List GetObjectListFromCsv(string csv, Func mapObjectF } else { - string[] headers = line.Split(Separator); - do { line = reader.ReadLine(); diff --git a/PhotoManager/PhotoManager.Infrastructure/StorageService.cs b/PhotoManager/PhotoManager.Infrastructure/StorageService.cs index 57c0b9e8..00850b9f 100644 --- a/PhotoManager/PhotoManager.Infrastructure/StorageService.cs +++ b/PhotoManager/PhotoManager.Infrastructure/StorageService.cs @@ -13,7 +13,7 @@ public List GetSubDirectories(string directoryPath) public List GetRecursiveSubDirectories(string directoryPath) { - List result = new(); + List result = []; GetRecursiveSubDirectories(directoryPath, result); return result; diff --git a/PhotoManager/PhotoManager.Infrastructure/TablesConfig/AssetConfigs.cs b/PhotoManager/PhotoManager.Infrastructure/TablesConfig/AssetConfigs.cs index adb21326..40796219 100644 --- a/PhotoManager/PhotoManager.Infrastructure/TablesConfig/AssetConfigs.cs +++ b/PhotoManager/PhotoManager.Infrastructure/TablesConfig/AssetConfigs.cs @@ -6,23 +6,23 @@ public static class AssetConfigs { public static ColumnProperties[] ConfigureDataTable() { - return new ColumnProperties[] - { - new ColumnProperties { ColumnName = "FolderId" }, - new ColumnProperties { ColumnName = "FileName" }, - new ColumnProperties { ColumnName = "FileSize" }, - new ColumnProperties { ColumnName = "ImageRotation" }, - new ColumnProperties { ColumnName = "PixelWidth" }, - new ColumnProperties { ColumnName = "PixelHeight" }, - new ColumnProperties { ColumnName = "ThumbnailPixelWidth" }, - new ColumnProperties { ColumnName = "ThumbnailPixelHeight" }, - new ColumnProperties { ColumnName = "ThumbnailCreationDateTime" }, - new ColumnProperties { ColumnName = "Hash" }, - new ColumnProperties { ColumnName = "AssetCorruptedMessage" }, - new ColumnProperties { ColumnName = "IsAssetCorrupted" }, - new ColumnProperties { ColumnName = "AssetRotatedMessage" }, - new ColumnProperties { ColumnName = "IsAssetRotated" } - }; + return + [ + new() { ColumnName = "FolderId" }, + new() { ColumnName = "FileName" }, + new() { ColumnName = "FileSize" }, + new() { ColumnName = "ImageRotation" }, + new() { ColumnName = "PixelWidth" }, + new() { ColumnName = "PixelHeight" }, + new() { ColumnName = "ThumbnailPixelWidth" }, + new() { ColumnName = "ThumbnailPixelHeight" }, + new() { ColumnName = "ThumbnailCreationDateTime" }, + new() { ColumnName = "Hash" }, + new() { ColumnName = "AssetCorruptedMessage" }, + new() { ColumnName = "IsAssetCorrupted" }, + new() { ColumnName = "AssetRotatedMessage" }, + new() { ColumnName = "IsAssetRotated" } + ]; } public static Asset ReadFunc(string[] values) @@ -37,6 +37,7 @@ public static Asset ReadFunc(string[] values) return new Asset { FolderId = new Guid(values[0]), + Folder = new() { Path = "" }, // Initialised later FileName = values[1], FileSize = long.Parse(values[2]), ImageRotation = (Rotation)Enum.Parse(typeof(Rotation), values[3]), diff --git a/PhotoManager/PhotoManager.Infrastructure/UserConfigurationService.cs b/PhotoManager/PhotoManager.Infrastructure/UserConfigurationService.cs index 098d53db..92f95f7a 100644 --- a/PhotoManager/PhotoManager.Infrastructure/UserConfigurationService.cs +++ b/PhotoManager/PhotoManager.Infrastructure/UserConfigurationService.cs @@ -32,7 +32,7 @@ public UserConfigurationService(IConfigurationRoot configuration) public void SetAsWallpaper(Asset asset, WallpaperStyle style) { - RegistryKey? key = Registry.CurrentUser?.OpenSubKey(@"Control Panel\Desktop", true); + RegistryKey? key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); switch (style) { @@ -102,10 +102,7 @@ public AboutInformation GetAboutInformation(Assembly assembly) public string[] GetRootCatalogFolderPaths() { - List rootPaths = new() - { - PathSettings.AssetsDirectory - }; + List rootPaths = [PathSettings.AssetsDirectory]; return rootPaths.ToArray(); } diff --git a/PhotoManager/PhotoManager.Tests/CatalogAssetsAsyncAsserts.cs b/PhotoManager/PhotoManager.Tests/CatalogAssetsAsyncAsserts.cs index 65079d32..fba0e012 100644 --- a/PhotoManager/PhotoManager.Tests/CatalogAssetsAsyncAsserts.cs +++ b/PhotoManager/PhotoManager.Tests/CatalogAssetsAsyncAsserts.cs @@ -352,7 +352,7 @@ private static void AssertAssetFromDatabaseValidity(Asset assetFromDatabase, Ass Assert.AreEqual(expectedAsset.FileName, assetFromDatabase.FileName); Assert.AreEqual(folderId, assetFromDatabase.FolderId); - Assert.IsNull(assetFromDatabase.Folder); // Not saved in Db, loaded at the runtime + Assert.AreEqual(string.Empty, assetFromDatabase.Folder.Path); // Not saved in Db, loaded at the runtime Assert.AreEqual(expectedAsset.FileSize, assetFromDatabase.FileSize); Assert.AreEqual(expectedAsset.PixelWidth, assetFromDatabase.PixelWidth); Assert.AreEqual(expectedAsset.PixelHeight, assetFromDatabase.PixelHeight); @@ -615,4 +615,4 @@ public static void RemoveDatabaseBackup( File.Delete(backupFilePath); Assert.IsFalse(File.Exists(backupFilePath)); } -} \ No newline at end of file +} diff --git a/PhotoManager/PhotoManager.Tests/Integration/Application/ApplicationCatalogAssetsAsyncTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Application/ApplicationCatalogAssetsAsyncTests.cs index bcbe84af..a71f5be8 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Application/ApplicationCatalogAssetsAsyncTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Application/ApplicationCatalogAssetsAsyncTests.cs @@ -62,6 +62,7 @@ public void SetUp() { _asset1 = new() { + Folder = new() { Path = "" }, FileName = "Image 1_duplicate.jpg", FileSize = 29857, PixelHeight = 720, @@ -78,6 +79,7 @@ public void SetUp() }; _asset2 = new() { + Folder = new() { Path = "" }, FileName = "Image 9.png", FileSize = 126277, PixelHeight = 720, @@ -94,6 +96,7 @@ public void SetUp() }; _asset3 = new() { + Folder = new() { Path = "" }, FileName = "Image 9_duplicate.png", FileSize = 126277, PixelHeight = 720, @@ -110,6 +113,7 @@ public void SetUp() }; _asset4 = new() { + Folder = new() { Path = "" }, FileName = "Image_11.heic", FileSize = 1411940, PixelHeight = 4032, @@ -126,6 +130,7 @@ public void SetUp() }; _asset1Temp = new() { + Folder = new() { Path = "" }, FileName = "Image 1_duplicate_copied.jpg", FileSize = 29857, PixelHeight = 720, @@ -142,6 +147,7 @@ public void SetUp() }; _asset2Temp = new() { + Folder = new() { Path = "" }, FileName = "Image 1.jpg", FileSize = 29857, PixelHeight = 720, @@ -158,6 +164,7 @@ public void SetUp() }; _asset3Temp = new() { + Folder = new() { Path = "" }, FileName = "Homer.gif", FileSize = 64123, PixelHeight = 320, @@ -174,6 +181,7 @@ public void SetUp() }; _asset4Temp = new() { + Folder = new() { Path = "" }, FileName = "Homer.jpg", FileSize = 6599, PixelHeight = 180, @@ -190,6 +198,7 @@ public void SetUp() }; _asset5Temp = new() { + Folder = new() { Path = "" }, FileName = "HomerDuplicated.jpg", FileSize = 6599, PixelHeight = 180, @@ -5529,8 +5538,8 @@ public async Task CatalogAssetsAsync_AssetsAndRootCatalogFolderExistsAndOneFolde Folder? folder2Updated = _testableAssetRepository!.GetFolderByPath(tempDirectory); Assert.IsNull(folder2Updated); - Dictionary> folderToAssetsMappingFourthSync = new(); - Dictionary assetNameToByteSizeMappingFourthSync = new(); + Dictionary> folderToAssetsMappingFourthSync = []; + Dictionary assetNameToByteSizeMappingFourthSync = []; Assert.IsTrue(_testableAssetRepository!.BackupExists()); diff --git a/PhotoManager/PhotoManager.Tests/Integration/Domain/AssetCreationServiceTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Domain/AssetCreationServiceTests.cs index ebb6ff66..18e5afcf 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Domain/AssetCreationServiceTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Domain/AssetCreationServiceTests.cs @@ -517,6 +517,7 @@ public void CreateAsset_PictureAndBasicHashTypeAndDifferentThumbnailSettings_Ret Asset expectedAsset = new() { + Folder = new() { Path = "" }, FileName = "Image 1.jpg", FileSize = 29857, PixelHeight = 720, @@ -594,6 +595,7 @@ public void CreateAsset_PortraitPictureAndBasicHashTypeAndDifferentThumbnailSett Asset expectedAsset = new() { + Folder = new() { Path = "" }, FileName = "Image 10 portrait.png", FileSize = 153318, PixelHeight = 1280, @@ -670,6 +672,7 @@ public void CreateAsset_HeicPictureAndBasicHashTypeAndDifferentThumbnailSettings Asset expectedAsset = new() { + Folder = new() { Path = "" }, FileName = "Image_11.heic", FileSize = 1411940, PixelHeight = 4032, @@ -734,6 +737,7 @@ public void CreateAsset_PictureAndBasicHashTypeAndCreatingTwiceSameImageInDiffer Asset expectedAsset = new() { + Folder = new() { Path = "" }, FileName = "Image 1.jpg", FileSize = 29857, PixelHeight = 720, @@ -857,6 +861,7 @@ public void CreateAsset_PictureAndBasicHashTypeAndCreatingTwiceSameImage_DoesNot Asset expectedAsset = new() { + Folder = new() { Path = "" }, FileName = "Image 1.jpg", FileSize = 29857, PixelHeight = 720, @@ -991,6 +996,7 @@ public void CreateAsset_CorruptedPictureBasicHashType_ReturnsAssetWithCorruptedM { Asset expectedAsset = new() { + Folder = new() { Path = "" }, FileName = corruptedAssetFileName, FileSize = fileSize, PixelHeight = pixelHeight, @@ -1808,6 +1814,7 @@ public void CreateAsset_VideoAndBasicHashTypeButAnotherImageAlreadyExistsInTheOu Asset expectedAsset = new() { + Folder = new() { Path = "" }, FileName = firstFrameFileName, FileSize = 29857, PixelHeight = 720, diff --git a/PhotoManager/PhotoManager.Tests/Integration/Domain/CatalogAssets/CatalogAssetsServiceMultipleInstancesTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Domain/CatalogAssets/CatalogAssetsServiceMultipleInstancesTests.cs index 51573eb5..9b8dd5e9 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Domain/CatalogAssets/CatalogAssetsServiceMultipleInstancesTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Domain/CatalogAssets/CatalogAssetsServiceMultipleInstancesTests.cs @@ -62,6 +62,7 @@ public void SetUp() { _asset1 = new() { + Folder = new() { Path = "" }, FileName = "Image 1_duplicate.jpg", FileSize = 29857, PixelHeight = 720, @@ -78,6 +79,7 @@ public void SetUp() }; _asset2 = new() { + Folder = new() { Path = "" }, FileName = "Image 9.png", FileSize = 126277, PixelHeight = 720, @@ -94,6 +96,7 @@ public void SetUp() }; _asset3 = new() { + Folder = new() { Path = "" }, FileName = "Image 9_duplicate.png", FileSize = 126277, PixelHeight = 720, @@ -110,6 +113,7 @@ public void SetUp() }; _asset4 = new() { + Folder = new() { Path = "" }, FileName = "Image_11.heic", FileSize = 1411940, PixelHeight = 4032, @@ -126,6 +130,7 @@ public void SetUp() }; _asset1Temp = new() { + Folder = new() { Path = "" }, FileName = "Image 1_duplicate_copied.jpg", FileSize = 29857, PixelHeight = 720, @@ -142,6 +147,7 @@ public void SetUp() }; _asset2Temp = new() { + Folder = new() { Path = "" }, FileName = "Image 1.jpg", FileSize = 29857, PixelHeight = 720, @@ -158,6 +164,7 @@ public void SetUp() }; _asset3Temp = new() { + Folder = new() { Path = "" }, FileName = "Homer.gif", FileSize = 64123, PixelHeight = 320, @@ -174,6 +181,7 @@ public void SetUp() }; _asset4Temp = new() { + Folder = new() { Path = "" }, FileName = "Homer.jpg", FileSize = 6599, PixelHeight = 180, @@ -190,6 +198,7 @@ public void SetUp() }; _asset5Temp = new() { + Folder = new() { Path = "" }, FileName = "HomerDuplicated.jpg", FileSize = 6599, PixelHeight = 180, diff --git a/PhotoManager/PhotoManager.Tests/Integration/Domain/CatalogAssets/CatalogAssetsServiceTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Domain/CatalogAssets/CatalogAssetsServiceTests.cs index ad6bdb12..66623514 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Domain/CatalogAssets/CatalogAssetsServiceTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Domain/CatalogAssets/CatalogAssetsServiceTests.cs @@ -62,6 +62,7 @@ public void SetUp() { _asset1 = new() { + Folder = new() { Path = "" }, FileName = "Image 1_duplicate.jpg", FileSize = 29857, PixelHeight = 720, @@ -78,6 +79,7 @@ public void SetUp() }; _asset2 = new() { + Folder = new() { Path = "" }, FileName = "Image 9.png", FileSize = 126277, PixelHeight = 720, @@ -94,6 +96,7 @@ public void SetUp() }; _asset3 = new() { + Folder = new() { Path = "" }, FileName = "Image 9_duplicate.png", FileSize = 126277, PixelHeight = 720, @@ -110,6 +113,7 @@ public void SetUp() }; _asset4 = new() { + Folder = new() { Path = "" }, FileName = "Image_11.heic", FileSize = 1411940, PixelHeight = 4032, @@ -126,6 +130,7 @@ public void SetUp() }; _asset1Temp = new() { + Folder = new() { Path = "" }, FileName = "Image 1_duplicate_copied.jpg", FileSize = 29857, PixelHeight = 720, @@ -142,6 +147,7 @@ public void SetUp() }; _asset2Temp = new() { + Folder = new() { Path = "" }, FileName = "Image 1.jpg", FileSize = 29857, PixelHeight = 720, @@ -158,6 +164,7 @@ public void SetUp() }; _asset3Temp = new() { + Folder = new() { Path = "" }, FileName = "Homer.gif", FileSize = 64123, PixelHeight = 320, @@ -174,6 +181,7 @@ public void SetUp() }; _asset4Temp = new() { + Folder = new() { Path = "" }, FileName = "Homer.jpg", FileSize = 6599, PixelHeight = 180, @@ -190,6 +198,7 @@ public void SetUp() }; _asset5Temp = new() { + Folder = new() { Path = "" }, FileName = "HomerDuplicated.jpg", FileSize = 6599, PixelHeight = 180, @@ -5525,8 +5534,8 @@ public async Task CatalogAssetsAsync_AssetsAndRootCatalogFolderExistsAndOneFolde Folder? folder2Updated = _testableAssetRepository!.GetFolderByPath(tempDirectory); Assert.IsNull(folder2Updated); - Dictionary> folderToAssetsMappingFourthSync = new(); - Dictionary assetNameToByteSizeMappingFourthSync = new(); + Dictionary> folderToAssetsMappingFourthSync = []; + Dictionary assetNameToByteSizeMappingFourthSync = []; Assert.IsTrue(_testableAssetRepository!.BackupExists()); diff --git a/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceTests.cs index b2a4e787..74952ae3 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceTests.cs @@ -3,9 +3,9 @@ [TestFixture] public class FindDuplicatedAssetsServiceTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; + private string? _backupPath; private FindDuplicatedAssetsService? _findDuplicatedAssetsService; private AssetRepository? _assetRepository; @@ -13,23 +13,23 @@ public class FindDuplicatedAssetsServiceTests private Mock? _storageServiceMock; private Mock? _configurationRootMock; - private Asset? asset1; - private Asset? asset2; - private Asset? asset3; - private Asset? asset4; - private Asset? asset5; + private Asset? _asset1; + private Asset? _asset2; + private Asset? _asset3; + private Asset? _asset4; + private Asset? _asset5; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -41,9 +41,10 @@ public void SetUp() _storageService = new (userConfigurationService); _findDuplicatedAssetsService = new (_assetRepository, _storageService, userConfigurationService); - asset1 = new() + _asset1 = new() { FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "Image 1.jpg", FileSize = 363888, ImageRotation = Rotation.Rotate0, @@ -58,9 +59,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset2 = new() + _asset2 = new() { FolderId = new Guid("886283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "Image 9.png", FileSize = 4602393, ImageRotation = Rotation.Rotate90, @@ -75,9 +77,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset3 = new() + _asset3 = new() { FolderId = new Guid("886283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "Image 1_duplicate.jpg", FileSize = 363888, ImageRotation = Rotation.Rotate0, @@ -92,9 +95,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset4 = new() + _asset4 = new() { FolderId = new Guid("886283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "Image 9_duplicate.png", FileSize = 4602393, ImageRotation = Rotation.Rotate90, @@ -109,9 +113,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset5 = new() + _asset5 = new() { FolderId = new Guid("886283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "Image_11.heic", FileSize = 2247285, ImageRotation = Rotation.Rotate0, @@ -131,28 +136,28 @@ public void SetUp() [Test] public void GetDuplicatedAssets_DuplicatedAssetsFound_ReturnsListOfDuplicatedSets() { - string destinationPath1 = Path.Combine(dataDirectory!, "Duplicates\\DestinationToCopy1"); - string destinationPath2 = Path.Combine(dataDirectory!, "Duplicates\\DestinationToCopy2"); + string destinationPath1 = Path.Combine(_dataDirectory!, "Duplicates\\DestinationToCopy1"); + string destinationPath2 = Path.Combine(_dataDirectory!, "Duplicates\\DestinationToCopy2"); try { Directory.CreateDirectory(destinationPath1); Directory.CreateDirectory(destinationPath2); - string sourcePath1 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); - string sourcePath2 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); + string sourcePath1 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); + string sourcePath2 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); - string asset1DestinationPath = Path.Combine(destinationPath1, asset1!.FileName); - string asset2DestinationPath = Path.Combine(destinationPath2, asset2!.FileName); - string asset3DestinationPath = Path.Combine(destinationPath2, asset3!.FileName); - string asset4DestinationPath = Path.Combine(destinationPath2, asset4!.FileName); - string asset5DestinationPath = Path.Combine(destinationPath2, asset5!.FileName); + string asset1DestinationPath = Path.Combine(destinationPath1, _asset1!.FileName); + string asset2DestinationPath = Path.Combine(destinationPath2, _asset2!.FileName); + string asset3DestinationPath = Path.Combine(destinationPath2, _asset3!.FileName); + string asset4DestinationPath = Path.Combine(destinationPath2, _asset4!.FileName); + string asset5DestinationPath = Path.Combine(destinationPath2, _asset5!.FileName); - File.Copy(Path.Combine(sourcePath1, asset1!.FileName), asset1DestinationPath); - File.Copy(Path.Combine(sourcePath2, asset2!.FileName), asset2DestinationPath); - File.Copy(Path.Combine(sourcePath2, asset3!.FileName), asset3DestinationPath); - File.Copy(Path.Combine(sourcePath2, asset4!.FileName), asset4DestinationPath); - File.Copy(Path.Combine(sourcePath2, asset5!.FileName), asset5DestinationPath); + File.Copy(Path.Combine(sourcePath1, _asset1!.FileName), asset1DestinationPath); + File.Copy(Path.Combine(sourcePath2, _asset2!.FileName), asset2DestinationPath); + File.Copy(Path.Combine(sourcePath2, _asset3!.FileName), asset3DestinationPath); + File.Copy(Path.Combine(sourcePath2, _asset4!.FileName), asset4DestinationPath); + File.Copy(Path.Combine(sourcePath2, _asset5!.FileName), asset5DestinationPath); DateTime oldDateTime1 = DateTime.Now.AddDays(-1); DateTime oldDateTime2 = DateTime.Now.AddDays(-5); @@ -166,20 +171,20 @@ public void GetDuplicatedAssets_DuplicatedAssetsFound_ReturnsListOfDuplicatedSet Folder folder1 = new() { Path = destinationPath1 }; Folder folder2 = new() { Path = destinationPath2 }; - asset1!.Folder = folder1; - asset2!.Folder = folder2; - asset3!.Folder = folder2; - asset4!.Folder = folder2; - asset5!.Folder = folder2; + _asset1!.Folder = folder1; + _asset2!.Folder = folder2; + _asset3!.Folder = folder2; + _asset4!.Folder = folder2; + _asset5!.Folder = folder2; - byte[] assetData1 = new byte[] { 1, 2, 3 }; - byte[] assetData2 = Array.Empty(); + byte[] assetData1 = [1, 2, 3]; + byte[] assetData2 = []; - _assetRepository!.AddAsset(asset1!, assetData1); - _assetRepository.AddAsset(asset2!, assetData2); - _assetRepository.AddAsset(asset3!, assetData1); - _assetRepository.AddAsset(asset4!, assetData2); - _assetRepository.AddAsset(asset5!, assetData1); + _assetRepository!.AddAsset(_asset1!, assetData1); + _assetRepository.AddAsset(_asset2!, assetData2); + _assetRepository.AddAsset(_asset3!, assetData1); + _assetRepository.AddAsset(_asset4!, assetData2); + _assetRepository.AddAsset(_asset5!, assetData1); List> duplicatedAssets = _findDuplicatedAssetsService!.GetDuplicatedAssets(); @@ -192,35 +197,35 @@ public void GetDuplicatedAssets_DuplicatedAssetsFound_ReturnsListOfDuplicatedSet Assert.AreEqual(2, firstDuplicatedAssetsSet.Count); Assert.AreEqual(2, secondDuplicatedAssetsSet.Count); - Asset? duplicatedAsset1 = firstDuplicatedAssetsSet.FirstOrDefault(x => x.FileName == asset1.FileName); - Asset? duplicatedAsset3 = firstDuplicatedAssetsSet.FirstOrDefault(x => x.FileName == asset3.FileName); + Asset? duplicatedAsset1 = firstDuplicatedAssetsSet.FirstOrDefault(x => x.FileName == _asset1.FileName); + Asset? duplicatedAsset3 = firstDuplicatedAssetsSet.FirstOrDefault(x => x.FileName == _asset3.FileName); DateTime actualDate = DateTime.Now.Date; Assert.IsNotNull(duplicatedAsset1); Assert.IsNotNull(duplicatedAsset3); - Assert.AreEqual(asset1.FileName, duplicatedAsset1!.FileName); - Assert.AreEqual(actualDate, duplicatedAsset1!.FileCreationDateTime.Date); - Assert.AreEqual(oldDateTime1.Date, duplicatedAsset1!.FileModificationDateTime.Date); - Assert.AreEqual(asset3.FileName, duplicatedAsset3!.FileName); - Assert.AreEqual(actualDate, duplicatedAsset3!.FileCreationDateTime.Date); - Assert.AreEqual(oldDateTime2.Date, duplicatedAsset3!.FileModificationDateTime.Date); + Assert.AreEqual(_asset1.FileName, duplicatedAsset1!.FileName); + Assert.AreEqual(actualDate, duplicatedAsset1.FileCreationDateTime.Date); + Assert.AreEqual(oldDateTime1.Date, duplicatedAsset1.FileModificationDateTime.Date); + Assert.AreEqual(_asset3.FileName, duplicatedAsset3!.FileName); + Assert.AreEqual(actualDate, duplicatedAsset3.FileCreationDateTime.Date); + Assert.AreEqual(oldDateTime2.Date, duplicatedAsset3.FileModificationDateTime.Date); - Asset? duplicatedAsset2 = secondDuplicatedAssetsSet.FirstOrDefault(x => x.FileName == asset2.FileName); - Asset? duplicatedAsset4 = secondDuplicatedAssetsSet.FirstOrDefault(x => x.FileName == asset4.FileName); + Asset? duplicatedAsset2 = secondDuplicatedAssetsSet.FirstOrDefault(x => x.FileName == _asset2.FileName); + Asset? duplicatedAsset4 = secondDuplicatedAssetsSet.FirstOrDefault(x => x.FileName == _asset4.FileName); Assert.IsNotNull(duplicatedAsset2); Assert.IsNotNull(duplicatedAsset4); - Assert.AreEqual(asset2.FileName, duplicatedAsset2!.FileName); - Assert.AreEqual(actualDate, duplicatedAsset2!.FileCreationDateTime.Date); - Assert.AreEqual(oldDateTime1.Date, duplicatedAsset2!.FileModificationDateTime.Date); - Assert.AreEqual(asset4.FileName, duplicatedAsset4!.FileName); - Assert.AreEqual(actualDate, duplicatedAsset4!.FileCreationDateTime.Date); - Assert.AreEqual(oldDateTime2.Date, duplicatedAsset4!.FileModificationDateTime.Date); + Assert.AreEqual(_asset2.FileName, duplicatedAsset2!.FileName); + Assert.AreEqual(actualDate, duplicatedAsset2.FileCreationDateTime.Date); + Assert.AreEqual(oldDateTime1.Date, duplicatedAsset2.FileModificationDateTime.Date); + Assert.AreEqual(_asset4.FileName, duplicatedAsset4!.FileName); + Assert.AreEqual(actualDate, duplicatedAsset4.FileCreationDateTime.Date); + Assert.AreEqual(oldDateTime2.Date, duplicatedAsset4.FileModificationDateTime.Date); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); Directory.Delete(destinationPath1, true); Directory.Delete(destinationPath2, true); } @@ -229,24 +234,24 @@ public void GetDuplicatedAssets_DuplicatedAssetsFound_ReturnsListOfDuplicatedSet [Test] public void GetDuplicatedAssets_MultiplesAssetsSameHash_ReturnsListOfDuplicatedSets() { - string destinationPath = Path.Combine(dataDirectory!, "Duplicates\\DestinationToCopy"); + string destinationPath = Path.Combine(_dataDirectory!, "Duplicates\\DestinationToCopy"); try { Directory.CreateDirectory(destinationPath); - string hash = "f8d5cf6deda198be0f181dd7cabfe74cb14c43426c867f0ae855d9e844651e2d7ce4833c178912d5bc7be600cfdd18d5ba19f45988a0c6943b4476a90295e960"; - string sourcePath = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); + const string hash = "f8d5cf6deda198be0f181dd7cabfe74cb14c43426c867f0ae855d9e844651e2d7ce4833c178912d5bc7be600cfdd18d5ba19f45988a0c6943b4476a90295e960"; + string sourcePath = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); - string asset2DestinationPath = Path.Combine(destinationPath, asset2!.FileName); - string asset3DestinationPath = Path.Combine(destinationPath, asset3!.FileName); - string asset4DestinationPath = Path.Combine(destinationPath, asset4!.FileName); - string asset5DestinationPath = Path.Combine(destinationPath, asset5!.FileName); + string asset2DestinationPath = Path.Combine(destinationPath, _asset2!.FileName); + string asset3DestinationPath = Path.Combine(destinationPath, _asset3!.FileName); + string asset4DestinationPath = Path.Combine(destinationPath, _asset4!.FileName); + string asset5DestinationPath = Path.Combine(destinationPath, _asset5!.FileName); - File.Copy(Path.Combine(sourcePath, asset2!.FileName), asset2DestinationPath); - File.Copy(Path.Combine(sourcePath, asset3!.FileName), asset3DestinationPath); - File.Copy(Path.Combine(sourcePath, asset4!.FileName), asset4DestinationPath); - File.Copy(Path.Combine(sourcePath, asset5!.FileName), asset5DestinationPath); + File.Copy(Path.Combine(sourcePath, _asset2!.FileName), asset2DestinationPath); + File.Copy(Path.Combine(sourcePath, _asset3!.FileName), asset3DestinationPath); + File.Copy(Path.Combine(sourcePath, _asset4!.FileName), asset4DestinationPath); + File.Copy(Path.Combine(sourcePath, _asset5!.FileName), asset5DestinationPath); DateTime oldDateTime1 = DateTime.Now.AddDays(-1); DateTime oldDateTime2 = DateTime.Now.AddDays(-5); @@ -258,21 +263,21 @@ public void GetDuplicatedAssets_MultiplesAssetsSameHash_ReturnsListOfDuplicatedS Folder folder = new() { Path = destinationPath }; - asset2!.Folder = folder; - asset2.Hash = hash; - asset3!.Folder = folder; - asset3.Hash = hash; - asset4!.Folder = folder; - asset4.Hash = hash; - asset5!.Folder = folder; - asset5.Hash = hash; + _asset2!.Folder = folder; + _asset2.Hash = hash; + _asset3!.Folder = folder; + _asset3.Hash = hash; + _asset4!.Folder = folder; + _asset4.Hash = hash; + _asset5!.Folder = folder; + _asset5.Hash = hash; - byte[] assetData = new byte[] { 1, 2, 3 }; + byte[] assetData = [1, 2, 3]; - _assetRepository!.AddAsset(asset2!, assetData); - _assetRepository.AddAsset(asset3!, assetData); - _assetRepository.AddAsset(asset4!, assetData); - _assetRepository.AddAsset(asset5!, assetData); + _assetRepository!.AddAsset(_asset2!, assetData); + _assetRepository.AddAsset(_asset3!, assetData); + _assetRepository.AddAsset(_asset4!, assetData); + _assetRepository.AddAsset(_asset5!, assetData); List> duplicatedAssets = _findDuplicatedAssetsService!.GetDuplicatedAssets(); @@ -283,10 +288,10 @@ public void GetDuplicatedAssets_MultiplesAssetsSameHash_ReturnsListOfDuplicatedS Assert.AreEqual(4, duplicatedAssetsSet.Count); - Asset? duplicatedAsset2 = duplicatedAssetsSet.FirstOrDefault(x => x.FileName == asset2.FileName); - Asset? duplicatedAsset3 = duplicatedAssetsSet.FirstOrDefault(x => x.FileName == asset3.FileName); - Asset? duplicatedAsset4 = duplicatedAssetsSet.FirstOrDefault(x => x.FileName == asset4.FileName); - Asset? duplicatedAsset5 = duplicatedAssetsSet.FirstOrDefault(x => x.FileName == asset5.FileName); + Asset? duplicatedAsset2 = duplicatedAssetsSet.FirstOrDefault(x => x.FileName == _asset2.FileName); + Asset? duplicatedAsset3 = duplicatedAssetsSet.FirstOrDefault(x => x.FileName == _asset3.FileName); + Asset? duplicatedAsset4 = duplicatedAssetsSet.FirstOrDefault(x => x.FileName == _asset4.FileName); + Asset? duplicatedAsset5 = duplicatedAssetsSet.FirstOrDefault(x => x.FileName == _asset5.FileName); DateTime actualDate = DateTime.Now.Date; @@ -295,25 +300,25 @@ public void GetDuplicatedAssets_MultiplesAssetsSameHash_ReturnsListOfDuplicatedS Assert.IsNotNull(duplicatedAsset4); Assert.IsNotNull(duplicatedAsset5); - Assert.AreEqual(asset2.FileName, duplicatedAsset2!.FileName); - Assert.AreEqual(actualDate, duplicatedAsset2!.FileCreationDateTime.Date); - Assert.AreEqual(oldDateTime1.Date, duplicatedAsset2!.FileModificationDateTime.Date); + Assert.AreEqual(_asset2.FileName, duplicatedAsset2!.FileName); + Assert.AreEqual(actualDate, duplicatedAsset2.FileCreationDateTime.Date); + Assert.AreEqual(oldDateTime1.Date, duplicatedAsset2.FileModificationDateTime.Date); - Assert.AreEqual(asset3.FileName, duplicatedAsset3!.FileName); - Assert.AreEqual(actualDate, duplicatedAsset3!.FileCreationDateTime.Date); - Assert.AreEqual(oldDateTime2.Date, duplicatedAsset3!.FileModificationDateTime.Date); + Assert.AreEqual(_asset3.FileName, duplicatedAsset3!.FileName); + Assert.AreEqual(actualDate, duplicatedAsset3.FileCreationDateTime.Date); + Assert.AreEqual(oldDateTime2.Date, duplicatedAsset3.FileModificationDateTime.Date); - Assert.AreEqual(asset4.FileName, duplicatedAsset4!.FileName); - Assert.AreEqual(actualDate, duplicatedAsset4!.FileCreationDateTime.Date); - Assert.AreEqual(oldDateTime2.Date, duplicatedAsset4!.FileModificationDateTime.Date); + Assert.AreEqual(_asset4.FileName, duplicatedAsset4!.FileName); + Assert.AreEqual(actualDate, duplicatedAsset4.FileCreationDateTime.Date); + Assert.AreEqual(oldDateTime2.Date, duplicatedAsset4.FileModificationDateTime.Date); - Assert.AreEqual(asset5.FileName, duplicatedAsset5!.FileName); - Assert.AreEqual(actualDate, duplicatedAsset5!.FileCreationDateTime.Date); - Assert.AreEqual(oldDateTime1.Date, duplicatedAsset5!.FileModificationDateTime.Date); + Assert.AreEqual(_asset5.FileName, duplicatedAsset5!.FileName); + Assert.AreEqual(actualDate, duplicatedAsset5.FileCreationDateTime.Date); + Assert.AreEqual(oldDateTime1.Date, duplicatedAsset5.FileModificationDateTime.Date); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); Directory.Delete(destinationPath, true); } } @@ -323,19 +328,19 @@ public void GetDuplicatedAssets_DuplicatesButOneFileDoesNotExist_ReturnsEmptyLis { try { - string folderPath1 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "NewFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "NewFolder2"); Folder folder1 = new() { Path = folderPath1 }; Folder folder2 = new() { Path = folderPath2 }; - asset1!.Folder = folder1; - asset3!.Folder = folder2; + _asset1!.Folder = folder1; + _asset3!.Folder = folder2; - byte[] assetData1 = new byte[] { 1, 2, 3 }; + byte[] assetData1 = [1, 2, 3]; - _assetRepository!.AddAsset(asset1!, assetData1); - _assetRepository.AddAsset(asset3!, assetData1); + _assetRepository!.AddAsset(_asset1!, assetData1); + _assetRepository.AddAsset(_asset3!, assetData1); List> duplicatedAssets = _findDuplicatedAssetsService!.GetDuplicatedAssets(); @@ -343,7 +348,7 @@ public void GetDuplicatedAssets_DuplicatesButOneFileDoesNotExist_ReturnsEmptyLis } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } @@ -352,26 +357,26 @@ public void GetDuplicatedAssets_FilesDoNotExist_ReturnsEmptyList() { try { - string folderPath1 = Path.Combine(dataDirectory!, "NewFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "NewFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "NewFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "NewFolder2"); Folder folder1 = new() { Path = folderPath1 }; Folder folder2 = new() { Path = folderPath2 }; - asset1!.Folder = folder1; - asset2!.Folder = folder2; - asset3!.Folder = folder2; - asset4!.Folder = folder2; - asset5!.Folder = folder2; + _asset1!.Folder = folder1; + _asset2!.Folder = folder2; + _asset3!.Folder = folder2; + _asset4!.Folder = folder2; + _asset5!.Folder = folder2; - byte[] assetData1 = new byte[] { 1, 2, 3 }; - byte[] assetData2 = Array.Empty(); + byte[] assetData1 = [1, 2, 3]; + byte[] assetData2 = []; - _assetRepository!.AddAsset(asset1!, assetData1); - _assetRepository.AddAsset(asset2!, assetData2); - _assetRepository.AddAsset(asset3!, assetData1); - _assetRepository.AddAsset(asset4!, assetData2); - _assetRepository.AddAsset(asset5!, assetData1); + _assetRepository!.AddAsset(_asset1!, assetData1); + _assetRepository.AddAsset(_asset2!, assetData2); + _assetRepository.AddAsset(_asset3!, assetData1); + _assetRepository.AddAsset(_asset4!, assetData2); + _assetRepository.AddAsset(_asset5!, assetData1); List> duplicatedAssets = _findDuplicatedAssetsService!.GetDuplicatedAssets(); @@ -379,7 +384,7 @@ public void GetDuplicatedAssets_FilesDoNotExist_ReturnsEmptyList() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } @@ -394,7 +399,7 @@ public void GetDuplicatedAssets_NoAssets_ReturnsEmptyList() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } @@ -403,18 +408,18 @@ public void GetDuplicatedAssets_NoDuplicatedAssets_ReturnsEmptyList() { try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); Folder folder = new() { Path = folderPath }; - asset1!.Folder = folder; - asset2!.Folder = folder; + _asset1!.Folder = folder; + _asset2!.Folder = folder; - byte[] assetData1 = new byte[] { 1, 2, 3 }; - byte[] assetData2 = Array.Empty(); + byte[] assetData1 = [1, 2, 3]; + byte[] assetData2 = []; - _assetRepository!.AddAsset(asset1!, assetData1); - _assetRepository.AddAsset(asset2!, assetData2); + _assetRepository!.AddAsset(_asset1!, assetData1); + _assetRepository.AddAsset(_asset2!, assetData2); List> duplicatedAssets = _findDuplicatedAssetsService!.GetDuplicatedAssets(); @@ -422,7 +427,7 @@ public void GetDuplicatedAssets_NoDuplicatedAssets_ReturnsEmptyList() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceThumbnailNotDuplicatesTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceThumbnailNotDuplicatesTests.cs index 1939ceb2..3a63b500 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceThumbnailNotDuplicatesTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceThumbnailNotDuplicatesTests.cs @@ -3,66 +3,66 @@ [TestFixture] public class FindDuplicatedAssetsServiceThumbnailNotDuplicatesTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; private AssetRepository? _assetRepository; private StorageService? _storageService; private Mock? _storageServiceMock; private Mock? _configurationRootMock; - private Asset? asset1; - private Asset? asset2; - private Asset? asset3; - private Asset? asset4; - private Asset? asset5; - private Asset? asset6; - private Asset? asset7; - private Asset? asset8; - - private readonly string asset1336Hash = "fb0bb3887c28d022113c5c52a65f9da14eab0806842f902b618806dedeb7c53da1ed26ae5bcaf9a358e81efead71c4807ea38054e44f426857f8bf2c1fd1c7aa"; - private readonly string asset1337Hash = "4435b989c27e16be1bf583fb6bb4b3474bd55735447a52e663482703553c5ce38947b17f88a2bfd9662956b24575e7578f7b7d921fdba2273d6046ee765eec36"; - private readonly string asset1349Hash = "715188ad52e6bd3dc9dfb7c0469038d92638dae94b7818f6326da093505f18b60d277831d451e259809af7dad3149cc2babf7442d1956ceca911f75180365cec"; - private readonly string asset1350Hash = "a4e02e2ac49b00c7b1b5f53d76d397b88a01148b16d920be66f8f6b7ebe6cb199e964a5129ee41a80db67b699bc3ffa04c6d87e8a2d89cdf46a8130287d11e7d"; - private readonly string asset1413Hash = "7c2961e6e6842b31a1dea11bfb655c5a2afba42b15c66c2dc155e6b86f2e510c0e2196149fa6d5e94e1c799c8a58503235f6f5f09b9cf618402c927991b6ae4c"; - private readonly string asset1414Hash = "4d4e53fa11a8e2ffde7e02fa774c959a87c24b9f70ab3dbb8ff6c3384808bfc9a822adb85ae77bef690f93469b2d575bc995317e2af5a63ae3151a04c5df57c7"; - private readonly string asset1415Hash = "5f122c429a160e0eb1df1a6b77cea6ee4c13b731ebff02c79646314d5bf57070d4fae13a1a8821927d7954f83ae706c937affb452ed32a38dc800e00ef0f6176"; - - private readonly string asset1336MD5Hash = "bed3d05d409001724e5f6095c2acaa95"; - private readonly string asset1337MD5Hash = "49f629639e6a86f43cc6863da60edc16"; - private readonly string asset1349MD5Hash = "40b609ff0eafe7c6a767e05daed14850"; - private readonly string asset1350MD5Hash = "a0501328ef7e513beadd169965353a0b"; - private readonly string asset1413MD5Hash = "c77db382d58e7cecca32bf39c966c8b9"; - private readonly string asset1414MD5Hash = "62ae52fd23a004cb2b70fdbf631712bf"; - private readonly string asset1415MD5Hash = "8a81b304ab3be092d2e46085fe818782"; - - private readonly string asset1336DHash = "1090783378"; - private readonly string asset1337DHash = "0"; - private readonly string asset1349DHash = "69788202038198207"; - private readonly string asset1350DHash = "58456436619323367"; - private readonly string asset1413DHash = "62941001906964359"; - private readonly string asset1414DHash = "58526839426719643"; - private readonly string asset1415DHash = "29520682973338550"; - - private readonly string asset1336PHash = "abf9e847058af2e892da61f508b70361f7162ee062ee062ee062ee062ee062ee062ee0abf9e847058af2e892da61f508b70361f7162ee062ee062ee062ee062ee062ee062ee0abf9e847058af2e892da61f508b70361f71abf9e847058af2e892da61f508b70361f71"; - private readonly string asset1337PHash = "aba21844698994389c3061fba8c26061fa362ee062ee062ee062ee062ee062ee062ee0aba21844698994389c3061fba8c26061fa362ee062ee062ee062ee062ee062ee062ee0aba21844698994389c3061fba8c26061fa3aba21844698994389c3061fba8c26061fa3"; - private readonly string asset1349PHash = "ab6ba84445890c1895e961dea8b85961f1662ee062ee062ee062ee062ee062ee062ee0ab6ba84445890c1895e961dea8b85961f1662ee062ee062ee062ee062ee062ee062ee0ab6ba84445890c1895e961dea8b85961f16ab6ba84445890c1895e961dea8b85961f16"; - private readonly string asset1350PHash = "abc9584a4e88a8388f3e61c818b47a61e5862ee062ee062ee062ee062ee062ee062ee0abc9584a4e88a8388f3e61c818b47a61e5862ee062ee062ee062ee062ee062ee062ee0abc9584a4e88a8388f3e61c818b47a61e58abc9584a4e88a8388f3e61c818b47a61e58"; - private readonly string asset1413PHash = "a66038379386f52862528d84e87e738cd2962ee062ee062ee062ee062ee062ee062ee0a66038379386f52862528d84e87e738cd2962ee062ee062ee062ee062ee062ee062ee0a66038379386f52862528d84e87e738cd29a66038379386f52862528d84e87e738cd29"; - private readonly string asset1414PHash = "a610d836af86c76860278de5287c4d8c6fc62ee062ee062ee062ee062ee062ee062ee0a610d836af86c76860278de5287c4d8c6fc62ee062ee062ee062ee062ee062ee062ee0a610d836af86c76860278de5287c4d8c6fca610d836af86c76860278de5287c4d8c6fc"; - private readonly string asset1415PHash = "a74048491d84b8c84917893a186db68b25562ee062ee062ee062ee062ee062ee062ee0a74048491d84b8c84917893a186db68b25562ee062ee062ee062ee062ee062ee062ee0a74048491d84b8c84917893a186db68b255a74048491d84b8c84917893a186db68b255"; - - private readonly string miscAssetHash = "1fafae17c3c5c38d1205449eebdb9f5976814a5e54ec5797270c8ec467fe6d6d1190255cbaac11d9057c4b2697d90bc7116a46ed90c5ffb71e32e569c3b47fb9"; - private readonly string miscAssetMD5Hash = "a886f237e1cf6da03fb793588fd79b64"; - private readonly string miscAssetDHash = "23831507941108244"; - private readonly string miscAssetPHash = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; + private Asset? _asset1; + private Asset? _asset2; + private Asset? _asset3; + private Asset? _asset4; + private Asset? _asset5; + private Asset? _asset6; + private Asset? _asset7; + private Asset? _asset8; + + private const string ASSET1336_HASH = "fb0bb3887c28d022113c5c52a65f9da14eab0806842f902b618806dedeb7c53da1ed26ae5bcaf9a358e81efead71c4807ea38054e44f426857f8bf2c1fd1c7aa"; + private const string ASSET1337_HASH = "4435b989c27e16be1bf583fb6bb4b3474bd55735447a52e663482703553c5ce38947b17f88a2bfd9662956b24575e7578f7b7d921fdba2273d6046ee765eec36"; + private const string ASSET1349_HASH = "715188ad52e6bd3dc9dfb7c0469038d92638dae94b7818f6326da093505f18b60d277831d451e259809af7dad3149cc2babf7442d1956ceca911f75180365cec"; + private const string ASSET1350_HASH = "a4e02e2ac49b00c7b1b5f53d76d397b88a01148b16d920be66f8f6b7ebe6cb199e964a5129ee41a80db67b699bc3ffa04c6d87e8a2d89cdf46a8130287d11e7d"; + private const string ASSET1413_HASH = "7c2961e6e6842b31a1dea11bfb655c5a2afba42b15c66c2dc155e6b86f2e510c0e2196149fa6d5e94e1c799c8a58503235f6f5f09b9cf618402c927991b6ae4c"; + private const string ASSET1414_HASH = "4d4e53fa11a8e2ffde7e02fa774c959a87c24b9f70ab3dbb8ff6c3384808bfc9a822adb85ae77bef690f93469b2d575bc995317e2af5a63ae3151a04c5df57c7"; + private const string ASSET1415_HASH = "5f122c429a160e0eb1df1a6b77cea6ee4c13b731ebff02c79646314d5bf57070d4fae13a1a8821927d7954f83ae706c937affb452ed32a38dc800e00ef0f6176"; + + private const string ASSET1336_MD5_HASH = "bed3d05d409001724e5f6095c2acaa95"; + private const string ASSET1337_MD5_HASH = "49f629639e6a86f43cc6863da60edc16"; + private const string ASSET1349_MD5_HASH = "40b609ff0eafe7c6a767e05daed14850"; + private const string ASSET1350_MD5_HASH = "a0501328ef7e513beadd169965353a0b"; + private const string ASSET1413_MD5_HASH = "c77db382d58e7cecca32bf39c966c8b9"; + private const string ASSET1414_MD5_HASH = "62ae52fd23a004cb2b70fdbf631712bf"; + private const string ASSET1415_MD5_HASH = "8a81b304ab3be092d2e46085fe818782"; + + private const string ASSET1336_D_HASH = "1090783378"; + private const string ASSET1337_D_HASH = "0"; + private const string ASSET1349_D_HASH = "69788202038198207"; + private const string ASSET1350_D_HASH = "58456436619323367"; + private const string ASSET1413_D_HASH = "62941001906964359"; + private const string ASSET1414_D_HASH = "58526839426719643"; + private const string ASSET1415_D_HASH = "29520682973338550"; + + private const string ASSET1336_P_HASH = "abf9e847058af2e892da61f508b70361f7162ee062ee062ee062ee062ee062ee062ee0abf9e847058af2e892da61f508b70361f7162ee062ee062ee062ee062ee062ee062ee0abf9e847058af2e892da61f508b70361f71abf9e847058af2e892da61f508b70361f71"; + private const string ASSET1337_P_HASH = "aba21844698994389c3061fba8c26061fa362ee062ee062ee062ee062ee062ee062ee0aba21844698994389c3061fba8c26061fa362ee062ee062ee062ee062ee062ee062ee0aba21844698994389c3061fba8c26061fa3aba21844698994389c3061fba8c26061fa3"; + private const string ASSET1349_P_HASH = "ab6ba84445890c1895e961dea8b85961f1662ee062ee062ee062ee062ee062ee062ee0ab6ba84445890c1895e961dea8b85961f1662ee062ee062ee062ee062ee062ee062ee0ab6ba84445890c1895e961dea8b85961f16ab6ba84445890c1895e961dea8b85961f16"; + private const string ASSET1350_P_HASH = "abc9584a4e88a8388f3e61c818b47a61e5862ee062ee062ee062ee062ee062ee062ee0abc9584a4e88a8388f3e61c818b47a61e5862ee062ee062ee062ee062ee062ee062ee0abc9584a4e88a8388f3e61c818b47a61e58abc9584a4e88a8388f3e61c818b47a61e58"; + private const string ASSET1413_P_HASH = "a66038379386f52862528d84e87e738cd2962ee062ee062ee062ee062ee062ee062ee0a66038379386f52862528d84e87e738cd2962ee062ee062ee062ee062ee062ee062ee0a66038379386f52862528d84e87e738cd29a66038379386f52862528d84e87e738cd29"; + private const string ASSET1414_P_HASH = "a610d836af86c76860278de5287c4d8c6fc62ee062ee062ee062ee062ee062ee062ee0a610d836af86c76860278de5287c4d8c6fc62ee062ee062ee062ee062ee062ee062ee0a610d836af86c76860278de5287c4d8c6fca610d836af86c76860278de5287c4d8c6fc"; + private const string ASSET1415_P_HASH = "a74048491d84b8c84917893a186db68b25562ee062ee062ee062ee062ee062ee062ee0a74048491d84b8c84917893a186db68b25562ee062ee062ee062ee062ee062ee062ee0a74048491d84b8c84917893a186db68b255a74048491d84b8c84917893a186db68b255"; + + private const string MISC_ASSET_HASH = "1fafae17c3c5c38d1205449eebdb9f5976814a5e54ec5797270c8ec467fe6d6d1190255cbaac11d9057c4b2697d90bc7116a46ed90c5ffb71e32e569c3b47fb9"; + private const string MISC_ASSET_MD5_HASH = "a886f237e1cf6da03fb793588fd79b64"; + private const string MISC_ASSET_D_HASH = "23831507941108244"; + private const string MISC_ASSET_P_HASH = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); @@ -70,7 +70,7 @@ public void OneTimeSetUp() _configurationRootMock.MockGetValue(UserConfigurationKeys.USING_PHASH, "true"); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -81,9 +81,10 @@ public void SetUp() _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); _storageService = new (userConfigurationService); - asset1 = new() + _asset1 = new() { FolderId = new Guid("db973547-ed18-4e7d-8dc8-ce441aabef80"), + Folder = new() { Path = "" }, FileName = "1336.JPG", FileSize = 2247285, ImageRotation = Rotation.Rotate0, @@ -98,9 +99,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset2 = new() + _asset2 = new() { FolderId = new Guid("65a65540-586e-4b2e-a62a-ccdbd7d442f2"), + Folder = new() { Path = "" }, FileName = "1337.JPG", FileSize = 2247285, ImageRotation = Rotation.Rotate0, @@ -115,9 +117,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset3 = new() + _asset3 = new() { FolderId = new Guid("65ba6b40-dc3c-46b6-8508-135cb4e1f961"), + Folder = new() { Path = "" }, FileName = "1349.JPG", FileSize = 2247285, ImageRotation = Rotation.Rotate0, @@ -132,9 +135,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset4 = new() + _asset4 = new() { FolderId = new Guid("ee3dcc63-53d8-4937-a38a-45b3189118e6"), + Folder = new() { Path = "" }, FileName = "1350.JPG", FileSize = 2247285, ImageRotation = Rotation.Rotate0, @@ -149,9 +153,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset5 = new() + _asset5 = new() { FolderId = new Guid("044e3039-0b4b-4065-b215-9cf185d1f90f"), + Folder = new() { Path = "" }, FileName = "1413.JPG", FileSize = 2247285, ImageRotation = Rotation.Rotate0, @@ -166,9 +171,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset6 = new() + _asset6 = new() { FolderId = new Guid("80fa1201-1b9d-4d8e-8730-6efe8e46fcbd"), + Folder = new() { Path = "" }, FileName = "1414.JPG", FileSize = 2247285, ImageRotation = Rotation.Rotate0, @@ -183,9 +189,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset7 = new() + _asset7 = new() { FolderId = new Guid("4c0b2c7c-3159-4855-850b-27c7e737a96e"), + Folder = new() { Path = "" }, FileName = "1415.JPG", FileSize = 2247285, ImageRotation = Rotation.Rotate0, @@ -200,9 +207,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset8 = new() // Another asset completely different than the actual asset + _asset8 = new() // Another asset completely different from the actual asset { FolderId = new Guid("5b506904-45af-4eaf-b402-53f6d0012075"), + Folder = new() { Path = "" }, FileName = "Image 1.jpg", FileSize = 2247285, ImageRotation = Rotation.Rotate0, @@ -228,7 +236,7 @@ public void SetUp() [TestCase("80", 0, new string[] { })] [TestCase("100", 0, new string[] { })] [TestCase("110", 0, new string[] { })] - [TestCase("128", 1, new string[] { "1336.JPG", "1337.JPG", "1349.JPG", "1350.JPG", "1413.JPG", "1414.JPG", "1415.JPG", "Image 1.jpg" })] + [TestCase("128", 1, new[] { "1336.JPG", "1337.JPG", "1349.JPG", "1350.JPG", "1413.JPG", "1414.JPG", "1415.JPG", "Image 1.jpg" })] public void GetDuplicatesBetweenOriginalAndThumbnail_NotDuplicateBasicHashDifferentThresholdValues(string thresholdToMock, int expected, string[] assetsName) { try @@ -237,43 +245,43 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_NotDuplicateBasicHashDiffer UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); FindDuplicatedAssetsService findDuplicatedAssetsService = new (_assetRepository!, _storageService!, userConfigurationService); - string folderPath1 = Path.Combine(dataDirectory!, "Duplicates\\NotDuplicate\\Sample1"); - string folderPath2 = Path.Combine(dataDirectory!, "Duplicates\\NotDuplicate\\Sample2"); - string folderPath3 = Path.Combine(dataDirectory!, "Duplicates\\NotDuplicate\\Sample3"); - string folderPath4 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "Duplicates\\NotDuplicate\\Sample1"); + string folderPath2 = Path.Combine(_dataDirectory!, "Duplicates\\NotDuplicate\\Sample2"); + string folderPath3 = Path.Combine(_dataDirectory!, "Duplicates\\NotDuplicate\\Sample3"); + string folderPath4 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); Folder folder1 = new() { Path = folderPath1 }; Folder folder2 = new() { Path = folderPath2 }; Folder folder3 = new() { Path = folderPath3 }; Folder folder4 = new() { Path = folderPath4 }; - asset1!.Folder = folder1; - asset1.Hash = asset1336Hash; - asset2!.Folder = folder1; - asset2.Hash = asset1337Hash; - asset3!.Folder = folder2; - asset3.Hash = asset1349Hash; - asset4!.Folder = folder2; - asset4.Hash = asset1350Hash; - asset5!.Folder = folder3; - asset5.Hash = asset1413Hash; - asset6!.Folder = folder3; - asset6.Hash = asset1414Hash; - asset7!.Folder = folder3; - asset7.Hash = asset1415Hash; - asset8!.Folder = folder4; - asset8.Hash = miscAssetHash; // If this asset is in the set, then the threshold is not good + _asset1!.Folder = folder1; + _asset1.Hash = ASSET1336_HASH; + _asset2!.Folder = folder1; + _asset2.Hash = ASSET1337_HASH; + _asset3!.Folder = folder2; + _asset3.Hash = ASSET1349_HASH; + _asset4!.Folder = folder2; + _asset4.Hash = ASSET1350_HASH; + _asset5!.Folder = folder3; + _asset5.Hash = ASSET1413_HASH; + _asset6!.Folder = folder3; + _asset6.Hash = ASSET1414_HASH; + _asset7!.Folder = folder3; + _asset7.Hash = ASSET1415_HASH; + _asset8!.Folder = folder4; + _asset8.Hash = MISC_ASSET_HASH; // If this asset is in the set, then the threshold is not good byte[] assetData1 = [1, 2, 3]; - _assetRepository!.AddAsset(asset1, assetData1); - _assetRepository.AddAsset(asset2, assetData1); - _assetRepository.AddAsset(asset3, assetData1); - _assetRepository.AddAsset(asset4, assetData1); - _assetRepository.AddAsset(asset5, assetData1); - _assetRepository.AddAsset(asset6, assetData1); - _assetRepository.AddAsset(asset7, assetData1); - _assetRepository.AddAsset(asset8, assetData1); + _assetRepository!.AddAsset(_asset1, assetData1); + _assetRepository.AddAsset(_asset2, assetData1); + _assetRepository.AddAsset(_asset3, assetData1); + _assetRepository.AddAsset(_asset4, assetData1); + _assetRepository.AddAsset(_asset5, assetData1); + _assetRepository.AddAsset(_asset6, assetData1); + _assetRepository.AddAsset(_asset7, assetData1); + _assetRepository.AddAsset(_asset8, assetData1); List> duplicatedAssets = findDuplicatedAssetsService.GetDuplicatedAssets(); @@ -287,7 +295,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_NotDuplicateBasicHashDiffer } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } @@ -299,7 +307,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_NotDuplicateBasicHashDiffer [TestCase("15", 0, new string[] { })] [TestCase("20", 0, new string[] { })] [TestCase("25", 0, new string[] { })] - [TestCase("32", 1, new string[] { "1336.JPG", "1337.JPG", "1349.JPG", "1350.JPG", "1413.JPG", "1414.JPG", "1415.JPG", "Image 1.jpg" })] + [TestCase("32", 1, new[] { "1336.JPG", "1337.JPG", "1349.JPG", "1350.JPG", "1413.JPG", "1414.JPG", "1415.JPG", "Image 1.jpg" })] public void GetDuplicatesBetweenOriginalAndThumbnail_NotDuplicateMD5HashDifferentThresholdValues(string thresholdToMock, int expected, string[] assetsName) { try @@ -308,43 +316,43 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_NotDuplicateMD5HashDifferen UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); FindDuplicatedAssetsService findDuplicatedAssetsService = new (_assetRepository!, _storageService!, userConfigurationService); - string folderPath1 = Path.Combine(dataDirectory!, "Duplicates\\NotDuplicate\\Sample1"); - string folderPath2 = Path.Combine(dataDirectory!, "Duplicates\\NotDuplicate\\Sample2"); - string folderPath3 = Path.Combine(dataDirectory!, "Duplicates\\NotDuplicate\\Sample3"); - string folderPath4 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "Duplicates\\NotDuplicate\\Sample1"); + string folderPath2 = Path.Combine(_dataDirectory!, "Duplicates\\NotDuplicate\\Sample2"); + string folderPath3 = Path.Combine(_dataDirectory!, "Duplicates\\NotDuplicate\\Sample3"); + string folderPath4 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); Folder folder1 = new() { Path = folderPath1 }; Folder folder2 = new() { Path = folderPath2 }; Folder folder3 = new() { Path = folderPath3 }; Folder folder4 = new() { Path = folderPath4 }; - asset1!.Folder = folder1; - asset1.Hash = asset1336MD5Hash; - asset2!.Folder = folder1; - asset2.Hash = asset1337MD5Hash; - asset3!.Folder = folder2; - asset3.Hash = asset1349MD5Hash; - asset4!.Folder = folder2; - asset4.Hash = asset1350MD5Hash; - asset5!.Folder = folder3; - asset5.Hash = asset1413MD5Hash; - asset6!.Folder = folder3; - asset6.Hash = asset1414MD5Hash; - asset7!.Folder = folder3; - asset7.Hash = asset1415MD5Hash; - asset8!.Folder = folder4; - asset8.Hash = miscAssetMD5Hash; // If this asset is in the set, then the threshold is not good + _asset1!.Folder = folder1; + _asset1.Hash = ASSET1336_MD5_HASH; + _asset2!.Folder = folder1; + _asset2.Hash = ASSET1337_MD5_HASH; + _asset3!.Folder = folder2; + _asset3.Hash = ASSET1349_MD5_HASH; + _asset4!.Folder = folder2; + _asset4.Hash = ASSET1350_MD5_HASH; + _asset5!.Folder = folder3; + _asset5.Hash = ASSET1413_MD5_HASH; + _asset6!.Folder = folder3; + _asset6.Hash = ASSET1414_MD5_HASH; + _asset7!.Folder = folder3; + _asset7.Hash = ASSET1415_MD5_HASH; + _asset8!.Folder = folder4; + _asset8.Hash = MISC_ASSET_MD5_HASH; // If this asset is in the set, then the threshold is not good byte[] assetData1 = [1, 2, 3]; - _assetRepository!.AddAsset(asset1, assetData1); - _assetRepository.AddAsset(asset2, assetData1); - _assetRepository.AddAsset(asset3, assetData1); - _assetRepository.AddAsset(asset4, assetData1); - _assetRepository.AddAsset(asset5, assetData1); - _assetRepository.AddAsset(asset6, assetData1); - _assetRepository.AddAsset(asset7, assetData1); - _assetRepository.AddAsset(asset8, assetData1); + _assetRepository!.AddAsset(_asset1, assetData1); + _assetRepository.AddAsset(_asset2, assetData1); + _assetRepository.AddAsset(_asset3, assetData1); + _assetRepository.AddAsset(_asset4, assetData1); + _assetRepository.AddAsset(_asset5, assetData1); + _assetRepository.AddAsset(_asset6, assetData1); + _assetRepository.AddAsset(_asset7, assetData1); + _assetRepository.AddAsset(_asset8, assetData1); List> duplicatedAssets = findDuplicatedAssetsService.GetDuplicatedAssets(); @@ -358,7 +366,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_NotDuplicateMD5HashDifferen } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } @@ -379,24 +387,24 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_NotDuplicateSample1DHashDif UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); FindDuplicatedAssetsService findDuplicatedAssetsService = new (_assetRepository!, _storageService!, userConfigurationService); - string folderPath1 = Path.Combine(dataDirectory!, "Duplicates\\NotDuplicate\\Sample1"); - string folderPath4 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "Duplicates\\NotDuplicate\\Sample1"); + string folderPath4 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); Folder folder1 = new() { Path = folderPath1 }; Folder folder4 = new() { Path = folderPath4 }; - asset1!.Folder = folder1; - asset1.Hash = asset1336DHash; - asset2!.Folder = folder1; - asset2.Hash = asset1337DHash; - asset8!.Folder = folder4; - asset8.Hash = miscAssetDHash; // If this asset is in the set, then the threshold is not good + _asset1!.Folder = folder1; + _asset1.Hash = ASSET1336_D_HASH; + _asset2!.Folder = folder1; + _asset2.Hash = ASSET1337_D_HASH; + _asset8!.Folder = folder4; + _asset8.Hash = MISC_ASSET_D_HASH; // If this asset is in the set, then the threshold is not good byte[] assetData1 = [1, 2, 3]; - _assetRepository!.AddAsset(asset1, assetData1); - _assetRepository.AddAsset(asset2, assetData1); - _assetRepository.AddAsset(asset8, assetData1); + _assetRepository!.AddAsset(_asset1, assetData1); + _assetRepository.AddAsset(_asset2, assetData1); + _assetRepository.AddAsset(_asset8, assetData1); ArgumentException? exception = Assert.Throws(() => findDuplicatedAssetsService.GetDuplicatedAssets()); @@ -404,7 +412,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_NotDuplicateSample1DHashDif } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } @@ -415,8 +423,8 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_NotDuplicateSample1DHashDif [TestCase("5", 0, new string[] { })] [TestCase("9", 0, new string[] { })] [TestCase("11", 0, new string[] { })] - [TestCase("14", 1, new string[] { "1349.JPG", "Image 1.jpg" })] - [TestCase("17", 1, new string[] { "1349.JPG", "1350.JPG", "Image 1.jpg" })] + [TestCase("14", 1, new[] { "1349.JPG", "Image 1.jpg" })] + [TestCase("17", 1, new[] { "1349.JPG", "1350.JPG", "Image 1.jpg" })] public void GetDuplicatesBetweenOriginalAndThumbnail_NotDuplicateSample2DHashDifferentThresholdValues(string thresholdToMock, int expected, string[] assetsName) { try @@ -425,24 +433,24 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_NotDuplicateSample2DHashDif UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); FindDuplicatedAssetsService findDuplicatedAssetsService = new (_assetRepository!, _storageService!, userConfigurationService); - string folderPath1 = Path.Combine(dataDirectory!, "Duplicates\\NotDuplicate\\Sample2"); - string folderPath2 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "Duplicates\\NotDuplicate\\Sample2"); + string folderPath2 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); Folder folder1 = new() { Path = folderPath1 }; Folder folder2 = new() { Path = folderPath2 }; - asset3!.Folder = folder1; - asset3.Hash = asset1349DHash; - asset4!.Folder = folder1; - asset4.Hash = asset1350DHash; - asset8!.Folder = folder2; - asset8.Hash = miscAssetDHash; // If this asset is in the set, then the threshold is not good + _asset3!.Folder = folder1; + _asset3.Hash = ASSET1349_D_HASH; + _asset4!.Folder = folder1; + _asset4.Hash = ASSET1350_D_HASH; + _asset8!.Folder = folder2; + _asset8.Hash = MISC_ASSET_D_HASH; // If this asset is in the set, then the threshold is not good byte[] assetData1 = [1, 2, 3]; - _assetRepository!.AddAsset(asset3, assetData1); - _assetRepository.AddAsset(asset4, assetData1); - _assetRepository.AddAsset(asset8, assetData1); + _assetRepository!.AddAsset(_asset3, assetData1); + _assetRepository.AddAsset(_asset4, assetData1); + _assetRepository.AddAsset(_asset8, assetData1); List> duplicatedAssets = findDuplicatedAssetsService.GetDuplicatedAssets(); @@ -456,7 +464,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_NotDuplicateSample2DHashDif } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } @@ -467,8 +475,8 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_NotDuplicateSample2DHashDif [TestCase("5", 0, new string[] { }, new string[] { })] [TestCase("9", 0, new string[] { }, new string[] { })] [TestCase("11", 0, new string[] { }, new string[] { })] - [TestCase("14", 2, new string[] { "1413.JPG", "Image 1.jpg" }, new string[] { "1415.JPG", "Image 1.jpg" })] // Weird result - [TestCase("17", 1, new string[] { "1413.JPG", "1414.JPG", "1415.JPG", "Image 1.jpg" }, new string[] { })] + [TestCase("14", 2, new[] { "1413.JPG", "Image 1.jpg" }, new[] { "1415.JPG", "Image 1.jpg" })] // Weird result + [TestCase("17", 1, new[] { "1413.JPG", "1414.JPG", "1415.JPG", "Image 1.jpg" }, new string[] { })] public void GetDuplicatesBetweenOriginalAndThumbnail_NotDuplicateSample3DHashDifferentThresholdValues(string thresholdToMock, int expected, string[] assetsName1, string[] assetsName2) { try @@ -477,27 +485,27 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_NotDuplicateSample3DHashDif UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); FindDuplicatedAssetsService findDuplicatedAssetsService = new (_assetRepository!, _storageService!, userConfigurationService); - string folderPath1 = Path.Combine(dataDirectory!, "Duplicates\\NotDuplicate\\Sample3"); - string folderPath2 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "Duplicates\\NotDuplicate\\Sample3"); + string folderPath2 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); Folder folder1 = new() { Path = folderPath1 }; Folder folder2 = new() { Path = folderPath2 }; - asset5!.Folder = folder1; - asset5.Hash = asset1413DHash; - asset6!.Folder = folder1; - asset6.Hash = asset1414DHash; - asset7!.Folder = folder1; - asset7.Hash = asset1415DHash; - asset8!.Folder = folder2; - asset8.Hash = miscAssetDHash; // If this asset is in the set, then the threshold is not good + _asset5!.Folder = folder1; + _asset5.Hash = ASSET1413_D_HASH; + _asset6!.Folder = folder1; + _asset6.Hash = ASSET1414_D_HASH; + _asset7!.Folder = folder1; + _asset7.Hash = ASSET1415_D_HASH; + _asset8!.Folder = folder2; + _asset8.Hash = MISC_ASSET_D_HASH; // If this asset is in the set, then the threshold is not good byte[] assetData1 = [1, 2, 3]; - _assetRepository!.AddAsset(asset5, assetData1); - _assetRepository.AddAsset(asset6, assetData1); - _assetRepository.AddAsset(asset7, assetData1); - _assetRepository.AddAsset(asset8, assetData1); + _assetRepository!.AddAsset(_asset5, assetData1); + _assetRepository.AddAsset(_asset6, assetData1); + _assetRepository.AddAsset(_asset7, assetData1); + _assetRepository.AddAsset(_asset8, assetData1); List> duplicatedAssets = findDuplicatedAssetsService.GetDuplicatedAssets(); @@ -516,7 +524,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_NotDuplicateSample3DHashDif } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } @@ -529,14 +537,14 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_NotDuplicateSample3DHashDif [TestCase("40", 0, new string[] { }, new string[] { }, new string[] { })] [TestCase("50", 0, new string[] { }, new string[] { }, new string[] { })] [TestCase("60", 0, new string[] { }, new string[] { }, new string[] { })] - [TestCase("80", 3, new string[] { "1336.JPG", "1349.JPG" }, new string[] { "1337.JPG", "1349.JPG" }, new string[] { "1413.JPG", "1414.JPG" })] // Weird result - [TestCase("90", 2, new string[] { "1336.JPG", "1337.JPG", "1349.JPG", "1350.JPG" }, new string[] { "1413.JPG", "1414.JPG" }, new string[] { })] // Weird result - [TestCase("100", 2, new string[] { "1336.JPG", "1337.JPG", "1349.JPG", "1350.JPG" }, new string[] { "1413.JPG", "1414.JPG" }, new string[] { })] // Weird result - [TestCase("120", 1, new string[] { "1336.JPG", "1337.JPG", "1349.JPG", "1350.JPG", "1413.JPG", "1414.JPG", "1415.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] - [TestCase("140", 1, new string[] { "1336.JPG", "1337.JPG", "1349.JPG", "1350.JPG", "1413.JPG", "1414.JPG", "1415.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] - [TestCase("160", 1, new string[] { "1336.JPG", "1337.JPG", "1349.JPG", "1350.JPG", "1413.JPG", "1414.JPG", "1415.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] - [TestCase("180", 1, new string[] { "1336.JPG", "1337.JPG", "1349.JPG", "1350.JPG", "1413.JPG", "1414.JPG", "1415.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] - [TestCase("210", 1, new string[] { "1336.JPG", "1337.JPG", "1349.JPG", "1350.JPG", "1413.JPG", "1414.JPG", "1415.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] + [TestCase("80", 3, new[] { "1336.JPG", "1349.JPG" }, new[] { "1337.JPG", "1349.JPG" }, new[] { "1413.JPG", "1414.JPG" })] // Weird result + [TestCase("90", 2, new[] { "1336.JPG", "1337.JPG", "1349.JPG", "1350.JPG" }, new[] { "1413.JPG", "1414.JPG" }, new string[] { })] // Weird result + [TestCase("100", 2, new[] { "1336.JPG", "1337.JPG", "1349.JPG", "1350.JPG" }, new[] { "1413.JPG", "1414.JPG" }, new string[] { })] // Weird result + [TestCase("120", 1, new[] { "1336.JPG", "1337.JPG", "1349.JPG", "1350.JPG", "1413.JPG", "1414.JPG", "1415.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] + [TestCase("140", 1, new[] { "1336.JPG", "1337.JPG", "1349.JPG", "1350.JPG", "1413.JPG", "1414.JPG", "1415.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] + [TestCase("160", 1, new[] { "1336.JPG", "1337.JPG", "1349.JPG", "1350.JPG", "1413.JPG", "1414.JPG", "1415.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] + [TestCase("180", 1, new[] { "1336.JPG", "1337.JPG", "1349.JPG", "1350.JPG", "1413.JPG", "1414.JPG", "1415.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] + [TestCase("210", 1, new[] { "1336.JPG", "1337.JPG", "1349.JPG", "1350.JPG", "1413.JPG", "1414.JPG", "1415.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] public void GetDuplicatesBetweenOriginalAndThumbnail_NotDuplicatePHashDifferentThresholdValues(string thresholdToMock, int expected, string[] assetsName1, string[] assetsName2, string[] assetsName3) { try @@ -545,43 +553,43 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_NotDuplicatePHashDifferentT UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); FindDuplicatedAssetsService findDuplicatedAssetsService = new (_assetRepository!, _storageService!, userConfigurationService); - string folderPath1 = Path.Combine(dataDirectory!, "Duplicates\\NotDuplicate\\Sample1"); - string folderPath2 = Path.Combine(dataDirectory!, "Duplicates\\NotDuplicate\\Sample2"); - string folderPath3 = Path.Combine(dataDirectory!, "Duplicates\\NotDuplicate\\Sample3"); - string folderPath4 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "Duplicates\\NotDuplicate\\Sample1"); + string folderPath2 = Path.Combine(_dataDirectory!, "Duplicates\\NotDuplicate\\Sample2"); + string folderPath3 = Path.Combine(_dataDirectory!, "Duplicates\\NotDuplicate\\Sample3"); + string folderPath4 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); Folder folder1 = new() { Path = folderPath1 }; Folder folder2 = new() { Path = folderPath2 }; Folder folder3 = new() { Path = folderPath3 }; Folder folder4 = new() { Path = folderPath4 }; - asset1!.Folder = folder1; - asset1.Hash = asset1336PHash; - asset2!.Folder = folder1; - asset2.Hash = asset1337PHash; - asset3!.Folder = folder2; - asset3.Hash = asset1349PHash; - asset4!.Folder = folder2; - asset4.Hash = asset1350PHash; - asset5!.Folder = folder3; - asset5.Hash = asset1413PHash; - asset6!.Folder = folder3; - asset6.Hash = asset1414PHash; - asset7!.Folder = folder3; - asset7.Hash = asset1415PHash; - asset8!.Folder = folder4; - asset8.Hash = miscAssetPHash; // If this asset is in the set, then the threshold is not good + _asset1!.Folder = folder1; + _asset1.Hash = ASSET1336_P_HASH; + _asset2!.Folder = folder1; + _asset2.Hash = ASSET1337_P_HASH; + _asset3!.Folder = folder2; + _asset3.Hash = ASSET1349_P_HASH; + _asset4!.Folder = folder2; + _asset4.Hash = ASSET1350_P_HASH; + _asset5!.Folder = folder3; + _asset5.Hash = ASSET1413_P_HASH; + _asset6!.Folder = folder3; + _asset6.Hash = ASSET1414_P_HASH; + _asset7!.Folder = folder3; + _asset7.Hash = ASSET1415_P_HASH; + _asset8!.Folder = folder4; + _asset8.Hash = MISC_ASSET_P_HASH; // If this asset is in the set, then the threshold is not good byte[] assetData1 = [1, 2, 3]; - _assetRepository!.AddAsset(asset1, assetData1); - _assetRepository.AddAsset(asset2, assetData1); - _assetRepository.AddAsset(asset3, assetData1); - _assetRepository.AddAsset(asset4, assetData1); - _assetRepository.AddAsset(asset5, assetData1); - _assetRepository.AddAsset(asset6, assetData1); - _assetRepository.AddAsset(asset7, assetData1); - _assetRepository.AddAsset(asset8, assetData1); + _assetRepository!.AddAsset(_asset1, assetData1); + _assetRepository.AddAsset(_asset2, assetData1); + _assetRepository.AddAsset(_asset3, assetData1); + _assetRepository.AddAsset(_asset4, assetData1); + _assetRepository.AddAsset(_asset5, assetData1); + _assetRepository.AddAsset(_asset6, assetData1); + _assetRepository.AddAsset(_asset7, assetData1); + _assetRepository.AddAsset(_asset8, assetData1); List> duplicatedAssets = findDuplicatedAssetsService.GetDuplicatedAssets(); @@ -605,7 +613,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_NotDuplicatePHashDifferentT } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceThumbnailPartTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceThumbnailPartTests.cs index f543e3a3..6a681e5a 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceThumbnailPartTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceThumbnailPartTests.cs @@ -3,76 +3,76 @@ [TestFixture] public class FindDuplicatedAssetsServiceThumbnailPartTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; private AssetRepository? _assetRepository; private StorageService? _storageService; private Mock? _storageServiceMock; private Mock? _configurationRootMock; - private Asset? asset1; - private Asset? asset2; - private Asset? asset3; - private Asset? asset4; - private Asset? asset5; - private Asset? asset6; - private Asset? asset7; - private Asset? asset8; - private Asset? asset9; - private Asset? asset10; - - private readonly string asset1336_BottomLeftPartHash = "c50e17cee9a52c0235afb410c361d094daf7330c20e4b3f3cb3e3e18683793355e903f84d49bf1db4af7e094980204cc005aa3c503829d14c9e6cd19826e284f"; - private readonly string asset1336_BottomPartHash = "aef59f88b3c54a5fd1bfc098acac1d662bb3799e83220049ee7c3ae5def487a1464112cce7b7384428ee9b69813448d509413a1fc1abcddc272ec2e044c5f876"; - private readonly string asset1336_BottomRightPartHash = "966370f38d7864499453b99934bb51f1654e567033e637b68ded1ec12c338eaa03d42bb4dc74621551c5dfd922180a291f7c58980bf6c94ae114e4d296a484e4"; - private readonly string asset1336_LeftPartHash = "8afa3f673b047d5096ed2a2528b37c7222ab5b44cf780a7920cea35228e93323709b09b1a2ffe1bd2f789061be9bef8ebcb642fc47a2f3b6573a68a8cd5045ee"; - private readonly string asset1336_OriginalHash = "fb0bb3887c28d022113c5c52a65f9da14eab0806842f902b618806dedeb7c53da1ed26ae5bcaf9a358e81efead71c4807ea38054e44f426857f8bf2c1fd1c7aa"; - private readonly string asset1336_RightPartHash = "0e0e12ea70894ad521c8d3da14b92bbd4e7c7c03010502d779f2e485ea30e917ad6a9bc0435520f70c3448fd96cd9ccf88cf95d2a75a6da669b0f41731aabbe7"; - private readonly string asset1336_TopLeftPartHash = "f59b3913bdd53b6cb485a2c04770d1153350df2caf6dabf38b8b8311fb3fb583becbf7d368a1e0987d3584251a64bca72042d334b6e6c25edb7dfaead2db383d"; - private readonly string asset1336_TopPartHash = "93d6ea1575ea8fd4f540b88ae3ce727d28c657a11388c9b6cf927572abffdcc467d3e9b43e622b34158c18ed680c841d43e17a80c7b544261f106d887b51d2d2"; - private readonly string asset1336_TopRightPartHash = "3fde05f0e85d71a909fa38351411f3d45305857ea7a920ad22bcffaf4cf50136b4a55acb128bdc9cd9d7db600332f83e4157926a511939b0b57f2e50c020e3d7"; - - private readonly string asset1336_BottomLeftPartMD5Hash = "1691eb898f26c38b8b5d66b5d5ed71c6"; - private readonly string asset1336_BottomPartMD5Hash = "bac5ead516448cc2a657ea75251ae88d"; - private readonly string asset1336_BottomRightPartMD5Hash = "25830c1fb500800d426c8832d7fabb9e"; - private readonly string asset1336_LeftPartMD5Hash = "55370d738498beff0963693512d2d94f"; - private readonly string asset1336_OriginalMD5Hash = "bed3d05d409001724e5f6095c2acaa95"; - private readonly string asset1336_RightPartMD5Hash = "01b35414fd99b583a5261ff83260b698"; - private readonly string asset1336_TopLeftPartMD5Hash = "58695d954982417e68b68975beff02c4"; - private readonly string asset1336_TopPartMD5Hash = "216eaa3b37a658bd0d288d858022c7e1"; - private readonly string asset1336_TopRightPartMD5Hash = "1ec7dfdec1b6e9aa8ad5f50aae638e0e"; - - private readonly string asset1336_BottomLeftPartDHash = "70927157499523007"; - private readonly string asset1336_BottomPartDHash = "70927157499523007"; - private readonly string asset1336_BottomRightPartDHash = "62485089979447164"; - private readonly string asset1336_LeftPartDHash = "72057594037927935"; - private readonly string asset1336_OriginalDHash = "72057594037927935"; - private readonly string asset1336_RightPartDHash = "17023704168856051"; - private readonly string asset1336_TopLeftPartDHash = "72057594037927935"; - private readonly string asset1336_TopPartDHash = "72057594037927935"; - private readonly string asset1336_TopRightPartDHash = "17023704168856051"; - - private readonly string asset1336_BottomLeftPartPHash = "a939484b35885058815f61a1f8a70361c4562ee062ee062ee062ee062ee062ee062ee0a939484b35885058815f61a1f8a70361c4562ee062ee062ee062ee062ee062ee062ee0a939484b35885058815f61a1f8a70361c45a939484b35885058815f61a1f8a70361c45"; - private readonly string asset1336_BottomPartPHash = "a3cb9ad75a86e60869ba8da5c876de8dd2f62ee062ee062ee062ee062ee062ee062ee0a3cb9ad75a86e60869ba8da5c876de8dd2f62ee062ee062ee062ee062ee062ee062ee0a3cb9ad75a86e60869ba8da5c876de8dd2fa3cb9ad75a86e60869ba8da5c876de8dd2f"; - private readonly string asset1336_BottomRightPartPHash = "a757a847f2873ca86abd8dc848a10a8e58f62ee062ee062ee062ee062ee062ee062ee0a757a847f2873ca86abd8dc848a10a8e58f62ee062ee062ee062ee062ee062ee062ee0a757a847f2873ca86abd8dc848a10a8e58fa757a847f2873ca86abd8dc848a10a8e58f"; - private readonly string asset1336_LeftPartPHash = "ac9c684f6c8797587bc88f6668a37d6207262ee062ee062ee062ee062ee062ee062ee0ac9c684f6c8797587bc88f6668a37d6207262ee062ee062ee062ee062ee062ee062ee0ac9c684f6c8797587bc88f6668a37d62072ac9c684f6c8797587bc88f6668a37d62072"; - private readonly string asset1336_OriginalPHash = "abf9e847058af2e892da61f508b70361f7162ee062ee062ee062ee062ee062ee062ee0abf9e847058af2e892da61f508b70361f7162ee062ee062ee062ee062ee062ee062ee0abf9e847058af2e892da61f508b70361f71abf9e847058af2e892da61f508b70361f71"; - private readonly string asset1336_RightPartPHash = "ac49784f3886c9286e8b8dcb9896648f28662ee062ee062ee062ee062ee062ee062ee0ac49784f3886c9286e8b8dcb9896648f28662ee062ee062ee062ee062ee062ee062ee0ac49784f3886c9286e8b8dcb9896648f286ac49784f3886c9286e8b8dcb9896648f286"; - private readonly string asset1336_TopLeftPartPHash = "ade578542a8bf548bb8b6261a8e6c36268562ee062ee062ee062ee062ee062ee062ee0ade578542a8bf548bb8b6261a8e6c36268562ee062ee062ee062ee062ee062ee062ee0ade578542a8bf548bb8b6261a8e6c362685ade578542a8bf548bb8b6261a8e6c362685"; - private readonly string asset1336_TopPartPHash = "a9d838286c8b5668b5f3625668cbfa624a862ee062ee062ee062ee062ee062ee062ee0a9d838286c8b5668b5f3625668cbfa624a862ee062ee062ee062ee062ee062ee062ee0a9d838286c8b5668b5f3625668cbfa624a8a9d838286c8b5668b5f3625668cbfa624a8"; - private readonly string asset1336_TopRightPartPHash = "ae3968548a8c4158c2f562b528f01e6270e62ee062ee062ee062ee062ee062ee062ee0ae3968548a8c4158c2f562b528f01e6270e62ee062ee062ee062ee062ee062ee062ee0ae3968548a8c4158c2f562b528f01e6270eae3968548a8c4158c2f562b528f01e6270e"; - - private readonly string miscAssetHash = "1fafae17c3c5c38d1205449eebdb9f5976814a5e54ec5797270c8ec467fe6d6d1190255cbaac11d9057c4b2697d90bc7116a46ed90c5ffb71e32e569c3b47fb9"; - private readonly string miscAssetMD5Hash = "a886f237e1cf6da03fb793588fd79b64"; - private readonly string miscAssetDHash = "23831507941108244"; - private readonly string miscAssetPHash = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; + private Asset? _asset1; + private Asset? _asset2; + private Asset? _asset3; + private Asset? _asset4; + private Asset? _asset5; + private Asset? _asset6; + private Asset? _asset7; + private Asset? _asset8; + private Asset? _asset9; + private Asset? _asset10; + + private const string ASSET1336_BOTTOM_LEFT_PART_HASH = "c50e17cee9a52c0235afb410c361d094daf7330c20e4b3f3cb3e3e18683793355e903f84d49bf1db4af7e094980204cc005aa3c503829d14c9e6cd19826e284f"; + private const string ASSET1336_BOTTOM_PART_HASH = "aef59f88b3c54a5fd1bfc098acac1d662bb3799e83220049ee7c3ae5def487a1464112cce7b7384428ee9b69813448d509413a1fc1abcddc272ec2e044c5f876"; + private const string ASSET1336_BOTTOM_RIGHT_PART_HASH = "966370f38d7864499453b99934bb51f1654e567033e637b68ded1ec12c338eaa03d42bb4dc74621551c5dfd922180a291f7c58980bf6c94ae114e4d296a484e4"; + private const string ASSET1336_LEFT_PART_HASH = "8afa3f673b047d5096ed2a2528b37c7222ab5b44cf780a7920cea35228e93323709b09b1a2ffe1bd2f789061be9bef8ebcb642fc47a2f3b6573a68a8cd5045ee"; + private const string ASSET1336_ORIGINAL_HASH = "fb0bb3887c28d022113c5c52a65f9da14eab0806842f902b618806dedeb7c53da1ed26ae5bcaf9a358e81efead71c4807ea38054e44f426857f8bf2c1fd1c7aa"; + private const string ASSET1336_RIGHT_PART_HASH = "0e0e12ea70894ad521c8d3da14b92bbd4e7c7c03010502d779f2e485ea30e917ad6a9bc0435520f70c3448fd96cd9ccf88cf95d2a75a6da669b0f41731aabbe7"; + private const string ASSET1336_TOP_LEFT_PART_HASH = "f59b3913bdd53b6cb485a2c04770d1153350df2caf6dabf38b8b8311fb3fb583becbf7d368a1e0987d3584251a64bca72042d334b6e6c25edb7dfaead2db383d"; + private const string ASSET1336_TOP_PART_HASH = "93d6ea1575ea8fd4f540b88ae3ce727d28c657a11388c9b6cf927572abffdcc467d3e9b43e622b34158c18ed680c841d43e17a80c7b544261f106d887b51d2d2"; + private const string ASSET1336_TOP_RIGHT_PART_HASH = "3fde05f0e85d71a909fa38351411f3d45305857ea7a920ad22bcffaf4cf50136b4a55acb128bdc9cd9d7db600332f83e4157926a511939b0b57f2e50c020e3d7"; + + private const string ASSET1336_BOTTOM_LEFT_PART_MD5_HASH = "1691eb898f26c38b8b5d66b5d5ed71c6"; + private const string ASSET1336_BOTTOM_PART_MD5_HASH = "bac5ead516448cc2a657ea75251ae88d"; + private const string ASSET1336_BOTTOM_RIGHT_PART_MD5_HASH = "25830c1fb500800d426c8832d7fabb9e"; + private const string ASSET1336_LEFT_PART_MD5_HASH = "55370d738498beff0963693512d2d94f"; + private const string ASSET1336_ORIGINAL_MD5_HASH = "bed3d05d409001724e5f6095c2acaa95"; + private const string ASSET1336_RIGHT_PART_MD5_HASH = "01b35414fd99b583a5261ff83260b698"; + private const string ASSET1336_TOP_LEFT_PART_MD5_HASH = "58695d954982417e68b68975beff02c4"; + private const string ASSET1336_TOP_PART_MD5_HASH = "216eaa3b37a658bd0d288d858022c7e1"; + private const string ASSET1336_TOP_RIGHT_PART_MD5_HASH = "1ec7dfdec1b6e9aa8ad5f50aae638e0e"; + + private const string ASSET1336_BOTTOM_LEFT_PART_D_HASH = "70927157499523007"; + private const string ASSET1336_BOTTOM_PART_D_HASH = "70927157499523007"; + private const string ASSET1336_BOTTOM_RIGHT_PART_D_HASH = "62485089979447164"; + private const string ASSET1336_LEFT_PART_D_HASH = "72057594037927935"; + private const string ASSET1336_ORIGINAL_D_HASH = "72057594037927935"; + private const string ASSET1336_RIGHT_PART_D_HASH = "17023704168856051"; + private const string ASSET1336_TOP_LEFT_PART_D_HASH = "72057594037927935"; + private const string ASSET1336_TOP_PART_D_HASH = "72057594037927935"; + private const string ASSET1336_TOP_RIGHT_PART_D_HASH = "17023704168856051"; + + private const string ASSET1336_BOTTOM_LEFT_PART_P_HASH = "a939484b35885058815f61a1f8a70361c4562ee062ee062ee062ee062ee062ee062ee0a939484b35885058815f61a1f8a70361c4562ee062ee062ee062ee062ee062ee062ee0a939484b35885058815f61a1f8a70361c45a939484b35885058815f61a1f8a70361c45"; + private const string ASSET1336_BOTTOM_PART_P_HASH = "a3cb9ad75a86e60869ba8da5c876de8dd2f62ee062ee062ee062ee062ee062ee062ee0a3cb9ad75a86e60869ba8da5c876de8dd2f62ee062ee062ee062ee062ee062ee062ee0a3cb9ad75a86e60869ba8da5c876de8dd2fa3cb9ad75a86e60869ba8da5c876de8dd2f"; + private const string ASSET1336_BOTTOM_RIGHT_PART_P_HASH = "a757a847f2873ca86abd8dc848a10a8e58f62ee062ee062ee062ee062ee062ee062ee0a757a847f2873ca86abd8dc848a10a8e58f62ee062ee062ee062ee062ee062ee062ee0a757a847f2873ca86abd8dc848a10a8e58fa757a847f2873ca86abd8dc848a10a8e58f"; + private const string ASSET1336_LEFT_PART_P_HASH = "ac9c684f6c8797587bc88f6668a37d6207262ee062ee062ee062ee062ee062ee062ee0ac9c684f6c8797587bc88f6668a37d6207262ee062ee062ee062ee062ee062ee062ee0ac9c684f6c8797587bc88f6668a37d62072ac9c684f6c8797587bc88f6668a37d62072"; + private const string ASSET1336_ORIGINAL_P_HASH = "abf9e847058af2e892da61f508b70361f7162ee062ee062ee062ee062ee062ee062ee0abf9e847058af2e892da61f508b70361f7162ee062ee062ee062ee062ee062ee062ee0abf9e847058af2e892da61f508b70361f71abf9e847058af2e892da61f508b70361f71"; + private const string ASSET1336_RIGHT_PART_P_HASH = "ac49784f3886c9286e8b8dcb9896648f28662ee062ee062ee062ee062ee062ee062ee0ac49784f3886c9286e8b8dcb9896648f28662ee062ee062ee062ee062ee062ee062ee0ac49784f3886c9286e8b8dcb9896648f286ac49784f3886c9286e8b8dcb9896648f286"; + private const string ASSET1336_TOP_LEFT_PART_P_HASH = "ade578542a8bf548bb8b6261a8e6c36268562ee062ee062ee062ee062ee062ee062ee0ade578542a8bf548bb8b6261a8e6c36268562ee062ee062ee062ee062ee062ee062ee0ade578542a8bf548bb8b6261a8e6c362685ade578542a8bf548bb8b6261a8e6c362685"; + private const string ASSET1336_TOP_PART_P_HASH = "a9d838286c8b5668b5f3625668cbfa624a862ee062ee062ee062ee062ee062ee062ee0a9d838286c8b5668b5f3625668cbfa624a862ee062ee062ee062ee062ee062ee062ee0a9d838286c8b5668b5f3625668cbfa624a8a9d838286c8b5668b5f3625668cbfa624a8"; + private const string ASSET1336_TOP_RIGHT_PART_P_HASH = "ae3968548a8c4158c2f562b528f01e6270e62ee062ee062ee062ee062ee062ee062ee0ae3968548a8c4158c2f562b528f01e6270e62ee062ee062ee062ee062ee062ee062ee0ae3968548a8c4158c2f562b528f01e6270eae3968548a8c4158c2f562b528f01e6270e"; + + private const string MISC_ASSET_HASH = "1fafae17c3c5c38d1205449eebdb9f5976814a5e54ec5797270c8ec467fe6d6d1190255cbaac11d9057c4b2697d90bc7116a46ed90c5ffb71e32e569c3b47fb9"; + private const string MISC_ASSET_MD5_HASH = "a886f237e1cf6da03fb793588fd79b64"; + private const string MISC_ASSET_D_HASH = "23831507941108244"; + private const string MISC_ASSET_P_HASH = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); @@ -80,7 +80,7 @@ public void OneTimeSetUp() _configurationRootMock.MockGetValue(UserConfigurationKeys.USING_PHASH, "true"); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -91,9 +91,10 @@ public void SetUp() _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); _storageService = new (userConfigurationService); - asset1 = new() + _asset1 = new() { FolderId = new Guid("5126101a-c970-4c87-92ee-ab415ff659f3"), + Folder = new() { Path = "" }, FileName = "1336_BottomLeftPart.JPG", FileSize = 1119873, ImageRotation = Rotation.Rotate0, @@ -108,9 +109,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset2 = new() + _asset2 = new() { FolderId = new Guid("5126101a-c970-4c87-92ee-ab415ff659f3"), + Folder = new() { Path = "" }, FileName = "1336_BottomPart.JPG", FileSize = 2172866, ImageRotation = Rotation.Rotate0, @@ -125,9 +127,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset3 = new() + _asset3 = new() { FolderId = new Guid("5126101a-c970-4c87-92ee-ab415ff659f3"), + Folder = new() { Path = "" }, FileName = "1336_BottomRightPart.JPG", FileSize = 1061673, ImageRotation = Rotation.Rotate0, @@ -142,9 +145,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset4 = new() + _asset4 = new() { FolderId = new Guid("5126101a-c970-4c87-92ee-ab415ff659f3"), + Folder = new() { Path = "" }, FileName = "1336_LeftPart.JPG", FileSize = 1475892, ImageRotation = Rotation.Rotate0, @@ -159,9 +163,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset5 = new() + _asset5 = new() { FolderId = new Guid("5126101a-c970-4c87-92ee-ab415ff659f3"), + Folder = new() { Path = "" }, FileName = "1336_Original.JPG", FileSize = 4526710, ImageRotation = Rotation.Rotate0, @@ -176,9 +181,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset6 = new() + _asset6 = new() { FolderId = new Guid("5126101a-c970-4c87-92ee-ab415ff659f3"), + Folder = new() { Path = "" }, FileName = "1336_RightPart.JPG", FileSize = 1437903, ImageRotation = Rotation.Rotate0, @@ -193,9 +199,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset7 = new() + _asset7 = new() { FolderId = new Guid("5126101a-c970-4c87-92ee-ab415ff659f3"), + Folder = new() { Path = "" }, FileName = "1336_TopLeftPart.JPG", FileSize = 362012, ImageRotation = Rotation.Rotate0, @@ -210,9 +217,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset8 = new() + _asset8 = new() { FolderId = new Guid("5126101a-c970-4c87-92ee-ab415ff659f3"), + Folder = new() { Path = "" }, FileName = "1336_TopPart.JPG", FileSize = 737269, ImageRotation = Rotation.Rotate0, @@ -227,9 +235,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset9 = new() + _asset9 = new() { FolderId = new Guid("5126101a-c970-4c87-92ee-ab415ff659f3"), + Folder = new() { Path = "" }, FileName = "1336_TopRightPart.JPG", FileSize = 383508, ImageRotation = Rotation.Rotate0, @@ -244,9 +253,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset10 = new() // Another asset completely different than the actual asset + _asset10 = new() // Another asset completely different from the actual asset { FolderId = new Guid("5b506904-45af-4eaf-b402-53f6d0012075"), + Folder = new() { Path = "" }, FileName = "Image 1.jpg", FileSize = 29857, ImageRotation = Rotation.Rotate0, @@ -272,7 +282,7 @@ public void SetUp() [TestCase("80", 0, new string[] { })] [TestCase("100", 0, new string[] { })] [TestCase("110", 0, new string[] { })] - [TestCase("128", 1, new string[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG", "1336_BottomRightPart.JPG", "1336_LeftPart.JPG", "1336_Original.JPG", "1336_RightPart.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG", "1336_TopRightPart.JPG", "Image 1.jpg" })] + [TestCase("128", 1, new[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG", "1336_BottomRightPart.JPG", "1336_LeftPart.JPG", "1336_Original.JPG", "1336_RightPart.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG", "1336_TopRightPart.JPG", "Image 1.jpg" })] public void GetDuplicatesBetweenOriginalAndThumbnail_PartBasicHashDifferentThresholdValues(string thresholdToMock, int expected, string[] assetsName) { try @@ -281,45 +291,45 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_PartBasicHashDifferentThres UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); FindDuplicatedAssetsService findDuplicatedAssetsService = new (_assetRepository!, _storageService!, userConfigurationService); - string folderPath1 = Path.Combine(dataDirectory!, "Duplicates\\Part"); - string folderPath2 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "Duplicates\\Part"); + string folderPath2 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); Folder folder1 = new() { Path = folderPath1 }; Folder folder2 = new() { Path = folderPath2 }; - asset1!.Folder = folder1; - asset1.Hash = asset1336_BottomLeftPartHash; - asset2!.Folder = folder1; - asset2.Hash = asset1336_BottomPartHash; - asset3!.Folder = folder1; - asset3.Hash = asset1336_BottomRightPartHash; - asset4!.Folder = folder1; - asset4.Hash = asset1336_LeftPartHash; - asset5!.Folder = folder1; - asset5.Hash = asset1336_OriginalHash; - asset6!.Folder = folder1; - asset6.Hash = asset1336_RightPartHash; - asset7!.Folder = folder1; - asset7!.Hash = asset1336_TopLeftPartHash; - asset8!.Folder = folder1; - asset8!.Hash = asset1336_TopPartHash; - asset9!.Folder = folder1; - asset9!.Hash = asset1336_TopRightPartHash; - asset10!.Folder = folder2; - asset10.Hash = miscAssetHash; // If this asset is in the set, then the threshold is not good + _asset1!.Folder = folder1; + _asset1.Hash = ASSET1336_BOTTOM_LEFT_PART_HASH; + _asset2!.Folder = folder1; + _asset2.Hash = ASSET1336_BOTTOM_PART_HASH; + _asset3!.Folder = folder1; + _asset3.Hash = ASSET1336_BOTTOM_RIGHT_PART_HASH; + _asset4!.Folder = folder1; + _asset4.Hash = ASSET1336_LEFT_PART_HASH; + _asset5!.Folder = folder1; + _asset5.Hash = ASSET1336_ORIGINAL_HASH; + _asset6!.Folder = folder1; + _asset6.Hash = ASSET1336_RIGHT_PART_HASH; + _asset7!.Folder = folder1; + _asset7!.Hash = ASSET1336_TOP_LEFT_PART_HASH; + _asset8!.Folder = folder1; + _asset8!.Hash = ASSET1336_TOP_PART_HASH; + _asset9!.Folder = folder1; + _asset9!.Hash = ASSET1336_TOP_RIGHT_PART_HASH; + _asset10!.Folder = folder2; + _asset10.Hash = MISC_ASSET_HASH; // If this asset is in the set, then the threshold is not good byte[] assetData1 = [1, 2, 3]; - _assetRepository!.AddAsset(asset1, assetData1); - _assetRepository.AddAsset(asset2, assetData1); - _assetRepository.AddAsset(asset3, assetData1); - _assetRepository.AddAsset(asset4, assetData1); - _assetRepository.AddAsset(asset5, assetData1); - _assetRepository.AddAsset(asset6, assetData1); - _assetRepository.AddAsset(asset7, assetData1); - _assetRepository.AddAsset(asset8, assetData1); - _assetRepository.AddAsset(asset9, assetData1); - _assetRepository.AddAsset(asset10, assetData1); + _assetRepository!.AddAsset(_asset1, assetData1); + _assetRepository.AddAsset(_asset2, assetData1); + _assetRepository.AddAsset(_asset3, assetData1); + _assetRepository.AddAsset(_asset4, assetData1); + _assetRepository.AddAsset(_asset5, assetData1); + _assetRepository.AddAsset(_asset6, assetData1); + _assetRepository.AddAsset(_asset7, assetData1); + _assetRepository.AddAsset(_asset8, assetData1); + _assetRepository.AddAsset(_asset9, assetData1); + _assetRepository.AddAsset(_asset10, assetData1); List> duplicatedAssets = findDuplicatedAssetsService.GetDuplicatedAssets(); @@ -333,7 +343,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_PartBasicHashDifferentThres } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } @@ -345,7 +355,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_PartBasicHashDifferentThres [TestCase("15", 0, new string[] { })] [TestCase("20", 0, new string[] { })] [TestCase("25", 0, new string[] { })] - [TestCase("32", 1, new string[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG", "1336_BottomRightPart.JPG", "1336_LeftPart.JPG", "1336_Original.JPG", "1336_RightPart.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG", "1336_TopRightPart.JPG", "Image 1.jpg" })] + [TestCase("32", 1, new[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG", "1336_BottomRightPart.JPG", "1336_LeftPart.JPG", "1336_Original.JPG", "1336_RightPart.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG", "1336_TopRightPart.JPG", "Image 1.jpg" })] public void GetDuplicatesBetweenOriginalAndThumbnail_PartMD5HashDifferentThresholdValues(string thresholdToMock, int expected, string[] assetsName) { try @@ -354,45 +364,45 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_PartMD5HashDifferentThresho UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); FindDuplicatedAssetsService findDuplicatedAssetsService = new (_assetRepository!, _storageService!, userConfigurationService); - string folderPath1 = Path.Combine(dataDirectory!, "Duplicates\\Part"); - string folderPath2 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "Duplicates\\Part"); + string folderPath2 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); Folder folder1 = new() { Path = folderPath1 }; Folder folder2 = new() { Path = folderPath2 }; - asset1!.Folder = folder1; - asset1.Hash = asset1336_BottomLeftPartMD5Hash; - asset2!.Folder = folder1; - asset2.Hash = asset1336_BottomPartMD5Hash; - asset3!.Folder = folder1; - asset3.Hash = asset1336_BottomRightPartMD5Hash; - asset4!.Folder = folder1; - asset4.Hash = asset1336_LeftPartMD5Hash; - asset5!.Folder = folder1; - asset5.Hash = asset1336_OriginalMD5Hash; - asset6!.Folder = folder1; - asset6.Hash = asset1336_RightPartMD5Hash; - asset7!.Folder = folder1; - asset7!.Hash = asset1336_TopLeftPartMD5Hash; - asset8!.Folder = folder1; - asset8!.Hash = asset1336_TopPartMD5Hash; - asset9!.Folder = folder1; - asset9!.Hash = asset1336_TopRightPartMD5Hash; - asset10!.Folder = folder2; - asset10.Hash = miscAssetMD5Hash; // If this asset is in the set, then the threshold is not good + _asset1!.Folder = folder1; + _asset1.Hash = ASSET1336_BOTTOM_LEFT_PART_MD5_HASH; + _asset2!.Folder = folder1; + _asset2.Hash = ASSET1336_BOTTOM_PART_MD5_HASH; + _asset3!.Folder = folder1; + _asset3.Hash = ASSET1336_BOTTOM_RIGHT_PART_MD5_HASH; + _asset4!.Folder = folder1; + _asset4.Hash = ASSET1336_LEFT_PART_MD5_HASH; + _asset5!.Folder = folder1; + _asset5.Hash = ASSET1336_ORIGINAL_MD5_HASH; + _asset6!.Folder = folder1; + _asset6.Hash = ASSET1336_RIGHT_PART_MD5_HASH; + _asset7!.Folder = folder1; + _asset7!.Hash = ASSET1336_TOP_LEFT_PART_MD5_HASH; + _asset8!.Folder = folder1; + _asset8!.Hash = ASSET1336_TOP_PART_MD5_HASH; + _asset9!.Folder = folder1; + _asset9!.Hash = ASSET1336_TOP_RIGHT_PART_MD5_HASH; + _asset10!.Folder = folder2; + _asset10.Hash = MISC_ASSET_MD5_HASH; // If this asset is in the set, then the threshold is not good byte[] assetData1 = [1, 2, 3]; - _assetRepository!.AddAsset(asset1, assetData1); - _assetRepository.AddAsset(asset2, assetData1); - _assetRepository.AddAsset(asset3, assetData1); - _assetRepository.AddAsset(asset4, assetData1); - _assetRepository.AddAsset(asset5, assetData1); - _assetRepository.AddAsset(asset6, assetData1); - _assetRepository.AddAsset(asset7, assetData1); - _assetRepository.AddAsset(asset8, assetData1); - _assetRepository.AddAsset(asset9, assetData1); - _assetRepository.AddAsset(asset10, assetData1); + _assetRepository!.AddAsset(_asset1, assetData1); + _assetRepository.AddAsset(_asset2, assetData1); + _assetRepository.AddAsset(_asset3, assetData1); + _assetRepository.AddAsset(_asset4, assetData1); + _assetRepository.AddAsset(_asset5, assetData1); + _assetRepository.AddAsset(_asset6, assetData1); + _assetRepository.AddAsset(_asset7, assetData1); + _assetRepository.AddAsset(_asset8, assetData1); + _assetRepository.AddAsset(_asset9, assetData1); + _assetRepository.AddAsset(_asset10, assetData1); List> duplicatedAssets = findDuplicatedAssetsService.GetDuplicatedAssets(); @@ -406,19 +416,19 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_PartMD5HashDifferentThresho } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } // The hamming distance is about 14 between these hashes (for some, 0) [Test] [Category("Part folder, DHash")] // The DHash is a 17-character number - [TestCase("3", 3, new string[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG" }, new string[] { "1336_LeftPart.JPG", "1336_Original.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG" }, new string[] { "1336_RightPart.JPG", "1336_TopRightPart.JPG" })] - [TestCase("5", 3, new string[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG" }, new string[] { "1336_LeftPart.JPG", "1336_Original.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG" }, new string[] { "1336_RightPart.JPG", "1336_TopRightPart.JPG" })] - [TestCase("9", 3, new string[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG" }, new string[] { "1336_LeftPart.JPG", "1336_Original.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG" }, new string[] { "1336_RightPart.JPG", "1336_TopRightPart.JPG" })] - [TestCase("11", 3, new string[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG" }, new string[] { "1336_LeftPart.JPG", "1336_Original.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG" }, new string[] { "1336_RightPart.JPG", "1336_TopRightPart.JPG" })] - [TestCase("14", 2, new string[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG", "1336_LeftPart.JPG", "1336_Original.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG" }, new string[] { "1336_RightPart.JPG", "1336_TopRightPart.JPG" }, new string[] { })] - [TestCase("17", 1, new string[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG", "1336_BottomRightPart.JPG", "1336_LeftPart.JPG", "1336_Original.JPG", "1336_RightPart.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG", "1336_TopRightPart.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] + [TestCase("3", 3, new[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG" }, new[] { "1336_LeftPart.JPG", "1336_Original.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG" }, new[] { "1336_RightPart.JPG", "1336_TopRightPart.JPG" })] + [TestCase("5", 3, new[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG" }, new[] { "1336_LeftPart.JPG", "1336_Original.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG" }, new[] { "1336_RightPart.JPG", "1336_TopRightPart.JPG" })] + [TestCase("9", 3, new[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG" }, new[] { "1336_LeftPart.JPG", "1336_Original.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG" }, new[] { "1336_RightPart.JPG", "1336_TopRightPart.JPG" })] + [TestCase("11", 3, new[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG" }, new[] { "1336_LeftPart.JPG", "1336_Original.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG" }, new[] { "1336_RightPart.JPG", "1336_TopRightPart.JPG" })] + [TestCase("14", 2, new[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG", "1336_LeftPart.JPG", "1336_Original.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG" }, new[] { "1336_RightPart.JPG", "1336_TopRightPart.JPG" }, new string[] { })] + [TestCase("17", 1, new[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG", "1336_BottomRightPart.JPG", "1336_LeftPart.JPG", "1336_Original.JPG", "1336_RightPart.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG", "1336_TopRightPart.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] public void GetDuplicatesBetweenOriginalAndThumbnail_PartDHashDifferentThresholdValues(string thresholdToMock, int expected, string[] assetsName1, string[] assetsName2, string[] assetsName3) { try @@ -427,45 +437,45 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_PartDHashDifferentThreshold UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); FindDuplicatedAssetsService findDuplicatedAssetsService = new (_assetRepository!, _storageService!, userConfigurationService); - string folderPath1 = Path.Combine(dataDirectory!, "Duplicates\\Part"); - string folderPath2 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "Duplicates\\Part"); + string folderPath2 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); Folder folder1 = new() { Path = folderPath1 }; Folder folder2 = new() { Path = folderPath2 }; - asset1!.Folder = folder1; - asset1.Hash = asset1336_BottomLeftPartDHash; - asset2!.Folder = folder1; - asset2.Hash = asset1336_BottomPartDHash; - asset3!.Folder = folder1; - asset3.Hash = asset1336_BottomRightPartDHash; - asset4!.Folder = folder1; - asset4.Hash = asset1336_LeftPartDHash; - asset5!.Folder = folder1; - asset5.Hash = asset1336_OriginalDHash; - asset6!.Folder = folder1; - asset6.Hash = asset1336_RightPartDHash; - asset7!.Folder = folder1; - asset7!.Hash = asset1336_TopLeftPartDHash; - asset8!.Folder = folder1; - asset8!.Hash = asset1336_TopPartDHash; - asset9!.Folder = folder1; - asset9!.Hash = asset1336_TopRightPartDHash; - asset10!.Folder = folder2; - asset10.Hash = miscAssetDHash; // If this asset is in the set, then the threshold is not good + _asset1!.Folder = folder1; + _asset1.Hash = ASSET1336_BOTTOM_LEFT_PART_D_HASH; + _asset2!.Folder = folder1; + _asset2.Hash = ASSET1336_BOTTOM_PART_D_HASH; + _asset3!.Folder = folder1; + _asset3.Hash = ASSET1336_BOTTOM_RIGHT_PART_D_HASH; + _asset4!.Folder = folder1; + _asset4.Hash = ASSET1336_LEFT_PART_D_HASH; + _asset5!.Folder = folder1; + _asset5.Hash = ASSET1336_ORIGINAL_D_HASH; + _asset6!.Folder = folder1; + _asset6.Hash = ASSET1336_RIGHT_PART_D_HASH; + _asset7!.Folder = folder1; + _asset7!.Hash = ASSET1336_TOP_LEFT_PART_D_HASH; + _asset8!.Folder = folder1; + _asset8!.Hash = ASSET1336_TOP_PART_D_HASH; + _asset9!.Folder = folder1; + _asset9!.Hash = ASSET1336_TOP_RIGHT_PART_D_HASH; + _asset10!.Folder = folder2; + _asset10.Hash = MISC_ASSET_D_HASH; // If this asset is in the set, then the threshold is not good byte[] assetData1 = [1, 2, 3]; - _assetRepository!.AddAsset(asset1, assetData1); - _assetRepository.AddAsset(asset2, assetData1); - _assetRepository.AddAsset(asset3, assetData1); - _assetRepository.AddAsset(asset4, assetData1); - _assetRepository.AddAsset(asset5, assetData1); - _assetRepository.AddAsset(asset6, assetData1); - _assetRepository.AddAsset(asset7, assetData1); - _assetRepository.AddAsset(asset8, assetData1); - _assetRepository.AddAsset(asset9, assetData1); - _assetRepository.AddAsset(asset10, assetData1); + _assetRepository!.AddAsset(_asset1, assetData1); + _assetRepository.AddAsset(_asset2, assetData1); + _assetRepository.AddAsset(_asset3, assetData1); + _assetRepository.AddAsset(_asset4, assetData1); + _assetRepository.AddAsset(_asset5, assetData1); + _assetRepository.AddAsset(_asset6, assetData1); + _assetRepository.AddAsset(_asset7, assetData1); + _assetRepository.AddAsset(_asset8, assetData1); + _assetRepository.AddAsset(_asset9, assetData1); + _assetRepository.AddAsset(_asset10, assetData1); List> duplicatedAssets = findDuplicatedAssetsService.GetDuplicatedAssets(); @@ -489,7 +499,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_PartDHashDifferentThreshold } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } @@ -502,14 +512,14 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_PartDHashDifferentThreshold [TestCase("40", 0, new string[] { }, new string[] { }, new string[] { })] [TestCase("50", 0, new string[] { }, new string[] { }, new string[] { })] [TestCase("60", 0, new string[] { }, new string[] { }, new string[] { })] - [TestCase("80", 1, new string[] { "1336_BottomLeftPart.JPG", "1336_Original.JPG" }, new string[] { }, new string[] { })] - [TestCase("90", 1, new string[] { "1336_BottomLeftPart.JPG", "1336_Original.JPG" }, new string[] { }, new string[] { })] - [TestCase("100", 3, new string[] { "1336_BottomLeftPart.JPG", "1336_Original.JPG", "1336_TopLeftPart.JPG", "1336_TopRightPart.JPG" }, new string[] { "1336_BottomPart.JPG", "1336_BottomRightPart.JPG", "1336_RightPart.JPG" }, new string[] { "1336_LeftPart.JPG", "1336_TopPart.JPG" })] - [TestCase("120", 1, new string[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG", "1336_BottomRightPart.JPG", "1336_LeftPart.JPG", "1336_Original.JPG", "1336_RightPart.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG", "1336_TopRightPart.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] - [TestCase("140", 1, new string[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG", "1336_BottomRightPart.JPG", "1336_LeftPart.JPG", "1336_Original.JPG", "1336_RightPart.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG", "1336_TopRightPart.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] - [TestCase("160", 1, new string[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG", "1336_BottomRightPart.JPG", "1336_LeftPart.JPG", "1336_Original.JPG", "1336_RightPart.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG", "1336_TopRightPart.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] - [TestCase("180", 1, new string[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG", "1336_BottomRightPart.JPG", "1336_LeftPart.JPG", "1336_Original.JPG", "1336_RightPart.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG", "1336_TopRightPart.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] - [TestCase("210", 1, new string[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG", "1336_BottomRightPart.JPG", "1336_LeftPart.JPG", "1336_Original.JPG", "1336_RightPart.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG", "1336_TopRightPart.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] + [TestCase("80", 1, new[] { "1336_BottomLeftPart.JPG", "1336_Original.JPG" }, new string[] { }, new string[] { })] + [TestCase("90", 1, new[] { "1336_BottomLeftPart.JPG", "1336_Original.JPG" }, new string[] { }, new string[] { })] + [TestCase("100", 3, new[] { "1336_BottomLeftPart.JPG", "1336_Original.JPG", "1336_TopLeftPart.JPG", "1336_TopRightPart.JPG" }, new[] { "1336_BottomPart.JPG", "1336_BottomRightPart.JPG", "1336_RightPart.JPG" }, new[] { "1336_LeftPart.JPG", "1336_TopPart.JPG" })] + [TestCase("120", 1, new[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG", "1336_BottomRightPart.JPG", "1336_LeftPart.JPG", "1336_Original.JPG", "1336_RightPart.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG", "1336_TopRightPart.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] + [TestCase("140", 1, new[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG", "1336_BottomRightPart.JPG", "1336_LeftPart.JPG", "1336_Original.JPG", "1336_RightPart.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG", "1336_TopRightPart.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] + [TestCase("160", 1, new[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG", "1336_BottomRightPart.JPG", "1336_LeftPart.JPG", "1336_Original.JPG", "1336_RightPart.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG", "1336_TopRightPart.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] + [TestCase("180", 1, new[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG", "1336_BottomRightPart.JPG", "1336_LeftPart.JPG", "1336_Original.JPG", "1336_RightPart.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG", "1336_TopRightPart.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] + [TestCase("210", 1, new[] { "1336_BottomLeftPart.JPG", "1336_BottomPart.JPG", "1336_BottomRightPart.JPG", "1336_LeftPart.JPG", "1336_Original.JPG", "1336_RightPart.JPG", "1336_TopLeftPart.JPG", "1336_TopPart.JPG", "1336_TopRightPart.JPG", "Image 1.jpg" }, new string[] { }, new string[] { })] public void GetDuplicatesBetweenOriginalAndThumbnail_PartPHashDifferentThresholdValues(string thresholdToMock, int expected, string[] assetsName1, string[] assetsName2, string[] assetsName3) { try @@ -518,45 +528,45 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_PartPHashDifferentThreshold UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); FindDuplicatedAssetsService findDuplicatedAssetsService = new (_assetRepository!, _storageService!, userConfigurationService); - string folderPath1 = Path.Combine(dataDirectory!, "Duplicates\\Part"); - string folderPath2 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "Duplicates\\Part"); + string folderPath2 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); Folder folder1 = new() { Path = folderPath1 }; Folder folder2 = new() { Path = folderPath2 }; - asset1!.Folder = folder1; - asset1.Hash = asset1336_BottomLeftPartPHash; - asset2!.Folder = folder1; - asset2.Hash = asset1336_BottomPartPHash; - asset3!.Folder = folder1; - asset3.Hash = asset1336_BottomRightPartPHash; - asset4!.Folder = folder1; - asset4.Hash = asset1336_LeftPartPHash; - asset5!.Folder = folder1; - asset5.Hash = asset1336_OriginalPHash; - asset6!.Folder = folder1; - asset6.Hash = asset1336_RightPartPHash; - asset7!.Folder = folder1; - asset7!.Hash = asset1336_TopLeftPartPHash; - asset8!.Folder = folder1; - asset8!.Hash = asset1336_TopPartPHash; - asset9!.Folder = folder1; - asset9!.Hash = asset1336_TopRightPartPHash; - asset10!.Folder = folder2; - asset10.Hash = miscAssetPHash; // If this asset is in the set, then the threshold is not good + _asset1!.Folder = folder1; + _asset1.Hash = ASSET1336_BOTTOM_LEFT_PART_P_HASH; + _asset2!.Folder = folder1; + _asset2.Hash = ASSET1336_BOTTOM_PART_P_HASH; + _asset3!.Folder = folder1; + _asset3.Hash = ASSET1336_BOTTOM_RIGHT_PART_P_HASH; + _asset4!.Folder = folder1; + _asset4.Hash = ASSET1336_LEFT_PART_P_HASH; + _asset5!.Folder = folder1; + _asset5.Hash = ASSET1336_ORIGINAL_P_HASH; + _asset6!.Folder = folder1; + _asset6.Hash = ASSET1336_RIGHT_PART_P_HASH; + _asset7!.Folder = folder1; + _asset7!.Hash = ASSET1336_TOP_LEFT_PART_P_HASH; + _asset8!.Folder = folder1; + _asset8!.Hash = ASSET1336_TOP_PART_P_HASH; + _asset9!.Folder = folder1; + _asset9!.Hash = ASSET1336_TOP_RIGHT_PART_P_HASH; + _asset10!.Folder = folder2; + _asset10.Hash = MISC_ASSET_P_HASH; // If this asset is in the set, then the threshold is not good byte[] assetData1 = [1, 2, 3]; - _assetRepository!.AddAsset(asset1, assetData1); - _assetRepository.AddAsset(asset2, assetData1); - _assetRepository.AddAsset(asset3, assetData1); - _assetRepository.AddAsset(asset4, assetData1); - _assetRepository.AddAsset(asset5, assetData1); - _assetRepository.AddAsset(asset6, assetData1); - _assetRepository.AddAsset(asset7, assetData1); - _assetRepository.AddAsset(asset8, assetData1); - _assetRepository.AddAsset(asset9, assetData1); - _assetRepository.AddAsset(asset10, assetData1); + _assetRepository!.AddAsset(_asset1, assetData1); + _assetRepository.AddAsset(_asset2, assetData1); + _assetRepository.AddAsset(_asset3, assetData1); + _assetRepository.AddAsset(_asset4, assetData1); + _assetRepository.AddAsset(_asset5, assetData1); + _assetRepository.AddAsset(_asset6, assetData1); + _assetRepository.AddAsset(_asset7, assetData1); + _assetRepository.AddAsset(_asset8, assetData1); + _assetRepository.AddAsset(_asset9, assetData1); + _assetRepository.AddAsset(_asset10, assetData1); List> duplicatedAssets = findDuplicatedAssetsService.GetDuplicatedAssets(); @@ -580,7 +590,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_PartPHashDifferentThreshold } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceThumbnailResolutionTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceThumbnailResolutionTests.cs index 0b949542..4d757cc1 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceThumbnailResolutionTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceThumbnailResolutionTests.cs @@ -3,61 +3,61 @@ [TestFixture] public class FindDuplicatedAssetsServiceThumbnailResolutionTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; private AssetRepository? _assetRepository; private StorageService? _storageService; private Mock? _storageServiceMock; private Mock? _configurationRootMock; - private Asset? asset1; - private Asset? asset2; - private Asset? asset3; - private Asset? asset4; - private Asset? asset5; - private Asset? asset6; - private Asset? asset7; - - private readonly string asset1KHash = "4dcbbf63585dc9fff056a0370ee33efc3d7c57b556bce917f89c5012fbacbc1ee2929f7d3a11ee2f8af426b183212d67167d87e48b80707ab5a1fb4e766d2544"; - private readonly string asset2KHash = "76a8f0b611fdd32b73bff92a186449a7e4bf0b84d618fe8b9666bbf2b022ff6bf259a4a98be42db7d9043ff3c3ff20ae720c5067966c40d16ad3fc67769f514b"; - private readonly string asset3KHash = "98044e6674187219ab629c901dfdf5a72f2535104d83cd167d1bdd9039ded91b7a585b74c5c89860f2e0fab85af9e2181265cba48b908028a42b8ec042265f03"; - private readonly string asset4KOriginalHash = "fb0bb3887c28d022113c5c52a65f9da14eab0806842f902b618806dedeb7c53da1ed26ae5bcaf9a358e81efead71c4807ea38054e44f426857f8bf2c1fd1c7aa"; - private readonly string asset8KHash = "18289324fb22b8b337b1f4a7d627c605056e04fd308699bc831af0579cbc2d6a5959811dbecce09b26f82c341ea82d02d5c99c1580f50c24106d19c88bd6eba2"; - private readonly string assetThumbnailHash = "0bbabdb2fe28d4ef53b78a917eb89938fe564d758ebb9cb011e5a675dbee0a8e92bc38b8fe0762e279d48e95e7d17f1bb392fd96e8db7006e9e0bb60c5d2ed31"; - - private readonly string asset1KMD5Hash = "80bbaf9483ef57ae043863fa954615c6"; - private readonly string asset2KMD5Hash = "83355feec0abe189e3b3f1bcff375151"; - private readonly string asset3KMD5Hash = "02433546c8d0b8a9b76f861077924f85"; - private readonly string asset4KOriginalMD5Hash = "bed3d05d409001724e5f6095c2acaa95"; - private readonly string asset8KMD5Hash = "961b08d1e4b7d9ed07fd9c5b83d23edb"; - private readonly string assetThumbnailMD5Hash = "dd33165a8c3329683ca1ce2bb90ed1b2"; - - private readonly string asset1KDHash = "1144041865478144"; - private readonly string asset2KDHash = "3951120804249760"; - private readonly string asset3KDHash = "54473113164973580"; - private readonly string asset4KOriginalDHash = "1090783378"; - private readonly string asset8KDHash = "276890633"; - private readonly string assetThumbnailDHash = "8421922"; - - private readonly string asset1KPHash = "abf0a846dd8aef48929a61f458b6af61f6262ee062ee062ee062ee062ee062ee062ee0abf0a846dd8aef48929a61f458b6af61f6262ee062ee062ee062ee062ee062ee062ee0abf0a846dd8aef48929a61f458b6af61f62abf0a846dd8aef48929a61f458b6af61f62"; - private readonly string asset2KPHash = "abf0b846dd8aef18929961f458b6af61f6262ee062ee062ee062ee062ee062ee062ee0abf0b846dd8aef18929961f458b6af61f6262ee062ee062ee062ee062ee062ee062ee0abf0b846dd8aef18929961f458b6af61f62abf0b846dd8aef18929961f458b6af61f62"; - private readonly string asset3KPHash = "abe7a846b68aeb78925961f3a8b65a61f5462ee062ee062ee062ee062ee062ee062ee0abe7a846b68aeb78925961f3a8b65a61f5462ee062ee062ee062ee062ee062ee062ee0abe7a846b68aeb78925961f3a8b65a61f54abe7a846b68aeb78925961f3a8b65a61f54"; - private readonly string asset4KOriginalPHash = "abf9e847058af2e892da61f508b70361f7162ee062ee062ee062ee062ee062ee062ee0abf9e847058af2e892da61f508b70361f7162ee062ee062ee062ee062ee062ee062ee0abf9e847058af2e892da61f508b70361f71abf9e847058af2e892da61f508b70361f71"; - private readonly string asset8KPHash = "abf6a846f88af0c892c361f4d8b6e661f6a62ee062ee062ee062ee062ee062ee062ee0abf6a846f88af0c892c361f4d8b6e661f6a62ee062ee062ee062ee062ee062ee062ee0abf6a846f88af0c892c361f4d8b6e661f6aabf6a846f88af0c892c361f4d8b6e661f6a"; - private readonly string assetThumbnailPHash = "abf0f846de8aeee8929b61f478b6b061f6062ee062ee062ee062ee062ee062ee062ee0abf0f846de8aeee8929b61f478b6b061f6062ee062ee062ee062ee062ee062ee062ee0abf0f846de8aeee8929b61f478b6b061f60abf0f846de8aeee8929b61f478b6b061f60"; - - private readonly string miscAssetHash = "1fafae17c3c5c38d1205449eebdb9f5976814a5e54ec5797270c8ec467fe6d6d1190255cbaac11d9057c4b2697d90bc7116a46ed90c5ffb71e32e569c3b47fb9"; - private readonly string miscAssetMD5Hash = "a886f237e1cf6da03fb793588fd79b64"; - private readonly string miscAssetDHash = "23831507941108244"; - private readonly string miscAssetPHash = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; + private Asset? _asset1; + private Asset? _asset2; + private Asset? _asset3; + private Asset? _asset4; + private Asset? _asset5; + private Asset? _asset6; + private Asset? _asset7; + + private const string ASSET1_K_HASH = "4dcbbf63585dc9fff056a0370ee33efc3d7c57b556bce917f89c5012fbacbc1ee2929f7d3a11ee2f8af426b183212d67167d87e48b80707ab5a1fb4e766d2544"; + private const string ASSET2_K_HASH = "76a8f0b611fdd32b73bff92a186449a7e4bf0b84d618fe8b9666bbf2b022ff6bf259a4a98be42db7d9043ff3c3ff20ae720c5067966c40d16ad3fc67769f514b"; + private const string ASSET3_K_HASH = "98044e6674187219ab629c901dfdf5a72f2535104d83cd167d1bdd9039ded91b7a585b74c5c89860f2e0fab85af9e2181265cba48b908028a42b8ec042265f03"; + private const string ASSET4_K_ORIGINAL_HASH = "fb0bb3887c28d022113c5c52a65f9da14eab0806842f902b618806dedeb7c53da1ed26ae5bcaf9a358e81efead71c4807ea38054e44f426857f8bf2c1fd1c7aa"; + private const string ASSET8_K_HASH = "18289324fb22b8b337b1f4a7d627c605056e04fd308699bc831af0579cbc2d6a5959811dbecce09b26f82c341ea82d02d5c99c1580f50c24106d19c88bd6eba2"; + private const string ASSET_THUMBNAIL_HASH = "0bbabdb2fe28d4ef53b78a917eb89938fe564d758ebb9cb011e5a675dbee0a8e92bc38b8fe0762e279d48e95e7d17f1bb392fd96e8db7006e9e0bb60c5d2ed31"; + + private const string ASSET1_K_MD5_HASH = "80bbaf9483ef57ae043863fa954615c6"; + private const string ASSET2_K_MD5_HASH = "83355feec0abe189e3b3f1bcff375151"; + private const string ASSET3_K_MD5_HASH = "02433546c8d0b8a9b76f861077924f85"; + private const string ASSET4_K_ORIGINAL_MD5_HASH = "bed3d05d409001724e5f6095c2acaa95"; + private const string ASSET8_K_MD5_HASH = "961b08d1e4b7d9ed07fd9c5b83d23edb"; + private const string ASSET_THUMBNAIL_MD5_HASH = "dd33165a8c3329683ca1ce2bb90ed1b2"; + + private const string ASSET1_K_D_HASH = "1144041865478144"; + private const string ASSET2_K_D_HASH = "3951120804249760"; + private const string ASSET3_K_D_HASH = "54473113164973580"; + private const string ASSET4_K_ORIGINAL_D_HASH = "1090783378"; + private const string ASSET8_K_D_HASH = "276890633"; + private const string ASSET_THUMBNAIL_D_HASH = "8421922"; + + private const string ASSET1_K_P_HASH = "abf0a846dd8aef48929a61f458b6af61f6262ee062ee062ee062ee062ee062ee062ee0abf0a846dd8aef48929a61f458b6af61f6262ee062ee062ee062ee062ee062ee062ee0abf0a846dd8aef48929a61f458b6af61f62abf0a846dd8aef48929a61f458b6af61f62"; + private const string ASSET2_K_P_HASH = "abf0b846dd8aef18929961f458b6af61f6262ee062ee062ee062ee062ee062ee062ee0abf0b846dd8aef18929961f458b6af61f6262ee062ee062ee062ee062ee062ee062ee0abf0b846dd8aef18929961f458b6af61f62abf0b846dd8aef18929961f458b6af61f62"; + private const string ASSET3_K_P_HASH = "abe7a846b68aeb78925961f3a8b65a61f5462ee062ee062ee062ee062ee062ee062ee0abe7a846b68aeb78925961f3a8b65a61f5462ee062ee062ee062ee062ee062ee062ee0abe7a846b68aeb78925961f3a8b65a61f54abe7a846b68aeb78925961f3a8b65a61f54"; + private const string ASSET4_K_ORIGINAL_P_HASH = "abf9e847058af2e892da61f508b70361f7162ee062ee062ee062ee062ee062ee062ee0abf9e847058af2e892da61f508b70361f7162ee062ee062ee062ee062ee062ee062ee0abf9e847058af2e892da61f508b70361f71abf9e847058af2e892da61f508b70361f71"; + private const string ASSET8_K_P_HASH = "abf6a846f88af0c892c361f4d8b6e661f6a62ee062ee062ee062ee062ee062ee062ee0abf6a846f88af0c892c361f4d8b6e661f6a62ee062ee062ee062ee062ee062ee062ee0abf6a846f88af0c892c361f4d8b6e661f6aabf6a846f88af0c892c361f4d8b6e661f6a"; + private const string ASSET_THUMBNAIL_P_HASH = "abf0f846de8aeee8929b61f478b6b061f6062ee062ee062ee062ee062ee062ee062ee0abf0f846de8aeee8929b61f478b6b061f6062ee062ee062ee062ee062ee062ee062ee0abf0f846de8aeee8929b61f478b6b061f60abf0f846de8aeee8929b61f478b6b061f60"; + + private const string MISC_ASSET_HASH = "1fafae17c3c5c38d1205449eebdb9f5976814a5e54ec5797270c8ec467fe6d6d1190255cbaac11d9057c4b2697d90bc7116a46ed90c5ffb71e32e569c3b47fb9"; + private const string MISC_ASSET_MD5_HASH = "a886f237e1cf6da03fb793588fd79b64"; + private const string MISC_ASSET_D_HASH = "23831507941108244"; + private const string MISC_ASSET_P_HASH = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); @@ -65,7 +65,7 @@ public void OneTimeSetUp() _configurationRootMock.MockGetValue(UserConfigurationKeys.USING_PHASH, "true"); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -76,9 +76,10 @@ public void SetUp() _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); _storageService = new (userConfigurationService); - asset1 = new() + _asset1 = new() { FolderId = new Guid("fb379e47-0fe4-4ba9-9ff3-cbd779dca559"), + Folder = new() { Path = "" }, FileName = "1336_1K.JPG", FileSize = 311067, ImageRotation = Rotation.Rotate0, @@ -93,9 +94,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset2 = new() + _asset2 = new() { FolderId = new Guid("fb379e47-0fe4-4ba9-9ff3-cbd779dca559"), + Folder = new() { Path = "" }, FileName = "1336_2K.JPG", FileSize = 1154116, ImageRotation = Rotation.Rotate0, @@ -110,9 +112,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset3 = new() + _asset3 = new() { FolderId = new Guid("fb379e47-0fe4-4ba9-9ff3-cbd779dca559"), + Folder = new() { Path = "" }, FileName = "1336_3K.JPG", FileSize = 2098339, ImageRotation = Rotation.Rotate0, @@ -127,9 +130,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset4 = new() + _asset4 = new() { FolderId = new Guid("fb379e47-0fe4-4ba9-9ff3-cbd779dca559"), + Folder = new() { Path = "" }, FileName = "1336_4K_Original.JPG", FileSize = 4526710, ImageRotation = Rotation.Rotate0, @@ -144,9 +148,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset5 = new() + _asset5 = new() { FolderId = new Guid("fb379e47-0fe4-4ba9-9ff3-cbd779dca559"), + Folder = new() { Path = "" }, FileName = "1336_8K.JPG", FileSize = 8855421, ImageRotation = Rotation.Rotate0, @@ -161,9 +166,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset6 = new() + _asset6 = new() { FolderId = new Guid("fb379e47-0fe4-4ba9-9ff3-cbd779dca559"), + Folder = new() { Path = "" }, FileName = "1336_Thumbnail.JPG", FileSize = 19472, ImageRotation = Rotation.Rotate0, @@ -178,9 +184,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset7 = new() // Another asset completely different than the actual asset + _asset7 = new() // Another asset completely different from the actual asset { FolderId = new Guid("5b506904-45af-4eaf-b402-53f6d0012075"), + Folder = new() { Path = "" }, FileName = "Image 1.jpg", FileSize = 29857, ImageRotation = Rotation.Rotate0, @@ -206,7 +213,7 @@ public void SetUp() [TestCase("80", 0, new string[] { })] [TestCase("100", 0, new string[] { })] [TestCase("110", 0, new string[] { })] - [TestCase("128", 1, new string[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_4K_Original.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG", "Image 1.jpg" })] + [TestCase("128", 1, new[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_4K_Original.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG", "Image 1.jpg" })] public void GetDuplicatesBetweenOriginalAndThumbnail_ResolutionBasicHashDifferentThresholdValues(string thresholdToMock, int expected, string[] assetsName) { try @@ -215,36 +222,36 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_ResolutionBasicHashDifferen UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); FindDuplicatedAssetsService findDuplicatedAssetsService = new (_assetRepository!, _storageService!, userConfigurationService); - string folderPath1 = Path.Combine(dataDirectory!, "Duplicates\\Resolution"); - string folderPath2 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "Duplicates\\Resolution"); + string folderPath2 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); Folder folder1 = new() { Path = folderPath1 }; Folder folder2 = new() { Path = folderPath2 }; - asset1!.Folder = folder1; - asset1.Hash = asset1KHash; - asset2!.Folder = folder1; - asset2.Hash = asset2KHash; - asset3!.Folder = folder1; - asset3.Hash = asset3KHash; - asset4!.Folder = folder1; - asset4.Hash = asset4KOriginalHash; - asset5!.Folder = folder1; - asset5.Hash = asset8KHash; - asset6!.Folder = folder1; - asset6.Hash = assetThumbnailHash; - asset7!.Folder = folder2; - asset7.Hash = miscAssetHash; // If this asset is in the set, then the threshold is not good + _asset1!.Folder = folder1; + _asset1.Hash = ASSET1_K_HASH; + _asset2!.Folder = folder1; + _asset2.Hash = ASSET2_K_HASH; + _asset3!.Folder = folder1; + _asset3.Hash = ASSET3_K_HASH; + _asset4!.Folder = folder1; + _asset4.Hash = ASSET4_K_ORIGINAL_HASH; + _asset5!.Folder = folder1; + _asset5.Hash = ASSET8_K_HASH; + _asset6!.Folder = folder1; + _asset6.Hash = ASSET_THUMBNAIL_HASH; + _asset7!.Folder = folder2; + _asset7.Hash = MISC_ASSET_HASH; // If this asset is in the set, then the threshold is not good byte[] assetData1 = [1, 2, 3]; - _assetRepository!.AddAsset(asset1, assetData1); - _assetRepository.AddAsset(asset2, assetData1); - _assetRepository.AddAsset(asset3, assetData1); - _assetRepository.AddAsset(asset4, assetData1); - _assetRepository.AddAsset(asset5, assetData1); - _assetRepository.AddAsset(asset6, assetData1); - _assetRepository.AddAsset(asset7, assetData1); + _assetRepository!.AddAsset(_asset1, assetData1); + _assetRepository.AddAsset(_asset2, assetData1); + _assetRepository.AddAsset(_asset3, assetData1); + _assetRepository.AddAsset(_asset4, assetData1); + _assetRepository.AddAsset(_asset5, assetData1); + _assetRepository.AddAsset(_asset6, assetData1); + _assetRepository.AddAsset(_asset7, assetData1); List> duplicatedAssets = findDuplicatedAssetsService.GetDuplicatedAssets(); @@ -258,7 +265,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_ResolutionBasicHashDifferen } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } @@ -270,7 +277,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_ResolutionBasicHashDifferen [TestCase("15", 0, new string[] { })] [TestCase("20", 0, new string[] { })] [TestCase("25", 0, new string[] { })] - [TestCase("32", 1, new string[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_4K_Original.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG", "Image 1.jpg" })] + [TestCase("32", 1, new[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_4K_Original.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG", "Image 1.jpg" })] public void GetDuplicatesBetweenOriginalAndThumbnail_ResolutionMD5HashDifferentThresholdValues(string thresholdToMock, int expected, string[] assetsName) { try @@ -279,36 +286,36 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_ResolutionMD5HashDifferentT UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); FindDuplicatedAssetsService findDuplicatedAssetsService = new (_assetRepository!, _storageService!, userConfigurationService); - string folderPath1 = Path.Combine(dataDirectory!, "Duplicates\\Resolution"); - string folderPath2 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "Duplicates\\Resolution"); + string folderPath2 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); Folder folder1 = new() { Path = folderPath1 }; Folder folder2 = new() { Path = folderPath2 }; - asset1!.Folder = folder1; - asset1.Hash = asset1KMD5Hash; - asset2!.Folder = folder1; - asset2.Hash = asset2KMD5Hash; - asset3!.Folder = folder1; - asset3.Hash = asset3KMD5Hash; - asset4!.Folder = folder1; - asset4.Hash = asset4KOriginalMD5Hash; - asset5!.Folder = folder1; - asset5.Hash = asset8KMD5Hash; - asset6!.Folder = folder1; - asset6.Hash = assetThumbnailMD5Hash; - asset7!.Folder = folder2; - asset7.Hash = miscAssetMD5Hash; // If this asset is in the set, then the threshold is not good + _asset1!.Folder = folder1; + _asset1.Hash = ASSET1_K_MD5_HASH; + _asset2!.Folder = folder1; + _asset2.Hash = ASSET2_K_MD5_HASH; + _asset3!.Folder = folder1; + _asset3.Hash = ASSET3_K_MD5_HASH; + _asset4!.Folder = folder1; + _asset4.Hash = ASSET4_K_ORIGINAL_MD5_HASH; + _asset5!.Folder = folder1; + _asset5.Hash = ASSET8_K_MD5_HASH; + _asset6!.Folder = folder1; + _asset6.Hash = ASSET_THUMBNAIL_MD5_HASH; + _asset7!.Folder = folder2; + _asset7.Hash = MISC_ASSET_MD5_HASH; // If this asset is in the set, then the threshold is not good byte[] assetData1 = [1, 2, 3]; - _assetRepository!.AddAsset(asset1, assetData1); - _assetRepository.AddAsset(asset2, assetData1); - _assetRepository.AddAsset(asset3, assetData1); - _assetRepository.AddAsset(asset4, assetData1); - _assetRepository.AddAsset(asset5, assetData1); - _assetRepository.AddAsset(asset6, assetData1); - _assetRepository.AddAsset(asset7, assetData1); + _assetRepository!.AddAsset(_asset1, assetData1); + _assetRepository.AddAsset(_asset2, assetData1); + _assetRepository.AddAsset(_asset3, assetData1); + _assetRepository.AddAsset(_asset4, assetData1); + _assetRepository.AddAsset(_asset5, assetData1); + _assetRepository.AddAsset(_asset6, assetData1); + _assetRepository.AddAsset(_asset7, assetData1); List> duplicatedAssets = findDuplicatedAssetsService.GetDuplicatedAssets(); @@ -322,7 +329,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_ResolutionMD5HashDifferentT } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } @@ -343,36 +350,36 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_ResolutionDHashDifferentThr UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); FindDuplicatedAssetsService findDuplicatedAssetsService = new (_assetRepository!, _storageService!, userConfigurationService); - string folderPath1 = Path.Combine(dataDirectory!, "Duplicates\\Resolution"); - string folderPath2 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "Duplicates\\Resolution"); + string folderPath2 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); Folder folder1 = new() { Path = folderPath1 }; Folder folder2 = new() { Path = folderPath2 }; - asset1!.Folder = folder1; - asset1.Hash = asset1KDHash; - asset2!.Folder = folder1; - asset2.Hash = asset2KDHash; - asset3!.Folder = folder1; - asset3.Hash = asset3KDHash; - asset4!.Folder = folder1; - asset4.Hash = asset4KOriginalDHash; - asset5!.Folder = folder1; - asset5.Hash = asset8KDHash; - asset6!.Folder = folder1; - asset6.Hash = assetThumbnailDHash; - asset7!.Folder = folder2; - asset7.Hash = miscAssetDHash; // If this asset is in the set, then the threshold is not good + _asset1!.Folder = folder1; + _asset1.Hash = ASSET1_K_D_HASH; + _asset2!.Folder = folder1; + _asset2.Hash = ASSET2_K_D_HASH; + _asset3!.Folder = folder1; + _asset3.Hash = ASSET3_K_D_HASH; + _asset4!.Folder = folder1; + _asset4.Hash = ASSET4_K_ORIGINAL_D_HASH; + _asset5!.Folder = folder1; + _asset5.Hash = ASSET8_K_D_HASH; + _asset6!.Folder = folder1; + _asset6.Hash = ASSET_THUMBNAIL_D_HASH; + _asset7!.Folder = folder2; + _asset7.Hash = MISC_ASSET_D_HASH; // If this asset is in the set, then the threshold is not good byte[] assetData1 = [1, 2, 3]; - _assetRepository!.AddAsset(asset1, assetData1); - _assetRepository.AddAsset(asset2, assetData1); - _assetRepository.AddAsset(asset3, assetData1); - _assetRepository.AddAsset(asset4, assetData1); - _assetRepository.AddAsset(asset5, assetData1); - _assetRepository.AddAsset(asset6, assetData1); - _assetRepository.AddAsset(asset7, assetData1); + _assetRepository!.AddAsset(_asset1, assetData1); + _assetRepository.AddAsset(_asset2, assetData1); + _assetRepository.AddAsset(_asset3, assetData1); + _assetRepository.AddAsset(_asset4, assetData1); + _assetRepository.AddAsset(_asset5, assetData1); + _assetRepository.AddAsset(_asset6, assetData1); + _assetRepository.AddAsset(_asset7, assetData1); ArgumentException? exception = Assert.Throws(() => findDuplicatedAssetsService.GetDuplicatedAssets()); @@ -380,7 +387,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_ResolutionDHashDifferentThr } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } @@ -388,19 +395,19 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_ResolutionDHashDifferentThr [Test] [Category("Resolution folder, PHash")] // The PHash is a 210-character hexadecimal string [TestCase("10", 0, new string[] { })] - [TestCase("20", 1, new string[] { "1336_1K.JPG", "1336_2K.JPG" })] - [TestCase("30", 1, new string[] { "1336_1K.JPG", "1336_2K.JPG" })] - [TestCase("40", 1, new string[] { "1336_1K.JPG", "1336_2K.JPG", "1336_Thumbnail.JPG" })] - [TestCase("50", 1, new string[] { "1336_1K.JPG", "1336_2K.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG" })] - [TestCase("60", 1, new string[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG" })] - [TestCase("80", 1, new string[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_4K_Original.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG" })] - [TestCase("90", 1, new string[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_4K_Original.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG" })] - [TestCase("100", 1, new string[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_4K_Original.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG" })] - [TestCase("120", 1, new string[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_4K_Original.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG", "Image 1.jpg" })] - [TestCase("140", 1, new string[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_4K_Original.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG", "Image 1.jpg" })] - [TestCase("160", 1, new string[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_4K_Original.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG", "Image 1.jpg" })] - [TestCase("180", 1, new string[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_4K_Original.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG", "Image 1.jpg" })] - [TestCase("210", 1, new string[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_4K_Original.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG", "Image 1.jpg" })] + [TestCase("20", 1, new[] { "1336_1K.JPG", "1336_2K.JPG" })] + [TestCase("30", 1, new[] { "1336_1K.JPG", "1336_2K.JPG" })] + [TestCase("40", 1, new[] { "1336_1K.JPG", "1336_2K.JPG", "1336_Thumbnail.JPG" })] + [TestCase("50", 1, new[] { "1336_1K.JPG", "1336_2K.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG" })] + [TestCase("60", 1, new[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG" })] + [TestCase("80", 1, new[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_4K_Original.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG" })] + [TestCase("90", 1, new[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_4K_Original.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG" })] + [TestCase("100", 1, new[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_4K_Original.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG" })] + [TestCase("120", 1, new[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_4K_Original.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG", "Image 1.jpg" })] + [TestCase("140", 1, new[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_4K_Original.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG", "Image 1.jpg" })] + [TestCase("160", 1, new[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_4K_Original.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG", "Image 1.jpg" })] + [TestCase("180", 1, new[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_4K_Original.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG", "Image 1.jpg" })] + [TestCase("210", 1, new[] { "1336_1K.JPG", "1336_2K.JPG", "1336_3K.JPG", "1336_4K_Original.JPG", "1336_8K.JPG", "1336_Thumbnail.JPG", "Image 1.jpg" })] public void GetDuplicatesBetweenOriginalAndThumbnail_ResolutionPHashDifferentThresholdValues(string thresholdToMock, int expected, string[] assetsName) { try @@ -409,36 +416,36 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_ResolutionPHashDifferentThr UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); FindDuplicatedAssetsService findDuplicatedAssetsService = new (_assetRepository!, _storageService!, userConfigurationService); - string folderPath1 = Path.Combine(dataDirectory!, "Duplicates\\Resolution"); - string folderPath2 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "Duplicates\\Resolution"); + string folderPath2 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); Folder folder1 = new() { Path = folderPath1 }; Folder folder2 = new() { Path = folderPath2 }; - asset1!.Folder = folder1; - asset1.Hash = asset1KPHash; - asset2!.Folder = folder1; - asset2.Hash = asset2KPHash; - asset3!.Folder = folder1; - asset3.Hash = asset3KPHash; - asset4!.Folder = folder1; - asset4.Hash = asset4KOriginalPHash; - asset5!.Folder = folder1; - asset5.Hash = asset8KPHash; - asset6!.Folder = folder1; - asset6.Hash = assetThumbnailPHash; - asset7!.Folder = folder2; - asset7.Hash = miscAssetPHash; // If this asset is in the set, then the threshold is not good + _asset1!.Folder = folder1; + _asset1.Hash = ASSET1_K_P_HASH; + _asset2!.Folder = folder1; + _asset2.Hash = ASSET2_K_P_HASH; + _asset3!.Folder = folder1; + _asset3.Hash = ASSET3_K_P_HASH; + _asset4!.Folder = folder1; + _asset4.Hash = ASSET4_K_ORIGINAL_P_HASH; + _asset5!.Folder = folder1; + _asset5.Hash = ASSET8_K_P_HASH; + _asset6!.Folder = folder1; + _asset6.Hash = ASSET_THUMBNAIL_P_HASH; + _asset7!.Folder = folder2; + _asset7.Hash = MISC_ASSET_P_HASH; // If this asset is in the set, then the threshold is not good byte[] assetData1 = [1, 2, 3]; - _assetRepository!.AddAsset(asset1, assetData1); - _assetRepository.AddAsset(asset2, assetData1); - _assetRepository.AddAsset(asset3, assetData1); - _assetRepository.AddAsset(asset4, assetData1); - _assetRepository.AddAsset(asset5, assetData1); - _assetRepository.AddAsset(asset6, assetData1); - _assetRepository.AddAsset(asset7, assetData1); + _assetRepository!.AddAsset(_asset1, assetData1); + _assetRepository.AddAsset(_asset2, assetData1); + _assetRepository.AddAsset(_asset3, assetData1); + _assetRepository.AddAsset(_asset4, assetData1); + _assetRepository.AddAsset(_asset5, assetData1); + _assetRepository.AddAsset(_asset6, assetData1); + _assetRepository.AddAsset(_asset7, assetData1); List> duplicatedAssets = findDuplicatedAssetsService.GetDuplicatedAssets(); @@ -452,7 +459,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_ResolutionPHashDifferentThr } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceThumbnailTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceThumbnailTests.cs index 1d276e6f..06377399 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceThumbnailTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceThumbnailTests.cs @@ -3,9 +3,9 @@ [TestFixture] public class FindDuplicatedAssetsServiceThumbnailTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; private FindDuplicatedAssetsService? _findDuplicatedAssetsService; private AssetRepository? _assetRepository; @@ -13,17 +13,17 @@ public class FindDuplicatedAssetsServiceThumbnailTests private Mock? _storageServiceMock; private Mock? _configurationRootMock; - private Asset? asset1; - private Asset? asset2; - private Asset? asset3; - private Asset? asset4; - private Asset? asset5; + private Asset? _asset1; + private Asset? _asset2; + private Asset? _asset3; + private Asset? _asset4; + private Asset? _asset5; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); @@ -31,7 +31,7 @@ public void OneTimeSetUp() _configurationRootMock.MockGetValue(UserConfigurationKeys.USING_PHASH, "true"); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -43,9 +43,10 @@ public void SetUp() _storageService = new (userConfigurationService); _findDuplicatedAssetsService = new (_assetRepository!, _storageService!, userConfigurationService); - asset1 = new() + _asset1 = new() { FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "Image 1.jpg", FileSize = 363888, ImageRotation = Rotation.Rotate0, @@ -60,9 +61,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset2 = new() + _asset2 = new() { FolderId = new Guid("886283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "Image 9.png", FileSize = 4602393, ImageRotation = Rotation.Rotate90, @@ -77,9 +79,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset3 = new() + _asset3 = new() { FolderId = new Guid("886283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "Image 1_duplicate.jpg", FileSize = 363888, ImageRotation = Rotation.Rotate0, @@ -94,9 +97,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset4 = new() + _asset4 = new() { FolderId = new Guid("886283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "Image 9_duplicate.png", FileSize = 4602393, ImageRotation = Rotation.Rotate90, @@ -111,9 +115,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset5 = new() + _asset5 = new() { FolderId = new Guid("886283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "Image_11.heic", FileSize = 2247285, ImageRotation = Rotation.Rotate0, @@ -133,28 +138,28 @@ public void SetUp() [Test] public void GetDuplicatesBetweenOriginalAndThumbnail_DuplicatedAssetsFound_ReturnsListOfDuplicatedSets() { - string destinationPath1 = Path.Combine(dataDirectory!, "Duplicates\\DestinationToCopy1"); - string destinationPath2 = Path.Combine(dataDirectory!, "Duplicates\\DestinationToCopy2"); + string destinationPath1 = Path.Combine(_dataDirectory!, "Duplicates\\DestinationToCopy1"); + string destinationPath2 = Path.Combine(_dataDirectory!, "Duplicates\\DestinationToCopy2"); try { Directory.CreateDirectory(destinationPath1); Directory.CreateDirectory(destinationPath2); - string sourcePath1 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); - string sourcePath2 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); + string sourcePath1 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); + string sourcePath2 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); - string asset1DestinationPath = Path.Combine(destinationPath1, asset1!.FileName); - string asset2DestinationPath = Path.Combine(destinationPath2, asset2!.FileName); - string asset3DestinationPath = Path.Combine(destinationPath2, asset3!.FileName); - string asset4DestinationPath = Path.Combine(destinationPath2, asset4!.FileName); - string asset5DestinationPath = Path.Combine(destinationPath2, asset5!.FileName); + string asset1DestinationPath = Path.Combine(destinationPath1, _asset1!.FileName); + string asset2DestinationPath = Path.Combine(destinationPath2, _asset2!.FileName); + string asset3DestinationPath = Path.Combine(destinationPath2, _asset3!.FileName); + string asset4DestinationPath = Path.Combine(destinationPath2, _asset4!.FileName); + string asset5DestinationPath = Path.Combine(destinationPath2, _asset5!.FileName); - File.Copy(Path.Combine(sourcePath1, asset1!.FileName), asset1DestinationPath); - File.Copy(Path.Combine(sourcePath2, asset2!.FileName), asset2DestinationPath); - File.Copy(Path.Combine(sourcePath2, asset3!.FileName), asset3DestinationPath); - File.Copy(Path.Combine(sourcePath2, asset4!.FileName), asset4DestinationPath); - File.Copy(Path.Combine(sourcePath2, asset5!.FileName), asset5DestinationPath); + File.Copy(Path.Combine(sourcePath1, _asset1!.FileName), asset1DestinationPath); + File.Copy(Path.Combine(sourcePath2, _asset2!.FileName), asset2DestinationPath); + File.Copy(Path.Combine(sourcePath2, _asset3!.FileName), asset3DestinationPath); + File.Copy(Path.Combine(sourcePath2, _asset4!.FileName), asset4DestinationPath); + File.Copy(Path.Combine(sourcePath2, _asset5!.FileName), asset5DestinationPath); DateTime oldDateTime1 = DateTime.Now.AddDays(-1); DateTime oldDateTime2 = DateTime.Now.AddDays(-5); @@ -168,25 +173,25 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_DuplicatedAssetsFound_Retur Folder folder1 = new() { Path = destinationPath1 }; Folder folder2 = new() { Path = destinationPath2 }; - asset1!.Folder = folder1; - asset1.Hash = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; - asset2!.Folder = folder2; - asset2.Hash = "afaff849b08fd348dc1f62dae619b262ee062ee062ee062ee062ee062ee062ee062ee0afaff849b08fd348dc1f62dae619b262ee062ee062ee062ee062ee062ee062ee062ee0afaff849b08fd348dc1f62dae619b262ee0afaff849b08fd348dc1f62dae619b262ee0"; - asset3!.Folder = folder2; - asset3.Hash = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; - asset4!.Folder = folder2; - asset4.Hash = "afaff849b08fd348dc1f62dae619b262ee062ee062ee062ee062ee062ee062ee062ee0afaff849b08fd348dc1f62dae619b262ee062ee062ee062ee062ee062ee062ee062ee0afaff849b08fd348dc1f62dae619b262ee0afaff849b08fd348dc1f62dae619b262ee0"; - asset5!.Folder = folder2; - asset5.Hash = "a926f84a9188106894a161cc28d7cf6205662ee062ee062ee062ee062ee062ee062ee0a926f84a9188106894a161cc28d7cf6205662ee062ee062ee062ee062ee062ee062ee0a926f84a9188106894a161cc28d7cf62056a926f84a9188106894a161cc28d7cf62056"; + _asset1!.Folder = folder1; + _asset1.Hash = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; + _asset2!.Folder = folder2; + _asset2.Hash = "afaff849b08fd348dc1f62dae619b262ee062ee062ee062ee062ee062ee062ee062ee0afaff849b08fd348dc1f62dae619b262ee062ee062ee062ee062ee062ee062ee062ee0afaff849b08fd348dc1f62dae619b262ee0afaff849b08fd348dc1f62dae619b262ee0"; + _asset3!.Folder = folder2; + _asset3.Hash = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; + _asset4!.Folder = folder2; + _asset4.Hash = "afaff849b08fd348dc1f62dae619b262ee062ee062ee062ee062ee062ee062ee062ee0afaff849b08fd348dc1f62dae619b262ee062ee062ee062ee062ee062ee062ee062ee0afaff849b08fd348dc1f62dae619b262ee0afaff849b08fd348dc1f62dae619b262ee0"; + _asset5!.Folder = folder2; + _asset5.Hash = "a926f84a9188106894a161cc28d7cf6205662ee062ee062ee062ee062ee062ee062ee0a926f84a9188106894a161cc28d7cf6205662ee062ee062ee062ee062ee062ee062ee0a926f84a9188106894a161cc28d7cf62056a926f84a9188106894a161cc28d7cf62056"; byte[] assetData1 = [1, 2, 3]; byte[] assetData2 = []; - _assetRepository!.AddAsset(asset1!, assetData1); - _assetRepository.AddAsset(asset2!, assetData2); - _assetRepository.AddAsset(asset3!, assetData1); - _assetRepository.AddAsset(asset4!, assetData2); - _assetRepository.AddAsset(asset5!, assetData1); + _assetRepository!.AddAsset(_asset1!, assetData1); + _assetRepository.AddAsset(_asset2!, assetData2); + _assetRepository.AddAsset(_asset3!, assetData1); + _assetRepository.AddAsset(_asset4!, assetData2); + _assetRepository.AddAsset(_asset5!, assetData1); List> duplicatedAssets = _findDuplicatedAssetsService!.GetDuplicatedAssets(); @@ -199,35 +204,35 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_DuplicatedAssetsFound_Retur Assert.AreEqual(2, firstDuplicatedAssetsSet.Count); Assert.AreEqual(2, secondDuplicatedAssetsSet.Count); - Asset? duplicatedAsset1 = firstDuplicatedAssetsSet.FirstOrDefault(x => x.FileName == asset1.FileName); - Asset? duplicatedAsset3 = firstDuplicatedAssetsSet.FirstOrDefault(x => x.FileName == asset3.FileName); + Asset? duplicatedAsset1 = firstDuplicatedAssetsSet.FirstOrDefault(x => x.FileName == _asset1.FileName); + Asset? duplicatedAsset3 = firstDuplicatedAssetsSet.FirstOrDefault(x => x.FileName == _asset3.FileName); DateTime actualDate = DateTime.Now.Date; Assert.IsNotNull(duplicatedAsset1); Assert.IsNotNull(duplicatedAsset3); - Assert.AreEqual(asset1.FileName, duplicatedAsset1!.FileName); - Assert.AreEqual(actualDate, duplicatedAsset1!.FileCreationDateTime.Date); - Assert.AreEqual(oldDateTime1.Date, duplicatedAsset1!.FileModificationDateTime.Date); - Assert.AreEqual(asset3.FileName, duplicatedAsset3!.FileName); - Assert.AreEqual(actualDate, duplicatedAsset3!.FileCreationDateTime.Date); - Assert.AreEqual(oldDateTime2.Date, duplicatedAsset3!.FileModificationDateTime.Date); + Assert.AreEqual(_asset1.FileName, duplicatedAsset1!.FileName); + Assert.AreEqual(actualDate, duplicatedAsset1.FileCreationDateTime.Date); + Assert.AreEqual(oldDateTime1.Date, duplicatedAsset1.FileModificationDateTime.Date); + Assert.AreEqual(_asset3.FileName, duplicatedAsset3!.FileName); + Assert.AreEqual(actualDate, duplicatedAsset3.FileCreationDateTime.Date); + Assert.AreEqual(oldDateTime2.Date, duplicatedAsset3.FileModificationDateTime.Date); - Asset? duplicatedAsset2 = secondDuplicatedAssetsSet.FirstOrDefault(x => x.FileName == asset2.FileName); - Asset? duplicatedAsset4 = secondDuplicatedAssetsSet.FirstOrDefault(x => x.FileName == asset4.FileName); + Asset? duplicatedAsset2 = secondDuplicatedAssetsSet.FirstOrDefault(x => x.FileName == _asset2.FileName); + Asset? duplicatedAsset4 = secondDuplicatedAssetsSet.FirstOrDefault(x => x.FileName == _asset4.FileName); Assert.IsNotNull(duplicatedAsset2); Assert.IsNotNull(duplicatedAsset4); - Assert.AreEqual(asset2.FileName, duplicatedAsset2!.FileName); - Assert.AreEqual(actualDate, duplicatedAsset2!.FileCreationDateTime.Date); - Assert.AreEqual(oldDateTime1.Date, duplicatedAsset2!.FileModificationDateTime.Date); - Assert.AreEqual(asset4.FileName, duplicatedAsset4!.FileName); - Assert.AreEqual(actualDate, duplicatedAsset4!.FileCreationDateTime.Date); - Assert.AreEqual(oldDateTime2.Date, duplicatedAsset4!.FileModificationDateTime.Date); + Assert.AreEqual(_asset2.FileName, duplicatedAsset2!.FileName); + Assert.AreEqual(actualDate, duplicatedAsset2.FileCreationDateTime.Date); + Assert.AreEqual(oldDateTime1.Date, duplicatedAsset2.FileModificationDateTime.Date); + Assert.AreEqual(_asset4.FileName, duplicatedAsset4!.FileName); + Assert.AreEqual(actualDate, duplicatedAsset4.FileCreationDateTime.Date); + Assert.AreEqual(oldDateTime2.Date, duplicatedAsset4.FileModificationDateTime.Date); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); Directory.Delete(destinationPath1, true); Directory.Delete(destinationPath2, true); } @@ -236,25 +241,25 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_DuplicatedAssetsFound_Retur [Test] public void GetDuplicatesBetweenOriginalAndThumbnail_MultiplesAssetsSameHash_ReturnsListOfDuplicatedSets() { - string destinationPath = Path.Combine(dataDirectory!, "Duplicates\\DestinationToCopy"); + string destinationPath = Path.Combine(_dataDirectory!, "Duplicates\\DestinationToCopy"); try { Directory.CreateDirectory(destinationPath); - string hash = "f8d5cf6deda198be0f181dd7cabfe74cb14c43426c867f0ae855d9e844651e2d7ce4833c178912d5bc7be600cfdd18d5ba19f45988a0c6943b4476a90295e960"; + const string hash = "f8d5cf6deda198be0f181dd7cabfe74cb14c43426c867f0ae855d9e844651e2d7ce4833c178912d5bc7be600cfdd18d5ba19f45988a0c6943b4476a90295e960"; - string sourcePath = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); + string sourcePath = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); - string asset2DestinationPath = Path.Combine(destinationPath, asset2!.FileName); - string asset3DestinationPath = Path.Combine(destinationPath, asset3!.FileName); - string asset4DestinationPath = Path.Combine(destinationPath, asset4!.FileName); - string asset5DestinationPath = Path.Combine(destinationPath, asset5!.FileName); + string asset2DestinationPath = Path.Combine(destinationPath, _asset2!.FileName); + string asset3DestinationPath = Path.Combine(destinationPath, _asset3!.FileName); + string asset4DestinationPath = Path.Combine(destinationPath, _asset4!.FileName); + string asset5DestinationPath = Path.Combine(destinationPath, _asset5!.FileName); - File.Copy(Path.Combine(sourcePath, asset2!.FileName), asset2DestinationPath); - File.Copy(Path.Combine(sourcePath, asset3!.FileName), asset3DestinationPath); - File.Copy(Path.Combine(sourcePath, asset4!.FileName), asset4DestinationPath); - File.Copy(Path.Combine(sourcePath, asset5!.FileName), asset5DestinationPath); + File.Copy(Path.Combine(sourcePath, _asset2!.FileName), asset2DestinationPath); + File.Copy(Path.Combine(sourcePath, _asset3!.FileName), asset3DestinationPath); + File.Copy(Path.Combine(sourcePath, _asset4!.FileName), asset4DestinationPath); + File.Copy(Path.Combine(sourcePath, _asset5!.FileName), asset5DestinationPath); DateTime oldDateTime1 = DateTime.Now.AddDays(-1); DateTime oldDateTime2 = DateTime.Now.AddDays(-5); @@ -266,22 +271,22 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_MultiplesAssetsSameHash_Ret Folder folder = new() { Path = destinationPath }; - asset2!.Folder = folder; - asset2.Hash = hash; - asset3!.Folder = folder; - asset3.Hash = hash; - asset4!.Folder = folder; - asset4.Hash = hash; - asset5!.Folder = folder; - asset5.Hash = hash; + _asset2!.Folder = folder; + _asset2.Hash = hash; + _asset3!.Folder = folder; + _asset3.Hash = hash; + _asset4!.Folder = folder; + _asset4.Hash = hash; + _asset5!.Folder = folder; + _asset5.Hash = hash; byte[] assetData = [1, 2, 3]; - _assetRepository!.AddAsset(asset1!, assetData); - _assetRepository.AddAsset(asset2!, assetData); - _assetRepository.AddAsset(asset3!, assetData); - _assetRepository.AddAsset(asset4!, assetData); - _assetRepository.AddAsset(asset5!, assetData); + _assetRepository!.AddAsset(_asset1!, assetData); + _assetRepository.AddAsset(_asset2!, assetData); + _assetRepository.AddAsset(_asset3!, assetData); + _assetRepository.AddAsset(_asset4!, assetData); + _assetRepository.AddAsset(_asset5!, assetData); List> duplicatedAssets = _findDuplicatedAssetsService!.GetDuplicatedAssets(); @@ -292,10 +297,10 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_MultiplesAssetsSameHash_Ret Assert.AreEqual(4, duplicatedAssetsSet.Count); - Asset? duplicatedAsset2 = duplicatedAssetsSet.FirstOrDefault(x => x.FileName == asset2.FileName); - Asset? duplicatedAsset3 = duplicatedAssetsSet.FirstOrDefault(x => x.FileName == asset3.FileName); - Asset? duplicatedAsset4 = duplicatedAssetsSet.FirstOrDefault(x => x.FileName == asset4.FileName); - Asset? duplicatedAsset5 = duplicatedAssetsSet.FirstOrDefault(x => x.FileName == asset5.FileName); + Asset? duplicatedAsset2 = duplicatedAssetsSet.FirstOrDefault(x => x.FileName == _asset2.FileName); + Asset? duplicatedAsset3 = duplicatedAssetsSet.FirstOrDefault(x => x.FileName == _asset3.FileName); + Asset? duplicatedAsset4 = duplicatedAssetsSet.FirstOrDefault(x => x.FileName == _asset4.FileName); + Asset? duplicatedAsset5 = duplicatedAssetsSet.FirstOrDefault(x => x.FileName == _asset5.FileName); DateTime actualDate = DateTime.Now.Date; @@ -304,25 +309,25 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_MultiplesAssetsSameHash_Ret Assert.IsNotNull(duplicatedAsset4); Assert.IsNotNull(duplicatedAsset5); - Assert.AreEqual(asset2.FileName, duplicatedAsset2!.FileName); - Assert.AreEqual(actualDate, duplicatedAsset2!.FileCreationDateTime.Date); - Assert.AreEqual(oldDateTime1.Date, duplicatedAsset2!.FileModificationDateTime.Date); + Assert.AreEqual(_asset2.FileName, duplicatedAsset2!.FileName); + Assert.AreEqual(actualDate, duplicatedAsset2.FileCreationDateTime.Date); + Assert.AreEqual(oldDateTime1.Date, duplicatedAsset2.FileModificationDateTime.Date); - Assert.AreEqual(asset3.FileName, duplicatedAsset3!.FileName); - Assert.AreEqual(actualDate, duplicatedAsset3!.FileCreationDateTime.Date); - Assert.AreEqual(oldDateTime2.Date, duplicatedAsset3!.FileModificationDateTime.Date); + Assert.AreEqual(_asset3.FileName, duplicatedAsset3!.FileName); + Assert.AreEqual(actualDate, duplicatedAsset3.FileCreationDateTime.Date); + Assert.AreEqual(oldDateTime2.Date, duplicatedAsset3.FileModificationDateTime.Date); - Assert.AreEqual(asset4.FileName, duplicatedAsset4!.FileName); - Assert.AreEqual(actualDate, duplicatedAsset4!.FileCreationDateTime.Date); - Assert.AreEqual(oldDateTime2.Date, duplicatedAsset4!.FileModificationDateTime.Date); + Assert.AreEqual(_asset4.FileName, duplicatedAsset4!.FileName); + Assert.AreEqual(actualDate, duplicatedAsset4.FileCreationDateTime.Date); + Assert.AreEqual(oldDateTime2.Date, duplicatedAsset4.FileModificationDateTime.Date); - Assert.AreEqual(asset5.FileName, duplicatedAsset5!.FileName); - Assert.AreEqual(actualDate, duplicatedAsset5!.FileCreationDateTime.Date); - Assert.AreEqual(oldDateTime1.Date, duplicatedAsset5!.FileModificationDateTime.Date); + Assert.AreEqual(_asset5.FileName, duplicatedAsset5!.FileName); + Assert.AreEqual(actualDate, duplicatedAsset5.FileCreationDateTime.Date); + Assert.AreEqual(oldDateTime1.Date, duplicatedAsset5.FileModificationDateTime.Date); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); Directory.Delete(destinationPath, true); } } @@ -332,21 +337,21 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_DuplicatesButOneFileDoesNot { try { - string folderPath1 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "NewFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "NewFolder2"); Folder folder1 = new() { Path = folderPath1 }; Folder folder2 = new() { Path = folderPath2 }; - asset1!.Folder = folder1; - asset1.Hash = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; - asset3!.Folder = folder2; - asset3.Hash = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; + _asset1!.Folder = folder1; + _asset1.Hash = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; + _asset3!.Folder = folder2; + _asset3.Hash = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; byte[] assetData1 = [1, 2, 3]; - _assetRepository!.AddAsset(asset1!, assetData1); - _assetRepository.AddAsset(asset3!, assetData1); + _assetRepository!.AddAsset(_asset1!, assetData1); + _assetRepository.AddAsset(_asset3!, assetData1); List> duplicatedAssets = _findDuplicatedAssetsService!.GetDuplicatedAssets(); @@ -354,7 +359,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_DuplicatesButOneFileDoesNot } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } @@ -363,31 +368,31 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_FilesDoNotExist_ReturnsEmpt { try { - string folderPath1 = Path.Combine(dataDirectory!, "NewFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "NewFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "NewFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "NewFolder2"); Folder folder1 = new() { Path = folderPath1 }; Folder folder2 = new() { Path = folderPath2 }; - asset1!.Folder = folder1; - asset1.Hash = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; - asset2!.Folder = folder2; - asset2.Hash = "afaff849b08fd348dc1f62dae619b262ee062ee062ee062ee062ee062ee062ee062ee0afaff849b08fd348dc1f62dae619b262ee062ee062ee062ee062ee062ee062ee062ee0afaff849b08fd348dc1f62dae619b262ee0afaff849b08fd348dc1f62dae619b262ee0"; - asset3!.Folder = folder2; - asset3.Hash = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; - asset4!.Folder = folder2; - asset4.Hash = "afaff849b08fd348dc1f62dae619b262ee062ee062ee062ee062ee062ee062ee062ee0afaff849b08fd348dc1f62dae619b262ee062ee062ee062ee062ee062ee062ee062ee0afaff849b08fd348dc1f62dae619b262ee0afaff849b08fd348dc1f62dae619b262ee0"; - asset5!.Folder = folder2; - asset5.Hash = "a926f84a9188106894a161cc28d7cf6205662ee062ee062ee062ee062ee062ee062ee0a926f84a9188106894a161cc28d7cf6205662ee062ee062ee062ee062ee062ee062ee0a926f84a9188106894a161cc28d7cf62056a926f84a9188106894a161cc28d7cf62056"; + _asset1!.Folder = folder1; + _asset1.Hash = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; + _asset2!.Folder = folder2; + _asset2.Hash = "afaff849b08fd348dc1f62dae619b262ee062ee062ee062ee062ee062ee062ee062ee0afaff849b08fd348dc1f62dae619b262ee062ee062ee062ee062ee062ee062ee062ee0afaff849b08fd348dc1f62dae619b262ee0afaff849b08fd348dc1f62dae619b262ee0"; + _asset3!.Folder = folder2; + _asset3.Hash = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; + _asset4!.Folder = folder2; + _asset4.Hash = "afaff849b08fd348dc1f62dae619b262ee062ee062ee062ee062ee062ee062ee062ee0afaff849b08fd348dc1f62dae619b262ee062ee062ee062ee062ee062ee062ee062ee0afaff849b08fd348dc1f62dae619b262ee0afaff849b08fd348dc1f62dae619b262ee0"; + _asset5!.Folder = folder2; + _asset5.Hash = "a926f84a9188106894a161cc28d7cf6205662ee062ee062ee062ee062ee062ee062ee0a926f84a9188106894a161cc28d7cf6205662ee062ee062ee062ee062ee062ee062ee0a926f84a9188106894a161cc28d7cf62056a926f84a9188106894a161cc28d7cf62056"; byte[] assetData1 = [1, 2, 3]; byte[] assetData2 = []; - _assetRepository!.AddAsset(asset1!, assetData1); - _assetRepository.AddAsset(asset2!, assetData2); - _assetRepository.AddAsset(asset3!, assetData1); - _assetRepository.AddAsset(asset4!, assetData2); - _assetRepository.AddAsset(asset5!, assetData1); + _assetRepository!.AddAsset(_asset1!, assetData1); + _assetRepository.AddAsset(_asset2!, assetData2); + _assetRepository.AddAsset(_asset3!, assetData1); + _assetRepository.AddAsset(_asset4!, assetData2); + _assetRepository.AddAsset(_asset5!, assetData1); List> duplicatedAssets = _findDuplicatedAssetsService!.GetDuplicatedAssets(); @@ -395,7 +400,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_FilesDoNotExist_ReturnsEmpt } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } @@ -410,7 +415,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_NoAssets_ReturnsEmptyList() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } @@ -419,20 +424,20 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_NoDuplicatedAssets_ReturnsE { try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); Folder folder = new() { Path = folderPath }; - asset1!.Folder = folder; - asset1.Hash = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; - asset2!.Folder = folder; - asset2.Hash = "afaff849b08fd348dc1f62dae619b262ee062ee062ee062ee062ee062ee062ee062ee0afaff849b08fd348dc1f62dae619b262ee062ee062ee062ee062ee062ee062ee062ee0afaff849b08fd348dc1f62dae619b262ee0afaff849b08fd348dc1f62dae619b262ee0"; + _asset1!.Folder = folder; + _asset1.Hash = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; + _asset2!.Folder = folder; + _asset2.Hash = "afaff849b08fd348dc1f62dae619b262ee062ee062ee062ee062ee062ee062ee062ee0afaff849b08fd348dc1f62dae619b262ee062ee062ee062ee062ee062ee062ee062ee0afaff849b08fd348dc1f62dae619b262ee0afaff849b08fd348dc1f62dae619b262ee0"; byte[] assetData1 = [1, 2, 3]; byte[] assetData2 = []; - _assetRepository!.AddAsset(asset1!, assetData1); - _assetRepository.AddAsset(asset2!, assetData2); + _assetRepository!.AddAsset(_asset1!, assetData1); + _assetRepository.AddAsset(_asset2!, assetData2); List> duplicatedAssets = _findDuplicatedAssetsService!.GetDuplicatedAssets(); @@ -440,7 +445,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_NoDuplicatedAssets_ReturnsE } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceThumbnailThumbnailTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceThumbnailThumbnailTests.cs index 9aa8c3e7..9ce406e6 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceThumbnailThumbnailTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Domain/FindDuplicatedAssets/FindDuplicatedAssetsServiceThumbnailThumbnailTests.cs @@ -3,51 +3,51 @@ [TestFixture] public class FindDuplicatedAssetsServiceThumbnailThumbnailTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; private AssetRepository? _assetRepository; private StorageService? _storageService; private Mock? _storageServiceMock; private Mock? _configurationRootMock; - private Asset? asset1; - private Asset? asset2; - private Asset? asset3; - private Asset? asset4; - private Asset? asset5; - - private readonly string originalAssetHash = "fb0bb3887c28d022113c5c52a65f9da14eab0806842f902b618806dedeb7c53da1ed26ae5bcaf9a358e81efead71c4807ea38054e44f426857f8bf2c1fd1c7aa"; - private readonly string miniAssetHash = "768d0fd37e280f1ef8d2a17702626ca1b290521167c22b0aecadd3cc2f858a88ed59a72f7a4b36c123f487da69842e55e4407de0dd248076947ce7df53e92be4"; - private readonly string shitQualityAssetHash = "0861602a84f5bf56e5f4acf49c1d98da8129542e871208a9c9f25eb497cdc65a75ccf4941874c2be7f4e36309053fe34d61a42b4d1b266910918a0b68f19cfc2"; - private readonly string smallAssetHash = "787146674307ab1e867c0961968dfea28aafc7d45e6cfd83f1562fbd201d029812289cd692c36a4f537c576b25af03c9f6f3cc996a8651f3c69f8240ecb3d5f4"; - - private readonly string originalAssetMD5Hash = "bed3d05d409001724e5f6095c2acaa95"; - private readonly string miniAssetMD5Hash = "051a784180ba8c0fce93ce0b81add76c"; - private readonly string shitQualityAssetMD5Hash = "5ec22ad598e3518bf7a5b78344ee8543"; - private readonly string smallAssetMD5Hash = "1f060a67916d271bd37c366d5e1287e8"; - - private readonly string originalAssetDHash = "1090783378"; - private readonly string miniAssetDHash = "61348232627230616"; - private readonly string shitQualityAssetDHash = "0"; - private readonly string smallAssetDHash = "0"; - - private readonly string originalAssetPHash = "abf9e847058af2e892da61f508b70361f7162ee062ee062ee062ee062ee062ee062ee0abf9e847058af2e892da61f508b70361f7162ee062ee062ee062ee062ee062ee062ee0abf9e847058af2e892da61f508b70361f71abf9e847058af2e892da61f508b70361f71"; - private readonly string miniAssetPHash = "abd4f8464c8af0d8926261f378b61d61f6362ee062ee062ee062ee062ee062ee062ee0abd4f8464c8af0d8926261f378b61d61f6362ee062ee062ee062ee062ee062ee062ee0abd4f8464c8af0d8926261f378b61d61f63abd4f8464c8af0d8926261f378b61d61f63"; - private readonly string shitQualityAssetPHash = "abd4c846458af188927261f388b63261f6962ee062ee062ee062ee062ee062ee062ee0abd4c846458af188927261f388b63261f6962ee062ee062ee062ee062ee062ee062ee0abd4c846458af188927261f388b63261f69abd4c846458af188927261f388b63261f69"; - private readonly string smallAssetPHash = "abd60846478ae848929b61f458b66761f5862ee062ee062ee062ee062ee062ee062ee0abd60846478ae848929b61f458b66761f5862ee062ee062ee062ee062ee062ee062ee0abd60846478ae848929b61f458b66761f58abd60846478ae848929b61f458b66761f58"; - - private readonly string miscAssetHash = "1fafae17c3c5c38d1205449eebdb9f5976814a5e54ec5797270c8ec467fe6d6d1190255cbaac11d9057c4b2697d90bc7116a46ed90c5ffb71e32e569c3b47fb9"; - private readonly string miscAssetMD5Hash = "a886f237e1cf6da03fb793588fd79b64"; - private readonly string miscAssetDHash = "23831507941108244"; - private readonly string miscAssetPHash = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; + private Asset? _asset1; + private Asset? _asset2; + private Asset? _asset3; + private Asset? _asset4; + private Asset? _asset5; + + private const string ORIGINAL_ASSET_HASH = "fb0bb3887c28d022113c5c52a65f9da14eab0806842f902b618806dedeb7c53da1ed26ae5bcaf9a358e81efead71c4807ea38054e44f426857f8bf2c1fd1c7aa"; + private const string MINI_ASSET_HASH = "768d0fd37e280f1ef8d2a17702626ca1b290521167c22b0aecadd3cc2f858a88ed59a72f7a4b36c123f487da69842e55e4407de0dd248076947ce7df53e92be4"; + private const string SHIT_QUALITY_ASSET_HASH = "0861602a84f5bf56e5f4acf49c1d98da8129542e871208a9c9f25eb497cdc65a75ccf4941874c2be7f4e36309053fe34d61a42b4d1b266910918a0b68f19cfc2"; + private const string SMALL_ASSET_HASH = "787146674307ab1e867c0961968dfea28aafc7d45e6cfd83f1562fbd201d029812289cd692c36a4f537c576b25af03c9f6f3cc996a8651f3c69f8240ecb3d5f4"; + + private const string ORIGINAL_ASSET_MD5_HASH = "bed3d05d409001724e5f6095c2acaa95"; + private const string MINI_ASSET_MD5_HASH = "051a784180ba8c0fce93ce0b81add76c"; + private const string SHIT_QUALITY_ASSET_MD5_HASH = "5ec22ad598e3518bf7a5b78344ee8543"; + private const string SMALL_ASSET_MD5_HASH = "1f060a67916d271bd37c366d5e1287e8"; + + private const string ORIGINAL_ASSET_D_HASH = "1090783378"; + private const string MINI_ASSET_D_HASH = "61348232627230616"; + private const string SHIT_QUALITY_ASSET_D_HASH = "0"; + private const string SMALL_ASSET_D_HASH = "0"; + + private const string ORIGINAL_ASSET_P_HASH = "abf9e847058af2e892da61f508b70361f7162ee062ee062ee062ee062ee062ee062ee0abf9e847058af2e892da61f508b70361f7162ee062ee062ee062ee062ee062ee062ee0abf9e847058af2e892da61f508b70361f71abf9e847058af2e892da61f508b70361f71"; + private const string MINI_ASSET_P_HASH = "abd4f8464c8af0d8926261f378b61d61f6362ee062ee062ee062ee062ee062ee062ee0abd4f8464c8af0d8926261f378b61d61f6362ee062ee062ee062ee062ee062ee062ee0abd4f8464c8af0d8926261f378b61d61f63abd4f8464c8af0d8926261f378b61d61f63"; + private const string SHIT_QUALITY_ASSET_P_HASH = "abd4c846458af188927261f388b63261f6962ee062ee062ee062ee062ee062ee062ee0abd4c846458af188927261f388b63261f6962ee062ee062ee062ee062ee062ee062ee0abd4c846458af188927261f388b63261f69abd4c846458af188927261f388b63261f69"; + private const string SMALL_ASSET_P_HASH = "abd60846478ae848929b61f458b66761f5862ee062ee062ee062ee062ee062ee062ee0abd60846478ae848929b61f458b66761f5862ee062ee062ee062ee062ee062ee062ee0abd60846478ae848929b61f458b66761f58abd60846478ae848929b61f458b66761f58"; + + private const string MISC_ASSET_HASH = "1fafae17c3c5c38d1205449eebdb9f5976814a5e54ec5797270c8ec467fe6d6d1190255cbaac11d9057c4b2697d90bc7116a46ed90c5ffb71e32e569c3b47fb9"; + private const string MISC_ASSET_MD5_HASH = "a886f237e1cf6da03fb793588fd79b64"; + private const string MISC_ASSET_D_HASH = "23831507941108244"; + private const string MISC_ASSET_P_HASH = "afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee062ee062ee062ee062ee062ee062ee062ee0afbaa849d28fc2b8dc1262d9e619b362ee0afbaa849d28fc2b8dc1262d9e619b362ee0"; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); @@ -55,7 +55,7 @@ public void OneTimeSetUp() _configurationRootMock.MockGetValue(UserConfigurationKeys.USING_PHASH, "true"); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -66,9 +66,10 @@ public void SetUp() _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); _storageService = new (userConfigurationService); - asset1 = new() + _asset1 = new() { FolderId = new Guid("ff140210-e4db-4c2c-96c1-85faed197aa7"), + Folder = new() { Path = "" }, FileName = "Image_1336_Mini.JPG", FileSize = 1586, ImageRotation = Rotation.Rotate0, @@ -83,9 +84,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset2 = new() + _asset2 = new() { FolderId = new Guid("ff140210-e4db-4c2c-96c1-85faed197aa7"), + Folder = new() { Path = "" }, FileName = "Image_1336_Original.JPG", FileSize = 4526710, ImageRotation = Rotation.Rotate0, @@ -100,9 +102,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset3 = new() + _asset3 = new() { FolderId = new Guid("ff140210-e4db-4c2c-96c1-85faed197aa7"), + Folder = new() { Path = "" }, FileName = "Image_1336_ShitQuality.JPG", FileSize = 370819, ImageRotation = Rotation.Rotate0, @@ -117,9 +120,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset4 = new() + _asset4 = new() { FolderId = new Guid("ff140210-e4db-4c2c-96c1-85faed197aa7"), + Folder = new() { Path = "" }, FileName = "Image_1336_Small.JPG", FileSize = 53227, ImageRotation = Rotation.Rotate0, @@ -134,9 +138,10 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset5 = new() // Another asset completely different than the actual asset + _asset5 = new() // Another asset completely different from the actual asset { FolderId = new Guid("5b506904-45af-4eaf-b402-53f6d0012075"), + Folder = new() { Path = "" }, FileName = "Image 1.jpg", FileSize = 29857, ImageRotation = Rotation.Rotate0, @@ -162,7 +167,7 @@ public void SetUp() [TestCase("80", 0, new string[] { })] [TestCase("100", 0, new string[] { })] [TestCase("110", 0, new string[] { })] - [TestCase("128", 1, new string[] { "Image_1336_Mini.JPG", "Image_1336_Original.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG", "Image 1.jpg" })] + [TestCase("128", 1, new[] { "Image_1336_Mini.JPG", "Image_1336_Original.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG", "Image 1.jpg" })] public void GetDuplicatesBetweenOriginalAndThumbnail_ThumbnailBasicHashDifferentThresholdValues(string thresholdToMock, int expected, string[] assetsName) { try @@ -171,30 +176,30 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_ThumbnailBasicHashDifferent UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); FindDuplicatedAssetsService findDuplicatedAssetsService = new (_assetRepository!, _storageService!, userConfigurationService); - string folderPath1 = Path.Combine(dataDirectory!, "Duplicates\\Thumbnail"); - string folderPath2 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "Duplicates\\Thumbnail"); + string folderPath2 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); Folder folder1 = new() { Path = folderPath1 }; Folder folder2 = new() { Path = folderPath2 }; - asset1!.Folder = folder1; - asset1.Hash = miniAssetHash; - asset2!.Folder = folder1; - asset2.Hash = originalAssetHash; - asset3!.Folder = folder1; - asset3.Hash = shitQualityAssetHash; - asset4!.Folder = folder1; - asset4.Hash = smallAssetHash; - asset5!.Folder = folder2; - asset5.Hash = miscAssetHash; // If this asset is in the set, then the threshold is not good + _asset1!.Folder = folder1; + _asset1.Hash = MINI_ASSET_HASH; + _asset2!.Folder = folder1; + _asset2.Hash = ORIGINAL_ASSET_HASH; + _asset3!.Folder = folder1; + _asset3.Hash = SHIT_QUALITY_ASSET_HASH; + _asset4!.Folder = folder1; + _asset4.Hash = SMALL_ASSET_HASH; + _asset5!.Folder = folder2; + _asset5.Hash = MISC_ASSET_HASH; // If this asset is in the set, then the threshold is not good byte[] assetData1 = [1, 2, 3]; - _assetRepository!.AddAsset(asset1, assetData1); - _assetRepository.AddAsset(asset2, assetData1); - _assetRepository.AddAsset(asset3, assetData1); - _assetRepository.AddAsset(asset4, assetData1); - _assetRepository.AddAsset(asset5, assetData1); + _assetRepository!.AddAsset(_asset1, assetData1); + _assetRepository.AddAsset(_asset2, assetData1); + _assetRepository.AddAsset(_asset3, assetData1); + _assetRepository.AddAsset(_asset4, assetData1); + _assetRepository.AddAsset(_asset5, assetData1); List> duplicatedAssets = findDuplicatedAssetsService.GetDuplicatedAssets(); @@ -208,7 +213,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_ThumbnailBasicHashDifferent } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } @@ -220,7 +225,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_ThumbnailBasicHashDifferent [TestCase("15", 0, new string[] { })] [TestCase("20", 0, new string[] { })] [TestCase("25", 0, new string[] { })] - [TestCase("32", 1, new string[] { "Image_1336_Mini.JPG", "Image_1336_Original.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG", "Image 1.jpg" })] + [TestCase("32", 1, new[] { "Image_1336_Mini.JPG", "Image_1336_Original.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG", "Image 1.jpg" })] public void GetDuplicatesBetweenOriginalAndThumbnail_ThumbnailMD5HashDifferentThresholdValues(string thresholdToMock, int expected, string[] assetsName) { try @@ -229,30 +234,30 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_ThumbnailMD5HashDifferentTh UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); FindDuplicatedAssetsService findDuplicatedAssetsService = new (_assetRepository!, _storageService!, userConfigurationService); - string folderPath1 = Path.Combine(dataDirectory!, "Duplicates\\Thumbnail"); - string folderPath2 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "Duplicates\\Thumbnail"); + string folderPath2 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); Folder folder1 = new() { Path = folderPath1 }; Folder folder2 = new() { Path = folderPath2 }; - asset1!.Folder = folder1; - asset1.Hash = miniAssetMD5Hash; - asset2!.Folder = folder1; - asset2.Hash = originalAssetMD5Hash; - asset3!.Folder = folder1; - asset3.Hash = shitQualityAssetMD5Hash; - asset4!.Folder = folder1; - asset4.Hash = smallAssetMD5Hash; - asset5!.Folder = folder2; - asset5.Hash = miscAssetMD5Hash; // If this asset is in the set, then the threshold is not good + _asset1!.Folder = folder1; + _asset1.Hash = MINI_ASSET_MD5_HASH; + _asset2!.Folder = folder1; + _asset2.Hash = ORIGINAL_ASSET_MD5_HASH; + _asset3!.Folder = folder1; + _asset3.Hash = SHIT_QUALITY_ASSET_MD5_HASH; + _asset4!.Folder = folder1; + _asset4.Hash = SMALL_ASSET_MD5_HASH; + _asset5!.Folder = folder2; + _asset5.Hash = MISC_ASSET_MD5_HASH; // If this asset is in the set, then the threshold is not good byte[] assetData1 = [1, 2, 3]; - _assetRepository!.AddAsset(asset1, assetData1); - _assetRepository.AddAsset(asset2, assetData1); - _assetRepository.AddAsset(asset3, assetData1); - _assetRepository.AddAsset(asset4, assetData1); - _assetRepository.AddAsset(asset5, assetData1); + _assetRepository!.AddAsset(_asset1, assetData1); + _assetRepository.AddAsset(_asset2, assetData1); + _assetRepository.AddAsset(_asset3, assetData1); + _assetRepository.AddAsset(_asset4, assetData1); + _assetRepository.AddAsset(_asset5, assetData1); List> duplicatedAssets = findDuplicatedAssetsService.GetDuplicatedAssets(); @@ -266,7 +271,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_ThumbnailMD5HashDifferentTh } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } @@ -287,30 +292,30 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_ThumbnailDHashDifferentThre UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); FindDuplicatedAssetsService findDuplicatedAssetsService = new (_assetRepository!, _storageService!, userConfigurationService); - string folderPath1 = Path.Combine(dataDirectory!, "Duplicates\\Thumbnail"); - string folderPath2 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "Duplicates\\Thumbnail"); + string folderPath2 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); Folder folder1 = new() { Path = folderPath1 }; Folder folder2 = new() { Path = folderPath2 }; - asset1!.Folder = folder1; - asset1.Hash = miniAssetDHash; - asset2!.Folder = folder1; - asset2.Hash = originalAssetDHash; - asset3!.Folder = folder1; - asset3.Hash = shitQualityAssetDHash; - asset4!.Folder = folder1; - asset4.Hash = smallAssetDHash; - asset5!.Folder = folder2; - asset5.Hash = miscAssetDHash; // If this asset is in the set, then the threshold is not good + _asset1!.Folder = folder1; + _asset1.Hash = MINI_ASSET_D_HASH; + _asset2!.Folder = folder1; + _asset2.Hash = ORIGINAL_ASSET_D_HASH; + _asset3!.Folder = folder1; + _asset3.Hash = SHIT_QUALITY_ASSET_D_HASH; + _asset4!.Folder = folder1; + _asset4.Hash = SMALL_ASSET_D_HASH; + _asset5!.Folder = folder2; + _asset5.Hash = MISC_ASSET_D_HASH; // If this asset is in the set, then the threshold is not good byte[] assetData1 = [1, 2, 3]; - _assetRepository!.AddAsset(asset1, assetData1); - _assetRepository.AddAsset(asset2, assetData1); - _assetRepository.AddAsset(asset3, assetData1); - _assetRepository.AddAsset(asset4, assetData1); - _assetRepository.AddAsset(asset5, assetData1); + _assetRepository!.AddAsset(_asset1, assetData1); + _assetRepository.AddAsset(_asset2, assetData1); + _assetRepository.AddAsset(_asset3, assetData1); + _assetRepository.AddAsset(_asset4, assetData1); + _assetRepository.AddAsset(_asset5, assetData1); ArgumentException? exception = Assert.Throws(() => findDuplicatedAssetsService.GetDuplicatedAssets()); @@ -318,7 +323,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_ThumbnailDHashDifferentThre } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } @@ -328,17 +333,17 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_ThumbnailDHashDifferentThre [TestCase("10", 0, new string[] { })] [TestCase("20", 0, new string[] { })] [TestCase("30", 0, new string[] { })] - [TestCase("40", 1, new string[] { "Image_1336_Mini.JPG", "Image_1336_ShitQuality.JPG" })] - [TestCase("50", 1, new string[] { "Image_1336_Mini.JPG", "Image_1336_ShitQuality.JPG" })] - [TestCase("60", 1, new string[] { "Image_1336_Mini.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG" })] - [TestCase("80", 1, new string[] { "Image_1336_Mini.JPG", "Image_1336_Original.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG" })] - [TestCase("90", 1, new string[] { "Image_1336_Mini.JPG", "Image_1336_Original.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG" })] - [TestCase("100", 1, new string[] { "Image_1336_Mini.JPG", "Image_1336_Original.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG" })] - [TestCase("120", 1, new string[] { "Image_1336_Mini.JPG", "Image_1336_Original.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG", "Image 1.jpg" })] - [TestCase("140", 1, new string[] { "Image_1336_Mini.JPG", "Image_1336_Original.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG", "Image 1.jpg" })] - [TestCase("160", 1, new string[] { "Image_1336_Mini.JPG", "Image_1336_Original.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG", "Image 1.jpg" })] - [TestCase("180", 1, new string[] { "Image_1336_Mini.JPG", "Image_1336_Original.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG", "Image 1.jpg" })] - [TestCase("210", 1, new string[] { "Image_1336_Mini.JPG", "Image_1336_Original.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG", "Image 1.jpg" })] + [TestCase("40", 1, new[] { "Image_1336_Mini.JPG", "Image_1336_ShitQuality.JPG" })] + [TestCase("50", 1, new[] { "Image_1336_Mini.JPG", "Image_1336_ShitQuality.JPG" })] + [TestCase("60", 1, new[] { "Image_1336_Mini.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG" })] + [TestCase("80", 1, new[] { "Image_1336_Mini.JPG", "Image_1336_Original.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG" })] + [TestCase("90", 1, new[] { "Image_1336_Mini.JPG", "Image_1336_Original.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG" })] + [TestCase("100", 1, new[] { "Image_1336_Mini.JPG", "Image_1336_Original.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG" })] + [TestCase("120", 1, new[] { "Image_1336_Mini.JPG", "Image_1336_Original.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG", "Image 1.jpg" })] + [TestCase("140", 1, new[] { "Image_1336_Mini.JPG", "Image_1336_Original.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG", "Image 1.jpg" })] + [TestCase("160", 1, new[] { "Image_1336_Mini.JPG", "Image_1336_Original.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG", "Image 1.jpg" })] + [TestCase("180", 1, new[] { "Image_1336_Mini.JPG", "Image_1336_Original.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG", "Image 1.jpg" })] + [TestCase("210", 1, new[] { "Image_1336_Mini.JPG", "Image_1336_Original.JPG", "Image_1336_ShitQuality.JPG", "Image_1336_Small.JPG", "Image 1.jpg" })] public void GetDuplicatesBetweenOriginalAndThumbnail_ThumbnailPHashDifferentThresholdValues(string thresholdToMock, int expected, string[] assetsName) { try @@ -347,30 +352,30 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_ThumbnailPHashDifferentThre UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); FindDuplicatedAssetsService findDuplicatedAssetsService = new (_assetRepository!, _storageService!, userConfigurationService); - string folderPath1 = Path.Combine(dataDirectory!, "Duplicates\\Thumbnail"); - string folderPath2 = Path.Combine(dataDirectory!, "Duplicates\\NewFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "Duplicates\\Thumbnail"); + string folderPath2 = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder1"); Folder folder1 = new() { Path = folderPath1 }; Folder folder2 = new() { Path = folderPath2 }; - asset1!.Folder = folder1; - asset1.Hash = miniAssetPHash; - asset2!.Folder = folder1; - asset2.Hash = originalAssetPHash; - asset3!.Folder = folder1; - asset3.Hash = shitQualityAssetPHash; - asset4!.Folder = folder1; - asset4.Hash = smallAssetPHash; - asset5!.Folder = folder2; - asset5.Hash = miscAssetPHash; // If this asset is in the set, then the threshold is not good + _asset1!.Folder = folder1; + _asset1.Hash = MINI_ASSET_P_HASH; + _asset2!.Folder = folder1; + _asset2.Hash = ORIGINAL_ASSET_P_HASH; + _asset3!.Folder = folder1; + _asset3.Hash = SHIT_QUALITY_ASSET_P_HASH; + _asset4!.Folder = folder1; + _asset4.Hash = SMALL_ASSET_P_HASH; + _asset5!.Folder = folder2; + _asset5.Hash = MISC_ASSET_P_HASH; // If this asset is in the set, then the threshold is not good byte[] assetData1 = [1, 2, 3]; - _assetRepository!.AddAsset(asset1, assetData1); - _assetRepository.AddAsset(asset2, assetData1); - _assetRepository.AddAsset(asset3, assetData1); - _assetRepository.AddAsset(asset4, assetData1); - _assetRepository.AddAsset(asset5, assetData1); + _assetRepository!.AddAsset(_asset1, assetData1); + _assetRepository.AddAsset(_asset2, assetData1); + _assetRepository.AddAsset(_asset3, assetData1); + _assetRepository.AddAsset(_asset4, assetData1); + _assetRepository.AddAsset(_asset5, assetData1); List> duplicatedAssets = findDuplicatedAssetsService.GetDuplicatedAssets(); @@ -384,7 +389,7 @@ public void GetDuplicatesBetweenOriginalAndThumbnail_ThumbnailPHashDifferentThre } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); } } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Domain/MoveAssetsServiceTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Domain/MoveAssetsServiceTests.cs index 291fb095..b2db508d 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Domain/MoveAssetsServiceTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Domain/MoveAssetsServiceTests.cs @@ -3,10 +3,10 @@ [TestFixture] public class MoveAssetsServiceTests { - private string? dataDirectory; - private string? databasePath; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _databasePath; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; private MoveAssetsService? _moveAssetsService; private UserConfigurationService? _userConfigurationService; @@ -20,15 +20,15 @@ public class MoveAssetsServiceTests [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); - databasePath = Path.Combine(dataDirectory, "DatabaseTests"); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); + _databasePath = Path.Combine(_dataDirectory, "DatabaseTests"); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); _storageServiceMock.Setup(x => x.LoadBitmapThumbnailImage(It.IsAny(), It.IsAny(), It.IsAny())).Returns(new BitmapImage()); } @@ -47,15 +47,15 @@ public void SetUp() [Test] public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsTrue_MoveSucceeds() { - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToMove"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToMove"); try { Directory.CreateDirectory(destinationDirectory); - string sourceFilePath1 = Path.Combine(dataDirectory!, "Image 6.jpg"); + string sourceFilePath1 = Path.Combine(_dataDirectory!, "Image 6.jpg"); string destinationFilePath1 = Path.Combine(destinationDirectory, "Image 6.jpg"); - string sourceFilePath2 = Path.Combine(dataDirectory!, "Image 1.jpg"); + string sourceFilePath2 = Path.Combine(_dataDirectory!, "Image 1.jpg"); string destinationFilePath2 = Path.Combine(destinationDirectory, "Image 1.jpg"); Assert.IsTrue(File.Exists(sourceFilePath1)); @@ -63,18 +63,18 @@ public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsTrue_MoveSucceeds Assert.IsTrue(File.Exists(sourceFilePath2)); Assert.IsFalse(File.Exists(destinationFilePath2)); - Folder sourceFolder = _assetRepository!.AddFolder(dataDirectory!); + Folder sourceFolder = _assetRepository!.AddFolder(_dataDirectory!); Folder destinationFolder = _assetRepository!.AddFolder(destinationDirectory); - Asset? asset1 = _assetCreationService!.CreateAsset(dataDirectory!, "Image 6.jpg"); + Asset? asset1 = _assetCreationService!.CreateAsset(_dataDirectory!, "Image 6.jpg"); Assert.IsNotNull(asset1); - Asset? asset2 = _assetCreationService!.CreateAsset(dataDirectory!, "Image 1.jpg"); + Asset? asset2 = _assetCreationService!.CreateAsset(_dataDirectory!, "Image 1.jpg"); Assert.IsNotNull(asset2); _assetRepository!.SaveCatalog(sourceFolder); _assetRepository!.SaveCatalog(destinationFolder); - Asset[] assetsInSource= _assetRepository!.GetAssetsByPath(dataDirectory!); + Asset[] assetsInSource= _assetRepository!.GetAssetsByPath(_dataDirectory!); Assert.IsNotEmpty(assetsInSource); Assert.AreEqual(2, assetsInSource.Length); Assert.IsTrue(assetsInSource.Any(x => x.FileName == asset1!.FileName)); @@ -86,8 +86,8 @@ public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsTrue_MoveSucceeds Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset1!.FileName)); Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset2!.FileName)); - Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1!.FileName)); - Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2!.FileName)); + Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1.FileName)); + Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2.FileName)); List assetsInDb = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.AssetsTableName, AssetConfigs.ReadFunc); Assert.IsNotEmpty(assetsInDb); @@ -98,8 +98,8 @@ public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsTrue_MoveSucceeds List cataloguedAssetsInSource = _assetRepository!.GetCataloguedAssetsByPath(sourceFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInSource); Assert.AreEqual(2, cataloguedAssetsInSource.Count); - Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1!.FileName)); - Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1.FileName)); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset2.FileName)); List cataloguedAssetsInDestination = _assetRepository!.GetCataloguedAssetsByPath(destinationFolder.Path); Assert.IsEmpty(cataloguedAssetsInDestination); @@ -107,7 +107,7 @@ public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsTrue_MoveSucceeds List recentTargetPaths = _assetRepository.GetRecentTargetPaths(); Assert.IsEmpty(recentTargetPaths); - Asset[] assets = { asset1, asset2 }; + Asset[] assets = [asset1, asset2]; bool hasBeenMoved = _moveAssetsService!.MoveAssets(assets, destinationFolder, true); @@ -117,23 +117,23 @@ public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsTrue_MoveSucceeds Assert.IsTrue(File.Exists(sourceFilePath2)); Assert.IsTrue(File.Exists(destinationFilePath2)); - assetsInSource = _assetRepository!.GetAssetsByPath(dataDirectory!); + assetsInSource = _assetRepository!.GetAssetsByPath(_dataDirectory!); Assert.IsNotEmpty(assetsInSource); Assert.AreEqual(2, assetsInSource.Length); - Assert.IsTrue(assetsInSource.Any(x => x.FileName == asset1!.FileName)); - Assert.IsTrue(assetsInSource.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(assetsInSource.Any(x => x.FileName == asset1.FileName)); + Assert.IsTrue(assetsInSource.Any(x => x.FileName == asset2.FileName)); assetsInDestination = _assetRepository!.GetAssetsByPath(destinationDirectory); Assert.IsNotEmpty(assetsInDestination); Assert.AreEqual(2, assetsInDestination.Length); - Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset1!.FileName)); - Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset1.FileName)); + Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset2.FileName)); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset1!.FileName)); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset2!.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset1.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset2.FileName)); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1!.FileName)); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2!.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2.FileName)); assetsInDb = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.AssetsTableName, AssetConfigs.ReadFunc); Assert.IsNotEmpty(assetsInDb); @@ -146,14 +146,14 @@ public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsTrue_MoveSucceeds cataloguedAssetsInSource = _assetRepository!.GetCataloguedAssetsByPath(sourceFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInSource); Assert.AreEqual(2, cataloguedAssetsInSource.Count); - Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1!.FileName)); - Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1.FileName)); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset2.FileName)); cataloguedAssetsInDestination = _assetRepository!.GetCataloguedAssetsByPath(destinationFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInDestination); Assert.AreEqual(2, cataloguedAssetsInDestination.Count); - Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset1!.FileName)); - Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset1.FileName)); + Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset2.FileName)); recentTargetPaths = _assetRepository.GetRecentTargetPaths(); Assert.IsNotEmpty(recentTargetPaths); @@ -163,25 +163,25 @@ public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsTrue_MoveSucceeds finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsFalse_MoveSucceeds() { - string sourceDirectory = Path.Combine(dataDirectory!, "SourceToMove"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToMove"); + string sourceDirectory = Path.Combine(_dataDirectory!, "SourceToMove"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToMove"); try { Directory.CreateDirectory(sourceDirectory); Directory.CreateDirectory(destinationDirectory); - string sourceFilePath1 = Path.Combine(dataDirectory!, "Image 6.jpg"); + string sourceFilePath1 = Path.Combine(_dataDirectory!, "Image 6.jpg"); string newSourceFilePath1 = Path.Combine(sourceDirectory, "Image 6.jpg"); string destinationFilePath1 = Path.Combine(destinationDirectory, "Image 6.jpg"); - string sourceFilePath2 = Path.Combine(dataDirectory!, "Image 1.jpg"); + string sourceFilePath2 = Path.Combine(_dataDirectory!, "Image 1.jpg"); string newSourceFilePath2 = Path.Combine(sourceDirectory, "Image 1.jpg"); string destinationFilePath2 = Path.Combine(destinationDirectory, "Image 1.jpg"); @@ -225,8 +225,8 @@ public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsFalse_MoveSucceed Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset1!.FileName)); Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset2!.FileName)); - Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1!.FileName)); - Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2!.FileName)); + Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1.FileName)); + Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2.FileName)); List assetsInDb = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.AssetsTableName, AssetConfigs.ReadFunc); Assert.IsNotEmpty(assetsInDb); @@ -237,8 +237,8 @@ public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsFalse_MoveSucceed List cataloguedAssetsInSource = _assetRepository!.GetCataloguedAssetsByPath(sourceFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInSource); Assert.AreEqual(2, cataloguedAssetsInSource.Count); - Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1!.FileName)); - Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1.FileName)); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset2.FileName)); List cataloguedAssetsInDestination = _assetRepository!.GetCataloguedAssetsByPath(destinationFolder.Path); Assert.IsEmpty(cataloguedAssetsInDestination); @@ -246,7 +246,7 @@ public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsFalse_MoveSucceed List recentTargetPaths = _assetRepository.GetRecentTargetPaths(); Assert.IsEmpty(recentTargetPaths); - Asset[] assets = { asset1, asset2 }; + Asset[] assets = [asset1, asset2]; bool hasBeenMoved = _moveAssetsService!.MoveAssets(assets, destinationFolder, false); @@ -262,14 +262,14 @@ public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsFalse_MoveSucceed assetsInDestination = _assetRepository!.GetAssetsByPath(destinationDirectory); Assert.IsNotEmpty(assetsInDestination); Assert.AreEqual(2, assetsInDestination.Length); - Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset1!.FileName)); - Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset1.FileName)); + Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset2.FileName)); - Assert.IsFalse(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset1!.FileName)); - Assert.IsFalse(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset2!.FileName)); + Assert.IsFalse(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset1.FileName)); + Assert.IsFalse(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset2.FileName)); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1!.FileName)); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2!.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2.FileName)); assetsInDb = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.AssetsTableName, AssetConfigs.ReadFunc); Assert.IsNotEmpty(assetsInDb); @@ -283,8 +283,8 @@ public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsFalse_MoveSucceed cataloguedAssetsInDestination = _assetRepository!.GetCataloguedAssetsByPath(destinationFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInDestination); Assert.AreEqual(2, cataloguedAssetsInDestination.Count); - Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset1!.FileName)); - Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset1.FileName)); + Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset2.FileName)); recentTargetPaths = _assetRepository.GetRecentTargetPaths(); Assert.IsNotEmpty(recentTargetPaths); @@ -295,22 +295,22 @@ public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsFalse_MoveSucceed { Directory.Delete(sourceDirectory, true); Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public void MoveAssets_AssetsAreValidAndDestinationFolderNotCataloguedAndPreserveOriginalFilesIsTrue_MoveSucceeds() { - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToMove"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToMove"); try { Directory.CreateDirectory(destinationDirectory); - string sourceFilePath1 = Path.Combine(dataDirectory!, "Image 6.jpg"); + string sourceFilePath1 = Path.Combine(_dataDirectory!, "Image 6.jpg"); string destinationFilePath1 = Path.Combine(destinationDirectory, "Image 6.jpg"); - string sourceFilePath2 = Path.Combine(dataDirectory!, "Image 1.jpg"); + string sourceFilePath2 = Path.Combine(_dataDirectory!, "Image 1.jpg"); string destinationFilePath2 = Path.Combine(destinationDirectory, "Image 1.jpg"); Assert.IsTrue(File.Exists(sourceFilePath1)); @@ -318,17 +318,17 @@ public void MoveAssets_AssetsAreValidAndDestinationFolderNotCataloguedAndPreserv Assert.IsTrue(File.Exists(sourceFilePath2)); Assert.IsFalse(File.Exists(destinationFilePath2)); - Folder sourceFolder = _assetRepository!.AddFolder(dataDirectory!); + Folder sourceFolder = _assetRepository!.AddFolder(_dataDirectory!); Folder destinationFolder = new() { FolderId = Guid.NewGuid(), Path = destinationDirectory }; - Asset? asset1 = _assetCreationService!.CreateAsset(dataDirectory!, "Image 6.jpg"); + Asset? asset1 = _assetCreationService!.CreateAsset(_dataDirectory!, "Image 6.jpg"); Assert.IsNotNull(asset1); - Asset? asset2 = _assetCreationService!.CreateAsset(dataDirectory!, "Image 1.jpg"); + Asset? asset2 = _assetCreationService!.CreateAsset(_dataDirectory!, "Image 1.jpg"); Assert.IsNotNull(asset2); _assetRepository!.SaveCatalog(sourceFolder); - Asset[] assetsInSource = _assetRepository!.GetAssetsByPath(dataDirectory!); + Asset[] assetsInSource = _assetRepository!.GetAssetsByPath(_dataDirectory!); Assert.IsNotEmpty(assetsInSource); Assert.AreEqual(2, assetsInSource.Length); Assert.IsTrue(assetsInSource.Any(x => x.FileName == asset1!.FileName)); @@ -340,8 +340,8 @@ public void MoveAssets_AssetsAreValidAndDestinationFolderNotCataloguedAndPreserv Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset1!.FileName)); Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset2!.FileName)); - Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1!.FileName)); - Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2!.FileName)); + Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1.FileName)); + Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2.FileName)); List assetsInDb = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.AssetsTableName, AssetConfigs.ReadFunc); Assert.IsNotEmpty(assetsInDb); @@ -352,8 +352,8 @@ public void MoveAssets_AssetsAreValidAndDestinationFolderNotCataloguedAndPreserv List cataloguedAssetsInSource = _assetRepository!.GetCataloguedAssetsByPath(sourceFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInSource); Assert.AreEqual(2, cataloguedAssetsInSource.Count); - Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1!.FileName)); - Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1.FileName)); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset2.FileName)); List cataloguedAssetsInDestination = _assetRepository!.GetCataloguedAssetsByPath(destinationFolder.Path); Assert.IsEmpty(cataloguedAssetsInDestination); @@ -361,7 +361,7 @@ public void MoveAssets_AssetsAreValidAndDestinationFolderNotCataloguedAndPreserv List recentTargetPaths = _assetRepository.GetRecentTargetPaths(); Assert.IsEmpty(recentTargetPaths); - Asset[] assets = { asset1, asset2 }; + Asset[] assets = [asset1, asset2]; bool hasBeenMoved = _moveAssetsService!.MoveAssets(assets, destinationFolder, true); @@ -371,23 +371,23 @@ public void MoveAssets_AssetsAreValidAndDestinationFolderNotCataloguedAndPreserv Assert.IsTrue(File.Exists(sourceFilePath2)); Assert.IsTrue(File.Exists(destinationFilePath2)); - assetsInSource = _assetRepository!.GetAssetsByPath(dataDirectory!); + assetsInSource = _assetRepository!.GetAssetsByPath(_dataDirectory!); Assert.IsNotEmpty(assetsInSource); Assert.AreEqual(2, assetsInSource.Length); - Assert.IsTrue(assetsInSource.Any(x => x.FileName == asset1!.FileName)); - Assert.IsTrue(assetsInSource.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(assetsInSource.Any(x => x.FileName == asset1.FileName)); + Assert.IsTrue(assetsInSource.Any(x => x.FileName == asset2.FileName)); assetsInDestination = _assetRepository!.GetAssetsByPath(destinationDirectory); Assert.IsNotEmpty(assetsInDestination); Assert.AreEqual(2, assetsInDestination.Length); - Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset1!.FileName)); - Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset1.FileName)); + Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset2.FileName)); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset1!.FileName)); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset2!.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset1.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset2.FileName)); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1!.FileName)); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2!.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2.FileName)); Folder? newDestinationFolder = _assetRepository.GetFolderByPath(destinationFolder.Path); Assert.IsNotNull(newDestinationFolder); @@ -403,14 +403,14 @@ public void MoveAssets_AssetsAreValidAndDestinationFolderNotCataloguedAndPreserv cataloguedAssetsInSource = _assetRepository!.GetCataloguedAssetsByPath(sourceFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInSource); Assert.AreEqual(2, cataloguedAssetsInSource.Count); - Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1!.FileName)); - Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1.FileName)); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset2.FileName)); cataloguedAssetsInDestination = _assetRepository!.GetCataloguedAssetsByPath(destinationFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInDestination); Assert.AreEqual(2, cataloguedAssetsInDestination.Count); - Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset1!.FileName)); - Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset1.FileName)); + Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset2.FileName)); recentTargetPaths = _assetRepository.GetRecentTargetPaths(); Assert.IsNotEmpty(recentTargetPaths); @@ -420,25 +420,25 @@ public void MoveAssets_AssetsAreValidAndDestinationFolderNotCataloguedAndPreserv finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public void MoveAssets_AssetsAreValidAndDestinationFolderNotCataloguedAndPreserveOriginalFilesIsFalse_MoveSucceeds() { - string sourceDirectory = Path.Combine(dataDirectory!, "SourceToMove"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToMove"); + string sourceDirectory = Path.Combine(_dataDirectory!, "SourceToMove"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToMove"); try { Directory.CreateDirectory(sourceDirectory); Directory.CreateDirectory(destinationDirectory); - string sourceFilePath1 = Path.Combine(dataDirectory!, "Image 6.jpg"); + string sourceFilePath1 = Path.Combine(_dataDirectory!, "Image 6.jpg"); string newSourceFilePath1 = Path.Combine(sourceDirectory, "Image 6.jpg"); string destinationFilePath1 = Path.Combine(destinationDirectory, "Image 6.jpg"); - string sourceFilePath2 = Path.Combine(dataDirectory!, "Image 1.jpg"); + string sourceFilePath2 = Path.Combine(_dataDirectory!, "Image 1.jpg"); string newSourceFilePath2 = Path.Combine(sourceDirectory, "Image 1.jpg"); string destinationFilePath2 = Path.Combine(destinationDirectory, "Image 1.jpg"); @@ -481,8 +481,8 @@ public void MoveAssets_AssetsAreValidAndDestinationFolderNotCataloguedAndPreserv Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset1!.FileName)); Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset2!.FileName)); - Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1!.FileName)); - Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2!.FileName)); + Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1.FileName)); + Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2.FileName)); List assetsInDb = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.AssetsTableName, AssetConfigs.ReadFunc); Assert.IsNotEmpty(assetsInDb); @@ -493,8 +493,8 @@ public void MoveAssets_AssetsAreValidAndDestinationFolderNotCataloguedAndPreserv List cataloguedAssetsInSource = _assetRepository!.GetCataloguedAssetsByPath(sourceFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInSource); Assert.AreEqual(2, cataloguedAssetsInSource.Count); - Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1!.FileName)); - Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1.FileName)); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset2.FileName)); List cataloguedAssetsInDestination = _assetRepository!.GetCataloguedAssetsByPath(destinationFolder.Path); Assert.IsEmpty(cataloguedAssetsInDestination); @@ -502,7 +502,7 @@ public void MoveAssets_AssetsAreValidAndDestinationFolderNotCataloguedAndPreserv List recentTargetPaths = _assetRepository.GetRecentTargetPaths(); Assert.IsEmpty(recentTargetPaths); - Asset[] assets = { asset1, asset2 }; + Asset[] assets = [asset1, asset2]; bool hasBeenMoved = _moveAssetsService!.MoveAssets(assets, destinationFolder, false); @@ -518,14 +518,14 @@ public void MoveAssets_AssetsAreValidAndDestinationFolderNotCataloguedAndPreserv assetsInDestination = _assetRepository!.GetAssetsByPath(destinationDirectory); Assert.IsNotEmpty(assetsInDestination); Assert.AreEqual(2, assetsInDestination.Length); - Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset1!.FileName)); - Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset1.FileName)); + Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset2.FileName)); - Assert.IsFalse(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset1!.FileName)); - Assert.IsFalse(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset2!.FileName)); + Assert.IsFalse(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset1.FileName)); + Assert.IsFalse(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset2.FileName)); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1!.FileName)); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2!.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2.FileName)); Folder? newDestinationFolder = _assetRepository.GetFolderByPath(destinationFolder.Path); Assert.IsNotNull(newDestinationFolder); @@ -542,8 +542,8 @@ public void MoveAssets_AssetsAreValidAndDestinationFolderNotCataloguedAndPreserv cataloguedAssetsInDestination = _assetRepository!.GetCataloguedAssetsByPath(destinationFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInDestination); Assert.AreEqual(2, cataloguedAssetsInDestination.Count); - Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset1!.FileName)); - Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset1.FileName)); + Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset2.FileName)); recentTargetPaths = _assetRepository.GetRecentTargetPaths(); Assert.IsNotEmpty(recentTargetPaths); @@ -554,7 +554,7 @@ public void MoveAssets_AssetsAreValidAndDestinationFolderNotCataloguedAndPreserv { Directory.Delete(sourceDirectory, true); Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } @@ -563,7 +563,7 @@ public void MoveAssets_AssetsAreValidAndDestinationFolderNotCataloguedAndPreserv [TestCase(false)] public void MoveAssets_AssetsAreValidButDirectoryIsInReadOnlyMode_DoesNotMoveAndReturnFalse(bool preserveOriginalFile) { - string destinationDirectory = Path.Combine(dataDirectory!, "NoMoveDirectory"); + string destinationDirectory = Path.Combine(_dataDirectory!, "NoMoveDirectory"); try { @@ -572,22 +572,22 @@ public void MoveAssets_AssetsAreValidButDirectoryIsInReadOnlyMode_DoesNotMoveAnd // Deny write access to the directory DirectoryHelper.DenyWriteAccess(destinationDirectory); - string sourceFilePath = Path.Combine(dataDirectory!, "Image 1.jpg"); + string sourceFilePath = Path.Combine(_dataDirectory!, "Image 1.jpg"); string destinationFilePath = Path.Combine(destinationDirectory, "Image 1.jpg"); Assert.IsTrue(File.Exists(sourceFilePath)); Assert.IsFalse(File.Exists(destinationFilePath)); - Folder sourceFolder = _assetRepository!.AddFolder(dataDirectory!); + Folder sourceFolder = _assetRepository!.AddFolder(_dataDirectory!); Folder destinationFolder = _assetRepository!.AddFolder(destinationDirectory); - Asset? asset1 = _assetCreationService!.CreateAsset(dataDirectory!, "Image 1.jpg"); + Asset? asset1 = _assetCreationService!.CreateAsset(_dataDirectory!, "Image 1.jpg"); Assert.IsNotNull(asset1); _assetRepository!.SaveCatalog(sourceFolder); _assetRepository!.SaveCatalog(destinationFolder); - Asset[] assetsInSource = _assetRepository!.GetAssetsByPath(dataDirectory!); + Asset[] assetsInSource = _assetRepository!.GetAssetsByPath(_dataDirectory!); Assert.IsNotEmpty(assetsInSource); Assert.AreEqual(1, assetsInSource.Length); Assert.IsTrue(assetsInSource.Any(x => x.FileName == asset1!.FileName)); @@ -597,7 +597,7 @@ public void MoveAssets_AssetsAreValidButDirectoryIsInReadOnlyMode_DoesNotMoveAnd Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset1!.FileName)); - Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1!.FileName)); + Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1.FileName)); List assetsInDb = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.AssetsTableName, AssetConfigs.ReadFunc); Assert.IsNotEmpty(assetsInDb); @@ -607,7 +607,7 @@ public void MoveAssets_AssetsAreValidButDirectoryIsInReadOnlyMode_DoesNotMoveAnd List cataloguedAssetsInSource = _assetRepository!.GetCataloguedAssetsByPath(sourceFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInSource); Assert.AreEqual(1, cataloguedAssetsInSource.Count); - Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1!.FileName)); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1.FileName)); List cataloguedAssetsInDestination = _assetRepository!.GetCataloguedAssetsByPath(destinationFolder.Path); Assert.IsEmpty(cataloguedAssetsInDestination); @@ -615,7 +615,7 @@ public void MoveAssets_AssetsAreValidButDirectoryIsInReadOnlyMode_DoesNotMoveAnd List recentTargetPaths = _assetRepository.GetRecentTargetPaths(); Assert.IsEmpty(recentTargetPaths); - Asset[] assets = { asset1 }; + Asset[] assets = [asset1]; bool hasBeenMoved = _moveAssetsService!.MoveAssets(assets, destinationFolder, preserveOriginalFile); @@ -623,16 +623,16 @@ public void MoveAssets_AssetsAreValidButDirectoryIsInReadOnlyMode_DoesNotMoveAnd Assert.IsTrue(File.Exists(sourceFilePath)); Assert.IsFalse(File.Exists(destinationFilePath)); - assetsInSource = _assetRepository!.GetAssetsByPath(dataDirectory!); + assetsInSource = _assetRepository!.GetAssetsByPath(_dataDirectory!); Assert.IsNotEmpty(assetsInSource); Assert.AreEqual(1, assetsInSource.Length); - Assert.IsTrue(assetsInSource.Any(x => x.FileName == asset1!.FileName)); + Assert.IsTrue(assetsInSource.Any(x => x.FileName == asset1.FileName)); assetsInDestination = _assetRepository!.GetAssetsByPath(destinationDirectory); Assert.IsEmpty(assetsInDestination); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset1!.FileName)); - Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1!.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset1.FileName)); + Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1.FileName)); assetsInDb = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.AssetsTableName, AssetConfigs.ReadFunc); Assert.IsNotEmpty(assetsInDb); @@ -642,7 +642,7 @@ public void MoveAssets_AssetsAreValidButDirectoryIsInReadOnlyMode_DoesNotMoveAnd cataloguedAssetsInSource = _assetRepository!.GetCataloguedAssetsByPath(sourceFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInSource); Assert.AreEqual(1, cataloguedAssetsInSource.Count); - Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1!.FileName)); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1.FileName)); cataloguedAssetsInDestination = _assetRepository!.GetCataloguedAssetsByPath(destinationFolder.Path); Assert.IsEmpty(cataloguedAssetsInDestination); @@ -652,9 +652,9 @@ public void MoveAssets_AssetsAreValidButDirectoryIsInReadOnlyMode_DoesNotMoveAnd } finally { - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); - // Allow write access to the directory + // Allow to write access to the directory DirectoryHelper.AllowWriteAccess(destinationDirectory); Directory.Delete(destinationDirectory, true); @@ -664,18 +664,18 @@ public void MoveAssets_AssetsAreValidButDirectoryIsInReadOnlyMode_DoesNotMoveAnd [Test] public void MoveAssets_AssetIsInTheDestinationButNotInTheSourceAndPreserveOriginalFilesIsTrue_ThrowsFileNotFoundException() { - string sourceDirectory = Path.Combine(dataDirectory!, "SourceToMove"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToMove"); + string sourceDirectory = Path.Combine(_dataDirectory!, "SourceToMove"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToMove"); try { Directory.CreateDirectory(sourceDirectory); Directory.CreateDirectory(destinationDirectory); - string sourceFilePath1 = Path.Combine(dataDirectory!, "Image 6.jpg"); + string sourceFilePath1 = Path.Combine(_dataDirectory!, "Image 6.jpg"); string newSourceFilePath1 = Path.Combine(sourceDirectory, "Image 6.jpg"); string destinationFilePath1 = Path.Combine(destinationDirectory, "Image 6.jpg"); - string sourceFilePath2 = Path.Combine(dataDirectory!, "Image 1.jpg"); + string sourceFilePath2 = Path.Combine(_dataDirectory!, "Image 1.jpg"); string newSourceFilePath2 = Path.Combine(sourceDirectory, "Image 1.jpg"); string destinationFilePath2 = Path.Combine(destinationDirectory, "Image 1.jpg"); @@ -720,8 +720,8 @@ public void MoveAssets_AssetIsInTheDestinationButNotInTheSourceAndPreserveOrigin Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset1!.FileName)); Assert.IsFalse(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset2!.FileName)); - Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1!.FileName)); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2!.FileName)); + Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2.FileName)); List assetsInDb = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.AssetsTableName, AssetConfigs.ReadFunc); Assert.IsNotEmpty(assetsInDb); @@ -732,19 +732,19 @@ public void MoveAssets_AssetIsInTheDestinationButNotInTheSourceAndPreserveOrigin List cataloguedAssetsInSource = _assetRepository!.GetCataloguedAssetsByPath(sourceFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInSource); Assert.AreEqual(1, cataloguedAssetsInSource.Count); - Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1!.FileName)); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1.FileName)); List cataloguedAssetsInDestination = _assetRepository!.GetCataloguedAssetsByPath(destinationFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInDestination); Assert.AreEqual(1, cataloguedAssetsInDestination.Count); - Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset2.FileName)); List recentTargetPaths = _assetRepository.GetRecentTargetPaths(); Assert.IsEmpty(recentTargetPaths); - asset2!.Folder = new() { Path = sourceDirectory }; // Asset will be in the dest and not in the source + asset2.Folder = new() { Path = sourceDirectory }; // Asset will be in the dest and not in the source - Asset[] assets = { asset1, asset2 }; + Asset[] assets = [asset1, asset2]; FileNotFoundException? exception = Assert.Throws(() => _moveAssetsService!.MoveAssets(assets, destinationFolder, false)); Assert.AreEqual($"File does not exist: '{newSourceFilePath2}'.", exception?.Message); @@ -757,18 +757,18 @@ public void MoveAssets_AssetIsInTheDestinationButNotInTheSourceAndPreserveOrigin assetsInSource = _assetRepository!.GetAssetsByPath(sourceDirectory); Assert.IsNotEmpty(assetsInSource); Assert.AreEqual(1, assetsInSource.Length); - Assert.IsTrue(assetsInSource.Any(x => x.FileName == asset1!.FileName)); + Assert.IsTrue(assetsInSource.Any(x => x.FileName == asset1.FileName)); assetsInDestination = _assetRepository!.GetAssetsByPath(destinationDirectory); Assert.IsNotEmpty(assetsInDestination); Assert.AreEqual(1, assetsInDestination.Length); - Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset2.FileName)); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset1!.FileName)); - Assert.IsFalse(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset2!.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset1.FileName)); + Assert.IsFalse(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset2.FileName)); - Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1!.FileName)); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2!.FileName)); + Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2.FileName)); assetsInDb = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.AssetsTableName, AssetConfigs.ReadFunc); Assert.IsNotEmpty(assetsInDb); @@ -776,15 +776,16 @@ public void MoveAssets_AssetIsInTheDestinationButNotInTheSourceAndPreserveOrigin Assert.IsTrue(assetsInDb.Any(x => x.FileName == asset1.FileName && x.FolderId == sourceFolder.FolderId)); Assert.IsTrue(assetsInDb.Any(x => x.FileName == asset2.FileName && x.FolderId == destinationFolder.FolderId)); + // TODO: Is it good now ? cataloguedAssetsInSource = _assetRepository!.GetCataloguedAssetsByPath(sourceFolder.Path); - Assert.IsNotEmpty(assetsInSource); - Assert.AreEqual(1, assetsInSource.Length); - Assert.IsTrue(assetsInSource.Any(x => x.FileName == asset1!.FileName)); + Assert.IsNotEmpty(cataloguedAssetsInSource); + Assert.AreEqual(1, cataloguedAssetsInSource.Count); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1.FileName)); cataloguedAssetsInDestination = _assetRepository!.GetCataloguedAssetsByPath(destinationFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInDestination); Assert.AreEqual(1, cataloguedAssetsInDestination.Count); - Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset2.FileName)); recentTargetPaths = _assetRepository.GetRecentTargetPaths(); Assert.IsEmpty(recentTargetPaths); @@ -793,22 +794,22 @@ public void MoveAssets_AssetIsInTheDestinationButNotInTheSourceAndPreserveOrigin { Directory.Delete(sourceDirectory, true); Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsTrueAndRecentTargetPathAlreadyAdded_MoveSucceeds() { - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToMove"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToMove"); try { Directory.CreateDirectory(destinationDirectory); - string sourceFilePath1 = Path.Combine(dataDirectory!, "Image 6.jpg"); + string sourceFilePath1 = Path.Combine(_dataDirectory!, "Image 6.jpg"); string destinationFilePath1 = Path.Combine(destinationDirectory, "Image 6.jpg"); - string sourceFilePath2 = Path.Combine(dataDirectory!, "Image 1.jpg"); + string sourceFilePath2 = Path.Combine(_dataDirectory!, "Image 1.jpg"); string destinationFilePath2 = Path.Combine(destinationDirectory, "Image 1.jpg"); Assert.IsTrue(File.Exists(sourceFilePath1)); @@ -816,21 +817,21 @@ public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsTrueAndRecentTarg Assert.IsTrue(File.Exists(sourceFilePath2)); Assert.IsFalse(File.Exists(destinationFilePath2)); - Folder sourceFolder = _assetRepository!.AddFolder(dataDirectory!); + Folder sourceFolder = _assetRepository!.AddFolder(_dataDirectory!); Folder destinationFolder = _assetRepository!.AddFolder(destinationDirectory); string fakeRecentTargetPath = Path.Combine(destinationDirectory, "fake"); - _assetRepository.SaveRecentTargetPaths(new List { fakeRecentTargetPath, destinationDirectory }); + _assetRepository.SaveRecentTargetPaths([fakeRecentTargetPath, destinationDirectory]); - Asset? asset1 = _assetCreationService!.CreateAsset(dataDirectory!, "Image 6.jpg"); + Asset? asset1 = _assetCreationService!.CreateAsset(_dataDirectory!, "Image 6.jpg"); Assert.IsNotNull(asset1); - Asset? asset2 = _assetCreationService!.CreateAsset(dataDirectory!, "Image 1.jpg"); + Asset? asset2 = _assetCreationService!.CreateAsset(_dataDirectory!, "Image 1.jpg"); Assert.IsNotNull(asset2); _assetRepository!.SaveCatalog(sourceFolder); _assetRepository!.SaveCatalog(destinationFolder); - Asset[] assetsInSource = _assetRepository!.GetAssetsByPath(dataDirectory!); + Asset[] assetsInSource = _assetRepository!.GetAssetsByPath(_dataDirectory!); Assert.IsNotEmpty(assetsInSource); Assert.AreEqual(2, assetsInSource.Length); Assert.IsTrue(assetsInSource.Any(x => x.FileName == asset1!.FileName)); @@ -842,8 +843,8 @@ public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsTrueAndRecentTarg Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset1!.FileName)); Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset2!.FileName)); - Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1!.FileName)); - Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2!.FileName)); + Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1.FileName)); + Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2.FileName)); List assetsInDb = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.AssetsTableName, AssetConfigs.ReadFunc); Assert.IsNotEmpty(assetsInDb); @@ -854,8 +855,8 @@ public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsTrueAndRecentTarg List cataloguedAssetsInSource = _assetRepository!.GetCataloguedAssetsByPath(sourceFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInSource); Assert.AreEqual(2, cataloguedAssetsInSource.Count); - Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1!.FileName)); - Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1.FileName)); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset2.FileName)); List cataloguedAssetsInDestination = _assetRepository!.GetCataloguedAssetsByPath(destinationFolder.Path); Assert.IsEmpty(cataloguedAssetsInDestination); @@ -866,7 +867,7 @@ public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsTrueAndRecentTarg Assert.AreEqual(fakeRecentTargetPath, recentTargetPaths[0]); Assert.AreEqual(destinationFolder.Path, recentTargetPaths[1]); - Asset[] assets = { asset1, asset2 }; + Asset[] assets = [asset1, asset2]; bool hasBeenMoved = _moveAssetsService!.MoveAssets(assets, destinationFolder, true); @@ -876,23 +877,23 @@ public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsTrueAndRecentTarg Assert.IsTrue(File.Exists(sourceFilePath2)); Assert.IsTrue(File.Exists(destinationFilePath2)); - assetsInSource = _assetRepository!.GetAssetsByPath(dataDirectory!); + assetsInSource = _assetRepository!.GetAssetsByPath(_dataDirectory!); Assert.IsNotEmpty(assetsInSource); Assert.AreEqual(2, assetsInSource.Length); - Assert.IsTrue(assetsInSource.Any(x => x.FileName == asset1!.FileName)); - Assert.IsTrue(assetsInSource.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(assetsInSource.Any(x => x.FileName == asset1.FileName)); + Assert.IsTrue(assetsInSource.Any(x => x.FileName == asset2.FileName)); assetsInDestination = _assetRepository!.GetAssetsByPath(destinationDirectory); Assert.IsNotEmpty(assetsInDestination); Assert.AreEqual(2, assetsInDestination.Length); - Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset1!.FileName)); - Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset1.FileName)); + Assert.IsTrue(assetsInDestination.Any(x => x.FileName == asset2.FileName)); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset1!.FileName)); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset2!.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset1.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset2.FileName)); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1!.FileName)); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2!.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset1.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset2.FileName)); assetsInDb = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.AssetsTableName, AssetConfigs.ReadFunc); Assert.IsNotEmpty(assetsInDb); @@ -905,14 +906,14 @@ public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsTrueAndRecentTarg cataloguedAssetsInSource = _assetRepository!.GetCataloguedAssetsByPath(sourceFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInSource); Assert.AreEqual(2, cataloguedAssetsInSource.Count); - Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1!.FileName)); - Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset1.FileName)); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset2.FileName)); cataloguedAssetsInDestination = _assetRepository!.GetCataloguedAssetsByPath(destinationFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInDestination); Assert.AreEqual(2, cataloguedAssetsInDestination.Count); - Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset1!.FileName)); - Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset2!.FileName)); + Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset1.FileName)); + Assert.IsTrue(cataloguedAssetsInDestination.Any(x => x.FileName == asset2.FileName)); recentTargetPaths = _assetRepository.GetRecentTargetPaths(); Assert.IsNotEmpty(recentTargetPaths); @@ -923,7 +924,7 @@ public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsTrueAndRecentTarg finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } @@ -932,13 +933,13 @@ public void MoveAssets_AssetsAreValidAndPreserveOriginalFilesIsTrueAndRecentTarg [TestCase(false)] public void MoveAssets_SameSourceAndDestination_DoesNotMoveFileAndReturnsTrue(bool preserveOriginalFile) { - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToMove"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToMove"); try { Directory.CreateDirectory(destinationDirectory); - string sourceFilePath = Path.Combine(dataDirectory!, "Image 1.jpg"); + string sourceFilePath = Path.Combine(_dataDirectory!, "Image 1.jpg"); string destinationFilePath = Path.Combine(destinationDirectory, "Image 1.jpg"); bool hasBeenCopied = _moveAssetsService!.CopyAsset(sourceFilePath, destinationFilePath); @@ -956,16 +957,16 @@ public void MoveAssets_SameSourceAndDestination_DoesNotMoveFileAndReturnsTrue(bo Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset!.FileName)); - bool hasBeenMoved = _moveAssetsService!.MoveAssets(new Asset[] { asset }, sourceFolder, preserveOriginalFile); + bool hasBeenMoved = _moveAssetsService!.MoveAssets([asset], sourceFolder, preserveOriginalFile); Assert.IsTrue(hasBeenMoved); Assert.IsTrue(File.Exists(destinationFilePath)); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset!.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset.FileName)); } finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } @@ -974,18 +975,18 @@ public void MoveAssets_SameSourceAndDestination_DoesNotMoveFileAndReturnsTrue(bo [TestCase(false)] public void MoveAssets_DifferentFileNameBetweenSourceAndDestination_ThrowsFileNotFoundException(bool preserveOriginalFile) { - string sourceDirectory = Path.Combine(dataDirectory!, "SourceToMove"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToMove"); + string sourceDirectory = Path.Combine(_dataDirectory!, "SourceToMove"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToMove"); try { Directory.CreateDirectory(sourceDirectory); Directory.CreateDirectory(destinationDirectory); - string assetOldFileName = "Image 1.jpg"; - string assetNewFileName = "Image 2.jpg"; + const string assetOldFileName = "Image 1.jpg"; + const string assetNewFileName = "Image 2.jpg"; - string sourceFilePath = Path.Combine(dataDirectory!, assetOldFileName); + string sourceFilePath = Path.Combine(_dataDirectory!, assetOldFileName); string newSourceFilePath = Path.Combine(sourceDirectory, assetOldFileName); string destinationFilePath = Path.Combine(destinationDirectory, assetNewFileName); @@ -1013,7 +1014,7 @@ public void MoveAssets_DifferentFileNameBetweenSourceAndDestination_ThrowsFileNo Assert.IsEmpty(assetsInDestination); Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset!.FileName)); - Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset!.FileName)); + Assert.IsFalse(_assetRepository!.ContainsThumbnail(destinationFolder.Path, asset.FileName)); List assetsInDb = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.AssetsTableName, AssetConfigs.ReadFunc); Assert.IsNotEmpty(assetsInDb); @@ -1023,7 +1024,7 @@ public void MoveAssets_DifferentFileNameBetweenSourceAndDestination_ThrowsFileNo List cataloguedAssetsInSource = _assetRepository!.GetCataloguedAssetsByPath(sourceFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInSource); Assert.AreEqual(1, cataloguedAssetsInSource.Count); - Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset!.FileName)); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset.FileName)); List cataloguedAssetsInDestination = _assetRepository!.GetCataloguedAssetsByPath(destinationFolder.Path); Assert.IsEmpty(cataloguedAssetsInDestination); @@ -1032,7 +1033,7 @@ public void MoveAssets_DifferentFileNameBetweenSourceAndDestination_ThrowsFileNo Assert.IsEmpty(recentTargetPaths); asset.FileName = assetNewFileName; - Asset[] assets = { asset }; + Asset[] assets = [asset]; FileNotFoundException? exception = Assert.Throws(() => _moveAssetsService!.MoveAssets(assets, destinationFolder, preserveOriginalFile)); @@ -1058,7 +1059,7 @@ public void MoveAssets_DifferentFileNameBetweenSourceAndDestination_ThrowsFileNo assetsInDb = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.AssetsTableName, AssetConfigs.ReadFunc); Assert.IsNotEmpty(assetsInDb); Assert.AreEqual(1, assetsInDb.Count); - Assert.IsTrue(assetsInDb.Any(x => x.FileName == assetOldFileName && x.FolderId == sourceFolder!.FolderId)); + Assert.IsTrue(assetsInDb.Any(x => x.FileName == assetOldFileName && x.FolderId == sourceFolder.FolderId)); cataloguedAssetsInSource = _assetRepository!.GetCataloguedAssetsByPath(sourceFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInSource); @@ -1075,7 +1076,7 @@ public void MoveAssets_DifferentFileNameBetweenSourceAndDestination_ThrowsFileNo { Directory.Delete(sourceDirectory, true); Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } @@ -1084,16 +1085,16 @@ public void MoveAssets_DifferentFileNameBetweenSourceAndDestination_ThrowsFileNo [TestCase(false)] public void MoveAssets_DifferentFileNameAndSameSourceAndDestination_MovesFileAndReturnsTrue(bool preserveOriginalFile) { - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToMove"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToMove"); try { Directory.CreateDirectory(destinationDirectory); - string assetOldFileName = "Image 1.jpg"; - string assetNewFileName = "Image 2.jpg"; + const string assetOldFileName = "Image 1.jpg"; + const string assetNewFileName = "Image 2.jpg"; - string sourceFilePath = Path.Combine(dataDirectory!, assetOldFileName); + string sourceFilePath = Path.Combine(_dataDirectory!, assetOldFileName); string destinationFilePath = Path.Combine(destinationDirectory, assetOldFileName); string newDestinationFilePath = Path.Combine(destinationDirectory, assetNewFileName); @@ -1126,13 +1127,13 @@ public void MoveAssets_DifferentFileNameAndSameSourceAndDestination_MovesFileAnd List cataloguedAssetsInSource = _assetRepository!.GetCataloguedAssetsByPath(sourceFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInSource); Assert.AreEqual(1, cataloguedAssetsInSource.Count); - Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset!.FileName)); + Assert.IsTrue(cataloguedAssetsInSource.Any(x => x.FileName == asset.FileName)); List recentTargetPaths = _assetRepository.GetRecentTargetPaths(); Assert.IsEmpty(recentTargetPaths); asset.FileName = assetNewFileName; - Asset[] assets = { asset }; + Asset[] assets = [asset]; FileNotFoundException? exception = Assert.Throws(() => _moveAssetsService!.MoveAssets(assets, sourceFolder, preserveOriginalFile)); @@ -1151,7 +1152,7 @@ public void MoveAssets_DifferentFileNameAndSameSourceAndDestination_MovesFileAnd assetsInDb = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.AssetsTableName, AssetConfigs.ReadFunc); Assert.IsNotEmpty(assetsInDb); Assert.AreEqual(1, assetsInDb.Count); - Assert.IsTrue(assetsInDb.Any(x => x.FileName == assetOldFileName && x.FolderId == sourceFolder!.FolderId)); + Assert.IsTrue(assetsInDb.Any(x => x.FileName == assetOldFileName && x.FolderId == sourceFolder.FolderId)); cataloguedAssetsInSource = _assetRepository!.GetCataloguedAssetsByPath(sourceFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInSource); @@ -1164,7 +1165,7 @@ public void MoveAssets_DifferentFileNameAndSameSourceAndDestination_MovesFileAnd finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } @@ -1177,7 +1178,7 @@ public void MoveAssets_AssetsIsNull_ThrowsArgumentNullException(bool preserveOri { Asset[]? assets = null; - Folder destinationFolder = new() { Path = dataDirectory! }; + Folder destinationFolder = new() { Path = _dataDirectory! }; ArgumentNullException? exception = Assert.Throws(() => _moveAssetsService!.MoveAssets(assets!, destinationFolder, preserveOriginalFile)); @@ -1186,7 +1187,7 @@ public void MoveAssets_AssetsIsNull_ThrowsArgumentNullException(bool preserveOri } finally { - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } @@ -1197,18 +1198,18 @@ public void MoveAssets_AssetsIsEmpty_ThrowsArgumentNullException(bool preserveOr { try { - Asset[]? assets = Array.Empty(); + Asset[] assets = []; - Folder destinationFolder = new() { Path = dataDirectory! }; + Folder destinationFolder = new() { Path = _dataDirectory! }; - ArgumentNullException? exception = Assert.Throws(() => _moveAssetsService!.MoveAssets(assets!, destinationFolder, preserveOriginalFile)); + ArgumentNullException? exception = Assert.Throws(() => _moveAssetsService!.MoveAssets(assets, destinationFolder, preserveOriginalFile)); Assert.AreEqual("assets cannot be null or empty. (Parameter 'assets')", exception?.Message); Assert.AreEqual(nameof(assets), exception?.ParamName); } finally { - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } @@ -1219,21 +1220,21 @@ public void MoveAssets_OneAssetIsNull_ThrowsArgumentNullException(bool preserveO { try { - Asset asset1 = new() { FileName = "Image 1.jpg", Folder = new Folder() { Path = dataDirectory! } }; + Asset asset1 = new() { FileName = "Image 1.jpg", Folder = new() { Path = _dataDirectory! }, Hash = string.Empty }; Asset? asset2 = null; - Asset asset3 = new() { FileName = "Image 2.jpg", Folder = new Folder() { Path = dataDirectory! } }; - Asset[] assets = { asset1, asset2!, asset3 }; + Asset asset3 = new() { FileName = "Image 2.jpg", Folder = new() { Path = _dataDirectory! }, Hash = string.Empty }; + Asset[] assets = [asset1, asset2!, asset3]; - Folder destinationFolder = new() { Path = dataDirectory! }; + Folder destinationFolder = new() { Path = _dataDirectory! }; - ArgumentNullException? exception = Assert.Throws(() => _moveAssetsService!.MoveAssets(assets!, destinationFolder, preserveOriginalFile)); + ArgumentNullException? exception = Assert.Throws(() => _moveAssetsService!.MoveAssets(assets, destinationFolder, preserveOriginalFile)); Assert.AreEqual("asset cannot be null. (Parameter 'asset')", exception?.Message); Assert.AreEqual("asset", exception?.ParamName); } finally { - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } @@ -1246,21 +1247,21 @@ public void MoveAssets_OneAssetFolderIsNull_ThrowsArgumentNullException(bool pre { Folder? folder = null; - Asset asset1 = new() { FileName = "Image 1.jpg", Folder = new Folder() { Path = dataDirectory! } }; - Asset? asset2 = new() { Folder = folder! }; - Asset asset3 = new() { FileName = "Image 2.jpg", Folder = new Folder() { Path = dataDirectory! } }; - Asset[] assets = { asset1, asset2, asset3 }; + Asset asset1 = new() { FileName = "Image 1.jpg", Folder = new() { Path = _dataDirectory! }, Hash = string.Empty }; + Asset asset2 = new() { FileName = "NonExistentFile.jpg", Folder = folder!, Hash = string.Empty }; + Asset asset3 = new() { FileName = "Image 2.jpg", Folder = new() { Path = _dataDirectory! }, Hash = string.Empty }; + Asset[] assets = [asset1, asset2, asset3]; - Folder destinationFolder = new() { Path = dataDirectory! }; + Folder destinationFolder = new() { Path = _dataDirectory! }; - ArgumentNullException? exception = Assert.Throws(() => _moveAssetsService!.MoveAssets(assets!, destinationFolder, preserveOriginalFile)); + ArgumentNullException? exception = Assert.Throws(() => _moveAssetsService!.MoveAssets(assets, destinationFolder, preserveOriginalFile)); Assert.AreEqual("asset.Folder cannot be null. (Parameter 'Folder')", exception?.Message); Assert.AreEqual(nameof(Folder), exception?.ParamName); } finally { - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } @@ -1271,18 +1272,18 @@ public void MoveAssets_DestinationFolderIsNull_ThrowsArgumentNullException(bool { try { - Asset[] assets = new Asset[] { new() { Folder = new() { Path = dataDirectory! } } }; + Asset[] assets = [new() { FileName = "NonExistentFile.jpg", Folder = new() { Path = _dataDirectory! }, Hash = string.Empty }]; Folder? destinationFolder = null; - ArgumentNullException? exception = Assert.Throws(() => _moveAssetsService!.MoveAssets(assets!, destinationFolder!, preserveOriginalFile)); + ArgumentNullException? exception = Assert.Throws(() => _moveAssetsService!.MoveAssets(assets, destinationFolder!, preserveOriginalFile)); Assert.AreEqual("destinationFolder cannot be null. (Parameter 'destinationFolder')", exception?.Message); Assert.AreEqual(nameof(destinationFolder), exception?.ParamName); } finally { - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } @@ -1291,48 +1292,49 @@ public void MoveAssets_DestinationFolderIsNull_ThrowsArgumentNullException(bool [TestCase(false)] public void MoveAssets_FileDoesNotExist_ThrowsFileNotFoundException(bool preserveOriginalFile) { - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToMove"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToMove"); try { Directory.CreateDirectory(destinationDirectory); - string sourceFilePath = Path.Combine(dataDirectory!, "NonExistentFile.jpg"); + string sourceFilePath = Path.Combine(_dataDirectory!, "NonExistentFile.jpg"); string destinationFilePath = Path.Combine(destinationDirectory, "NonExistentFile.jpg"); Assert.IsFalse(File.Exists(sourceFilePath)); Assert.IsFalse(File.Exists(destinationFilePath)); - Folder sourceFolder = _assetRepository!.AddFolder(dataDirectory!); + Folder sourceFolder = _assetRepository!.AddFolder(_dataDirectory!); Folder destinationFolder = _assetRepository!.AddFolder(destinationDirectory); Asset asset = new() { FileName = "NonExistentFile.jpg", Folder = sourceFolder, - FolderId = sourceFolder.FolderId + FolderId = sourceFolder.FolderId, + Hash = string.Empty }; - FileNotFoundException? exception = Assert.Throws(() => _moveAssetsService!.MoveAssets(new Asset[] { asset }, destinationFolder, preserveOriginalFile)); + FileNotFoundException? exception = Assert.Throws(() => _moveAssetsService!.MoveAssets([asset], destinationFolder, preserveOriginalFile)); Assert.AreEqual($"File does not exist: '{sourceFilePath}'.", exception?.Message); } finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public void DeleteAssets_AssetsAreValid_DeletesAssetsAndSavesCatalog() { - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToCopy"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToCopy"); try { Directory.CreateDirectory(destinationDirectory); - string sourceFilePath1 = Path.Combine(dataDirectory!, "Image 6.jpg"); + string sourceFilePath1 = Path.Combine(_dataDirectory!, "Image 6.jpg"); string destinationFilePath1 = Path.Combine(destinationDirectory, "Image 6.jpg"); bool hasBeenCopied = _moveAssetsService!.CopyAsset(sourceFilePath1, destinationFilePath1); @@ -1341,7 +1343,7 @@ public void DeleteAssets_AssetsAreValid_DeletesAssetsAndSavesCatalog() Assert.IsTrue(File.Exists(sourceFilePath1)); Assert.IsTrue(File.Exists(destinationFilePath1)); - string sourceFilePath2 = Path.Combine(dataDirectory!, "Image 1.jpg"); + string sourceFilePath2 = Path.Combine(_dataDirectory!, "Image 1.jpg"); string destinationFilePath2 = Path.Combine(destinationDirectory, "Image 1.jpg"); hasBeenCopied = _moveAssetsService!.CopyAsset(sourceFilePath2, destinationFilePath2); @@ -1363,14 +1365,14 @@ public void DeleteAssets_AssetsAreValid_DeletesAssetsAndSavesCatalog() Assert.AreEqual(1, assetsInRepository.Length); Assert.AreEqual(asset!.FileName, assetsInRepository[0].FileName); - Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset!.FileName)); + Assert.IsTrue(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset.FileName)); List assetsInDb = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.AssetsTableName, AssetConfigs.ReadFunc); Assert.IsNotEmpty(assetsInDb); Assert.AreEqual(1, assetsInDb.Count); - Assert.AreEqual(asset!.FileName, assetsInDb[0].FileName); + Assert.AreEqual(asset.FileName, assetsInDb[0].FileName); - _moveAssetsService!.DeleteAssets(new Asset[] { asset }); + _moveAssetsService!.DeleteAssets([asset]); Assert.IsFalse(_assetRepository!.ContainsThumbnail(sourceFolder.Path, asset.FileName)); @@ -1386,7 +1388,7 @@ public void DeleteAssets_AssetsAreValid_DeletesAssetsAndSavesCatalog() finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } @@ -1404,7 +1406,7 @@ public void DeleteAssets_AssetsIsNull_ThrowsArgumentNullException() } finally { - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } @@ -1413,16 +1415,16 @@ public void DeleteAssets_AssetsIsEmpty_ThrowsArgumentNullException() { try { - Asset[]? assets = Array.Empty(); + Asset[] assets = []; - ArgumentNullException? exception = Assert.Throws(() => _moveAssetsService!.DeleteAssets(assets!)); + ArgumentNullException? exception = Assert.Throws(() => _moveAssetsService!.DeleteAssets(assets)); Assert.AreEqual("assets cannot be null or empty. (Parameter 'assets')", exception?.Message); Assert.AreEqual(nameof(assets), exception?.ParamName); } finally { - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } @@ -1431,19 +1433,19 @@ public void DeleteAssets_OneAssetIsNull_ThrowsArgumentNullException() { try { - Asset asset1 = new() { FileName = "Image 1.jpg", Folder = new Folder() { Path = dataDirectory! } }; + Asset asset1 = new() { FileName = "Image 1.jpg", Folder = new() { Path = _dataDirectory! }, Hash = string.Empty }; Asset? asset2 = null; - Asset asset3 = new() { FileName = "Image 2.jpg", Folder = new Folder() { Path = dataDirectory! } }; - Asset[] assets = { asset1, asset2!, asset3 }; + Asset asset3 = new() { FileName = "Image 2.jpg", Folder = new() { Path = _dataDirectory! }, Hash = string.Empty }; + Asset[] assets = [asset1, asset2!, asset3]; - ArgumentNullException? exception = Assert.Throws(() => _moveAssetsService!.DeleteAssets(assets!)); + ArgumentNullException? exception = Assert.Throws(() => _moveAssetsService!.DeleteAssets(assets)); Assert.AreEqual("asset cannot be null. (Parameter 'asset')", exception?.Message); Assert.AreEqual("asset", exception?.ParamName); } finally { - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } @@ -1454,19 +1456,19 @@ public void DeleteAssets_OneAssetFolderIsNull_ThrowsArgumentNullException() { Folder? folder = null; - Asset asset1 = new() { FileName = "Image 1.jpg", Folder = new Folder() { Path = dataDirectory! } }; - Asset? asset2 = new() { Folder = folder! }; - Asset asset3 = new() { FileName = "Image 2.jpg", Folder = new Folder() { Path = dataDirectory! } }; - Asset[] assets = { asset1, asset2, asset3 }; + Asset asset1 = new() { FileName = "Image 1.jpg", Folder = new() { Path = _dataDirectory! }, Hash = string.Empty }; + Asset asset2 = new() { FileName = "NonExistentFile.jpg", Folder = folder!, Hash = string.Empty }; + Asset asset3 = new() { FileName = "Image 2.jpg", Folder = new() { Path = _dataDirectory! }, Hash = string.Empty }; + Asset[] assets = [asset1, asset2, asset3]; - ArgumentNullException? exception = Assert.Throws(() => _moveAssetsService!.DeleteAssets(assets!)); + ArgumentNullException? exception = Assert.Throws(() => _moveAssetsService!.DeleteAssets(assets)); Assert.AreEqual("asset.Folder cannot be null. (Parameter 'Folder')", exception?.Message); Assert.AreEqual(nameof(Folder), exception?.ParamName); } finally { - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } @@ -1475,30 +1477,30 @@ public void DeleteAssets_AssetDoesNotExists_ThrowsFileNotFoundException() { try { - Folder folder = new() { Path = dataDirectory! }; - Asset asset = new() { FileName = "NonExistentFile.jpg", Folder = folder }; - Asset[] assets = { asset }; + Folder folder = new() { Path = _dataDirectory! }; + Asset asset = new() { FileName = "NonExistentFile.jpg", Folder = folder, Hash = string.Empty }; + Asset[] assets = [asset]; - FileNotFoundException? exception = Assert.Throws(() => _moveAssetsService!.DeleteAssets(assets!)); + FileNotFoundException? exception = Assert.Throws(() => _moveAssetsService!.DeleteAssets(assets)); Assert.AreEqual($"File does not exist: '{asset.FullPath}'.", exception?.Message); } finally { - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public void CopyAsset_SourceAndDestinationAreValid_CopiesFileAndReturnsTrue() { - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToCopy"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToCopy"); try { Directory.CreateDirectory(destinationDirectory); - string sourceFilePath = Path.Combine(dataDirectory!, "Image 1.jpg"); + string sourceFilePath = Path.Combine(_dataDirectory!, "Image 1.jpg"); string destinationFilePath = Path.Combine(destinationDirectory, "Image 1.jpg"); bool hasBeenCopied = _moveAssetsService!.CopyAsset(sourceFilePath, destinationFilePath); @@ -1510,23 +1512,23 @@ public void CopyAsset_SourceAndDestinationAreValid_CopiesFileAndReturnsTrue() finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public void CopyAsset_SourceAndDestinationAreValidButDirectoryIsInReadOnlyMode_DoesNotCopyAndReturnFalse() { - string destinationDirectory = Path.Combine(dataDirectory!, "NoCopyDirectory"); + string destinationDirectory = Path.Combine(_dataDirectory!, "NoCopyDirectory"); try { Directory.CreateDirectory(destinationDirectory); - // Deny write access to the directory + // Deny to write access to the directory DirectoryHelper.DenyWriteAccess(destinationDirectory); - string sourceFilePath = Path.Combine(dataDirectory!, "Image 1.jpg"); + string sourceFilePath = Path.Combine(_dataDirectory!, "Image 1.jpg"); string destinationFilePath = Path.Combine(destinationDirectory, "Image 1.jpg"); bool hasBeenCopied = _moveAssetsService!.CopyAsset(sourceFilePath, destinationFilePath); @@ -1537,9 +1539,9 @@ public void CopyAsset_SourceAndDestinationAreValidButDirectoryIsInReadOnlyMode_D } finally { - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); - // Allow write access to the directory + // Allow to write access to the directory DirectoryHelper.AllowWriteAccess(destinationDirectory); Directory.Delete(destinationDirectory, true); @@ -1549,7 +1551,7 @@ public void CopyAsset_SourceAndDestinationAreValidButDirectoryIsInReadOnlyMode_D [Test] public void CopyAsset_SourceFilePathIsADirectory_DoesNotCopyAndReturnFalse() { - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToCopy"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToCopy"); try { @@ -1557,14 +1559,14 @@ public void CopyAsset_SourceFilePathIsADirectory_DoesNotCopyAndReturnFalse() string destinationFilePath = Path.Combine(destinationDirectory, "Image 1.jpg"); - bool hasBeenCopied = _moveAssetsService!.CopyAsset(dataDirectory!, destinationFilePath); // Access denied when source file path is a directory -> UnauthorizedAccessException + bool hasBeenCopied = _moveAssetsService!.CopyAsset(_dataDirectory!, destinationFilePath); // Access denied when source file path is a directory -> UnauthorizedAccessException Assert.IsFalse(hasBeenCopied); Assert.IsFalse(File.Exists(destinationFilePath)); } finally { - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); Directory.Delete(destinationDirectory, true); } } @@ -1572,8 +1574,8 @@ public void CopyAsset_SourceFilePathIsADirectory_DoesNotCopyAndReturnFalse() [Test] public void CopyAsset_DestinationFilePathIsADirectory_DoesNotCopyAndThrowsIOException() { - string sourceDirectory = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); + string sourceDirectory = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); try { @@ -1584,7 +1586,7 @@ public void CopyAsset_DestinationFilePathIsADirectory_DoesNotCopyAndThrowsIOExce } finally { - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); Directory.Delete(destinationDirectory, true); } } @@ -1592,13 +1594,13 @@ public void CopyAsset_DestinationFilePathIsADirectory_DoesNotCopyAndThrowsIOExce [Test] public void CopyAsset_SameSourceAndDestination_DoesNotCopyFileAndReturnsTrue() { - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToCopy"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToCopy"); try { Directory.CreateDirectory(destinationDirectory); - string sourceFilePath = Path.Combine(dataDirectory!, "Image 1.jpg"); + string sourceFilePath = Path.Combine(_dataDirectory!, "Image 1.jpg"); string destinationFilePath = Path.Combine(destinationDirectory, "Image 1.jpg"); bool hasBeenCopied = _moveAssetsService!.CopyAsset(sourceFilePath, destinationFilePath); @@ -1615,20 +1617,20 @@ public void CopyAsset_SameSourceAndDestination_DoesNotCopyFileAndReturnsTrue() finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public void CopyAsset_DifferentFileNameBetweenSourceAndDestination_CopiesFileAndReturnsTrue() { - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToCopy"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToCopy"); try { Directory.CreateDirectory(destinationDirectory); - string sourceFilePath = Path.Combine(dataDirectory!, "Image 1.jpg"); + string sourceFilePath = Path.Combine(_dataDirectory!, "Image 1.jpg"); string destinationFilePath = Path.Combine(destinationDirectory, "Image 2.jpg"); bool hasBeenCopied = _moveAssetsService!.CopyAsset(sourceFilePath, destinationFilePath); @@ -1640,20 +1642,20 @@ public void CopyAsset_DifferentFileNameBetweenSourceAndDestination_CopiesFileAnd finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public void CopyAsset_DifferentFileNameAndSameSourceAndDestination_CopiesFileAndReturnsTrue() { - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToCopy"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToCopy"); try { Directory.CreateDirectory(destinationDirectory); - string sourceFilePath = Path.Combine(dataDirectory!, "Image 1.jpg"); + string sourceFilePath = Path.Combine(_dataDirectory!, "Image 1.jpg"); string destinationFilePath = Path.Combine(destinationDirectory, "Image 1.jpg"); bool hasBeenCopied = _moveAssetsService!.CopyAsset(sourceFilePath, destinationFilePath); @@ -1674,20 +1676,20 @@ public void CopyAsset_DifferentFileNameAndSameSourceAndDestination_CopiesFileAnd finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public void CopyAsset_FileInSourceDoesNotExist_DoesNotCopyFileAndThrowsFileNotFoundException() { - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToCopy"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToCopy"); try { Directory.CreateDirectory(destinationDirectory); - string nonExistentFilePath = Path.Combine(dataDirectory!, "NonExistentFile.jpg"); + string nonExistentFilePath = Path.Combine(_dataDirectory!, "NonExistentFile.jpg"); string destinationFilePath = Path.Combine(destinationDirectory, "Image.jpg"); FileNotFoundException? exception = Assert.Throws(() => _moveAssetsService!.CopyAsset(nonExistentFilePath, destinationFilePath)); @@ -1698,15 +1700,15 @@ public void CopyAsset_FileInSourceDoesNotExist_DoesNotCopyFileAndThrowsFileNotFo finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public void CopyAsset_SourceDoesNotExist_DoesNotCopyFileAndThrowsDirectoryNotFoundException() { - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToCopy"); - string nonExistentSource = Path.Combine(dataDirectory!, "toto"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToCopy"); + string nonExistentSource = Path.Combine(_dataDirectory!, "toto"); try { @@ -1723,18 +1725,18 @@ public void CopyAsset_SourceDoesNotExist_DoesNotCopyFileAndThrowsDirectoryNotFou finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public void CopyAsset_DestinationDoesNotExist_CopiesFileAndReturnsTrue() { - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToCopy"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToCopy"); try { - string sourceFilePath = Path.Combine(dataDirectory!, "Image 1.jpg"); + string sourceFilePath = Path.Combine(_dataDirectory!, "Image 1.jpg"); string destinationFilePath = Path.Combine(destinationDirectory, "Image 1.jpg"); bool hasBeenCopied = _moveAssetsService!.CopyAsset(sourceFilePath, destinationFilePath); @@ -1746,7 +1748,7 @@ public void CopyAsset_DestinationDoesNotExist_CopiesFileAndReturnsTrue() finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } @@ -1755,8 +1757,8 @@ public void CopyAsset_FileInSourceDoesNotExistButExistsInTheDestination_DoesNotC { try { - string sourceFilePath = Path.Combine(dataDirectory!, "NonExistentFile.jpg"); - string destinationFilePath = Path.Combine(dataDirectory!, "Image 1.jpg"); + string sourceFilePath = Path.Combine(_dataDirectory!, "NonExistentFile.jpg"); + string destinationFilePath = Path.Combine(_dataDirectory!, "Image 1.jpg"); bool hasBeenCopied = _moveAssetsService!.CopyAsset(sourceFilePath, destinationFilePath); @@ -1766,14 +1768,14 @@ public void CopyAsset_FileInSourceDoesNotExistButExistsInTheDestination_DoesNotC } finally { - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public void CopyAsset_SourceIsEmpty_ThrowsArgumentException() { - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToCopy"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToCopy"); try { @@ -1788,7 +1790,7 @@ public void CopyAsset_SourceIsEmpty_ThrowsArgumentException() finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } @@ -1797,23 +1799,23 @@ public void CopyAsset_DestinationIsEmpty_DoesNotCopyFileAndReturnsFalse() { try { - string sourceFilePath = Path.Combine(dataDirectory!, "Image 1.jpg"); + string sourceFilePath = Path.Combine(_dataDirectory!, "Image 1.jpg"); string destinationFilePath = string.Empty; - bool hasBeenCopied = _moveAssetsService!.CopyAsset(sourceFilePath, destinationFilePath!); + bool hasBeenCopied = _moveAssetsService!.CopyAsset(sourceFilePath, destinationFilePath); Assert.IsFalse(hasBeenCopied); } finally { - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public void CopyAsset_SourceIsNull_ThrowsArgumentNullException() { - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToCopy"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToCopy"); try { @@ -1828,7 +1830,7 @@ public void CopyAsset_SourceIsNull_ThrowsArgumentNullException() finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } @@ -1838,7 +1840,7 @@ public void CopyAsset_SourceIsNullButFileExistsInDestination_DoesNotCopyFileAndR try { string? sourceFilePath = null; - string destinationFilePath = Path.Combine(dataDirectory!, "Image 1.jpg"); + string destinationFilePath = Path.Combine(_dataDirectory!, "Image 1.jpg"); bool hasBeenCopied = _moveAssetsService!.CopyAsset(sourceFilePath!, destinationFilePath); @@ -1846,7 +1848,7 @@ public void CopyAsset_SourceIsNullButFileExistsInDestination_DoesNotCopyFileAndR } finally { - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } @@ -1855,7 +1857,7 @@ public void CopyAsset_DestinationIsNull_DoesNotCopyFileAndReturnsFalse() { try { - string sourceFilePath = Path.Combine(dataDirectory!, "Image 1.jpg"); + string sourceFilePath = Path.Combine(_dataDirectory!, "Image 1.jpg"); string? destinationFilePath = null; bool hasBeenCopied = _moveAssetsService!.CopyAsset(sourceFilePath, destinationFilePath!); @@ -1864,7 +1866,7 @@ public void CopyAsset_DestinationIsNull_DoesNotCopyFileAndReturnsFalse() } finally { - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Domain/SyncAssetsServiceTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Domain/SyncAssetsServiceTests.cs index 3dc8f0e8..11ac27cd 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Domain/SyncAssetsServiceTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Domain/SyncAssetsServiceTests.cs @@ -3,10 +3,10 @@ [TestFixture] public class SyncAssetsServiceTests { - private string? dataDirectory; - private string? databasePath; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _databasePath; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; private SyncAssetsService? _syncAssetsService; private UserConfigurationService? _userConfigurationService; @@ -20,15 +20,15 @@ public class SyncAssetsServiceTests [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - databasePath = Path.Combine(dataDirectory, "DatabaseTests"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _databasePath = Path.Combine(_dataDirectory, "DatabaseTests"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); _storageServiceMock.Setup(x => x.LoadBitmapThumbnailImage(It.IsAny(), It.IsAny(), It.IsAny())).Returns(new BitmapImage()); } @@ -49,8 +49,8 @@ public void SetUp() [Test] public async Task ExecuteAsync_SourceAndDestinationAreEmpty_NoStatusChangesAndNoImagesAreAdded() { - string sourceDirectory = Path.Combine(dataDirectory!, "SourceToSync"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); + string sourceDirectory = Path.Combine(_dataDirectory!, "SourceToSync"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); try { @@ -90,24 +90,24 @@ public async Task ExecuteAsync_SourceAndDestinationAreEmpty_NoStatusChangesAndNo { Directory.Delete(sourceDirectory, true); Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public async Task ExecuteAsync_SourceIsNotEmptyAndDestinationIsEmpty_StatusChangesAndImagesAreAdded() { - string sourceDirectory = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); + string sourceDirectory = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); try { Directory.CreateDirectory(destinationDirectory); - string assetName1 = "Image 1_duplicate.jpg"; - string assetName2 = "Image 9.png"; - string assetName3 = "Image 9_duplicate.png"; - string assetName4 = "Image_11.heic"; + const string assetName1 = "Image 1_duplicate.jpg"; + const string assetName2 = "Image 9.png"; + const string assetName3 = "Image 9_duplicate.png"; + const string assetName4 = "Image_11.heic"; string assetSourcePath1 = Path.Combine(sourceDirectory, assetName1); string assetSourcePath2 = Path.Combine(sourceDirectory, assetName2); @@ -199,26 +199,26 @@ public async Task ExecuteAsync_SourceIsNotEmptyAndDestinationIsEmpty_StatusChang finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public async Task ExecuteAsync_SourceIsEmptyAndDestinationIsNotEmpty_NoStatusChangesAndNoImagesAreAdded() { - string sourceToCopyPath = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); + string sourceToCopyPath = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); string sourceDirectory = Path.Combine(sourceToCopyPath, "Source"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); try { Directory.CreateDirectory(sourceDirectory); Directory.CreateDirectory(destinationDirectory); - string assetName1 = "Image 1_duplicate.jpg"; - string assetName2 = "Image 9.png"; - string assetName3 = "Image 9_duplicate.png"; - string assetName4 = "Image_11.heic"; + const string assetName1 = "Image 1_duplicate.jpg"; + const string assetName2 = "Image 9.png"; + const string assetName3 = "Image 9_duplicate.png"; + const string assetName4 = "Image_11.heic"; string assetSourcePath1 = Path.Combine(sourceDirectory, assetName1); string assetSourcePath2 = Path.Combine(sourceDirectory, assetName2); @@ -333,24 +333,24 @@ public async Task ExecuteAsync_SourceIsEmptyAndDestinationIsNotEmpty_NoStatusCha { Directory.Delete(sourceDirectory, true); Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public async Task ExecuteAsync_SourceAndDestinationAreNotEmptyMultipleNewImages_StatusChangesAndImagesAreAdded() { - string sourceDirectory = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); + string sourceDirectory = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); try { Directory.CreateDirectory(destinationDirectory); - string assetName1 = "Image 1_duplicate.jpg"; - string assetName2 = "Image 9.png"; - string assetName3 = "Image 9_duplicate.png"; - string assetName4 = "Image_11.heic"; + const string assetName1 = "Image 1_duplicate.jpg"; + const string assetName2 = "Image 9.png"; + const string assetName3 = "Image 9_duplicate.png"; + const string assetName4 = "Image_11.heic"; string assetSourcePath1 = Path.Combine(sourceDirectory, assetName1); string assetSourcePath2 = Path.Combine(sourceDirectory, assetName2); @@ -447,24 +447,24 @@ public async Task ExecuteAsync_SourceAndDestinationAreNotEmptyMultipleNewImages_ finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public async Task ExecuteAsync_SourceAndDestinationAreNotEmptyOneNewImage_StatusChangesAndImageAdded() { - string sourceDirectory = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); + string sourceDirectory = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); try { Directory.CreateDirectory(destinationDirectory); - string assetName1 = "Image 1_duplicate.jpg"; - string assetName2 = "Image 9.png"; - string assetName3 = "Image 9_duplicate.png"; - string assetName4 = "Image_11.heic"; + const string assetName1 = "Image 1_duplicate.jpg"; + const string assetName2 = "Image 9.png"; + const string assetName3 = "Image 9_duplicate.png"; + const string assetName4 = "Image_11.heic"; string assetSourcePath1 = Path.Combine(sourceDirectory, assetName1); string assetSourcePath2 = Path.Combine(sourceDirectory, assetName2); @@ -563,32 +563,32 @@ public async Task ExecuteAsync_SourceAndDestinationAreNotEmptyOneNewImage_Status finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public async Task ExecuteAsync_SourceAndDestinationAreNotEmptyMultipleNewImagesAndTwoDefinitions_StatusChangesAndImagesAreAdded() { - string firstSourceDirectory = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); - string secondSourceDirectory = Path.Combine(dataDirectory!, "Duplicates\\Thumbnail"); - string firstDestinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync1"); - string secondDestinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync2"); + string firstSourceDirectory = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); + string secondSourceDirectory = Path.Combine(_dataDirectory!, "Duplicates\\Thumbnail"); + string firstDestinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync1"); + string secondDestinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync2"); try { Directory.CreateDirectory(firstDestinationDirectory); Directory.CreateDirectory(secondDestinationDirectory); - string assetName1 = "Image 1_duplicate.jpg"; - string assetName2 = "Image 9.png"; - string assetName3 = "Image 9_duplicate.png"; - string assetName4 = "Image_11.heic"; + const string assetName1 = "Image 1_duplicate.jpg"; + const string assetName2 = "Image 9.png"; + const string assetName3 = "Image 9_duplicate.png"; + const string assetName4 = "Image_11.heic"; - string assetName5 = "Image_1336_Mini.JPG"; - string assetName6 = "Image_1336_Original.JPG"; - string assetName7 = "Image_1336_ShitQuality.JPG"; - string assetName8 = "Image_1336_Small.JPG"; + const string assetName5 = "Image_1336_Mini.JPG"; + const string assetName6 = "Image_1336_Original.JPG"; + const string assetName7 = "Image_1336_ShitQuality.JPG"; + const string assetName8 = "Image_1336_Small.JPG"; string assetSourcePath1 = Path.Combine(firstSourceDirectory, assetName1); string assetSourcePath2 = Path.Combine(firstSourceDirectory, assetName2); @@ -767,15 +767,15 @@ public async Task ExecuteAsync_SourceAndDestinationAreNotEmptyMultipleNewImagesA { Directory.Delete(firstDestinationDirectory, true); Directory.Delete(secondDestinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] - public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDestinationOrSubDirectoriresAndDestinationSubDirectoriesAreSingleLevel_StatusChangesAndImagesAreAdded() + public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDestinationOrSubDirectoriesAndDestinationSubDirectoriesAreSingleLevel_StatusChangesAndImagesAreAdded() { - string sourceDirectory = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); + string sourceDirectory = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); string destinationSubDirectory1 = Path.Combine(destinationDirectory, "SubDirectory1"); string destinationSubDirectory2 = Path.Combine(destinationDirectory, "SubDirectory2"); @@ -785,10 +785,10 @@ public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDes Directory.CreateDirectory(destinationSubDirectory1); Directory.CreateDirectory(destinationSubDirectory2); - string assetName1 = "Image 1_duplicate.jpg"; - string assetName2 = "Image 9.png"; - string assetName3 = "Image 9_duplicate.png"; - string assetName4 = "Image_11.heic"; + const string assetName1 = "Image 1_duplicate.jpg"; + const string assetName2 = "Image 9.png"; + const string assetName3 = "Image 9_duplicate.png"; + const string assetName4 = "Image_11.heic"; string assetSourcePath1 = Path.Combine(sourceDirectory, assetName1); string assetSourcePath2 = Path.Combine(sourceDirectory, assetName2); @@ -929,15 +929,15 @@ public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDes finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] - public async Task ExecuteAsync_SourceAndDestinationAreNotEmptyAllImagesAreInDestinationOrSubDirectoriresAndDestinationSubDirectoriesAreSingleLevel_StatusChangesAndNoImagesAreAdded() + public async Task ExecuteAsync_SourceAndDestinationAreNotEmptyAllImagesAreInDestinationOrSubDirectoriesAndDestinationSubDirectoriesAreSingleLevel_StatusChangesAndNoImagesAreAdded() { - string sourceDirectory = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); + string sourceDirectory = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); string destinationSubDirectory1 = Path.Combine(destinationDirectory, "SubDirectory1"); string destinationSubDirectory2 = Path.Combine(destinationDirectory, "SubDirectory2"); @@ -947,10 +947,10 @@ public async Task ExecuteAsync_SourceAndDestinationAreNotEmptyAllImagesAreInDest Directory.CreateDirectory(destinationSubDirectory1); Directory.CreateDirectory(destinationSubDirectory2); - string assetName1 = "Image 1_duplicate.jpg"; - string assetName2 = "Image 9.png"; - string assetName3 = "Image 9_duplicate.png"; - string assetName4 = "Image_11.heic"; + const string assetName1 = "Image 1_duplicate.jpg"; + const string assetName2 = "Image 9.png"; + const string assetName3 = "Image 9_duplicate.png"; + const string assetName4 = "Image_11.heic"; string assetSourcePath1 = Path.Combine(sourceDirectory, assetName1); string assetSourcePath2 = Path.Combine(sourceDirectory, assetName2); @@ -1093,18 +1093,18 @@ public async Task ExecuteAsync_SourceAndDestinationAreNotEmptyAllImagesAreInDest finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDestinationAndSourceSubDirectoriesAreSingleLevelAndIncludeSubFoldersIsFalse_StatusChangesAndImagesAreAdded() { - string sourceDirectory = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); + string sourceDirectory = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); string sourceSubDirectory1 = Path.Combine(sourceDirectory, "SubDirectory1"); string sourceSubDirectory2 = Path.Combine(sourceDirectory, "SubDirectory2"); - string sourceToCopy = Path.Combine(dataDirectory!, "Duplicates\\Part"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); + string sourceToCopy = Path.Combine(_dataDirectory!, "Duplicates\\Part"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); string destinationSubDirectory1 = Path.Combine(destinationDirectory, "SubDirectory1"); string destinationSubDirectory2 = Path.Combine(destinationDirectory, "SubDirectory2"); @@ -1114,12 +1114,12 @@ public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDes Directory.CreateDirectory(sourceSubDirectory1); Directory.CreateDirectory(sourceSubDirectory2); - string assetName1 = "Image 1_duplicate.jpg"; - string assetName2 = "Image 9.png"; - string assetName3 = "Image 9_duplicate.png"; - string assetName4 = "Image_11.heic"; - string assetName5 = "1336_BottomLeftPart.JPG"; - string assetName6 = "1336_TopRightPart.JPG"; + const string assetName1 = "Image 1_duplicate.jpg"; + const string assetName2 = "Image 9.png"; + const string assetName3 = "Image 9_duplicate.png"; + const string assetName4 = "Image_11.heic"; + const string assetName5 = "1336_BottomLeftPart.JPG"; + const string assetName6 = "1336_TopRightPart.JPG"; string assetSourcePath1 = Path.Combine(sourceDirectory, assetName1); string assetSourcePath2 = Path.Combine(sourceDirectory, assetName2); @@ -1257,18 +1257,18 @@ public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDes Directory.Delete(destinationDirectory, true); Directory.Delete(sourceSubDirectory1, true); Directory.Delete(sourceSubDirectory2, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDestinationAndSourceSubDirectoriesAreSingleLevelAndIncludeSubFoldersIsTrue_StatusChangesAndImagesAreAdded() { - string sourceDirectory = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); + string sourceDirectory = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); string sourceSubDirectory1 = Path.Combine(sourceDirectory, "SubDirectory1"); string sourceSubDirectory2 = Path.Combine(sourceDirectory, "SubDirectory2"); - string sourceToCopy = Path.Combine(dataDirectory!, "Duplicates\\Part"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); + string sourceToCopy = Path.Combine(_dataDirectory!, "Duplicates\\Part"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); string destinationSubDirectory1 = Path.Combine(destinationDirectory, "SubDirectory1"); string destinationSubDirectory2 = Path.Combine(destinationDirectory, "SubDirectory2"); @@ -1278,12 +1278,12 @@ public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDes Directory.CreateDirectory(sourceSubDirectory1); Directory.CreateDirectory(sourceSubDirectory2); - string assetName1 = "Image 1_duplicate.jpg"; - string assetName2 = "Image 9.png"; - string assetName3 = "Image 9_duplicate.png"; - string assetName4 = "Image_11.heic"; - string assetName5 = "1336_BottomLeftPart.JPG"; - string assetName6 = "1336_TopRightPart.JPG"; + const string assetName1 = "Image 1_duplicate.jpg"; + const string assetName2 = "Image 9.png"; + const string assetName3 = "Image 9_duplicate.png"; + const string assetName4 = "Image_11.heic"; + const string assetName5 = "1336_BottomLeftPart.JPG"; + const string assetName6 = "1336_TopRightPart.JPG"; string assetSourcePath1 = Path.Combine(sourceDirectory, assetName1); string assetSourcePath2 = Path.Combine(sourceDirectory, assetName2); @@ -1446,18 +1446,18 @@ public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDes Directory.Delete(destinationDirectory, true); Directory.Delete(sourceSubDirectory1, true); Directory.Delete(sourceSubDirectory2, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDestinationAndSourceAndDestinationSubDirectoriesAreSingleLevelAndIncludeSubFoldersIsTrue_StatusChangesAndImagesAreAdded() { - string sourceDirectory = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); + string sourceDirectory = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); string sourceSubDirectory1 = Path.Combine(sourceDirectory, "SubDirectory1"); string sourceSubDirectory2 = Path.Combine(sourceDirectory, "SubDirectory2"); - string sourceToCopy = Path.Combine(dataDirectory!, "Duplicates\\Part"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); + string sourceToCopy = Path.Combine(_dataDirectory!, "Duplicates\\Part"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); string destinationSubDirectory1 = Path.Combine(destinationDirectory, "SubDirectory1"); string destinationSubDirectory2 = Path.Combine(destinationDirectory, "SubDirectory2"); @@ -1469,12 +1469,12 @@ public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDes Directory.CreateDirectory(destinationSubDirectory1); Directory.CreateDirectory(destinationSubDirectory2); - string assetName1 = "Image 1_duplicate.jpg"; - string assetName2 = "Image 9.png"; - string assetName3 = "Image 9_duplicate.png"; - string assetName4 = "Image_11.heic"; - string assetName5 = "1336_BottomLeftPart.JPG"; - string assetName6 = "1336_TopRightPart.JPG"; + const string assetName1 = "Image 1_duplicate.jpg"; + const string assetName2 = "Image 9.png"; + const string assetName3 = "Image 9_duplicate.png"; + const string assetName4 = "Image_11.heic"; + const string assetName5 = "1336_BottomLeftPart.JPG"; + const string assetName6 = "1336_TopRightPart.JPG"; string assetSourcePath1 = Path.Combine(sourceDirectory, assetName1); string assetSourcePath2 = Path.Combine(sourceDirectory, assetName2); @@ -1643,15 +1643,15 @@ public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDes Directory.Delete(destinationDirectory, true); Directory.Delete(sourceSubDirectory1, true); Directory.Delete(sourceSubDirectory2, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] - public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDestinationOrSubDirectoriresAndDestinationSubDirectoriesAreMultipleLevel_StatusChangesAndImagesAreAdded() + public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDestinationOrSubDirectoriesAndDestinationSubDirectoriesAreMultipleLevel_StatusChangesAndImagesAreAdded() { - string sourceDirectory = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); + string sourceDirectory = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); string destinationSubDirectory1 = Path.Combine(destinationDirectory, "SubDirectory2//SubDirectory2"); string destinationSubDirectory2 = Path.Combine(destinationDirectory, "SubDirectory3//SubDirectory4//SubDirectory5"); @@ -1661,10 +1661,10 @@ public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDes Directory.CreateDirectory(destinationSubDirectory1); Directory.CreateDirectory(destinationSubDirectory2); - string assetName1 = "Image 1_duplicate.jpg"; - string assetName2 = "Image 9.png"; - string assetName3 = "Image 9_duplicate.png"; - string assetName4 = "Image_11.heic"; + const string assetName1 = "Image 1_duplicate.jpg"; + const string assetName2 = "Image 9.png"; + const string assetName3 = "Image 9_duplicate.png"; + const string assetName4 = "Image_11.heic"; string assetSourcePath1 = Path.Combine(sourceDirectory, assetName1); string assetSourcePath2 = Path.Combine(sourceDirectory, assetName2); @@ -1805,19 +1805,19 @@ public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDes finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDestinationAndSourceSubDirectoriesAreMultipleLevelAndIncludeSubFoldersIsTrue_StatusChangesAndImagesAreAdded() { - string sourceDirectory = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); + string sourceDirectory = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); string sourceSubDirectory1 = Path.Combine(sourceDirectory, "SubDirectory1"); string sourceSubDirectory2 = Path.Combine(sourceSubDirectory1, "SubDirectory2"); string sourceSubDirectory3 = Path.Combine(sourceDirectory, "SubDirectory3"); - string sourceToCopy = Path.Combine(dataDirectory!, "Duplicates\\Part"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); + string sourceToCopy = Path.Combine(_dataDirectory!, "Duplicates\\Part"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); string destinationSubDirectory1 = Path.Combine(destinationDirectory, "SubDirectory1"); string destinationSubDirectory2 = Path.Combine(destinationSubDirectory1, "SubDirectory2"); string destinationSubDirectory3 = Path.Combine(destinationDirectory, "SubDirectory3"); @@ -1829,12 +1829,12 @@ public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDes Directory.CreateDirectory(sourceSubDirectory2); Directory.CreateDirectory(sourceSubDirectory3); - string assetName1 = "Image 1_duplicate.jpg"; - string assetName2 = "Image 9.png"; - string assetName3 = "Image 9_duplicate.png"; - string assetName4 = "Image_11.heic"; - string assetName5 = "1336_BottomLeftPart.JPG"; - string assetName6 = "1336_TopRightPart.JPG"; + const string assetName1 = "Image 1_duplicate.jpg"; + const string assetName2 = "Image 9.png"; + const string assetName3 = "Image 9_duplicate.png"; + const string assetName4 = "Image_11.heic"; + const string assetName5 = "1336_BottomLeftPart.JPG"; + const string assetName6 = "1336_TopRightPart.JPG"; string assetSourcePath1 = Path.Combine(sourceDirectory, assetName1); string assetSourcePath2 = Path.Combine(sourceDirectory, assetName2); @@ -2013,16 +2013,16 @@ public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDes Directory.Delete(destinationDirectory, true); Directory.Delete(sourceSubDirectory1, true); Directory.Delete(sourceSubDirectory3, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDestinationAndDuplicatedAssetInSourceAndIncludeSubFoldersIsTrue_StatusChangesAndImagesAreAdded() { - string sourceDirectory = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); + string sourceDirectory = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); string sourceSubDirectory1 = Path.Combine(sourceDirectory, "SubDirectory1"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); string destinationSubDirectory1 = Path.Combine(destinationDirectory, "SubDirectory1"); try @@ -2030,10 +2030,10 @@ public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDes Directory.CreateDirectory(destinationDirectory); Directory.CreateDirectory(sourceSubDirectory1); - string assetName1 = "Image 1_duplicate.jpg"; - string assetName2 = "Image 9.png"; - string assetName3 = "Image 9_duplicate.png"; - string assetName4 = "Image_11.heic"; + const string assetName1 = "Image 1_duplicate.jpg"; + const string assetName2 = "Image 9.png"; + const string assetName3 = "Image 9_duplicate.png"; + const string assetName4 = "Image_11.heic"; string assetSourcePath1 = Path.Combine(sourceDirectory, assetName1); string assetSourcePath2 = Path.Combine(sourceDirectory, assetName2); @@ -2161,30 +2161,30 @@ public async Task ExecuteAsync_SourceAndDestinationAreNotEmptySomeImagesAreInDes { Directory.Delete(destinationDirectory, true); Directory.Delete(sourceSubDirectory1, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public async Task ExecuteAsync_SourceAndDestinationAreNotEmptyBothContainDifferentImagesAndDeleteAssetsNotInSourceIsTrue_StatusChangesAndImagesAreAdded() { - string sourceDirectory = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); - string destinationToCopy = Path.Combine(dataDirectory!, "Duplicates\\Thumbnail"); + string sourceDirectory = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); + string destinationToCopy = Path.Combine(_dataDirectory!, "Duplicates\\Thumbnail"); try { Directory.CreateDirectory(destinationDirectory); - string assetName1 = "Image 1_duplicate.jpg"; - string assetName2 = "Image 9.png"; - string assetName3 = "Image 9_duplicate.png"; - string assetName4 = "Image_11.heic"; + const string assetName1 = "Image 1_duplicate.jpg"; + const string assetName2 = "Image 9.png"; + const string assetName3 = "Image 9_duplicate.png"; + const string assetName4 = "Image_11.heic"; - string assetName5 = "Image_1336_Mini.JPG"; - string assetName6 = "Image_1336_Original.JPG"; - string assetName7 = "Image_1336_ShitQuality.JPG"; - string assetName8 = "Image_1336_Small.JPG"; + const string assetName5 = "Image_1336_Mini.JPG"; + const string assetName6 = "Image_1336_Original.JPG"; + const string assetName7 = "Image_1336_ShitQuality.JPG"; + const string assetName8 = "Image_1336_Small.JPG"; string assetSourcePath1 = Path.Combine(sourceDirectory, assetName1); string assetSourcePath2 = Path.Combine(sourceDirectory, assetName2); @@ -2311,24 +2311,24 @@ public async Task ExecuteAsync_SourceAndDestinationAreNotEmptyBothContainDiffere finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] - public async Task ExecuteAsync_SourceIsNotEmptyAndDestinationIsEmptyAndSyncAssetsConfigurationDefintionIsEmpty_NoStatusChangesAndNoImagesAreAdded() + public async Task ExecuteAsync_SourceIsNotEmptyAndDestinationIsEmptyAndSyncAssetsConfigurationDefinitionIsEmpty_NoStatusChangesAndNoImagesAreAdded() { - string sourceDirectory = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); + string sourceDirectory = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); try { Directory.CreateDirectory(destinationDirectory); - string assetName1 = "Image 1_duplicate.jpg"; - string assetName2 = "Image 9.png"; - string assetName3 = "Image 9_duplicate.png"; - string assetName4 = "Image_11.heic"; + const string assetName1 = "Image 1_duplicate.jpg"; + const string assetName2 = "Image 9.png"; + const string assetName3 = "Image 9_duplicate.png"; + const string assetName4 = "Image_11.heic"; string assetSourcePath1 = Path.Combine(sourceDirectory, assetName1); string assetSourcePath2 = Path.Combine(sourceDirectory, assetName2); @@ -2395,24 +2395,24 @@ public async Task ExecuteAsync_SourceIsNotEmptyAndDestinationIsEmptyAndSyncAsset finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] - public void ExecuteAsync_SourceIsNotEmptyAndDestinationIsEmptyAndSyncAssetsConfigurationDefintionIsNull_ThrowsNullReferenceException() + public void ExecuteAsync_SourceIsNotEmptyAndDestinationIsEmptyAndSyncAssetsConfigurationDefinitionIsNull_ThrowsNullReferenceException() { - string sourceDirectory = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); + string sourceDirectory = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); try { Directory.CreateDirectory(destinationDirectory); - string assetName1 = "Image 1_duplicate.jpg"; - string assetName2 = "Image 9.png"; - string assetName3 = "Image 9_duplicate.png"; - string assetName4 = "Image_11.heic"; + const string assetName1 = "Image 1_duplicate.jpg"; + const string assetName2 = "Image 9.png"; + const string assetName3 = "Image 9_duplicate.png"; + const string assetName4 = "Image_11.heic"; string assetSourcePath1 = Path.Combine(sourceDirectory, assetName1); string assetSourcePath2 = Path.Combine(sourceDirectory, assetName2); @@ -2462,24 +2462,24 @@ public void ExecuteAsync_SourceIsNotEmptyAndDestinationIsEmptyAndSyncAssetsConfi finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public async Task ExecuteAsync_SourceIsNotEmptyAndDestinationIsEmptyAndSyncAssetsConfigurationNotSaved_NoStatusChangesAndNoImagesAreAdded() { - string sourceDirectory = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); + string sourceDirectory = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); try { Directory.CreateDirectory(destinationDirectory); - string assetName1 = "Image 1_duplicate.jpg"; - string assetName2 = "Image 9.png"; - string assetName3 = "Image 9_duplicate.png"; - string assetName4 = "Image_11.heic"; + const string assetName1 = "Image 1_duplicate.jpg"; + const string assetName2 = "Image 9.png"; + const string assetName3 = "Image 9_duplicate.png"; + const string assetName4 = "Image_11.heic"; string assetSourcePath1 = Path.Combine(sourceDirectory, assetName1); string assetSourcePath2 = Path.Combine(sourceDirectory, assetName2); @@ -2543,24 +2543,24 @@ public async Task ExecuteAsync_SourceIsNotEmptyAndDestinationIsEmptyAndSyncAsset finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public void ExecuteAsync_SourceIsNotEmptyAndDestinationIsEmptyAndSyncAssetsConfigurationIsNull_ThrowsNullReferenceException() { - string sourceDirectory = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); + string sourceDirectory = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); try { Directory.CreateDirectory(destinationDirectory); - string assetName1 = "Image 1_duplicate.jpg"; - string assetName2 = "Image 9.png"; - string assetName3 = "Image 9_duplicate.png"; - string assetName4 = "Image_11.heic"; + const string assetName1 = "Image 1_duplicate.jpg"; + const string assetName2 = "Image 9.png"; + const string assetName3 = "Image 9_duplicate.png"; + const string assetName4 = "Image_11.heic"; string assetSourcePath1 = Path.Combine(sourceDirectory, assetName1); string assetSourcePath2 = Path.Combine(sourceDirectory, assetName2); @@ -2606,15 +2606,15 @@ public void ExecuteAsync_SourceIsNotEmptyAndDestinationIsEmptyAndSyncAssetsConfi finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public async Task ExecuteAsync_SourceDirectoryDoesNotExist_NoStatusChangesAndNoImagesAreAdded() { - string sourceDirectory = Path.Combine(dataDirectory!, "SourceToSync"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); + string sourceDirectory = Path.Combine(_dataDirectory!, "SourceToSync"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); try { @@ -2652,7 +2652,7 @@ public async Task ExecuteAsync_SourceDirectoryDoesNotExist_NoStatusChangesAndNoI finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } @@ -2660,7 +2660,7 @@ public async Task ExecuteAsync_SourceDirectoryDoesNotExist_NoStatusChangesAndNoI public async Task ExecuteAsync_SourceDirectoryIsNull_NoStatusChangesAndNoImagesAreAdded() { string? sourceDirectory = null; - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); try { @@ -2698,22 +2698,22 @@ public async Task ExecuteAsync_SourceDirectoryIsNull_NoStatusChangesAndNoImagesA finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public async Task ExecuteAsync_SourceIsNotEmptyAndDestinationDirectoryDoesNotExist_StatusChangesAndImagesAreAdded() { - string sourceDirectory = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); - string destinationDirectory = Path.Combine(dataDirectory!, "DestinationToSync"); + string sourceDirectory = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); + string destinationDirectory = Path.Combine(_dataDirectory!, "DestinationToSync"); try { - string assetName1 = "Image 1_duplicate.jpg"; - string assetName2 = "Image 9.png"; - string assetName3 = "Image 9_duplicate.png"; - string assetName4 = "Image_11.heic"; + const string assetName1 = "Image 1_duplicate.jpg"; + const string assetName2 = "Image 9.png"; + const string assetName3 = "Image 9_duplicate.png"; + const string assetName4 = "Image_11.heic"; string assetSourcePath1 = Path.Combine(sourceDirectory, assetName1); string assetSourcePath2 = Path.Combine(sourceDirectory, assetName2); @@ -2799,22 +2799,22 @@ public async Task ExecuteAsync_SourceIsNotEmptyAndDestinationDirectoryDoesNotExi finally { Directory.Delete(destinationDirectory, true); - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } [Test] public async Task ExecuteAsync_SourceIsNotEmptyAndDestinationDirectoryIsNull_NoStatusChangesAndNoImagesAreAdded() { - string sourceDirectory = Path.Combine(dataDirectory!, "Duplicates\\NewFolder2"); + string sourceDirectory = Path.Combine(_dataDirectory!, "Duplicates\\NewFolder2"); string? destinationDirectory = null; try { - string assetName1 = "Image 1_duplicate.jpg"; - string assetName2 = "Image 9.png"; - string assetName3 = "Image 9_duplicate.png"; - string assetName4 = "Image_11.heic"; + const string assetName1 = "Image 1_duplicate.jpg"; + const string assetName2 = "Image 9.png"; + const string assetName3 = "Image 9_duplicate.png"; + const string assetName4 = "Image_11.heic"; string assetSourcePath1 = Path.Combine(sourceDirectory, assetName1); string assetSourcePath2 = Path.Combine(sourceDirectory, assetName2); @@ -2878,7 +2878,7 @@ public async Task ExecuteAsync_SourceIsNotEmptyAndDestinationDirectoryIsNull_NoS } finally { - Directory.Delete(databasePath!, true); + Directory.Delete(_databasePath!, true); } } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryAddAssetTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryAddAssetTests.cs index 325f77ce..6e802a88 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryAddAssetTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryAddAssetTests.cs @@ -5,29 +5,30 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositoryAddAssetTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; + private TestableAssetRepository? _testableAssetRepository; private PhotoManager.Infrastructure.Database.Database? _database; private Mock? _storageServiceMock; private Mock? _configurationRootMock; - private Asset? asset1; - private Asset? asset2; + private Asset? _asset1; + private Asset? _asset2; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -37,8 +38,9 @@ public void SetUp() UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); _testableAssetRepository = new (_database, _storageServiceMock!.Object, userConfigurationService); - asset1 = new() + _asset1 = new() { + Folder = new() { Path = "" }, FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), FileName = "Image 1.jpg", FileSize = 363888, @@ -54,8 +56,9 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset2 = new() + _asset2 = new() { + Folder = new() { Path = "" }, FolderId = new Guid("68493435-e299-4bb5-9e02-214da41d0256"), FileName = "Image 9.png", FileSize = 4602393, @@ -76,21 +79,21 @@ public void SetUp() [Test] public void AddAsset_FolderAndThumbnailsExist_AssetIsAddedAndAssetsUpdatedIsUpdated() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); Folder folder1 = _testableAssetRepository!.AddFolder(folderPath); Folder folder2 = new() { Path = folderPath }; - asset1!.Folder = folder1; - asset1!.FolderId = folder1.FolderId; - byte[] assetData1 = new byte[] { 1, 2, 3 }; + _asset1!.Folder = folder1; + _asset1!.FolderId = folder1.FolderId; + byte[] assetData1 = [1, 2, 3]; - asset2!.Folder = folder2; - byte[] assetData2 = Array.Empty(); + _asset2!.Folder = folder2; + byte[] assetData2 = []; List assets = _testableAssetRepository!.GetCataloguedAssets(); Assert.IsEmpty(assets); @@ -98,23 +101,23 @@ public void AddAsset_FolderAndThumbnailsExist_AssetIsAddedAndAssetsUpdatedIsUpda Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - _testableAssetRepository.AddAsset(asset1!, assetData1); // Just to make the thumbnail exists for this path - _testableAssetRepository.AddAsset(asset2!, assetData2); + _testableAssetRepository.AddAsset(_asset1!, assetData1); // Just to make the thumbnail exists for this path + _testableAssetRepository.AddAsset(_asset2!, assetData2); Assert.IsTrue(_testableAssetRepository.HasChanges()); Assert.AreEqual(2, assets.Count); - Assert.AreEqual(asset1.FileName, assets[0].FileName); - Assert.AreEqual(asset2!.FileName, assets[1].FileName); + Assert.AreEqual(_asset1.FileName, assets[0].FileName); + Assert.AreEqual(_asset2!.FileName, assets[1].FileName); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(asset1!.Folder.Path)); - Assert.IsTrue(thumbnails.ContainsKey(asset2!.Folder.Path)); + Assert.IsTrue(thumbnails.ContainsKey(_asset1!.Folder.Path)); + Assert.IsTrue(thumbnails.ContainsKey(_asset2!.Folder.Path)); Assert.AreEqual(2, thumbnails[folderPath].Count); - Assert.IsTrue(thumbnails[folderPath].ContainsKey(asset1.FileName)); - Assert.IsTrue(thumbnails[folderPath].ContainsKey(asset2.FileName)); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath][asset1.FileName]); - Assert.AreEqual(Array.Empty(), thumbnails[folderPath][asset2.FileName]); + Assert.IsTrue(thumbnails[folderPath].ContainsKey(_asset1.FileName)); + Assert.IsTrue(thumbnails[folderPath].ContainsKey(_asset2.FileName)); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath][_asset1.FileName]); + Assert.AreEqual(Array.Empty(), thumbnails[folderPath][_asset2.FileName]); Assert.AreEqual(2, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); @@ -122,7 +125,7 @@ public void AddAsset_FolderAndThumbnailsExist_AssetIsAddedAndAssetsUpdatedIsUpda } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -130,21 +133,21 @@ public void AddAsset_FolderAndThumbnailsExist_AssetIsAddedAndAssetsUpdatedIsUpda [Test] public void AddAsset_FolderDoesNotExist_AssetIsAddedAndAssetsUpdatedIsUpdated() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); Folder folder1 = new() { Path = folderPath }; Folder folder2 = new() { Path = folderPath }; - asset1!.Folder = folder1; - asset1!.FolderId = folder1.FolderId; - byte[] assetData1 = new byte[] { 1, 2, 3 }; + _asset1!.Folder = folder1; + _asset1!.FolderId = folder1.FolderId; + byte[] assetData1 = [1, 2, 3]; - asset2!.Folder = folder2; - byte[] assetData2 = Array.Empty(); + _asset2!.Folder = folder2; + byte[] assetData2 = []; List assets = _testableAssetRepository!.GetCataloguedAssets(); Assert.IsEmpty(assets); @@ -152,23 +155,23 @@ public void AddAsset_FolderDoesNotExist_AssetIsAddedAndAssetsUpdatedIsUpdated() Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - _testableAssetRepository.AddAsset(asset1!, assetData1); // Just to make the thumbnail exists for this path - _testableAssetRepository.AddAsset(asset2!, assetData2); + _testableAssetRepository.AddAsset(_asset1!, assetData1); // Just to make the thumbnail exists for this path + _testableAssetRepository.AddAsset(_asset2!, assetData2); Assert.IsTrue(_testableAssetRepository.HasChanges()); Assert.AreEqual(2, assets.Count); - Assert.AreEqual(asset1.FileName, assets[0].FileName); - Assert.AreEqual(asset2!.FileName, assets[1].FileName); + Assert.AreEqual(_asset1.FileName, assets[0].FileName); + Assert.AreEqual(_asset2!.FileName, assets[1].FileName); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(asset1!.Folder.Path)); - Assert.IsTrue(thumbnails.ContainsKey(asset2!.Folder.Path)); + Assert.IsTrue(thumbnails.ContainsKey(_asset1!.Folder.Path)); + Assert.IsTrue(thumbnails.ContainsKey(_asset2!.Folder.Path)); Assert.AreEqual(2, thumbnails[folderPath].Count); - Assert.IsTrue(thumbnails[folderPath].ContainsKey(asset1.FileName)); - Assert.IsTrue(thumbnails[folderPath].ContainsKey(asset2.FileName)); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath][asset1.FileName]); - Assert.AreEqual(Array.Empty(), thumbnails[folderPath][asset2.FileName]); + Assert.IsTrue(thumbnails[folderPath].ContainsKey(_asset1.FileName)); + Assert.IsTrue(thumbnails[folderPath].ContainsKey(_asset2.FileName)); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath][_asset1.FileName]); + Assert.AreEqual(Array.Empty(), thumbnails[folderPath][_asset2.FileName]); Assert.AreEqual(2, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); @@ -176,7 +179,7 @@ public void AddAsset_FolderDoesNotExist_AssetIsAddedAndAssetsUpdatedIsUpdated() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -184,16 +187,16 @@ public void AddAsset_FolderDoesNotExist_AssetIsAddedAndAssetsUpdatedIsUpdated() [Test] public void AddAsset_ThumbnailDoesNotExist_AssetIsAddedAndAssetsUpdatedIsUpdated() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); Folder folder = _testableAssetRepository!.AddFolder(folderPath); - asset1!.Folder = folder; - asset1!.FolderId = folder.FolderId; - byte[] assetData = new byte[] { 1, 2, 3 }; + _asset1!.Folder = folder; + _asset1!.FolderId = folder.FolderId; + byte[] assetData = [1, 2, 3]; List assets = _testableAssetRepository!.GetCataloguedAssets(); Assert.IsEmpty(assets); @@ -201,25 +204,25 @@ public void AddAsset_ThumbnailDoesNotExist_AssetIsAddedAndAssetsUpdatedIsUpdated Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - _testableAssetRepository.AddAsset(asset1!, assetData); + _testableAssetRepository.AddAsset(_asset1!, assetData); Assert.IsTrue(_testableAssetRepository.HasChanges()); Assert.AreEqual(1, assets.Count); - Assert.AreEqual(asset1.FileName, assets[0].FileName); + Assert.AreEqual(_asset1.FileName, assets[0].FileName); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(asset1!.Folder.Path)); - Assert.AreEqual(1, thumbnails[asset1!.Folder.Path].Count); - Assert.IsTrue(thumbnails[asset1!.Folder.Path].ContainsKey(asset1.FileName)); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[asset1!.Folder.Path][asset1.FileName]); + Assert.IsTrue(thumbnails.ContainsKey(_asset1!.Folder.Path)); + Assert.AreEqual(1, thumbnails[_asset1!.Folder.Path].Count); + Assert.IsTrue(thumbnails[_asset1!.Folder.Path].ContainsKey(_asset1.FileName)); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[_asset1!.Folder.Path][_asset1.FileName]); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -227,21 +230,21 @@ public void AddAsset_ThumbnailDoesNotExist_AssetIsAddedAndAssetsUpdatedIsUpdated [Test] public void AddAsset_ThumbnailDoesNotExistButBinExists_AssetIsAddedAndAssetsUpdatedIsUpdated() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); Folder folder = _testableAssetRepository!.AddFolder(folderPath); - asset1!.Folder = folder; - asset1!.FolderId = folder.FolderId; - byte[] assetData = new byte[] { 1, 2, 3 }; + _asset1!.Folder = folder; + _asset1!.FolderId = folder.FolderId; + byte[] assetData = [1, 2, 3]; Dictionary blobToWrite = new() { - { asset1!.FileName, new byte[] { 1, 2, 3 } }, - { asset2!.FileName, Array.Empty() } + { _asset1!.FileName, [1, 2, 3]}, + { _asset2!.FileName, [] } }; _database!.WriteBlob(blobToWrite, folder.ThumbnailsFilename); @@ -252,27 +255,27 @@ public void AddAsset_ThumbnailDoesNotExistButBinExists_AssetIsAddedAndAssetsUpda Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - _testableAssetRepository.AddAsset(asset1!, assetData); + _testableAssetRepository.AddAsset(_asset1!, assetData); Assert.IsTrue(_testableAssetRepository.HasChanges()); Assert.AreEqual(1, assets.Count); - Assert.AreEqual(asset1.FileName, assets[0].FileName); + Assert.AreEqual(_asset1.FileName, assets[0].FileName); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(asset1!.Folder.Path)); + Assert.IsTrue(thumbnails.ContainsKey(_asset1!.Folder.Path)); Assert.AreEqual(2, thumbnails[folderPath].Count); - Assert.IsTrue(thumbnails[folderPath].ContainsKey(asset1.FileName)); - Assert.IsTrue(thumbnails[folderPath].ContainsKey(asset2.FileName)); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath][asset1.FileName]); - Assert.AreEqual(Array.Empty(), thumbnails[folderPath][asset2.FileName]); + Assert.IsTrue(thumbnails[folderPath].ContainsKey(_asset1.FileName)); + Assert.IsTrue(thumbnails[folderPath].ContainsKey(_asset2.FileName)); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath][_asset1.FileName]); + Assert.AreEqual(Array.Empty(), thumbnails[folderPath][_asset2.FileName]); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -287,16 +290,16 @@ public void AddAsset_ThumbnailsDictionaryEntriesToKeepIs0_AssetIsNotAddedAndAsse UserConfigurationService userConfigurationService = new (configurationRootMock.Object); TestableAssetRepository testableAssetRepository = new (_database!, _storageServiceMock!.Object, userConfigurationService); - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = testableAssetRepository.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); Folder folder = testableAssetRepository.AddFolder(folderPath); - asset1!.Folder = folder; - asset1!.FolderId = folder.FolderId; - byte[] assetData = new byte[] { 1, 2, 3 }; + _asset1!.Folder = folder; + _asset1!.FolderId = folder.FolderId; + byte[] assetData = [1, 2, 3]; List assets = testableAssetRepository.GetCataloguedAssets(); Assert.IsEmpty(assets); @@ -304,7 +307,7 @@ public void AddAsset_ThumbnailsDictionaryEntriesToKeepIs0_AssetIsNotAddedAndAsse Dictionary> thumbnails = testableAssetRepository.GetThumbnails(); Assert.IsEmpty(thumbnails); - testableAssetRepository.AddAsset(asset1!, assetData); + testableAssetRepository.AddAsset(_asset1!, assetData); Assert.IsTrue(testableAssetRepository.HasChanges()); // Due to AddFolder() Assert.IsEmpty(assets); @@ -314,7 +317,7 @@ public void AddAsset_ThumbnailsDictionaryEntriesToKeepIs0_AssetIsNotAddedAndAsse } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -322,16 +325,16 @@ public void AddAsset_ThumbnailsDictionaryEntriesToKeepIs0_AssetIsNotAddedAndAsse [Test] public void AddAsset_FolderAndThumbnailsDoNotExist_AssetIsAddedAndAssetsUpdatedIsUpdated() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); Folder folder = new() { Path = folderPath }; - asset1!.Folder = folder; - asset1!.FolderId = folder.FolderId; - byte[] assetData = new byte[] { 1, 2, 3 }; + _asset1!.Folder = folder; + _asset1!.FolderId = folder.FolderId; + byte[] assetData = [1, 2, 3]; List assets = _testableAssetRepository!.GetCataloguedAssets(); Assert.IsEmpty(assets); @@ -339,25 +342,25 @@ public void AddAsset_FolderAndThumbnailsDoNotExist_AssetIsAddedAndAssetsUpdatedI Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - _testableAssetRepository.AddAsset(asset1!, assetData); + _testableAssetRepository.AddAsset(_asset1!, assetData); Assert.IsTrue(_testableAssetRepository.HasChanges()); Assert.AreEqual(1, assets.Count); - Assert.AreEqual(asset1.FileName, assets[0].FileName); + Assert.AreEqual(_asset1.FileName, assets[0].FileName); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(asset1!.Folder.Path)); - Assert.AreEqual(1, thumbnails[asset1!.Folder.Path].Count); - Assert.IsTrue(thumbnails[asset1!.Folder.Path].ContainsKey(asset1.FileName)); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[asset1!.Folder.Path][asset1.FileName]); + Assert.IsTrue(thumbnails.ContainsKey(_asset1!.Folder.Path)); + Assert.AreEqual(1, thumbnails[_asset1!.Folder.Path].Count); + Assert.IsTrue(thumbnails[_asset1!.Folder.Path].ContainsKey(_asset1.FileName)); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[_asset1!.Folder.Path][_asset1.FileName]); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -365,12 +368,12 @@ public void AddAsset_FolderAndThumbnailsDoNotExist_AssetIsAddedAndAssetsUpdatedI [Test] public void AddAsset_AssetFolderIsNull_AssetIsNotAddedAndAssetsUpdatedIsNotUpdated() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - byte[] assetData = new byte[] { 1, 2, 3 }; + byte[] assetData = [1, 2, 3]; List assets = _testableAssetRepository!.GetCataloguedAssets(); Assert.IsEmpty(assets); @@ -378,7 +381,7 @@ public void AddAsset_AssetFolderIsNull_AssetIsNotAddedAndAssetsUpdatedIsNotUpdat Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - _testableAssetRepository.AddAsset(asset1!, assetData); + _testableAssetRepository.AddAsset(_asset1!, assetData); Assert.IsFalse(_testableAssetRepository.HasChanges()); Assert.IsEmpty(assets); @@ -388,7 +391,7 @@ public void AddAsset_AssetFolderIsNull_AssetIsNotAddedAndAssetsUpdatedIsNotUpdat } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -396,13 +399,13 @@ public void AddAsset_AssetFolderIsNull_AssetIsNotAddedAndAssetsUpdatedIsNotUpdat [Test] public void AddAsset_AssetIsNull_ThrowsNullReferenceExceptionAndAssetsUpdatedIsNotUpdated() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { Asset? asset = null; - byte[] assetData = new byte[] { 1, 2, 3 }; + byte[] assetData = [1, 2, 3]; List assets = _testableAssetRepository!.GetCataloguedAssets(); Assert.IsEmpty(assets); @@ -421,7 +424,7 @@ public void AddAsset_AssetIsNull_ThrowsNullReferenceExceptionAndAssetsUpdatedIsN } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -429,15 +432,15 @@ public void AddAsset_AssetIsNull_ThrowsNullReferenceExceptionAndAssetsUpdatedIsN [Test] public void AddAsset_ThumbnailDataIsNull_AssetIsAddedAndAssetsUpdatedIsUpdated() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); Folder folder = _testableAssetRepository!.AddFolder(folderPath); - asset1!.Folder = folder; - asset1!.FolderId = folder.FolderId; + _asset1!.Folder = folder; + _asset1!.FolderId = folder.FolderId; byte[]? assetData = null; List assets = _testableAssetRepository!.GetCataloguedAssets(); @@ -446,25 +449,25 @@ public void AddAsset_ThumbnailDataIsNull_AssetIsAddedAndAssetsUpdatedIsUpdated() Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - _testableAssetRepository.AddAsset(asset1!, assetData!); + _testableAssetRepository.AddAsset(_asset1!, assetData!); Assert.IsTrue(_testableAssetRepository.HasChanges()); Assert.AreEqual(1, assets.Count); - Assert.AreEqual(asset1.FileName, assets[0].FileName); + Assert.AreEqual(_asset1.FileName, assets[0].FileName); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(asset1!.Folder.Path)); - Assert.AreEqual(1, thumbnails[asset1!.Folder.Path].Count); - Assert.IsTrue(thumbnails[asset1!.Folder.Path].ContainsKey(asset1.FileName)); - Assert.AreEqual(null, thumbnails[asset1!.Folder.Path][asset1.FileName]); + Assert.IsTrue(thumbnails.ContainsKey(_asset1!.Folder.Path)); + Assert.AreEqual(1, thumbnails[_asset1!.Folder.Path].Count); + Assert.IsTrue(thumbnails[_asset1!.Folder.Path].ContainsKey(_asset1.FileName)); + Assert.AreEqual(null, thumbnails[_asset1!.Folder.Path][_asset1.FileName]); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -472,21 +475,21 @@ public void AddAsset_ThumbnailDataIsNull_AssetIsAddedAndAssetsUpdatedIsUpdated() [Test] public void AddAsset_ConcurrentAccess_AssetsAreHandledSafelyAndAssetsUpdatedIsUpdated() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); Folder folder1 = _testableAssetRepository!.AddFolder(folderPath); Folder folder2 = new() { Path = folderPath }; - asset1!.Folder = folder1; - asset1!.FolderId = folder1.FolderId; - byte[] assetData1 = new byte[] { 1, 2, 3 }; + _asset1!.Folder = folder1; + _asset1!.FolderId = folder1.FolderId; + byte[] assetData1 = [1, 2, 3]; - asset2!.Folder = folder2; - byte[] assetData2 = Array.Empty(); + _asset2!.Folder = folder2; + byte[] assetData2 = []; List assets = _testableAssetRepository!.GetCataloguedAssets(); Assert.IsEmpty(assets); @@ -496,24 +499,24 @@ public void AddAsset_ConcurrentAccess_AssetsAreHandledSafelyAndAssetsUpdatedIsUp // Simulate concurrent access Parallel.Invoke( - () => _testableAssetRepository.AddAsset(asset1!, assetData1), - () => _testableAssetRepository.AddAsset(asset2!, assetData2) + () => _testableAssetRepository.AddAsset(_asset1!, assetData1), + () => _testableAssetRepository.AddAsset(_asset2!, assetData2) ); Assert.IsTrue(_testableAssetRepository.HasChanges()); Assert.AreEqual(2, assets.Count); - Assert.IsTrue(assets.Any(x => x.FileName == asset1.FileName)); - Assert.IsTrue(assets.Any(x => x.FileName == asset2.FileName)); + Assert.IsTrue(assets.Any(x => x.FileName == _asset1.FileName)); + Assert.IsTrue(assets.Any(x => x.FileName == _asset2.FileName)); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(asset1!.Folder.Path)); - Assert.IsTrue(thumbnails.ContainsKey(asset2!.Folder.Path)); + Assert.IsTrue(thumbnails.ContainsKey(_asset1!.Folder.Path)); + Assert.IsTrue(thumbnails.ContainsKey(_asset2!.Folder.Path)); Assert.AreEqual(2, thumbnails[folderPath].Count); - Assert.IsTrue(thumbnails[folderPath].ContainsKey(asset1.FileName)); - Assert.IsTrue(thumbnails[folderPath].ContainsKey(asset2.FileName)); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath][asset1.FileName]); - Assert.AreEqual(Array.Empty(), thumbnails[folderPath][asset2.FileName]); + Assert.IsTrue(thumbnails[folderPath].ContainsKey(_asset1.FileName)); + Assert.IsTrue(thumbnails[folderPath].ContainsKey(_asset2.FileName)); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath][_asset1.FileName]); + Assert.AreEqual(Array.Empty(), thumbnails[folderPath][_asset2.FileName]); Assert.AreEqual(2, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); @@ -521,7 +524,7 @@ public void AddAsset_ConcurrentAccess_AssetsAreHandledSafelyAndAssetsUpdatedIsUp } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryAddFolderTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryAddFolderTests.cs index b950e07a..2854e1dc 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryAddFolderTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryAddFolderTests.cs @@ -5,26 +5,26 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositoryAddFolderTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; - private readonly Guid defaultGuid = Guid.Empty; + private string? _dataDirectory; + private string? _backupPath; + private readonly Guid _defaultGuid = Guid.Empty; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; - private IAssetRepository? _assetRepository; + private AssetRepository? _assetRepository; private Mock? _storageServiceMock; private Mock? _configurationRootMock; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -32,28 +32,28 @@ public void SetUp() { PhotoManager.Infrastructure.Database.Database database = new (new ObjectListStorage(), new BlobStorage(), new BackupStorage()); UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); - _assetRepository = new AssetRepository(database, _storageServiceMock!.Object, userConfigurationService); + _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); } [Test] public void AddFolder_DifferentPaths_AddsFoldersToList() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "TestFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "TestFolder2"); Folder addedFolder1 = _assetRepository!.AddFolder(folderPath1); Folder addedFolder2 = _assetRepository!.AddFolder(folderPath2); Assert.AreEqual(folderPath1, addedFolder1.Path); - Assert.IsFalse(addedFolder1.FolderId == defaultGuid); + Assert.IsFalse(addedFolder1.FolderId == _defaultGuid); Assert.AreEqual(folderPath2, addedFolder2.Path); - Assert.IsFalse(addedFolder2.FolderId == defaultGuid); + Assert.IsFalse(addedFolder2.FolderId == _defaultGuid); Assert.AreNotEqual(addedFolder1.Path, addedFolder2.Path); Assert.AreNotEqual(addedFolder1.FolderId, addedFolder2.FolderId); @@ -84,7 +84,7 @@ public void AddFolder_DifferentPaths_AddsFoldersToList() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -92,21 +92,21 @@ public void AddFolder_DifferentPaths_AddsFoldersToList() [Test] public void AddFolder_SamePath_AddsFoldersToList() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); Folder addedFolder1 = _assetRepository!.AddFolder(folderPath1); Folder addedFolder2 = _assetRepository!.AddFolder(folderPath1); Assert.AreEqual(folderPath1, addedFolder1.Path); - Assert.IsFalse(addedFolder1.FolderId == defaultGuid); + Assert.IsFalse(addedFolder1.FolderId == _defaultGuid); Assert.AreEqual(folderPath1, addedFolder2.Path); - Assert.IsFalse(addedFolder2.FolderId == defaultGuid); + Assert.IsFalse(addedFolder2.FolderId == _defaultGuid); Assert.AreEqual(addedFolder1.Path, addedFolder2.Path); Assert.AreNotEqual(addedFolder1.FolderId, addedFolder2.FolderId); @@ -137,7 +137,7 @@ public void AddFolder_SamePath_AddsFoldersToList() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -145,16 +145,16 @@ public void AddFolder_SamePath_AddsFoldersToList() [Test] public void AddFolder_ConcurrentAccess_FoldersAreHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "TestFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "TestFolder2"); - Folder addedFolder1 = new() { Path = dataDirectory! }; - Folder addedFolder2 = new() { Path = dataDirectory! }; + Folder addedFolder1 = new() { Path = _dataDirectory! }; + Folder addedFolder2 = new() { Path = _dataDirectory! }; // Simulate concurrent access Parallel.Invoke( @@ -163,10 +163,10 @@ public void AddFolder_ConcurrentAccess_FoldersAreHandledSafely() ); Assert.AreEqual(folderPath1, addedFolder1.Path); - Assert.IsFalse(addedFolder1.FolderId == defaultGuid); + Assert.IsFalse(addedFolder1.FolderId == _defaultGuid); Assert.AreEqual(folderPath2, addedFolder2.Path); - Assert.IsFalse(addedFolder2.FolderId == defaultGuid); + Assert.IsFalse(addedFolder2.FolderId == _defaultGuid); Assert.AreNotEqual(addedFolder1.Path, addedFolder2.Path); Assert.AreNotEqual(addedFolder1.FolderId, addedFolder2.FolderId); @@ -201,7 +201,7 @@ public void AddFolder_ConcurrentAccess_FoldersAreHandledSafely() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryBackupExistsTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryBackupExistsTests.cs index 67f2387e..b25001f4 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryBackupExistsTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryBackupExistsTests.cs @@ -5,25 +5,25 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositoryBackupExistsTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; + private string? _backupPath; - private IAssetRepository? _assetRepository; + private AssetRepository? _assetRepository; private Mock? _storageServiceMock; private Mock? _configurationRootMock; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -31,13 +31,13 @@ public void SetUp() { PhotoManager.Infrastructure.Database.Database database = new (new ObjectListStorage(), new BlobStorage(), new BackupStorage()); UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); - _assetRepository = new AssetRepository(database, _storageServiceMock!.Object, userConfigurationService); + _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); } [Test] public void BackupExists_BackupExists_ReturnsTrue() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -50,7 +50,7 @@ public void BackupExists_BackupExists_ReturnsTrue() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -58,7 +58,7 @@ public void BackupExists_BackupExists_ReturnsTrue() [Test] public void BackupExists_BackupDoesNotExist_ReturnsTrue() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -69,7 +69,7 @@ public void BackupExists_BackupDoesNotExist_ReturnsTrue() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -77,7 +77,7 @@ public void BackupExists_BackupDoesNotExist_ReturnsTrue() [Test] public void BackupExists_ConcurrentAccess_CheckExistenceIsHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -103,7 +103,7 @@ public void BackupExists_ConcurrentAccess_CheckExistenceIsHandledSafely() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryConcurrentAccessTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryConcurrentAccessTests.cs index edc969a9..d4ccb37f 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryConcurrentAccessTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryConcurrentAccessTests.cs @@ -44,6 +44,7 @@ public void SetUp() _asset1 = new() { FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "Image 1.jpg", FileSize = 363888, ImageRotation = Rotation.Rotate0, @@ -61,6 +62,7 @@ public void SetUp() _asset2 = new() { FolderId = new Guid("68493435-e299-4bb5-9e02-214da41d0256"), + Folder = new() { Path = "" }, FileName = "Image 9.png", FileSize = 4602393, ImageRotation = Rotation.Rotate90, @@ -78,6 +80,7 @@ public void SetUp() _asset3 = new() { FolderId = new Guid("f91b8c81-6938-431a-a689-d86c7c4db126"), + Folder = new() { Path = "" }, FileName = "Image_11.heic", FileSize = 2247285, ImageRotation = Rotation.Rotate0, @@ -100,6 +103,7 @@ public void AssetRepository_ConcurrentAccess_WorksCorrectly() Asset asset4 = new() { FolderId = new Guid("cf9293ad-d835-4126-8a76-17c7bbfe626e"), + Folder = new() { Path = "" }, FileName = "Image 2.jpg", FileSize = 2247285, ImageRotation = Rotation.Rotate0, @@ -117,6 +121,7 @@ public void AssetRepository_ConcurrentAccess_WorksCorrectly() Asset asset5 = new() { FolderId = new Guid("1e3c2274-bc11-482a-a7b4-e86e5aeb17f1"), + Folder = new() { Path = "" }, FileName = "Image 3.jpg", FileSize = 2247285, ImageRotation = Rotation.Rotate0, @@ -132,7 +137,7 @@ public void AssetRepository_ConcurrentAccess_WorksCorrectly() IsAssetRotated = true }; - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryContainsThumbnailTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryContainsThumbnailTests.cs index 638cc9cb..1fd05f0e 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryContainsThumbnailTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryContainsThumbnailTests.cs @@ -5,28 +5,29 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositoryContainsThumbnailTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; + private TestableAssetRepository? _testableAssetRepository; private PhotoManager.Infrastructure.Database.Database? _database; private Mock? _storageServiceMock; private Mock? _configurationRootMock; - private Asset? asset1; + private Asset? _asset1; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -36,9 +37,10 @@ public void SetUp() UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); _testableAssetRepository = new (_database, _storageServiceMock!.Object, userConfigurationService); - asset1 = new() + _asset1 = new() { FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "Image 1.jpg", FileSize = 363888, ImageRotation = Rotation.Rotate0, @@ -58,23 +60,23 @@ public void SetUp() [Test] public void ContainsThumbnail_ThumbnailsExistInRepository_ReturnsTrue() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); Folder folder = _testableAssetRepository!.AddFolder(folderPath); - asset1!.Folder = folder; - asset1!.FolderId = folder.FolderId; - _testableAssetRepository!.AddAsset(asset1!, Array.Empty()); + _asset1!.Folder = folder; + _asset1!.FolderId = folder.FolderId; + _testableAssetRepository!.AddAsset(_asset1!, []); Assert.IsTrue(_testableAssetRepository.HasChanges()); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); - bool isContainingThumbnail = _testableAssetRepository!.ContainsThumbnail(asset1!.Folder.Path, asset1!.FileName); + bool isContainingThumbnail = _testableAssetRepository!.ContainsThumbnail(_asset1!.Folder.Path, _asset1!.FileName); Assert.IsTrue(isContainingThumbnail); @@ -83,7 +85,7 @@ public void ContainsThumbnail_ThumbnailsExistInRepository_ReturnsTrue() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -91,16 +93,16 @@ public void ContainsThumbnail_ThumbnailsExistInRepository_ReturnsTrue() [Test] public void ContainsThumbnail_ConcurrentAccess_ThumbnailsAreHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); Folder folder = _testableAssetRepository!.AddFolder(folderPath); - asset1!.Folder = folder; - asset1!.FolderId = folder.FolderId; - _testableAssetRepository!.AddAsset(asset1!, Array.Empty()); + _asset1!.Folder = folder; + _asset1!.FolderId = folder.FolderId; + _testableAssetRepository!.AddAsset(_asset1!, []); Assert.IsTrue(_testableAssetRepository.HasChanges()); @@ -113,9 +115,9 @@ public void ContainsThumbnail_ConcurrentAccess_ThumbnailsAreHandledSafely() // Simulate concurrent access Parallel.Invoke( - () => isContainingThumbnail1 = _testableAssetRepository!.ContainsThumbnail(asset1!.Folder.Path, asset1!.FileName), - () => isContainingThumbnail2 = _testableAssetRepository!.ContainsThumbnail(asset1!.Folder.Path, asset1!.FileName), - () => isContainingThumbnail3 = _testableAssetRepository!.ContainsThumbnail(asset1!.Folder.Path, asset1!.FileName) + () => isContainingThumbnail1 = _testableAssetRepository!.ContainsThumbnail(_asset1!.Folder.Path, _asset1!.FileName), + () => isContainingThumbnail2 = _testableAssetRepository!.ContainsThumbnail(_asset1!.Folder.Path, _asset1!.FileName), + () => isContainingThumbnail3 = _testableAssetRepository!.ContainsThumbnail(_asset1!.Folder.Path, _asset1!.FileName) ); Assert.IsTrue(isContainingThumbnail1); @@ -127,7 +129,7 @@ public void ContainsThumbnail_ConcurrentAccess_ThumbnailsAreHandledSafely() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -135,29 +137,29 @@ public void ContainsThumbnail_ConcurrentAccess_ThumbnailsAreHandledSafely() [Test] public void ContainsThumbnail_FolderDoesNotExistButAdded_ReturnsTrue() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); Folder folder = new() { Path = folderPath, FolderId = Guid.NewGuid(), }; - asset1!.Folder = folder; - asset1!.FolderId = folder.FolderId; + _asset1!.Folder = folder; + _asset1!.FolderId = folder.FolderId; - _testableAssetRepository!.AddAsset(asset1!, Array.Empty()); + _testableAssetRepository!.AddAsset(_asset1!, []); Assert.IsTrue(_testableAssetRepository.HasChanges()); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); - bool isContainingThumbnail = _testableAssetRepository!.ContainsThumbnail(asset1!.Folder.Path, asset1!.FileName); + bool isContainingThumbnail = _testableAssetRepository!.ContainsThumbnail(_asset1!.Folder.Path, _asset1!.FileName); Assert.IsTrue(isContainingThumbnail); @@ -166,7 +168,7 @@ public void ContainsThumbnail_FolderDoesNotExistButAdded_ReturnsTrue() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -174,37 +176,37 @@ public void ContainsThumbnail_FolderDoesNotExistButAdded_ReturnsTrue() [Test] public void ContainsThumbnail_FolderDoesNotExist_ReturnsFalse() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); Folder folder = new() { Path = folderPath, FolderId = Guid.NewGuid(), }; - asset1!.Folder = folder; - asset1!.FolderId = folder.FolderId; + _asset1!.Folder = folder; + _asset1!.FolderId = folder.FolderId; Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - Assert.IsFalse(thumbnails.ContainsKey(asset1!.Folder.Path)); + Assert.IsFalse(thumbnails.ContainsKey(_asset1!.Folder.Path)); - bool isContainingThumbnail = _testableAssetRepository!.ContainsThumbnail(asset1!.Folder.Path, asset1!.FileName); + bool isContainingThumbnail = _testableAssetRepository!.ContainsThumbnail(_asset1!.Folder.Path, _asset1!.FileName); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(asset1!.Folder.Path)); - Assert.IsEmpty(thumbnails[asset1!.Folder.Path]); + Assert.IsTrue(thumbnails.ContainsKey(_asset1!.Folder.Path)); + Assert.IsEmpty(thumbnails[_asset1!.Folder.Path]); Assert.IsFalse(isContainingThumbnail); Assert.IsEmpty(assetsUpdatedEvents); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -219,28 +221,28 @@ public void ContainsThumbnail_FolderDoesNotExistAndThumbnailsDictionaryEntriesTo UserConfigurationService userConfigurationService = new (configurationRootMock.Object); TestableAssetRepository testableAssetRepository = new (_database!, _storageServiceMock!.Object, userConfigurationService); - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = testableAssetRepository.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); Folder folder = new() { Path = folderPath, FolderId = Guid.NewGuid(), }; - asset1!.Folder = folder; - asset1!.FolderId = folder.FolderId; + _asset1!.Folder = folder; + _asset1!.FolderId = folder.FolderId; - testableAssetRepository.AddAsset(asset1!, Array.Empty()); + testableAssetRepository.AddAsset(_asset1!, []); Assert.IsTrue(testableAssetRepository.HasChanges()); // Set by AddFolder method, called by AddAsset method Assert.IsEmpty(assetsUpdatedEvents); - bool isContainingThumbnail = testableAssetRepository.ContainsThumbnail(asset1!.Folder.Path, asset1!.FileName); + bool isContainingThumbnail = testableAssetRepository.ContainsThumbnail(_asset1!.Folder.Path, _asset1!.FileName); Assert.IsFalse(isContainingThumbnail); @@ -248,7 +250,7 @@ public void ContainsThumbnail_FolderDoesNotExistAndThumbnailsDictionaryEntriesTo } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -256,15 +258,15 @@ public void ContainsThumbnail_FolderDoesNotExistAndThumbnailsDictionaryEntriesTo [Test] public void ContainsThumbnail_ThumbnailsDoNotExistInRepository_ReturnsFalse() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); Folder folder = _testableAssetRepository!.AddFolder(folderPath); - asset1!.Folder = folder; - asset1!.FolderId = folder.FolderId; + _asset1!.Folder = folder; + _asset1!.FolderId = folder.FolderId; Assert.IsTrue(_testableAssetRepository.HasChanges()); @@ -272,20 +274,20 @@ public void ContainsThumbnail_ThumbnailsDoNotExistInRepository_ReturnsFalse() Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - Assert.IsFalse(thumbnails.ContainsKey(asset1!.Folder.Path)); + Assert.IsFalse(thumbnails.ContainsKey(_asset1!.Folder.Path)); - bool isContainingThumbnail = _testableAssetRepository!.ContainsThumbnail(asset1!.Folder.Path, asset1!.FileName); + bool isContainingThumbnail = _testableAssetRepository!.ContainsThumbnail(_asset1!.Folder.Path, _asset1!.FileName); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(asset1!.Folder.Path)); - Assert.IsEmpty(thumbnails[asset1!.Folder.Path]); + Assert.IsTrue(thumbnails.ContainsKey(_asset1!.Folder.Path)); + Assert.IsEmpty(thumbnails[_asset1!.Folder.Path]); Assert.IsFalse(isContainingThumbnail); Assert.IsEmpty(assetsUpdatedEvents); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -293,38 +295,38 @@ public void ContainsThumbnail_ThumbnailsDoNotExistInRepository_ReturnsFalse() [Test] public void ContainsThumbnail_ThumbnailsDoNotExistInRepositoryButBinExists_ReturnsTrue() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); Dictionary blobToWrite = new() { - { asset1!.FileName, new byte[] { 1, 2, 3 } }, - { "Image2.png", new byte[] { 4, 5, 6 } } + { _asset1!.FileName, [1, 2, 3]}, + { "Image2.png", [4, 5, 6]} }; Folder folder = _testableAssetRepository!.AddFolder(folderPath); - asset1!.Folder = folder; - asset1!.FolderId = folder.FolderId; + _asset1!.Folder = folder; + _asset1!.FolderId = folder.FolderId; Assert.IsTrue(_testableAssetRepository.HasChanges()); Assert.IsEmpty(assetsUpdatedEvents); - _database!.WriteBlob(blobToWrite, asset1!.Folder.ThumbnailsFilename); + _database!.WriteBlob(blobToWrite, _asset1!.Folder.ThumbnailsFilename); Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - Assert.IsFalse(thumbnails.ContainsKey(asset1!.Folder.Path)); + Assert.IsFalse(thumbnails.ContainsKey(_asset1!.Folder.Path)); - bool isContainingThumbnail = _testableAssetRepository!.ContainsThumbnail(asset1!.Folder.Path, asset1!.FileName); + bool isContainingThumbnail = _testableAssetRepository!.ContainsThumbnail(_asset1!.Folder.Path, _asset1!.FileName); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(asset1.Folder.Path)); - Assert.AreEqual(2, thumbnails[asset1.Folder.Path].Count); - Assert.IsTrue(thumbnails[asset1.Folder.Path].ContainsKey(asset1.FileName)); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[asset1.Folder.Path][asset1.FileName]); + Assert.IsTrue(thumbnails.ContainsKey(_asset1.Folder.Path)); + Assert.AreEqual(2, thumbnails[_asset1.Folder.Path].Count); + Assert.IsTrue(thumbnails[_asset1.Folder.Path].ContainsKey(_asset1.FileName)); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[_asset1.Folder.Path][_asset1.FileName]); Assert.IsTrue(isContainingThumbnail); @@ -332,7 +334,7 @@ public void ContainsThumbnail_ThumbnailsDoNotExistInRepositoryButBinExists_Retur } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -340,24 +342,24 @@ public void ContainsThumbnail_ThumbnailsDoNotExistInRepositoryButBinExists_Retur [Test] public void ContainsThumbnail_DifferentFileName_ReturnsFalse() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); - string fileName = "toto"; + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); + const string fileName = "toto"; Folder folder = _testableAssetRepository!.AddFolder(folderPath); - asset1!.Folder = folder; - asset1!.FolderId = folder.FolderId; - _testableAssetRepository!.AddAsset(asset1!, Array.Empty()); + _asset1!.Folder = folder; + _asset1!.FolderId = folder.FolderId; + _testableAssetRepository!.AddAsset(_asset1!, []); Assert.IsTrue(_testableAssetRepository.HasChanges()); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); - bool isContainingThumbnail = _testableAssetRepository!.ContainsThumbnail(asset1!.Folder.Path, fileName); + bool isContainingThumbnail = _testableAssetRepository!.ContainsThumbnail(_asset1!.Folder.Path, fileName); Assert.IsFalse(isContainingThumbnail); @@ -366,7 +368,7 @@ public void ContainsThumbnail_DifferentFileName_ReturnsFalse() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -374,24 +376,24 @@ public void ContainsThumbnail_DifferentFileName_ReturnsFalse() [Test] public void ContainsThumbnail_NullFileName_ReturnsFalse() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); string? fileName = null; Folder folder = _testableAssetRepository!.AddFolder(folderPath); - asset1!.Folder = folder; - asset1!.FolderId = folder.FolderId; - _testableAssetRepository!.AddAsset(asset1!, Array.Empty()); + _asset1!.Folder = folder; + _asset1!.FolderId = folder.FolderId; + _testableAssetRepository!.AddAsset(_asset1!, []); Assert.IsTrue(_testableAssetRepository.HasChanges()); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); - bool isContainingThumbnail = _testableAssetRepository!.ContainsThumbnail(asset1!.Folder.Path, fileName!); + bool isContainingThumbnail = _testableAssetRepository!.ContainsThumbnail(_asset1!.Folder.Path, fileName!); Assert.IsFalse(isContainingThumbnail); @@ -400,7 +402,7 @@ public void ContainsThumbnail_NullFileName_ReturnsFalse() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -408,24 +410,24 @@ public void ContainsThumbnail_NullFileName_ReturnsFalse() [Test] public void ContainsThumbnail_NullDirectoryName_ThrowsArgumentNullException() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); string? directoryName = null; Folder folder = _testableAssetRepository!.AddFolder(folderPath); - asset1!.Folder = folder; - asset1!.FolderId = folder.FolderId; - _testableAssetRepository!.AddAsset(asset1!, Array.Empty()); + _asset1!.Folder = folder; + _asset1!.FolderId = folder.FolderId; + _testableAssetRepository!.AddAsset(_asset1!, []); Assert.IsTrue(_testableAssetRepository.HasChanges()); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); - ArgumentNullException? exception = Assert.Throws(() => _testableAssetRepository!.ContainsThumbnail(directoryName!, asset1!.FileName)); + ArgumentNullException? exception = Assert.Throws(() => _testableAssetRepository!.ContainsThumbnail(directoryName!, _asset1!.FileName)); Assert.AreEqual("Value cannot be null. (Parameter 'key')", exception?.Message); @@ -434,7 +436,7 @@ public void ContainsThumbnail_NullDirectoryName_ThrowsArgumentNullException() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryDeleteAssetTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryDeleteAssetTests.cs index e7448d31..b74bfedd 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryDeleteAssetTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryDeleteAssetTests.cs @@ -39,6 +39,7 @@ public void SetUp() _asset1 = new() { + Folder = new() { Path = "" }, FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), FileName = "Image 1.jpg", FileSize = 363888, @@ -59,7 +60,7 @@ public void SetUp() [Test] public void DeleteAsset_FolderAndAssetExist_ReturnsDeletedAssetAndThumbnailsAndAssetAreDeletedAndAssetsUpdatedIsUpdated() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -129,7 +130,7 @@ public void DeleteAsset_AssetDoesNotExistAndThumbnailsDictionaryEntriesToKeepIs0 UserConfigurationService userConfigurationService = new (configurationRootMock.Object); TestableAssetRepository testableAssetRepository = new (_database!, _storageServiceMock!.Object, userConfigurationService); - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = testableAssetRepository.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -166,7 +167,7 @@ public void DeleteAsset_AssetDoesNotExistAndThumbnailsDictionaryEntriesToKeepIs0 [Test] public void DeleteAsset_FolderIsNull_ReturnsNullAndDoesNothingAndAssetsUpdatedIsNotUpdated() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -221,7 +222,7 @@ public void DeleteAsset_FolderIsNull_ReturnsNullAndDoesNothingAndAssetsUpdatedIs [Test] public void DeleteAsset_ThumbnailsDoNotExistInRepositoryButBinExists_ReturnsDeletedAssetAndThumbnailsAndAssetAreDeletedAndAssetsUpdatedIsNotUpdated() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -272,7 +273,7 @@ public void DeleteAsset_ThumbnailsDoNotExistInRepositoryButBinExists_ReturnsDele [Test] public void DeleteAsset_DirectoryIsNull_ReturnsNullAndDoesNothingAndAssetsUpdatedIsNotUpdated() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -328,7 +329,7 @@ public void DeleteAsset_DirectoryIsNull_ReturnsNullAndDoesNothingAndAssetsUpdate [Test] public void DeleteAsset_FileNameIsNull_ThrowsArgumentNullExceptionAndAssetsUpdatedIsNotUpdated() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -383,7 +384,7 @@ public void DeleteAsset_FileNameIsNull_ThrowsArgumentNullExceptionAndAssetsUpdat [Test] public void DeleteAsset_FolderAndAssetDoNotExist_ReturnsNullAndHasChangesIsFalseAndAssetsUpdatedIsNotUpdated() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -411,7 +412,7 @@ public void DeleteAsset_FolderAndAssetDoNotExist_ReturnsNullAndHasChangesIsFalse [Test] public void DeleteAsset_ConcurrentAccess_ReturnsDeletedAssetsAndAssetsAreHandledSafelyAndAssetsUpdatedIsUpdated() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryDeleteFolderTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryDeleteFolderTests.cs index 113eb5d7..d57af13b 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryDeleteFolderTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryDeleteFolderTests.cs @@ -5,9 +5,9 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositoryDeleteFolderTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; private TestableAssetRepository? _testableAssetRepository; private PhotoManager.Infrastructure.Database.Database? _database; @@ -15,19 +15,19 @@ public class AssetRepositoryDeleteFolderTests private Mock? _storageServiceMock; private Mock? _configurationRootMock; - private Asset? asset1; + private Asset? _asset1; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -37,8 +37,9 @@ public void SetUp() _userConfigurationService = new (_configurationRootMock!.Object); _testableAssetRepository = new (_database, _storageServiceMock!.Object, _userConfigurationService); - asset1 = new() + _asset1 = new() { + Folder = new() { Path = "" }, FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), FileName = "Image 1.jpg", FileSize = 363888, @@ -59,7 +60,7 @@ public void SetUp() [Test] public void DeleteFolder_FolderIsNull_ThrowsNullReferenceException() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -74,7 +75,7 @@ public void DeleteFolder_FolderIsNull_ThrowsNullReferenceException() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -82,26 +83,26 @@ public void DeleteFolder_FolderIsNull_ThrowsNullReferenceException() [Test] public void DeleteFolder_FolderExistsWithThumbnails_RemovesThumbnailsAndFolder() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); try { Directory.CreateDirectory(folderPath); Folder folder = _testableAssetRepository!.AddFolder(folderPath); - asset1!.Folder = folder; - asset1!.FolderId = folder.FolderId; - _testableAssetRepository!.AddAsset(asset1!, Array.Empty()); + _asset1!.Folder = folder; + _asset1!.FolderId = folder.FolderId; + _testableAssetRepository!.AddAsset(_asset1!, []); Assert.IsTrue(_testableAssetRepository.HasChanges()); - bool isContainingThumbnail = _testableAssetRepository!.ContainsThumbnail(asset1!.Folder.Path, asset1!.FileName); + bool isContainingThumbnail = _testableAssetRepository!.ContainsThumbnail(_asset1!.Folder.Path, _asset1!.FileName); Assert.IsTrue(isContainingThumbnail); - _testableAssetRepository.SaveCatalog(asset1!.Folder); // SaveThumbnails, write blob file, reset hasChanges to false + _testableAssetRepository.SaveCatalog(_asset1!.Folder); // SaveThumbnails, write blob file, reset hasChanges to false Assert.IsFalse(_testableAssetRepository.HasChanges()); @@ -110,17 +111,17 @@ public void DeleteFolder_FolderExistsWithThumbnails_RemovesThumbnailsAndFolder() Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(asset1!.Folder.Path)); - Assert.AreEqual(1, thumbnails[asset1!.Folder.Path].Count); - Assert.IsTrue(thumbnails[asset1!.Folder.Path].ContainsKey(asset1.FileName)); - Assert.AreEqual(Array.Empty(), thumbnails[asset1!.Folder.Path][asset1.FileName]); + Assert.IsTrue(thumbnails.ContainsKey(_asset1!.Folder.Path)); + Assert.AreEqual(1, thumbnails[_asset1!.Folder.Path].Count); + Assert.IsTrue(thumbnails[_asset1!.Folder.Path].ContainsKey(_asset1.FileName)); + Assert.AreEqual(Array.Empty(), thumbnails[_asset1!.Folder.Path][_asset1.FileName]); - _testableAssetRepository!.DeleteFolder(asset1!.Folder); + _testableAssetRepository!.DeleteFolder(_asset1!.Folder); Folder[] folders = _testableAssetRepository!.GetFolders(); - Assert.IsFalse(thumbnails.ContainsKey(asset1!.Folder.Path)); - Assert.IsFalse(folders.Contains(asset1!.Folder)); + Assert.IsFalse(thumbnails.ContainsKey(_asset1!.Folder.Path)); + Assert.IsFalse(folders.Contains(_asset1!.Folder)); Assert.IsTrue(_testableAssetRepository.HasChanges()); Assert.AreEqual(1, assetsUpdatedEvents.Count); @@ -128,7 +129,7 @@ public void DeleteFolder_FolderExistsWithThumbnails_RemovesThumbnailsAndFolder() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); Directory.Delete(folderPath, true); assetsUpdatedSubscription.Dispose(); } @@ -137,21 +138,21 @@ public void DeleteFolder_FolderExistsWithThumbnails_RemovesThumbnailsAndFolder() [Test] public void DeleteFolder_FolderExistsNoThumbnails_RemovesOnlyFolder() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); try { Directory.CreateDirectory(folderPath); Folder folder = _testableAssetRepository!.AddFolder(folderPath); - asset1!.Folder = folder; - asset1!.FolderId = folder.FolderId; + _asset1!.Folder = folder; + _asset1!.FolderId = folder.FolderId; Assert.IsTrue(_testableAssetRepository.HasChanges()); - _testableAssetRepository.SaveCatalog(asset1!.Folder); // SaveThumbnails, write blob file, reset hasChanges to false + _testableAssetRepository.SaveCatalog(_asset1!.Folder); // SaveThumbnails, write blob file, reset hasChanges to false Assert.IsFalse(_testableAssetRepository.HasChanges()); @@ -159,21 +160,21 @@ public void DeleteFolder_FolderExistsNoThumbnails_RemovesOnlyFolder() Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - Assert.IsFalse(thumbnails.ContainsKey(asset1!.Folder.Path)); + Assert.IsFalse(thumbnails.ContainsKey(_asset1!.Folder.Path)); - _testableAssetRepository!.DeleteFolder(asset1!.Folder); + _testableAssetRepository!.DeleteFolder(_asset1!.Folder); Folder[] folders = _testableAssetRepository!.GetFolders(); - Assert.IsFalse(thumbnails.ContainsKey(asset1!.Folder.Path)); - Assert.IsFalse(folders.Contains(asset1!.Folder)); + Assert.IsFalse(thumbnails.ContainsKey(_asset1!.Folder.Path)); + Assert.IsFalse(folders.Contains(_asset1!.Folder)); Assert.IsTrue(_testableAssetRepository.HasChanges()); Assert.IsEmpty(assetsUpdatedEvents); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); Directory.Delete(folderPath, true); assetsUpdatedSubscription.Dispose(); } @@ -182,25 +183,25 @@ public void DeleteFolder_FolderExistsNoThumbnails_RemovesOnlyFolder() [Test] public void DeleteFolder_FolderExistsNoThumbnailsButCreated_RemovesFolderAndThumbnail() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); try { Directory.CreateDirectory(folderPath); Folder folder = _testableAssetRepository!.AddFolder(folderPath); - asset1!.Folder = folder; - asset1!.FolderId = folder.FolderId; + _asset1!.Folder = folder; + _asset1!.FolderId = folder.FolderId; Assert.IsTrue(_testableAssetRepository.HasChanges()); - bool isContainingThumbnail = _testableAssetRepository!.ContainsThumbnail(asset1!.Folder.Path, asset1!.FileName); + bool isContainingThumbnail = _testableAssetRepository!.ContainsThumbnail(_asset1!.Folder.Path, _asset1!.FileName); Assert.IsFalse(isContainingThumbnail); - _testableAssetRepository.SaveCatalog(asset1!.Folder); // SaveThumbnails, write blob file, reset hasChanges to false + _testableAssetRepository.SaveCatalog(_asset1!.Folder); // SaveThumbnails, write blob file, reset hasChanges to false Assert.IsFalse(_testableAssetRepository.HasChanges()); @@ -208,22 +209,22 @@ public void DeleteFolder_FolderExistsNoThumbnailsButCreated_RemovesFolderAndThum Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(asset1!.Folder.Path)); - Assert.IsEmpty(thumbnails[asset1!.Folder.Path]); + Assert.IsTrue(thumbnails.ContainsKey(_asset1!.Folder.Path)); + Assert.IsEmpty(thumbnails[_asset1!.Folder.Path]); - _testableAssetRepository!.DeleteFolder(asset1!.Folder); + _testableAssetRepository!.DeleteFolder(_asset1!.Folder); Folder[] folders = _testableAssetRepository!.GetFolders(); - Assert.IsFalse(thumbnails.ContainsKey(asset1!.Folder.Path)); - Assert.IsFalse(folders.Contains(asset1!.Folder)); + Assert.IsFalse(thumbnails.ContainsKey(_asset1!.Folder.Path)); + Assert.IsFalse(folders.Contains(_asset1!.Folder)); Assert.IsTrue(_testableAssetRepository.HasChanges()); Assert.IsEmpty(assetsUpdatedEvents); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); Directory.Delete(folderPath, true); assetsUpdatedSubscription.Dispose(); } @@ -232,21 +233,21 @@ public void DeleteFolder_FolderExistsNoThumbnailsButCreated_RemovesFolderAndThum [Test] public void DeleteFolder_FolderExistsNoThumbnailsButBinExists_RemovesFolderAndBinFile() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); try { Directory.CreateDirectory(folderPath); Folder folder = _testableAssetRepository!.AddFolder(folderPath); - asset1!.Folder = folder; - asset1!.FolderId = folder.FolderId; + _asset1!.Folder = folder; + _asset1!.FolderId = folder.FolderId; Assert.IsTrue(_testableAssetRepository.HasChanges()); - _testableAssetRepository.SaveCatalog(asset1!.Folder); // SaveThumbnails, write blob file, reset hasChanges to false + _testableAssetRepository.SaveCatalog(_asset1!.Folder); // SaveThumbnails, write blob file, reset hasChanges to false Assert.IsFalse(_testableAssetRepository.HasChanges()); @@ -254,27 +255,27 @@ public void DeleteFolder_FolderExistsNoThumbnailsButBinExists_RemovesFolderAndBi Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - Assert.IsFalse(thumbnails.ContainsKey(asset1!.Folder.Path)); + Assert.IsFalse(thumbnails.ContainsKey(_asset1!.Folder.Path)); - _database!.WriteBlob(new Dictionary(), asset1!.Folder.ThumbnailsFilename); + _database!.WriteBlob([], _asset1!.Folder.ThumbnailsFilename); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, asset1.Folder.ThumbnailsFilename))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, _asset1.Folder.ThumbnailsFilename))); - _testableAssetRepository!.DeleteFolder(asset1!.Folder); + _testableAssetRepository!.DeleteFolder(_asset1!.Folder); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, asset1.Folder.ThumbnailsFilename))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, _asset1.Folder.ThumbnailsFilename))); Folder[] folders = _testableAssetRepository!.GetFolders(); - Assert.IsFalse(thumbnails.ContainsKey(asset1!.Folder.Path)); - Assert.IsFalse(folders.Contains(asset1!.Folder)); + Assert.IsFalse(thumbnails.ContainsKey(_asset1!.Folder.Path)); + Assert.IsFalse(folders.Contains(_asset1!.Folder)); Assert.IsTrue(_testableAssetRepository.HasChanges()); Assert.IsEmpty(assetsUpdatedEvents); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); Directory.Delete(folderPath, true); assetsUpdatedSubscription.Dispose(); } @@ -283,10 +284,10 @@ public void DeleteFolder_FolderExistsNoThumbnailsButBinExists_RemovesFolderAndBi [Test] public void DeleteFolder_FolderDoesNotExist_RemovesNothing() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); try { @@ -309,7 +310,7 @@ public void DeleteFolder_FolderDoesNotExist_RemovesNothing() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); Directory.Delete(folderPath, true); assetsUpdatedSubscription.Dispose(); } @@ -318,26 +319,26 @@ public void DeleteFolder_FolderDoesNotExist_RemovesNothing() [Test] public void DeleteFolder_ConcurrentAccess_ThumbnailsAndFoldersAreHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); try { Directory.CreateDirectory(folderPath); Folder folder = _testableAssetRepository!.AddFolder(folderPath); - asset1!.Folder = folder; - asset1!.FolderId = folder.FolderId; - _testableAssetRepository!.AddAsset(asset1!, Array.Empty()); + _asset1!.Folder = folder; + _asset1!.FolderId = folder.FolderId; + _testableAssetRepository!.AddAsset(_asset1!, []); Assert.IsTrue(_testableAssetRepository.HasChanges()); - bool isContainingThumbnail = _testableAssetRepository!.ContainsThumbnail(asset1!.Folder.Path, asset1!.FileName); + bool isContainingThumbnail = _testableAssetRepository!.ContainsThumbnail(_asset1!.Folder.Path, _asset1!.FileName); Assert.IsTrue(isContainingThumbnail); - _testableAssetRepository.SaveCatalog(asset1!.Folder); // SaveThumbnails, write blob file, reset hasChanges to false + _testableAssetRepository.SaveCatalog(_asset1!.Folder); // SaveThumbnails, write blob file, reset hasChanges to false Assert.IsFalse(_testableAssetRepository.HasChanges()); @@ -346,22 +347,22 @@ public void DeleteFolder_ConcurrentAccess_ThumbnailsAndFoldersAreHandledSafely() Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(asset1!.Folder.Path)); - Assert.AreEqual(1, thumbnails[asset1!.Folder.Path].Count); - Assert.IsTrue(thumbnails[asset1!.Folder.Path].ContainsKey(asset1.FileName)); - Assert.AreEqual(Array.Empty(), thumbnails[asset1!.Folder.Path][asset1.FileName]); + Assert.IsTrue(thumbnails.ContainsKey(_asset1!.Folder.Path)); + Assert.AreEqual(1, thumbnails[_asset1!.Folder.Path].Count); + Assert.IsTrue(thumbnails[_asset1!.Folder.Path].ContainsKey(_asset1.FileName)); + Assert.AreEqual(Array.Empty(), thumbnails[_asset1!.Folder.Path][_asset1.FileName]); // Simulate concurrent access Parallel.Invoke( - () => _testableAssetRepository!.DeleteFolder(asset1!.Folder), - () => _testableAssetRepository!.DeleteFolder(asset1!.Folder), - () => _testableAssetRepository!.DeleteFolder(asset1!.Folder) + () => _testableAssetRepository!.DeleteFolder(_asset1!.Folder), + () => _testableAssetRepository!.DeleteFolder(_asset1!.Folder), + () => _testableAssetRepository!.DeleteFolder(_asset1!.Folder) ); Folder[] folders = _testableAssetRepository!.GetFolders(); - Assert.IsFalse(thumbnails.ContainsKey(asset1!.Folder.Path)); - Assert.IsFalse(folders.Contains(asset1!.Folder)); + Assert.IsFalse(thumbnails.ContainsKey(_asset1!.Folder.Path)); + Assert.IsFalse(folders.Contains(_asset1!.Folder)); Assert.IsTrue(_testableAssetRepository.HasChanges()); Assert.AreEqual(1, assetsUpdatedEvents.Count); @@ -369,7 +370,7 @@ public void DeleteFolder_ConcurrentAccess_ThumbnailsAndFoldersAreHandledSafely() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); Directory.Delete(folderPath, true); assetsUpdatedSubscription.Dispose(); } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryFolderExistsTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryFolderExistsTests.cs index 5d69970f..044bb501 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryFolderExistsTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryFolderExistsTests.cs @@ -5,25 +5,25 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositoryFolderExistsTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; - private IAssetRepository? _assetRepository; + private AssetRepository? _assetRepository; private Mock? _storageServiceMock; private Mock? _configurationRootMock; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -31,18 +31,18 @@ public void SetUp() { PhotoManager.Infrastructure.Database.Database database = new (new ObjectListStorage(), new BlobStorage(), new BackupStorage()); UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); - _assetRepository = new AssetRepository(database, _storageServiceMock!.Object, userConfigurationService); + _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); } [Test] public void FolderExists_FolderExists_ReturnsTrue() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "TestFolder1"); + string folderPath = Path.Combine(_dataDirectory!, "TestFolder1"); _assetRepository!.AddFolder(folderPath); @@ -54,7 +54,7 @@ public void FolderExists_FolderExists_ReturnsTrue() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -62,13 +62,13 @@ public void FolderExists_FolderExists_ReturnsTrue() [Test] public void FolderExists_FolderDoesNotExist_ReturnsFalse() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "TestFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "TestFolder2"); _assetRepository!.AddFolder(folderPath1); @@ -80,7 +80,7 @@ public void FolderExists_FolderDoesNotExist_ReturnsFalse() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -88,12 +88,12 @@ public void FolderExists_FolderDoesNotExist_ReturnsFalse() [Test] public void FolderExists_ConcurrentAccess_FoldersAreHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "TestFolder1"); + string folderPath = Path.Combine(_dataDirectory!, "TestFolder1"); _assetRepository!.AddFolder(folderPath); @@ -116,7 +116,7 @@ public void FolderExists_ConcurrentAccess_FoldersAreHandledSafely() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryFolderHasThumbnailsTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryFolderHasThumbnailsTests.cs index 048018bb..2232b41f 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryFolderHasThumbnailsTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryFolderHasThumbnailsTests.cs @@ -5,26 +5,26 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositoryFolderHasThumbnailsTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; private PhotoManager.Infrastructure.Database.Database? _database; - private IAssetRepository? _assetRepository; + private AssetRepository? _assetRepository; private Mock? _storageServiceMock; private Mock? _configurationRootMock; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -32,19 +32,19 @@ public void SetUp() { _database = new (new ObjectListStorage(), new BlobStorage(), new BackupStorage()); UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); - _assetRepository = new AssetRepository(_database, _storageServiceMock!.Object, userConfigurationService); + _assetRepository = new (_database, _storageServiceMock!.Object, userConfigurationService); } [Test] public void FolderHasThumbnails_ThumbnailsExist_ReturnsTrue() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - Folder folder = new() { FolderId = Guid.NewGuid(), Path = dataDirectory! }; - _database!.WriteBlob(new Dictionary(), folder.ThumbnailsFilename); + Folder folder = new() { FolderId = Guid.NewGuid(), Path = _dataDirectory! }; + _database!.WriteBlob([], folder.ThumbnailsFilename); bool folderHasThumbnails = _assetRepository!.FolderHasThumbnails(folder); @@ -54,7 +54,7 @@ public void FolderHasThumbnails_ThumbnailsExist_ReturnsTrue() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -62,12 +62,12 @@ public void FolderHasThumbnails_ThumbnailsExist_ReturnsTrue() [Test] public void FolderHasThumbnails_ThumbnailsDoNotExist_ReturnsFalse() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - Folder folder = new() { FolderId = Guid.NewGuid(), Path = dataDirectory! }; + Folder folder = new() { FolderId = Guid.NewGuid(), Path = _dataDirectory! }; bool folderHasThumbnails = _assetRepository!.FolderHasThumbnails(folder); @@ -77,7 +77,7 @@ public void FolderHasThumbnails_ThumbnailsDoNotExist_ReturnsFalse() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -85,7 +85,7 @@ public void FolderHasThumbnails_ThumbnailsDoNotExist_ReturnsFalse() [Test] public void FolderHasThumbnails_FolderIsNull_ThrowsNullReferenceException() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -100,7 +100,7 @@ public void FolderHasThumbnails_FolderIsNull_ThrowsNullReferenceException() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetAssetsByPathTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetAssetsByPathTests.cs index e4671c93..56afc41d 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetAssetsByPathTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetAssetsByPathTests.cs @@ -5,24 +5,25 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositoryGetAssetsByPathTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; + private TestableAssetRepository? _testableAssetRepository; private PhotoManager.Infrastructure.Database.Database? _database; private Mock? _storageServiceMock; private Mock? _configurationRootMock; - private Asset? asset1; - private Asset? asset2; - private Asset? asset3; + private Asset? _asset1; + private Asset? _asset2; + private Asset? _asset3; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); @@ -32,7 +33,7 @@ public void OneTimeSetUp() public void SetUp() { _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath!); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath!); _storageServiceMock.Setup(x => x.LoadBitmapThumbnailImage(It.IsAny(), It.IsAny(), It.IsAny())).Returns(new BitmapImage()); _storageServiceMock.Setup(x => x.UpdateAssetFileDateTimeProperties(It.IsAny())); @@ -40,8 +41,9 @@ public void SetUp() UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); _testableAssetRepository = new (_database, _storageServiceMock!.Object, userConfigurationService); - asset1 = new() + _asset1 = new() { + Folder = new() { Path = "" }, FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), FileName = "Image 1.jpg", FileSize = 363888, @@ -57,8 +59,9 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset2 = new() + _asset2 = new() { + Folder = new() { Path = "" }, FolderId = new Guid("68493435-e299-4bb5-9e02-214da41d0256"), FileName = "Image 9.png", FileSize = 4602393, @@ -74,8 +77,9 @@ public void SetUp() AssetRotatedMessage = "The asset has been rotated", IsAssetRotated = true }; - asset3 = new() + _asset3 = new() { + Folder = new() { Path = "" }, FolderId = new Guid("f91b8c81-6938-431a-a689-d86c7c4db126"), FileName = "Image_11.heic", FileSize = 2247285, @@ -96,27 +100,27 @@ public void SetUp() [Test] public void GetAssetsByPath_ThumbnailsAndFolderExist_ReturnsAssets() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "NewFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "NewFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "NewFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "NewFolder2"); Folder folder1 = _testableAssetRepository!.AddFolder(folderPath1); Folder folder2 = _testableAssetRepository!.AddFolder(folderPath2); - asset1!.Folder = folder1; - asset1!.FolderId = folder1.FolderId; - byte[] assetData1 = new byte[] { 1, 2, 3 }; + _asset1!.Folder = folder1; + _asset1!.FolderId = folder1.FolderId; + byte[] assetData1 = [1, 2, 3]; - asset2!.Folder = folder1; - asset2!.FolderId = folder1.FolderId; - byte[] assetData2 = Array.Empty(); + _asset2!.Folder = folder1; + _asset2!.FolderId = folder1.FolderId; + byte[] assetData2 = []; - asset3!.Folder = folder2; - asset3!.FolderId = folder2.FolderId; - byte[] assetData3 = new byte[] { 4, 5, 6 }; + _asset3!.Folder = folder2; + _asset3!.FolderId = folder2.FolderId; + byte[] assetData3 = [4, 5, 6]; List cataloguedAssets = _testableAssetRepository!.GetCataloguedAssets(); Assert.IsEmpty(cataloguedAssets); @@ -124,9 +128,9 @@ public void GetAssetsByPath_ThumbnailsAndFolderExist_ReturnsAssets() Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - _testableAssetRepository.AddAsset(asset1, assetData1); - _testableAssetRepository.AddAsset(asset2, assetData2); - _testableAssetRepository.AddAsset(asset3, assetData3); + _testableAssetRepository.AddAsset(_asset1, assetData1); + _testableAssetRepository.AddAsset(_asset2, assetData2); + _testableAssetRepository.AddAsset(_asset3, assetData3); Assert.AreEqual(3, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); @@ -137,9 +141,9 @@ public void GetAssetsByPath_ThumbnailsAndFolderExist_ReturnsAssets() Asset[] assets2 = _testableAssetRepository.GetAssetsByPath(folderPath2); Assert.AreEqual(3, cataloguedAssets.Count); - Assert.AreEqual(asset1.FileName, cataloguedAssets[0].FileName); - Assert.AreEqual(asset2!.FileName, cataloguedAssets[1].FileName); - Assert.AreEqual(asset3!.FileName, cataloguedAssets[2].FileName); + Assert.AreEqual(_asset1.FileName, cataloguedAssets[0].FileName); + Assert.AreEqual(_asset2!.FileName, cataloguedAssets[1].FileName); + Assert.AreEqual(_asset3!.FileName, cataloguedAssets[2].FileName); Assert.AreEqual(2, thumbnails.Count); Assert.IsTrue(thumbnails.ContainsKey(folderPath1)); @@ -148,20 +152,20 @@ public void GetAssetsByPath_ThumbnailsAndFolderExist_ReturnsAssets() Assert.AreEqual(2, thumbnails[folderPath1].Count); Assert.AreEqual(1, thumbnails[folderPath2].Count); - Assert.IsTrue(thumbnails[folderPath1].ContainsKey(asset1.FileName)); - Assert.IsTrue(thumbnails[folderPath1].ContainsKey(asset2.FileName)); - Assert.IsTrue(thumbnails[folderPath2].ContainsKey(asset3.FileName)); + Assert.IsTrue(thumbnails[folderPath1].ContainsKey(_asset1.FileName)); + Assert.IsTrue(thumbnails[folderPath1].ContainsKey(_asset2.FileName)); + Assert.IsTrue(thumbnails[folderPath2].ContainsKey(_asset3.FileName)); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath1][asset1.FileName]); - Assert.AreEqual(Array.Empty(), thumbnails[folderPath1][asset2.FileName]); - Assert.AreEqual(new byte[] { 4, 5, 6 }, thumbnails[folderPath2][asset3.FileName]); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath1][_asset1.FileName]); + Assert.AreEqual(Array.Empty(), thumbnails[folderPath1][_asset2.FileName]); + Assert.AreEqual(new byte[] { 4, 5, 6 }, thumbnails[folderPath2][_asset3.FileName]); Assert.AreEqual(2, assets1.Length); Assert.AreEqual(1, assets2.Length); - Assert.AreEqual(asset1.FileName, assets1[0].FileName); - Assert.AreEqual(asset2!.FileName, assets1[1].FileName); - Assert.AreEqual(asset3!.FileName, assets2[0].FileName); + Assert.AreEqual(_asset1.FileName, assets1[0].FileName); + Assert.AreEqual(_asset2!.FileName, assets1[1].FileName); + Assert.AreEqual(_asset3!.FileName, assets2[0].FileName); _storageServiceMock!.Verify(x => x.LoadBitmapThumbnailImage(It.IsAny(), It.IsAny(), It.IsAny()), Times.Exactly(3)); _storageServiceMock!.Verify(x => x.UpdateAssetFileDateTimeProperties(It.IsAny()), Times.Exactly(3)); @@ -173,7 +177,7 @@ public void GetAssetsByPath_ThumbnailsAndFolderExist_ReturnsAssets() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -183,24 +187,24 @@ public void GetAssetsByPath_ThumbnailsAndFolderExistButLoadBitmapThumbnailImageR { BitmapImage? bitmapImage = null; Mock storageService = new(); - storageService.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath!); + storageService.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath!); storageService.Setup(x => x.LoadBitmapThumbnailImage(It.IsAny(), It.IsAny(), It.IsAny())).Returns(bitmapImage!); storageService.Setup(x => x.UpdateAssetFileDateTimeProperties(It.IsAny())); UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); TestableAssetRepository testableAssetRepository = new (_database!, storageService.Object, userConfigurationService); - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = testableAssetRepository.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "NewFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "NewFolder1"); Folder folder1 = testableAssetRepository.AddFolder(folderPath1); - asset1!.Folder = folder1; - asset1!.FolderId = folder1.FolderId; - byte[] assetData1 = new byte[] { 1, 2, 3 }; + _asset1!.Folder = folder1; + _asset1!.FolderId = folder1.FolderId; + byte[] assetData1 = [1, 2, 3]; List cataloguedAssets = testableAssetRepository.GetCataloguedAssets(); Assert.IsEmpty(cataloguedAssets); @@ -208,7 +212,7 @@ public void GetAssetsByPath_ThumbnailsAndFolderExistButLoadBitmapThumbnailImageR Dictionary> thumbnails = testableAssetRepository.GetThumbnails(); Assert.IsEmpty(thumbnails); - testableAssetRepository.AddAsset(asset1, assetData1); + testableAssetRepository.AddAsset(_asset1, assetData1); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); @@ -216,12 +220,12 @@ public void GetAssetsByPath_ThumbnailsAndFolderExistButLoadBitmapThumbnailImageR Asset[] assets1 = testableAssetRepository.GetAssetsByPath(folderPath1); Assert.AreEqual(1, cataloguedAssets.Count); - Assert.AreEqual(asset1.FileName, cataloguedAssets[0].FileName); + Assert.AreEqual(_asset1.FileName, cataloguedAssets[0].FileName); Assert.AreEqual(1, thumbnails.Count); Assert.IsTrue(thumbnails.ContainsKey(folderPath1)); - Assert.IsTrue(thumbnails[folderPath1].ContainsKey(asset1.FileName)); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath1][asset1.FileName]); + Assert.IsTrue(thumbnails[folderPath1].ContainsKey(_asset1.FileName)); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath1][_asset1.FileName]); Assert.IsEmpty(assets1); @@ -233,7 +237,7 @@ public void GetAssetsByPath_ThumbnailsAndFolderExistButLoadBitmapThumbnailImageR } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -241,26 +245,26 @@ public void GetAssetsByPath_ThumbnailsAndFolderExistButLoadBitmapThumbnailImageR [Test] public void GetAssetsByPath_ThumbnailsAndFolderExistButBinExists_ReturnsAssets() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { Dictionary blobToWrite = new() { - { asset1!.FileName, new byte[] { 1, 2, 3 } }, - { asset2!.FileName, new byte[] { 4, 5, 6 } } + { _asset1!.FileName, [1, 2, 3]}, + { _asset2!.FileName, [4, 5, 6]} }; - string folderPath1 = Path.Combine(dataDirectory!, "NewFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "NewFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "NewFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "NewFolder2"); Folder folder1 = _testableAssetRepository!.AddFolder(folderPath1); - asset1!.Folder = new() { FolderId = folder1.FolderId, Path = folderPath2 }; - asset1!.FolderId = folder1.FolderId; - byte[] assetData1 = new byte[] { 1, 2, 3 }; + _asset1!.Folder = new() { FolderId = folder1.FolderId, Path = folderPath2 }; + _asset1!.FolderId = folder1.FolderId; + byte[] assetData1 = [1, 2, 3]; - _database!.WriteBlob(blobToWrite, asset1!.Folder.ThumbnailsFilename); + _database!.WriteBlob(blobToWrite, _asset1!.Folder.ThumbnailsFilename); List cataloguedAssets = _testableAssetRepository!.GetCataloguedAssets(); Assert.IsEmpty(cataloguedAssets); @@ -268,7 +272,7 @@ public void GetAssetsByPath_ThumbnailsAndFolderExistButBinExists_ReturnsAssets() Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - _testableAssetRepository.AddAsset(asset1, assetData1); + _testableAssetRepository.AddAsset(_asset1, assetData1); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); @@ -276,7 +280,7 @@ public void GetAssetsByPath_ThumbnailsAndFolderExistButBinExists_ReturnsAssets() Asset[] assets1 = _testableAssetRepository.GetAssetsByPath(folderPath1); Assert.AreEqual(1, cataloguedAssets.Count); - Assert.AreEqual(asset1.FileName, cataloguedAssets[0].FileName); + Assert.AreEqual(_asset1.FileName, cataloguedAssets[0].FileName); Assert.AreEqual(2, thumbnails.Count); Assert.IsTrue(thumbnails.ContainsKey(folderPath1)); @@ -285,18 +289,18 @@ public void GetAssetsByPath_ThumbnailsAndFolderExistButBinExists_ReturnsAssets() Assert.AreEqual(2, thumbnails[folderPath1].Count); Assert.AreEqual(2, thumbnails[folderPath2].Count); - Assert.IsTrue(thumbnails[folderPath1].ContainsKey(asset1.FileName)); - Assert.IsTrue(thumbnails[folderPath1].ContainsKey(asset2.FileName)); - Assert.IsTrue(thumbnails[folderPath2].ContainsKey(asset1.FileName)); - Assert.IsTrue(thumbnails[folderPath2].ContainsKey(asset2.FileName)); + Assert.IsTrue(thumbnails[folderPath1].ContainsKey(_asset1.FileName)); + Assert.IsTrue(thumbnails[folderPath1].ContainsKey(_asset2.FileName)); + Assert.IsTrue(thumbnails[folderPath2].ContainsKey(_asset1.FileName)); + Assert.IsTrue(thumbnails[folderPath2].ContainsKey(_asset2.FileName)); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath1][asset1.FileName]); - Assert.AreEqual(new byte[] { 4, 5, 6 }, thumbnails[folderPath1][asset2.FileName]); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath2][asset1.FileName]); - Assert.AreEqual(new byte[] { 4, 5, 6 }, thumbnails[folderPath2][asset2.FileName]); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath1][_asset1.FileName]); + Assert.AreEqual(new byte[] { 4, 5, 6 }, thumbnails[folderPath1][_asset2.FileName]); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath2][_asset1.FileName]); + Assert.AreEqual(new byte[] { 4, 5, 6 }, thumbnails[folderPath2][_asset2.FileName]); Assert.AreEqual(1, assets1.Length); - Assert.AreEqual(asset1.FileName, assets1[0].FileName); + Assert.AreEqual(_asset1.FileName, assets1[0].FileName); _storageServiceMock!.Verify(x => x.LoadBitmapThumbnailImage(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); _storageServiceMock!.Verify(x => x.UpdateAssetFileDateTimeProperties(It.IsAny()), Times.Once); @@ -306,7 +310,7 @@ public void GetAssetsByPath_ThumbnailsAndFolderExistButBinExists_ReturnsAssets() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -314,18 +318,18 @@ public void GetAssetsByPath_ThumbnailsAndFolderExistButBinExists_ReturnsAssets() [Test] public void GetAssetsByPath_ThumbnailsAndFolderExistDifferentDirectory_ReturnsAssets() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "NewFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "NewFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "NewFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "NewFolder2"); Folder folder1 = _testableAssetRepository!.AddFolder(folderPath1); - asset1!.Folder = new() { Path = folderPath2 }; - asset1!.FolderId = folder1.FolderId; - byte[] assetData1 = new byte[] { 1, 2, 3 }; + _asset1!.Folder = new() { Path = folderPath2 }; + _asset1!.FolderId = folder1.FolderId; + byte[] assetData1 = [1, 2, 3]; List cataloguedAssets = _testableAssetRepository!.GetCataloguedAssets(); Assert.IsEmpty(cataloguedAssets); @@ -333,7 +337,7 @@ public void GetAssetsByPath_ThumbnailsAndFolderExistDifferentDirectory_ReturnsAs Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - _testableAssetRepository.AddAsset(asset1, assetData1); + _testableAssetRepository.AddAsset(_asset1, assetData1); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); @@ -341,18 +345,18 @@ public void GetAssetsByPath_ThumbnailsAndFolderExistDifferentDirectory_ReturnsAs Asset[] assets1 = _testableAssetRepository.GetAssetsByPath(folderPath1); Assert.AreEqual(1, cataloguedAssets.Count); - Assert.AreEqual(asset1.FileName, cataloguedAssets[0].FileName); + Assert.AreEqual(_asset1.FileName, cataloguedAssets[0].FileName); Assert.AreEqual(2, thumbnails.Count); Assert.IsTrue(thumbnails.ContainsKey(folderPath1)); Assert.IsTrue(thumbnails.ContainsKey(folderPath2)); Assert.IsEmpty(thumbnails[folderPath1]); Assert.AreEqual(1, thumbnails[folderPath2].Count); - Assert.IsTrue(thumbnails[folderPath2].ContainsKey(asset1.FileName)); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath2][asset1.FileName]); + Assert.IsTrue(thumbnails[folderPath2].ContainsKey(_asset1.FileName)); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath2][_asset1.FileName]); Assert.AreEqual(1, assets1.Length); - Assert.AreEqual(asset1.FileName, assets1[0].FileName); + Assert.AreEqual(_asset1.FileName, assets1[0].FileName); _storageServiceMock!.Verify(x => x.LoadBitmapThumbnailImage(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); _storageServiceMock!.Verify(x => x.UpdateAssetFileDateTimeProperties(It.IsAny()), Times.Once); @@ -362,7 +366,7 @@ public void GetAssetsByPath_ThumbnailsAndFolderExistDifferentDirectory_ReturnsAs } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -370,13 +374,13 @@ public void GetAssetsByPath_ThumbnailsAndFolderExistDifferentDirectory_ReturnsAs [Test] public void GetAssetsByPath_AssetFolderIsNull_ReturnsEmptyArray() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); - byte[] assetData1 = new byte[] { 1, 2, 3 }; + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); + byte[] assetData1 = [1, 2, 3]; List cataloguedAssets = _testableAssetRepository!.GetCataloguedAssets(); Assert.IsEmpty(cataloguedAssets); @@ -384,7 +388,7 @@ public void GetAssetsByPath_AssetFolderIsNull_ReturnsEmptyArray() Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - _testableAssetRepository.AddAsset(asset1!, assetData1); + _testableAssetRepository.AddAsset(_asset1!, assetData1); Assert.IsEmpty(assetsUpdatedEvents); @@ -401,7 +405,7 @@ public void GetAssetsByPath_AssetFolderIsNull_ReturnsEmptyArray() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -409,18 +413,18 @@ public void GetAssetsByPath_AssetFolderIsNull_ReturnsEmptyArray() [Test] public void GetAssetsByPath_FolderDoesNotExist_ReturnsEmptyArray() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); Guid folderId = Guid.NewGuid(); Folder folder1 = new() { Path = folderPath, FolderId = folderId }; - asset1!.Folder = folder1; - asset1!.FolderId = folder1.FolderId; - byte[] assetData1 = new byte[] { 1, 2, 3 }; + _asset1!.Folder = folder1; + _asset1!.FolderId = folder1.FolderId; + byte[] assetData1 = [1, 2, 3]; List cataloguedAssets = _testableAssetRepository!.GetCataloguedAssets(); Assert.IsEmpty(cataloguedAssets); @@ -428,7 +432,7 @@ public void GetAssetsByPath_FolderDoesNotExist_ReturnsEmptyArray() Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - _testableAssetRepository.AddAsset(asset1!, assetData1); + _testableAssetRepository.AddAsset(_asset1!, assetData1); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); @@ -436,13 +440,13 @@ public void GetAssetsByPath_FolderDoesNotExist_ReturnsEmptyArray() Asset[] assets = _testableAssetRepository.GetAssetsByPath(folderPath); Assert.AreEqual(1, cataloguedAssets.Count); - Assert.AreEqual(asset1.FileName, cataloguedAssets[0].FileName); + Assert.AreEqual(_asset1.FileName, cataloguedAssets[0].FileName); Assert.AreEqual(1, thumbnails.Count); Assert.IsTrue(thumbnails.ContainsKey(folderPath)); Assert.AreEqual(1, thumbnails[folderPath].Count); - Assert.IsTrue(thumbnails[folderPath].ContainsKey(asset1.FileName)); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath][asset1.FileName]); + Assert.IsTrue(thumbnails[folderPath].ContainsKey(_asset1.FileName)); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath][_asset1.FileName]); Assert.IsEmpty(assets); @@ -454,7 +458,7 @@ public void GetAssetsByPath_FolderDoesNotExist_ReturnsEmptyArray() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -462,12 +466,12 @@ public void GetAssetsByPath_FolderDoesNotExist_ReturnsEmptyArray() [Test] public void GetAssetsByPath_ThumbnailDoesNotExist_ReturnsEmptyArray() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); _testableAssetRepository!.AddFolder(folderPath); List cataloguedAssets = _testableAssetRepository!.GetCataloguedAssets(); @@ -493,7 +497,7 @@ public void GetAssetsByPath_ThumbnailDoesNotExist_ReturnsEmptyArray() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -501,18 +505,18 @@ public void GetAssetsByPath_ThumbnailDoesNotExist_ReturnsEmptyArray() [Test] public void GetAssetsByPath_ThumbnailDoesNotExistButBinExists_ReturnsEmptyArray() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); Folder folder = _testableAssetRepository!.AddFolder(folderPath); Dictionary blobToWrite = new() { - { asset1!.FileName, new byte[] { 1, 2, 3 } }, - { asset2!.FileName, Array.Empty() } + { _asset1!.FileName, [1, 2, 3]}, + { _asset2!.FileName, [] } }; _database!.WriteBlob(blobToWrite, folder.ThumbnailsFilename); @@ -530,10 +534,10 @@ public void GetAssetsByPath_ThumbnailDoesNotExistButBinExists_ReturnsEmptyArray( Assert.AreEqual(1, thumbnails.Count); Assert.IsTrue(thumbnails.ContainsKey(folderPath)); Assert.AreEqual(2, thumbnails[folderPath].Count); - Assert.IsTrue(thumbnails[folderPath].ContainsKey(asset1.FileName)); - Assert.IsTrue(thumbnails[folderPath].ContainsKey(asset2.FileName)); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath][asset1.FileName]); - Assert.AreEqual(Array.Empty(), thumbnails[folderPath][asset2.FileName]); + Assert.IsTrue(thumbnails[folderPath].ContainsKey(_asset1.FileName)); + Assert.IsTrue(thumbnails[folderPath].ContainsKey(_asset2.FileName)); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath][_asset1.FileName]); + Assert.AreEqual(Array.Empty(), thumbnails[folderPath][_asset2.FileName]); Assert.IsEmpty(assets); @@ -544,7 +548,7 @@ public void GetAssetsByPath_ThumbnailDoesNotExistButBinExists_ReturnsEmptyArray( } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -552,12 +556,12 @@ public void GetAssetsByPath_ThumbnailDoesNotExistButBinExists_ReturnsEmptyArray( [Test] public void GetAssetsByPath_FolderAndThumbnailsDoNotExist_ReturnsEmptyArray() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath = Path.Combine(dataDirectory!, "NewFolder"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder"); List cataloguedAssets = _testableAssetRepository!.GetCataloguedAssets(); Assert.IsEmpty(cataloguedAssets); @@ -578,7 +582,7 @@ public void GetAssetsByPath_FolderAndThumbnailsDoNotExist_ReturnsEmptyArray() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -586,18 +590,18 @@ public void GetAssetsByPath_FolderAndThumbnailsDoNotExist_ReturnsEmptyArray() [Test] public void GetAssetsByPath_DirectoryIsNull_ReturnsEmptyArray() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { string? directory = null; - string folderPath = Path.Combine(dataDirectory!, "NewFolder1"); + string folderPath = Path.Combine(_dataDirectory!, "NewFolder1"); Folder folder = _testableAssetRepository!.AddFolder(folderPath); - asset1!.Folder = folder; - asset1!.FolderId = folder.FolderId; - byte[] assetData1 = new byte[] { 1, 2, 3 }; + _asset1!.Folder = folder; + _asset1!.FolderId = folder.FolderId; + byte[] assetData1 = [1, 2, 3]; List cataloguedAssets = _testableAssetRepository!.GetCataloguedAssets(); Assert.IsEmpty(cataloguedAssets); @@ -605,7 +609,7 @@ public void GetAssetsByPath_DirectoryIsNull_ReturnsEmptyArray() Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - _testableAssetRepository.AddAsset(asset1, assetData1); + _testableAssetRepository.AddAsset(_asset1, assetData1); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); @@ -613,13 +617,13 @@ public void GetAssetsByPath_DirectoryIsNull_ReturnsEmptyArray() Asset[] assets1 = _testableAssetRepository.GetAssetsByPath(directory!); Assert.AreEqual(1, cataloguedAssets.Count); - Assert.AreEqual(asset1.FileName, cataloguedAssets[0].FileName); + Assert.AreEqual(_asset1.FileName, cataloguedAssets[0].FileName); Assert.AreEqual(1, thumbnails.Count); Assert.IsTrue(thumbnails.ContainsKey(folderPath)); Assert.AreEqual(1, thumbnails[folderPath].Count); - Assert.IsTrue(thumbnails[folderPath].ContainsKey(asset1.FileName)); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath][asset1.FileName]); + Assert.IsTrue(thumbnails[folderPath].ContainsKey(_asset1.FileName)); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath][_asset1.FileName]); Assert.IsEmpty(assets1); @@ -631,7 +635,7 @@ public void GetAssetsByPath_DirectoryIsNull_ReturnsEmptyArray() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -640,28 +644,28 @@ public void GetAssetsByPath_DirectoryIsNull_ReturnsEmptyArray() public void GetAssetsByPath_ExceptionThrown_ReturnsAssetsWithPartialData() { Mock storageService = new(); - storageService.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath!); + storageService.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath!); storageService.Setup(x => x.LoadBitmapThumbnailImage(It.IsAny(), It.IsAny(), It.IsAny())).Throws(new Exception()); storageService.Setup(x => x.UpdateAssetFileDateTimeProperties(It.IsAny())); UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); TestableAssetRepository testableAssetRepository = new (_database!, storageService.Object, userConfigurationService); - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = testableAssetRepository.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "NewFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "NewFolder1"); Folder folder1 = testableAssetRepository.AddFolder(folderPath1); - asset1!.Folder = folder1; - asset1!.FolderId = folder1.FolderId; - byte[] assetData1 = new byte[] { 1, 2, 3 }; + _asset1!.Folder = folder1; + _asset1!.FolderId = folder1.FolderId; + byte[] assetData1 = [1, 2, 3]; - asset2!.Folder = folder1; - asset2!.FolderId = folder1.FolderId; - byte[] assetData2 = Array.Empty(); + _asset2!.Folder = folder1; + _asset2!.FolderId = folder1.FolderId; + byte[] assetData2 = []; List cataloguedAssets = testableAssetRepository.GetCataloguedAssets(); Assert.IsEmpty(cataloguedAssets); @@ -669,8 +673,8 @@ public void GetAssetsByPath_ExceptionThrown_ReturnsAssetsWithPartialData() Dictionary> thumbnails = testableAssetRepository.GetThumbnails(); Assert.IsEmpty(thumbnails); - testableAssetRepository.AddAsset(asset1, assetData1); - testableAssetRepository.AddAsset(asset2, assetData2); + testableAssetRepository.AddAsset(_asset1, assetData1); + testableAssetRepository.AddAsset(_asset2, assetData2); Assert.AreEqual(2, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); @@ -679,23 +683,23 @@ public void GetAssetsByPath_ExceptionThrown_ReturnsAssetsWithPartialData() Asset[] assets1 = testableAssetRepository.GetAssetsByPath(folderPath1); Assert.AreEqual(2, cataloguedAssets.Count); - Assert.AreEqual(asset1.FileName, cataloguedAssets[0].FileName); - Assert.AreEqual(asset2!.FileName, cataloguedAssets[1].FileName); + Assert.AreEqual(_asset1.FileName, cataloguedAssets[0].FileName); + Assert.AreEqual(_asset2!.FileName, cataloguedAssets[1].FileName); Assert.AreEqual(1, thumbnails.Count); Assert.IsTrue(thumbnails.ContainsKey(folderPath1)); Assert.AreEqual(2, thumbnails[folderPath1].Count); - Assert.IsTrue(thumbnails[folderPath1].ContainsKey(asset1.FileName)); - Assert.IsTrue(thumbnails[folderPath1].ContainsKey(asset2.FileName)); + Assert.IsTrue(thumbnails[folderPath1].ContainsKey(_asset1.FileName)); + Assert.IsTrue(thumbnails[folderPath1].ContainsKey(_asset2.FileName)); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath1][asset1.FileName]); - Assert.AreEqual(Array.Empty(), thumbnails[folderPath1][asset2.FileName]); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath1][_asset1.FileName]); + Assert.AreEqual(Array.Empty(), thumbnails[folderPath1][_asset2.FileName]); Assert.AreEqual(2, assets1.Length); - Assert.AreEqual(asset1.FileName, assets1[0].FileName); - Assert.AreEqual(asset2.FileName, assets1[1].FileName); + Assert.AreEqual(_asset1.FileName, assets1[0].FileName); + Assert.AreEqual(_asset2.FileName, assets1[1].FileName); storageService.Verify(x => x.LoadBitmapThumbnailImage(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); storageService.Verify(x => x.UpdateAssetFileDateTimeProperties(It.IsAny()), Times.Never); @@ -706,7 +710,7 @@ public void GetAssetsByPath_ExceptionThrown_ReturnsAssetsWithPartialData() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -714,27 +718,27 @@ public void GetAssetsByPath_ExceptionThrown_ReturnsAssetsWithPartialData() [Test] public void GetAssetsByPath_ConcurrentAccess_AssetsAreHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "NewFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "NewFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "NewFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "NewFolder2"); Folder folder1 = _testableAssetRepository!.AddFolder(folderPath1); Folder folder2 = _testableAssetRepository!.AddFolder(folderPath2); - asset1!.Folder = folder1; - asset1!.FolderId = folder1.FolderId; - byte[] assetData1 = new byte[] { 1, 2, 3 }; + _asset1!.Folder = folder1; + _asset1!.FolderId = folder1.FolderId; + byte[] assetData1 = [1, 2, 3]; - asset2!.Folder = folder1; - asset2!.FolderId = folder1.FolderId; - byte[] assetData2 = Array.Empty(); + _asset2!.Folder = folder1; + _asset2!.FolderId = folder1.FolderId; + byte[] assetData2 = []; - asset3!.Folder = folder2; - asset3!.FolderId = folder2.FolderId; - byte[] assetData3 = new byte[] { 4, 5, 6 }; + _asset3!.Folder = folder2; + _asset3!.FolderId = folder2.FolderId; + byte[] assetData3 = [4, 5, 6]; List cataloguedAssets = _testableAssetRepository!.GetCataloguedAssets(); Assert.IsEmpty(cataloguedAssets); @@ -742,17 +746,17 @@ public void GetAssetsByPath_ConcurrentAccess_AssetsAreHandledSafely() Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - _testableAssetRepository.AddAsset(asset1, assetData1); - _testableAssetRepository.AddAsset(asset2, assetData2); - _testableAssetRepository.AddAsset(asset3, assetData3); + _testableAssetRepository.AddAsset(_asset1, assetData1); + _testableAssetRepository.AddAsset(_asset2, assetData2); + _testableAssetRepository.AddAsset(_asset3, assetData3); Assert.AreEqual(3, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[1]); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[2]); - Asset[] assets1 = Array.Empty(); - Asset[] assets2 = Array.Empty(); + Asset[] assets1 = []; + Asset[] assets2 = []; // Simulate concurrent access Parallel.Invoke( @@ -761,9 +765,9 @@ public void GetAssetsByPath_ConcurrentAccess_AssetsAreHandledSafely() ); Assert.AreEqual(3, cataloguedAssets.Count); - Assert.AreEqual(asset1.FileName, cataloguedAssets[0].FileName); - Assert.AreEqual(asset2!.FileName, cataloguedAssets[1].FileName); - Assert.AreEqual(asset3!.FileName, cataloguedAssets[2].FileName); + Assert.AreEqual(_asset1.FileName, cataloguedAssets[0].FileName); + Assert.AreEqual(_asset2!.FileName, cataloguedAssets[1].FileName); + Assert.AreEqual(_asset3!.FileName, cataloguedAssets[2].FileName); Assert.AreEqual(2, thumbnails.Count); Assert.IsTrue(thumbnails.ContainsKey(folderPath1)); @@ -772,20 +776,20 @@ public void GetAssetsByPath_ConcurrentAccess_AssetsAreHandledSafely() Assert.AreEqual(2, thumbnails[folderPath1].Count); Assert.AreEqual(1, thumbnails[folderPath2].Count); - Assert.IsTrue(thumbnails[folderPath1].ContainsKey(asset1.FileName)); - Assert.IsTrue(thumbnails[folderPath1].ContainsKey(asset2.FileName)); - Assert.IsTrue(thumbnails[folderPath2].ContainsKey(asset3.FileName)); + Assert.IsTrue(thumbnails[folderPath1].ContainsKey(_asset1.FileName)); + Assert.IsTrue(thumbnails[folderPath1].ContainsKey(_asset2.FileName)); + Assert.IsTrue(thumbnails[folderPath2].ContainsKey(_asset3.FileName)); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath1][asset1.FileName]); - Assert.AreEqual(Array.Empty(), thumbnails[folderPath1][asset2.FileName]); - Assert.AreEqual(new byte[] { 4, 5, 6 }, thumbnails[folderPath2][asset3.FileName]); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[folderPath1][_asset1.FileName]); + Assert.AreEqual(Array.Empty(), thumbnails[folderPath1][_asset2.FileName]); + Assert.AreEqual(new byte[] { 4, 5, 6 }, thumbnails[folderPath2][_asset3.FileName]); Assert.AreEqual(2, assets1.Length); Assert.AreEqual(1, assets2.Length); - Assert.AreEqual(asset1.FileName, assets1[0].FileName); - Assert.AreEqual(asset2!.FileName, assets1[1].FileName); - Assert.AreEqual(asset3!.FileName, assets2[0].FileName); + Assert.AreEqual(_asset1.FileName, assets1[0].FileName); + Assert.AreEqual(_asset2!.FileName, assets1[1].FileName); + Assert.AreEqual(_asset3!.FileName, assets2[0].FileName); _storageServiceMock!.Verify(x => x.LoadBitmapThumbnailImage(It.IsAny(), It.IsAny(), It.IsAny()), Times.Exactly(3)); _storageServiceMock!.Verify(x => x.UpdateAssetFileDateTimeProperties(It.IsAny()), Times.Exactly(3)); @@ -797,7 +801,7 @@ public void GetAssetsByPath_ConcurrentAccess_AssetsAreHandledSafely() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetAssetsCounterTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetAssetsCounterTests.cs index a67cd967..41dc114a 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetAssetsCounterTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetAssetsCounterTests.cs @@ -9,7 +9,7 @@ public class AssetRepositoryGetAssetsCounterTests private string? _backupPath; private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; - private IAssetRepository? _assetRepository; + private AssetRepository? _assetRepository; private Mock? _storageServiceMock; private Mock? _configurationRootMock; @@ -35,10 +35,11 @@ public void SetUp() { PhotoManager.Infrastructure.Database.Database database = new (new ObjectListStorage(), new BlobStorage(), new BackupStorage()); UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); - _assetRepository = new AssetRepository(database, _storageServiceMock!.Object, userConfigurationService); + _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); _asset1 = new() { + Folder = new() { Path = "" }, FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), FileName = "Image 1.jpg", FileSize = 363888, @@ -56,6 +57,7 @@ public void SetUp() }; _asset2 = new() { + Folder = new() { Path = "" }, FolderId = new Guid("68493435-e299-4bb5-9e02-214da41d0256"), FileName = "Image 9.png", FileSize = 4602393, @@ -73,6 +75,7 @@ public void SetUp() }; _asset3 = new() { + Folder = new() { Path = "" }, FolderId = new Guid("f91b8c81-6938-431a-a689-d86c7c4db126"), FileName = "Image_11.heic", FileSize = 2247285, @@ -93,7 +96,7 @@ public void SetUp() [Test] public void GetAssetsCounter_AssetsExist_ReturnsNumberOfAssets() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -159,7 +162,7 @@ public void GetAssetsCounter_AssetsExist_ReturnsNumberOfAssets() [Test] public void GetAssetsCounter_NoAsset_Returns0() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -180,7 +183,7 @@ public void GetAssetsCounter_NoAsset_Returns0() [Test] public void GetAssetsCounter_ConcurrentAccess_AssetsAreHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetCataloguedAssetsByPathTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetCataloguedAssetsByPathTests.cs index 22d9d3da..5c3ea8aa 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetCataloguedAssetsByPathTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetCataloguedAssetsByPathTests.cs @@ -5,27 +5,27 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositoryGetCataloguedAssetsByPathTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; - private IAssetRepository? _assetRepository; + private AssetRepository? _assetRepository; private Mock? _storageServiceMock; private Mock? _configurationRootMock; - private Asset? asset1; + private Asset? _asset1; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -33,10 +33,11 @@ public void SetUp() { PhotoManager.Infrastructure.Database.Database database = new (new ObjectListStorage(), new BlobStorage(), new BackupStorage()); UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); - _assetRepository = new AssetRepository(database, _storageServiceMock!.Object, userConfigurationService); + _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); - asset1 = new() + _asset1 = new() { + Folder = new() { Path = "" }, FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), FileName = "Image 1.jpg", FileSize = 363888, @@ -57,20 +58,20 @@ public void SetUp() [Test] public void GetCataloguedAssetsByPath_FolderAndAssetExist_ReturnsMatchingAssets() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "TestFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "TestFolder2"); Folder addedFolder1 = _assetRepository!.AddFolder(folderPath1); _assetRepository!.AddFolder(folderPath2); - asset1!.Folder = addedFolder1; - asset1!.FolderId = addedFolder1.FolderId; - _assetRepository!.AddAsset(asset1!, Array.Empty()); + _asset1!.Folder = addedFolder1; + _asset1!.FolderId = addedFolder1.FolderId; + _assetRepository!.AddAsset(_asset1!, []); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); @@ -81,14 +82,14 @@ public void GetCataloguedAssetsByPath_FolderAndAssetExist_ReturnsMatchingAssets( Assert.AreEqual(1, cataloguedAssets1.Count); Assert.IsEmpty(cataloguedAssets2); - Assert.IsTrue(cataloguedAssets1.FirstOrDefault(x => x.Hash == asset1.Hash)?.FileName == asset1.FileName); + Assert.IsTrue(cataloguedAssets1.FirstOrDefault(x => x.Hash == _asset1.Hash)?.FileName == _asset1.FileName); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -96,19 +97,19 @@ public void GetCataloguedAssetsByPath_FolderAndAssetExist_ReturnsMatchingAssets( [Test] public void GetCataloguedAssetsByPath_DirectoryWithNoFolder_ReturnsEmptyList() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "TestFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "TestFolder2"); Folder addedFolder1 = _assetRepository!.AddFolder(folderPath1); - asset1!.Folder = addedFolder1; - asset1!.FolderId = addedFolder1.FolderId; - _assetRepository!.AddAsset(asset1!, Array.Empty()); + _asset1!.Folder = addedFolder1; + _asset1!.FolderId = addedFolder1.FolderId; + _assetRepository!.AddAsset(_asset1!, []); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); @@ -122,7 +123,7 @@ public void GetCataloguedAssetsByPath_DirectoryWithNoFolder_ReturnsEmptyList() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -130,19 +131,19 @@ public void GetCataloguedAssetsByPath_DirectoryWithNoFolder_ReturnsEmptyList() [Test] public void GetCataloguedAssetsByPath_DirectoryIsNull_ReturnsEmptyList() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); string? folderPath2 = null; Folder addedFolder1 = _assetRepository!.AddFolder(folderPath1); - asset1!.Folder = addedFolder1; - asset1!.FolderId = addedFolder1.FolderId; - _assetRepository!.AddAsset(asset1!, Array.Empty()); + _asset1!.Folder = addedFolder1; + _asset1!.FolderId = addedFolder1.FolderId; + _assetRepository!.AddAsset(_asset1!, []); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); @@ -156,7 +157,7 @@ public void GetCataloguedAssetsByPath_DirectoryIsNull_ReturnsEmptyList() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -164,26 +165,26 @@ public void GetCataloguedAssetsByPath_DirectoryIsNull_ReturnsEmptyList() [Test] public void GetCataloguedAssetsByPath_ConcurrentAccess_AssetsAreHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "TestFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "TestFolder2"); Folder addedFolder1 = _assetRepository!.AddFolder(folderPath1); _assetRepository!.AddFolder(folderPath2); - asset1!.Folder = addedFolder1; - asset1!.FolderId = addedFolder1.FolderId; - _assetRepository!.AddAsset(asset1!, Array.Empty()); + _asset1!.Folder = addedFolder1; + _asset1!.FolderId = addedFolder1.FolderId; + _assetRepository!.AddAsset(_asset1!, []); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); - List cataloguedAssets1 = new(); - List cataloguedAssets2 = new(); + List cataloguedAssets1 = []; + List cataloguedAssets2 = []; // Simulate concurrent access Parallel.Invoke( @@ -194,14 +195,14 @@ public void GetCataloguedAssetsByPath_ConcurrentAccess_AssetsAreHandledSafely() Assert.AreEqual(1, cataloguedAssets1.Count); Assert.IsEmpty(cataloguedAssets2); - Assert.IsTrue(cataloguedAssets1.FirstOrDefault(x => x.Hash == asset1.Hash)?.FileName == asset1.FileName); + Assert.IsTrue(cataloguedAssets1.FirstOrDefault(x => x.Hash == _asset1.Hash)?.FileName == _asset1.FileName); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetCataloguedAssetsTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetCataloguedAssetsTests.cs index d9d3ca81..5b28f2f5 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetCataloguedAssetsTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetCataloguedAssetsTests.cs @@ -5,28 +5,28 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositoryGetCataloguedAssetsTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; - private IAssetRepository? _assetRepository; + private AssetRepository? _assetRepository; private Mock? _storageServiceMock; private Mock? _configurationRootMock; - private Asset? asset1; - private Asset? asset2; + private Asset? _asset1; + private Asset? _asset2; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -34,10 +34,11 @@ public void SetUp() { PhotoManager.Infrastructure.Database.Database database = new (new ObjectListStorage(), new BlobStorage(), new BackupStorage()); UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); - _assetRepository = new AssetRepository(database, _storageServiceMock!.Object, userConfigurationService); + _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); - asset1 = new() + _asset1 = new() { + Folder = new() { Path = "" }, FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), FileName = "Image 1.jpg", FileSize = 363888, @@ -53,8 +54,9 @@ public void SetUp() AssetRotatedMessage = null, IsAssetRotated = false }; - asset2 = new() + _asset2 = new() { + Folder = new() { Path = "" }, FolderId = new Guid("68493435-e299-4bb5-9e02-214da41d0256"), FileName = "Image 9.png", FileSize = 4602393, @@ -75,25 +77,25 @@ public void SetUp() [Test] public void GetCataloguedAssets_AssetsCatalogued_ReturnsEmptyList() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "NewFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "NewFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "NewFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "NewFolder2"); - asset1!.Folder = new() + _asset1!.Folder = new() { Path = folderPath1 }; - asset2!.Folder = new() + _asset2!.Folder = new() { Path = folderPath2 }; - _assetRepository!.AddAsset(asset1!, Array.Empty()); - _assetRepository!.AddAsset(asset2!, Array.Empty()); + _assetRepository!.AddAsset(_asset1!, []); + _assetRepository!.AddAsset(_asset2!, []); Assert.IsTrue(_assetRepository.HasChanges()); @@ -105,8 +107,8 @@ public void GetCataloguedAssets_AssetsCatalogued_ReturnsEmptyList() Assert.IsNotEmpty(assets); Assert.AreEqual(2, assets.Count); - Assert.IsTrue(assets.FirstOrDefault(x => x.Hash == asset1.Hash)?.FileName == asset1.FileName); - Assert.IsTrue(assets.FirstOrDefault(x => x.Hash == asset2.Hash)?.FileName == asset2.FileName); + Assert.IsTrue(assets.FirstOrDefault(x => x.Hash == _asset1.Hash)?.FileName == _asset1.FileName); + Assert.IsTrue(assets.FirstOrDefault(x => x.Hash == _asset2.Hash)?.FileName == _asset2.FileName); Assert.AreEqual(2, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); @@ -114,7 +116,7 @@ public void GetCataloguedAssets_AssetsCatalogued_ReturnsEmptyList() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -122,7 +124,7 @@ public void GetCataloguedAssets_AssetsCatalogued_ReturnsEmptyList() [Test] public void GetCataloguedAssets_NoAssetCatalogued_ReturnsEmptyList() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -135,7 +137,7 @@ public void GetCataloguedAssets_NoAssetCatalogued_ReturnsEmptyList() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -143,25 +145,25 @@ public void GetCataloguedAssets_NoAssetCatalogued_ReturnsEmptyList() [Test] public void GetCataloguedAssets_ConcurrentAccess_AssetsAreHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "NewFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "NewFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "NewFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "NewFolder2"); - asset1!.Folder = new() + _asset1!.Folder = new() { Path = folderPath1 }; - asset2!.Folder = new() + _asset2!.Folder = new() { Path = folderPath2 }; - _assetRepository!.AddAsset(asset1!, Array.Empty()); - _assetRepository!.AddAsset(asset2!, Array.Empty()); + _assetRepository!.AddAsset(_asset1!, []); + _assetRepository!.AddAsset(_asset2!, []); Assert.IsTrue(_assetRepository.HasChanges()); @@ -169,9 +171,9 @@ public void GetCataloguedAssets_ConcurrentAccess_AssetsAreHandledSafely() Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[1]); - List assets1 = new(); - List assets2 = new(); - List assets3 = new(); + List assets1 = []; + List assets2 = []; + List assets3 = []; // Simulate concurrent access Parallel.Invoke( @@ -182,18 +184,18 @@ public void GetCataloguedAssets_ConcurrentAccess_AssetsAreHandledSafely() Assert.IsNotEmpty(assets1); Assert.AreEqual(2, assets1.Count); - Assert.IsTrue(assets1.FirstOrDefault(x => x.Hash == asset1.Hash)?.FileName == asset1.FileName); - Assert.IsTrue(assets1.FirstOrDefault(x => x.Hash == asset2.Hash)?.FileName == asset2.FileName); + Assert.IsTrue(assets1.FirstOrDefault(x => x.Hash == _asset1.Hash)?.FileName == _asset1.FileName); + Assert.IsTrue(assets1.FirstOrDefault(x => x.Hash == _asset2.Hash)?.FileName == _asset2.FileName); Assert.IsNotEmpty(assets2); Assert.AreEqual(2, assets2.Count); - Assert.IsTrue(assets2.FirstOrDefault(x => x.Hash == asset1.Hash)?.FileName == asset1.FileName); - Assert.IsTrue(assets2.FirstOrDefault(x => x.Hash == asset2.Hash)?.FileName == asset2.FileName); + Assert.IsTrue(assets2.FirstOrDefault(x => x.Hash == _asset1.Hash)?.FileName == _asset1.FileName); + Assert.IsTrue(assets2.FirstOrDefault(x => x.Hash == _asset2.Hash)?.FileName == _asset2.FileName); Assert.IsNotEmpty(assets3); Assert.AreEqual(2, assets3.Count); - Assert.IsTrue(assets3.FirstOrDefault(x => x.Hash == asset1.Hash)?.FileName == asset1.FileName); - Assert.IsTrue(assets3.FirstOrDefault(x => x.Hash == asset2.Hash)?.FileName == asset2.FileName); + Assert.IsTrue(assets3.FirstOrDefault(x => x.Hash == _asset1.Hash)?.FileName == _asset1.FileName); + Assert.IsTrue(assets3.FirstOrDefault(x => x.Hash == _asset2.Hash)?.FileName == _asset2.FileName); Assert.AreEqual(2, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); @@ -201,7 +203,7 @@ public void GetCataloguedAssets_ConcurrentAccess_AssetsAreHandledSafely() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetFolderByPathTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetFolderByPathTests.cs index 2392fe8d..d1e7a57b 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetFolderByPathTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetFolderByPathTests.cs @@ -5,25 +5,25 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositoryGetFolderByPathTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; - private IAssetRepository? _assetRepository; + private AssetRepository? _assetRepository; private Mock? _storageServiceMock; private Mock? _configurationRootMock; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -31,19 +31,19 @@ public void SetUp() { PhotoManager.Infrastructure.Database.Database database = new (new ObjectListStorage(), new BlobStorage(), new BackupStorage()); UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); - _assetRepository = new AssetRepository(database, _storageServiceMock!.Object, userConfigurationService); + _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); } [Test] public void GetFolderByPath_DifferentPaths_ReturnsCorrectFolder() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "TestFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "TestFolder2"); Folder addedFolder1 = _assetRepository!.AddFolder(folderPath1); Folder addedFolder2 = _assetRepository!.AddFolder(folderPath2); @@ -64,7 +64,7 @@ public void GetFolderByPath_DifferentPaths_ReturnsCorrectFolder() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -72,12 +72,12 @@ public void GetFolderByPath_DifferentPaths_ReturnsCorrectFolder() [Test] public void GetFolderByPath_SamePath_ReturnsFirstFolder() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); Folder addedFolder1 = _assetRepository!.AddFolder(folderPath1); Folder addedFolder2 = _assetRepository!.AddFolder(folderPath1); @@ -98,7 +98,7 @@ public void GetFolderByPath_SamePath_ReturnsFirstFolder() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -106,12 +106,12 @@ public void GetFolderByPath_SamePath_ReturnsFirstFolder() [Test] public void GetFolderByPath_PathNotRegistered_ReturnsNull() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); Folder? folderByPath1 = _assetRepository!.GetFolderByPath(folderPath1); @@ -122,7 +122,7 @@ public void GetFolderByPath_PathNotRegistered_ReturnsNull() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -130,14 +130,14 @@ public void GetFolderByPath_PathNotRegistered_ReturnsNull() [Test] public void GetFolderByPath_PathIsNull_ReturnsNull() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { string? folderPath1 = null; - _assetRepository!.AddFolder(Path.Combine(dataDirectory!, "TestFolder1")); + _assetRepository!.AddFolder(Path.Combine(_dataDirectory!, "TestFolder1")); Folder? folderByPath1 = _assetRepository!.GetFolderByPath(folderPath1!); @@ -147,7 +147,7 @@ public void GetFolderByPath_PathIsNull_ReturnsNull() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -155,19 +155,19 @@ public void GetFolderByPath_PathIsNull_ReturnsNull() [Test] public void GetFolderByPath_ConcurrentAccess_FoldersAreHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "TestFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "TestFolder2"); Folder addedFolder1 = _assetRepository!.AddFolder(folderPath1); Folder addedFolder2 = _assetRepository!.AddFolder(folderPath2); - Folder? folderByPath1 = new() { Path = dataDirectory! }; - Folder? folderByPath2 = new() { Path = dataDirectory! }; + Folder? folderByPath1 = new() { Path = _dataDirectory! }; + Folder? folderByPath2 = new() { Path = _dataDirectory! }; // Simulate concurrent access Parallel.Invoke( @@ -188,7 +188,7 @@ public void GetFolderByPath_ConcurrentAccess_FoldersAreHandledSafely() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetFoldersPathTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetFoldersPathTests.cs index 05d373fd..d498648a 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetFoldersPathTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetFoldersPathTests.cs @@ -6,8 +6,8 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; public class AssetRepositoryGetFoldersPathTests { private string? _dataDirectory; - private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; private AssetRepository? _assetRepository; private Mock? _storageServiceMock; @@ -31,13 +31,13 @@ public void SetUp() { PhotoManager.Infrastructure.Database.Database database = new (new ObjectListStorage(), new BlobStorage(), new BackupStorage()); UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); - _assetRepository = new AssetRepository(database, _storageServiceMock!.Object, userConfigurationService); + _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); } [Test] public void GetFoldersPath_Folders_ReturnsCorrectFoldersPath() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -68,7 +68,7 @@ public void GetFoldersPath_Folders_ReturnsCorrectFoldersPath() [Test] public void GetFoldersPath_NoFolders_ReturnsEmptyHashSet() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -89,7 +89,7 @@ public void GetFoldersPath_NoFolders_ReturnsEmptyHashSet() [Test] public void GetFoldersPath_ConcurrentAccess_FoldersPathAreHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetFoldersTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetFoldersTests.cs index bb796060..0267b727 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetFoldersTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetFoldersTests.cs @@ -6,8 +6,8 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; public class AssetRepositoryGetFoldersTests { private string? _dataDirectory; - private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; private AssetRepository? _assetRepository; private Mock? _storageServiceMock; @@ -31,13 +31,13 @@ public void SetUp() { PhotoManager.Infrastructure.Database.Database database = new (new ObjectListStorage(), new BlobStorage(), new BackupStorage()); UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); - _assetRepository = new AssetRepository(database, _storageServiceMock!.Object, userConfigurationService); + _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); } [Test] public void GetFolders_Folders_ReturnsCorrectFolders() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -68,7 +68,7 @@ public void GetFolders_Folders_ReturnsCorrectFolders() [Test] public void GetFolders_NoFolders_ReturnsEmptyArray() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -89,7 +89,7 @@ public void GetFolders_NoFolders_ReturnsEmptyArray() [Test] public void GetFolders_ConcurrentAccess_FoldersAreHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetRecentTargetPathsTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetRecentTargetPathsTests.cs index 0212b685..b65fc507 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetRecentTargetPathsTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetRecentTargetPathsTests.cs @@ -5,25 +5,25 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositoryGetRecentTargetPathsTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; - private IAssetRepository? _assetRepository; + private AssetRepository? _assetRepository; private Mock? _storageServiceMock; private Mock? _configurationRootMock; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -31,22 +31,22 @@ public void SetUp() { PhotoManager.Infrastructure.Database.Database database = new (new ObjectListStorage(), new BlobStorage(), new BackupStorage()); UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); - _assetRepository = new AssetRepository(database, _storageServiceMock!.Object, userConfigurationService); + _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); } [Test] public void GetRecentTargetPaths_RecentTargetPaths_ReturnsRecentTargetPaths() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - List recentTargetPathsToSave = new() - { + List recentTargetPathsToSave = + [ "D:\\Workspace\\PhotoManager\\Toto", "D:\\Workspace\\PhotoManager\\Tutu" - }; + ]; _assetRepository!.SaveRecentTargetPaths(recentTargetPathsToSave); List recentTargetPaths = _assetRepository.GetRecentTargetPaths(); @@ -59,7 +59,7 @@ public void GetRecentTargetPaths_RecentTargetPaths_ReturnsRecentTargetPaths() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -67,7 +67,7 @@ public void GetRecentTargetPaths_RecentTargetPaths_ReturnsRecentTargetPaths() [Test] public void GetRecentTargetPaths_NoRecentTargetPaths_ReturnsEmptyList() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -80,7 +80,7 @@ public void GetRecentTargetPaths_NoRecentTargetPaths_ReturnsEmptyList() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -88,22 +88,22 @@ public void GetRecentTargetPaths_NoRecentTargetPaths_ReturnsEmptyList() [Test] public void GetRecentTargetPaths_ConcurrentAccess_RecentTargetPathsAreHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - List recentTargetPathsToSave = new() - { + List recentTargetPathsToSave = + [ "D:\\Workspace\\PhotoManager\\Toto", "D:\\Workspace\\PhotoManager\\Tutu" - }; + ]; _assetRepository!.SaveRecentTargetPaths(recentTargetPathsToSave); - List recentTargetPaths1 = new(); - List recentTargetPaths2 = new(); - List recentTargetPaths3 = new(); + List recentTargetPaths1 = []; + List recentTargetPaths2 = []; + List recentTargetPaths3 = []; // Simulate concurrent access Parallel.Invoke( @@ -128,7 +128,7 @@ public void GetRecentTargetPaths_ConcurrentAccess_RecentTargetPathsAreHandledSaf } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetSubFoldersTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetSubFoldersTests.cs index 5b13dea2..9b80fb52 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetSubFoldersTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetSubFoldersTests.cs @@ -5,25 +5,25 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositoryGetSubFoldersTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; - private IAssetRepository? _assetRepository; + private AssetRepository? _assetRepository; private Mock? _storageServiceMock; private Mock? _configurationRootMock; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -31,19 +31,19 @@ public void SetUp() { PhotoManager.Infrastructure.Database.Database database = new (new ObjectListStorage(), new BlobStorage(), new BackupStorage()); UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); - _assetRepository = new AssetRepository(database, _storageServiceMock!.Object, userConfigurationService); + _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); } [Test] public void GetSubFolders_ParentHasSubFolders_ReturnsMatchingSubFolders() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string parentFolderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); - string parentFolderPath2 = Path.Combine(dataDirectory!, "TestFolder2"); + string parentFolderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); + string parentFolderPath2 = Path.Combine(_dataDirectory!, "TestFolder2"); string childFolderPath1 = Path.Combine(parentFolderPath1, "TestSubFolder1"); string childFolderPath2 = Path.Combine(parentFolderPath2, "TestSubFolder2"); @@ -80,7 +80,7 @@ public void GetSubFolders_ParentHasSubFolders_ReturnsMatchingSubFolders() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -88,13 +88,13 @@ public void GetSubFolders_ParentHasSubFolders_ReturnsMatchingSubFolders() [Test] public void GetSubFolders_ParentHasNoSubFolders_ReturnsEmptyArray() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string parentFolderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); - string parentFolderPath2 = Path.Combine(dataDirectory!, "TestFolder2"); + string parentFolderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); + string parentFolderPath2 = Path.Combine(_dataDirectory!, "TestFolder2"); Folder parentFolder1 = _assetRepository!.AddFolder(parentFolderPath1); Folder parentFolder2 = _assetRepository!.AddFolder(parentFolderPath2); @@ -109,7 +109,7 @@ public void GetSubFolders_ParentHasNoSubFolders_ReturnsEmptyArray() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -117,13 +117,13 @@ public void GetSubFolders_ParentHasNoSubFolders_ReturnsEmptyArray() [Test] public void GetSubFolders_NoFoldersRegistered_ReturnsEmptyArray() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string parentFolderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); - string parentFolderPath2 = Path.Combine(dataDirectory!, "TestFolder2"); + string parentFolderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); + string parentFolderPath2 = Path.Combine(_dataDirectory!, "TestFolder2"); Folder parentFolder1 = new() { Path = parentFolderPath1 }; Folder parentFolder2 = new() { Path = parentFolderPath2 }; @@ -138,7 +138,7 @@ public void GetSubFolders_NoFoldersRegistered_ReturnsEmptyArray() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -146,14 +146,14 @@ public void GetSubFolders_NoFoldersRegistered_ReturnsEmptyArray() [Test] public void GetSubFolders_ParentFolderIsNull_ThrowsArgumentException() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { Folder? parentFolder1 = null; - string parentFolderPath2 = Path.Combine(dataDirectory!, "TestFolder2"); + string parentFolderPath2 = Path.Combine(_dataDirectory!, "TestFolder2"); _assetRepository!.AddFolder(parentFolderPath2); // At least one folder to trigger the Where on folders @@ -165,7 +165,7 @@ public void GetSubFolders_ParentFolderIsNull_ThrowsArgumentException() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetSyncAssetsConfigurationTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetSyncAssetsConfigurationTests.cs index a71ab67f..0fa04ce7 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetSyncAssetsConfigurationTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryGetSyncAssetsConfigurationTests.cs @@ -5,25 +5,25 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositoryGetSyncAssetsConfigurationTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; - private IAssetRepository? _assetRepository; + private AssetRepository? _assetRepository; private Mock? _storageServiceMock; private Mock? _configurationRootMock; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -31,13 +31,13 @@ public void SetUp() { PhotoManager.Infrastructure.Database.Database database = new (new ObjectListStorage(), new BlobStorage(), new BackupStorage()); UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); - _assetRepository = new AssetRepository(database, _storageServiceMock!.Object, userConfigurationService); + _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); } [Test] public void GetSyncAssetsConfiguration_SyncAssetsConfiguration_ReturnsSyncAssetsConfiguration() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -73,7 +73,7 @@ public void GetSyncAssetsConfiguration_SyncAssetsConfiguration_ReturnsSyncAssets } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -81,7 +81,7 @@ public void GetSyncAssetsConfiguration_SyncAssetsConfiguration_ReturnsSyncAssets [Test] public void GetSyncAssetsConfiguration_NoSyncAssetsConfiguration_ReturnsEmptyList() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -94,7 +94,7 @@ public void GetSyncAssetsConfiguration_NoSyncAssetsConfiguration_ReturnsEmptyLis } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -102,7 +102,7 @@ public void GetSyncAssetsConfiguration_NoSyncAssetsConfiguration_ReturnsEmptyLis [Test] public void GetSyncAssetsConfiguration_ConcurrentAccess_SyncAssetsConfigurationIsHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -160,7 +160,7 @@ public void GetSyncAssetsConfiguration_ConcurrentAccess_SyncAssetsConfigurationI } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryHasChangesTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryHasChangesTests.cs index 8cda4409..b1a85b41 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryHasChangesTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryHasChangesTests.cs @@ -5,25 +5,25 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositoryHasChangesTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; - private IAssetRepository? _assetRepository; + private AssetRepository? _assetRepository; private Mock? _storageServiceMock; private Mock? _configurationRootMock; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -31,13 +31,13 @@ public void SetUp() { PhotoManager.Infrastructure.Database.Database database = new (new ObjectListStorage(), new BlobStorage(), new BackupStorage()); UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); - _assetRepository = new AssetRepository(database, _storageServiceMock!.Object, userConfigurationService); + _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); } [Test] public void HasChanges_Initialization_ReturnFalse() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -48,7 +48,7 @@ public void HasChanges_Initialization_ReturnFalse() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -56,14 +56,14 @@ public void HasChanges_Initialization_ReturnFalse() [Test] public void HasChanges_AfterChange_ReturnTrue() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { Assert.IsFalse(_assetRepository!.HasChanges()); - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); _assetRepository!.AddFolder(folderPath1); @@ -73,7 +73,7 @@ public void HasChanges_AfterChange_ReturnTrue() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -81,14 +81,14 @@ public void HasChanges_AfterChange_ReturnTrue() [Test] public void HasChanges_ConcurrentAccess_ChangesAreHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { Assert.IsFalse(_assetRepository!.HasChanges()); - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); _assetRepository!.AddFolder(folderPath1); @@ -111,7 +111,7 @@ public void HasChanges_ConcurrentAccess_ChangesAreHandledSafely() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryIsAssetCataloguedTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryIsAssetCataloguedTests.cs index 8d7e8eec..713d247e 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryIsAssetCataloguedTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryIsAssetCataloguedTests.cs @@ -5,27 +5,27 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositoryIsAssetCataloguedTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; - private IAssetRepository? _assetRepository; + private AssetRepository? _assetRepository; private Mock? _storageServiceMock; private Mock? _configurationRootMock; - private Asset? asset1; + private Asset? _asset1; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -33,10 +33,11 @@ public void SetUp() { PhotoManager.Infrastructure.Database.Database database = new (new ObjectListStorage(), new BlobStorage(), new BackupStorage()); UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); - _assetRepository = new AssetRepository(database, _storageServiceMock!.Object, userConfigurationService); + _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); - asset1 = new() + _asset1 = new() { + Folder = new() { Path = "" }, FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), FileName = "Image 1.jpg", FileSize = 363888, @@ -57,25 +58,25 @@ public void SetUp() [Test] public void IsAssetCatalogued_FolderAndAssetExist_ReturnsTrue() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "TestFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "TestFolder2"); Folder addedFolder1 = _assetRepository!.AddFolder(folderPath1); _assetRepository!.AddFolder(folderPath2); - asset1!.Folder = addedFolder1; - asset1!.FolderId = addedFolder1.FolderId; - _assetRepository!.AddAsset(asset1!, Array.Empty()); + _asset1!.Folder = addedFolder1; + _asset1!.FolderId = addedFolder1.FolderId; + _assetRepository!.AddAsset(_asset1!, []); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); - bool isAssetCatalogued1 = _assetRepository!.IsAssetCatalogued(folderPath1, asset1.FileName); + bool isAssetCatalogued1 = _assetRepository!.IsAssetCatalogued(folderPath1, _asset1.FileName); bool isAssetCatalogued2 = _assetRepository!.IsAssetCatalogued(folderPath2, "toto.jpg"); Assert.IsTrue(isAssetCatalogued1); @@ -86,7 +87,7 @@ public void IsAssetCatalogued_FolderAndAssetExist_ReturnsTrue() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -94,19 +95,19 @@ public void IsAssetCatalogued_FolderAndAssetExist_ReturnsTrue() [Test] public void IsAssetCatalogued_DirectoryWithNoFolder_ReturnsFalse() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "TestFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "TestFolder2"); Folder addedFolder1 = _assetRepository!.AddFolder(folderPath1); - asset1!.Folder = addedFolder1; - asset1!.FolderId = addedFolder1.FolderId; - _assetRepository!.AddAsset(asset1!, Array.Empty()); + _asset1!.Folder = addedFolder1; + _asset1!.FolderId = addedFolder1.FolderId; + _assetRepository!.AddAsset(_asset1!, []); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); @@ -120,7 +121,7 @@ public void IsAssetCatalogued_DirectoryWithNoFolder_ReturnsFalse() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -128,7 +129,7 @@ public void IsAssetCatalogued_DirectoryWithNoFolder_ReturnsFalse() [Test] public void IsAssetCatalogued_DirectoryNameIsNull_ReturnsFalse() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -143,7 +144,7 @@ public void IsAssetCatalogued_DirectoryNameIsNull_ReturnsFalse() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -151,12 +152,12 @@ public void IsAssetCatalogued_DirectoryNameIsNull_ReturnsFalse() [Test] public void IsAssetCatalogued_FileNameIsNull_ReturnsFalse() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); _assetRepository!.AddFolder(folderPath1); @@ -170,7 +171,7 @@ public void IsAssetCatalogued_FileNameIsNull_ReturnsFalse() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -178,20 +179,20 @@ public void IsAssetCatalogued_FileNameIsNull_ReturnsFalse() [Test] public void IsAssetCatalogued_ConcurrentAccess_AssetsAreHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "TestFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "TestFolder2"); Folder addedFolder1 = _assetRepository!.AddFolder(folderPath1); _assetRepository!.AddFolder(folderPath2); - asset1!.Folder = addedFolder1; - asset1!.FolderId = addedFolder1.FolderId; - _assetRepository!.AddAsset(asset1!, Array.Empty()); + _asset1!.Folder = addedFolder1; + _asset1!.FolderId = addedFolder1.FolderId; + _assetRepository!.AddAsset(_asset1!, []); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); @@ -201,7 +202,7 @@ public void IsAssetCatalogued_ConcurrentAccess_AssetsAreHandledSafely() // Simulate concurrent access Parallel.Invoke( - () => isAssetCatalogued1 = _assetRepository!.IsAssetCatalogued(folderPath1, asset1.FileName), + () => isAssetCatalogued1 = _assetRepository!.IsAssetCatalogued(folderPath1, _asset1.FileName), () => isAssetCatalogued2 = _assetRepository!.IsAssetCatalogued(folderPath2, "toto.jpg") ); @@ -213,7 +214,7 @@ public void IsAssetCatalogued_ConcurrentAccess_AssetsAreHandledSafely() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryLoadThumbnailTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryLoadThumbnailTests.cs index 6141a7f8..980a5d57 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryLoadThumbnailTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryLoadThumbnailTests.cs @@ -5,9 +5,9 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositoryLoadThumbnailTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; private TestableAssetRepository? _testableAssetRepository; private PhotoManager.Infrastructure.Database.Database? _database; @@ -15,19 +15,19 @@ public class AssetRepositoryLoadThumbnailTests private Mock? _storageServiceMock; private Mock? _configurationRootMock; - private Asset? asset1; + private Asset? _asset1; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); _storageServiceMock!.Setup(x => x.LoadBitmapThumbnailImage(It.IsAny(), It.IsAny(), It.IsAny())).Returns(new BitmapImage()); } @@ -38,8 +38,9 @@ public void SetUp() _userConfigurationService = new (_configurationRootMock!.Object); _testableAssetRepository = new (_database, _storageServiceMock!.Object, _userConfigurationService); - asset1 = new() + _asset1 = new() { + Folder = new() { Path = "" }, FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), FileName = "Image 1.jpg", FileSize = 363888, @@ -60,52 +61,52 @@ public void SetUp() [Test] public void LoadThumbnail_ThumbnailExists_ReturnsBitmapImage() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - Folder addedFolder1 = _testableAssetRepository!.AddFolder(dataDirectory!); - asset1!.Folder = addedFolder1; - asset1!.FolderId = addedFolder1.FolderId; - _testableAssetRepository!.AddAsset(asset1!, new byte[] { 1, 2, 3 }); + Folder addedFolder1 = _testableAssetRepository!.AddFolder(_dataDirectory!); + _asset1!.Folder = addedFolder1; + _asset1!.FolderId = addedFolder1.FolderId; + _testableAssetRepository!.AddAsset(_asset1!, [1, 2, 3]); Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(asset1!.Folder.Path)); - Assert.AreEqual(1, thumbnails[asset1!.Folder.Path].Count); - Assert.IsTrue(thumbnails[asset1!.Folder.Path].ContainsKey(asset1.FileName)); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[asset1!.Folder.Path][asset1.FileName]); + Assert.IsTrue(thumbnails.ContainsKey(_asset1!.Folder.Path)); + Assert.AreEqual(1, thumbnails[_asset1!.Folder.Path].Count); + Assert.IsTrue(thumbnails[_asset1!.Folder.Path].ContainsKey(_asset1.FileName)); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[_asset1!.Folder.Path][_asset1.FileName]); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); - BitmapImage? bitmapImage = _testableAssetRepository!.LoadThumbnail(dataDirectory!, asset1!.FileName, asset1.ThumbnailPixelWidth, asset1.ThumbnailPixelHeight); + BitmapImage? bitmapImage = _testableAssetRepository!.LoadThumbnail(_dataDirectory!, _asset1!.FileName, _asset1.ThumbnailPixelWidth, _asset1.ThumbnailPixelHeight); Assert.IsNotNull(bitmapImage); List assets = _testableAssetRepository.GetCataloguedAssets(); Assert.AreEqual(1, assets.Count); - Assert.AreEqual(asset1.FileName, assets[0].FileName); + Assert.AreEqual(_asset1.FileName, assets[0].FileName); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(asset1!.Folder.Path)); - Assert.AreEqual(1, thumbnails[asset1!.Folder.Path].Count); - Assert.IsTrue(thumbnails[asset1!.Folder.Path].ContainsKey(asset1.FileName)); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[asset1!.Folder.Path][asset1.FileName]); + Assert.IsTrue(thumbnails.ContainsKey(_asset1!.Folder.Path)); + Assert.AreEqual(1, thumbnails[_asset1!.Folder.Path].Count); + Assert.IsTrue(thumbnails[_asset1!.Folder.Path].ContainsKey(_asset1.FileName)); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[_asset1!.Folder.Path][_asset1.FileName]); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, asset1.Folder.ThumbnailsFilename))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, _asset1.Folder.ThumbnailsFilename))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -113,49 +114,49 @@ public void LoadThumbnail_ThumbnailExists_ReturnsBitmapImage() [Test] public void LoadThumbnail_AssetDoesNotExistButBinExists_ReturnsBitmapImage() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string fileName = "Image2.png"; + const string fileName = "Image2.png"; Dictionary blobToWrite = new() { - { asset1!.FileName, new byte[] { 1, 2, 3 } }, - { fileName, new byte[] { 4, 5, 6 } } + { _asset1!.FileName, [1, 2, 3]}, + { fileName, [4, 5, 6]} }; - Folder addedFolder1 = _testableAssetRepository!.AddFolder(dataDirectory!); + Folder addedFolder1 = _testableAssetRepository!.AddFolder(_dataDirectory!); _database!.WriteBlob(blobToWrite, addedFolder1.ThumbnailsFilename); Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - BitmapImage? bitmapImage = _testableAssetRepository!.LoadThumbnail(dataDirectory!, asset1!.FileName, asset1.ThumbnailPixelWidth, asset1.ThumbnailPixelHeight); + BitmapImage? bitmapImage = _testableAssetRepository!.LoadThumbnail(_dataDirectory!, _asset1!.FileName, _asset1.ThumbnailPixelWidth, _asset1.ThumbnailPixelHeight); Assert.IsNotNull(bitmapImage); List assets = _testableAssetRepository.GetCataloguedAssets(); Assert.AreEqual(0, assets.Count); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(dataDirectory!)); - Assert.AreEqual(2, thumbnails[dataDirectory!].Count); - Assert.IsTrue(thumbnails[dataDirectory!].ContainsKey(asset1.FileName)); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[dataDirectory!][asset1.FileName]); + Assert.IsTrue(thumbnails.ContainsKey(_dataDirectory!)); + Assert.AreEqual(2, thumbnails[_dataDirectory!].Count); + Assert.IsTrue(thumbnails[_dataDirectory!].ContainsKey(_asset1.FileName)); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[_dataDirectory!][_asset1.FileName]); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, addedFolder1.ThumbnailsFilename))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, addedFolder1.ThumbnailsFilename))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); Assert.IsEmpty(assetsUpdatedEvents); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -170,26 +171,26 @@ public void LoadThumbnail_AssetDoesNotExistButBinExistsAndRemoveOldThumbnailsDic UserConfigurationService userConfigurationService = new (configurationRootMock.Object); TestableAssetRepository testableAssetRepository = new (_database!, _storageServiceMock!.Object, userConfigurationService); - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = testableAssetRepository.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string fileName = "Image2.png"; + const string fileName = "Image2.png"; Dictionary blobToWrite = new() { - { asset1!.FileName, new byte[] { 1, 2, 3 } }, - { fileName, new byte[] { 4, 5, 6 } } + { _asset1!.FileName, [1, 2, 3]}, + { fileName, [4, 5, 6]} }; - Folder addedFolder1 = testableAssetRepository.AddFolder(dataDirectory!); + Folder addedFolder1 = testableAssetRepository.AddFolder(_dataDirectory!); _database!.WriteBlob(blobToWrite, addedFolder1.ThumbnailsFilename); Dictionary> thumbnails = testableAssetRepository.GetThumbnails(); Assert.IsEmpty(thumbnails); - BitmapImage? bitmapImage = testableAssetRepository.LoadThumbnail(dataDirectory!, asset1!.FileName, asset1.ThumbnailPixelWidth, asset1.ThumbnailPixelHeight); + BitmapImage? bitmapImage = testableAssetRepository.LoadThumbnail(_dataDirectory!, _asset1!.FileName, _asset1.ThumbnailPixelWidth, _asset1.ThumbnailPixelHeight); Assert.IsNull(bitmapImage); List assets = testableAssetRepository.GetCataloguedAssets(); @@ -197,18 +198,18 @@ public void LoadThumbnail_AssetDoesNotExistButBinExistsAndRemoveOldThumbnailsDic Assert.IsEmpty(thumbnails); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, addedFolder1.ThumbnailsFilename))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, addedFolder1.ThumbnailsFilename))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); Assert.IsEmpty(assetsUpdatedEvents); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -216,19 +217,19 @@ public void LoadThumbnail_AssetDoesNotExistButBinExistsAndRemoveOldThumbnailsDic [Test] public void LoadThumbnail_AssetDoesNotExistButBinNotContainingTheAssetExists_ReturnsNullAndWritesBlobAndDbFiles() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - Folder addedFolder1 = _testableAssetRepository!.AddFolder(dataDirectory!); + Folder addedFolder1 = _testableAssetRepository!.AddFolder(_dataDirectory!); - _database!.WriteBlob(new Dictionary(), addedFolder1.ThumbnailsFilename); + _database!.WriteBlob([], addedFolder1.ThumbnailsFilename); Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - BitmapImage? bitmapImage = _testableAssetRepository!.LoadThumbnail(dataDirectory!, asset1!.FileName, asset1.ThumbnailPixelWidth, asset1.ThumbnailPixelHeight); + BitmapImage? bitmapImage = _testableAssetRepository!.LoadThumbnail(_dataDirectory!, _asset1!.FileName, _asset1.ThumbnailPixelWidth, _asset1.ThumbnailPixelHeight); Assert.IsNull(bitmapImage); @@ -236,21 +237,21 @@ public void LoadThumbnail_AssetDoesNotExistButBinNotContainingTheAssetExists_Ret Assert.AreEqual(0, assets.Count); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(dataDirectory!)); - Assert.IsEmpty(thumbnails[dataDirectory!]); + Assert.IsTrue(thumbnails.ContainsKey(_dataDirectory!)); + Assert.IsEmpty(thumbnails[_dataDirectory!]); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, addedFolder1.ThumbnailsFilename))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, addedFolder1.ThumbnailsFilename))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); Assert.IsEmpty(assetsUpdatedEvents); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -258,27 +259,27 @@ public void LoadThumbnail_AssetDoesNotExistButBinNotContainingTheAssetExists_Ret [Test] public void LoadThumbnail_FolderDoesNotExist_ReturnsBitmapImage() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { Guid folderId = Guid.NewGuid(); - asset1!.Folder = new Folder() { FolderId = folderId, Path = dataDirectory! }; - asset1!.FolderId = folderId; - _testableAssetRepository!.AddAsset(asset1!, Array.Empty()); + _asset1!.Folder = new Folder() { FolderId = folderId, Path = _dataDirectory! }; + _asset1!.FolderId = folderId; + _testableAssetRepository!.AddAsset(_asset1!, []); Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(dataDirectory!)); - Assert.AreEqual(1, thumbnails[dataDirectory!].Count); - Assert.IsTrue(thumbnails[dataDirectory!].ContainsKey(asset1.FileName)); - Assert.AreEqual(Array.Empty(), thumbnails[dataDirectory!][asset1.FileName]); + Assert.IsTrue(thumbnails.ContainsKey(_dataDirectory!)); + Assert.AreEqual(1, thumbnails[_dataDirectory!].Count); + Assert.IsTrue(thumbnails[_dataDirectory!].ContainsKey(_asset1.FileName)); + Assert.AreEqual(Array.Empty(), thumbnails[_dataDirectory!][_asset1.FileName]); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); - BitmapImage? bitmapImage = _testableAssetRepository!.LoadThumbnail(dataDirectory!, asset1!.FileName, asset1.ThumbnailPixelWidth, asset1.ThumbnailPixelHeight); + BitmapImage? bitmapImage = _testableAssetRepository!.LoadThumbnail(_dataDirectory!, _asset1!.FileName, _asset1.ThumbnailPixelWidth, _asset1.ThumbnailPixelHeight); Assert.IsNotNull(bitmapImage); @@ -286,22 +287,22 @@ public void LoadThumbnail_FolderDoesNotExist_ReturnsBitmapImage() Assert.AreEqual(1, assets.Count); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(dataDirectory!)); - Assert.AreEqual(1, thumbnails[dataDirectory!].Count); - Assert.IsTrue(thumbnails[dataDirectory!].ContainsKey(asset1.FileName)); - Assert.AreEqual(Array.Empty(), thumbnails[dataDirectory!][asset1.FileName]); + Assert.IsTrue(thumbnails.ContainsKey(_dataDirectory!)); + Assert.AreEqual(1, thumbnails[_dataDirectory!].Count); + Assert.IsTrue(thumbnails[_dataDirectory!].ContainsKey(_asset1.FileName)); + Assert.AreEqual(Array.Empty(), thumbnails[_dataDirectory!][_asset1.FileName]); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -309,7 +310,7 @@ public void LoadThumbnail_FolderDoesNotExist_ReturnsBitmapImage() [Test] public void LoadThumbnail_AssetAndFolderDoNotExist_ReturnsNull() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -317,7 +318,7 @@ public void LoadThumbnail_AssetAndFolderDoNotExist_ReturnsNull() Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.IsEmpty(thumbnails); - BitmapImage? bitmapImage = _testableAssetRepository!.LoadThumbnail(dataDirectory!, asset1!.FileName, asset1.ThumbnailPixelWidth, asset1.ThumbnailPixelHeight); + BitmapImage? bitmapImage = _testableAssetRepository!.LoadThumbnail(_dataDirectory!, _asset1!.FileName, _asset1.ThumbnailPixelWidth, _asset1.ThumbnailPixelHeight); Assert.IsNull(bitmapImage); @@ -325,19 +326,19 @@ public void LoadThumbnail_AssetAndFolderDoNotExist_ReturnsNull() Assert.AreEqual(0, assets.Count); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(dataDirectory!)); - Assert.IsEmpty(thumbnails[dataDirectory!]); + Assert.IsTrue(thumbnails.ContainsKey(_dataDirectory!)); + Assert.IsEmpty(thumbnails[_dataDirectory!]); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); Assert.IsEmpty(assetsUpdatedEvents); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -345,23 +346,23 @@ public void LoadThumbnail_AssetAndFolderDoNotExist_ReturnsNull() [Test] public void LoadThumbnail_DirectoryNameIsNull_ThrowsArgumentNullException() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { string? directoryName = null; - Folder addedFolder1 = _testableAssetRepository!.AddFolder(dataDirectory!); - asset1!.Folder = addedFolder1; - asset1!.FolderId = addedFolder1.FolderId; - _testableAssetRepository!.AddAsset(asset1!, Array.Empty()); + Folder addedFolder1 = _testableAssetRepository!.AddFolder(_dataDirectory!); + _asset1!.Folder = addedFolder1; + _asset1!.FolderId = addedFolder1.FolderId; + _testableAssetRepository!.AddAsset(_asset1!, []); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); ArgumentNullException? exception = Assert.Throws(() => { - _testableAssetRepository!.LoadThumbnail(directoryName!, asset1!.FileName, asset1.ThumbnailPixelWidth, asset1.ThumbnailPixelHeight); + _testableAssetRepository!.LoadThumbnail(directoryName!, _asset1!.FileName, _asset1.ThumbnailPixelWidth, _asset1.ThumbnailPixelHeight); }); Assert.AreEqual("Value cannot be null. (Parameter 'key')", exception?.Message); @@ -371,7 +372,7 @@ public void LoadThumbnail_DirectoryNameIsNull_ThrowsArgumentNullException() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -379,22 +380,22 @@ public void LoadThumbnail_DirectoryNameIsNull_ThrowsArgumentNullException() [Test] public void LoadThumbnail_FileNameIsNull_ThrowsArgumentNullException() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - Folder addedFolder1 = _testableAssetRepository!.AddFolder(dataDirectory!); - asset1!.Folder = addedFolder1; - asset1!.FolderId = addedFolder1.FolderId; - _testableAssetRepository!.AddAsset(asset1!, Array.Empty()); + Folder addedFolder1 = _testableAssetRepository!.AddFolder(_dataDirectory!); + _asset1!.Folder = addedFolder1; + _asset1!.FolderId = addedFolder1.FolderId; + _testableAssetRepository!.AddAsset(_asset1!, []); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); string? fileName = null; - ArgumentNullException? exception = Assert.Throws(() => _testableAssetRepository!.LoadThumbnail(dataDirectory!, fileName!, 0, 0)); + ArgumentNullException? exception = Assert.Throws(() => _testableAssetRepository!.LoadThumbnail(_dataDirectory!, fileName!, 0, 0)); Assert.AreEqual("Value cannot be null. (Parameter 'key')", exception?.Message); @@ -403,7 +404,7 @@ public void LoadThumbnail_FileNameIsNull_ThrowsArgumentNullException() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -411,22 +412,22 @@ public void LoadThumbnail_FileNameIsNull_ThrowsArgumentNullException() [Test] public void LoadThumbnail_ConcurrentAccess_ThumbnailsIsHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _testableAssetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - Folder addedFolder1 = _testableAssetRepository!.AddFolder(dataDirectory!); - asset1!.Folder = addedFolder1; - asset1!.FolderId = addedFolder1.FolderId; - _testableAssetRepository!.AddAsset(asset1!, new byte[] { 1, 2, 3 }); + Folder addedFolder1 = _testableAssetRepository!.AddFolder(_dataDirectory!); + _asset1!.Folder = addedFolder1; + _asset1!.FolderId = addedFolder1.FolderId; + _testableAssetRepository!.AddAsset(_asset1!, [1, 2, 3]); Dictionary> thumbnails = _testableAssetRepository!.GetThumbnails(); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(asset1!.Folder.Path)); - Assert.AreEqual(1, thumbnails[asset1!.Folder.Path].Count); - Assert.IsTrue(thumbnails[asset1!.Folder.Path].ContainsKey(asset1.FileName)); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[asset1!.Folder.Path][asset1.FileName]); + Assert.IsTrue(thumbnails.ContainsKey(_asset1!.Folder.Path)); + Assert.AreEqual(1, thumbnails[_asset1!.Folder.Path].Count); + Assert.IsTrue(thumbnails[_asset1!.Folder.Path].ContainsKey(_asset1.FileName)); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[_asset1!.Folder.Path][_asset1.FileName]); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); @@ -437,9 +438,9 @@ public void LoadThumbnail_ConcurrentAccess_ThumbnailsIsHandledSafely() // Simulate concurrent access Parallel.Invoke( - () => bitmapImage1 = _testableAssetRepository!.LoadThumbnail(dataDirectory!, asset1!.FileName, asset1.ThumbnailPixelWidth, asset1.ThumbnailPixelHeight), - () => bitmapImage2 = _testableAssetRepository!.LoadThumbnail(dataDirectory!, asset1!.FileName, asset1.ThumbnailPixelWidth, asset1.ThumbnailPixelHeight), - () => bitmapImage3 = _testableAssetRepository!.LoadThumbnail(dataDirectory!, asset1!.FileName, asset1.ThumbnailPixelWidth, asset1.ThumbnailPixelHeight) + () => bitmapImage1 = _testableAssetRepository!.LoadThumbnail(_dataDirectory!, _asset1!.FileName, _asset1.ThumbnailPixelWidth, _asset1.ThumbnailPixelHeight), + () => bitmapImage2 = _testableAssetRepository!.LoadThumbnail(_dataDirectory!, _asset1!.FileName, _asset1.ThumbnailPixelWidth, _asset1.ThumbnailPixelHeight), + () => bitmapImage3 = _testableAssetRepository!.LoadThumbnail(_dataDirectory!, _asset1!.FileName, _asset1.ThumbnailPixelWidth, _asset1.ThumbnailPixelHeight) ); Assert.IsNotNull(bitmapImage1); @@ -448,27 +449,27 @@ public void LoadThumbnail_ConcurrentAccess_ThumbnailsIsHandledSafely() List assets = _testableAssetRepository.GetCataloguedAssets(); Assert.AreEqual(1, assets.Count); - Assert.AreEqual(asset1.FileName, assets[0].FileName); + Assert.AreEqual(_asset1.FileName, assets[0].FileName); Assert.AreEqual(1, thumbnails.Count); - Assert.IsTrue(thumbnails.ContainsKey(asset1!.Folder.Path)); - Assert.AreEqual(1, thumbnails[asset1!.Folder.Path].Count); - Assert.IsTrue(thumbnails[asset1!.Folder.Path].ContainsKey(asset1.FileName)); - Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[asset1!.Folder.Path][asset1.FileName]); + Assert.IsTrue(thumbnails.ContainsKey(_asset1!.Folder.Path)); + Assert.AreEqual(1, thumbnails[_asset1!.Folder.Path].Count); + Assert.IsTrue(thumbnails[_asset1!.Folder.Path].ContainsKey(_asset1.FileName)); + Assert.AreEqual(new byte[] { 1, 2, 3 }, thumbnails[_asset1!.Folder.Path][_asset1.FileName]); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, asset1.Folder.ThumbnailsFilename))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, _asset1.Folder.ThumbnailsFilename))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositorySaveCatalogTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositorySaveCatalogTests.cs index 35bea348..69e4547a 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositorySaveCatalogTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositorySaveCatalogTests.cs @@ -5,9 +5,9 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositorySaveCatalogTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; private AssetRepository? _assetRepository; PhotoManager.Infrastructure.Database.Database? _database; @@ -15,19 +15,19 @@ public class AssetRepositorySaveCatalogTests private Mock? _storageServiceMock; private Mock? _configurationRootMock; - private Asset? asset1; + private Asset? _asset1; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -37,8 +37,9 @@ public void SetUp() _userConfigurationService = new (_configurationRootMock!.Object); _assetRepository = new (_database, _storageServiceMock!.Object, _userConfigurationService); - asset1 = new() + _asset1 = new() { + Folder = new() { Path = "" }, FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), FileName = "Image 1.jpg", FileSize = 363888, @@ -59,27 +60,27 @@ public void SetUp() [Test] public void SaveCatalog_HasChanges_SaveOperationsPerformed() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "TestFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "TestFolder2"); Folder addedFolder1 = _assetRepository!.AddFolder(folderPath1); Folder addedFolder2 = _assetRepository!.AddFolder(folderPath2); - asset1!.Folder = addedFolder1; - asset1!.FolderId = addedFolder1.FolderId; - _assetRepository!.AddAsset(asset1!, Array.Empty()); + _asset1!.Folder = addedFolder1; + _asset1!.FolderId = addedFolder1.FolderId; + _assetRepository!.AddAsset(_asset1!, []); Assert.IsTrue(_assetRepository.HasChanges()); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, asset1.Folder.ThumbnailsFilename))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, _asset1.Folder.ThumbnailsFilename))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); // Just to fill the syncassetsdirectoriesdefinitions.db and the recenttargetpaths.db files SyncAssetsConfiguration syncAssetsConfiguration = new(); @@ -100,11 +101,11 @@ public void SaveCatalog_HasChanges_SaveOperationsPerformed() DeleteAssetsNotInSource = false }); - List recentTargetPathsToSave = new() - { + List recentTargetPathsToSave = + [ "D:\\Workspace\\PhotoManager\\Toto", "D:\\Workspace\\PhotoManager\\Tutu" - }; + ]; _assetRepository.SaveSyncAssetsConfiguration(syncAssetsConfiguration); _assetRepository.SaveRecentTargetPaths(recentTargetPathsToSave); @@ -121,13 +122,13 @@ public void SaveCatalog_HasChanges_SaveOperationsPerformed() Assert.IsFalse(_assetRepository.HasChanges()); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, asset1.Folder.ThumbnailsFilename))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, addedFolder2.ThumbnailsFilename))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, _asset1.Folder.ThumbnailsFilename))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, addedFolder2.ThumbnailsFilename))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); List folders = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.FoldersTableName, FolderConfigs.ReadFunc); List assets = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.AssetsTableName, AssetConfigs.ReadFunc); @@ -136,11 +137,11 @@ public void SaveCatalog_HasChanges_SaveOperationsPerformed() List recentTargetPaths = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.RecentTargetPathsTableName, RecentPathsConfigs.ReadFunc); Assert.AreEqual(2, folders.Count); - Assert.IsTrue(folders.FirstOrDefault(x => x.FolderId == asset1.FolderId)?.Name == asset1.Folder.Name); + Assert.IsTrue(folders.FirstOrDefault(x => x.FolderId == _asset1.FolderId)?.Name == _asset1.Folder.Name); Assert.AreEqual(1, assets.Count); - Asset? asset = assets.FirstOrDefault(x => x.Hash == asset1.Hash); - Assert.IsTrue(asset?.FileName == asset1.FileName && asset.FolderId == asset1.FolderId); + Asset? asset = assets.FirstOrDefault(x => x.Hash == _asset1.Hash); + Assert.IsTrue(asset?.FileName == _asset1.FileName && asset.FolderId == _asset1.FolderId); Assert.AreEqual(2, syncAssetsDirectoriesDefinitions.Count); Assert.IsTrue(syncAssetsDirectoriesDefinitions.Any(x => x.SourceDirectory == "C:\\Toto\\Screenshots")); @@ -153,7 +154,7 @@ public void SaveCatalog_HasChanges_SaveOperationsPerformed() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -161,25 +162,25 @@ public void SaveCatalog_HasChanges_SaveOperationsPerformed() [Test] public void SaveCatalog_FolderIsNullAndHasChanges_SaveOperationsPerformed() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); Folder addedFolder1 = _assetRepository!.AddFolder(folderPath1); - asset1!.Folder = addedFolder1; - asset1!.FolderId = addedFolder1.FolderId; - _assetRepository!.AddAsset(asset1!, Array.Empty()); + _asset1!.Folder = addedFolder1; + _asset1!.FolderId = addedFolder1.FolderId; + _assetRepository!.AddAsset(_asset1!, []); Assert.IsTrue(_assetRepository.HasChanges()); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, asset1.Folder.ThumbnailsFilename))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, _asset1.Folder.ThumbnailsFilename))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); @@ -188,18 +189,18 @@ public void SaveCatalog_FolderIsNullAndHasChanges_SaveOperationsPerformed() Assert.IsFalse(_assetRepository.HasChanges()); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, asset1.Folder.ThumbnailsFilename))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, _asset1.Folder.ThumbnailsFilename))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); Assert.AreEqual(1, assetsUpdatedEvents.Count); Assert.AreEqual(Reactive.Unit.Default, assetsUpdatedEvents[0]); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -207,37 +208,37 @@ public void SaveCatalog_FolderIsNullAndHasChanges_SaveOperationsPerformed() [Test] public void SaveCatalog_FolderIsNullAndHasChangesAndEverythingEmpty_SaveOperationsPerformed() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); Folder addedFolder1 = _assetRepository!.AddFolder(folderPath1); _assetRepository.DeleteFolder(addedFolder1); Assert.IsTrue(_assetRepository.HasChanges()); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); _assetRepository.SaveCatalog(null); Assert.IsFalse(_assetRepository.HasChanges()); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); Assert.IsEmpty(assetsUpdatedEvents); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -245,31 +246,31 @@ public void SaveCatalog_FolderIsNullAndHasChangesAndEverythingEmpty_SaveOperatio [Test] public void SaveCatalog_FolderIsNullAndHasNoChanges_DoesNothing() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { Assert.IsFalse(_assetRepository!.HasChanges()); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); _assetRepository.SaveCatalog(null); Assert.IsFalse(_assetRepository.HasChanges()); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); Assert.IsEmpty(assetsUpdatedEvents); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -277,27 +278,27 @@ public void SaveCatalog_FolderIsNullAndHasNoChanges_DoesNothing() [Test] public void SaveCatalog_ConcurrentAccess_EverythingIsHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - string folderPath1 = Path.Combine(dataDirectory!, "TestFolder1"); - string folderPath2 = Path.Combine(dataDirectory!, "TestFolder2"); + string folderPath1 = Path.Combine(_dataDirectory!, "TestFolder1"); + string folderPath2 = Path.Combine(_dataDirectory!, "TestFolder2"); Folder addedFolder1 = _assetRepository!.AddFolder(folderPath1); Folder addedFolder2 = _assetRepository!.AddFolder(folderPath2); - asset1!.Folder = addedFolder1; - asset1!.FolderId = addedFolder1.FolderId; - _assetRepository!.AddAsset(asset1!, Array.Empty()); + _asset1!.Folder = addedFolder1; + _asset1!.FolderId = addedFolder1.FolderId; + _assetRepository!.AddAsset(_asset1!, []); Assert.IsTrue(_assetRepository.HasChanges()); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, asset1.Folder.ThumbnailsFilename))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, _asset1.Folder.ThumbnailsFilename))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); // Just to fill the syncassetsdirectoriesdefinitions.db and the recenttargetpaths.db files SyncAssetsConfiguration syncAssetsConfiguration = new(); @@ -318,11 +319,11 @@ public void SaveCatalog_ConcurrentAccess_EverythingIsHandledSafely() DeleteAssetsNotInSource = false }); - List recentTargetPathsToSave = new() - { + List recentTargetPathsToSave = + [ "D:\\Workspace\\PhotoManager\\Toto", "D:\\Workspace\\PhotoManager\\Tutu" - }; + ]; _assetRepository.SaveSyncAssetsConfiguration(syncAssetsConfiguration); _assetRepository.SaveRecentTargetPaths(recentTargetPathsToSave); @@ -339,13 +340,13 @@ public void SaveCatalog_ConcurrentAccess_EverythingIsHandledSafely() Assert.IsFalse(_assetRepository.HasChanges()); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, asset1.Folder.ThumbnailsFilename))); - Assert.IsFalse(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, addedFolder2.ThumbnailsFilename))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, _asset1.Folder.ThumbnailsFilename))); + Assert.IsFalse(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, addedFolder2.ThumbnailsFilename))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); - Assert.IsTrue(File.Exists(Path.Combine(backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "assets.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "folders.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "syncassetsdirectoriesdefinitions.db"))); + Assert.IsTrue(File.Exists(Path.Combine(_backupPath!, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, "recenttargetpaths.db"))); List folders = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.FoldersTableName, FolderConfigs.ReadFunc); List assets = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.AssetsTableName, AssetConfigs.ReadFunc); @@ -354,11 +355,11 @@ public void SaveCatalog_ConcurrentAccess_EverythingIsHandledSafely() List recentTargetPaths = _database!.ReadObjectList(_userConfigurationService!.StorageSettings.TablesSettings.RecentTargetPathsTableName, RecentPathsConfigs.ReadFunc); Assert.AreEqual(2, folders.Count); - Assert.IsTrue(folders.FirstOrDefault(x => x.FolderId == asset1.FolderId)?.Name == asset1.Folder.Name); + Assert.IsTrue(folders.FirstOrDefault(x => x.FolderId == _asset1.FolderId)?.Name == _asset1.Folder.Name); Assert.AreEqual(1, assets.Count); - Asset? asset = assets.FirstOrDefault(x => x.Hash == asset1.Hash); - Assert.IsTrue(asset?.FileName == asset1.FileName && asset.FolderId == asset1.FolderId); + Asset? asset = assets.FirstOrDefault(x => x.Hash == _asset1.Hash); + Assert.IsTrue(asset?.FileName == _asset1.FileName && asset.FolderId == _asset1.FolderId); Assert.AreEqual(2, syncAssetsDirectoriesDefinitions.Count); Assert.IsTrue(syncAssetsDirectoriesDefinitions.Any(x => x.SourceDirectory == "C:\\Toto\\Screenshots")); @@ -371,7 +372,7 @@ public void SaveCatalog_ConcurrentAccess_EverythingIsHandledSafely() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositorySaveRecentTargetPathsTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositorySaveRecentTargetPathsTests.cs index cffa168b..a9c391e2 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositorySaveRecentTargetPathsTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositorySaveRecentTargetPathsTests.cs @@ -5,25 +5,25 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositorySaveRecentTargetPathsTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; - private IAssetRepository? _assetRepository; + private AssetRepository? _assetRepository; private Mock? _storageServiceMock; private Mock? _configurationRootMock; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -31,22 +31,22 @@ public void SetUp() { PhotoManager.Infrastructure.Database.Database database = new (new ObjectListStorage(), new BlobStorage(), new BackupStorage()); UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); - _assetRepository = new AssetRepository(database, _storageServiceMock!.Object, userConfigurationService); + _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); } [Test] public void SaveRecentTargetPaths_RecentTargetPaths_SaveRecentTargetPaths() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - List recentTargetPathsToSave = new() - { + List recentTargetPathsToSave = + [ "D:\\Workspace\\PhotoManager\\Toto", "D:\\Workspace\\PhotoManager\\Tutu" - }; + ]; _assetRepository!.SaveRecentTargetPaths(recentTargetPathsToSave); List recentTargetPaths = _assetRepository.GetRecentTargetPaths(); @@ -57,7 +57,7 @@ public void SaveRecentTargetPaths_RecentTargetPaths_SaveRecentTargetPaths() Assert.IsTrue(_assetRepository.HasChanges()); - _assetRepository.SaveRecentTargetPaths(new List()); + _assetRepository.SaveRecentTargetPaths([]); recentTargetPaths = _assetRepository.GetRecentTargetPaths(); Assert.IsEmpty(recentTargetPaths); @@ -68,7 +68,7 @@ public void SaveRecentTargetPaths_RecentTargetPaths_SaveRecentTargetPaths() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -76,16 +76,16 @@ public void SaveRecentTargetPaths_RecentTargetPaths_SaveRecentTargetPaths() [Test] public void SaveRecentTargetPaths_ConcurrentAccess_RecentTargetPathsAreHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { - List recentTargetPathsToSave = new() - { + List recentTargetPathsToSave = + [ "D:\\Workspace\\PhotoManager\\Toto", "D:\\Workspace\\PhotoManager\\Tutu" - }; + ]; // Simulate concurrent access Parallel.Invoke( @@ -106,7 +106,7 @@ public void SaveRecentTargetPaths_ConcurrentAccess_RecentTargetPathsAreHandledSa } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositorySaveSyncAssetsConfigurationTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositorySaveSyncAssetsConfigurationTests.cs index 3160cb91..44a02b49 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositorySaveSyncAssetsConfigurationTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositorySaveSyncAssetsConfigurationTests.cs @@ -5,25 +5,25 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositorySaveSyncAssetsConfigurationTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; - private IAssetRepository? _assetRepository; + private AssetRepository? _assetRepository; private Mock? _storageServiceMock; private Mock? _configurationRootMock; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -31,13 +31,13 @@ public void SetUp() { PhotoManager.Infrastructure.Database.Database database = new (new ObjectListStorage(), new BlobStorage(), new BackupStorage()); UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); - _assetRepository = new AssetRepository(database, _storageServiceMock!.Object, userConfigurationService); + _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); } [Test] public void SaveSyncAssetsConfiguration_SyncAssetsConfiguration_SaveConfiguration() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -82,7 +82,7 @@ public void SaveSyncAssetsConfiguration_SyncAssetsConfiguration_SaveConfiguratio } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -90,7 +90,7 @@ public void SaveSyncAssetsConfiguration_SyncAssetsConfiguration_SaveConfiguratio [Test] public void SaveSyncAssetsConfiguration_ConcurrentAccess_SyncAssetsConfigurationIsHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -134,7 +134,7 @@ public void SaveSyncAssetsConfiguration_ConcurrentAccess_SyncAssetsConfiguration } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryUpdateTargetPathToRecentTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryUpdateTargetPathToRecentTests.cs index 36b174a7..d7e99154 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryUpdateTargetPathToRecentTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryUpdateTargetPathToRecentTests.cs @@ -5,25 +5,25 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositoryUpdateTargetPathToRecentTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; - private IAssetRepository? _assetRepository; + private AssetRepository? _assetRepository; private Mock? _storageServiceMock; private Mock? _configurationRootMock; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath); } [SetUp] @@ -31,13 +31,13 @@ public void SetUp() { PhotoManager.Infrastructure.Database.Database database = new (new ObjectListStorage(), new BlobStorage(), new BackupStorage()); UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); - _assetRepository = new AssetRepository(database, _storageServiceMock!.Object, userConfigurationService); + _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); } [Test] public void UpdateTargetPathToRecent_NewFolderAndExisting_UpdateRecentTargetPathsAndSave() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -64,7 +64,7 @@ public void UpdateTargetPathToRecent_NewFolderAndExisting_UpdateRecentTargetPath } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -72,7 +72,7 @@ public void UpdateTargetPathToRecent_NewFolderAndExisting_UpdateRecentTargetPath [Test] public void UpdateTargetPathToRecent_MaxCountHasBeenReached_UpdateRecentPathsAndSave() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -95,7 +95,7 @@ public void UpdateTargetPathToRecent_MaxCountHasBeenReached_UpdateRecentPathsAnd } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -103,7 +103,7 @@ public void UpdateTargetPathToRecent_MaxCountHasBeenReached_UpdateRecentPathsAnd [Test] public void UpdateTargetPathToRecent_PathIsNull_UpdateRecentPathsAndSave() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -131,7 +131,7 @@ public void UpdateTargetPathToRecent_PathIsNull_UpdateRecentPathsAndSave() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -139,7 +139,7 @@ public void UpdateTargetPathToRecent_PathIsNull_UpdateRecentPathsAndSave() [Test] public void UpdateTargetPathToRecent_PathIsEmpty_UpdateRecentPathsAndSave() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -167,7 +167,7 @@ public void UpdateTargetPathToRecent_PathIsEmpty_UpdateRecentPathsAndSave() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -175,7 +175,7 @@ public void UpdateTargetPathToRecent_PathIsEmpty_UpdateRecentPathsAndSave() [Test] public void UpdateTargetPathToRecent_FolderIsNull_ThrowsNullReferenceException() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -203,7 +203,7 @@ public void UpdateTargetPathToRecent_FolderIsNull_ThrowsNullReferenceException() } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -211,7 +211,7 @@ public void UpdateTargetPathToRecent_FolderIsNull_ThrowsNullReferenceException() [Test] public void UpdateTargetPathToRecent_ConcurrentAccess_RecentTargetPathsAreHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try @@ -241,7 +241,7 @@ public void UpdateTargetPathToRecent_ConcurrentAccess_RecentTargetPathsAreHandle } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryWriteBackupTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryWriteBackupTests.cs index df1e1bfb..f77b1b94 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryWriteBackupTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/AssetRepositoryTests/AssetRepositoryWriteBackupTests.cs @@ -5,25 +5,25 @@ namespace PhotoManager.Tests.Integration.Infrastructure.AssetRepositoryTests; [TestFixture] public class AssetRepositoryWriteBackupTests { - private string? dataDirectory; - private const string backupEndPath = "DatabaseTests\\v1.0"; - private string? backupPath; + private string? _dataDirectory; + private string? _backupPath; + private const string BACKUP_END_PATH = "DatabaseTests\\v1.0"; - private IAssetRepository? _assetRepository; + private AssetRepository? _assetRepository; private Mock? _storageServiceMock; private Mock? _configurationRootMock; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - backupPath = Path.Combine(dataDirectory, backupEndPath); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _backupPath = Path.Combine(_dataDirectory, BACKUP_END_PATH); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); _storageServiceMock = new Mock(); - _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(backupPath!); + _storageServiceMock!.Setup(x => x.ResolveDataDirectory(It.IsAny())).Returns(_backupPath!); } [SetUp] @@ -31,19 +31,19 @@ public void SetUp() { PhotoManager.Infrastructure.Database.Database database = new (new ObjectListStorage(), new BlobStorage(), new BackupStorage()); UserConfigurationService userConfigurationService = new (_configurationRootMock!.Object); - _assetRepository = new AssetRepository(database, _storageServiceMock!.Object, userConfigurationService); + _assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); } [Test] public void WriteBackup_BackupWrittenAndMoreBackupsToKeep_WritesBackupAndDoesNotDeleteOldBackups() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { DateTime backupDate = DateTime.Now; - string backupFilePath = Path.Combine(backupPath! + "_Backups", backupDate.ToString("yyyyMMdd") + ".zip"); + string backupFilePath = Path.Combine(_backupPath! + "_Backups", backupDate.ToString("yyyyMMdd") + ".zip"); Assert.IsFalse(File.Exists(backupFilePath)); Assert.IsFalse(_assetRepository!.BackupExists()); @@ -53,14 +53,14 @@ public void WriteBackup_BackupWrittenAndMoreBackupsToKeep_WritesBackupAndDoesNot Assert.IsTrue(File.Exists(backupFilePath)); Assert.IsTrue(_assetRepository!.BackupExists()); - int filesInBackupDirectory = Directory.GetFiles(backupPath! + "_Backups").Length; + int filesInBackupDirectory = Directory.GetFiles(_backupPath! + "_Backups").Length; Assert.AreEqual(1, filesInBackupDirectory); Assert.IsEmpty(assetsUpdatedEvents); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -76,13 +76,13 @@ public void WriteBackup_BackupWrittenAndLessBackupsToKeep_WritesBackupAndDeletes UserConfigurationService userConfigurationService = new (configurationRootMock.Object); AssetRepository assetRepository = new (database, _storageServiceMock!.Object, userConfigurationService); - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = assetRepository.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { DateTime backupDate = DateTime.Now; - string backupFilePath = Path.Combine(backupPath! + "_Backups", backupDate.ToString("yyyyMMdd") + ".zip"); + string backupFilePath = Path.Combine(_backupPath! + "_Backups", backupDate.ToString("yyyyMMdd") + ".zip"); Assert.IsFalse(File.Exists(backupFilePath)); Assert.IsFalse(assetRepository.BackupExists()); @@ -92,14 +92,14 @@ public void WriteBackup_BackupWrittenAndLessBackupsToKeep_WritesBackupAndDeletes Assert.IsFalse(File.Exists(backupFilePath)); Assert.IsFalse(assetRepository.BackupExists()); - int filesInBackupDirectory = Directory.GetFiles(backupPath! + "_Backups").Length; + int filesInBackupDirectory = Directory.GetFiles(_backupPath! + "_Backups").Length; Assert.AreEqual(0, filesInBackupDirectory); Assert.IsEmpty(assetsUpdatedEvents); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -107,13 +107,13 @@ public void WriteBackup_BackupWrittenAndLessBackupsToKeep_WritesBackupAndDeletes [Test] public void WriteBackup_BackupWrittenTwiceAndMoreBackupsToKeep_WritesBackupOnceAndDoesNotDeleteOldBackups() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { DateTime backupDate = DateTime.Now; - string backupFilePath = Path.Combine(backupPath! + "_Backups", backupDate.ToString("yyyyMMdd") + ".zip"); + string backupFilePath = Path.Combine(_backupPath! + "_Backups", backupDate.ToString("yyyyMMdd") + ".zip"); Assert.IsFalse(File.Exists(backupFilePath)); Assert.IsFalse(_assetRepository!.BackupExists()); @@ -124,14 +124,14 @@ public void WriteBackup_BackupWrittenTwiceAndMoreBackupsToKeep_WritesBackupOnceA Assert.IsTrue(File.Exists(backupFilePath)); Assert.IsTrue(_assetRepository!.BackupExists()); - int filesInBackupDirectory = Directory.GetFiles(backupPath! + "_Backups").Length; + int filesInBackupDirectory = Directory.GetFiles(_backupPath! + "_Backups").Length; Assert.AreEqual(1, filesInBackupDirectory); Assert.IsEmpty(assetsUpdatedEvents); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } @@ -139,13 +139,13 @@ public void WriteBackup_BackupWrittenTwiceAndMoreBackupsToKeep_WritesBackupOnceA [Test] public void WriteBackup_ConcurrentAccess_BackupsAreHandledSafely() { - List assetsUpdatedEvents = new(); + List assetsUpdatedEvents = []; IDisposable assetsUpdatedSubscription = _assetRepository!.AssetsUpdated.Subscribe(assetsUpdatedEvents.Add); try { DateTime backupDate = DateTime.Now; - string backupFilePath = Path.Combine(backupPath! + "_Backups", backupDate.ToString("yyyyMMdd") + ".zip"); + string backupFilePath = Path.Combine(_backupPath! + "_Backups", backupDate.ToString("yyyyMMdd") + ".zip"); Assert.IsFalse(File.Exists(backupFilePath)); Assert.IsFalse(_assetRepository!.BackupExists()); @@ -160,14 +160,14 @@ public void WriteBackup_ConcurrentAccess_BackupsAreHandledSafely() Assert.IsTrue(File.Exists(backupFilePath)); Assert.IsTrue(_assetRepository!.BackupExists()); - int filesInBackupDirectory = Directory.GetFiles(backupPath! + "_Backups").Length; + int filesInBackupDirectory = Directory.GetFiles(_backupPath! + "_Backups").Length; Assert.AreEqual(1, filesInBackupDirectory); Assert.IsEmpty(assetsUpdatedEvents); } finally { - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests"), true); assetsUpdatedSubscription.Dispose(); } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/Database/DatabaseTests/DatabaseDeleteOldBackupsTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/Database/DatabaseTests/DatabaseDeleteOldBackupsTests.cs index 611a1e53..edae6b40 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/Database/DatabaseTests/DatabaseDeleteOldBackupsTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/Database/DatabaseTests/DatabaseDeleteOldBackupsTests.cs @@ -3,7 +3,7 @@ [TestFixture] public class DatabaseDeleteOldBackupsTests { - private string? dataDirectory; + private string? _dataDirectory; private PhotoManager.Infrastructure.Database.Database? _database; private UserConfigurationService? _userConfigurationService; @@ -11,7 +11,7 @@ public class DatabaseDeleteOldBackupsTests [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); Mock configurationRootMock = new(); configurationRootMock.GetDefaultMockConfig(); @@ -28,14 +28,14 @@ public void SetUp() [Test] public void DeleteOldBackups_DeletesExcessBackups_SuccessfullyDeletesBackups() { - ushort backupsToKeep = 3; - string path1 = Path.Combine(dataDirectory!, "DatabaseTests_Backups", "20230404.zip"); - string path2 = Path.Combine(dataDirectory!, "DatabaseTests_Backups", "20230304.zip"); - string path3 = Path.Combine(dataDirectory!, "DatabaseTests_Backups", "20230204.zip"); - string path4 = Path.Combine(dataDirectory!, "DatabaseTests_Backups", "20230104.zip"); - string path5 = Path.Combine(dataDirectory!, "DatabaseTests_Backups", "20230504.zip"); + const ushort backupsToKeep = 3; + string path1 = Path.Combine(_dataDirectory!, "DatabaseTests_Backups", "20230404.zip"); + string path2 = Path.Combine(_dataDirectory!, "DatabaseTests_Backups", "20230304.zip"); + string path3 = Path.Combine(_dataDirectory!, "DatabaseTests_Backups", "20230204.zip"); + string path4 = Path.Combine(_dataDirectory!, "DatabaseTests_Backups", "20230104.zip"); + string path5 = Path.Combine(_dataDirectory!, "DatabaseTests_Backups", "20230504.zip"); - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); try { @@ -73,19 +73,19 @@ public void DeleteOldBackups_DeletesExcessBackups_SuccessfullyDeletesBackups() finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } [Test] public void DeleteOldBackups_NoExcessBackups_NothingDeleted() { - ushort backupsToKeep = 3; - string path1 = Path.Combine(dataDirectory!, "DatabaseTests_Backups", "20230404.zip"); - string path2 = Path.Combine(dataDirectory!, "DatabaseTests_Backups", "20230304.zip"); - string path3 = Path.Combine(dataDirectory!, "DatabaseTests_Backups", "20230204.zip"); + const ushort backupsToKeep = 3; + string path1 = Path.Combine(_dataDirectory!, "DatabaseTests_Backups", "20230404.zip"); + string path2 = Path.Combine(_dataDirectory!, "DatabaseTests_Backups", "20230304.zip"); + string path3 = Path.Combine(_dataDirectory!, "DatabaseTests_Backups", "20230204.zip"); - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); try { @@ -115,7 +115,7 @@ public void DeleteOldBackups_NoExcessBackups_NothingDeleted() finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } } diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/Database/Storage/ObjectListStorageTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/Database/Storage/ObjectListStorageTests.cs index df493ed6..b10b89a1 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/Database/Storage/ObjectListStorageTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/Database/Storage/ObjectListStorageTests.cs @@ -3,7 +3,7 @@ [TestFixture] public class ObjectListStorageTests { - private string? dataDirectory; + private string? _dataDirectory; private ObjectListStorage? _objectListStorage; private UserConfigurationService? _userConfigurationService; @@ -11,7 +11,7 @@ public class ObjectListStorageTests [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); Mock configurationRootMock = new(); configurationRootMock.GetDefaultMockConfig(); @@ -28,7 +28,7 @@ public void SetUp() [Test] public void ReadObjectList_FolderType_ReturnsNotEmptyList() { - string dataFilePath = Path.Combine(dataDirectory!, "TestBackup\\v1.0\\Tables\\folders.db"); + string dataFilePath = Path.Combine(_dataDirectory!, "TestBackup\\v1.0\\Tables\\folders.db"); DataTableProperties dataTableProperties = new() { TableName = _userConfigurationService!.StorageSettings.TablesSettings.FoldersTableName, @@ -59,7 +59,7 @@ public void ReadObjectList_FolderType_ReturnsNotEmptyList() [Test] public void ReadObjectList_AssetType_ReturnsNotEmptyList() { - string dataFilePath = Path.Combine(dataDirectory!, "TestBackup\\v1.0\\Tables\\assets.db"); + string dataFilePath = Path.Combine(_dataDirectory!, "TestBackup\\v1.0\\Tables\\assets.db"); DataTableProperties dataTableProperties = new() { TableName = _userConfigurationService!.StorageSettings.TablesSettings.AssetsTableName, @@ -77,24 +77,24 @@ public void ReadObjectList_AssetType_ReturnsNotEmptyList() Asset? asset = result.FirstOrDefault(x => x.Hash == "ee43714d8b96d7ed3308d18afcb701444198c783fbe4103ce44e95aaf99c2095ae70e6e2035a7a438d1598fadaf5fe8cb0d541378387d20e91f26819fcc64b82"); Assert.IsNotNull(asset); Assert.AreEqual("533.JPG", asset!.FileName); - Assert.AreEqual(new Guid("f1f00403-0554-4201-9b6b-11a6b4cea3a9"), asset!.FolderId); - Assert.AreEqual(2986996, asset!.FileSize); - Assert.AreEqual(Rotation.Rotate270, asset!.ImageRotation); - Assert.AreEqual(3072, asset!.PixelWidth); - Assert.AreEqual(4080, asset!.PixelHeight); - Assert.AreEqual(113, asset!.ThumbnailPixelWidth); - Assert.AreEqual(150, asset!.ThumbnailPixelHeight); - Assert.AreEqual(new DateTime(2023, 8, 25, 12, 01, 21), asset!.ThumbnailCreationDateTime); - Assert.AreEqual(string.Empty, asset!.AssetCorruptedMessage); - Assert.AreEqual(false, asset!.IsAssetCorrupted); - Assert.AreEqual("The asset has been rotated", asset!.AssetRotatedMessage); - Assert.AreEqual(true, asset!.IsAssetRotated); + Assert.AreEqual(new Guid("f1f00403-0554-4201-9b6b-11a6b4cea3a9"), asset.FolderId); + Assert.AreEqual(2986996, asset.FileSize); + Assert.AreEqual(Rotation.Rotate270, asset.ImageRotation); + Assert.AreEqual(3072, asset.PixelWidth); + Assert.AreEqual(4080, asset.PixelHeight); + Assert.AreEqual(113, asset.ThumbnailPixelWidth); + Assert.AreEqual(150, asset.ThumbnailPixelHeight); + Assert.AreEqual(new DateTime(2023, 8, 25, 12, 01, 21), asset.ThumbnailCreationDateTime); + Assert.AreEqual(string.Empty, asset.AssetCorruptedMessage); + Assert.AreEqual(false, asset.IsAssetCorrupted); + Assert.AreEqual("The asset has been rotated", asset.AssetRotatedMessage); + Assert.AreEqual(true, asset.IsAssetRotated); } [Test] public void ReadObjectList_SyncAssetsDirectoriesDefinitionType_ReturnsNotEmptyList() { - string dataFilePath = Path.Combine(dataDirectory!, "TestBackup\\v1.0\\Tables\\syncassetsdirectoriesdefinitions.db"); + string dataFilePath = Path.Combine(_dataDirectory!, "TestBackup\\v1.0\\Tables\\syncassetsdirectoriesdefinitions.db"); DataTableProperties dataTableProperties = new() { TableName = _userConfigurationService!.StorageSettings.TablesSettings.SyncAssetsDirectoriesDefinitionsTableName, @@ -125,7 +125,7 @@ public void ReadObjectList_SyncAssetsDirectoriesDefinitionType_ReturnsNotEmptyLi [Test] public void ReadObjectList_RecentTargetPathsType_ReturnsNotEmptyList() { - string dataFilePath = Path.Combine(dataDirectory!, "TestBackup\\v1.0\\Tables\\recenttargetpaths.db"); + string dataFilePath = Path.Combine(_dataDirectory!, "TestBackup\\v1.0\\Tables\\recenttargetpaths.db"); DataTableProperties dataTableProperties = new() { TableName = _userConfigurationService!.StorageSettings.TablesSettings.RecentTargetPathsTableName, @@ -145,7 +145,7 @@ public void ReadObjectList_RecentTargetPathsType_ReturnsNotEmptyList() [Test] public void ReadObjectList_SyncAssetsDirectoriesDefinitionTypeEmpty_ReturnsEmptyList() { - string dataFilePath = Path.Combine(dataDirectory!, "TestBackup\\v1.0\\Tables\\syncassetsdirectoriesdefinitions_empty.db"); + string dataFilePath = Path.Combine(_dataDirectory!, "TestBackup\\v1.0\\Tables\\syncassetsdirectoriesdefinitions_empty.db"); DataTableProperties dataTableProperties = new() { TableName = _userConfigurationService!.StorageSettings.TablesSettings.SyncAssetsDirectoriesDefinitionsTableName, @@ -163,7 +163,7 @@ public void ReadObjectList_SyncAssetsDirectoriesDefinitionTypeEmpty_ReturnsEmpty [Test] public void ReadObjectList_FolderTypeWithoutProperties_ReturnsNotEmptyList() { - string dataFilePath = Path.Combine(dataDirectory!, "TestBackup\\v1.0\\Tables\\folders.db"); + string dataFilePath = Path.Combine(_dataDirectory!, "TestBackup\\v1.0\\Tables\\folders.db"); DataTableProperties? dataTableProperties = null; _objectListStorage!.Initialize(dataTableProperties!, _userConfigurationService!.StorageSettings.Separator); @@ -178,7 +178,7 @@ public void ReadObjectList_FolderTypeWithoutProperties_ReturnsNotEmptyList() [Test] public void ReadObjectList_FolderTypeWithoutInitialize_ThrowsFormatException() { - string dataFilePath = Path.Combine(dataDirectory!, "TestBackup\\v1.0\\Tables\\folders.db"); + string dataFilePath = Path.Combine(_dataDirectory!, "TestBackup\\v1.0\\Tables\\folders.db"); FormatException? exception = Assert.Throws(() => { @@ -191,7 +191,7 @@ public void ReadObjectList_FolderTypeWithoutInitialize_ThrowsFormatException() [Test] public void ReadObjectList_SyncAssetsDirectoriesDefinitionTypeWithoutInitialize_ThrowsIndexOutOfRangeException() { - string dataFilePath = Path.Combine(dataDirectory!, "TestBackup\\v1.0\\Tables\\syncassetsdirectoriesdefinitions.db"); + string dataFilePath = Path.Combine(_dataDirectory!, "TestBackup\\v1.0\\Tables\\syncassetsdirectoriesdefinitions.db"); IndexOutOfRangeException? exception = Assert.Throws(() => { @@ -204,7 +204,7 @@ public void ReadObjectList_SyncAssetsDirectoriesDefinitionTypeWithoutInitialize_ [Test] public void ReadObjectList_AssetTypeButReadingWrongFile_ThrowsFormatException() { - string dataFilePath = Path.Combine(dataDirectory!, "TestBackup\\v1.0\\Tables\\folders.db"); + string dataFilePath = Path.Combine(_dataDirectory!, "TestBackup\\v1.0\\Tables\\folders.db"); DataTableProperties dataTableProperties = new() { TableName = _userConfigurationService!.StorageSettings.TablesSettings.AssetsTableName, @@ -224,14 +224,14 @@ public void ReadObjectList_AssetTypeButReadingWrongFile_ThrowsFormatException() [Test] public void ReadObjectList_FileDoesNotExist_ReturnsEmptyList() { - string dataFilePath = Path.Combine(dataDirectory!, "TestBackup\\v1.0\\Tables\\nonExistent.db"); + string dataFilePath = Path.Combine(_dataDirectory!, "TestBackup\\v1.0\\Tables\\nonExistent.db"); DataTableProperties dataTableProperties = new() { TableName = "NonExistent", - ColumnProperties = new ColumnProperties[] - { - new ColumnProperties { ColumnName = "NonExistent" } - } + ColumnProperties = + [ + new() { ColumnName = "NonExistent" } + ] }; _objectListStorage!.Initialize(dataTableProperties, _userConfigurationService!.StorageSettings.Separator); @@ -247,15 +247,15 @@ public void ReadObjectList_FilePathIsInvalid_ReturnsEmptyList() DataTableProperties dataTableProperties = new() { TableName = "NonExistent", - ColumnProperties = new ColumnProperties[] - { - new ColumnProperties { ColumnName = "NonExistent" } - } + ColumnProperties = + [ + new() { ColumnName = "NonExistent" } + ] }; _objectListStorage!.Initialize(dataTableProperties, _userConfigurationService!.StorageSettings.Separator); - List result = _objectListStorage!.ReadObjectList(dataDirectory!, RecentPathsConfigs.ReadFunc, new Diagnostics()); + List result = _objectListStorage!.ReadObjectList(_dataDirectory!, RecentPathsConfigs.ReadFunc, new Diagnostics()); Assert.IsEmpty(result); } @@ -263,14 +263,14 @@ public void ReadObjectList_FilePathIsInvalid_ReturnsEmptyList() [Test] public void ReadObjectList_FilePathDoesNotExist_ReturnsEmptyList() { - string dataFilePath = Path.Combine(dataDirectory!, "Toto\\nonExistent.db"); + string dataFilePath = Path.Combine(_dataDirectory!, "Toto\\nonExistent.db"); DataTableProperties dataTableProperties = new() { TableName = "NonExistent", - ColumnProperties = new ColumnProperties[] - { - new ColumnProperties { ColumnName = "NonExistent" } - } + ColumnProperties = + [ + new() { ColumnName = "NonExistent" } + ] }; _objectListStorage!.Initialize(dataTableProperties, _userConfigurationService!.StorageSettings.Separator); @@ -287,10 +287,10 @@ public void ReadObjectList_FilePathIsNull_ReturnsEmptyList() DataTableProperties dataTableProperties = new() { TableName = "NonExistent", - ColumnProperties = new ColumnProperties[] - { - new ColumnProperties { ColumnName = "NonExistent" } - } + ColumnProperties = + [ + new() { ColumnName = "NonExistent" } + ] }; _objectListStorage!.Initialize(dataTableProperties, _userConfigurationService!.StorageSettings.Separator); @@ -303,7 +303,7 @@ public void ReadObjectList_FilePathIsNull_ReturnsEmptyList() [Test] public void ReadObjectList_FolderTypeFuncIsNull_ThrowsNullReferenceException() { - string dataFilePath = Path.Combine(dataDirectory!, "TestBackup\\v1.0\\Tables\\folders.db"); + string dataFilePath = Path.Combine(_dataDirectory!, "TestBackup\\v1.0\\Tables\\folders.db"); DataTableProperties dataTableProperties = new() { TableName = _userConfigurationService!.StorageSettings.TablesSettings.FoldersTableName, @@ -314,7 +314,7 @@ public void ReadObjectList_FolderTypeFuncIsNull_ThrowsNullReferenceException() Func? func = null; - NullReferenceException? exception = Assert.Throws(() => _objectListStorage!.ReadObjectList(dataFilePath!, func!, new Diagnostics())); + NullReferenceException? exception = Assert.Throws(() => _objectListStorage!.ReadObjectList(dataFilePath, func!, new Diagnostics())); Assert.AreEqual("Object reference not set to an instance of an object.", exception?.Message); } @@ -322,25 +322,27 @@ public void ReadObjectList_FolderTypeFuncIsNull_ThrowsNullReferenceException() [Test] public void WriteObjectList_FolderType_WritesCorrectCsv() { - string dataFilePath = Path.Combine(dataDirectory!, "folders.db"); - List folders = new() - { - new Folder + string dataFilePath = Path.Combine(_dataDirectory!, "folders.db"); + List folders = + [ + new() { FolderId = new Guid("dfc8aab7-3543-48e7-9fdc-596ba733761e"), Path = "D:\\Workspace\\PhotoManager\\Test" }, - new Folder + + new() { FolderId = new Guid("8f9dff55-4a15-411e-a4cb-7ec3024b2238"), Path = "D:\\Workspace\\PhotoManager\\Test\\OutputVideoFirstFrame" }, - new Folder + + new() { FolderId = new Guid("db4d226f-6901-43f9-9e82-e6a052f627d2"), Path = "D:\\Workspace\\PhotoManager\\Test\\toto" } - }; + ]; DataTableProperties dataTableProperties = new() { @@ -364,12 +366,13 @@ public void WriteObjectList_FolderType_WritesCorrectCsv() [Test] public void WriteObjectList_AssetType_WritesCorrectCsv() { - string dataFilePath = Path.Combine(dataDirectory!, "assets.db"); - List assets = new() - { - new Asset + string dataFilePath = Path.Combine(_dataDirectory!, "assets.db"); + List assets = + [ + new() { FolderId = new Guid("dfc8aab7-3543-48e7-9fdc-596ba733761e"), + Folder = new() { Path = "" }, FileName = "1336.JPG", FileSize = 4526710, ImageRotation = Rotation.Rotate0, @@ -378,15 +381,18 @@ public void WriteObjectList_AssetType_WritesCorrectCsv() ThumbnailPixelWidth = 200, ThumbnailPixelHeight = 150, ThumbnailCreationDateTime = new DateTime(2023, 8, 19, 11, 26, 05), - Hash = "fb0bb3887c28d022113c5c52a65f9da14eab0806842f902b618806dedeb7c53da1ed26ae5bcaf9a358e81efead71c4807ea38054e44f426857f8bf2c1fd1c7aa", + Hash = + "fb0bb3887c28d022113c5c52a65f9da14eab0806842f902b618806dedeb7c53da1ed26ae5bcaf9a358e81efead71c4807ea38054e44f426857f8bf2c1fd1c7aa", AssetCorruptedMessage = null, IsAssetCorrupted = false, AssetRotatedMessage = null, IsAssetRotated = false }, - new Asset + + new() { FolderId = new Guid("dfc8aab7-3543-48e7-9fdc-596ba733761f"), + Folder = new() { Path = "" }, FileName = "1452.DNG", FileSize = 5286168, ImageRotation = Rotation.Rotate90, @@ -395,13 +401,14 @@ public void WriteObjectList_AssetType_WritesCorrectCsv() ThumbnailPixelWidth = 200, ThumbnailPixelHeight = 150, ThumbnailCreationDateTime = new DateTime(2023, 8, 19, 11, 26, 05), - Hash = "e9680ad893bee9471a55421c0ea30075723f3ad274caec6300f7ce44adefb8a68b1a4f65ea25543a39f60d63af1681eca61bfb6b6f18d38c8dbb0672e2018e58", + Hash = + "e9680ad893bee9471a55421c0ea30075723f3ad274caec6300f7ce44adefb8a68b1a4f65ea25543a39f60d63af1681eca61bfb6b6f18d38c8dbb0672e2018e58", AssetCorruptedMessage = null, IsAssetCorrupted = false, AssetRotatedMessage = "The asset has been rotated", IsAssetRotated = true } - }; + ]; DataTableProperties dataTableProperties = new() { @@ -425,15 +432,15 @@ public void WriteObjectList_AssetType_WritesCorrectCsv() [Test] public void WriteObjectList_SyncAssetsDirectoriesDefinitionType_WritesCorrectCsv() { - string dataFilePath = Path.Combine(dataDirectory!, "syncassetsdirectoriesdefinitions.db"); - List syncAssetsDirectoriesDefinitions = new() - { - new SyncAssetsDirectoriesDefinition + string dataFilePath = Path.Combine(_dataDirectory!, "syncassetsdirectoriesdefinitions.db"); + List syncAssetsDirectoriesDefinitions = + [ + new() { - SourceDirectory = Path.Combine(dataDirectory!, "toto"), - DestinationDirectory = Path.Combine(dataDirectory!, "tutu") + SourceDirectory = Path.Combine(_dataDirectory!, "toto"), + DestinationDirectory = Path.Combine(_dataDirectory!, "tutu") } - }; + ]; DataTableProperties dataTableProperties = new() { @@ -457,12 +464,12 @@ public void WriteObjectList_SyncAssetsDirectoriesDefinitionType_WritesCorrectCsv [Test] public void WriteObjectList_RecentTargetPathsType_WritesCorrectCsv() { - string dataFilePath = Path.Combine(dataDirectory!, "recenttargetpaths.db"); - List recentTargetPaths = new() - { - Path.Combine(dataDirectory!, "toto"), - Path.Combine(dataDirectory!, "tutu") - }; + string dataFilePath = Path.Combine(_dataDirectory!, "recenttargetpaths.db"); + List recentTargetPaths = + [ + Path.Combine(_dataDirectory!, "toto"), + Path.Combine(_dataDirectory!, "tutu") + ]; DataTableProperties dataTableProperties = new() { @@ -486,25 +493,27 @@ public void WriteObjectList_RecentTargetPathsType_WritesCorrectCsv() [Test] public void WriteObjectList_FolderTypeWithoutProperties_ThrowsException() { - string dataFilePath = Path.Combine(dataDirectory!, "folders.db"); - List folders = new() - { - new Folder + string dataFilePath = Path.Combine(_dataDirectory!, "folders.db"); + List folders = + [ + new() { FolderId = new Guid("dfc8aab7-3543-48e7-9fdc-596ba733761e"), Path = "D:\\Workspace\\PhotoManager\\Test" }, - new Folder + + new() { FolderId = new Guid("8f9dff55-4a15-411e-a4cb-7ec3024b2238"), Path = "D:\\Workspace\\PhotoManager\\Test\\OutputVideoFirstFrame" }, - new Folder + + new() { FolderId = new Guid("db4d226f-6901-43f9-9e82-e6a052f627d2"), Path = "D:\\Workspace\\PhotoManager\\Test\\toto" } - }; + ]; DataTableProperties? dataTableProperties = null; @@ -520,31 +529,27 @@ public void WriteObjectList_FolderTypeWithoutProperties_ThrowsException() [Test] public void WriteObjectList_FolderTypeWithoutInitialize_ThrowsException() { - string dataFilePath = Path.Combine(dataDirectory!, "folders.db"); - List folders = new() - { - new Folder + string dataFilePath = Path.Combine(_dataDirectory!, "folders.db"); + List folders = + [ + new() { FolderId = new Guid("dfc8aab7-3543-48e7-9fdc-596ba733761e"), Path = "D:\\Workspace\\PhotoManager\\Test" }, - new Folder + + new() { FolderId = new Guid("8f9dff55-4a15-411e-a4cb-7ec3024b2238"), Path = "D:\\Workspace\\PhotoManager\\Test\\OutputVideoFirstFrame" }, - new Folder + + new() { FolderId = new Guid("db4d226f-6901-43f9-9e82-e6a052f627d2"), Path = "D:\\Workspace\\PhotoManager\\Test\\toto" } - }; - - DataTableProperties dataTableProperties = new() - { - TableName = _userConfigurationService!.StorageSettings.TablesSettings.FoldersTableName, - ColumnProperties = FolderConfigs.ConfigureDataTable() - }; + ]; Exception? exception = Assert.Throws(() => _objectListStorage!.WriteObjectList(dataFilePath, folders, FolderConfigs.WriteFunc, new Diagnostics())); @@ -556,26 +561,23 @@ public void WriteObjectList_FolderTypeWithoutInitialize_ThrowsException() [Test] public void WriteObjectList_FilePathDoesNotExist_ThrowsDirectoryNotFoundException() { - string dataFilePath = Path.Combine(dataDirectory!, "nonExistent", "nonExistent.db"); - List nonExistents = new() - { - "D:\\Workspace\\PhotoManager\\Test" - }; + string dataFilePath = Path.Combine(_dataDirectory!, "nonExistent", "nonExistent.db"); + List nonExistentValues = ["D:\\Workspace\\PhotoManager\\Test"]; DataTableProperties dataTableProperties = new() { TableName = "NonExistent", - ColumnProperties = new ColumnProperties[] - { - new ColumnProperties { ColumnName = "NonExistent" } - } + ColumnProperties = + [ + new() { ColumnName = "NonExistent" } + ] }; _objectListStorage!.Initialize(dataTableProperties, _userConfigurationService!.StorageSettings.Separator); DirectoryNotFoundException? exception = Assert.Throws(() => { - _objectListStorage!.WriteObjectList(dataFilePath, nonExistents, RecentPathsConfigs.WriteFunc, new Diagnostics()); + _objectListStorage!.WriteObjectList(dataFilePath, nonExistentValues, RecentPathsConfigs.WriteFunc, new Diagnostics()); }); Assert.AreEqual($"Could not find a part of the path '{dataFilePath}'.", exception?.Message); @@ -585,53 +587,47 @@ public void WriteObjectList_FilePathDoesNotExist_ThrowsDirectoryNotFoundExceptio [Test] public void WriteObjectList_FilePathIsInvalid_ThrowsUnauthorizedAccessException() { - List nonExistents = new() - { - "D:\\Workspace\\PhotoManager\\Test" - }; + List nonExistentValues = ["D:\\Workspace\\PhotoManager\\Test"]; DataTableProperties dataTableProperties = new() { TableName = "NonExistent", - ColumnProperties = new ColumnProperties[] - { - new ColumnProperties { ColumnName = "NonExistent" } - } + ColumnProperties = + [ + new() { ColumnName = "NonExistent" } + ] }; _objectListStorage!.Initialize(dataTableProperties, _userConfigurationService!.StorageSettings.Separator); UnauthorizedAccessException? exception = Assert.Throws(() => { - _objectListStorage!.WriteObjectList(dataDirectory!, nonExistents, RecentPathsConfigs.WriteFunc, new Diagnostics()); + _objectListStorage!.WriteObjectList(_dataDirectory!, nonExistentValues, RecentPathsConfigs.WriteFunc, new Diagnostics()); }); - Assert.AreEqual($"Access to the path '{dataDirectory!}' is denied.", exception?.Message); + Assert.AreEqual($"Access to the path '{_dataDirectory!}' is denied.", exception?.Message); } [Test] public void WriteObjectList_FilePathIsNull_ThrowsArgumentNullException() { string? dataFilePath = null; - List nonExistents = new() - { - "D:\\Workspace\\PhotoManager\\Test" - }; + List nonExistentValues = ["D:\\Workspace\\PhotoManager\\Test"]; DataTableProperties dataTableProperties = new() { TableName = "NonExistent", - ColumnProperties = new ColumnProperties[] - { - new ColumnProperties { ColumnName = "NonExistent" } - } + ColumnProperties = + [ + new() { ColumnName = "NonExistent" } + ] }; _objectListStorage!.Initialize(dataTableProperties, _userConfigurationService!.StorageSettings.Separator); ArgumentNullException? exception = Assert.Throws(() => { - _objectListStorage!.WriteObjectList(dataFilePath!, nonExistents, RecentPathsConfigs.WriteFunc, new Diagnostics()); + _objectListStorage!.WriteObjectList(dataFilePath!, nonExistentValues, RecentPathsConfigs.WriteFunc, new Diagnostics()); }); Assert.AreEqual("Value cannot be null. (Parameter 'path')", exception?.Message); @@ -641,16 +637,16 @@ public void WriteObjectList_FilePathIsNull_ThrowsArgumentNullException() [Test] public void WriteObjectList_ListIsNull_ThrowsNullReferenceException() { - string dataFilePath = Path.Combine(dataDirectory!, "nonExistent.db"); - List? nonExistents = null; + string dataFilePath = Path.Combine(_dataDirectory!, "nonExistent.db"); + List? nonExistentValues = null; DataTableProperties dataTableProperties = new() { TableName = "NonExistent", - ColumnProperties = new ColumnProperties[] - { - new ColumnProperties { ColumnName = "NonExistent" } - } + ColumnProperties = + [ + new() { ColumnName = "NonExistent" } + ] }; _objectListStorage!.Initialize(dataTableProperties, _userConfigurationService!.StorageSettings.Separator); @@ -658,7 +654,7 @@ public void WriteObjectList_ListIsNull_ThrowsNullReferenceException() NullReferenceException? exception = Assert.Throws(() => _objectListStorage!.WriteObjectList( dataFilePath, - nonExistents!, + nonExistentValues!, (f, i) => { return i switch @@ -676,19 +672,16 @@ public void WriteObjectList_ListIsNull_ThrowsNullReferenceException() [Test] public void WriteObjectList_FuncIsNull_ThrowsNullReferenceException() { - string dataFilePath = Path.Combine(dataDirectory!, "nonExistent.db"); - List nonExistents = new() - { - "D:\\Workspace\\PhotoManager\\Test" - }; + string dataFilePath = Path.Combine(_dataDirectory!, "nonExistent.db"); + List nonExistentValues = ["D:\\Workspace\\PhotoManager\\Test"]; DataTableProperties dataTableProperties = new() { TableName = "NonExistent", - ColumnProperties = new ColumnProperties[] - { - new ColumnProperties { ColumnName = "NonExistent" } - } + ColumnProperties = + [ + new() { ColumnName = "NonExistent" } + ] }; _objectListStorage!.Initialize(dataTableProperties, _userConfigurationService!.StorageSettings.Separator); @@ -697,7 +690,7 @@ public void WriteObjectList_FuncIsNull_ThrowsNullReferenceException() NullReferenceException? exception = Assert.Throws(() => _objectListStorage!.WriteObjectList( dataFilePath, - nonExistents, + nonExistentValues, f!, new Diagnostics())); diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/StorageServiceTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/StorageServiceTests.cs index 1fb2da47..df2a4ff0 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/StorageServiceTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/StorageServiceTests.cs @@ -542,7 +542,7 @@ public void GetGifBitmapImage_NullImage_ThrowsArgumentException() public void FileExists_ExistingFile_ReturnsTrue() { Folder folder = new() { Path = _dataDirectory! }; - Asset asset = new() { FileName = "Image 1.jpg" }; + Asset asset = new() { Folder = new() { Path = "" }, FileName = "Image 1.jpg", Hash = string.Empty }; bool exists = _storageService!.FileExists(folder, asset); @@ -553,7 +553,7 @@ public void FileExists_ExistingFile_ReturnsTrue() public void FileExists_FileDoesNotExist_ReturnsFalse() { Folder folder = new() { Path = _dataDirectory! }; - Asset asset = new() { FileName = "NonExistent.jpg" }; + Asset asset = new() { Folder = new() { Path = "" }, FileName = "NonExistent.jpg", Hash = string.Empty }; bool exists = _storageService!.FileExists(folder, asset); @@ -566,7 +566,7 @@ public void FileExists_FileDoesNotExist_ReturnsFalse() public void FileExists_NullFileNameOrNullPath_ThrowsArgumentNullException(string path, string fileName, string exceptionParameter) { Folder folder = new() { Path = path }; - Asset asset = new() { FileName = fileName }; + Asset asset = new() { Folder = new() { Path = "" }, FileName = fileName, Hash = string.Empty }; ArgumentNullException? exception = Assert.Throws(() => _storageService!.FileExists(folder, asset)); @@ -668,11 +668,11 @@ public void UpdateAssetsFileDateTimeProperties_SomeFilesExist_PopulatesAssetsDat File.SetLastWriteTime(destinationFilePath3, oldDateTime); File.SetLastWriteTime(destinationFilePath4, oldDateTime); - Asset asset1 = new() { Folder = folder, FileName = fileName1 }; - Asset asset2 = new() { Folder = folder, FileName = fileName2 }; - Asset asset3 = new() { Folder = folder, FileName = fileName3 }; - Asset asset4 = new() { Folder = folder, FileName = fileName4 }; - Asset asset5 = new() { Folder = folder, FileName = fileName5 }; + Asset asset1 = new() { Folder = folder, FileName = fileName1, Hash = string.Empty }; + Asset asset2 = new() { Folder = folder, FileName = fileName2, Hash = string.Empty }; + Asset asset3 = new() { Folder = folder, FileName = fileName3, Hash = string.Empty }; + Asset asset4 = new() { Folder = folder, FileName = fileName4, Hash = string.Empty }; + Asset asset5 = new() { Folder = folder, FileName = fileName5, Hash = string.Empty }; Assert.AreEqual(DateTime.MinValue, asset1.FileCreationDateTime.Date); Assert.AreEqual(DateTime.MinValue, asset1.FileModificationDateTime.Date); @@ -720,82 +720,6 @@ public void UpdateAssetsFileDateTimeProperties_AssetsIsNull_ThrowsNullReferenceE Assert.AreEqual("Object reference not set to an instance of an object.", exception?.Message); } - [Test] - public void UpdateAssetsFileDateTimeProperties_FolderIsNull_DoesNotPopulateAssetsDates() - { - string destinationPath = Path.Combine(_dataDirectory!, "DestinationToCopy"); - - try - { - Directory.CreateDirectory(destinationPath); - - const string fileName1 = "Homer.gif"; - const string fileName2 = "Image 1.jpg"; - const string fileName3 = "Image 9.png"; - const string fileName4 = "Image_11.heic"; - const string fileName5 = "nonexistent.jpg"; - - string sourceFilePath1 = Path.Combine(_dataDirectory!, fileName1); - string destinationFilePath1 = Path.Combine(destinationPath, fileName1); - string sourceFilePath2 = Path.Combine(_dataDirectory!, fileName2); - string destinationFilePath2 = Path.Combine(destinationPath, fileName2); - string sourceFilePath3 = Path.Combine(_dataDirectory!, fileName3); - string destinationFilePath3 = Path.Combine(destinationPath, fileName3); - string sourceFilePath4 = Path.Combine(_dataDirectory!, fileName4); - string destinationFilePath4 = Path.Combine(destinationPath, fileName4); - - File.Copy(sourceFilePath1, destinationFilePath1); - File.Copy(sourceFilePath2, destinationFilePath2); - File.Copy(sourceFilePath3, destinationFilePath3); - File.Copy(sourceFilePath4, destinationFilePath4); - - Folder? folder = null; - - DateTime creationTime = default; - DateTime modificationTime = default; - DateTime oldDateTime = DateTime.Now.AddDays(-1); - - File.SetLastWriteTime(destinationFilePath1, oldDateTime); - File.SetLastWriteTime(destinationFilePath2, oldDateTime); - File.SetLastWriteTime(destinationFilePath3, oldDateTime); - File.SetLastWriteTime(destinationFilePath4, oldDateTime); - - Asset asset1 = new() { Folder = folder!, FileName = fileName1 }; - Asset asset2 = new() { Folder = folder!, FileName = fileName2 }; - Asset asset3 = new() { Folder = folder!, FileName = fileName3 }; - Asset asset4 = new() { Folder = folder!, FileName = fileName4 }; - Asset asset5 = new() { Folder = folder!, FileName = fileName5 }; - - Assert.AreEqual(creationTime.Date, asset1.FileCreationDateTime.Date); - Assert.AreEqual(modificationTime.Date, asset1.FileModificationDateTime.Date); - Assert.AreEqual(creationTime.Date, asset2.FileCreationDateTime.Date); - Assert.AreEqual(modificationTime.Date, asset2.FileModificationDateTime.Date); - Assert.AreEqual(creationTime.Date, asset3.FileCreationDateTime.Date); - Assert.AreEqual(modificationTime.Date, asset3.FileModificationDateTime.Date); - Assert.AreEqual(creationTime.Date, asset4.FileCreationDateTime.Date); - Assert.AreEqual(modificationTime.Date, asset4.FileModificationDateTime.Date); - Assert.AreEqual(creationTime.Date, asset5.FileCreationDateTime.Date); - Assert.AreEqual(modificationTime.Date, asset5.FileModificationDateTime.Date); - - _storageService!.UpdateAssetsFileDateTimeProperties([asset1, asset2, asset3, asset4, asset5]); - - Assert.AreEqual(creationTime.Date, asset1.FileCreationDateTime.Date); - Assert.AreEqual(modificationTime.Date, asset1.FileModificationDateTime.Date); - Assert.AreEqual(creationTime.Date, asset2.FileCreationDateTime.Date); - Assert.AreEqual(modificationTime.Date, asset2.FileModificationDateTime.Date); - Assert.AreEqual(creationTime.Date, asset3.FileCreationDateTime.Date); - Assert.AreEqual(modificationTime.Date, asset3.FileModificationDateTime.Date); - Assert.AreEqual(creationTime.Date, asset4.FileCreationDateTime.Date); - Assert.AreEqual(modificationTime.Date, asset4.FileModificationDateTime.Date); - Assert.AreEqual(creationTime.Date, asset5.FileCreationDateTime.Date); - Assert.AreEqual(modificationTime.Date, asset5.FileModificationDateTime.Date); - } - finally - { - Directory.Delete(destinationPath, true); - } - } - [Test] public void UpdateAssetsFileDateTimeProperties_FilePathIsNull_ThrowsArgumentNullException() { @@ -837,11 +761,11 @@ public void UpdateAssetsFileDateTimeProperties_FilePathIsNull_ThrowsArgumentNull File.SetLastWriteTime(destinationFilePath3, oldDateTime); File.SetLastWriteTime(destinationFilePath4, oldDateTime); - Asset asset1 = new() { Folder = folder, FileName = fileName1 }; - Asset asset2 = new() { Folder = folder, FileName = fileName2 }; - Asset asset3 = new() { Folder = folder, FileName = fileName3 }; - Asset asset4 = new() { Folder = folder, FileName = fileName4 }; - Asset asset5 = new() { Folder = folder, FileName = fileName5 }; + Asset asset1 = new() { Folder = folder, FileName = fileName1, Hash = string.Empty }; + Asset asset2 = new() { Folder = folder, FileName = fileName2, Hash = string.Empty }; + Asset asset3 = new() { Folder = folder, FileName = fileName3, Hash = string.Empty }; + Asset asset4 = new() { Folder = folder, FileName = fileName4, Hash = string.Empty }; + Asset asset5 = new() { Folder = folder, FileName = fileName5, Hash = string.Empty }; Assert.AreEqual(creationTime.Date, asset1.FileCreationDateTime.Date); Assert.AreEqual(modificationTime.Date, asset1.FileModificationDateTime.Date); @@ -914,11 +838,11 @@ public void UpdateAssetsFileDateTimeProperties_OneAssetIsNull_ThrowsNullReferenc File.SetLastWriteTime(destinationFilePath3, oldDateTime); File.SetLastWriteTime(destinationFilePath4, oldDateTime); - Asset asset1 = new() { Folder = folder, FileName = fileName1 }; - Asset asset2 = new() { Folder = folder, FileName = fileName2 }; + Asset asset1 = new() { Folder = folder, FileName = fileName1, Hash = string.Empty }; + Asset asset2 = new() { Folder = folder, FileName = fileName2, Hash = string.Empty }; Asset? asset3 = null; - Asset asset4 = new() { Folder = folder, FileName = fileName4 }; - Asset asset5 = new() { Folder = folder, FileName = fileName5 }; + Asset asset4 = new() { Folder = folder, FileName = fileName4, Hash = string.Empty }; + Asset asset5 = new() { Folder = folder, FileName = fileName5, Hash = string.Empty }; Assert.AreEqual(DateTime.MinValue, asset1.FileCreationDateTime.Date); Assert.AreEqual(DateTime.MinValue, asset1.FileModificationDateTime.Date); @@ -971,7 +895,7 @@ public void UpdateAssetFileDateTimeProperties_FileExists_PopulatesAssetDates() File.SetLastWriteTime(destinationFilePath, oldDateTime); - Asset asset = new() { Folder = folder, FileName = fileName }; + Asset asset = new() { Folder = folder, FileName = fileName, Hash = string.Empty }; Assert.AreEqual(DateTime.MinValue, asset.FileCreationDateTime.Date); Assert.AreEqual(DateTime.MinValue, asset.FileModificationDateTime.Date); @@ -999,7 +923,7 @@ public void UpdateAssetFileDateTimeProperties_FileDoesNotExist_DoesNotPopulateAs const string fileName = "nonexistent.jpg"; Folder folder = new() { Path = destinationPath }; - Asset asset = new() { Folder = folder, FileName = fileName }; + Asset asset = new() { Folder = folder, FileName = fileName, Hash = string.Empty }; DateTime creationTime = default; DateTime modificationTime = default; @@ -1018,46 +942,6 @@ public void UpdateAssetFileDateTimeProperties_FileDoesNotExist_DoesNotPopulateAs } } - [Test] - public void UpdateAssetFileDateTimeProperties_FolderIsNull_DoesNotPopulateAssetDates() - { - string destinationPath = Path.Combine(_dataDirectory!, "DestinationToCopy"); - - try - { - Directory.CreateDirectory(destinationPath); - - const string fileName = "Image 1.jpg"; - - string sourceFilePath = Path.Combine(_dataDirectory!, fileName); - string destinationFilePath = Path.Combine(destinationPath, fileName); - - File.Copy(sourceFilePath, destinationFilePath); - - Folder? folder = null; - - DateTime creationTime = default; - DateTime modificationTime = default; - DateTime oldDateTime = DateTime.Now.AddDays(-1); - - File.SetLastWriteTime(destinationFilePath, oldDateTime); - - Asset asset = new() { Folder = folder!, FileName = fileName }; - - Assert.AreEqual(creationTime.Date, asset.FileCreationDateTime.Date); - Assert.AreEqual(modificationTime.Date, asset.FileModificationDateTime.Date); - - _storageService!.UpdateAssetFileDateTimeProperties(asset); - - Assert.AreEqual(creationTime.Date, asset.FileCreationDateTime.Date); - Assert.AreEqual(modificationTime.Date, asset.FileModificationDateTime.Date); - } - finally - { - Directory.Delete(destinationPath, true); - } - } - [Test] public void UpdateAssetFileDateTimeProperties_FilePathIsNull_ThrowsArgumentNullException() { @@ -1083,7 +967,7 @@ public void UpdateAssetFileDateTimeProperties_FilePathIsNull_ThrowsArgumentNullE File.SetLastWriteTime(destinationFilePath, oldDateTime); - Asset asset = new() { Folder = folder, FileName = fileName }; + Asset asset = new() { Folder = folder, FileName = fileName, Hash = string.Empty }; Assert.AreEqual(creationTime.Date, asset.FileCreationDateTime.Date); Assert.AreEqual(modificationTime.Date, asset.FileModificationDateTime.Date); diff --git a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/UserConfigurationServiceTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/UserConfigurationServiceTests.cs index d41b9ab3..7b2e128c 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/UserConfigurationServiceTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Infrastructure/UserConfigurationServiceTests.cs @@ -5,14 +5,14 @@ namespace PhotoManager.Tests.Integration.Infrastructure; [TestFixture] public class UserConfigurationServiceTests { - private string? dataDirectory; + private string? _dataDirectory; private UserConfigurationService? _userConfigurationService; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); - string configFilePath = Path.Combine(dataDirectory, "appsettings.json"); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + string configFilePath = Path.Combine(_dataDirectory, "appsettings.json"); IConfigurationBuilder builder = new ConfigurationBuilder().AddJsonFile(configFilePath, optional: false, reloadOnChange: true); IConfigurationRoot configuration = builder.Build(); @@ -30,8 +30,8 @@ public void OneTimeSetUp() [TestCase(WallpaperStyle.Fill, "10", "0")] public void SetAsWallpaper_ValidStyleAndTile_RegistersExpectedValues(WallpaperStyle style, string expectedStyleValue, string expectedTileValue) { - Folder folder = new() { Path = dataDirectory! }; - Asset asset = new() { Folder = folder, FileName = "NonExistentFile.jpg" }; // Not giving an existing file to prevent the wallpaper to be changed + Folder folder = new() { Path = _dataDirectory! }; + Asset asset = new() { Folder = folder, FileName = "NonExistentFile.jpg", Hash = string.Empty }; // Not giving an existing file to prevent the wallpaper to be changed // Set up a StringWriter to capture console output StringWriter stringWriter = new(); @@ -226,7 +226,7 @@ public void FirstFrameVideosPath_CorrectValue_ReturnsFirstFrameVideosPathValue() Assert.IsNotNull(assetsDirectory); Assert.IsNotNull(firstFrameVideosPath); - Assert.AreEqual(Path.Combine(assetsDirectory!, "OutputVideoFirstFrame"), firstFrameVideosPath); + Assert.AreEqual(Path.Combine(assetsDirectory, "OutputVideoFirstFrame"), firstFrameVideosPath); Assert.AreEqual(Path.Combine("E:\\Workspace\\PhotoManager\\Test\\OutputVideoFirstFrame"), firstFrameVideosPath); } diff --git a/PhotoManager/PhotoManager.Tests/Integration/UI/ViewModels/ApplicationVM/ApplicationViewModelCatalogAssetsTests.cs b/PhotoManager/PhotoManager.Tests/Integration/UI/ViewModels/ApplicationVM/ApplicationViewModelCatalogAssetsTests.cs index 64217ad9..b03c58e4 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/UI/ViewModels/ApplicationVM/ApplicationViewModelCatalogAssetsTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/UI/ViewModels/ApplicationVM/ApplicationViewModelCatalogAssetsTests.cs @@ -62,6 +62,7 @@ public void SetUp() { _asset1 = new() { + Folder = new() { Path = "" }, FileName = "Image 1_duplicate.jpg", FileSize = 29857, PixelHeight = 720, @@ -78,6 +79,7 @@ public void SetUp() }; _asset2 = new() { + Folder = new() { Path = "" }, FileName = "Image 9.png", FileSize = 126277, PixelHeight = 720, @@ -94,6 +96,7 @@ public void SetUp() }; _asset3 = new() { + Folder = new() { Path = "" }, FileName = "Image 9_duplicate.png", FileSize = 126277, PixelHeight = 720, @@ -110,6 +113,7 @@ public void SetUp() }; _asset4 = new() { + Folder = new() { Path = "" }, FileName = "Image_11.heic", FileSize = 1411940, PixelHeight = 4032, @@ -126,6 +130,7 @@ public void SetUp() }; _asset1Temp = new() { + Folder = new() { Path = "" }, FileName = "Image 1_duplicate_copied.jpg", FileSize = 29857, PixelHeight = 720, @@ -142,6 +147,7 @@ public void SetUp() }; _asset2Temp = new() { + Folder = new() { Path = "" }, FileName = "Image 1.jpg", FileSize = 29857, PixelHeight = 720, @@ -158,6 +164,7 @@ public void SetUp() }; _asset3Temp = new() { + Folder = new() { Path = "" }, FileName = "Homer.gif", FileSize = 64123, PixelHeight = 320, @@ -174,6 +181,7 @@ public void SetUp() }; _asset4Temp = new() { + Folder = new() { Path = "" }, FileName = "Homer.jpg", FileSize = 6599, PixelHeight = 180, @@ -190,6 +198,7 @@ public void SetUp() }; _asset5Temp = new() { + Folder = new() { Path = "" }, FileName = "HomerDuplicated.jpg", FileSize = 6599, PixelHeight = 180, @@ -5530,8 +5539,8 @@ public async Task CatalogAssets_AssetsAndRootCatalogFolderExistsAndOneFolderIsDe Folder? folder2Updated = _testableAssetRepository!.GetFolderByPath(tempDirectory); Assert.IsNull(folder2Updated); - Dictionary> folderToAssetsMappingFourthSync = new(); - Dictionary assetNameToByteSizeMappingFourthSync = new(); + Dictionary> folderToAssetsMappingFourthSync = []; + Dictionary assetNameToByteSizeMappingFourthSync = []; Assert.IsTrue(_testableAssetRepository!.BackupExists()); diff --git a/PhotoManager/PhotoManager.Tests/Integration/UI/ViewModels/ApplicationVM/ApplicationViewModelNotifyCatalogChangeTests.cs b/PhotoManager/PhotoManager.Tests/Integration/UI/ViewModels/ApplicationVM/ApplicationViewModelNotifyCatalogChangeTests.cs index 5c5da3cf..67749bda 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/UI/ViewModels/ApplicationVM/ApplicationViewModelNotifyCatalogChangeTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/UI/ViewModels/ApplicationVM/ApplicationViewModelNotifyCatalogChangeTests.cs @@ -67,6 +67,7 @@ public void SetUp() { _asset1 = new() { + Folder = new() { Path = "" }, FileName = "Image 1_duplicate.jpg", FileSize = 29857, PixelHeight = 720, @@ -83,6 +84,7 @@ public void SetUp() }; _asset2 = new() { + Folder = new() { Path = "" }, FileName = "Image 9.png", FileSize = 126277, PixelHeight = 720, @@ -99,6 +101,7 @@ public void SetUp() }; _asset3 = new() { + Folder = new() { Path = "" }, FileName = "Image 9_duplicate.png", FileSize = 126277, PixelHeight = 720, @@ -115,6 +118,7 @@ public void SetUp() }; _asset4 = new() { + Folder = new() { Path = "" }, FileName = "Image_11.heic", FileSize = 1411940, PixelHeight = 4032, @@ -131,6 +135,7 @@ public void SetUp() }; _asset1Temp = new() { + Folder = new() { Path = "" }, FileName = "Image 1_duplicate_copied.jpg", FileSize = 29857, PixelHeight = 720, @@ -147,6 +152,7 @@ public void SetUp() }; _asset2Temp = new() { + Folder = new() { Path = "" }, FileName = "Image 1.jpg", FileSize = 29857, PixelHeight = 720, @@ -163,6 +169,7 @@ public void SetUp() }; _asset3Temp = new() { + Folder = new() { Path = "" }, FileName = "Homer.gif", FileSize = 64123, PixelHeight = 320, @@ -179,6 +186,7 @@ public void SetUp() }; _asset4Temp = new() { + Folder = new() { Path = "" }, FileName = "Homer.jpg", FileSize = 6599, PixelHeight = 180, @@ -195,6 +203,7 @@ public void SetUp() }; _asset5Temp = new() { + Folder = new() { Path = "" }, FileName = "HomerDuplicated.jpg", FileSize = 6599, PixelHeight = 180, @@ -7165,8 +7174,8 @@ List folderAddedEvents, List folderRemovedEvents Folder? folder2Updated = _testableAssetRepository!.GetFolderByPath(tempDirectory); Assert.IsNull(folder2Updated); - Dictionary> folderToAssetsMappingFourthSync = new(); - Dictionary assetNameToByteSizeMappingFourthSync = new(); + Dictionary> folderToAssetsMappingFourthSync = []; + Dictionary assetNameToByteSizeMappingFourthSync = []; Assert.IsTrue(_testableAssetRepository!.BackupExists()); @@ -11243,8 +11252,8 @@ List folderAddedEvents, List folderRemovedEvents List folderRemovedEvents) NotifyPropertyChangedEvents() { - List notifyPropertyChangedEvents = new(); - List applicationViewModelInstances = new(); + List notifyPropertyChangedEvents = []; + List applicationViewModelInstances = []; _applicationViewModel!.PropertyChanged += delegate(object? sender, PropertyChangedEventArgs e) { @@ -11252,14 +11261,14 @@ List folderAddedEvents, List folderRemovedEvents applicationViewModelInstances.Add((ApplicationViewModel)sender!); }; - List folderAddedEvents = new(); + List folderAddedEvents = []; _applicationViewModel.FolderAdded += delegate(object _, FolderAddedEventArgs e) { folderAddedEvents.Add(e.Folder); }; - List folderRemovedEvents = new(); + List folderRemovedEvents = []; _applicationViewModel.FolderRemoved += delegate(object _, FolderRemovedEventArgs e) { diff --git a/PhotoManager/PhotoManager.Tests/Unit/Domain/AssetsComparatorTests.cs b/PhotoManager/PhotoManager.Tests/Unit/Domain/AssetsComparatorTests.cs index 9146534a..a9992820 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/Domain/AssetsComparatorTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/Domain/AssetsComparatorTests.cs @@ -22,6 +22,7 @@ public void SetUp() _asset1 = new() { FolderId = new Guid("010233a2-8ea6-4cb0-86e4-156fef7cd772"), + Folder = new() { Path = "" }, FileName = "Image 1.jpg", FileSize = 363888, ImageRotation = Rotation.Rotate0, @@ -39,6 +40,7 @@ public void SetUp() _asset2 = new() { FolderId = new Guid("010233a2-8ea6-4cb0-86e4-156fef7cd772"), + Folder = new() { Path = "" }, FileName = "Image 9.png", FileSize = 4602393, ImageRotation = Rotation.Rotate90, @@ -55,6 +57,7 @@ public void SetUp() }; _asset3 = new() { + Folder = new() { Path = "" }, FileName = "Homer.gif", FileSize = 64123, PixelHeight = 320, @@ -71,6 +74,7 @@ public void SetUp() }; _asset4 = new() { + Folder = new() { Path = "" }, FileName = "Image_11.heic", FileSize = 1411940, PixelHeight = 4032, @@ -93,10 +97,10 @@ public void GetNewFileNames_AllNewFiles_ReturnsArrayOfNewFileNames() string[] fileNames = ["file1.jpg", "file2.png", "file3.gif", "file4.heic", "file5.mp4", "toto.txt", "tutu.bat"]; List cataloguedAssets = [ - new Asset { FileName = "file6.jpg" }, - new Asset { FileName = "file7.png" }, - new Asset { FileName = "file8.gif" }, - new Asset { FileName = "file9.heic" } + new() { Folder = new() { Path = "" }, FileName = "file6.jpg", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file7.png", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file8.gif", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file9.heic", Hash = string.Empty } ]; string[] newFileNames = _assetsComparator!.GetNewFileNames(fileNames, cataloguedAssets); @@ -111,12 +115,12 @@ public void GetNewFileNames_SomeNewFiles_ReturnsArrayOfNewFileNames() string[] fileNames = ["file1.jpg", "file2.png", "file3.gif", "file4.heic", "file5.mp4", "toto.txt", "tutu.bat"]; List cataloguedAssets = [ - new Asset { FileName = "file1.jpg" }, - new Asset { FileName = "file4.heic" }, - new Asset { FileName = "file6.jpg" }, - new Asset { FileName = "file7.png" }, - new Asset { FileName = "file8.gif" }, - new Asset { FileName = "file9.heic" } + new() { Folder = new() { Path = "" }, FileName = "file1.jpg", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file4.heic", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file6.jpg", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file7.png", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file8.gif", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file9.heic", Hash = string.Empty } ]; string[] newFileNames = _assetsComparator!.GetNewFileNames(fileNames, cataloguedAssets); @@ -131,11 +135,11 @@ public void GetNewFileNames_NoNewFiles_ReturnsEmptyArray() string[] fileNames = ["file1.jpg", "file2.png", "file3.gif", "file4.heic", "file5.mp4", "toto.txt", "tutu.bat"]; List cataloguedAssets = [ - new Asset { FileName = "file1.jpg" }, - new Asset { FileName = "file2.png" }, - new Asset { FileName = "file3.gif" }, - new Asset { FileName = "file4.heic" }, - new Asset { FileName = "file5.mp4" } + new() { Folder = new() { Path = "" }, FileName = "file1.jpg", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file2.png", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file3.gif", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file4.heic", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file5.mp4", Hash = string.Empty } ]; string[] newFileNames = _assetsComparator!.GetNewFileNames(fileNames, cataloguedAssets); @@ -149,11 +153,11 @@ public void GetNewFileNames_FileNamesIsEmpty_ReturnsEmptyArray() string[] fileNames = []; List cataloguedAssets = [ - new Asset { FileName = "file1.jpg" }, - new Asset { FileName = "file2.png" }, - new Asset { FileName = "file3.gif" }, - new Asset { FileName = "file4.heic" }, - new Asset { FileName = "file5.mp4" } + new() { Folder = new() { Path = "" }, FileName = "file1.jpg", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file2.png", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file3.gif", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file4.heic", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file5.mp4", Hash = string.Empty } ]; string[] newFileNames = _assetsComparator!.GetNewFileNames(fileNames, cataloguedAssets); @@ -167,11 +171,11 @@ public void GetNewFileNames_FileNamesIsNull_ThrowsArgumentNullException() string[]? fileNames = null; List cataloguedAssets = [ - new Asset { FileName = "file1.jpg" }, - new Asset { FileName = "file2.png" }, - new Asset { FileName = "file3.gif" }, - new Asset { FileName = "file4.heic" }, - new Asset { FileName = "file5.mp4" } + new() { Folder = new() { Path = "" }, FileName = "file1.jpg", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file2.png", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file3.gif", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file4.heic", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file5.mp4", Hash = string.Empty } ]; ArgumentNullException? exception = Assert.Throws(() => _assetsComparator!.GetNewFileNames(fileNames!, cataloguedAssets)); @@ -389,10 +393,10 @@ public void GetDeletedFileNames_AllDeletedFiles_ReturnsArrayOfDeletedFileNames() string[] fileNames = ["file1.jpg", "file2.png", "file3.gif", "file4.heic", "file5.mp4", "toto.txt", "tutu.bat"]; List cataloguedAssets = [ - new Asset { FileName = "file6.jpg" }, - new Asset { FileName = "file7.png" }, - new Asset { FileName = "file8.gif" }, - new Asset { FileName = "file9.heic" } + new() { Folder = new() { Path = "" }, FileName = "file6.jpg", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file7.png", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file8.gif", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file9.heic", Hash = string.Empty } ]; string[] deletedFileNames = _assetsComparator!.GetDeletedFileNames(fileNames, cataloguedAssets); @@ -407,11 +411,11 @@ public void GetDeletedFileNames_SomeDeletedFiles_ReturnsArrayOfDeletedFileNames( string[] fileNames = ["file1.jpg", "file2.png", "file3.gif", "file4.heic", "file5.mp4", "toto.txt", "tutu.bat"]; List cataloguedAssets = [ - new Asset { FileName = "file1.jpg" }, - new Asset { FileName = "file6.jpg" }, - new Asset { FileName = "file7.png" }, - new Asset { FileName = "file8.gif" }, - new Asset { FileName = "file9.heic" } + new() { Folder = new() { Path = "" }, FileName = "file1.jpg", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file6.jpg", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file7.png", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file8.gif", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file9.heic", Hash = string.Empty } ]; string[] deletedFileNames = _assetsComparator!.GetDeletedFileNames(fileNames, cataloguedAssets); @@ -426,11 +430,11 @@ public void GetDeletedFileNames_NoDeletedFiles_ReturnsEmptyArray() string[] fileNames = ["file1.jpg", "file2.png", "file3.gif", "file4.heic", "file5.mp4", "toto.txt", "tutu.bat"]; List cataloguedAssets = [ - new Asset { FileName = "file1.jpg" }, - new Asset { FileName = "file2.png" }, - new Asset { FileName = "file3.gif" }, - new Asset { FileName = "file4.heic" }, - new Asset { FileName = "file5.mp4" } + new() { Folder = new() { Path = "" }, FileName = "file1.jpg", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file2.png", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file3.gif", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file4.heic", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file5.mp4", Hash = string.Empty } ]; string[] deletedFileNames = _assetsComparator!.GetDeletedFileNames(fileNames, cataloguedAssets); @@ -444,11 +448,11 @@ public void GetDeletedFileNames_FileNamesIsEmpty_ReturnsArrayOfDeletedFileNames( string[] fileNames = []; List cataloguedAssets = [ - new Asset { FileName = "file1.jpg" }, - new Asset { FileName = "file2.png" }, - new Asset { FileName = "file3.gif" }, - new Asset { FileName = "file4.heic" }, - new Asset { FileName = "file5.mp4" } + new() { Folder = new() { Path = "" }, FileName = "file1.jpg", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file2.png", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file3.gif", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file4.heic", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file5.mp4", Hash = string.Empty } ]; string[] deletedFileNames = _assetsComparator!.GetDeletedFileNames(fileNames, cataloguedAssets); @@ -463,11 +467,11 @@ public void GetDeletedFileNames_FileNamesIsNull_ThrowsArgumentNullException() string[]? fileNames = null; List cataloguedAssets = [ - new Asset { FileName = "file1.jpg" }, - new Asset { FileName = "file2.png" }, - new Asset { FileName = "file3.gif" }, - new Asset { FileName = "file4.heic" }, - new Asset { FileName = "file5.mp4" } + new() { Folder = new() { Path = "" }, FileName = "file1.jpg", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file2.png", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file3.gif", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file4.heic", Hash = string.Empty }, + new() { Folder = new() { Path = "" }, FileName = "file5.mp4", Hash = string.Empty } ]; ArgumentNullException? exception = Assert.Throws(() => _assetsComparator!.GetDeletedFileNames(fileNames!, cataloguedAssets)); diff --git a/PhotoManager/PhotoManager.Tests/Unit/Domain/FolderTests.cs b/PhotoManager/PhotoManager.Tests/Unit/Domain/FolderTests.cs index f04e1355..541b0997 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/Domain/FolderTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/Domain/FolderTests.cs @@ -3,12 +3,12 @@ [TestFixture] public class FolderTests { - private string? dataDirectory; + private string? _dataDirectory; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); } [Test] @@ -20,8 +20,8 @@ public void OneTimeSetUp() [TestCase("TestFolder\\TestSubFolder1", "TestFolder\\TestSubFolder2", false)] public void IsParentOf_PathIsValid_ReturnsExpected(string parentFolderSubPath1, string childFolderSubPath2, bool expected) { - Folder parentFolder1 = new() { Path = Path.Combine(dataDirectory!, parentFolderSubPath1) }; - Folder childFolder2 = new() { Path = Path.Combine(dataDirectory!, childFolderSubPath2) }; + Folder parentFolder1 = new() { Path = Path.Combine(_dataDirectory!, parentFolderSubPath1) }; + Folder childFolder2 = new() { Path = Path.Combine(_dataDirectory!, childFolderSubPath2) }; bool isFolderParentOfChild = parentFolder1.IsParentOf(childFolder2); @@ -47,7 +47,7 @@ public void IsParentOf_PathIsInvalid_ReturnsExpected(string parentFolderSubPath1 public void IsParentOf_PathIsNull_ReturnsFalse() { Folder folder = new() { Path = null! }; - Folder childFolder = new() { Path = Path.Combine(dataDirectory!, "TestFolder") }; + Folder childFolder = new() { Path = Path.Combine(_dataDirectory!, "TestFolder") }; bool isFolderParentOfChild = folder.IsParentOf(childFolder); @@ -57,7 +57,7 @@ public void IsParentOf_PathIsNull_ReturnsFalse() [Test] public void IsParentOf_ChildPathIsNull_ReturnsFalse() { - Folder folder = new() { Path = dataDirectory! }; + Folder folder = new() { Path = _dataDirectory! }; Folder childFolder = new() { Path = null! }; bool isFolderParentOfChild = folder.IsParentOf(childFolder); diff --git a/PhotoManager/PhotoManager.Tests/Unit/Domain/SyncAssetsConfigurationTests.cs b/PhotoManager/PhotoManager.Tests/Unit/Domain/SyncAssetsConfigurationTests.cs index 834f8ad5..ed785e44 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/Domain/SyncAssetsConfigurationTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/Domain/SyncAssetsConfigurationTests.cs @@ -152,7 +152,7 @@ public void Validate_DefinitionsAreValidAndInvalid_RemovesInvalidDefinitions() public void Validate_DefinitionsAreInvalid_RemovesAllDefinitions() { _syncAssetsConfiguration!.Definitions.Add(new() { SourceDirectory = "Invalid1\\Path", DestinationDirectory = "Invalid2\\Path" }); - _syncAssetsConfiguration.Definitions.Add(new() { SourceDirectory = "http://www.some-site.com", DestinationDirectory = "ftp://some-location.com" }); + _syncAssetsConfiguration.Definitions.Add(new() { SourceDirectory = "https://www.some-site.com", DestinationDirectory = "ftp://some-location.com" }); _syncAssetsConfiguration.Definitions.Add(new() { SourceDirectory = "Invalid@Value.com", DestinationDirectory = "Invalid@Value.com" }); _syncAssetsConfiguration.Definitions.Add(new() { SourceDirectory = "", DestinationDirectory = "" }); _syncAssetsConfiguration.Definitions.Add(new() { SourceDirectory = "", DestinationDirectory = null! }); diff --git a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseBackupExistsTests.cs b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseBackupExistsTests.cs index 06d1a9f9..afb0198c 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseBackupExistsTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseBackupExistsTests.cs @@ -3,7 +3,7 @@ [TestFixture] public class DatabaseBackupExistsTests { - private string? dataDirectory; + private string? _dataDirectory; private PhotoManager.Infrastructure.Database.Database? _database; private UserConfigurationService? _userConfigurationService; @@ -11,7 +11,7 @@ public class DatabaseBackupExistsTests [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); Mock configurationRootMock = new(); configurationRootMock.GetDefaultMockConfig(); @@ -30,7 +30,7 @@ public void BackupExists_BackupExists_ReturnsTrue() { DateTime backupDate = DateTime.Now; - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); try { @@ -49,7 +49,7 @@ public void BackupExists_BackupExists_ReturnsTrue() finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } @@ -58,7 +58,7 @@ public void BackupExists_BackupDoesNotExist_ReturnsFalse() { DateTime backupDate = DateTime.Now; - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); try { @@ -75,7 +75,7 @@ public void BackupExists_BackupDoesNotExist_ReturnsFalse() finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } } diff --git a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseDeleteOldBackupsTests.cs b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseDeleteOldBackupsTests.cs index e24a4d8d..fe469fc5 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseDeleteOldBackupsTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseDeleteOldBackupsTests.cs @@ -3,7 +3,7 @@ [TestFixture] public class DatabaseDeleteOldBackupsTests { - private string? dataDirectory; + private string? _dataDirectory; private UserConfigurationService? _userConfigurationService; private Mock? _backupStorageMock; @@ -11,7 +11,7 @@ public class DatabaseDeleteOldBackupsTests [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); Mock configurationRootMock = new(); configurationRootMock.GetDefaultMockConfig(); @@ -28,23 +28,23 @@ public void SetUp() [Test] public void DeleteOldBackups_ExcessBackups_SuccessfullyDeletesBackups() { - ushort backupsToKeep = 3; - string path1 = Path.Combine(dataDirectory!, "DatabaseTests_Backups", "20230404.zip"); - string path2 = Path.Combine(dataDirectory!, "DatabaseTests_Backups", "20230304.zip"); - string path3 = Path.Combine(dataDirectory!, "DatabaseTests_Backups", "20230204.zip"); - string path4 = Path.Combine(dataDirectory!, "DatabaseTests_Backups", "20230104.zip"); - string path5 = Path.Combine(dataDirectory!, "DatabaseTests_Backups", "20230504.zip"); - - string[] filesPath = new string[] - { + const ushort backupsToKeep = 3; + string path1 = Path.Combine(_dataDirectory!, "DatabaseTests_Backups", "20230404.zip"); + string path2 = Path.Combine(_dataDirectory!, "DatabaseTests_Backups", "20230304.zip"); + string path3 = Path.Combine(_dataDirectory!, "DatabaseTests_Backups", "20230204.zip"); + string path4 = Path.Combine(_dataDirectory!, "DatabaseTests_Backups", "20230104.zip"); + string path5 = Path.Combine(_dataDirectory!, "DatabaseTests_Backups", "20230504.zip"); + + string[] filesPath = + [ path1, path2, path3, path4, path5 - }; + ]; - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); try { @@ -73,22 +73,22 @@ public void DeleteOldBackups_ExcessBackups_SuccessfullyDeletesBackups() finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } [Test] public void DeleteOldBackups_NoExcessBackups_NothingDeleted() { - ushort backupsToKeep = 3; - string[] filesPath = new string[] - { - Path.Combine(dataDirectory!, "DatabaseTests_Backups", "20230404.zip"), - Path.Combine(dataDirectory!, "DatabaseTests_Backups", "20230304.zip"), - Path.Combine(dataDirectory!, "DatabaseTests_Backups", "20230204.zip") - }; + const ushort backupsToKeep = 3; + string[] filesPath = + [ + Path.Combine(_dataDirectory!, "DatabaseTests_Backups", "20230404.zip"), + Path.Combine(_dataDirectory!, "DatabaseTests_Backups", "20230304.zip"), + Path.Combine(_dataDirectory!, "DatabaseTests_Backups", "20230204.zip") + ]; - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); try { @@ -110,7 +110,7 @@ public void DeleteOldBackups_NoExcessBackups_NothingDeleted() finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } } diff --git a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseDeleteThumbnailsTests.cs b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseDeleteThumbnailsTests.cs index 5a01883e..72700818 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseDeleteThumbnailsTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseDeleteThumbnailsTests.cs @@ -3,7 +3,7 @@ [TestFixture] public class DatabaseDeleteThumbnailsTests { - private string? dataDirectory; + private string? _dataDirectory; private PhotoManager.Infrastructure.Database.Database? _database; private UserConfigurationService? _userConfigurationService; @@ -11,7 +11,7 @@ public class DatabaseDeleteThumbnailsTests [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); Mock configurationRootMock = new(); configurationRootMock.GetDefaultMockConfig(); @@ -29,7 +29,7 @@ public void SetUp() public void DeleteThumbnails_BlobExists_DeleteFile() { string blobName = Guid.NewGuid() + ".bin"; // The blobName is always like this FolderId + ".bin" - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string blobFilePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, blobName); Dictionary blobToWrite = new() { @@ -56,7 +56,7 @@ public void DeleteThumbnails_BlobExists_DeleteFile() finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } @@ -64,7 +64,7 @@ public void DeleteThumbnails_BlobExists_DeleteFile() public void DeleteThumbnails_BlobDoesNotExist_DoesNotDeleteFile() { string blobName = Guid.NewGuid() + ".bin"; // The blobName is always like this FolderId + ".bin" - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string blobFilePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, blobName); try @@ -84,7 +84,7 @@ public void DeleteThumbnails_BlobDoesNotExist_DoesNotDeleteFile() finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } } diff --git a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseFolderHasThumbnailsTests.cs b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseFolderHasThumbnailsTests.cs index 6ec39e53..5cee2c50 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseFolderHasThumbnailsTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseFolderHasThumbnailsTests.cs @@ -3,7 +3,7 @@ [TestFixture] public class DatabaseFolderHasThumbnailsTests { - private string? dataDirectory; + private string? _dataDirectory; private PhotoManager.Infrastructure.Database.Database? _database; private UserConfigurationService? _userConfigurationService; @@ -11,7 +11,7 @@ public class DatabaseFolderHasThumbnailsTests [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); Mock configurationRootMock = new(); configurationRootMock.GetDefaultMockConfig(); @@ -29,7 +29,7 @@ public void SetUp() public void FolderHasThumbnails_BlobExists_ReturnsTrue() { string blobName = Guid.NewGuid() + ".bin"; // The blobName is always like this FolderId + ".bin" - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); Dictionary blobToWrite = new() { { "Image1.jpg", new byte[] { 1, 2, 3 } }, @@ -53,7 +53,7 @@ public void FolderHasThumbnails_BlobExists_ReturnsTrue() finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } @@ -61,7 +61,7 @@ public void FolderHasThumbnails_BlobExists_ReturnsTrue() public void FolderHasThumbnails_BlobDoesNotExist_ReturnsFalse() { string blobName = Guid.NewGuid() + ".bin"; // The blobName is always like this FolderId + ".bin" - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); try { @@ -78,7 +78,7 @@ public void FolderHasThumbnails_BlobDoesNotExist_ReturnsFalse() finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } } diff --git a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseInitializeTests.cs b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseInitializeTests.cs index b86c1849..8af3531d 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseInitializeTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseInitializeTests.cs @@ -3,7 +3,7 @@ [TestFixture] public class DatabaseInitializeTests { - private string? dataDirectory; + private string? _dataDirectory; private TestableDatabase? _testableDatabase; private UserConfigurationService? _userConfigurationService; @@ -11,7 +11,7 @@ public class DatabaseInitializeTests [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); Mock configurationRootMock = new(); configurationRootMock.GetDefaultMockConfig(); @@ -28,7 +28,7 @@ public void SetUp() [Test] public void Initialize_ValidPath_InitializeData() { - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); try { @@ -58,7 +58,7 @@ public void Initialize_ValidPath_InitializeData() finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } diff --git a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseReadBlobTests.cs b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseReadBlobTests.cs index def8ee4b..6fea6648 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseReadBlobTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseReadBlobTests.cs @@ -3,17 +3,17 @@ [TestFixture] public class DatabaseReadBlobTests { - private string? dataDirectory; + private string? _dataDirectory; private PhotoManager.Infrastructure.Database.Database? _database; private UserConfigurationService? _userConfigurationService; - private readonly char semicolonSeparator = ';'; + private const char SEMICOLON_SEPARATOR = ';'; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); Mock configurationRootMock = new(); configurationRootMock.GetDefaultMockConfig(); @@ -31,19 +31,19 @@ public void SetUp() public void ReadBlob_FileExistsAndSemicolonSeparator_ReturnsBlob() { string blobName = Guid.NewGuid() + ".bin"; // The blobName is always like this FolderId + ".bin" - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string blobFilePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, blobName); Dictionary blobToWrite = new() { - { "Image1.jpg", new byte[] { 1, 2, 3 } }, - { "Image2.png", new byte[] { 4, 5, 6 } } + { "Image1.jpg", [1, 2, 3]}, + { "Image2.png", [4, 5, 6]} }; try { _database!.Initialize( directoryPath, - semicolonSeparator, + SEMICOLON_SEPARATOR, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs); @@ -65,7 +65,7 @@ public void ReadBlob_FileExistsAndSemicolonSeparator_ReturnsBlob() finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } @@ -73,12 +73,12 @@ public void ReadBlob_FileExistsAndSemicolonSeparator_ReturnsBlob() public void ReadBlob_FileExistsAndPipeSeparator_ReturnsBlob() { string blobName = Guid.NewGuid() + ".bin"; // The blobName is always like this FolderId + ".bin" - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string blobFilePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, blobName); Dictionary blobToWrite = new() { - { "Image1.jpg", new byte[] { 1, 2, 3 } }, - { "Image2.png", new byte[] { 4, 5, 6 } } + { "Image1.jpg", [1, 2, 3]}, + { "Image2.png", [4, 5, 6]} }; try @@ -107,7 +107,7 @@ public void ReadBlob_FileExistsAndPipeSeparator_ReturnsBlob() finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } @@ -115,7 +115,7 @@ public void ReadBlob_FileExistsAndPipeSeparator_ReturnsBlob() public void ReadBlob_FileDoesNotExistsAndPipeSeparator_ReturnsNull() { string blobName = Guid.NewGuid() + ".bin"; // The blobName is always like this FolderId + ".bin" - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string blobFilePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, blobName); try @@ -134,7 +134,7 @@ public void ReadBlob_FileDoesNotExistsAndPipeSeparator_ReturnsNull() finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } } diff --git a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseReadObjectListTests.cs b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseReadObjectListTests.cs index 1454e321..0f7493f9 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseReadObjectListTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseReadObjectListTests.cs @@ -3,50 +3,50 @@ [TestFixture] public class DatabaseReadObjectListTests { - private string? dataDirectory; + private string? _dataDirectory; private PhotoManager.Infrastructure.Database.Database? _database; private UserConfigurationService? _userConfigurationService; - private string? csvEscapedTextWithSemicolon; - private string? csvUnescapedTextWithSemicolon; - private string? csvEscapedTextWithPipe; - private string? csvUnescapedTextWithPipe; - private string? csvSomeUnescapedTextWithPipe; - private string? csvInvalid; - private readonly char semicolonSeparator = ';'; + private string? _csvEscapedTextWithSemicolon; + private string? _csvUnescapedTextWithSemicolon; + private string? _csvEscapedTextWithPipe; + private string? _csvUnescapedTextWithPipe; + private string? _csvSomeUnescapedTextWithPipe; + private string? _csvInvalid; + private const char SEMICOLON_SEPARATOR = ';'; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); Mock configurationRootMock = new(); configurationRootMock.GetDefaultMockConfig(); _userConfigurationService = new (configurationRootMock.Object); - csvEscapedTextWithSemicolon = "\"FolderId\";\"FileName\";\"FileSize\";\"ImageRotation\";\"PixelWidth\";\"PixelHeight\";\"ThumbnailPixelWidth\";\"ThumbnailPixelHeight\";\"ThumbnailCreationDateTime\";\"Hash\";\"AssetCorruptedMessage\";\"IsAssetCorrupted\";\"AssetRotatedMessage\";\"IsAssetRotated\"\r\n" + + _csvEscapedTextWithSemicolon = "\"FolderId\";\"FileName\";\"FileSize\";\"ImageRotation\";\"PixelWidth\";\"PixelHeight\";\"ThumbnailPixelWidth\";\"ThumbnailPixelHeight\";\"ThumbnailCreationDateTime\";\"Hash\";\"AssetCorruptedMessage\";\"IsAssetCorrupted\";\"AssetRotatedMessage\";\"IsAssetRotated\"\r\n" + "\"876283c6-780e-4ad5-975c-be63044c087a\";\"20200720175810_3.jpg\";\"363888\";\"Rotate0\";\"1920\";\"1080\";\"200\";\"112\";\"8/19/2023 11:26:09\";\"4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4\";\"\";\"false\";\"\";\"false\"\r\n" + "\"876283c6-780e-4ad5-975c-be63044c087a\";\"20200720175816_3.jpg\";\"343633\";\"Rotate0\";\"1920\";\"1080\";\"200\";\"112\";\"8/19/2023 11:26:09\";\"0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124\";\"The asset is corrupted\";\"true\";\"The asset has been rotated\";\"true\"\r\n"; - csvUnescapedTextWithSemicolon = "FolderId;FileName;FileSize;ImageRotation;PixelWidth;PixelHeight;ThumbnailPixelWidth;ThumbnailPixelHeight;ThumbnailCreationDateTime;Hash;AssetCorruptedMessage;IsAssetCorrupted;AssetRotatedMessage;IsAssetRotated\r\n" + + _csvUnescapedTextWithSemicolon = "FolderId;FileName;FileSize;ImageRotation;PixelWidth;PixelHeight;ThumbnailPixelWidth;ThumbnailPixelHeight;ThumbnailCreationDateTime;Hash;AssetCorruptedMessage;IsAssetCorrupted;AssetRotatedMessage;IsAssetRotated\r\n" + "876283c6-780e-4ad5-975c-be63044c087a;20200720175810_3.jpg;363888;Rotate0;1920;1080;200;112;8/19/2023 11:26:09;4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4;;false;;false\r\n" + "876283c6-780e-4ad5-975c-be63044c087a;20200720175816_3.jpg;343633;Rotate0;1920;1080;200;112;8/19/2023 11:26:09;0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124;The asset is corrupted;true;The asset has been rotated;true\r\n"; - csvEscapedTextWithPipe = "\"FolderId\"|\"FileName\"|\"FileSize\"|\"ImageRotation\"|\"PixelWidth\"|\"PixelHeight\"|\"ThumbnailPixelWidth\"|\"ThumbnailPixelHeight\"|\"ThumbnailCreationDateTime\"|\"Hash\"|\"AssetCorruptedMessage\"|\"IsAssetCorrupted\"|\"AssetRotatedMessage\"|\"IsAssetRotated\"\r\n" + + _csvEscapedTextWithPipe = "\"FolderId\"|\"FileName\"|\"FileSize\"|\"ImageRotation\"|\"PixelWidth\"|\"PixelHeight\"|\"ThumbnailPixelWidth\"|\"ThumbnailPixelHeight\"|\"ThumbnailCreationDateTime\"|\"Hash\"|\"AssetCorruptedMessage\"|\"IsAssetCorrupted\"|\"AssetRotatedMessage\"|\"IsAssetRotated\"\r\n" + "\"876283c6-780e-4ad5-975c-be63044c087a\"|\"20200720175810_3.jpg\"|\"363888\"|\"Rotate0\"|\"1920\"|\"1080\"|\"200\"|\"112\"|\"8/19/2023 11:26:09\"|\"4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4\"|\"\"|\"false\"|\"\"|\"false\"\r\n" + "\"876283c6-780e-4ad5-975c-be63044c087a\"|\"20200720175816_3.jpg\"|\"343633\"|\"Rotate0\"|\"1920\"|\"1080\"|\"200\"|\"112\"|\"8/19/2023 11:26:09\"|\"0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124\"|\"The asset is corrupted\"|\"true\"|\"The asset has been rotated\"|\"true\"\r\n"; - csvUnescapedTextWithPipe = "FolderId|FileName|FileSize|ImageRotation|PixelWidth|PixelHeight|ThumbnailPixelWidth|ThumbnailPixelHeight|ThumbnailCreationDateTime|Hash|AssetCorruptedMessage|IsAssetCorrupted|AssetRotatedMessage|IsAssetRotated\r\n" + + _csvUnescapedTextWithPipe = "FolderId|FileName|FileSize|ImageRotation|PixelWidth|PixelHeight|ThumbnailPixelWidth|ThumbnailPixelHeight|ThumbnailCreationDateTime|Hash|AssetCorruptedMessage|IsAssetCorrupted|AssetRotatedMessage|IsAssetRotated\r\n" + "876283c6-780e-4ad5-975c-be63044c087a|20200720175810_3.jpg|363888|Rotate0|1920|1080|200|112|8/19/2023 11:26:09|4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4||false||false\r\n" + "876283c6-780e-4ad5-975c-be63044c087a|20200720175816_3.jpg|343633|Rotate0|1920|1080|200|112|8/19/2023 11:26:09|0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124|The asset is corrupted|true|The asset has been rotated|true\r\n"; - csvSomeUnescapedTextWithPipe = "\"FolderId\"|FileName|FileSize|ImageRotation|PixelWidth|PixelHeight|ThumbnailPixelWidth|ThumbnailPixelHeight|ThumbnailCreationDateTime|Hash|AssetCorruptedMessage|IsAssetCorrupted|AssetRotatedMessage|\"IsAssetRotated\"\r\n" + + _csvSomeUnescapedTextWithPipe = "\"FolderId\"|FileName|FileSize|ImageRotation|PixelWidth|PixelHeight|ThumbnailPixelWidth|ThumbnailPixelHeight|ThumbnailCreationDateTime|Hash|AssetCorruptedMessage|IsAssetCorrupted|AssetRotatedMessage|\"IsAssetRotated\"\r\n" + "\"876283c6-780e-4ad5-975c-be63044c087a\"|20200720175810_3.jpg|363888|Rotate0|1920|1080|200|112|8/19/2023 11:26:09|4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4||false||\"false\"\r\n" + "\"876283c6-780e-4ad5-975c-be63044c087a\"|20200720175816_3.jpg|343633|Rotate0|1920|1080|200|112|8/19/2023 11:26:09|0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124|The asset is corrupted|true|The asset has been rotated|\"true\"\r\n"; - csvInvalid = "FolderId|FileSize\r\n" + "1920|false|toto\r\n"; + _csvInvalid = "FolderId|FileSize\r\n" + "1920|false|toto\r\n"; } [SetUp] @@ -60,31 +60,22 @@ public void SetUp() [TestCase("UnescapedText", false)] public void ReadObjectList_AllColumnsAndSemicolonSeparator_ReturnsAssets(string csvType, bool escapeText) { - string csv; - - if (csvType == "EscapedText") - { - csv = csvEscapedTextWithSemicolon!; - } - else - { - csv = csvUnescapedTextWithSemicolon!; - } + string csv = csvType == "EscapedText" ? _csvEscapedTextWithSemicolon! : _csvUnescapedTextWithSemicolon!; string tableName = "assets" + Guid.NewGuid(); - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string filePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, tableName + ".db"); try { - List assets = ReadObjectList(directoryPath, semicolonSeparator, filePath, csv, tableName, escapeText); + List assets = ReadObjectList(directoryPath, SEMICOLON_SEPARATOR, filePath, csv, tableName, escapeText); - Asserts(assets, filePath, csv!); + Asserts(assets, filePath, csv); } finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } @@ -93,41 +84,32 @@ public void ReadObjectList_AllColumnsAndSemicolonSeparator_ReturnsAssets(string [TestCase("UnescapedText", false)] public void ReadObjectList_AllColumnsAndPipeSeparator_ReturnsAssets(string csvType, bool escapeText) { - string csv; - - if (csvType == "EscapedText") - { - csv = csvEscapedTextWithPipe!; - } - else - { - csv = csvUnescapedTextWithPipe!; - } + string csv = csvType == "EscapedText" ? _csvEscapedTextWithPipe! : _csvUnescapedTextWithPipe!; string tableName = "assets" + Guid.NewGuid(); - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string filePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, tableName + ".db"); try { List assets = ReadObjectList(directoryPath, _userConfigurationService!.StorageSettings.Separator, filePath, csv, tableName, escapeText); - Asserts(assets, filePath, csv!); + Asserts(assets, filePath, csv); } finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } [Test] public void ReadObjectList_AllColumnsAndPipeSeparatorEscapedTextWithoutDataTableProperties_ThrowsArgumentException() { - string csv = csvEscapedTextWithPipe!; + string csv = _csvEscapedTextWithPipe!; string tableName = "assets" + Guid.NewGuid(); - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string filePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, tableName + ".db"); string exceptionMessage = $"Error while trying to read data table {tableName}.\n" + $"DataDirectory: {directoryPath}\n" + @@ -151,17 +133,17 @@ public void ReadObjectList_AllColumnsAndPipeSeparatorEscapedTextWithoutDataTable finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } [Test] public void ReadObjectList_AllColumnsAndPipeSeparatorUnescapedTextWithoutDataTableProperties_ReturnsAssets() { - string csv = csvUnescapedTextWithPipe!; + string csv = _csvUnescapedTextWithPipe!; string tableName = "assets" + Guid.NewGuid(); - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string filePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, tableName + ".db"); try @@ -176,22 +158,22 @@ public void ReadObjectList_AllColumnsAndPipeSeparatorUnescapedTextWithoutDataTab List assets = _database!.ReadObjectList(tableName, AssetConfigs.ReadFunc); - Asserts(assets, filePath, csv!); + Asserts(assets, filePath, csv); } finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } [Test] public void ReadObjectList_SomeColumnsWithEscapedTextAndPipeSeparator_ReturnsAssets() { - string csv = csvSomeUnescapedTextWithPipe!; + string csv = _csvSomeUnescapedTextWithPipe!; string tableName = "assets" + Guid.NewGuid(); - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string filePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, tableName + ".db"); try @@ -207,43 +189,43 @@ public void ReadObjectList_SomeColumnsWithEscapedTextAndPipeSeparator_ReturnsAss _database!.SetDataTableProperties(new DataTableProperties { TableName = tableName, - ColumnProperties = new ColumnProperties[] - { - new ColumnProperties { ColumnName = "FolderId", EscapeText = true }, - new ColumnProperties { ColumnName = "FileName", EscapeText = false }, - new ColumnProperties { ColumnName = "FileSize", EscapeText = false }, - new ColumnProperties { ColumnName = "ImageRotation", EscapeText = false }, - new ColumnProperties { ColumnName = "PixelWidth", EscapeText = false }, - new ColumnProperties { ColumnName = "PixelHeight", EscapeText = false }, - new ColumnProperties { ColumnName = "ThumbnailPixelWidth", EscapeText = false }, - new ColumnProperties { ColumnName = "ThumbnailPixelHeight", EscapeText = false }, - new ColumnProperties { ColumnName = "ThumbnailCreationDateTime", EscapeText = false }, - new ColumnProperties { ColumnName = "Hash", EscapeText = false }, - new ColumnProperties { ColumnName = "AssetCorruptedMessage", EscapeText = false }, - new ColumnProperties { ColumnName = "IsAssetCorrupted", EscapeText = false }, - new ColumnProperties { ColumnName = "AssetRotatedMessage", EscapeText = false }, - new ColumnProperties { ColumnName = "IsAssetRotated", EscapeText = true } - } + ColumnProperties = + [ + new() { ColumnName = "FolderId", EscapeText = true }, + new() { ColumnName = "FileName", EscapeText = false }, + new() { ColumnName = "FileSize", EscapeText = false }, + new() { ColumnName = "ImageRotation", EscapeText = false }, + new() { ColumnName = "PixelWidth", EscapeText = false }, + new() { ColumnName = "PixelHeight", EscapeText = false }, + new() { ColumnName = "ThumbnailPixelWidth", EscapeText = false }, + new() { ColumnName = "ThumbnailPixelHeight", EscapeText = false }, + new() { ColumnName = "ThumbnailCreationDateTime", EscapeText = false }, + new() { ColumnName = "Hash", EscapeText = false }, + new() { ColumnName = "AssetCorruptedMessage", EscapeText = false }, + new() { ColumnName = "IsAssetCorrupted", EscapeText = false }, + new() { ColumnName = "AssetRotatedMessage", EscapeText = false }, + new() { ColumnName = "IsAssetRotated", EscapeText = true } + ] }); List assets = _database!.ReadObjectList(tableName, AssetConfigs.ReadFunc); - Asserts(assets, filePath, csv!); + Asserts(assets, filePath, csv); } finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } [Test] public void ReadObjectList_SomeColumnsInvalidsAndPipeSeparator_ReturnsAssets() { - string csv = csvUnescapedTextWithPipe!; + string csv = _csvUnescapedTextWithPipe!; string tableName = "assets" + Guid.NewGuid(); - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string filePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, tableName + ".db"); try @@ -259,33 +241,33 @@ public void ReadObjectList_SomeColumnsInvalidsAndPipeSeparator_ReturnsAssets() _database!.SetDataTableProperties(new DataTableProperties { TableName = tableName, - ColumnProperties = new ColumnProperties[] - { - new ColumnProperties { ColumnName = "FolderId", EscapeText = false }, - new ColumnProperties { ColumnName = "Toto", EscapeText = false }, - new ColumnProperties { ColumnName = "FileSize", EscapeText = false }, - new ColumnProperties { ColumnName = "ImageRotation", EscapeText = false }, - new ColumnProperties { ColumnName = "PixelWidth", EscapeText = false }, - new ColumnProperties { ColumnName = "PixelHeight", EscapeText = false }, - new ColumnProperties { ColumnName = "ThumbnailPixelWidth", EscapeText = false }, - new ColumnProperties { ColumnName = "ThumbnailPixelHeight", EscapeText = false }, - new ColumnProperties { ColumnName = "ThumbnailCreationDateTime", EscapeText = false }, - new ColumnProperties { ColumnName = "Tutu", EscapeText = false }, - new ColumnProperties { ColumnName = "AssetCorruptedMessage", EscapeText = false }, - new ColumnProperties { ColumnName = "IsAssetCorrupted", EscapeText = false }, - new ColumnProperties { ColumnName = "AssetRotatedMessage", EscapeText = false }, - new ColumnProperties { ColumnName = "Tata", EscapeText = false } - } + ColumnProperties = + [ + new() { ColumnName = "FolderId", EscapeText = false }, + new() { ColumnName = "Toto", EscapeText = false }, + new() { ColumnName = "FileSize", EscapeText = false }, + new() { ColumnName = "ImageRotation", EscapeText = false }, + new() { ColumnName = "PixelWidth", EscapeText = false }, + new() { ColumnName = "PixelHeight", EscapeText = false }, + new() { ColumnName = "ThumbnailPixelWidth", EscapeText = false }, + new() { ColumnName = "ThumbnailPixelHeight", EscapeText = false }, + new() { ColumnName = "ThumbnailCreationDateTime", EscapeText = false }, + new() { ColumnName = "Tutu", EscapeText = false }, + new() { ColumnName = "AssetCorruptedMessage", EscapeText = false }, + new() { ColumnName = "IsAssetCorrupted", EscapeText = false }, + new() { ColumnName = "AssetRotatedMessage", EscapeText = false }, + new() { ColumnName = "Tata", EscapeText = false } + ] }); List assets = _database!.ReadObjectList(tableName, AssetConfigs.ReadFunc); - Asserts(assets, filePath, csv!); + Asserts(assets, filePath, csv); } finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } @@ -297,7 +279,7 @@ public void ReadObjectList_CsvIsNullAndPipeSeparator_ReturnsEmptyList(bool escap string? csv = null; string tableName = "assets" + Guid.NewGuid(); - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string filePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, tableName + ".db"); try @@ -309,7 +291,7 @@ public void ReadObjectList_CsvIsNullAndPipeSeparator_ReturnsEmptyList(bool escap finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } @@ -321,7 +303,7 @@ public void ReadObjectList_CsvIsEmptyAndPipeSeparator_ReturnsEmptyList(bool esca string csv = string.Empty; string tableName = "assets" + Guid.NewGuid(); - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string filePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, tableName + ".db"); try @@ -333,7 +315,7 @@ public void ReadObjectList_CsvIsEmptyAndPipeSeparator_ReturnsEmptyList(bool esca finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } @@ -342,10 +324,10 @@ public void ReadObjectList_CsvIsEmptyAndPipeSeparator_ReturnsEmptyList(bool esca [TestCase(false)] public void ReadObjectList_CsvIsIncorrectPipeSeparator_ThrowsArgumentException(bool escapeText) { - string csv = csvInvalid!; + string csv = _csvInvalid!; string tableName = "assets" + Guid.NewGuid(); - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string filePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, tableName + ".db"); string exceptionMessage = $"Error while trying to read data table {tableName}.\n" + $"DataDirectory: {directoryPath}\n" + @@ -365,16 +347,16 @@ public void ReadObjectList_CsvIsIncorrectPipeSeparator_ThrowsArgumentException(b finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } [Test] public void ReadObjectList_FuncIsNull_ThrowsArgumentException() { - string csv = csvUnescapedTextWithPipe!; + string csv = _csvUnescapedTextWithPipe!; string tableName = "assets" + Guid.NewGuid(); - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string filePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, tableName + ".db"); Func? nullFunc = null; string exceptionMessage = $"Error while trying to read data table {tableName}.\n" + @@ -405,16 +387,16 @@ public void ReadObjectList_FuncIsNull_ThrowsArgumentException() finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } [Test] public void ReadObjectList_ErrorInObjectListStorage_ThrowsArgumentException() { - string csv = csvUnescapedTextWithPipe!; + string csv = _csvUnescapedTextWithPipe!; string tableName = "assets" + Guid.NewGuid(); - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string filePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, tableName + ".db"); string exceptionMessage = $"Error while trying to read data table {tableName}.\n" + $"DataDirectory: {directoryPath}\n" + @@ -426,9 +408,9 @@ public void ReadObjectList_ErrorInObjectListStorage_ThrowsArgumentException() { Mock objectListStorageMock = new(); objectListStorageMock.Setup(x => x.ReadObjectList(It.IsAny(), It.IsAny>(), It.IsAny())).Throws(new Exception()); - PhotoManager.Infrastructure.Database.Database? database = new (objectListStorageMock.Object, new BlobStorage(), new BackupStorage()); + PhotoManager.Infrastructure.Database.Database database = new (objectListStorageMock.Object, new BlobStorage(), new BackupStorage()); - database!.Initialize( + database.Initialize( directoryPath, _userConfigurationService!.StorageSettings.Separator, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, @@ -436,19 +418,19 @@ public void ReadObjectList_ErrorInObjectListStorage_ThrowsArgumentException() File.WriteAllText(filePath, csv); - database!.SetDataTableProperties(new DataTableProperties + database.SetDataTableProperties(new DataTableProperties { TableName = tableName, ColumnProperties = AssetConfigs.ConfigureDataTable() }); - ArgumentException? exception = Assert.Throws(() => database!.ReadObjectList(tableName, AssetConfigs.ReadFunc)); + ArgumentException? exception = Assert.Throws(() => database.ReadObjectList(tableName, AssetConfigs.ReadFunc)); Assert.AreEqual(exceptionMessage, exception?.Message); } finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } @@ -465,23 +447,23 @@ private List ReadObjectList(string directoryPath, char separator, string _database!.SetDataTableProperties(new DataTableProperties { TableName = tableName, - ColumnProperties = new ColumnProperties[] - { - new ColumnProperties { ColumnName = "FolderId", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "FileName", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "FileSize", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "ImageRotation", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "PixelWidth", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "PixelHeight", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "ThumbnailPixelWidth", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "ThumbnailPixelHeight", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "ThumbnailCreationDateTime", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "Hash", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "AssetCorruptedMessage", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "IsAssetCorrupted", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "AssetRotatedMessage", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "IsAssetRotated", EscapeText = escapeText } - } + ColumnProperties = + [ + new() { ColumnName = "FolderId", EscapeText = escapeText }, + new() { ColumnName = "FileName", EscapeText = escapeText }, + new() { ColumnName = "FileSize", EscapeText = escapeText }, + new() { ColumnName = "ImageRotation", EscapeText = escapeText }, + new() { ColumnName = "PixelWidth", EscapeText = escapeText }, + new() { ColumnName = "PixelHeight", EscapeText = escapeText }, + new() { ColumnName = "ThumbnailPixelWidth", EscapeText = escapeText }, + new() { ColumnName = "ThumbnailPixelHeight", EscapeText = escapeText }, + new() { ColumnName = "ThumbnailCreationDateTime", EscapeText = escapeText }, + new() { ColumnName = "Hash", EscapeText = escapeText }, + new() { ColumnName = "AssetCorruptedMessage", EscapeText = escapeText }, + new() { ColumnName = "IsAssetCorrupted", EscapeText = escapeText }, + new() { ColumnName = "AssetRotatedMessage", EscapeText = escapeText }, + new() { ColumnName = "IsAssetRotated", EscapeText = escapeText } + ] }); List assets = _database!.ReadObjectList(tableName, AssetConfigs.ReadFunc); diff --git a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseSetDataTablePropertiesTests.cs b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseSetDataTablePropertiesTests.cs index 6e8e2c61..d65fc0df 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseSetDataTablePropertiesTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseSetDataTablePropertiesTests.cs @@ -3,7 +3,7 @@ [TestFixture] public class DatabaseSetDataTablePropertiesTests { - private string? dataDirectory; + private string? _dataDirectory; private PhotoManager.Infrastructure.Database.Database? _database; private TestableDatabase? _testableDatabase; @@ -12,7 +12,7 @@ public class DatabaseSetDataTablePropertiesTests [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); Mock configurationRootMock = new(); configurationRootMock.GetDefaultMockConfig(); @@ -30,7 +30,7 @@ public void SetUp() [Test] public void SetDataTableProperties_FolderType_SetsDataTableProperties() { - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); DataTableProperties properties = new() { TableName = _userConfigurationService!.StorageSettings.TablesSettings.FoldersTableName, @@ -57,14 +57,14 @@ public void SetDataTableProperties_FolderType_SetsDataTableProperties() finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } [Test] public void SetDataTableProperties_AssetType_SetsDataTableProperties() { - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); DataTableProperties properties = new() { TableName = _userConfigurationService!.StorageSettings.TablesSettings.AssetsTableName, @@ -91,14 +91,14 @@ public void SetDataTableProperties_AssetType_SetsDataTableProperties() finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } [Test] public void SetDataTableProperties_SyncAssetsDirectoriesDefinitionType_SetsDataTableProperties() { - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); DataTableProperties properties = new() { TableName = _userConfigurationService!.StorageSettings.TablesSettings.SyncAssetsDirectoriesDefinitionsTableName, @@ -125,14 +125,14 @@ public void SetDataTableProperties_SyncAssetsDirectoriesDefinitionType_SetsDataT finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } [Test] public void SetDataTableProperties_RecentTargetPathsType_SetsDataTableProperties() { - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); DataTableProperties properties = new() { TableName = _userConfigurationService!.StorageSettings.TablesSettings.RecentTargetPathsTableName, @@ -159,7 +159,7 @@ public void SetDataTableProperties_RecentTargetPathsType_SetsDataTableProperties finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } @@ -191,7 +191,7 @@ public void SetDataTableProperties_WithEmptyColumnProperties_ThrowsArgumentExcep DataTableProperties properties = new() { TableName = "TestTable", - ColumnProperties = Array.Empty() + ColumnProperties = [] }; ArgumentException? exception = Assert.Throws(() => _database!.SetDataTableProperties(properties)); @@ -207,11 +207,11 @@ public void SetDataTableProperties_WithInvalidColumnName_ThrowsArgumentNullExcep DataTableProperties properties = new() { TableName = "TestTable", - ColumnProperties = new ColumnProperties[] - { - new ColumnProperties { ColumnName = "Column1" }, - new ColumnProperties { ColumnName = columnName } - } + ColumnProperties = + [ + new() { ColumnName = "Column1" }, + new() { ColumnName = columnName } + ] }; ArgumentNullException? exception = Assert.Throws(() => _database!.SetDataTableProperties(properties)); @@ -225,11 +225,11 @@ public void SetDataTableProperties_WithDuplicateColumnNames_ThrowsArgumentExcept DataTableProperties properties = new() { TableName = "TestTable", - ColumnProperties = new ColumnProperties[] - { - new ColumnProperties { ColumnName = "Column1" }, - new ColumnProperties { ColumnName = "Column1" } - } + ColumnProperties = + [ + new() { ColumnName = "Column1" }, + new() { ColumnName = "Column1" } + ] }; ArgumentException? exception = Assert.Throws(() => _database!.SetDataTableProperties(properties)); diff --git a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseWriteBackupTests.cs b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseWriteBackupTests.cs index 4d14d965..dba2b2bc 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseWriteBackupTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseWriteBackupTests.cs @@ -3,7 +3,7 @@ [TestFixture] public class DatabaseWriteBackupTests { - private string? dataDirectory; + private string? _dataDirectory; private PhotoManager.Infrastructure.Database.Database? _database; private UserConfigurationService? _userConfigurationService; @@ -11,7 +11,7 @@ public class DatabaseWriteBackupTests [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); Mock configurationRootMock = new(); configurationRootMock.GetDefaultMockConfig(); @@ -31,8 +31,8 @@ public void WriteBackup_BackupDoesNotExist_SuccessfullyWritesBackup() DateTime backupDate = DateTime.Now; string backupName = backupDate.ToString("yyyyMMdd") + ".zip"; - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); - string filePath = Path.Combine(dataDirectory!, "DatabaseTests_Backups", backupName); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); + string filePath = Path.Combine(_dataDirectory!, "DatabaseTests_Backups", backupName); try { @@ -50,7 +50,7 @@ public void WriteBackup_BackupDoesNotExist_SuccessfullyWritesBackup() finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } @@ -60,8 +60,8 @@ public void WriteBackup_BackupExists_OverwritesBackup() DateTime backupDate = DateTime.Now; string backupName = backupDate.ToString("yyyyMMdd") + ".zip"; - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); - string filePath = Path.Combine(dataDirectory!, "DatabaseTests_Backups", backupName); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); + string filePath = Path.Combine(_dataDirectory!, "DatabaseTests_Backups", backupName); try { @@ -81,7 +81,7 @@ public void WriteBackup_BackupExists_OverwritesBackup() finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } } diff --git a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseWriteBlobTests.cs b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseWriteBlobTests.cs index bdf11a67..cc633da3 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseWriteBlobTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseWriteBlobTests.cs @@ -3,17 +3,17 @@ [TestFixture] public class DatabaseWriteBlobTests { - private string? dataDirectory; + private string? _dataDirectory; private PhotoManager.Infrastructure.Database.Database? _database; private UserConfigurationService? _userConfigurationService; - private readonly char semicolonSeparator = ';'; + private const char SEMICOLON_SEPARATOR = ';'; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); Mock configurationRootMock = new(); configurationRootMock.GetDefaultMockConfig(); @@ -31,19 +31,19 @@ public void SetUp() public void WriteBlob_BlobToWriteIsCorrectAndSemicolonSeparator_WritesBlob() { string blobName = Guid.NewGuid() + ".bin"; // The blobName is always like this FolderId + ".bin" - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string blobFilePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, blobName); Dictionary blobToWrite = new() { - { "Image1.jpg", new byte[] { 1, 2, 3 } }, - { "Image2.png", new byte[] { 4, 5, 6 } } + { "Image1.jpg", [1, 2, 3]}, + { "Image2.png", [4, 5, 6]} }; try { _database!.Initialize( directoryPath, - semicolonSeparator, + SEMICOLON_SEPARATOR, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs); @@ -67,7 +67,7 @@ public void WriteBlob_BlobToWriteIsCorrectAndSemicolonSeparator_WritesBlob() finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } @@ -75,12 +75,12 @@ public void WriteBlob_BlobToWriteIsCorrectAndSemicolonSeparator_WritesBlob() public void WriteBlob_BlobToWriteIsCorrectAndPipeSeparator_WritesBlob() { string blobName = Guid.NewGuid() + ".bin"; // The blobName is always like this FolderId + ".bin" - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string blobFilePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, blobName); Dictionary blobToWrite = new() { - { "Image1.jpg", new byte[] { 1, 2, 3 } }, - { "Image2.png", new byte[] { 4, 5, 6 } } + { "Image1.jpg", [1, 2, 3]}, + { "Image2.png", [4, 5, 6]} }; try @@ -111,7 +111,7 @@ public void WriteBlob_BlobToWriteIsCorrectAndPipeSeparator_WritesBlob() finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } @@ -119,7 +119,7 @@ public void WriteBlob_BlobToWriteIsCorrectAndPipeSeparator_WritesBlob() public void WriteBlob_BlobToWriteIsNullAndPipeSeparator_ThrowsNullReferenceException() { string blobName = Guid.NewGuid() + ".bin"; // The blobName is always like this FolderId + ".bin" - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string blobFilePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, blobName); Dictionary? blobToWrite = null; @@ -141,7 +141,7 @@ public void WriteBlob_BlobToWriteIsNullAndPipeSeparator_ThrowsNullReferenceExcep finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } @@ -149,9 +149,9 @@ public void WriteBlob_BlobToWriteIsNullAndPipeSeparator_ThrowsNullReferenceExcep public void WriteBlob_BlobToWriteIsEmptyAndPipeSeparator_WritesNothingInTheFile() { string blobName = Guid.NewGuid() + ".bin"; // The blobName is always like this FolderId + ".bin" - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string blobFilePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, blobName); - Dictionary blobToWrite = new(); + Dictionary blobToWrite = []; try { @@ -175,7 +175,7 @@ public void WriteBlob_BlobToWriteIsEmptyAndPipeSeparator_WritesNothingInTheFile( finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } } diff --git a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseWriteObjectListTests.cs b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseWriteObjectListTests.cs index c89a810f..99cfc722 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseWriteObjectListTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/DatabaseTests/DatabaseWriteObjectListTests.cs @@ -3,45 +3,45 @@ [TestFixture] public class DatabaseWriteObjectListTests { - private string? dataDirectory; + private string? _dataDirectory; private PhotoManager.Infrastructure.Database.Database? _database; private UserConfigurationService? _userConfigurationService; - private string? csvEscapedTextWithSemicolon; - private string? csvUnescapedTextWithSemicolon; - private string? csvEscapedTextWithPipe; - private string? csvUnescapedTextWithPipe; - private string? csvSomeUnescapedTextWithPipe; - private readonly char semicolonSeparator = ';'; + private string? _csvEscapedTextWithSemicolon; + private string? _csvUnescapedTextWithSemicolon; + private string? _csvEscapedTextWithPipe; + private string? _csvUnescapedTextWithPipe; + private string? _csvSomeUnescapedTextWithPipe; + private const char SEMICOLON_SEPARATOR = ';'; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); Mock configurationRootMock = new(); configurationRootMock.GetDefaultMockConfig(); _userConfigurationService = new (configurationRootMock.Object); - csvEscapedTextWithSemicolon = "\"FolderId\";\"FileName\";\"FileSize\";\"ImageRotation\";\"PixelWidth\";\"PixelHeight\";\"ThumbnailPixelWidth\";\"ThumbnailPixelHeight\";\"ThumbnailCreationDateTime\";\"Hash\";\"AssetCorruptedMessage\";\"IsAssetCorrupted\";\"AssetRotatedMessage\";\"IsAssetRotated\"\r\n" + + _csvEscapedTextWithSemicolon = "\"FolderId\";\"FileName\";\"FileSize\";\"ImageRotation\";\"PixelWidth\";\"PixelHeight\";\"ThumbnailPixelWidth\";\"ThumbnailPixelHeight\";\"ThumbnailCreationDateTime\";\"Hash\";\"AssetCorruptedMessage\";\"IsAssetCorrupted\";\"AssetRotatedMessage\";\"IsAssetRotated\"\r\n" + "\"876283c6-780e-4ad5-975c-be63044c087a\";\"20200720175810_3.jpg\";\"363888\";\"Rotate0\";\"1920\";\"1080\";\"200\";\"112\";\"8/19/2023 11:26:09\";\"4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4\";\"\";\"False\";\"\";\"False\"\r\n" + "\"876283c6-780e-4ad5-975c-be63044c087a\";\"20200720175816_3.jpg\";\"343633\";\"Rotate0\";\"1920\";\"1080\";\"200\";\"112\";\"8/19/2023 11:26:09\";\"0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124\";\"The asset is corrupted\";\"True\";\"The asset has been rotated\";\"True\"\r\n"; - csvUnescapedTextWithSemicolon = "FolderId;FileName;FileSize;ImageRotation;PixelWidth;PixelHeight;ThumbnailPixelWidth;ThumbnailPixelHeight;ThumbnailCreationDateTime;Hash;AssetCorruptedMessage;IsAssetCorrupted;AssetRotatedMessage;IsAssetRotated\r\n" + + _csvUnescapedTextWithSemicolon = "FolderId;FileName;FileSize;ImageRotation;PixelWidth;PixelHeight;ThumbnailPixelWidth;ThumbnailPixelHeight;ThumbnailCreationDateTime;Hash;AssetCorruptedMessage;IsAssetCorrupted;AssetRotatedMessage;IsAssetRotated\r\n" + "876283c6-780e-4ad5-975c-be63044c087a;20200720175810_3.jpg;363888;Rotate0;1920;1080;200;112;8/19/2023 11:26:09;4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4;;False;;False\r\n" + "876283c6-780e-4ad5-975c-be63044c087a;20200720175816_3.jpg;343633;Rotate0;1920;1080;200;112;8/19/2023 11:26:09;0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124;The asset is corrupted;True;The asset has been rotated;True\r\n"; - csvEscapedTextWithPipe = "\"FolderId\"|\"FileName\"|\"FileSize\"|\"ImageRotation\"|\"PixelWidth\"|\"PixelHeight\"|\"ThumbnailPixelWidth\"|\"ThumbnailPixelHeight\"|\"ThumbnailCreationDateTime\"|\"Hash\"|\"AssetCorruptedMessage\"|\"IsAssetCorrupted\"|\"AssetRotatedMessage\"|\"IsAssetRotated\"\r\n" + + _csvEscapedTextWithPipe = "\"FolderId\"|\"FileName\"|\"FileSize\"|\"ImageRotation\"|\"PixelWidth\"|\"PixelHeight\"|\"ThumbnailPixelWidth\"|\"ThumbnailPixelHeight\"|\"ThumbnailCreationDateTime\"|\"Hash\"|\"AssetCorruptedMessage\"|\"IsAssetCorrupted\"|\"AssetRotatedMessage\"|\"IsAssetRotated\"\r\n" + "\"876283c6-780e-4ad5-975c-be63044c087a\"|\"20200720175810_3.jpg\"|\"363888\"|\"Rotate0\"|\"1920\"|\"1080\"|\"200\"|\"112\"|\"8/19/2023 11:26:09\"|\"4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4\"|\"\"|\"False\"|\"\"|\"False\"\r\n" + "\"876283c6-780e-4ad5-975c-be63044c087a\"|\"20200720175816_3.jpg\"|\"343633\"|\"Rotate0\"|\"1920\"|\"1080\"|\"200\"|\"112\"|\"8/19/2023 11:26:09\"|\"0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124\"|\"The asset is corrupted\"|\"True\"|\"The asset has been rotated\"|\"True\"\r\n"; - csvUnescapedTextWithPipe = "FolderId|FileName|FileSize|ImageRotation|PixelWidth|PixelHeight|ThumbnailPixelWidth|ThumbnailPixelHeight|ThumbnailCreationDateTime|Hash|AssetCorruptedMessage|IsAssetCorrupted|AssetRotatedMessage|IsAssetRotated\r\n" + + _csvUnescapedTextWithPipe = "FolderId|FileName|FileSize|ImageRotation|PixelWidth|PixelHeight|ThumbnailPixelWidth|ThumbnailPixelHeight|ThumbnailCreationDateTime|Hash|AssetCorruptedMessage|IsAssetCorrupted|AssetRotatedMessage|IsAssetRotated\r\n" + "876283c6-780e-4ad5-975c-be63044c087a|20200720175810_3.jpg|363888|Rotate0|1920|1080|200|112|8/19/2023 11:26:09|4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4||False||False\r\n" + "876283c6-780e-4ad5-975c-be63044c087a|20200720175816_3.jpg|343633|Rotate0|1920|1080|200|112|8/19/2023 11:26:09|0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124|The asset is corrupted|True|The asset has been rotated|True\r\n"; - csvSomeUnescapedTextWithPipe = "\"FolderId\"|FileName|FileSize|ImageRotation|PixelWidth|PixelHeight|ThumbnailPixelWidth|ThumbnailPixelHeight|ThumbnailCreationDateTime|Hash|AssetCorruptedMessage|IsAssetCorrupted|AssetRotatedMessage|\"IsAssetRotated\"\r\n" + + _csvSomeUnescapedTextWithPipe = "\"FolderId\"|FileName|FileSize|ImageRotation|PixelWidth|PixelHeight|ThumbnailPixelWidth|ThumbnailPixelHeight|ThumbnailCreationDateTime|Hash|AssetCorruptedMessage|IsAssetCorrupted|AssetRotatedMessage|\"IsAssetRotated\"\r\n" + "\"876283c6-780e-4ad5-975c-be63044c087a\"|20200720175810_3.jpg|363888|Rotate0|1920|1080|200|112|8/19/2023 11:26:09|4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4||False||\"False\"\r\n" + "\"876283c6-780e-4ad5-975c-be63044c087a\"|20200720175816_3.jpg|343633|Rotate0|1920|1080|200|112|8/19/2023 11:26:09|0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124|The asset is corrupted|True|The asset has been rotated|\"True\"\r\n"; } @@ -57,31 +57,22 @@ public void SetUp() [TestCase("UnescapedText", false)] public void WriteObjectList_AllColumnsAndSemicolonSeparator_WritesCorrectCsv(string csvType, bool escapeText) { - string csv; - - if (csvType == "EscapedText") - { - csv = csvEscapedTextWithSemicolon!; - } - else - { - csv = csvUnescapedTextWithSemicolon!; - } + string csv = csvType == "EscapedText" ? _csvEscapedTextWithSemicolon! : _csvUnescapedTextWithSemicolon!; string tableName = "assets" + Guid.NewGuid(); - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string filePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, tableName + ".db"); try { - WriteObjectList(directoryPath, semicolonSeparator, tableName, escapeText); + WriteObjectList(directoryPath, SEMICOLON_SEPARATOR, tableName, escapeText); Asserts(filePath, csv); } finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } @@ -90,19 +81,10 @@ public void WriteObjectList_AllColumnsAndSemicolonSeparator_WritesCorrectCsv(str [TestCase("UnescapedText", false)] public void WriteObjectList_AllColumnsAndPipeSeparator_WritesCorrectCsv(string csvType, bool escapeText) { - string csv; - - if (csvType == "EscapedText") - { - csv = csvEscapedTextWithPipe!; - } - else - { - csv = csvUnescapedTextWithPipe!; - } + string csv = csvType == "EscapedText" ? _csvEscapedTextWithPipe! : _csvUnescapedTextWithPipe!; string tableName = "assets" + Guid.NewGuid(); - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string filePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, tableName + ".db"); try @@ -114,37 +96,25 @@ public void WriteObjectList_AllColumnsAndPipeSeparator_WritesCorrectCsv(string c finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } [Test] - [TestCase("EscapedText")] - [TestCase("UnescapedText")] - public void WriteObjectList_AllColumnsAndPipeSeparatorWithoutDataTableProperties_ThrowsException(string csvType) + public void WriteObjectList_AllColumnsAndPipeSeparatorWithoutDataTableProperties_ThrowsException() { - string csv; - - if (csvType == "EscapedText") - { - csv = csvEscapedTextWithPipe!; - } - else - { - csv = csvUnescapedTextWithPipe!; - } - string tableName = "assets" + Guid.NewGuid(); - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string filePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, tableName + ".db"); try { - List assets = new() - { - new Asset + List assets = + [ + new() { FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "20200720175810_3.jpg", FileSize = 363888, ImageRotation = Rotation.Rotate0, @@ -153,15 +123,18 @@ public void WriteObjectList_AllColumnsAndPipeSeparatorWithoutDataTableProperties ThumbnailPixelWidth = 200, ThumbnailPixelHeight = 112, ThumbnailCreationDateTime = new DateTime(2023, 8, 19, 11, 26, 09), - Hash = "4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4", + Hash = + "4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4", AssetCorruptedMessage = null, IsAssetCorrupted = false, AssetRotatedMessage = null, IsAssetRotated = false }, - new Asset + + new() { FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "20200720175816_3.jpg", FileSize = 343633, ImageRotation = Rotation.Rotate0, @@ -170,13 +143,14 @@ public void WriteObjectList_AllColumnsAndPipeSeparatorWithoutDataTableProperties ThumbnailPixelWidth = 200, ThumbnailPixelHeight = 112, ThumbnailCreationDateTime = new DateTime(2023, 8, 19, 11, 26, 09), - Hash = "0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124", + Hash = + "0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124", AssetCorruptedMessage = "The asset is corrupted", IsAssetCorrupted = true, AssetRotatedMessage = "The asset has been rotated", IsAssetRotated = true } - }; + ]; _database!.Initialize( directoryPath, @@ -193,26 +167,27 @@ public void WriteObjectList_AllColumnsAndPipeSeparatorWithoutDataTableProperties finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } [Test] public void WriteObjectList_SomeColumnsWithEscapedTextAndPipeSeparator_WritesCorrectCsv() { - string csv = csvSomeUnescapedTextWithPipe!; + string csv = _csvSomeUnescapedTextWithPipe!; string tableName = "assets" + Guid.NewGuid(); - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string filePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, tableName + ".db"); try { - List assets = new() - { - new Asset + List assets = + [ + new() { FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "20200720175810_3.jpg", FileSize = 363888, ImageRotation = Rotation.Rotate0, @@ -221,15 +196,18 @@ public void WriteObjectList_SomeColumnsWithEscapedTextAndPipeSeparator_WritesCor ThumbnailPixelWidth = 200, ThumbnailPixelHeight = 112, ThumbnailCreationDateTime = new DateTime(2023, 8, 19, 11, 26, 09), - Hash = "4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4", + Hash = + "4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4", AssetCorruptedMessage = null, IsAssetCorrupted = false, AssetRotatedMessage = null, IsAssetRotated = false }, - new Asset + + new() { FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "20200720175816_3.jpg", FileSize = 343633, ImageRotation = Rotation.Rotate0, @@ -238,13 +216,14 @@ public void WriteObjectList_SomeColumnsWithEscapedTextAndPipeSeparator_WritesCor ThumbnailPixelWidth = 200, ThumbnailPixelHeight = 112, ThumbnailCreationDateTime = new DateTime(2023, 8, 19, 11, 26, 09), - Hash = "0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124", + Hash = + "0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124", AssetCorruptedMessage = "The asset is corrupted", IsAssetCorrupted = true, AssetRotatedMessage = "The asset has been rotated", IsAssetRotated = true } - }; + ]; _database!.Initialize( directoryPath, @@ -255,23 +234,23 @@ public void WriteObjectList_SomeColumnsWithEscapedTextAndPipeSeparator_WritesCor _database!.SetDataTableProperties(new DataTableProperties { TableName = tableName, - ColumnProperties = new ColumnProperties[] - { - new ColumnProperties { ColumnName = "FolderId", EscapeText = true }, - new ColumnProperties { ColumnName = "FileName", EscapeText = false }, - new ColumnProperties { ColumnName = "FileSize", EscapeText = false }, - new ColumnProperties { ColumnName = "ImageRotation", EscapeText = false }, - new ColumnProperties { ColumnName = "PixelWidth", EscapeText = false }, - new ColumnProperties { ColumnName = "PixelHeight", EscapeText = false }, - new ColumnProperties { ColumnName = "ThumbnailPixelWidth", EscapeText = false }, - new ColumnProperties { ColumnName = "ThumbnailPixelHeight", EscapeText = false }, - new ColumnProperties { ColumnName = "ThumbnailCreationDateTime", EscapeText = false }, - new ColumnProperties { ColumnName = "Hash", EscapeText = false }, - new ColumnProperties { ColumnName = "AssetCorruptedMessage", EscapeText = false }, - new ColumnProperties { ColumnName = "IsAssetCorrupted", EscapeText = false }, - new ColumnProperties { ColumnName = "AssetRotatedMessage", EscapeText = false }, - new ColumnProperties { ColumnName = "IsAssetRotated", EscapeText = true } - } + ColumnProperties = + [ + new() { ColumnName = "FolderId", EscapeText = true }, + new() { ColumnName = "FileName", EscapeText = false }, + new() { ColumnName = "FileSize", EscapeText = false }, + new() { ColumnName = "ImageRotation", EscapeText = false }, + new() { ColumnName = "PixelWidth", EscapeText = false }, + new() { ColumnName = "PixelHeight", EscapeText = false }, + new() { ColumnName = "ThumbnailPixelWidth", EscapeText = false }, + new() { ColumnName = "ThumbnailPixelHeight", EscapeText = false }, + new() { ColumnName = "ThumbnailCreationDateTime", EscapeText = false }, + new() { ColumnName = "Hash", EscapeText = false }, + new() { ColumnName = "AssetCorruptedMessage", EscapeText = false }, + new() { ColumnName = "IsAssetCorrupted", EscapeText = false }, + new() { ColumnName = "AssetRotatedMessage", EscapeText = false }, + new() { ColumnName = "IsAssetRotated", EscapeText = true } + ] }); _database!.WriteObjectList(assets, tableName, AssetConfigs.WriteFunc); @@ -281,26 +260,27 @@ public void WriteObjectList_SomeColumnsWithEscapedTextAndPipeSeparator_WritesCor finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } [Test] public void WriteObjectList_SomeColumnsInvalidsAndPipeSeparator_WritesIncorrectCsv() { - string csv = csvUnescapedTextWithPipe!; + string csv = _csvUnescapedTextWithPipe!; string tableName = "assets" + Guid.NewGuid(); - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string filePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, tableName + ".db"); try { - List assets = new() - { - new Asset + List assets = + [ + new() { FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "20200720175810_3.jpg", FileSize = 363888, ImageRotation = Rotation.Rotate0, @@ -309,15 +289,18 @@ public void WriteObjectList_SomeColumnsInvalidsAndPipeSeparator_WritesIncorrectC ThumbnailPixelWidth = 200, ThumbnailPixelHeight = 112, ThumbnailCreationDateTime = new DateTime(2023, 8, 19, 11, 26, 09), - Hash = "4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4", + Hash = + "4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4", AssetCorruptedMessage = null, IsAssetCorrupted = false, AssetRotatedMessage = null, IsAssetRotated = false }, - new Asset + + new() { FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "20200720175816_3.jpg", FileSize = 343633, ImageRotation = Rotation.Rotate0, @@ -326,13 +309,14 @@ public void WriteObjectList_SomeColumnsInvalidsAndPipeSeparator_WritesIncorrectC ThumbnailPixelWidth = 200, ThumbnailPixelHeight = 112, ThumbnailCreationDateTime = new DateTime(2023, 8, 19, 11, 26, 09), - Hash = "0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124", + Hash = + "0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124", AssetCorruptedMessage = "The asset is corrupted", IsAssetCorrupted = true, AssetRotatedMessage = "The asset has been rotated", IsAssetRotated = true } - }; + ]; _database!.Initialize( directoryPath, @@ -343,23 +327,23 @@ public void WriteObjectList_SomeColumnsInvalidsAndPipeSeparator_WritesIncorrectC _database!.SetDataTableProperties(new DataTableProperties { TableName = tableName, - ColumnProperties = new ColumnProperties[] - { - new ColumnProperties { ColumnName = "FolderId", EscapeText = false }, - new ColumnProperties { ColumnName = "Toto", EscapeText = false }, - new ColumnProperties { ColumnName = "FileSize", EscapeText = false }, - new ColumnProperties { ColumnName = "ImageRotation", EscapeText = false }, - new ColumnProperties { ColumnName = "PixelWidth", EscapeText = false }, - new ColumnProperties { ColumnName = "PixelHeight", EscapeText = false }, - new ColumnProperties { ColumnName = "ThumbnailPixelWidth", EscapeText = false }, - new ColumnProperties { ColumnName = "ThumbnailPixelHeight", EscapeText = false }, - new ColumnProperties { ColumnName = "ThumbnailCreationDateTime", EscapeText = false }, - new ColumnProperties { ColumnName = "Tutu", EscapeText = false }, - new ColumnProperties { ColumnName = "AssetCorruptedMessage", EscapeText = false }, - new ColumnProperties { ColumnName = "IsAssetCorrupted", EscapeText = false }, - new ColumnProperties { ColumnName = "AssetRotatedMessage", EscapeText = false }, - new ColumnProperties { ColumnName = "Tata", EscapeText = false } - } + ColumnProperties = + [ + new() { ColumnName = "FolderId", EscapeText = false }, + new() { ColumnName = "Toto", EscapeText = false }, + new() { ColumnName = "FileSize", EscapeText = false }, + new() { ColumnName = "ImageRotation", EscapeText = false }, + new() { ColumnName = "PixelWidth", EscapeText = false }, + new() { ColumnName = "PixelHeight", EscapeText = false }, + new() { ColumnName = "ThumbnailPixelWidth", EscapeText = false }, + new() { ColumnName = "ThumbnailPixelHeight", EscapeText = false }, + new() { ColumnName = "ThumbnailCreationDateTime", EscapeText = false }, + new() { ColumnName = "Tutu", EscapeText = false }, + new() { ColumnName = "AssetCorruptedMessage", EscapeText = false }, + new() { ColumnName = "IsAssetCorrupted", EscapeText = false }, + new() { ColumnName = "AssetRotatedMessage", EscapeText = false }, + new() { ColumnName = "Tata", EscapeText = false } + ] }); _database!.WriteObjectList(assets, tableName, AssetConfigs.WriteFunc); @@ -375,17 +359,15 @@ public void WriteObjectList_SomeColumnsInvalidsAndPipeSeparator_WritesIncorrectC finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } [Test] public void WriteObjectList_ListIsNullAndAllColumnsWithUnescapedTextAndPipeSeparator_ThrowsArgumentNullException() { - string csv = csvUnescapedTextWithPipe!; - string tableName = "assets" + Guid.NewGuid(); - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string filePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, tableName + ".db"); try @@ -413,7 +395,7 @@ public void WriteObjectList_ListIsNullAndAllColumnsWithUnescapedTextAndPipeSepar finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } @@ -422,18 +404,17 @@ public void WriteObjectList_ListIsNullAndAllColumnsWithUnescapedTextAndPipeSepar [TestCase(" ")] public void WriteObjectList_TableNameIsInvalidAllColumnsWithEscapedTextAndPipeSeparator_ThrowsArgumentNullException(string tableName) { - string csv = csvUnescapedTextWithPipe!; - - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string filePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, tableName + ".db"); try { - List assets = new() - { - new Asset + List assets = + [ + new() { FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "20200720175810_3.jpg", FileSize = 363888, ImageRotation = Rotation.Rotate0, @@ -442,15 +423,18 @@ public void WriteObjectList_TableNameIsInvalidAllColumnsWithEscapedTextAndPipeSe ThumbnailPixelWidth = 200, ThumbnailPixelHeight = 112, ThumbnailCreationDateTime = new DateTime(2023, 8, 19, 11, 26, 09), - Hash = "4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4", + Hash = + "4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4", AssetCorruptedMessage = null, IsAssetCorrupted = false, AssetRotatedMessage = null, IsAssetRotated = false }, - new Asset + + new() { FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "20200720175816_3.jpg", FileSize = 343633, ImageRotation = Rotation.Rotate0, @@ -459,13 +443,14 @@ public void WriteObjectList_TableNameIsInvalidAllColumnsWithEscapedTextAndPipeSe ThumbnailPixelWidth = 200, ThumbnailPixelHeight = 112, ThumbnailCreationDateTime = new DateTime(2023, 8, 19, 11, 26, 09), - Hash = "0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124", + Hash = + "0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124", AssetCorruptedMessage = "The asset is corrupted", IsAssetCorrupted = true, AssetRotatedMessage = "The asset has been rotated", IsAssetRotated = true } - }; + ]; _database!.Initialize( directoryPath, @@ -488,26 +473,25 @@ public void WriteObjectList_TableNameIsInvalidAllColumnsWithEscapedTextAndPipeSe finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } [Test] public void WriteObjectList_TableNameIsNullAllColumnsWithEscapedTextAndPipeSeparator_ThrowsTwoArgumentNullException() { - string csv = csvUnescapedTextWithPipe!; - string? tableName = null; - string directoryPath = Path.Combine(dataDirectory!, "DatabaseTests"); + string directoryPath = Path.Combine(_dataDirectory!, "DatabaseTests"); string filePath = Path.Combine(directoryPath, _userConfigurationService!.StorageSettings.FoldersNameSettings.Tables, tableName + ".db"); try { - List assets = new() - { - new Asset + List assets = + [ + new() { FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "20200720175810_3.jpg", FileSize = 363888, ImageRotation = Rotation.Rotate0, @@ -516,15 +500,18 @@ public void WriteObjectList_TableNameIsNullAllColumnsWithEscapedTextAndPipeSepar ThumbnailPixelWidth = 200, ThumbnailPixelHeight = 112, ThumbnailCreationDateTime = new DateTime(2023, 8, 19, 11, 26, 09), - Hash = "4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4", + Hash = + "4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4", AssetCorruptedMessage = null, IsAssetCorrupted = false, AssetRotatedMessage = null, IsAssetRotated = false }, - new Asset + + new() { FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "20200720175816_3.jpg", FileSize = 343633, ImageRotation = Rotation.Rotate0, @@ -533,13 +520,14 @@ public void WriteObjectList_TableNameIsNullAllColumnsWithEscapedTextAndPipeSepar ThumbnailPixelWidth = 200, ThumbnailPixelHeight = 112, ThumbnailCreationDateTime = new DateTime(2023, 8, 19, 11, 26, 09), - Hash = "0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124", + Hash = + "0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124", AssetCorruptedMessage = "The asset is corrupted", IsAssetCorrupted = true, AssetRotatedMessage = "The asset has been rotated", IsAssetRotated = true } - }; + ]; _database!.Initialize( directoryPath, @@ -564,17 +552,18 @@ public void WriteObjectList_TableNameIsNullAllColumnsWithEscapedTextAndPipeSepar finally { Directory.Delete(directoryPath, true); - Directory.Delete(Path.Combine(dataDirectory!, "DatabaseTests_Backups"), true); + Directory.Delete(Path.Combine(_dataDirectory!, "DatabaseTests_Backups"), true); } } private void WriteObjectList(string directoryPath, char separator, string tableName, bool escapeText) { - List assets = new() - { - new Asset + List assets = + [ + new() { FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "20200720175810_3.jpg", FileSize = 363888, ImageRotation = Rotation.Rotate0, @@ -583,15 +572,18 @@ private void WriteObjectList(string directoryPath, char separator, string tableN ThumbnailPixelWidth = 200, ThumbnailPixelHeight = 112, ThumbnailCreationDateTime = new DateTime(2023, 8, 19, 11, 26, 09), - Hash = "4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4", + Hash = + "4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4", AssetCorruptedMessage = null, IsAssetCorrupted = false, AssetRotatedMessage = null, IsAssetRotated = false }, - new Asset + + new() { FolderId = new Guid("876283c6-780e-4ad5-975c-be63044c087a"), + Folder = new() { Path = "" }, FileName = "20200720175816_3.jpg", FileSize = 343633, ImageRotation = Rotation.Rotate0, @@ -600,13 +592,14 @@ private void WriteObjectList(string directoryPath, char separator, string tableN ThumbnailPixelWidth = 200, ThumbnailPixelHeight = 112, ThumbnailCreationDateTime = new DateTime(2023, 8, 19, 11, 26, 09), - Hash = "0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124", + Hash = + "0af8f118b7d606e5d174643727bd3c0c6028b52c50481585274fd572110b108c7a0d7901227f75a72b44c89335e002a65e8137ff5b238ab1c0bba0505e783124", AssetCorruptedMessage = "The asset is corrupted", IsAssetCorrupted = true, AssetRotatedMessage = "The asset has been rotated", IsAssetRotated = true } - }; + ]; _database!.Initialize( directoryPath, @@ -617,23 +610,23 @@ private void WriteObjectList(string directoryPath, char separator, string tableN _database!.SetDataTableProperties(new DataTableProperties { TableName = tableName, - ColumnProperties = new ColumnProperties[] - { - new ColumnProperties { ColumnName = "FolderId", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "FileName", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "FileSize", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "ImageRotation", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "PixelWidth", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "PixelHeight", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "ThumbnailPixelWidth", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "ThumbnailPixelHeight", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "ThumbnailCreationDateTime", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "Hash", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "AssetCorruptedMessage", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "IsAssetCorrupted", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "AssetRotatedMessage", EscapeText = escapeText }, - new ColumnProperties { ColumnName = "IsAssetRotated", EscapeText = escapeText } - } + ColumnProperties = + [ + new() { ColumnName = "FolderId", EscapeText = escapeText }, + new() { ColumnName = "FileName", EscapeText = escapeText }, + new() { ColumnName = "FileSize", EscapeText = escapeText }, + new() { ColumnName = "ImageRotation", EscapeText = escapeText }, + new() { ColumnName = "PixelWidth", EscapeText = escapeText }, + new() { ColumnName = "PixelHeight", EscapeText = escapeText }, + new() { ColumnName = "ThumbnailPixelWidth", EscapeText = escapeText }, + new() { ColumnName = "ThumbnailPixelHeight", EscapeText = escapeText }, + new() { ColumnName = "ThumbnailCreationDateTime", EscapeText = escapeText }, + new() { ColumnName = "Hash", EscapeText = escapeText }, + new() { ColumnName = "AssetCorruptedMessage", EscapeText = escapeText }, + new() { ColumnName = "IsAssetCorrupted", EscapeText = escapeText }, + new() { ColumnName = "AssetRotatedMessage", EscapeText = escapeText }, + new() { ColumnName = "IsAssetRotated", EscapeText = escapeText } + ] }); _database!.WriteObjectList(assets, tableName, AssetConfigs.WriteFunc); diff --git a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/Storage/BackupStorageTests.cs b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/Storage/BackupStorageTests.cs index abd9b242..997eca02 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/Storage/BackupStorageTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/Storage/BackupStorageTests.cs @@ -3,13 +3,14 @@ [TestFixture] public class BackupStorageTests { - private string? dataDirectory; + private string? _dataDirectory; + private BackupStorage? _backupStorage; [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); _backupStorage = new BackupStorage(); } @@ -17,16 +18,16 @@ public void OneTimeSetUp() [Test] public void GetBackupFilesPaths_PathWithFiles_ReturnsCorrectFiles() { - string[] partialExpectedFiles = new string[] - { - Path.Combine(dataDirectory!, "Homer.gif"), - Path.Combine(dataDirectory!, "Homer.mp4"), - Path.Combine(dataDirectory!, "Image 8.jpeg"), - Path.Combine(dataDirectory!, "Image 9.png"), - Path.Combine(dataDirectory!, "Image_11.heic") - }; + string[] partialExpectedFiles = + [ + Path.Combine(_dataDirectory!, "Homer.gif"), + Path.Combine(_dataDirectory!, "Homer.mp4"), + Path.Combine(_dataDirectory!, "Image 8.jpeg"), + Path.Combine(_dataDirectory!, "Image 9.png"), + Path.Combine(_dataDirectory!, "Image_11.heic") + ]; - string[] actualFiles = _backupStorage!.GetBackupFilesPaths(dataDirectory!); + string[] actualFiles = _backupStorage!.GetBackupFilesPaths(_dataDirectory!); CollectionAssert.IsSubsetOf(partialExpectedFiles, actualFiles); } @@ -34,7 +35,7 @@ public void GetBackupFilesPaths_PathWithFiles_ReturnsCorrectFiles() [Test] public void GetBackupFilesPaths_PathWithNoFiles_ReturnsEmptyArray() { - string backupDirectory = Path.Combine(dataDirectory!, "EmptyFolder"); + string backupDirectory = Path.Combine(_dataDirectory!, "EmptyFolder"); try { @@ -56,9 +57,9 @@ public void GetBackupFilesPaths_PathWithNoFiles_ReturnsEmptyArray() [Test] public void GetBackupFilesPaths_PathDoesNotExist_ThrowsDirectoryNotFoundException() { - string backupDirectory = Path.Combine(dataDirectory!, "NonExistentFolder"); + string backupDirectory = Path.Combine(_dataDirectory!, "NonExistentFolder"); - DirectoryNotFoundException? exception = Assert.Throws(() => _backupStorage!.GetBackupFilesPaths(backupDirectory!)); + DirectoryNotFoundException? exception = Assert.Throws(() => _backupStorage!.GetBackupFilesPaths(backupDirectory)); Assert.AreEqual($"Could not find a part of the path '{backupDirectory}'.", exception?.Message); } @@ -76,8 +77,8 @@ public void GetBackupFilesPaths_PathIsNull_ThrowsArgumentNullException() [Test] public void WriteFolderToZipFile_ValidSourceDirectoryName_SuccessfullyCreatesZipFile() { - string sourceDirectoryName = Path.Combine(dataDirectory!, "TestFolder"); - string destinationArchiveFileName = Path.Combine(dataDirectory!, "TestFolder.zip"); + string sourceDirectoryName = Path.Combine(_dataDirectory!, "TestFolder"); + string destinationArchiveFileName = Path.Combine(_dataDirectory!, "TestFolder.zip"); try { @@ -94,8 +95,8 @@ public void WriteFolderToZipFile_ValidSourceDirectoryName_SuccessfullyCreatesZip [Test] public void WriteFolderToZipFile_InvalidSourceDirectoryName_ThrowsDirectoryNotFoundException() { - string invalidSourceDirectoryName = "InvalidDirectory"; - string destinationArchiveFileName = Path.Combine(dataDirectory!, "backup.zip"); + const string invalidSourceDirectoryName = "InvalidDirectory"; + string destinationArchiveFileName = Path.Combine(_dataDirectory!, "backup.zip"); try { @@ -116,7 +117,7 @@ public void WriteFolderToZipFile_InvalidSourceDirectoryName_ThrowsDirectoryNotFo [Test] public void WriteFolderToZipFile_DestinationArchiveFileNameIsNull_ThrowsArgumentNullException() { - string sourceDirectoryName = Path.Combine(dataDirectory!, "TestFolder"); + string sourceDirectoryName = Path.Combine(_dataDirectory!, "TestFolder"); string? destinationArchiveFileName = null; BackupStorage backupStorage = new(); @@ -132,8 +133,8 @@ public void WriteFolderToZipFile_DestinationArchiveFileNameIsNull_ThrowsArgument [Test] public void WriteFolderToZipFile_DestinationArchiveFileNameDoesNotExist_ThrowsDirectoryNotFoundException() { - string sourceDirectoryName = Path.Combine(dataDirectory!, "TestFolder"); - string destinationArchiveFileName = Path.Combine(dataDirectory!, "nonexistent", "backup.zip"); + string sourceDirectoryName = Path.Combine(_dataDirectory!, "TestFolder"); + string destinationArchiveFileName = Path.Combine(_dataDirectory!, "nonexistent", "backup.zip"); BackupStorage backupStorage = new(); @@ -148,8 +149,8 @@ public void WriteFolderToZipFile_DestinationArchiveFileNameDoesNotExist_ThrowsDi [Test] public void DeleteBackupFile_FileExists_FileDeleted() { - string sourceDirectoryName = Path.Combine(dataDirectory!, "TestFolder"); - string destinationArchiveFileName = Path.Combine(dataDirectory!, "TestFolder.zip"); + string sourceDirectoryName = Path.Combine(_dataDirectory!, "TestFolder"); + string destinationArchiveFileName = Path.Combine(_dataDirectory!, "TestFolder.zip"); _backupStorage!.WriteFolderToZipFile(sourceDirectoryName, destinationArchiveFileName); @@ -163,7 +164,7 @@ public void DeleteBackupFile_FileExists_FileDeleted() [Test] public void DeleteBackupFile_FileDoesNotExist_NoExceptionThrown() { - string tempFilePath = Path.Combine(dataDirectory!, "nonExistentFileToDelete.zip"); + string tempFilePath = Path.Combine(_dataDirectory!, "nonExistentFileToDelete.zip"); Assert.DoesNotThrow(() => _backupStorage!.DeleteBackupFile(tempFilePath)); } @@ -171,9 +172,9 @@ public void DeleteBackupFile_FileDoesNotExist_NoExceptionThrown() [Test] public void DeleteBackupFile_FilePathIsInvalid_ThrowsUnauthorizedAccessException() { - UnauthorizedAccessException? exception = Assert.Throws(() => _backupStorage!.DeleteBackupFile(dataDirectory!)); + UnauthorizedAccessException? exception = Assert.Throws(() => _backupStorage!.DeleteBackupFile(_dataDirectory!)); - Assert.AreEqual($"Access to the path '{dataDirectory!}' is denied.", exception?.Message); + Assert.AreEqual($"Access to the path '{_dataDirectory!}' is denied.", exception?.Message); } [Test] diff --git a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/Storage/BlobStorageTests.cs b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/Storage/BlobStorageTests.cs index 45293194..a6956be0 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/Storage/BlobStorageTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/Database/Storage/BlobStorageTests.cs @@ -3,7 +3,8 @@ [TestFixture] public class BlobStorageTests { - private string? dataDirectory; + private string? _dataDirectory; + private BlobStorage? _blobStorage; private UserConfigurationService? _userConfigurationService; private Mock? _configurationRootMock; @@ -11,7 +12,7 @@ public class BlobStorageTests [OneTimeSetUp] public void OneTimeSetUp() { - dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); + _dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles"); _configurationRootMock = new Mock(); _configurationRootMock.GetDefaultMockConfig(); @@ -30,7 +31,7 @@ public void SetUp() [TestCase("f1f00403-0554-4201-9b6b-11a6b4cea3a9.bin", 7, "1336.JPG")] public void ReadFromBinaryFile_FileExists_ReturnsDeserializedObject(string blobFileName, int countExpected, string keyContained) { - string blobFilePath = Path.Combine(dataDirectory!, "TestBackup\\v1.0", _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, blobFileName); + string blobFilePath = Path.Combine(_dataDirectory!, "TestBackup\\v1.0", _userConfigurationService!.StorageSettings.FoldersNameSettings.Blobs, blobFileName); Dictionary? deserializedObject = _blobStorage!.ReadFromBinaryFile(blobFilePath); @@ -43,7 +44,7 @@ public void ReadFromBinaryFile_FileExists_ReturnsDeserializedObject(string blobF [Test] public void ReadFromBinaryFile_FileDoesNotExist_ReturnsNull() { - string blobFilePath = Path.Combine(dataDirectory!, "TestBackup\\v1.0\\Blobs\\eacd6c1b-d432-4424-9498-8c4c8d8940dd.bin"); + string blobFilePath = Path.Combine(_dataDirectory!, "TestBackup\\v1.0\\Blobs\\eacd6c1b-d432-4424-9498-8c4c8d8940dd.bin"); Dictionary? result = _blobStorage!.ReadFromBinaryFile(blobFilePath); @@ -53,7 +54,7 @@ public void ReadFromBinaryFile_FileDoesNotExist_ReturnsNull() [Test] public void ReadFromBinaryFile_FilePathIsInvalid_ReturnsNull() { - Dictionary? result = _blobStorage!.ReadFromBinaryFile(dataDirectory!); + Dictionary? result = _blobStorage!.ReadFromBinaryFile(_dataDirectory!); Assert.IsNull(result); } @@ -71,14 +72,14 @@ public void ReadFromBinaryFile_FilePathIsNull_ReturnsNull() [Test] public void WriteToBinaryFile_DataIsCorrect_WritesDataToFile() { - string binaryFilePath = Path.Combine(dataDirectory!, "abcd6c1b-d432-4424-9498-8c4c8d8940dd.bin"); + string binaryFilePath = Path.Combine(_dataDirectory!, "abcd6c1b-d432-4424-9498-8c4c8d8940dd.bin"); try { Dictionary data = new() { - { "Image1.jpg", new byte[] { 1, 2, 3 } }, - { "Image2.png", new byte[] { 4, 5, 6 } } + { "Image1.jpg", [1, 2, 3]}, + { "Image2.png", [4, 5, 6]} }; _blobStorage!.WriteToBinaryFile(data, binaryFilePath); @@ -100,7 +101,7 @@ public void WriteToBinaryFile_DataIsCorrect_WritesDataToFile() [Test] public void WriteToBinaryFile_DataIsNull_ThrowsNullReferenceException() { - string binaryFilePath = Path.Combine(dataDirectory!, "bbcd6c1b-d432-4424-9498-8c4c8d8940dd.bin"); + string binaryFilePath = Path.Combine(_dataDirectory!, "bbcd6c1b-d432-4424-9498-8c4c8d8940dd.bin"); try { @@ -120,11 +121,11 @@ public void WriteToBinaryFile_DataIsNull_ThrowsNullReferenceException() [Test] public void WriteToBinaryFile_DataIsEmpty_WritesNothingInTheFile() { - string binaryFilePath = Path.Combine(dataDirectory!, "cbcd6c1b-d432-4424-9498-8c4c8d8940dd.bin"); + string binaryFilePath = Path.Combine(_dataDirectory!, "cbcd6c1b-d432-4424-9498-8c4c8d8940dd.bin"); try { - Dictionary data = new(); + Dictionary data = []; _blobStorage!.WriteToBinaryFile(data, binaryFilePath); @@ -145,13 +146,13 @@ public void WriteToBinaryFile_FilePathIsInvalid_ThrowsUnauthorizedAccessExceptio { Dictionary data = new() { - { "Image1.jpg", new byte[] { 1, 2, 3 } }, - { "Image2.png", new byte[] { 4, 5, 6 } } + { "Image1.jpg", [1, 2, 3]}, + { "Image2.png", [4, 5, 6]} }; - UnauthorizedAccessException? exception = Assert.Throws(() => _blobStorage!.WriteToBinaryFile(data, dataDirectory!)); + UnauthorizedAccessException? exception = Assert.Throws(() => _blobStorage!.WriteToBinaryFile(data, _dataDirectory!)); - Assert.AreEqual($"Access to the path '{dataDirectory!}' is denied.", exception?.Message); + Assert.AreEqual($"Access to the path '{_dataDirectory!}' is denied.", exception?.Message); } [Test] @@ -161,8 +162,8 @@ public void WriteToBinaryFile_FilePathIsNull_ThrowsArgumentNullException() Dictionary data = new() { - { "Image1.jpg", new byte[] { 1, 2, 3 } }, - { "Image2.png", new byte[] { 4, 5, 6 } } + { "Image1.jpg", [1, 2, 3]}, + { "Image2.png", [4, 5, 6]} }; ArgumentNullException? exception = Assert.Throws(() => _blobStorage!.WriteToBinaryFile(data, binaryFilePath!)); diff --git a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/TablesConfig/AssetConfigsTests.cs b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/TablesConfig/AssetConfigsTests.cs index 28b20640..76e1e2b0 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/TablesConfig/AssetConfigsTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/TablesConfig/AssetConfigsTests.cs @@ -3,16 +3,16 @@ [TestFixture] public class AssetConfigsTests { - private readonly Guid folderId = Guid.NewGuid(); - private string[]? validValues; - private string[]? tooManyValues; + private readonly Guid _folderId = Guid.NewGuid(); + private string[]? _validValues; + private string[]? _tooManyValues; [OneTimeSetUp] public void OneTimeSetUp() { - validValues = new string[] - { - folderId.ToString(), + _validValues = + [ + _folderId.ToString(), "Image 1.jpg", "1000", "0", @@ -26,11 +26,11 @@ public void OneTimeSetUp() "True", null!, "False" - }; + ]; - tooManyValues = new string[] - { - folderId.ToString(), + _tooManyValues = + [ + _folderId.ToString(), "Image 1.jpg", "1000", "0", @@ -46,7 +46,7 @@ public void OneTimeSetUp() "False", "False", "False" - }; + ]; } [Test] @@ -76,10 +76,10 @@ public void ConfigureDataTable_ReturnsCorrectColumnNames() [Test] public void ReadFunc_ValidValues_ParsesStringArrayIntoAsset() { - Asset asset = AssetConfigs.ReadFunc(validValues!); + Asset asset = AssetConfigs.ReadFunc(_validValues!); Assert.IsNotNull(asset); - Assert.AreEqual(folderId, asset.FolderId); + Assert.AreEqual(_folderId, asset.FolderId); Assert.AreEqual("Image 1.jpg", asset.FileName); Assert.AreEqual(1000, asset.FileSize); Assert.AreEqual(Rotation.Rotate0, asset.ImageRotation); @@ -98,10 +98,10 @@ public void ReadFunc_ValidValues_ParsesStringArrayIntoAsset() [Test] public void ReadFunc_TooManyValues_ParsesStringArrayIntoAsset() { - Asset asset = AssetConfigs.ReadFunc(tooManyValues!); + Asset asset = AssetConfigs.ReadFunc(_tooManyValues!); Assert.IsNotNull(asset); - Assert.AreEqual(folderId, asset.FolderId); + Assert.AreEqual(_folderId, asset.FolderId); Assert.AreEqual("Image 1.jpg", asset.FileName); Assert.AreEqual(1000, asset.FileSize); Assert.AreEqual(Rotation.Rotate0, asset.ImageRotation); @@ -130,9 +130,9 @@ public void ReadFunc_NullValues_ThrowsArgumentNullException() [Test] public void ReadFunc_EmptyArray_ThrowsIndexOutOfRangeException() { - string[] emptyArrray = Array.Empty(); + string[] emptyArray = []; - IndexOutOfRangeException? exception = Assert.Throws(() => AssetConfigs.ReadFunc(emptyArrray)); + IndexOutOfRangeException? exception = Assert.Throws(() => AssetConfigs.ReadFunc(emptyArray)); Assert.AreEqual("Index was outside the bounds of the array.", exception?.Message); } @@ -140,9 +140,9 @@ public void ReadFunc_EmptyArray_ThrowsIndexOutOfRangeException() [Test] public void ReadFunc_InvalidValues_ThrowsFormatException() { - string[] invalidValues = new string[] - { - folderId.ToString(), + string[] invalidValues = + [ + _folderId.ToString(), "Image 1.jpg", "toto", "0", @@ -156,7 +156,7 @@ public void ReadFunc_InvalidValues_ThrowsFormatException() "15", null!, "False" - }; + ]; FormatException? exception = Assert.Throws(() => AssetConfigs.ReadFunc(invalidValues)); @@ -168,7 +168,8 @@ public void WriteFunc_AssetWithValidValues_ConvertsAssetPropertiesToIndexInArray { Asset asset = new() { - FolderId = folderId, + FolderId = _folderId, + Folder = new() { Path = "" }, FileName = "Image 1.jpg", FileSize = 1000, ImageRotation = Rotation.Rotate0, @@ -190,7 +191,7 @@ public void WriteFunc_AssetWithValidValues_ConvertsAssetPropertiesToIndexInArray result[i] = AssetConfigs.WriteFunc(asset, i); } - Assert.AreEqual(folderId, result[0]); + Assert.AreEqual(_folderId, result[0]); Assert.AreEqual("Image 1.jpg", result[1]); Assert.AreEqual(1000, result[2]); Assert.AreEqual(Rotation.Rotate0, result[3]); @@ -211,7 +212,9 @@ public void WriteFunc_AssetWithPartialValues_ConvertsAssetPropertiesToIndexInArr { Asset asset = new() { - FolderId = folderId, + FolderId = _folderId, + Folder = new() { Path = "" }, + FileName = "toto.jpg", ThumbnailCreationDateTime = new DateTime(2023, 08, 30, 12, 0, 0), Hash = "4e50d5c7f1a64b5d61422382ac822641ad4e5b943aca9ade955f4655f799558bb0ae9c342ee3ead0949b32019b25606bd16988381108f56bb6c6dd673edaa1e4", AssetCorruptedMessage = "The asset is corrupted", @@ -225,8 +228,8 @@ public void WriteFunc_AssetWithPartialValues_ConvertsAssetPropertiesToIndexInArr result[i] = AssetConfigs.WriteFunc(asset, i); } - Assert.AreEqual(folderId, result[0]); - Assert.AreEqual(null, result[1]); + Assert.AreEqual(_folderId, result[0]); + Assert.AreEqual("toto.jpg", result[1]); Assert.AreEqual(0, result[2]); Assert.AreEqual(Rotation.Rotate0, result[3]); Assert.AreEqual(0, result[4]); @@ -246,7 +249,8 @@ public void WriteFunc_IndexOutOfRange_ThrowsArgumentOutOfRangeException() { Asset asset = new() { - FolderId = folderId, + FolderId = _folderId, + Folder = new() { Path = "" }, FileName = "Image 1.jpg", FileSize = 1000, ImageRotation = Rotation.Rotate0, @@ -279,4 +283,4 @@ public void WriteFunc_AssetIsNull_ThrowsNullReferenceException() Assert.AreEqual("Object reference not set to an instance of an object.", exception?.Message); } } -} \ No newline at end of file +} diff --git a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/TablesConfig/FolderConfigsTests.cs b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/TablesConfig/FolderConfigsTests.cs index 66631fc6..6544736a 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/TablesConfig/FolderConfigsTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/TablesConfig/FolderConfigsTests.cs @@ -3,7 +3,7 @@ [TestFixture] public class FolderConfigsTests { - private readonly Guid folderId = Guid.NewGuid(); + private readonly Guid _folderId = Guid.NewGuid(); [Test] public void ConfigureDataTable_ReturnsCorrectColumnNames() @@ -20,34 +20,34 @@ public void ConfigureDataTable_ReturnsCorrectColumnNames() [Test] public void ReadFunc_ValidValues_ParsesStringArrayIntoFolder() { - string[] validValues = new string[] - { - folderId.ToString(), + string[] validValues = + [ + _folderId.ToString(), "D:\\folder\\newFolder" - }; + ]; Folder folder = FolderConfigs.ReadFunc(validValues); Assert.IsNotNull(folder); - Assert.AreEqual(folderId, folder.FolderId); + Assert.AreEqual(_folderId, folder.FolderId); Assert.AreEqual("D:\\folder\\newFolder", folder.Path); } [Test] public void ReadFunc_TooManyValues_ParsesStringArrayIntoFolder() { - string[] tooManyValues = new string[] - { - folderId.ToString(), + string[] tooManyValues = + [ + _folderId.ToString(), "D:\\folder\\newFolder", "toto", "15" - }; + ]; Folder folder = FolderConfigs.ReadFunc(tooManyValues); Assert.IsNotNull(folder); - Assert.AreEqual(folderId, folder.FolderId); + Assert.AreEqual(_folderId, folder.FolderId); Assert.AreEqual("D:\\folder\\newFolder", folder.Path); } @@ -64,9 +64,9 @@ public void ReadFunc_NullValues_ThrowsArgumentNullException() [Test] public void ReadFunc_EmptyArray_ThrowsIndexOutOfRangeException() { - string[] emptyArrray = Array.Empty(); + string[] emptyArray = []; - IndexOutOfRangeException? exception = Assert.Throws(() => FolderConfigs.ReadFunc(emptyArrray)); + IndexOutOfRangeException? exception = Assert.Throws(() => FolderConfigs.ReadFunc(emptyArray)); Assert.AreEqual("Index was outside the bounds of the array.", exception?.Message); } @@ -76,7 +76,7 @@ public void WriteFunc_FolderWithValidValues_ConvertsFolderPropertiesToIndexInArr { Folder folder = new() { - FolderId = folderId, + FolderId = _folderId, Path = "D:\\folder\\newFolder" }; @@ -86,7 +86,7 @@ public void WriteFunc_FolderWithValidValues_ConvertsFolderPropertiesToIndexInArr result[i] = FolderConfigs.WriteFunc(folder, i); } - Assert.AreEqual(folderId, result[0]); + Assert.AreEqual(_folderId, result[0]); Assert.AreEqual("D:\\folder\\newFolder", result[1]); } @@ -113,7 +113,7 @@ public void WriteFunc_IndexOutOfRange_ThrowsArgumentOutOfRangeException() { Folder folder = new() { - FolderId = folderId, + FolderId = _folderId, Path = "D:\\folder\\newFolder" }; @@ -134,4 +134,4 @@ public void WriteFunc_FolderIsNull_ThrowsNullReferenceException() Assert.AreEqual("Object reference not set to an instance of an object.", exception?.Message); } } -} \ No newline at end of file +} diff --git a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/TablesConfig/RecentPathsConfigsTests.cs b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/TablesConfig/RecentPathsConfigsTests.cs index 90ca736d..929bcc5d 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/TablesConfig/RecentPathsConfigsTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/TablesConfig/RecentPathsConfigsTests.cs @@ -17,10 +17,10 @@ public void ConfigureDataTable_ReturnsCorrectColumnNames() [Test] public void ReadFunc_ValidValues_ParsesStringArrayIntoRecentPath() { - string[] validValues = new string[] - { + string[] validValues = + [ "D:\\folder\\newFolder" - }; + ]; string recentPath = RecentPathsConfigs.ReadFunc(validValues); @@ -31,11 +31,11 @@ public void ReadFunc_ValidValues_ParsesStringArrayIntoRecentPath() [Test] public void ReadFunc_TooManyValues_ParsesStringArrayIntoRecentPath() { - string[] tooManyValues = new string[] - { + string[] tooManyValues = + [ "D:\\folder\\newFolder1", "D:\\folder\\newFolder2" - }; + ]; string recentPath = RecentPathsConfigs.ReadFunc(tooManyValues); @@ -56,9 +56,9 @@ public void ReadFunc_NullValues_ParsesStringArrayIntoNullValue() [Test] public void ReadFunc_EmptyArray_ThrowsIndexOutOfRangeException() { - string[] emptyArrray = Array.Empty(); + string[] emptyArray = []; - IndexOutOfRangeException? exception = Assert.Throws(() => RecentPathsConfigs.ReadFunc(emptyArrray)); + IndexOutOfRangeException? exception = Assert.Throws(() => RecentPathsConfigs.ReadFunc(emptyArray)); Assert.AreEqual("Index was outside the bounds of the array.", exception?.Message); } @@ -66,7 +66,7 @@ public void ReadFunc_EmptyArray_ThrowsIndexOutOfRangeException() [Test] public void WriteFunc_RecentPathWithValidValues_ConvertsRecentPathPropertiesToIndexInArray() { - string recentPath = "D:\\folder\\newFolder"; + const string recentPath = "D:\\folder\\newFolder"; object result = RecentPathsConfigs.WriteFunc(recentPath, 0); @@ -76,7 +76,7 @@ public void WriteFunc_RecentPathWithValidValues_ConvertsRecentPathPropertiesToIn [Test] public void WriteFunc_IndexOutOfRange_ThrowsArgumentOutOfRangeException() { - string recentPath = "D:\\folder\\newFolder"; + const string recentPath = "D:\\folder\\newFolder"; ArgumentOutOfRangeException? exception = Assert.Throws(() => RecentPathsConfigs.WriteFunc(recentPath, 2)); diff --git a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/TablesConfig/SyncAssetsDirectoriesDefinitionConfigsTests.cs b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/TablesConfig/SyncAssetsDirectoriesDefinitionConfigsTests.cs index 3992ff2e..f01bf4f3 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/TablesConfig/SyncAssetsDirectoriesDefinitionConfigsTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/TablesConfig/SyncAssetsDirectoriesDefinitionConfigsTests.cs @@ -20,13 +20,13 @@ public void ConfigureDataTable_ReturnsCorrectColumnNames() [Test] public void ReadFunc_ValidValues_ParsesStringArrayIntoSyncAssetsDirectoriesDefinition() { - string[] validValues = new string[] - { + string[] validValues = + [ "D:\\source\\newFolder", "D:\\destination\\newFolder", "False", "True" - }; + ]; SyncAssetsDirectoriesDefinition syncAssetsDirectoriesDefinition = SyncAssetsDirectoriesDefinitionConfigs.ReadFunc(validValues); @@ -40,15 +40,15 @@ public void ReadFunc_ValidValues_ParsesStringArrayIntoSyncAssetsDirectoriesDefin [Test] public void ReadFunc_TooManyValues_ParsesStringArrayIntoSyncAssetsDirectoriesDefinition() { - string[] tooManyValues = new string[] - { + string[] tooManyValues = + [ "D:\\source\\newFolder", "D:\\destination\\newFolder", "False", "True", "toto", "15" - }; + ]; SyncAssetsDirectoriesDefinition syncAssetsDirectoriesDefinition = SyncAssetsDirectoriesDefinitionConfigs.ReadFunc(tooManyValues); @@ -72,9 +72,9 @@ public void ReadFunc_NullValues_ThrowsArgumentNullException() [Test] public void ReadFunc_EmptyArray_ThrowsIndexOutOfRangeException() { - string[] emptyArrray = Array.Empty(); + string[] emptyArray = []; - IndexOutOfRangeException? exception = Assert.Throws(() => SyncAssetsDirectoriesDefinitionConfigs.ReadFunc(emptyArrray)); + IndexOutOfRangeException? exception = Assert.Throws(() => SyncAssetsDirectoriesDefinitionConfigs.ReadFunc(emptyArray)); Assert.AreEqual("Index was outside the bounds of the array.", exception?.Message); } @@ -82,13 +82,13 @@ public void ReadFunc_EmptyArray_ThrowsIndexOutOfRangeException() [Test] public void ReadFunc_InvalidValues_ThrowsFormatException() { - string[] invalidValues = new string[] - { + string[] invalidValues = + [ "D:\\source\\newFolder", "D:\\destination\\newFolder", "15", "False" - }; + ]; FormatException? exception = Assert.Throws(() => SyncAssetsDirectoriesDefinitionConfigs.ReadFunc(invalidValues)); diff --git a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/UserConfigurationServiceTests.cs b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/UserConfigurationServiceTests.cs index dfe71b67..076b887e 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/UserConfigurationServiceTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/Infrastructure/UserConfigurationServiceTests.cs @@ -196,7 +196,7 @@ public void FirstFrameVideosPath_CorrectValue_ReturnsFirstFrameVideosPathValue() Assert.IsNotNull(assetsDirectory); Assert.IsNotNull(firstFrameVideosPath); - Assert.AreEqual(Path.Combine(assetsDirectory!, "OutputVideoFirstFrame"), firstFrameVideosPath); + Assert.AreEqual(Path.Combine(assetsDirectory, "OutputVideoFirstFrame"), firstFrameVideosPath); Assert.AreEqual(Path.Combine("C:\\Path\\OutputVideoFirstFrame"), firstFrameVideosPath); } diff --git a/PhotoManager/PhotoManager.Tests/Unit/UI/Converters/FileNameConverterTests.cs b/PhotoManager/PhotoManager.Tests/Unit/UI/Converters/FileNameConverterTests.cs index 905106e8..29a6e858 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/UI/Converters/FileNameConverterTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/UI/Converters/FileNameConverterTests.cs @@ -17,7 +17,9 @@ public void Convert_InputStringNotNull_ReturnsFormattedFileName(string name, str FileNameConverter fileNameConverter = new(); Asset asset = new() { + Folder = new() { Path = "" }, FileName = name, + Hash = string.Empty }; object? parameter = null; @@ -42,7 +44,7 @@ public void Convert_InputStringNull_ReturnsNull() public void Convert_InputValueType_ReturnsInputValue() { FileNameConverter fileNameConverter = new(); - int input = 123; + const int input = 123; object? parameter = null; object result = fileNameConverter.Convert(input, typeof(int), parameter!, CultureInfo.InvariantCulture); diff --git a/PhotoManager/PhotoManager.Tests/Unit/UI/Converters/FileSizeConverterTests.cs b/PhotoManager/PhotoManager.Tests/Unit/UI/Converters/FileSizeConverterTests.cs index ef7eb35c..7651089a 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/UI/Converters/FileSizeConverterTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/UI/Converters/FileSizeConverterTests.cs @@ -44,7 +44,7 @@ public void Convert_NullInput_Returns0Bytes() public void Convert_NonNumberInputType_ReturnsFileSize() { FileSizeConverter fileSizeConverter = new(); - string input = "12345"; + const string input = "12345"; object? parameter = null; object result = fileSizeConverter.Convert(input, typeof(string), parameter!, CultureInfo.InvariantCulture); @@ -56,7 +56,7 @@ public void Convert_NonNumberInputType_ReturnsFileSize() public void Convert_InvalidFormat_ThrowsFormatException() { FileSizeConverter fileSizeConverter = new(); - string input = "abc"; + const string input = "abc"; object? parameter = null; FormatException? exception = Assert.Throws(() => diff --git a/PhotoManager/PhotoManager.Tests/Unit/UI/Converters/PixelSizeConverterTests.cs b/PhotoManager/PhotoManager.Tests/Unit/UI/Converters/PixelSizeConverterTests.cs index 149d4680..dc874955 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/UI/Converters/PixelSizeConverterTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/UI/Converters/PixelSizeConverterTests.cs @@ -13,8 +13,11 @@ public void Convert_AssetWithDifferentPixelsSize_ReturnsResolution(int width, in PixelSizeConverter pixelSizeConverter = new(); Asset asset = new() { + Folder = new() { Path = "" }, + FileName = "toto.jpg", PixelWidth = width, - PixelHeight = height + PixelHeight = height, + Hash = string.Empty }; object? parameter = null; @@ -39,7 +42,7 @@ public void Convert_NullInput_ReturnsEmptyString() public void Convert_NonAssetValue_ReturnsEmptyString() { PixelSizeConverter pixelSizeConverter = new(); - string input = "Not an Asset object"; + const string input = "Not an Asset object"; object? parameter = null; object result = pixelSizeConverter.Convert(input, typeof(string), parameter!, CultureInfo.InvariantCulture); diff --git a/PhotoManager/PhotoManager.Tests/Unit/UI/Converters/TernaryConverterTests.cs b/PhotoManager/PhotoManager.Tests/Unit/UI/Converters/TernaryConverterTests.cs index 0067a392..304a702d 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/UI/Converters/TernaryConverterTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/UI/Converters/TernaryConverterTests.cs @@ -13,9 +13,11 @@ public void Convert_AssetCorrupted_ReturnsValue(bool assertion, string message, TernaryConverter ternaryConverter = new(); Asset asset = new() { - FileName = "toto", + Folder = new() { Path = "" }, + FileName = "toto.jpg", IsAssetCorrupted = assertion, AssetCorruptedMessage = message, + Hash = string.Empty }; object[] converterParameters = [asset.IsAssetCorrupted, asset.AssetCorruptedMessage]; @@ -34,9 +36,11 @@ public void Convert_AssetRotated_ReturnsValue(bool assertion, string message, st TernaryConverter ternaryConverter = new(); Asset asset = new() { - FileName = "toto", + Folder = new() { Path = "" }, + FileName = "toto.jpg", IsAssetRotated = assertion, AssetRotatedMessage = message, + Hash = string.Empty }; object[] converterParameters = [asset.IsAssetRotated, asset.AssetRotatedMessage]; diff --git a/PhotoManager/PhotoManager.Tests/Unit/UI/ViewModels/ApplicationViewModelTests.cs b/PhotoManager/PhotoManager.Tests/Unit/UI/ViewModels/ApplicationViewModelTests.cs index eb0f3729..03dab199 100644 --- a/PhotoManager/PhotoManager.Tests/Unit/UI/ViewModels/ApplicationViewModelTests.cs +++ b/PhotoManager/PhotoManager.Tests/Unit/UI/ViewModels/ApplicationViewModelTests.cs @@ -143,14 +143,14 @@ public void NotifyCatalogChange_CreatedToNonEmptyListCurrentFolder_AddNewAssetTo Asset[] assets = [ - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage(), Folder = folder } + new() { FileName = "Image 1.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 2.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 3.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 4.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 5.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder } ]; - Asset newAsset = new() { FileName = "NewImage.jpg", ImageData = new BitmapImage(), Folder = folder }; + Asset newAsset = new() { FileName = "NewImage.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }; const string statusMessage = "Creating thumbnail for NewImage.jpg"; _applicationViewModel!.SetAssets(assets); @@ -193,14 +193,14 @@ public void NotifyCatalogChange_CreatedToNonEmptyListNotCurrentFolder_DoesNotAdd Asset[] assets = [ - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage(), Folder = folder } + new() { FileName = "Image 1.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 2.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 3.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 4.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 5.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder } ]; - Asset newAsset = new() { FileName = "NewImage.jpg", ImageData = new BitmapImage(), Folder = folder }; + Asset newAsset = new() { FileName = "NewImage.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }; const string statusMessage = "Creating thumbnail for NewImage.jpg"; _applicationViewModel!.SetAssets(assets); @@ -243,11 +243,11 @@ public void NotifyCatalogChange_CreatedToEmptyListCurrentFolderWithCataloguedAss List cataloguedAssets = [ - new Asset {FileName = "Image 1.jpg", ImageData = new BitmapImage(), Folder = folder}, - new Asset {FileName = "Image 2.jpg", ImageData = new BitmapImage(), Folder = folder}, - new Asset {FileName = "Image 3.jpg", ImageData = new BitmapImage(), Folder = folder}, - new Asset {FileName = "Image 4.jpg", ImageData = new BitmapImage(), Folder = folder}, - new Asset {FileName = "Image 5.jpg", ImageData = new BitmapImage(), Folder = folder} + new() {FileName = "Image 1.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder}, + new() {FileName = "Image 2.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder}, + new() {FileName = "Image 3.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder}, + new() {FileName = "Image 4.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder}, + new() {FileName = "Image 5.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder} ]; const string statusMessage = "Creating thumbnail for Image 5.jpg"; @@ -289,7 +289,7 @@ public void NotifyCatalogChange_CreatedToEmptyListCurrentFolderWithoutCatalogued Folder folder = _testableAssetRepository!.AddFolder(_dataDirectory!); Asset[] assets = []; - Asset newAsset = new() { FileName = "NewImage.jpg", ImageData = new BitmapImage(), Folder = folder }; + Asset newAsset = new() { FileName = "NewImage.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }; _applicationViewModel!.SetAssets(assets); @@ -322,15 +322,15 @@ public void NotifyCatalogChange_CreatedToNonEmptyListDifferentFolder_KeepExistin Asset[] assets = [ - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage(), Folder = folder } + new() { FileName = "Image 1.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 2.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 3.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 4.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 5.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder } ]; Folder newFolder = new() { Path = @"D:\NewFolder" }; - Asset newAsset = new() { FileName = "NewImage.jpg", ImageData = new BitmapImage(), Folder = newFolder }; + Asset newAsset = new() { FileName = "NewImage.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = newFolder }; _applicationViewModel!.SetAssets(assets); @@ -368,18 +368,18 @@ public void NotifyCatalogChange_NullFolder_IgnoreNewAsset(bool analyseVideos) Asset[] assets = [ - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage(), Folder = folder } + new() { FileName = "Image 1.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 2.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 3.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 4.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 5.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder } ]; - Asset newAsset = new() { FileName = "NewImage.jpg", ImageData = new BitmapImage(), Folder = null }; + Asset newAsset = new() { Folder = new() { Path = "" }, FileName = "NewImage.jpg", Hash = string.Empty, ImageData = new BitmapImage() }; _applicationViewModel!.SetAssets(assets); - _applicationViewModel!.NotifyCatalogChange(null); + _applicationViewModel!.NotifyCatalogChange(null!); _applicationViewModel!.NotifyCatalogChange(new CatalogChangeCallbackEventArgs { @@ -433,23 +433,24 @@ public void NotifyCatalogChange_InvalidParameters_IgnoreAsset(string fileName, b Asset[] assets = [ - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage(), Folder = folder } + new() { FileName = "Image 1.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 2.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 3.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 4.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 5.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder } ]; Asset newAsset = new() { FileName = fileName, + Hash = string.Empty, ImageData = new BitmapImage(), Folder = new Folder { FolderId = folderId, Path = folderPath } }; _applicationViewModel!.SetAssets(assets); - _applicationViewModel!.NotifyCatalogChange(null); + _applicationViewModel!.NotifyCatalogChange(null!); _applicationViewModel!.NotifyCatalogChange(new CatalogChangeCallbackEventArgs { @@ -492,11 +493,11 @@ public void NotifyCatalogChange_DeletedInFromCurrentFolder_RemoveFromAssetList(b Asset[] assets = [ - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage(), Folder = folder } + new() { FileName = "Image 1.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 2.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 3.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 4.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 5.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder } ]; const string statusMessage = "Removing thumbnail for Image 3.jpg"; @@ -543,11 +544,11 @@ public void GoToPreviousAsset_ChangeViewerPosition(int currentPosition, int expe { Asset[] assets = [ - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage() } + new() { Folder = new() { Path = "" }, FileName = "Image 1.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 2.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 3.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 4.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 5.jpg", Hash = string.Empty, ImageData = new BitmapImage() } ]; _applicationViewModel!.SetAssets(assets); @@ -583,11 +584,11 @@ public void CanGoToPreviousAsset(int currentPosition, bool expectedCanGoToPrevio { Asset[] assets = [ - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage() } + new() { Folder = new() { Path = "" }, FileName = "Image 1.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 2.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 3.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 4.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 5.jpg", Hash = string.Empty, ImageData = new BitmapImage() } ]; _applicationViewModel!.SetAssets(assets); @@ -621,11 +622,11 @@ public void CanGoToNextAsset(int currentPosition, bool expectedCanGoToNextAsset, { Asset[] assets = [ - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage() } + new() { Folder = new() { Path = "" }, FileName = "Image 1.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 2.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 3.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 4.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 5.jpg", Hash = string.Empty, ImageData = new BitmapImage() } ]; _applicationViewModel!.SetAssets(assets); @@ -659,11 +660,11 @@ public void GoToNextAsset_ChangeViewerPosition(int currentPosition, int expected { Asset[] assets = [ - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage() } + new() { Folder = new() { Path = "" }, FileName = "Image 1.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 2.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 3.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 4.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 5.jpg", Hash = string.Empty, ImageData = new BitmapImage() } ]; _applicationViewModel!.SetAssets(assets); @@ -742,11 +743,11 @@ public void GoToAsset_ChangeViewerPosition(int currentPosition, int goToAssetInd Asset[] assets = [ - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage(), Folder = folder } + new() { FileName = "Image 1.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 2.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 3.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 4.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 5.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder } ]; _applicationViewModel!.SetAssets(assets); @@ -776,14 +777,14 @@ public void GoToAsset_NotInList_KeepPosition(bool analyseVideos) Asset[] assets = [ - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage(), Folder = folder }, - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage(), Folder = folder } + new() { FileName = "Image 1.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 2.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 3.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 4.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }, + new() { FileName = "Image 5.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder } ]; - Asset assetNotInList = new() { FileName = "ImageNotInList.jpg", ImageData = new BitmapImage(), Folder = folder }; + Asset assetNotInList = new() { FileName = "ImageNotInList.jpg", Hash = string.Empty, ImageData = new BitmapImage(), Folder = folder }; _applicationViewModel!.SetAssets(assets); _applicationViewModel!.ViewerPosition = 4; @@ -820,11 +821,11 @@ public void RemoveAsset_AssetRemovedIsCurrent_RemoveFromAssetList(int index, int { Asset[] assets = [ - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage() } + new() { Folder = new() { Path = "" }, FileName = "Image 1.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 2.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 3.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 4.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 5.jpg", Hash = string.Empty, ImageData = new BitmapImage() } ]; _applicationViewModel!.SetAssets(assets); @@ -853,7 +854,7 @@ public void RemoveAsset_SoleElement_ListBeEmptyAndPositionBeforeFirstItem(bool a { Asset[] assets = [ - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage() } + new() { Folder = new() { Path = "" }, FileName = "Image 1.jpg", Hash = string.Empty, ImageData = new BitmapImage() } ]; _applicationViewModel!.SetAssets(assets); @@ -885,7 +886,7 @@ public void RemoveAsset_NullAssetFromEmptyAssetList_EmptyAssetList(bool analyseV _applicationViewModel!.SetAssets(assets); _applicationViewModel!.ViewerPosition = -1; - _applicationViewModel!.RemoveAssets(null); + _applicationViewModel!.RemoveAssets(null!); Assert.AreEqual(-1, _applicationViewModel!.ViewerPosition); Assert.IsEmpty(_applicationViewModel!.ObservableAssets); @@ -906,10 +907,10 @@ public void RemoveAsset_NullAssetFromNullAssetList_NullAssetList(bool analyseVid try { - _applicationViewModel!.SetAssets(null); + _applicationViewModel!.SetAssets(null!); _applicationViewModel!.ViewerPosition = -1; - _applicationViewModel!.RemoveAssets(null); + _applicationViewModel!.RemoveAssets(null!); Assert.AreEqual(-1, _applicationViewModel!.ViewerPosition); Assert.IsEmpty(_applicationViewModel!.ObservableAssets); @@ -938,11 +939,11 @@ public void AppTitle_AppMode_ApplyAppTitleFormat(AppMode appMode, bool analyseVi Asset[] assets = [ - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage() } + new() { Folder = new() { Path = "" }, FileName = "Image 1.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 2.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 3.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 4.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 5.jpg", Hash = string.Empty, ImageData = new BitmapImage() } ]; _applicationViewModel!.Product = "PhotoManager"; @@ -969,7 +970,7 @@ public void SortAssetsByCriteria_NullAssetList_AssetListIsNull(bool analyseVideo try { - Asset[] assets = null; + Asset[] assets = null!; _applicationViewModel!.SetAssets(assets); _applicationViewModel!.SortAssetsByCriteria(SortCriteria.FileName); @@ -1027,9 +1028,11 @@ public void SortAssetsByCriteria_SingleItemAssetList_AssetListHasSameSingleItem( { Asset[] assets = [ - new Asset + new() { + Folder = new() { Path = "" }, FileName = "Image 1.jpg", + Hash = string.Empty, ImageData = new BitmapImage(), FileSize = 2048, FileCreationDateTime = DateTime.Now, @@ -1062,11 +1065,11 @@ public void SortAssetsByCriteria_ByFileNameMultipleAssetsList_AssetListSortedByF { Asset[] assets = [ - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage() } + new() { Folder = new() { Path = "" }, FileName = "Image 5.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 2.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 1.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 3.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 4.jpg", Hash = string.Empty, ImageData = new BitmapImage() } ]; _applicationViewModel!.SortAssetsByCriteria(SortCriteria.Undefined); @@ -1099,11 +1102,11 @@ public void SortAssetsByCriteria_ByFileNameMultipleAssetsListMultipleTimes_Asset { Asset[] assets = [ - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage() }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage() } + new() { Folder = new() { Path = "" }, FileName = "Image 5.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 2.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 1.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 3.jpg", Hash = string.Empty, ImageData = new BitmapImage() }, + new() { Folder = new() { Path = "" }, FileName = "Image 4.jpg", Hash = string.Empty, ImageData = new BitmapImage() } ]; _applicationViewModel!.SortAssetsByCriteria(SortCriteria.Undefined); @@ -1153,11 +1156,46 @@ public void SortAssetsByCriteria_ByThumbnailCreationDateTimeMultipleAssetsList_A { Asset[] assets = [ - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage(), ThumbnailCreationDateTime = new DateTime(2020, 6, 1) }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage(), ThumbnailCreationDateTime = new DateTime(2020, 6, 1) }, - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage(), ThumbnailCreationDateTime = new DateTime(2010, 2, 1) }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage(), ThumbnailCreationDateTime = new DateTime(2010, 1, 1) }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage(), ThumbnailCreationDateTime = new DateTime(2010, 8, 1) } + new() + { + Folder = new() { Path = "" }, + FileName = "Image 5.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + ThumbnailCreationDateTime = new DateTime(2020, 6, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 2.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + ThumbnailCreationDateTime = new DateTime(2020, 6, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 1.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + ThumbnailCreationDateTime = new DateTime(2010, 2, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 3.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + ThumbnailCreationDateTime = new DateTime(2010, 1, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 4.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + ThumbnailCreationDateTime = new DateTime(2010, 8, 1) + } ]; _applicationViewModel!.SetAssets(assets); @@ -1188,11 +1226,46 @@ public void SortAssetsByCriteria_ByThumbnailCreationDateTimeMultipleAssetsListMu { Asset[] assets = [ - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage(), ThumbnailCreationDateTime = new DateTime(2020, 6, 1) }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage(), ThumbnailCreationDateTime = new DateTime(2020, 6, 1) }, - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage(), ThumbnailCreationDateTime = new DateTime(2010, 2, 1) }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage(), ThumbnailCreationDateTime = new DateTime(2010, 1, 1) }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage(), ThumbnailCreationDateTime = new DateTime(2010, 8, 1) } + new() + { + Folder = new() { Path = "" }, + FileName = "Image 5.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + ThumbnailCreationDateTime = new DateTime(2020, 6, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 2.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + ThumbnailCreationDateTime = new DateTime(2020, 6, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 1.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + ThumbnailCreationDateTime = new DateTime(2010, 2, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 3.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + ThumbnailCreationDateTime = new DateTime(2010, 1, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 4.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + ThumbnailCreationDateTime = new DateTime(2010, 8, 1) + } ]; _applicationViewModel!.SetAssets(assets); @@ -1241,11 +1314,46 @@ public void SortAssetsByCriteria_ByFileCreationDateTimeMultipleAssetsList_AssetL { Asset[] assets = [ - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage(), FileCreationDateTime = new DateTime(2020, 6, 1) }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage(), FileCreationDateTime = new DateTime(2020, 6, 1) }, - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage(), FileCreationDateTime = new DateTime(2010, 2, 1) }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage(), FileCreationDateTime = new DateTime(2010, 1, 1) }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage(), FileCreationDateTime = new DateTime(2010, 8, 1) } + new() + { + Folder = new() { Path = "" }, + FileName = "Image 5.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileCreationDateTime = new DateTime(2020, 6, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 2.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileCreationDateTime = new DateTime(2020, 6, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 1.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileCreationDateTime = new DateTime(2010, 2, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 3.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileCreationDateTime = new DateTime(2010, 1, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 4.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileCreationDateTime = new DateTime(2010, 8, 1) + } ]; _applicationViewModel!.SetAssets(assets); @@ -1276,11 +1384,46 @@ public void SortAssetsByCriteria_ByFileCreationDateTimeMultipleAssetsListMultipl { Asset[] assets = [ - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage(), FileCreationDateTime = new DateTime(2020, 6, 1) }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage(), FileCreationDateTime = new DateTime(2020, 6, 1) }, - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage(), FileCreationDateTime = new DateTime(2010, 2, 1) }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage(), FileCreationDateTime = new DateTime(2010, 1, 1) }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage(), FileCreationDateTime = new DateTime(2010, 8, 1) } + new() + { + Folder = new() { Path = "" }, + FileName = "Image 5.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileCreationDateTime = new DateTime(2020, 6, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 2.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileCreationDateTime = new DateTime(2020, 6, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 1.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileCreationDateTime = new DateTime(2010, 2, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 3.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileCreationDateTime = new DateTime(2010, 1, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 4.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileCreationDateTime = new DateTime(2010, 8, 1) + } ]; _applicationViewModel!.SetAssets(assets); @@ -1329,11 +1472,46 @@ public void SortByFileModificationDateTimeMultipleFilesOneTimeTest(bool analyseV { Asset[] assets = [ - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage(), FileModificationDateTime = new DateTime(2020, 6, 1) }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage(), FileModificationDateTime = new DateTime(2020, 6, 1) }, - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage(), FileModificationDateTime = new DateTime(2010, 2, 1) }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage(), FileModificationDateTime = new DateTime(2010, 1, 1) }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage(), FileModificationDateTime = new DateTime(2010, 8, 1) } + new() + { + Folder = new() { Path = "" }, + FileName = "Image 5.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileModificationDateTime = new DateTime(2020, 6, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 2.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileModificationDateTime = new DateTime(2020, 6, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 1.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileModificationDateTime = new DateTime(2010, 2, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 3.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileModificationDateTime = new DateTime(2010, 1, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 4.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileModificationDateTime = new DateTime(2010, 8, 1) + } ]; _applicationViewModel!.SetAssets(assets); @@ -1364,11 +1542,46 @@ public void SortByFileModificationDateTimeMultipleFilesMultipleTimesTest(bool an { Asset[] assets = [ - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage(), FileModificationDateTime = new DateTime(2020, 6, 1) }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage(), FileModificationDateTime = new DateTime(2020, 6, 1) }, - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage(), FileModificationDateTime = new DateTime(2010, 2, 1) }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage(), FileModificationDateTime = new DateTime(2010, 1, 1) }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage(), FileModificationDateTime = new DateTime(2010, 8, 1) } + new() + { + Folder = new() { Path = "" }, + FileName = "Image 5.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileModificationDateTime = new DateTime(2020, 6, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 2.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileModificationDateTime = new DateTime(2020, 6, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 1.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileModificationDateTime = new DateTime(2010, 2, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 3.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileModificationDateTime = new DateTime(2010, 1, 1) + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 4.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileModificationDateTime = new DateTime(2010, 8, 1) + } ]; _applicationViewModel!.SetAssets(assets); @@ -1415,11 +1628,46 @@ public void SortByFileSizeMultipleFilesOneTimeTest(bool analyseVideos) { Asset[] assets = [ - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage(), FileSize = 2048 }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage(), FileSize = 2048 }, - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage(), FileSize = 2020 }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage(), FileSize = 2000 }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage(), FileSize = 2030 } + new() + { + Folder = new() { Path = "" }, + FileName = "Image 5.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileSize = 2048 + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 2.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileSize = 2048 + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 1.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileSize = 2020 + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 3.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileSize = 2000 + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 4.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileSize = 2030 + } ]; _applicationViewModel!.SetAssets(assets); @@ -1450,11 +1698,46 @@ public void SortByFileSizeMultipleFilesMultipleTimesTest(bool analyseVideos) { Asset[] assets = [ - new Asset { FileName = "Image 5.jpg", ImageData = new BitmapImage(), FileSize = 2048 }, - new Asset { FileName = "Image 2.jpg", ImageData = new BitmapImage(), FileSize = 2048 }, - new Asset { FileName = "Image 1.jpg", ImageData = new BitmapImage(), FileSize = 2020 }, - new Asset { FileName = "Image 3.jpg", ImageData = new BitmapImage(), FileSize = 2000 }, - new Asset { FileName = "Image 4.jpg", ImageData = new BitmapImage(), FileSize = 2030 } + new() + { + Folder = new() { Path = "" }, + FileName = "Image 5.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileSize = 2048 + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 2.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileSize = 2048 + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 1.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileSize = 2020 + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 3.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileSize = 2000 + }, + new() + { + Folder = new() { Path = "" }, + FileName = "Image 4.jpg", + Hash = string.Empty, + ImageData = new BitmapImage(), + FileSize = 2030 + } ]; _applicationViewModel!.SetAssets(assets); From c4c97cbea922f9f1aaf5f3f645382756c35b3379 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Berthier Date: Wed, 20 Nov 2024 21:12:03 +0100 Subject: [PATCH 12/17] Remove TODO done --- .../Integration/Domain/MoveAssetsServiceTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/PhotoManager/PhotoManager.Tests/Integration/Domain/MoveAssetsServiceTests.cs b/PhotoManager/PhotoManager.Tests/Integration/Domain/MoveAssetsServiceTests.cs index b2db508d..8be76ade 100644 --- a/PhotoManager/PhotoManager.Tests/Integration/Domain/MoveAssetsServiceTests.cs +++ b/PhotoManager/PhotoManager.Tests/Integration/Domain/MoveAssetsServiceTests.cs @@ -776,7 +776,6 @@ public void MoveAssets_AssetIsInTheDestinationButNotInTheSourceAndPreserveOrigin Assert.IsTrue(assetsInDb.Any(x => x.FileName == asset1.FileName && x.FolderId == sourceFolder.FolderId)); Assert.IsTrue(assetsInDb.Any(x => x.FileName == asset2.FileName && x.FolderId == destinationFolder.FolderId)); - // TODO: Is it good now ? cataloguedAssetsInSource = _assetRepository!.GetCataloguedAssetsByPath(sourceFolder.Path); Assert.IsNotEmpty(cataloguedAssetsInSource); Assert.AreEqual(1, cataloguedAssetsInSource.Count); From f031caf9b128122c2277aa0904bb9a7f2e24efe9 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Berthier Date: Thu, 21 Nov 2024 10:06:23 +0100 Subject: [PATCH 13/17] Fallback to v4 --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 910015e4..cceb92fb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -79,7 +79,7 @@ jobs: # Step 12: Upload coverage report to Codecov - name: ☁️ Upload coverage reports to Codecov - uses: codecov/codecov-action@v5 + uses: codecov/codecov-action@v4 with: files: ${{ env.PROJECT_TESTRESULTS_PATH }}/*/coverage.cobertura.xml name: codecov-windows-latest From 6a352fa4b343c40b0d9202a71cb50fba83d24bad Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Berthier Date: Thu, 21 Nov 2024 10:31:38 +0100 Subject: [PATCH 14/17] Try with full version in V4 --- codecov.yml | 54 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/codecov.yml b/codecov.yml index 1431f246..c2d756ab 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,5 +1,13 @@ codecov: - require_ci_to_pass: yes + require_ci_to_pass: yes + max_report_age: off + max_path_depth: 500 + +comment: + layout: "reach,diff,flags,files" + behavior: default + require_changes: false + require_base: false coverage: precision: 2 @@ -8,13 +16,39 @@ coverage: parsers: gcov: - branch_detection: - conditional: yes - loop: yes - method: no - macro: no + branch_detection: + conditional: yes + loop: yes + method: yes + macro: no -comment: - layout: "header,diff" - behavior: default - require_changes: false \ No newline at end of file +notifications: + commit: + status: + default: + target: "https://docs.codecov.io/docs/commit-status" + threshold: 1% + paths: [] + informational: false + + +comment_template: | + :rocket: **Code Coverage Report** for `{{ commit }}` + - **Coverage**: {{ diff_coverage }}% ({{ coverage_change }}% change) + - **Files**: {{ total_files }} with modifications + - **Hits**: {{ hits }} / {{ lines }} lines + {{#flags}} + {{#name}} + - Flag **{{ name }}**: {{ coverage }}% + {{/name}} + {{/flags}} + {{#reach}} + - **Reach**: Improved {{ diff_coverage }}% compared to base. + {{/reach}} + [View Full Report](https://codecov.io/{{ slug }}/commit/{{ commit }}) + {{#threshold_exceeded}} + :warning: The threshold of {{ threshold }}% was exceeded by {{ diff }}%. + {{/threshold_exceeded}} + {{#is_new}} + :green_circle: This is a **newly added test**. + {{/is_new}} \ No newline at end of file From e48390d62e426604a1e62328e63b5026858e4c3d Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Berthier Date: Thu, 21 Nov 2024 11:04:37 +0100 Subject: [PATCH 15/17] Improve config --- codecov.yml | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/codecov.yml b/codecov.yml index c2d756ab..36c48b42 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,13 +1,11 @@ codecov: require_ci_to_pass: yes max_report_age: off - max_path_depth: 500 comment: - layout: "reach,diff,flags,files" + layout: "condensed_header, condensed_files, condensed_footer" behavior: default require_changes: false - require_base: false coverage: precision: 2 @@ -21,34 +19,3 @@ parsers: loop: yes method: yes macro: no - -notifications: - commit: - status: - default: - target: "https://docs.codecov.io/docs/commit-status" - threshold: 1% - paths: [] - informational: false - - -comment_template: | - :rocket: **Code Coverage Report** for `{{ commit }}` - - **Coverage**: {{ diff_coverage }}% ({{ coverage_change }}% change) - - **Files**: {{ total_files }} with modifications - - **Hits**: {{ hits }} / {{ lines }} lines - {{#flags}} - {{#name}} - - Flag **{{ name }}**: {{ coverage }}% - {{/name}} - {{/flags}} - {{#reach}} - - **Reach**: Improved {{ diff_coverage }}% compared to base. - {{/reach}} - [View Full Report](https://codecov.io/{{ slug }}/commit/{{ commit }}) - {{#threshold_exceeded}} - :warning: The threshold of {{ threshold }}% was exceeded by {{ diff }}%. - {{/threshold_exceeded}} - {{#is_new}} - :green_circle: This is a **newly added test**. - {{/is_new}} \ No newline at end of file From bf82da50bfc15e8405562438a519e5e00de85e5f Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Berthier Date: Thu, 21 Nov 2024 11:23:49 +0100 Subject: [PATCH 16/17] Improve layout --- codecov.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codecov.yml b/codecov.yml index 36c48b42..1ba0baf1 100644 --- a/codecov.yml +++ b/codecov.yml @@ -3,7 +3,7 @@ codecov: max_report_age: off comment: - layout: "condensed_header, condensed_files, condensed_footer" + layout: "header, diff, flags, components, files, footer" behavior: default require_changes: false From 822e341a00134703813016eb3a20ba8249b8c3d0 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Berthier Date: Thu, 21 Nov 2024 16:58:20 +0100 Subject: [PATCH 17/17] Add components configuration --- codecov.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/codecov.yml b/codecov.yml index 1ba0baf1..ba35ff45 100644 --- a/codecov.yml +++ b/codecov.yml @@ -19,3 +19,30 @@ parsers: loop: yes method: yes macro: no + +component_management: + default_rules: + statuses: + - type: project + target: auto + individual_components: + - component_id: module_ui + name: UI + paths: + - PhotoManager/PhotoManager.UI/** + - component_id: module_application + name: Application + paths: + - PhotoManager/PhotoManager.Application/** + - component_id: module_domain + name: Domain + paths: + - PhotoManager/PhotoManager.Domain/** + - component_id: module_infrastructure + name: Infrastructure + paths: + - PhotoManager/PhotoManager.Infrastructure/** + - component_id: module_common + name: Common + paths: + - PhotoManager/PhotoManager.Common/**