From c70bc36752e0e31503594f4f5e41028811a9fafb Mon Sep 17 00:00:00 2001 From: jbe2277 Date: Sat, 25 Nov 2023 13:45:31 +0100 Subject: [PATCH] Simplify test code by using new C# features --- .../ApplicationsTest.cs | 4 +-- .../Controllers/ManagerControllerTest.cs | 2 +- .../MusicPropertiesControllerTest.cs | 7 ++-- .../Controllers/PlayerControllerTest.cs | 11 +++---- .../Controllers/PlaylistControllerTest.cs | 11 +++---- .../Controllers/TranscodingControllerTest.cs | 5 ++- .../DataModels/FolderItemTest.cs | 2 +- .../DataModels/MusicFileDataModelTest.cs | 6 ++-- .../Services/MockEnvironmentService.cs | 7 +--- .../Services/MockFileService.cs | 5 ++- .../Services/MusicTitleHelperTest.cs | 10 +++--- .../MusicPropertiesViewModelTest.cs | 2 +- .../Views/MockPlayerView.cs | 7 +--- .../ViewModels/MusicPropertiesViewModel.cs | 2 +- .../MusicFiles/MockMusicFile.cs | 2 +- .../Playlists/PlaylistManagerTest.cs | 32 +++++++++---------- .../Playlists/StatisticsHelperTest.cs | 4 +-- .../Transcoding/TranscodeItemTest.cs | 4 +-- .../Transcoding/TranscodingManagerTest.cs | 6 ++-- .../PlaylistControllerIntegrationTest.cs | 2 +- ...IsPlaylistItemPlayingMultiConverterTest.cs | 4 +-- .../MusicPropertiesEnabledConverterTest.cs | 4 +-- ...opertiesProgressVisibilityConverterTest.cs | 6 ++-- .../Converters/MusicTitleConverterTest.cs | 12 +++---- .../StringListToStringConverterTest.cs | 20 ++++++------ .../Converters/TotalDurationConverterTest.cs | 4 +-- .../Converters/WindowTitleConverterTest.cs | 6 ++-- .../PresentationTest.cs | 5 ++- .../Services/FileServiceTest.cs | 8 ++--- .../Services/SequenceEqualityComparerTest.cs | 4 +-- .../Services/StringListConverterTest.cs | 30 ++++++++--------- .../TestHelper.cs | 2 +- .../Services/Metadata/SaveMetadata.cs | 24 +++++++------- 33 files changed, 121 insertions(+), 139 deletions(-) diff --git a/src/MusicManager/MusicManager.Applications.Test/ApplicationsTest.cs b/src/MusicManager/MusicManager.Applications.Test/ApplicationsTest.cs index 9b168dc..a882ef8 100644 --- a/src/MusicManager/MusicManager.Applications.Test/ApplicationsTest.cs +++ b/src/MusicManager/MusicManager.Applications.Test/ApplicationsTest.cs @@ -26,10 +26,10 @@ protected override void OnInitialize() Context = UnitTestSynchronizationContext.Create(); - catalog = new AggregateCatalog(); + catalog = new(); OnCatalogInitialize(catalog); - Container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection); + Container = new(catalog, CompositionOptions.DisableSilentRejection); var batch = new CompositionBatch(); batch.AddExportedValue(Container); Container.Compose(batch); diff --git a/src/MusicManager/MusicManager.Applications.Test/Controllers/ManagerControllerTest.cs b/src/MusicManager/MusicManager.Applications.Test/Controllers/ManagerControllerTest.cs index 8d89d1f..a9a6683 100644 --- a/src/MusicManager/MusicManager.Applications.Test/Controllers/ManagerControllerTest.cs +++ b/src/MusicManager/MusicManager.Applications.Test/Controllers/ManagerControllerTest.cs @@ -43,7 +43,7 @@ public void FileSystemWatcherService() { var path = @"C:\Music"; var fileService = Container.GetExportedValue(); - fileService.GetFilesStub = (dir, deep, f1, f2, c) => Task.FromResult((IReadOnlyList)new[] { Path.Combine(path, "TestMP3.mp3"), Path.Combine(path, "Test42.mp3") }); + fileService.GetFilesStub = (dir, deep, f1, f2, c) => Task.FromResult>([ Path.Combine(path, "TestMP3.mp3"), Path.Combine(path, "Test42.mp3") ]); var fileSystemWatcherService = Container.GetExportedValue(); viewModel.FolderBrowser.CurrentPath = path; diff --git a/src/MusicManager/MusicManager.Applications.Test/Controllers/MusicPropertiesControllerTest.cs b/src/MusicManager/MusicManager.Applications.Test/Controllers/MusicPropertiesControllerTest.cs index 5a3ab6b..e5c61d7 100644 --- a/src/MusicManager/MusicManager.Applications.Test/Controllers/MusicPropertiesControllerTest.cs +++ b/src/MusicManager/MusicManager.Applications.Test/Controllers/MusicPropertiesControllerTest.cs @@ -27,15 +27,14 @@ protected override void OnInitialize() base.OnInitialize(); musicFileContext = Container.GetExportedValue(); - musicFiles = new ObservableCollection() - { + musicFiles = [ musicFileContext.Create(@"C:\Users\Public\Music\Dancefloor\Culture Beat - Serenity.wav"), musicFileContext.Create(@"C:\Culture Beat - Serenity - Epilog.wma"), - }; + ]; selectionService = Container.GetExportedValue(); selectionService.Initialize(musicFiles); - playlistManager = new PlaylistManager(); + playlistManager = new(); controller = Container.GetExportedValue(); controller.PlaylistManager = playlistManager; controller.Initialize(); diff --git a/src/MusicManager/MusicManager.Applications.Test/Controllers/PlayerControllerTest.cs b/src/MusicManager/MusicManager.Applications.Test/Controllers/PlayerControllerTest.cs index 2ec532a..117d761 100644 --- a/src/MusicManager/MusicManager.Applications.Test/Controllers/PlayerControllerTest.cs +++ b/src/MusicManager/MusicManager.Applications.Test/Controllers/PlayerControllerTest.cs @@ -30,16 +30,15 @@ protected override void OnInitialize() base.OnInitialize(); var musicFileContext = Container.GetExportedValue(); - musicFiles = new ObservableCollection() - { + musicFiles = [ musicFileContext.Create(@"C:\Users\Public\Music\Dancefloor\Culture Beat - Serenity.wav"), musicFileContext.Create(@"C:\Culture Beat - Serenity - Epilog.wma"), - }; + ]; selectionService = Container.GetExportedValue(); selectionService.Initialize(musicFiles); - playlistManager = new PlaylistManager(); - playlistSettings = new PlaylistSettings(); + playlistManager = new(); + playlistSettings = new(); controller = Container.GetExportedValue(); controller.PlaylistSettings = playlistSettings; controller.PlaylistManager = playlistManager; @@ -106,7 +105,7 @@ public void PlayAllAndSelected() Assert.IsTrue(viewModel.PlayerService.PlaySelectedCommand.CanExecute(null)); // Insert a dummy playlist item which will be replaced by Play - playlistManager.AddAndReplaceItems(new[] { new PlaylistItem(MockMusicFile.CreateEmpty("empty.mp3")) }); + playlistManager.AddAndReplaceItems([new PlaylistItem(MockMusicFile.CreateEmpty("empty.mp3")) ]); Assert.AreEqual(1, playlistManager.Items.Count); // Play all diff --git a/src/MusicManager/MusicManager.Applications.Test/Controllers/PlaylistControllerTest.cs b/src/MusicManager/MusicManager.Applications.Test/Controllers/PlaylistControllerTest.cs index cc393d5..28c5591 100644 --- a/src/MusicManager/MusicManager.Applications.Test/Controllers/PlaylistControllerTest.cs +++ b/src/MusicManager/MusicManager.Applications.Test/Controllers/PlaylistControllerTest.cs @@ -27,17 +27,16 @@ protected override void OnInitialize() base.OnInitialize(); musicFileContext = Container.GetExportedValue(); - musicFiles = new ObservableCollection() - { + musicFiles = [ musicFileContext.Create(@"C:\Users\Public\Music\Dancefloor\Culture Beat - Serenity.wav"), musicFileContext.Create(@"C:\Culture Beat - Serenity - Epilog.wma"), - }; + ]; selectionService = Container.GetExportedValue(); selectionService.Initialize(musicFiles); - playlistManager = new PlaylistManager(); + playlistManager = new(); controller = Container.GetExportedValue(); - controller.PlaylistSettings = new PlaylistSettings(); + controller.PlaylistSettings = new(); controller.PlaylistManager = playlistManager; controller.Initialize(); controller.Run(); @@ -133,7 +132,7 @@ public void ShowMusicPropertiesTest() private static void SetSelection(PlaylistViewModel viewModel, params PlaylistItem[] items) { - viewModel.SelectedPlaylistItem = items.Last(); + viewModel.SelectedPlaylistItem = items[^1]; viewModel.SelectedPlaylistItems.Clear(); foreach (var x in items) viewModel.SelectedPlaylistItems.Add(x); } diff --git a/src/MusicManager/MusicManager.Applications.Test/Controllers/TranscodingControllerTest.cs b/src/MusicManager/MusicManager.Applications.Test/Controllers/TranscodingControllerTest.cs index 863086f..0382c3a 100644 --- a/src/MusicManager/MusicManager.Applications.Test/Controllers/TranscodingControllerTest.cs +++ b/src/MusicManager/MusicManager.Applications.Test/Controllers/TranscodingControllerTest.cs @@ -21,11 +21,10 @@ protected override void OnInitialize() base.OnInitialize(); musicFileContext = Container.GetExportedValue(); - musicFiles = new ObservableCollection() - { + musicFiles = [ musicFileContext.Create(@"C:\Users\Public\Music\Dancefloor\Culture Beat - Serenity.wav"), musicFileContext.Create(@"C:\Culture Beat - Serenity - Epilog.wma"), - }; + ]; selectionService = Container.GetExportedValue(); selectionService.Initialize(musicFiles); diff --git a/src/MusicManager/MusicManager.Applications.Test/DataModels/FolderItemTest.cs b/src/MusicManager/MusicManager.Applications.Test/DataModels/FolderItemTest.cs index cb015b4..a77567c 100644 --- a/src/MusicManager/MusicManager.Applications.Test/DataModels/FolderItemTest.cs +++ b/src/MusicManager/MusicManager.Applications.Test/DataModels/FolderItemTest.cs @@ -1,5 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using Waf.MusicManager.Applications.DataModels; +using Waf.MusicManager.Applications.Services; namespace Test.MusicManager.Applications.DataModels; diff --git a/src/MusicManager/MusicManager.Applications.Test/DataModels/MusicFileDataModelTest.cs b/src/MusicManager/MusicManager.Applications.Test/DataModels/MusicFileDataModelTest.cs index 8dc3056..7194f6f 100644 --- a/src/MusicManager/MusicManager.Applications.Test/DataModels/MusicFileDataModelTest.cs +++ b/src/MusicManager/MusicManager.Applications.Test/DataModels/MusicFileDataModelTest.cs @@ -17,17 +17,17 @@ public void RaisePropertyChangedTest() var musicFile = new MockMusicFile(new MusicMetadata(new TimeSpan(0, 3, 33), 320) { - Artists = Array.Empty(), + Artists = [], Title = "" }, @"C:\Users\Public\Music\Dancefloor\Culture Beat - Serenity.mp3"); var dataModel = new MusicFileDataModel(musicFile); Assert.AreEqual("", dataModel.ArtistsString); - AssertHelper.PropertyChangedEvent(dataModel, x => x.ArtistsString, () => musicFile.Metadata!.Artists = new[] { "Culture Beat" }); + AssertHelper.PropertyChangedEvent(dataModel, x => x.ArtistsString, () => musicFile.Metadata!.Artists = [ "Culture Beat" ]); Assert.AreEqual("Culture Beat", dataModel.ArtistsString); - AssertHelper.PropertyChangedEvent(dataModel, x => x.ArtistsString, () => musicFile.Metadata!.Artists = new[] { "Culture Beat", "Second artist" }); + AssertHelper.PropertyChangedEvent(dataModel, x => x.ArtistsString, () => musicFile.Metadata!.Artists = [ "Culture Beat", "Second artist" ]); Assert.AreEqual("Culture Beat" + ls + " Second artist", dataModel.ArtistsString); } } diff --git a/src/MusicManager/MusicManager.Applications.Test/Services/MockEnvironmentService.cs b/src/MusicManager/MusicManager.Applications.Test/Services/MockEnvironmentService.cs index c58d862..f54e7ca 100644 --- a/src/MusicManager/MusicManager.Applications.Test/Services/MockEnvironmentService.cs +++ b/src/MusicManager/MusicManager.Applications.Test/Services/MockEnvironmentService.cs @@ -6,12 +6,7 @@ namespace Test.MusicManager.Applications.Services; [Export, Export(typeof(IEnvironmentService))] public class MockEnvironmentService : IEnvironmentService { - public MockEnvironmentService() - { - MusicFilesToLoad = Array.Empty(); - } - - public IReadOnlyList MusicFilesToLoad { get; set; } + public IReadOnlyList MusicFilesToLoad { get; set; } = []; public string MusicPath { get; set; } = ""; diff --git a/src/MusicManager/MusicManager.Applications.Test/Services/MockFileService.cs b/src/MusicManager/MusicManager.Applications.Test/Services/MockFileService.cs index 407d1c2..63bf825 100644 --- a/src/MusicManager/MusicManager.Applications.Test/Services/MockFileService.cs +++ b/src/MusicManager/MusicManager.Applications.Test/Services/MockFileService.cs @@ -1,5 +1,4 @@ using System.ComponentModel.Composition; -using Waf.MusicManager.Applications.DataModels; using Waf.MusicManager.Applications.Services; namespace Test.MusicManager.Applications.Services @@ -15,13 +14,13 @@ public class MockFileService : IFileService public Func>>? GetFilesStub { get; set; } public Task> GetFiles(string directory, bool deep, string userSearchFilter, string applicationSearchFilter, CancellationToken cancellation) - => GetFilesStub?.Invoke(directory, deep, userSearchFilter, applicationSearchFilter, cancellation) ?? Task.FromResult((IReadOnlyList)Array.Empty()); + => GetFilesStub?.Invoke(directory, deep, userSearchFilter, applicationSearchFilter, cancellation) ?? Task.FromResult>([]); public Task GetFolderFromPath(string path) => Task.FromResult(new FolderItem(path, path)); public Task GetParentPath(string path) => throw new NotImplementedException(); - public Task> GetSubFoldersFromPath(string path) => Task.FromResult((IReadOnlyList)Array.Empty()); + public Task> GetSubFoldersFromPath(string path) => Task.FromResult>([]); public bool IsFileSupported(string fileName) => true; diff --git a/src/MusicManager/MusicManager.Applications.Test/Services/MusicTitleHelperTest.cs b/src/MusicManager/MusicManager.Applications.Test/Services/MusicTitleHelperTest.cs index 60234c6..f9ce1d3 100644 --- a/src/MusicManager/MusicManager.Applications.Test/Services/MusicTitleHelperTest.cs +++ b/src/MusicManager/MusicManager.Applications.Test/Services/MusicTitleHelperTest.cs @@ -11,12 +11,12 @@ public void GetTitleTextTest() { var fileName = @"C:\Users\Public\Music\Dancefloor\Culture Beat - Serenity.mp3"; - Assert.AreEqual("Culture Beat - Serenity", MusicTitleHelper.GetTitleText(fileName, Array.Empty(), null)); - Assert.AreEqual("Culture Beat - Serenity", MusicTitleHelper.GetTitleText(fileName, Array.Empty(), "")); + Assert.AreEqual("Culture Beat - Serenity", MusicTitleHelper.GetTitleText(fileName, [], null)); + Assert.AreEqual("Culture Beat - Serenity", MusicTitleHelper.GetTitleText(fileName, [], "")); - Assert.AreEqual("", MusicTitleHelper.GetTitleText(fileName, new[] { "Culture Beat" }, null)); - Assert.AreEqual("", MusicTitleHelper.GetTitleText(fileName, new[] { "Culture Beat" }, "")); + Assert.AreEqual("", MusicTitleHelper.GetTitleText(fileName, [ "Culture Beat" ], null)); + Assert.AreEqual("", MusicTitleHelper.GetTitleText(fileName, [ "Culture Beat" ], "")); - Assert.AreEqual("Serenity (Epilog)", MusicTitleHelper.GetTitleText(fileName, new[] { "Culture Beat" }, "Serenity (Epilog)")); + Assert.AreEqual("Serenity (Epilog)", MusicTitleHelper.GetTitleText(fileName, [ "Culture Beat" ], "Serenity (Epilog)")); } } diff --git a/src/MusicManager/MusicManager.Applications.Test/ViewModels/MusicPropertiesViewModelTest.cs b/src/MusicManager/MusicManager.Applications.Test/ViewModels/MusicPropertiesViewModelTest.cs index 21ff7a1..517f285 100644 --- a/src/MusicManager/MusicManager.Applications.Test/ViewModels/MusicPropertiesViewModelTest.cs +++ b/src/MusicManager/MusicManager.Applications.Test/ViewModels/MusicPropertiesViewModelTest.cs @@ -78,7 +78,7 @@ public void UpdateAutoFillFromFileNameTestCommand() AssertHelper.CanExecuteChangedEvent(viewModel.AutoFillFromFileNameCommand, () => musicFile.Metadata!.Title = ""); Assert.IsTrue(viewModel.AutoFillFromFileNameCommand.CanExecute(null)); - AssertHelper.CanExecuteChangedEvent(viewModel.AutoFillFromFileNameCommand, () => musicFile.Metadata!.Artists = new[] { "Culture Beat" }); + AssertHelper.CanExecuteChangedEvent(viewModel.AutoFillFromFileNameCommand, () => musicFile.Metadata!.Artists = [ "Culture Beat" ]); Assert.IsFalse(viewModel.AutoFillFromFileNameCommand.CanExecute(null)); } } diff --git a/src/MusicManager/MusicManager.Applications.Test/Views/MockPlayerView.cs b/src/MusicManager/MusicManager.Applications.Test/Views/MockPlayerView.cs index 4d122b7..f3e7fe5 100644 --- a/src/MusicManager/MusicManager.Applications.Test/Views/MockPlayerView.cs +++ b/src/MusicManager/MusicManager.Applications.Test/Views/MockPlayerView.cs @@ -7,12 +7,7 @@ namespace Test.MusicManager.Applications.Views; [Export(typeof(IPlayerView))] public class MockPlayerView : MockView, IPlayerView { - public MockPlayerView() - { - Position = TimeSpan.FromSeconds(33); - } - - public TimeSpan Position { get; set; } + public TimeSpan Position { get; set; } = TimeSpan.FromSeconds(33); public TimeSpan GetPosition() => Position; diff --git a/src/MusicManager/MusicManager.Applications/ViewModels/MusicPropertiesViewModel.cs b/src/MusicManager/MusicManager.Applications/ViewModels/MusicPropertiesViewModel.cs index 2e575f4..b871ece 100644 --- a/src/MusicManager/MusicManager.Applications/ViewModels/MusicPropertiesViewModel.cs +++ b/src/MusicManager/MusicManager.Applications/ViewModels/MusicPropertiesViewModel.cs @@ -79,7 +79,7 @@ private void AutoFillFromFileName() private void MetadataLoaded() { if (MusicFile?.IsMetadataLoaded != true) return; - metadataPropertyChangedProxy = WeakEvent.PropertyChanged.Add(MusicFile.Metadata, MetadataPropertyChanged); + metadataPropertyChangedProxy = WeakEvent.PropertyChanged.Add(MusicFile.Metadata!, MetadataPropertyChanged); autoFillFromFileNameCommand.RaiseCanExecuteChanged(); } diff --git a/src/MusicManager/MusicManager.Domain.Test/MusicFiles/MockMusicFile.cs b/src/MusicManager/MusicManager.Domain.Test/MusicFiles/MockMusicFile.cs index c812e61..ab78854 100644 --- a/src/MusicManager/MusicManager.Domain.Test/MusicFiles/MockMusicFile.cs +++ b/src/MusicManager/MusicManager.Domain.Test/MusicFiles/MockMusicFile.cs @@ -11,7 +11,7 @@ public MockMusicFile(MusicMetadata? metadata, string? fileName) : base(x => Task public static MusicFile CreateEmpty(string fileName) => new MockMusicFile(new MusicMetadata(new TimeSpan(0, 3, 33), 320000) { - Artists = Array.Empty(), + Artists = [], Title = "" }, fileName); } diff --git a/src/MusicManager/MusicManager.Domain.Test/Playlists/PlaylistManagerTest.cs b/src/MusicManager/MusicManager.Domain.Test/Playlists/PlaylistManagerTest.cs index 4322af4..28cb524 100644 --- a/src/MusicManager/MusicManager.Domain.Test/Playlists/PlaylistManagerTest.cs +++ b/src/MusicManager/MusicManager.Domain.Test/Playlists/PlaylistManagerTest.cs @@ -1,6 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Waf.UnitTesting; -using Waf.MusicManager.Domain; using Waf.MusicManager.Domain.MusicFiles; using Waf.MusicManager.Domain.Playlists; @@ -14,12 +13,11 @@ public class PlaylistManagerTest : DomainTest protected override void OnInitialize() { base.OnInitialize(); - threeItems = new[] - { - new PlaylistItem(new MockMusicFile(new MusicMetadata(TimeSpan.FromMinutes(2), 256) { Album = "1" }, "")), - new PlaylistItem(new MockMusicFile(new MusicMetadata(TimeSpan.FromMinutes(2), 256) { Album = "2" }, "")), - new PlaylistItem(new MockMusicFile(new MusicMetadata(TimeSpan.FromMinutes(2), 256) { Album = "3" }, "")), - }; + threeItems = [ + new(new MockMusicFile(new(TimeSpan.FromMinutes(2), 256) { Album = "1" }, "")), + new(new MockMusicFile(new(TimeSpan.FromMinutes(2), 256) { Album = "2" }, "")), + new(new MockMusicFile(new(TimeSpan.FromMinutes(2), 256) { Album = "3" }, "")), + ]; } [TestMethod] @@ -193,14 +191,14 @@ public void AddRemoveAndMoveItems() manager.AddItems(threeItems); Assert.AreEqual(3, manager.Items.Count); - manager.RemoveItems(new[] { threeItems[2] }); + manager.RemoveItems([ threeItems[2] ]); Assert.AreEqual(2, manager.Items.Count); manager.AddAndReplaceItems(threeItems); Assert.AreEqual(3, manager.Items.Count); - manager.MoveItems(2, new[] { manager.Items[0] }); - AssertHelper.SequenceEqual(new[] { threeItems[1], threeItems[2], threeItems[0] }, manager.Items); + manager.MoveItems(2, [ manager.Items[0] ]); + AssertHelper.SequenceEqual([ threeItems[1], threeItems[2], threeItems[0] ], manager.Items); } [TestMethod] @@ -213,9 +211,9 @@ public void PreviousAndNextDuringAddRemoveItems() manager.NextItem(); Assert.IsTrue(manager.CanNextItem); - AssertHelper.PropertyChangedEvent(manager, x => x.CanNextItem, () => manager.RemoveItems(new[] { threeItems[2] })); + AssertHelper.PropertyChangedEvent(manager, x => x.CanNextItem, () => manager.RemoveItems([ threeItems[2] ])); Assert.IsFalse(manager.CanNextItem); - AssertHelper.PropertyChangedEvent(manager, x => x.CanNextItem, () => manager.AddItems(new[] { threeItems[2] })); + AssertHelper.PropertyChangedEvent(manager, x => x.CanNextItem, () => manager.AddItems([ threeItems[2] ])); Assert.IsTrue(manager.CanNextItem); manager.NextItem(); @@ -224,7 +222,7 @@ public void PreviousAndNextDuringAddRemoveItems() Assert.AreEqual(threeItems[1], manager.CurrentItem); Assert.IsTrue(manager.CanPreviousItem); - AssertHelper.PropertyChangedEvent(manager, x => x.CanPreviousItem, () => manager.RemoveItems(new[] { threeItems[0] })); + AssertHelper.PropertyChangedEvent(manager, x => x.CanPreviousItem, () => manager.RemoveItems([ threeItems[0] ])); Assert.IsFalse(manager.CanPreviousItem); } @@ -233,8 +231,8 @@ public void TotalDurationWithMetadataLoading() { var manager = new PlaylistManager(); Assert.AreEqual(TimeSpan.Zero, manager.TotalDuration); - var firstFile = new MockMusicFile(new MusicMetadata(TimeSpan.FromSeconds(10), 0), ""); - manager.AddAndReplaceItems(new[] { new PlaylistItem(firstFile) }); + var firstFile = new MockMusicFile(new(TimeSpan.FromSeconds(10), 0), ""); + manager.AddAndReplaceItems([ new PlaylistItem(firstFile) ]); var secondMetadata = new MusicMetadata(TimeSpan.FromSeconds(20), 0); var secondFile = new MusicFile(async x => @@ -243,7 +241,7 @@ public void TotalDurationWithMetadataLoading() return secondMetadata; }, ""); - manager.AddItems(new[] { new PlaylistItem(secondFile) }); + manager.AddItems([ new PlaylistItem(secondFile) ]); Assert.IsTrue(manager.IsTotalDurationEstimated); Assert.AreEqual(TimeSpan.FromSeconds(20), manager.TotalDuration); AssertHelper.PropertyChangedEvent(manager, x => x.TotalDuration, () => _ = secondFile.GetMetadataAsync().Result); @@ -251,7 +249,7 @@ public void TotalDurationWithMetadataLoading() Assert.AreEqual(TimeSpan.FromSeconds(30), manager.TotalDuration); var thirdFile = new MockMusicFile(new MusicMetadata(TimeSpan.FromSeconds(30), 0), ""); - AssertHelper.PropertyChangedEvent(manager, x => x.TotalDuration, () => manager.AddItems(new[] { new PlaylistItem(thirdFile) })); + AssertHelper.PropertyChangedEvent(manager, x => x.TotalDuration, () => manager.AddItems([ new PlaylistItem(thirdFile) ])); Assert.AreEqual(TimeSpan.FromSeconds(60), manager.TotalDuration); } } diff --git a/src/MusicManager/MusicManager.Domain.Test/Playlists/StatisticsHelperTest.cs b/src/MusicManager/MusicManager.Domain.Test/Playlists/StatisticsHelperTest.cs index d1ddaba..333b627 100644 --- a/src/MusicManager/MusicManager.Domain.Test/Playlists/StatisticsHelperTest.cs +++ b/src/MusicManager/MusicManager.Domain.Test/Playlists/StatisticsHelperTest.cs @@ -9,8 +9,8 @@ public class StatisticsHelperTest [TestMethod] public void TruncatedMeanTest() { - Assert.AreEqual(0, StatisticsHelper.TruncatedMean(Array.Empty(), 0.25)); + Assert.AreEqual(0, StatisticsHelper.TruncatedMean([], 0.25)); - Assert.AreEqual(6.5, StatisticsHelper.TruncatedMean(new double[] { 5, 8, 4, 38, 8, 6, 9, 7, 7, 3, 1, 6 }, 0.25)); + Assert.AreEqual(6.5, StatisticsHelper.TruncatedMean([ 5, 8, 4, 38, 8, 6, 9, 7, 7, 3, 1, 6 ], 0.25)); } } diff --git a/src/MusicManager/MusicManager.Domain.Test/Transcoding/TranscodeItemTest.cs b/src/MusicManager/MusicManager.Domain.Test/Transcoding/TranscodeItemTest.cs index 1784a4e..7b2f64d 100644 --- a/src/MusicManager/MusicManager.Domain.Test/Transcoding/TranscodeItemTest.cs +++ b/src/MusicManager/MusicManager.Domain.Test/Transcoding/TranscodeItemTest.cs @@ -12,7 +12,7 @@ public class TranscodeItemTest : DomainTest [TestMethod] public void PropertiesTest() { - var musicFile = new MockMusicFile(new MusicMetadata(TimeSpan.FromSeconds(33), 320), "TestFile.wma"); + var musicFile = new MockMusicFile(new(TimeSpan.FromSeconds(33), 320), "TestFile.wma"); var item = new TranscodeItem(musicFile, "TestFile.mp3"); Assert.AreEqual(musicFile, item.Source); @@ -31,7 +31,7 @@ public void PropertiesTest() [TestMethod] public void TranscodeStatusTest() { - var musicFile = new MockMusicFile(new MusicMetadata(TimeSpan.FromSeconds(33), 320), "TestFile.wma"); + var musicFile = new MockMusicFile(new(TimeSpan.FromSeconds(33), 320), "TestFile.wma"); var item = new TranscodeItem(musicFile, "TestFile.mp3"); Assert.AreEqual(TranscodeStatus.Pending, item.TranscodeStatus); diff --git a/src/MusicManager/MusicManager.Domain.Test/Transcoding/TranscodingManagerTest.cs b/src/MusicManager/MusicManager.Domain.Test/Transcoding/TranscodingManagerTest.cs index 4ef99d2..424067f 100644 --- a/src/MusicManager/MusicManager.Domain.Test/Transcoding/TranscodingManagerTest.cs +++ b/src/MusicManager/MusicManager.Domain.Test/Transcoding/TranscodingManagerTest.cs @@ -12,8 +12,8 @@ public class TranscodingManagerTest : DomainTest [TestMethod] public void AddRemoveTranscodeItemsTest() { - var musicFile1 = new MockMusicFile(new MusicMetadata(TimeSpan.FromSeconds(33), 320), "TestFile1.wma"); - var musicFile2 = new MockMusicFile(new MusicMetadata(TimeSpan.FromSeconds(33), 320), "TestFile2.wma"); + var musicFile1 = new MockMusicFile(new(TimeSpan.FromSeconds(33), 320), "TestFile1.wma"); + var musicFile2 = new MockMusicFile(new(TimeSpan.FromSeconds(33), 320), "TestFile2.wma"); var item1 = new TranscodeItem(musicFile1, "TestFile1.mp3"); var item2 = new TranscodeItem(musicFile2, "TestFile2.mp3"); @@ -23,7 +23,7 @@ public void AddRemoveTranscodeItemsTest() manager.AddTranscodeItem(item1); manager.AddTranscodeItem(item2); - AssertHelper.SequenceEqual(new[] { item1, item2 }, manager.TranscodeItems); + AssertHelper.SequenceEqual([ item1, item2 ], manager.TranscodeItems); manager.RemoveTranscodeItem(item1); diff --git a/src/MusicManager/MusicManager.Presentation.Test/Controllers/PlaylistControllerIntegrationTest.cs b/src/MusicManager/MusicManager.Presentation.Test/Controllers/PlaylistControllerIntegrationTest.cs index b37b83d..e562665 100644 --- a/src/MusicManager/MusicManager.Presentation.Test/Controllers/PlaylistControllerIntegrationTest.cs +++ b/src/MusicManager/MusicManager.Presentation.Test/Controllers/PlaylistControllerIntegrationTest.cs @@ -46,7 +46,7 @@ public void SaveAndLoadPlaylist() Assert.AreEqual(2, viewModel.PlaylistManager.Items.Count); var fileDialogService = Container.GetExportedValue(); - fileDialogService.Result = new FileDialogResult(playlistFileName, new FileType("test", ".m3u")); + fileDialogService.Result = new(playlistFileName, new FileType("test", ".m3u")); viewModel.SaveListCommand.Execute(null); Assert.IsTrue(File.Exists(playlistFileName)); diff --git a/src/MusicManager/MusicManager.Presentation.Test/Converters/IsPlaylistItemPlayingMultiConverterTest.cs b/src/MusicManager/MusicManager.Presentation.Test/Converters/IsPlaylistItemPlayingMultiConverterTest.cs index 35f834c..7670313 100644 --- a/src/MusicManager/MusicManager.Presentation.Test/Converters/IsPlaylistItemPlayingMultiConverterTest.cs +++ b/src/MusicManager/MusicManager.Presentation.Test/Converters/IsPlaylistItemPlayingMultiConverterTest.cs @@ -14,7 +14,7 @@ public void ConvertTest() var item2 = new PlaylistItem(null!); var converter = new IsPlaylistItemPlayingMultiConverter(); - Assert.IsTrue((bool)converter.Convert(new[] { item1, item1 }, null, null, null)); - Assert.IsFalse((bool)converter.Convert(new[] { item1, item2 }, null, null, null)); + Assert.IsTrue((bool)converter.Convert([ item1, item1 ], null, null, null)); + Assert.IsFalse((bool)converter.Convert([ item1, item2 ], null, null, null)); } } diff --git a/src/MusicManager/MusicManager.Presentation.Test/Converters/MusicPropertiesEnabledConverterTest.cs b/src/MusicManager/MusicManager.Presentation.Test/Converters/MusicPropertiesEnabledConverterTest.cs index 51c5d3d..0d85304 100644 --- a/src/MusicManager/MusicManager.Presentation.Test/Converters/MusicPropertiesEnabledConverterTest.cs +++ b/src/MusicManager/MusicManager.Presentation.Test/Converters/MusicPropertiesEnabledConverterTest.cs @@ -16,8 +16,8 @@ public void ConvertTest() var unsupportedFile = new MockMusicFile(MusicMetadata.CreateUnsupported(TimeSpan.FromSeconds(20), 0), ""); var converter = new MusicPropertiesEnabledConverter(); - Assert.AreEqual(true, converter.Convert(new object[] { musicFile, true }, null, null, null)); - Assert.AreEqual(false, converter.Convert(new object[] { unsupportedFile, true }, null, null, null)); + Assert.AreEqual(true, converter.Convert([ musicFile, true ], null, null, null)); + Assert.AreEqual(false, converter.Convert([ unsupportedFile, true ], null, null, null)); AssertHelper.ExpectedException(() => converter.ConvertBack(null, null, null, null)); } diff --git a/src/MusicManager/MusicManager.Presentation.Test/Converters/MusicPropertiesProgressVisibilityConverterTest.cs b/src/MusicManager/MusicManager.Presentation.Test/Converters/MusicPropertiesProgressVisibilityConverterTest.cs index fb37858..07b5af0 100644 --- a/src/MusicManager/MusicManager.Presentation.Test/Converters/MusicPropertiesProgressVisibilityConverterTest.cs +++ b/src/MusicManager/MusicManager.Presentation.Test/Converters/MusicPropertiesProgressVisibilityConverterTest.cs @@ -12,9 +12,9 @@ public class MusicPropertiesProgressVisibilityConverterTest public void ConvertTest() { var converter = new MusicPropertiesProgressVisibilityConverter(); - Assert.AreEqual(Visibility.Visible, converter.Convert(new object?[] { false, null }, null, null, null)); - Assert.AreEqual(Visibility.Collapsed, converter.Convert(new object?[] { true, null }, null, null, null)); - Assert.AreEqual(Visibility.Collapsed, converter.Convert(new object?[] { false, new ArgumentException() }, null, null, null)); + Assert.AreEqual(Visibility.Visible, converter.Convert([ false, null ], null, null, null)); + Assert.AreEqual(Visibility.Collapsed, converter.Convert([ true, null ], null, null, null)); + Assert.AreEqual(Visibility.Collapsed, converter.Convert([ false, new ArgumentException() ], null, null, null)); AssertHelper.ExpectedException(() => converter.ConvertBack(null, null, null, null)); } diff --git a/src/MusicManager/MusicManager.Presentation.Test/Converters/MusicTitleConverterTest.cs b/src/MusicManager/MusicManager.Presentation.Test/Converters/MusicTitleConverterTest.cs index 9adc13f..d924ff7 100644 --- a/src/MusicManager/MusicManager.Presentation.Test/Converters/MusicTitleConverterTest.cs +++ b/src/MusicManager/MusicManager.Presentation.Test/Converters/MusicTitleConverterTest.cs @@ -13,19 +13,19 @@ public void ConvertTest() var converter = new MusicTitleConverter(); var fileName = @"C:\Users\Public\Music\Dancefloor\Culture Beat - Serenity.mp3"; - Assert.AreEqual("Culture Beat - Serenity", ConvertCore(converter, fileName, Array.Empty(), null)); - Assert.AreEqual("Culture Beat - Serenity", ConvertCore(converter, fileName, Array.Empty(), "")); + Assert.AreEqual("Culture Beat - Serenity", ConvertCore(converter, fileName, [], null)); + Assert.AreEqual("Culture Beat - Serenity", ConvertCore(converter, fileName, [], "")); - Assert.AreEqual("", ConvertCore(converter, fileName, new[] { "Culture Beat" }, null)); - Assert.AreEqual("", ConvertCore(converter, fileName, new[] { "Culture Beat" }, "")); + Assert.AreEqual("", ConvertCore(converter, fileName, [ "Culture Beat" ], null)); + Assert.AreEqual("", ConvertCore(converter, fileName, [ "Culture Beat" ], "")); - Assert.AreEqual("Serenity (Epilog)", ConvertCore(converter, fileName, new[] { "Culture Beat" }, "Serenity (Epilog)")); + Assert.AreEqual("Serenity (Epilog)", ConvertCore(converter, fileName, [ "Culture Beat" ], "Serenity (Epilog)")); AssertHelper.ExpectedException(() => converter.ConvertBack(null, null, null, null)); } private static string ConvertCore(MusicTitleConverter converter, string fileName, IEnumerable artists, string? title) { - return (string)converter.Convert(new object?[] { fileName, artists, title }, null, null, null); + return (string)converter.Convert([ fileName, artists, title ], null, null, null); } } diff --git a/src/MusicManager/MusicManager.Presentation.Test/Converters/StringListToStringConverterTest.cs b/src/MusicManager/MusicManager.Presentation.Test/Converters/StringListToStringConverterTest.cs index 095ff57..0649942 100644 --- a/src/MusicManager/MusicManager.Presentation.Test/Converters/StringListToStringConverterTest.cs +++ b/src/MusicManager/MusicManager.Presentation.Test/Converters/StringListToStringConverterTest.cs @@ -31,18 +31,18 @@ public void ConvertBackTest() var ls = CultureInfo.CurrentCulture.TextInfo.ListSeparator; var converter = new StringListToStringConverter(); - AssertHelper.SequenceEqual(Array.Empty(), (string[])converter.ConvertBack("", null, null, null)); + AssertHelper.SequenceEqual([], (string[])converter.ConvertBack("", null, null, null)); - AssertHelper.SequenceEqual(new[] { "Pop" }, (string[])converter.ConvertBack("Pop", null, null, null)); - AssertHelper.SequenceEqual(new[] { "Pop", "Rock" }, (string[])converter.ConvertBack("Pop" + nl + "Rock", null, null, null)); - AssertHelper.SequenceEqual(new[] { "Pop", "Rock" }, (string[])converter.ConvertBack(" Pop" + nl + " Rock", null, null, null)); - AssertHelper.SequenceEqual(new[] { "Pop", "Rock" }, (string[])converter.ConvertBack("Pop " + nl + "Rock ", null, null, null)); + AssertHelper.SequenceEqual([ "Pop" ], (string[])converter.ConvertBack("Pop", null, null, null)); + AssertHelper.SequenceEqual([ "Pop", "Rock" ], (string[])converter.ConvertBack("Pop" + nl + "Rock", null, null, null)); + AssertHelper.SequenceEqual([ "Pop", "Rock" ], (string[])converter.ConvertBack(" Pop" + nl + " Rock", null, null, null)); + AssertHelper.SequenceEqual([ "Pop", "Rock" ], (string[])converter.ConvertBack("Pop " + nl + "Rock ", null, null, null)); - AssertHelper.SequenceEqual(new[] { "Pop", "Rock" }, (string[])converter.ConvertBack("Pop" + ls + "Rock", null, "ListSeparator", null)); - AssertHelper.SequenceEqual(new[] { "Pop", "Rock" }, (string[])converter.ConvertBack(" Pop" + ls + " Rock", null, "ListSeparator", null)); - AssertHelper.SequenceEqual(new[] { "Pop", "Rock" }, (string[])converter.ConvertBack("Pop " + ls + "Rock ", null, "ListSeparator", null)); + AssertHelper.SequenceEqual([ "Pop", "Rock" ], (string[])converter.ConvertBack("Pop" + ls + "Rock", null, "ListSeparator", null)); + AssertHelper.SequenceEqual([ "Pop", "Rock" ], (string[])converter.ConvertBack(" Pop" + ls + " Rock", null, "ListSeparator", null)); + AssertHelper.SequenceEqual([ "Pop", "Rock" ], (string[])converter.ConvertBack("Pop " + ls + "Rock ", null, "ListSeparator", null)); - AssertHelper.SequenceEqual(new[] { "Pop" }, (string[])converter.ConvertBack("Pop" + ls, null, "ListSeparator", null)); - AssertHelper.SequenceEqual(new[] { "Pop" }, (string[])converter.ConvertBack("Pop" + ls + " ", null, "ListSeparator", null)); + AssertHelper.SequenceEqual([ "Pop" ], (string[])converter.ConvertBack("Pop" + ls, null, "ListSeparator", null)); + AssertHelper.SequenceEqual([ "Pop" ], (string[])converter.ConvertBack("Pop" + ls + " ", null, "ListSeparator", null)); } } diff --git a/src/MusicManager/MusicManager.Presentation.Test/Converters/TotalDurationConverterTest.cs b/src/MusicManager/MusicManager.Presentation.Test/Converters/TotalDurationConverterTest.cs index 86e1f29..d96a0c1 100644 --- a/src/MusicManager/MusicManager.Presentation.Test/Converters/TotalDurationConverterTest.cs +++ b/src/MusicManager/MusicManager.Presentation.Test/Converters/TotalDurationConverterTest.cs @@ -13,8 +13,8 @@ public class TotalDurationConverterTest public void ConvertTest() { var converter = new TotalDurationConverter(); - Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, Resources.AboutDuration, "0:03"), converter.Convert(new object[] { true, TimeSpan.FromSeconds(3) }, null, null, null)); - Assert.AreEqual("0:04", converter.Convert(new object[] { false, TimeSpan.FromSeconds(4) }, null, null, null)); + Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, Resources.AboutDuration, "0:03"), converter.Convert([ true, TimeSpan.FromSeconds(3) ], null, null, null)); + Assert.AreEqual("0:04", converter.Convert([ false, TimeSpan.FromSeconds(4) ], null, null, null)); AssertHelper.ExpectedException(() => converter.ConvertBack(null, null, null, null)); } diff --git a/src/MusicManager/MusicManager.Presentation.Test/Converters/WindowTitleConverterTest.cs b/src/MusicManager/MusicManager.Presentation.Test/Converters/WindowTitleConverterTest.cs index 82351be..e31073e 100644 --- a/src/MusicManager/MusicManager.Presentation.Test/Converters/WindowTitleConverterTest.cs +++ b/src/MusicManager/MusicManager.Presentation.Test/Converters/WindowTitleConverterTest.cs @@ -12,11 +12,11 @@ public void ConvertTest() { var converter = new WindowTitleConverter(); - Assert.AreEqual("Waf Music Manager", converter.Convert(new string?[] { null, null, "Waf Music Manager" }, null, null, null)); + Assert.AreEqual("Waf Music Manager", converter.Convert([ null, null, "Waf Music Manager" ], null, null, null)); - Assert.AreEqual("Culture Beat - Waf Music Manager", converter.Convert(new string?[] { "Culture Beat", null, "Waf Music Manager" }, null, null, null)); + Assert.AreEqual("Culture Beat - Waf Music Manager", converter.Convert([ "Culture Beat", null, "Waf Music Manager" ], null, null, null)); - Assert.AreEqual("Culture Beat - Serenity (Epilog) - Waf Music Manager", converter.Convert(new string?[] { "Culture Beat", "Serenity (Epilog)", "Waf Music Manager" }, null, null, null)); + Assert.AreEqual("Culture Beat - Serenity (Epilog) - Waf Music Manager", converter.Convert([ "Culture Beat", "Serenity (Epilog)", "Waf Music Manager" ], null, null, null)); AssertHelper.ExpectedException(() => converter.ConvertBack(null, null, null, null)); } diff --git a/src/MusicManager/MusicManager.Presentation.Test/PresentationTest.cs b/src/MusicManager/MusicManager.Presentation.Test/PresentationTest.cs index 7b3d6bc..e2e943b 100644 --- a/src/MusicManager/MusicManager.Presentation.Test/PresentationTest.cs +++ b/src/MusicManager/MusicManager.Presentation.Test/PresentationTest.cs @@ -14,13 +14,12 @@ namespace Test.MusicManager.Presentation public class PresentationTest : ApplicationsTest { // List of exports which must use the real implementation instead of the mock (integration test) - private static readonly Type[] exportNames = new[] - { + private static readonly Type[] exportNames = [ typeof(IFileService), typeof(IFileSystemWatcherService), typeof(FileSystemWatcherService), typeof(IMusicFileContext), typeof(MusicFileContext), typeof(ITranscoder), typeof(Transcoder), - }; + ]; protected override void OnCatalogInitialize(AggregateCatalog catalog) { diff --git a/src/MusicManager/MusicManager.Presentation.Test/Services/FileServiceTest.cs b/src/MusicManager/MusicManager.Presentation.Test/Services/FileServiceTest.cs index 3b9fac0..94a1545 100644 --- a/src/MusicManager/MusicManager.Presentation.Test/Services/FileServiceTest.cs +++ b/src/MusicManager/MusicManager.Presentation.Test/Services/FileServiceTest.cs @@ -43,15 +43,15 @@ public void GetLocalizedDisplayPath() public void GetPathSegmentsTest() { var pathSegments = FileService.GetPathSegments(@"C:\Users\Public\Music"); - AssertHelper.SequenceEqual(new[] { @"C:\", "Users", "Public", "Music" }, pathSegments); + AssertHelper.SequenceEqual([ @"C:\", "Users", "Public", "Music" ], pathSegments); pathSegments = FileService.GetPathSegments(@"C:\Users\Public\Music\"); - AssertHelper.SequenceEqual(new[] { @"C:\", "Users", "Public", "Music" }, pathSegments); + AssertHelper.SequenceEqual([ @"C:\", "Users", "Public", "Music" ], pathSegments); pathSegments = FileService.GetPathSegments(@"C:"); - AssertHelper.SequenceEqual(new[] { @"C:" }, pathSegments); + AssertHelper.SequenceEqual([ @"C:" ], pathSegments); pathSegments = FileService.GetPathSegments(@"\\localhost\Users\Public\Music"); - AssertHelper.SequenceEqual(new[] { @"\\localhost\Users", "Public", "Music" }, pathSegments); + AssertHelper.SequenceEqual([ @"\\localhost\Users", "Public", "Music" ], pathSegments); } } diff --git a/src/MusicManager/MusicManager.Presentation.Test/Services/SequenceEqualityComparerTest.cs b/src/MusicManager/MusicManager.Presentation.Test/Services/SequenceEqualityComparerTest.cs index 48480d3..6736b67 100644 --- a/src/MusicManager/MusicManager.Presentation.Test/Services/SequenceEqualityComparerTest.cs +++ b/src/MusicManager/MusicManager.Presentation.Test/Services/SequenceEqualityComparerTest.cs @@ -21,7 +21,7 @@ public void ComparerTest() Assert.IsFalse(comparer.Equals(null, list1)); Assert.AreEqual(list1![0].GetHashCode() ^ list1[1].GetHashCode() ^ list1[2].GetHashCode(), comparer.GetHashCode(list1)); - Assert.AreEqual("Han".GetHashCode(), comparer.GetHashCode(new[] { "Han" })); - Assert.AreEqual(0, comparer.GetHashCode(System.Array.Empty())); + Assert.AreEqual("Han".GetHashCode(), comparer.GetHashCode([ "Han" ])); + Assert.AreEqual(0, comparer.GetHashCode([])); } } diff --git a/src/MusicManager/MusicManager.Presentation.Test/Services/StringListConverterTest.cs b/src/MusicManager/MusicManager.Presentation.Test/Services/StringListConverterTest.cs index 7027951..95f3e22 100644 --- a/src/MusicManager/MusicManager.Presentation.Test/Services/StringListConverterTest.cs +++ b/src/MusicManager/MusicManager.Presentation.Test/Services/StringListConverterTest.cs @@ -15,12 +15,12 @@ public void ToStringTest() var ls = CultureInfo.CurrentCulture.TextInfo.ListSeparator; Assert.AreEqual("", StringListConverter.ToString(null)); - Assert.AreEqual("", StringListConverter.ToString(Array.Empty())); - Assert.AreEqual("", StringListConverter.ToString(new[] { "" })); + Assert.AreEqual("", StringListConverter.ToString([])); + Assert.AreEqual("", StringListConverter.ToString([ "" ])); - Assert.AreEqual("Pop", StringListConverter.ToString(new[] { "Pop" })); - Assert.AreEqual("Pop" + ls + " Rock", StringListConverter.ToString(new[] { "Pop", "Rock" })); - Assert.AreEqual("Pop" + nl + "Rock", StringListConverter.ToString(new[] { "Pop", "Rock" }, nl)); + Assert.AreEqual("Pop", StringListConverter.ToString([ "Pop" ])); + Assert.AreEqual("Pop" + ls + " Rock", StringListConverter.ToString([ "Pop", "Rock" ])); + Assert.AreEqual("Pop" + nl + "Rock", StringListConverter.ToString([ "Pop", "Rock" ], nl)); } [TestMethod] @@ -29,18 +29,18 @@ public void ConvertBackTest() var nl = Environment.NewLine; var ls = CultureInfo.CurrentCulture.TextInfo.ListSeparator; - AssertHelper.SequenceEqual(Array.Empty(), StringListConverter.FromString("")); + AssertHelper.SequenceEqual([], StringListConverter.FromString("")); - AssertHelper.SequenceEqual(new[] { "Pop" }, StringListConverter.FromString("Pop")); - AssertHelper.SequenceEqual(new[] { "Pop", "Rock" }, StringListConverter.FromString("Pop" + nl + "Rock", nl)); - AssertHelper.SequenceEqual(new[] { "Pop", "Rock" }, StringListConverter.FromString(" Pop" + nl + " Rock", nl)); - AssertHelper.SequenceEqual(new[] { "Pop", "Rock" }, StringListConverter.FromString("Pop " + nl + "Rock ", nl)); + AssertHelper.SequenceEqual([ "Pop" ], StringListConverter.FromString("Pop")); + AssertHelper.SequenceEqual([ "Pop", "Rock" ], StringListConverter.FromString("Pop" + nl + "Rock", nl)); + AssertHelper.SequenceEqual([ "Pop", "Rock" ], StringListConverter.FromString(" Pop" + nl + " Rock", nl)); + AssertHelper.SequenceEqual([ "Pop", "Rock" ], StringListConverter.FromString("Pop " + nl + "Rock ", nl)); - AssertHelper.SequenceEqual(new[] { "Pop", "Rock" }, StringListConverter.FromString("Pop" + ls + "Rock")); - AssertHelper.SequenceEqual(new[] { "Pop", "Rock" }, StringListConverter.FromString(" Pop" + ls + " Rock")); - AssertHelper.SequenceEqual(new[] { "Pop", "Rock" }, StringListConverter.FromString("Pop " + ls + "Rock ")); + AssertHelper.SequenceEqual([ "Pop", "Rock" ], StringListConverter.FromString("Pop" + ls + "Rock")); + AssertHelper.SequenceEqual([ "Pop", "Rock" ], StringListConverter.FromString(" Pop" + ls + " Rock")); + AssertHelper.SequenceEqual([ "Pop", "Rock" ], StringListConverter.FromString("Pop " + ls + "Rock ")); - AssertHelper.SequenceEqual(new[] { "Pop" }, StringListConverter.FromString("Pop" + ls)); - AssertHelper.SequenceEqual(new[] { "Pop" }, StringListConverter.FromString("Pop" + ls + " ")); + AssertHelper.SequenceEqual([ "Pop" ], StringListConverter.FromString("Pop" + ls)); + AssertHelper.SequenceEqual([ "Pop" ], StringListConverter.FromString("Pop" + ls + " ")); } } diff --git a/src/MusicManager/MusicManager.Presentation.Test/TestHelper.cs b/src/MusicManager/MusicManager.Presentation.Test/TestHelper.cs index b34ed1b..abe8c47 100644 --- a/src/MusicManager/MusicManager.Presentation.Test/TestHelper.cs +++ b/src/MusicManager/MusicManager.Presentation.Test/TestHelper.cs @@ -5,7 +5,7 @@ namespace Test.MusicManager.Presentation; [TestClass] public static class TestHelper { - private static readonly HashSet tempFiles = new(); + private static readonly HashSet tempFiles = []; public static string GetTempFileName(string? extension = null) { diff --git a/src/MusicManager/MusicManager.Presentation/Services/Metadata/SaveMetadata.cs b/src/MusicManager/MusicManager.Presentation/Services/Metadata/SaveMetadata.cs index 3614d32..61ff26d 100644 --- a/src/MusicManager/MusicManager.Presentation/Services/Metadata/SaveMetadata.cs +++ b/src/MusicManager/MusicManager.Presentation/Services/Metadata/SaveMetadata.cs @@ -21,18 +21,18 @@ public async Task SaveChangesAsync(MusicFile musicFile) var musicProperties = await file.Properties.GetMusicPropertiesAsync(); var customProperties = new Dictionary(); - if (changedProperties.Contains(nameof(MusicMetadata.Title))) { ApplyTitle(musicProperties, customProperties, metadata.Title); } - if (changedProperties.Contains(nameof(MusicMetadata.Artists))) { ApplyArtists(musicProperties, customProperties, metadata.Artists); } - if (changedProperties.Contains(nameof(MusicMetadata.Rating))) { ApplyRating(musicProperties, customProperties, metadata.Rating); } - if (changedProperties.Contains(nameof(MusicMetadata.Album))) { ApplyAlbum(musicProperties, customProperties, metadata.Album); } - if (changedProperties.Contains(nameof(MusicMetadata.TrackNumber))) { ApplyTrackNumber(musicProperties, customProperties, metadata.TrackNumber); } - if (changedProperties.Contains(nameof(MusicMetadata.Year))) { ApplyYear(musicProperties, customProperties, metadata.Year); } - if (changedProperties.Contains(nameof(MusicMetadata.Genre))) { ApplyGenre(musicProperties, customProperties, metadata.Genre); } - if (changedProperties.Contains(nameof(MusicMetadata.AlbumArtist))) { ApplyAlbumArtist(musicProperties, customProperties, metadata.AlbumArtist); } - if (changedProperties.Contains(nameof(MusicMetadata.Publisher))) { ApplyPublisher(musicProperties, customProperties, metadata.Publisher); } - if (changedProperties.Contains(nameof(MusicMetadata.Subtitle))) { ApplySubtitle(musicProperties, customProperties, metadata.Subtitle); } - if (changedProperties.Contains(nameof(MusicMetadata.Composers))) { ApplyComposers(musicProperties, customProperties, metadata.Composers); } - if (changedProperties.Contains(nameof(MusicMetadata.Conductors))) { ApplyConductors(musicProperties, customProperties, metadata.Conductors); } + if (changedProperties.Contains(nameof(MusicMetadata.Title))) ApplyTitle(musicProperties, customProperties, metadata.Title); + if (changedProperties.Contains(nameof(MusicMetadata.Artists))) ApplyArtists(musicProperties, customProperties, metadata.Artists); + if (changedProperties.Contains(nameof(MusicMetadata.Rating))) ApplyRating(musicProperties, customProperties, metadata.Rating); + if (changedProperties.Contains(nameof(MusicMetadata.Album))) ApplyAlbum(musicProperties, customProperties, metadata.Album); + if (changedProperties.Contains(nameof(MusicMetadata.TrackNumber))) ApplyTrackNumber(musicProperties, customProperties, metadata.TrackNumber); + if (changedProperties.Contains(nameof(MusicMetadata.Year))) ApplyYear(musicProperties, customProperties, metadata.Year); + if (changedProperties.Contains(nameof(MusicMetadata.Genre))) ApplyGenre(musicProperties, customProperties, metadata.Genre); + if (changedProperties.Contains(nameof(MusicMetadata.AlbumArtist))) ApplyAlbumArtist(musicProperties, customProperties, metadata.AlbumArtist); + if (changedProperties.Contains(nameof(MusicMetadata.Publisher))) ApplyPublisher(musicProperties, customProperties, metadata.Publisher); + if (changedProperties.Contains(nameof(MusicMetadata.Subtitle))) ApplySubtitle(musicProperties, customProperties, metadata.Subtitle); + if (changedProperties.Contains(nameof(MusicMetadata.Composers))) ApplyComposers(musicProperties, customProperties, metadata.Composers); + if (changedProperties.Contains(nameof(MusicMetadata.Conductors))) ApplyConductors(musicProperties, customProperties, metadata.Conductors); Log.Default.Trace("SaveMetadata.SaveChangesAsync:Save: {0}", musicFile.FileName); await musicProperties.SavePropertiesAsync(customProperties);