From 7cb67fb47b8340110a259cd5c8f34699b8d47ac2 Mon Sep 17 00:00:00 2001 From: Mark-James McDougall Date: Sun, 3 Dec 2023 22:45:18 -0500 Subject: [PATCH] Updated project to .NET 8 Changed testing from MSTest to Nunit. --- .idea/.idea.MusicSharp/.idea/.gitignore | 13 ++++++++++ .idea/.idea.MusicSharp/.idea/encodings.xml | 4 +++ .idea/.idea.MusicSharp/.idea/indexLayout.xml | 8 ++++++ .idea/.idea.MusicSharp/.idea/vcs.xml | 6 +++++ MusicSharp.sln | 12 ++++----- MusicSharpTests/MusicSharpTests.csproj | 23 ++++++++++++++++ MusicSharpTests/PlaylistLoaderTests.cs | 13 ++++++++++ MusicSharpTests/Usings.cs | 1 + MusicSharpTests/WinPlayerTests.cs | 26 +++++++++++++++++++ src/MusicSharp.csproj | 4 +-- src/SoundEngines/WinPlayer.cs | 21 ++++++++------- .../src/PlaylistLoaderTests.cs | 19 -------------- .../MusicSharpTestsOld.csproj} | 2 ++ .../src/WinPlayerTests.cs | 0 14 files changed, 116 insertions(+), 36 deletions(-) create mode 100644 .idea/.idea.MusicSharp/.idea/.gitignore create mode 100644 .idea/.idea.MusicSharp/.idea/encodings.xml create mode 100644 .idea/.idea.MusicSharp/.idea/indexLayout.xml create mode 100644 .idea/.idea.MusicSharp/.idea/vcs.xml create mode 100644 MusicSharpTests/MusicSharpTests.csproj create mode 100644 MusicSharpTests/PlaylistLoaderTests.cs create mode 100644 MusicSharpTests/Usings.cs create mode 100644 MusicSharpTests/WinPlayerTests.cs delete mode 100644 tests/MusicSharpTests/src/PlaylistLoaderTests.cs rename tests/{MusicSharpTests/MusicSharpTests.csproj => MusicSharpTestsOld/MusicSharpTestsOld.csproj} (91%) rename tests/{MusicSharpTests => MusicSharpTestsOld}/src/WinPlayerTests.cs (100%) diff --git a/.idea/.idea.MusicSharp/.idea/.gitignore b/.idea/.idea.MusicSharp/.idea/.gitignore new file mode 100644 index 0000000..97791b0 --- /dev/null +++ b/.idea/.idea.MusicSharp/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/modules.xml +/contentModel.xml +/projectSettingsUpdater.xml +/.idea.MusicSharp.iml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.idea.MusicSharp/.idea/encodings.xml b/.idea/.idea.MusicSharp/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/.idea.MusicSharp/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.MusicSharp/.idea/indexLayout.xml b/.idea/.idea.MusicSharp/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.MusicSharp/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.MusicSharp/.idea/vcs.xml b/.idea/.idea.MusicSharp/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/.idea.MusicSharp/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MusicSharp.sln b/MusicSharp.sln index 1251fb6..7120784 100644 --- a/MusicSharp.sln +++ b/MusicSharp.sln @@ -5,8 +5,6 @@ VisualStudioVersion = 16.0.30621.155 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MusicSharp", "src\MusicSharp.csproj", "{A1943162-1979-46C6-9082-7F49BEC191BA}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MusicSharpTests", "tests\MusicSharpTests\MusicSharpTests.csproj", "{4D76B590-6B8E-46FC-B79C-C29F93C5C80D}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6A4109AE-AA05-4695-A7EB-412C02252269}" ProjectSection(SolutionItems) = preProject .gitignore = .gitignore @@ -14,6 +12,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution README.md = README.md EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MusicSharpTests", "MusicSharpTests\MusicSharpTests.csproj", "{B0797164-0016-4ED1-BDDA-42DE8D414CD6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -24,10 +24,10 @@ Global {A1943162-1979-46C6-9082-7F49BEC191BA}.Debug|Any CPU.Build.0 = Debug|Any CPU {A1943162-1979-46C6-9082-7F49BEC191BA}.Release|Any CPU.ActiveCfg = Release|Any CPU {A1943162-1979-46C6-9082-7F49BEC191BA}.Release|Any CPU.Build.0 = Release|Any CPU - {4D76B590-6B8E-46FC-B79C-C29F93C5C80D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4D76B590-6B8E-46FC-B79C-C29F93C5C80D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4D76B590-6B8E-46FC-B79C-C29F93C5C80D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4D76B590-6B8E-46FC-B79C-C29F93C5C80D}.Release|Any CPU.Build.0 = Release|Any CPU + {B0797164-0016-4ED1-BDDA-42DE8D414CD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B0797164-0016-4ED1-BDDA-42DE8D414CD6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B0797164-0016-4ED1-BDDA-42DE8D414CD6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B0797164-0016-4ED1-BDDA-42DE8D414CD6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MusicSharpTests/MusicSharpTests.csproj b/MusicSharpTests/MusicSharpTests.csproj new file mode 100644 index 0000000..74f3a7b --- /dev/null +++ b/MusicSharpTests/MusicSharpTests.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + enable + enable + + false + + + + + + + + + + + + + + + diff --git a/MusicSharpTests/PlaylistLoaderTests.cs b/MusicSharpTests/PlaylistLoaderTests.cs new file mode 100644 index 0000000..9693a14 --- /dev/null +++ b/MusicSharpTests/PlaylistLoaderTests.cs @@ -0,0 +1,13 @@ +using MusicSharp.Models; + +namespace MusicSharpTests; + +public class Tests +{ + [Test] + public void Load_NullPlaylist() + { + // Act and assert + Assert.Throws(() => PlaylistLoader.LoadPlaylist(null)); + } +} \ No newline at end of file diff --git a/MusicSharpTests/Usings.cs b/MusicSharpTests/Usings.cs new file mode 100644 index 0000000..cefced4 --- /dev/null +++ b/MusicSharpTests/Usings.cs @@ -0,0 +1 @@ +global using NUnit.Framework; \ No newline at end of file diff --git a/MusicSharpTests/WinPlayerTests.cs b/MusicSharpTests/WinPlayerTests.cs new file mode 100644 index 0000000..37612b4 --- /dev/null +++ b/MusicSharpTests/WinPlayerTests.cs @@ -0,0 +1,26 @@ +using MusicSharp.SoundEngines; + +namespace MusicSharpTests; + +public class WinPlayerTests +{ + [Test] + public void PlayFromPlaylist_NullFile() + { + // arrange + var player = new WinPlayer(); + + // act and assert + Assert.Throws(() => player.PlayFromPlaylist(null)); + } + + [Test] + public void OpenStream_NullFile() + { + // arrange + var player = new WinPlayer(); + + // act and assert + Assert.Throws(() => player.OpenStream(null)); + } +} \ No newline at end of file diff --git a/src/MusicSharp.csproj b/src/MusicSharp.csproj index e8b6cda..d92021d 100644 --- a/src/MusicSharp.csproj +++ b/src/MusicSharp.csproj @@ -2,8 +2,8 @@ Exe - net7.0 - 0.4.8 + net8.0 + 0.4.9 Mark-James McDougall Mark-James McDougall diff --git a/src/SoundEngines/WinPlayer.cs b/src/SoundEngines/WinPlayer.cs index 5c35b11..97e2934 100644 --- a/src/SoundEngines/WinPlayer.cs +++ b/src/SoundEngines/WinPlayer.cs @@ -49,10 +49,16 @@ public void OpenFile(string path) if (isFileValid) { - _audioFileReader = new AudioFileReader(path); - _outputDevice.Init(_audioFileReader); - _outputDevice.Play(); - PlayerStatus = ePlayerStatus.Playing; + try + { + _audioFileReader = new AudioFileReader(path); + _outputDevice.Init(_audioFileReader); + _outputDevice.Play(); + PlayerStatus = ePlayerStatus.Playing; + } + catch (FileNotFoundException) + { + } } // Space for error message, should one be wanted/needed. @@ -96,7 +102,7 @@ public void PlayFromPlaylist(string path) _outputDevice.Play(); PlayerStatus = ePlayerStatus.Playing; } - catch (System.IO.FileNotFoundException) + catch (FileNotFoundException) { } } @@ -162,10 +168,7 @@ public void OpenStream(string streamUrl) _outputDevice.Init(mf); _outputDevice.Play(); } - catch (ArgumentException) - { - } - catch (FileNotFoundException) + catch (NullReferenceException) { } } diff --git a/tests/MusicSharpTests/src/PlaylistLoaderTests.cs b/tests/MusicSharpTests/src/PlaylistLoaderTests.cs deleted file mode 100644 index 7815cb4..0000000 --- a/tests/MusicSharpTests/src/PlaylistLoaderTests.cs +++ /dev/null @@ -1,19 +0,0 @@ -// -// Licensed under the GNU GPL v3 License. See LICENSE in the project root for license information. -// - -using MusicSharp.Models; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace MusicSharpTests; - - [TestClass()] - public class PlaylistLoaderTests - { - [TestMethod()] - public void Load_NullPlaylist() - { - // Act and assert - Assert.ThrowsException(() => PlaylistLoader.LoadPlaylist(null)); - } - } \ No newline at end of file diff --git a/tests/MusicSharpTests/MusicSharpTests.csproj b/tests/MusicSharpTestsOld/MusicSharpTestsOld.csproj similarity index 91% rename from tests/MusicSharpTests/MusicSharpTests.csproj rename to tests/MusicSharpTestsOld/MusicSharpTestsOld.csproj index ede7b03..f5d311c 100644 --- a/tests/MusicSharpTests/MusicSharpTests.csproj +++ b/tests/MusicSharpTestsOld/MusicSharpTestsOld.csproj @@ -4,6 +4,8 @@ net7.0 false + + MusicSharpTests diff --git a/tests/MusicSharpTests/src/WinPlayerTests.cs b/tests/MusicSharpTestsOld/src/WinPlayerTests.cs similarity index 100% rename from tests/MusicSharpTests/src/WinPlayerTests.cs rename to tests/MusicSharpTestsOld/src/WinPlayerTests.cs