diff --git a/src/AudioBand.Logging/AudioBand.Logging.csproj b/src/AudioBand.Logging/AudioBand.Logging.csproj
index 6e5a9557..170e0bbd 100644
--- a/src/AudioBand.Logging/AudioBand.Logging.csproj
+++ b/src/AudioBand.Logging/AudioBand.Logging.csproj
@@ -9,9 +9,10 @@
Properties
AudioBand.Logging
AudioBand.Logging
- v4.6.1
+ v4.7
512
true
+
true
@@ -88,7 +89,7 @@
0.1.4
- 4.6.3
+ 4.6.5
1.1.118
diff --git a/src/AudioBand.Logging/app.config b/src/AudioBand.Logging/app.config
index 74f5bf7e..9ea4dacd 100644
--- a/src/AudioBand.Logging/app.config
+++ b/src/AudioBand.Logging/app.config
@@ -1,15 +1,15 @@
-
+
-
-
+
+
-
-
+
+
-
\ No newline at end of file
+
diff --git a/src/AudioBand.Test/Assets/imgsource.png b/src/AudioBand.Test/Assets/imgsource.png
new file mode 100644
index 00000000..f6512b71
Binary files /dev/null and b/src/AudioBand.Test/Assets/imgsource.png differ
diff --git a/src/AudioBand.Test/AudioBand.Test.csproj b/src/AudioBand.Test/AudioBand.Test.csproj
index 7331766e..b4dca433 100644
--- a/src/AudioBand.Test/AudioBand.Test.csproj
+++ b/src/AudioBand.Test/AudioBand.Test.csproj
@@ -93,18 +93,20 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
@@ -121,24 +123,28 @@
- 4.10.1
-
-
- 1.4.0
-
-
- 1.4.0
+ 4.12.0
- 0.11.0
+ 0.12.0
4.5.2
-
- 4.5.0
+
+ 2.4.1
+
+
+ 2.4.1
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
+ PreserveNewest
+
+
\ No newline at end of file
diff --git a/src/AudioBand.Test/AudioBand.Test.csproj.DotSettings b/src/AudioBand.Test/AudioBand.Test.csproj.DotSettings
new file mode 100644
index 00000000..bf95c7ff
--- /dev/null
+++ b/src/AudioBand.Test/AudioBand.Test.csproj.DotSettings
@@ -0,0 +1,5 @@
+
+ True
+ True
+ True
+ True
\ No newline at end of file
diff --git a/src/AudioBand.Test/ButtonViewModels.cs b/src/AudioBand.Test/ButtonViewModels.cs
deleted file mode 100644
index 59b89fbc..00000000
--- a/src/AudioBand.Test/ButtonViewModels.cs
+++ /dev/null
@@ -1,316 +0,0 @@
-using System;
-using System.Drawing;
-using System.Threading.Tasks;
-using AudioBand.AudioSource;
-using AudioBand.Models;
-using AudioBand.Settings;
-using AudioBand.ViewModels;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-
-namespace AudioBand.Test
-{
- [TestClass]
- public class ButtonViewModels
- {
- private Mock _appSettings;
- private Mock _dialog;
-
- [TestInitialize]
- public void TestInit()
- {
- _appSettings = new Mock();
- _dialog = new Mock();
- }
-
- [TestMethod]
- public void NextButtonListensforProfileChanges()
- {
- var first = new NextButton() {Height = 1};
- var second = new NextButton() {Height = 2};
- _appSettings.SetupSequence(m => m.NextButton)
- .Returns(first)
- .Returns(second);
-
- var vm = new NextButtonViewModel(_appSettings.Object, _dialog.Object);
- bool raised = false;
- vm.PropertyChanged += (_, __) => raised = true;
-
- Assert.AreEqual(first.Height, vm.Height);
- _appSettings.Raise(m => m.ProfileChanged += null, EventArgs.Empty);
-
- Assert.IsFalse(vm.IsEditing);
- Assert.IsTrue(raised);
- Assert.AreEqual(second.Height, vm.Height);
- }
-
-
- [TestMethod]
- public async Task NextButtonCommandCallsNextTrack()
- {
- _appSettings.SetupGet(m => m.NextButton).Returns(new NextButton());
- var vm = new NextButtonViewModel(_appSettings.Object, _dialog.Object);
- var audioSourceMock = new Mock();
- audioSourceMock.Setup(m => m.NextTrackAsync()).Returns(Task.CompletedTask);
- vm.AudioSource = audioSourceMock.Object;
-
- await vm.NextTrackCommand.ExecuteAsync(null);
- audioSourceMock.Verify(m => m.NextTrackAsync());
- }
-
- [TestMethod]
- public void PlayPauseButtonListensForProfileChanges()
- {
- var first = new PlayPauseButton() {Height = 1};
- var second = new PlayPauseButton() {Height = 2};
- _appSettings.SetupSequence(m => m.PlayPauseButton)
- .Returns(first)
- .Returns(second);
-
- var vm = new PlayPauseButtonViewModel(_appSettings.Object, _dialog.Object);
- bool raised = false;
- vm.PropertyChanged += (_, __) => raised = true;
-
- Assert.AreEqual(first.Height, vm.Height);
- _appSettings.Raise(m => m.ProfileChanged += null, EventArgs.Empty);
-
- Assert.IsFalse(vm.IsEditing);
- Assert.IsTrue(raised);
- Assert.AreEqual(second.Height, vm.Height);
- }
-
- [TestMethod]
- public void PlayPauseButtonMarkedAsEditingWhenContentIsEdited()
- {
- _appSettings.SetupGet(m => m.PlayPauseButton).Returns(new PlayPauseButton());
- var viewModel = new PlayPauseButtonViewModel(_appSettings.Object, _dialog.Object);
-
- viewModel.PlayContent.Text = "";
- Assert.IsTrue(viewModel.PlayContent.IsEditing);
- Assert.IsTrue(viewModel.IsEditing);
-
- viewModel.EndEdit();
- Assert.IsFalse(viewModel.IsEditing);
- Assert.IsFalse(viewModel.PlayContent.IsEditing);
-
- viewModel.PauseContent.Text = "";
- Assert.IsTrue(viewModel.IsEditing);
- Assert.IsTrue(viewModel.PauseContent.IsEditing);
- }
-
- [TestMethod]
- public void PlayPauseButtonListensToAudioSource()
- {
- _appSettings.SetupGet(m => m.PlayPauseButton).Returns(new PlayPauseButton());
- var viewModel = new PlayPauseButtonViewModel(_appSettings.Object, _dialog.Object);
- var audioSourceMock = new Mock();
-
- viewModel.AudioSource = audioSourceMock.Object;
-
- audioSourceMock.Raise(m => m.IsPlayingChanged += null, null, true);
- Assert.IsTrue(viewModel.IsPlaying);
- Assert.IsFalse(viewModel.IsPlayButtonShown);
-
- audioSourceMock.Raise(m => m.IsPlayingChanged += null, null, false);
- Assert.IsFalse(viewModel.IsPlaying);
- Assert.IsTrue(viewModel.IsPlayButtonShown);
- }
-
- [TestMethod]
- public async Task PlayPauseButtonPlayAndPauseCommandWorks()
- {
- _appSettings.SetupGet(m => m.PlayPauseButton).Returns(new PlayPauseButton());
- var viewModel = new PlayPauseButtonViewModel(_appSettings.Object, _dialog.Object);
- var audioSourceMock = new Mock();
- var isPlayingSequence = new[] {true, false};
- var index = 0;
- audioSourceMock.Setup(m => m.PlayTrackAsync())
- .Callback(() => Assert.AreEqual(isPlayingSequence[index++], true))
- .Returns(Task.CompletedTask);
- audioSourceMock.Setup(m => m.PauseTrackAsync())
- .Callback(() => Assert.AreEqual(isPlayingSequence[index++], false))
- .Returns(Task.CompletedTask);
-
- await viewModel.PlayPauseTrackCommand.ExecuteAsync(null);
- audioSourceMock.Raise(m => m.IsPlayingChanged += null, null, true);
- await viewModel.PlayPauseTrackCommand.ExecuteAsync(null);
- }
-
- [TestMethod]
- public void PreviousButtonListensForProfileChanges()
- {
- var first = new PreviousButton() { Height = 1 };
- var second = new PreviousButton() { Height = 2 };
- _appSettings.SetupSequence(m => m.PreviousButton)
- .Returns(first)
- .Returns(second);
-
- var vm = new PreviousButtonViewModel(_appSettings.Object, _dialog.Object);
- bool raised = false;
- vm.PropertyChanged += (_, __) => raised = true;
-
- Assert.AreEqual(first.Height, vm.Height);
- _appSettings.Raise(m => m.ProfileChanged += null, EventArgs.Empty);
-
- Assert.IsFalse(vm.IsEditing);
- Assert.IsTrue(raised);
- Assert.AreEqual(second.Height, vm.Height);
- }
-
- [TestMethod]
- public async Task PreviousButtonCommandCallsPreviousTrack()
- {
- _appSettings.SetupGet(m => m.PreviousButton).Returns(new PreviousButton());
- var vm = new PreviousButtonViewModel(_appSettings.Object, _dialog.Object);
- var audioSourceMock = new Mock();
- audioSourceMock.Setup(m => m.PreviousTrackAsync()).Returns(Task.CompletedTask);
- vm.AudioSource = audioSourceMock.Object;
-
- await vm.PreviousTrackCommand.ExecuteAsync(null);
- audioSourceMock.Verify(m => m.PreviousTrackAsync());
- }
-
- [TestMethod]
- public void RepeatModeButtonListensForProfileChanges()
- {
- var first = new RepeatModeButton() { Height = 1 };
- var second = new RepeatModeButton() { Height = 2 };
- _appSettings.SetupSequence(m => m.RepeatModeButton)
- .Returns(first)
- .Returns(second);
-
- var vm = new RepeatModeButtonViewModel(_appSettings.Object, _dialog.Object);
- bool raised = false;
- vm.PropertyChanged += (_, __) => raised = true;
-
- Assert.AreEqual(first.Height, vm.Height);
- _appSettings.Raise(m => m.ProfileChanged += null, EventArgs.Empty);
-
- Assert.IsFalse(vm.IsEditing);
- Assert.IsTrue(raised);
- Assert.AreEqual(second.Height, vm.Height);
- }
-
- [TestMethod]
- public void RepeatModeButtonMarkedAsEditingWhenContentIsEditing()
- {
- _appSettings.SetupGet(m => m.RepeatModeButton).Returns(new RepeatModeButton());
- var viewModel = new RepeatModeButtonViewModel(_appSettings.Object, _dialog.Object);
-
- Assert.IsFalse(viewModel.RepeatTrackContent.IsEditing);
- Assert.IsFalse(viewModel.IsEditing);
-
- viewModel.RepeatTrackContent.Text = "test";
-
- Assert.IsTrue(viewModel.RepeatTrackContent.IsEditing);
- Assert.IsTrue(viewModel.IsEditing);
- }
-
- [TestMethod]
- public void RepeatModeButtonSubscribesToAudioSource()
- {
- _appSettings.SetupGet(m => m.RepeatModeButton).Returns(new RepeatModeButton());
- var viewModel = new RepeatModeButtonViewModel(_appSettings.Object, _dialog.Object);
- var audiosourceMock = new Mock();
- viewModel.AudioSource = audiosourceMock.Object;
-
- audiosourceMock.Raise(m => m.RepeatModeChanged += null, null, RepeatMode.RepeatTrack);
- Assert.AreEqual(RepeatMode.RepeatTrack, viewModel.RepeatMode);
- }
-
- [TestMethod]
- public async Task RepeatModeButtonCyclesRepeatMode()
- {
- _appSettings.SetupGet(m => m.RepeatModeButton).Returns(new RepeatModeButton());
- var viewModel = new RepeatModeButtonViewModel(_appSettings.Object, _dialog.Object);
- var audiosourceMock = new Mock();
- var repeatSequence = new[] {RepeatMode.RepeatContext, RepeatMode.RepeatTrack, RepeatMode.Off};
- var index = 0;
- audiosourceMock.Setup(m => m.SetRepeatModeAsync(It.IsAny()))
- .Callback((RepeatMode mode) => Assert.AreEqual(repeatSequence[index++], mode))
- .Returns(Task.CompletedTask);
-
- viewModel.AudioSource = audiosourceMock.Object;
-
- Assert.AreEqual(RepeatMode.Off, viewModel.RepeatMode);
- await viewModel.CycleRepeatModeCommand.ExecuteAsync(null);
- audiosourceMock.Raise(m => m.RepeatModeChanged += null, null, RepeatMode.RepeatContext);
- await viewModel.CycleRepeatModeCommand.ExecuteAsync(null);
- audiosourceMock.Raise(m => m.RepeatModeChanged += null, null, RepeatMode.RepeatTrack);
- await viewModel.CycleRepeatModeCommand.ExecuteAsync(null);
- }
-
- [TestMethod]
- public void ShuffleModeButtonListensForProfileChanges()
- {
- var first = new ShuffleModeButton() { Height = 1 };
- var second = new ShuffleModeButton() { Height = 2 };
- _appSettings.SetupSequence(m => m.ShuffleModeButton)
- .Returns(first)
- .Returns(second);
-
- var vm = new ShuffleModeButtonViewModel(_appSettings.Object, _dialog.Object);
- bool raised = false;
- vm.PropertyChanged += (_, __) => raised = true;
-
- Assert.AreEqual(first.Height, vm.Height);
- _appSettings.Raise(m => m.ProfileChanged += null, EventArgs.Empty);
-
- Assert.IsFalse(vm.IsEditing);
- Assert.IsTrue(raised);
- Assert.AreEqual(second.Height, vm.Height);
- }
-
- [TestMethod]
- public void ShuffleModeButtonMarkedAsEditingWhenContentIsEdited()
- {
- _appSettings.SetupGet(m => m.ShuffleModeButton).Returns(new ShuffleModeButton());
- var vm = new ShuffleModeButtonViewModel(_appSettings.Object, _dialog.Object);
-
- vm.ShuffleOnContent.Text = "A";
- Assert.IsTrue(vm.ShuffleOnContent.IsEditing);
- Assert.IsTrue(vm.IsEditing);
-
- vm.EndEdit();
- Assert.IsFalse(vm.ShuffleOnContent.IsEditing);
- Assert.IsFalse(vm.IsEditing);
-
- vm.ShuffleOffContent.Text = "...";
- Assert.IsTrue(vm.ShuffleOffContent.IsEditing);
- Assert.IsTrue(vm.IsEditing);
- }
-
- [TestMethod]
- public void ShuffleModeButtonSubscribesToAudioSource()
- {
- _appSettings.SetupGet(m => m.ShuffleModeButton).Returns(new ShuffleModeButton());
- var vm = new ShuffleModeButtonViewModel(_appSettings.Object, _dialog.Object);
- var audioSourceMock = new Mock();
- vm.AudioSource = audioSourceMock.Object;
-
- audioSourceMock.Raise(m => m.ShuffleChanged += null, null, true);
- Assert.IsTrue(vm.IsShuffleOn);
-
- audioSourceMock.Raise(m => m.ShuffleChanged += null, null, false);
- Assert.IsFalse(vm.IsShuffleOn);
- }
-
- [TestMethod]
- public async Task ShuffleModeButtonCommandTogglesShuffle()
- {
- _appSettings.SetupGet(m => m.ShuffleModeButton).Returns(new ShuffleModeButton());
- var vm = new ShuffleModeButtonViewModel(_appSettings.Object, _dialog.Object);
- var audioSourceMock = new Mock();
- var sequence = new[] {true, false};
- var index = 0;
- audioSourceMock.Setup(m => m.SetShuffleAsync(It.IsAny()))
- .Callback((bool shuffle) => Assert.AreEqual(sequence[index++], shuffle))
- .Returns(Task.CompletedTask);
-
- vm.AudioSource = audioSourceMock.Object;
- await vm.ToggleShuffleCommand.ExecuteAsync(null);
- audioSourceMock.Raise(m => m.ShuffleChanged += null, null, true);
- await vm.ToggleShuffleCommand.ExecuteAsync(null);
- }
- }
-}
diff --git a/src/AudioBand.Test/Settings/SettingsMigrationTests.cs b/src/AudioBand.Test/Settings/SettingsMigrationTests.cs
new file mode 100644
index 00000000..9c28c433
--- /dev/null
+++ b/src/AudioBand.Test/Settings/SettingsMigrationTests.cs
@@ -0,0 +1,503 @@
+using System.Collections.Generic;
+using System.Windows.Media;
+using AudioBand.Models;
+using AudioBand.Settings;
+using AudioBand.Settings.Migrations;
+using AudioBand.Settings.Models.v3;
+using AudioBand.Settings.Models.V1;
+using V1Settings = AudioBand.Settings.Models.V1.AudioBandSettings;
+using V2Settings = AudioBand.Settings.Models.V2.Settings;
+using Nett;
+using Xunit;
+using AudioSourceSetting = AudioBand.Settings.Models.V1.AudioSourceSetting;
+
+namespace AudioBand.Test
+{
+ public class SettingsMigrationTests
+ {
+ [Fact]
+ public void MigrateV1ToV2_Main()
+ {
+ var v1 = new V1Settings()
+ {
+ AudioSource = "test"
+ };
+
+ var v2 = Migration.MigrateSettings(v1, "0.1", "2");
+
+ Assert.Equal("2", v2.Version);
+ Assert.Equal("test", v2.AudioSource);
+ }
+
+ [Fact]
+ public void MigrateV1ToV2_AlbumArtPopup()
+ {
+ var setting = new AlbumArtPopupAppearance
+ {
+ Width = 100,
+ Height = 50,
+ IsVisible = true,
+ Margin = 100,
+ XOffset = 50
+ };
+
+ var v1 = new V1Settings()
+ {
+ AlbumArtPopupAppearance = setting,
+ };
+
+ var v2 = Migration.MigrateSettings(v1, "0.1", "2");
+
+ Assert.Equal(v2.AlbumArtPopupSettings.Width, setting.Width);
+ Assert.Equal(v2.AlbumArtPopupSettings.Height, setting.Height);
+ Assert.Equal(v2.AlbumArtPopupSettings.IsVisible, setting.IsVisible);
+ Assert.Equal(v2.AlbumArtPopupSettings.Margin, setting.Margin);
+ Assert.Equal(v2.AlbumArtPopupSettings.XPosition, setting.XOffset);
+ }
+
+ [Fact]
+ public void MigrateV1ToV2_AlbumArt()
+ {
+ var setting = new AlbumArtAppearance
+ {
+ Width = 10,
+ Height = 10,
+ IsVisible = true,
+ XPosition = 10,
+ YPosition = 10,
+ PlaceholderPath = "test"
+ };
+
+ var v1 = new V1Settings
+ {
+ AlbumArtAppearance = setting
+ };
+
+ var v2 = Migration.MigrateSettings(v1, "0.1", "2");
+
+ Assert.Equal(v2.AlbumArtSettings.Width, setting.Width);
+ Assert.Equal(v2.AlbumArtSettings.Height, setting.Height);
+ Assert.Equal(v2.AlbumArtSettings.IsVisible, setting.IsVisible);
+ Assert.Equal(v2.AlbumArtSettings.XPosition, setting.XPosition);
+ Assert.Equal(v2.AlbumArtSettings.YPosition, setting.YPosition);
+ Assert.Equal(v2.AlbumArtSettings.PlaceholderPath, setting.PlaceholderPath);
+ }
+
+ [Fact]
+ public void MigrateV1ToV2_Audioband()
+ {
+ var setting = new AudioBandAppearance
+ {
+ Height = 20,
+ Width = 50,
+ };
+
+ var v1 = new V1Settings
+ {
+ AudioBandAppearance = setting
+ };
+
+ var v2 = Migration.MigrateSettings(v1, "0.1", "2");
+
+ Assert.Equal(v2.AudioBandSettings.Width, setting.Width);
+ Assert.Equal(v2.AudioBandSettings.Height, setting.Height);
+ }
+
+ [Fact]
+ public void MigrateV1ToV2_NextSong()
+ {
+ var setting = new NextSongButtonAppearance
+ {
+ Width = 20,
+ Height = 20,
+ XPosition = 10,
+ IsVisible = false,
+ YPosition = 30,
+ ImagePath = "path"
+ };
+
+ var v1 = new V1Settings
+ {
+ NextSongButtonAppearance = setting
+ };
+
+ var v2 = Migration.MigrateSettings(v1, "0.1", "2");
+
+ Assert.Equal(v2.NextButtonSettings.Width, setting.Width);
+ Assert.Equal(v2.NextButtonSettings.Height, setting.Height);
+ Assert.Equal(v2.NextButtonSettings.IsVisible, setting.IsVisible);
+ Assert.Equal(v2.NextButtonSettings.XPosition, setting.XPosition);
+ Assert.Equal(v2.NextButtonSettings.YPosition, setting.YPosition);
+ Assert.Equal(v2.NextButtonSettings.ImagePath, setting.ImagePath);
+ }
+
+ [Fact]
+ public void MigrateV1ToV2_AudioSourceSettings()
+ {
+ var setting1 = new AudioSourceSettingsCollection
+ {
+ Name = "test",
+ Settings = new List {new AudioSourceSetting {Name = "key1", Value = "val1"}}
+ };
+
+ var setting2 = new AudioSourceSettingsCollection
+ {
+ Name = "test2",
+ Settings = new List { new AudioSourceSetting { Name = "key2", Value = "val2" } }
+ };
+
+ var settings = new List {setting1,setting2};
+ var v1 = new V1Settings
+ {
+ AudioSourceSettings = settings
+ };
+
+ var v2 = Migration.MigrateSettings(v1, "0.1", "2");
+
+ Assert.Equal(v2.AudioSourceSettings.Count, settings.Count);
+ Assert.Equal(v2.AudioSourceSettings[0].AudioSourceName, setting1.Name);
+ Assert.Equal(v2.AudioSourceSettings[0].Settings.Count, setting1.Settings.Count);
+ Assert.Equal(v2.AudioSourceSettings[0].Settings[0].Name, setting1.Settings[0].Name);
+ Assert.Equal(v2.AudioSourceSettings[0].Settings[0].Value, setting1.Settings[0].Value);
+
+ Assert.Equal(v2.AudioSourceSettings[1].AudioSourceName, setting2.Name);
+ Assert.Equal(v2.AudioSourceSettings[1].Settings.Count, setting2.Settings.Count);
+ Assert.Equal(v2.AudioSourceSettings[1].Settings[0].Name, setting2.Settings[0].Name);
+ Assert.Equal(v2.AudioSourceSettings[1].Settings[0].Value, setting2.Settings[0].Value);
+ }
+
+ [Fact]
+ public void MigrateV1ToV2_PlayPauseButton()
+ {
+ var setting = new PlayPauseButtonAppearance
+ {
+ Width = 1,
+ Height = 2,
+ XPosition = 3,
+ IsVisible = true,
+ YPosition = 4,
+ PauseButtonImagePath = "pause",
+ PlayButtonImagePath = "play"
+ };
+
+ var v1 = new V1Settings {PlayPauseButtonAppearance = setting};
+ var v2 = Migration.MigrateSettings(v1, "0.1", "2");
+
+ Assert.Equal(v2.PlayPauseButtonSettings.Width, setting.Width);
+ Assert.Equal(v2.PlayPauseButtonSettings.Height, setting.Height);
+ Assert.Equal(v2.PlayPauseButtonSettings.XPosition, setting.XPosition);
+ Assert.Equal(v2.PlayPauseButtonSettings.YPosition, setting.YPosition);
+ Assert.Equal(v2.PlayPauseButtonSettings.IsVisible, setting.IsVisible);
+ Assert.Equal(v2.PlayPauseButtonSettings.PauseButtonImagePath, setting.PauseButtonImagePath);
+ Assert.Equal(v2.PlayPauseButtonSettings.PlayButtonImagePath, setting.PlayButtonImagePath);
+ }
+
+ [Fact]
+ public void MigrateV1ToV2_PreviousButton()
+ {
+ var setting = new PreviousSongButtonAppearance
+ {
+ Width = 1,
+ Height = 2,
+ XPosition = 3,
+ IsVisible = true,
+ YPosition = 4,
+ ImagePath = "path"
+ };
+
+ var v1 = new V1Settings {PreviousSongButtonAppearance = setting};
+ var v2 = Migration.MigrateSettings(v1, "0.1", "2");
+
+ Assert.Equal(v2.PreviousButtonSettings.Height, setting.Height);
+ Assert.Equal(v2.PreviousButtonSettings.Width, setting.Width);
+ Assert.Equal(v2.PreviousButtonSettings.XPosition, setting.XPosition);
+ Assert.Equal(v2.PreviousButtonSettings.YPosition, setting.YPosition);
+ Assert.Equal(v2.PreviousButtonSettings.IsVisible, setting.IsVisible);
+ Assert.Equal(v2.PreviousButtonSettings.ImagePath, setting.ImagePath);
+ }
+
+ [Fact]
+ public void MigrateV1ToV2_ProgressBar()
+ {
+ var setting = new ProgressBarAppearance
+ {
+ Height = 1,
+ Width = 2,
+ XPosition = 3,
+ IsVisible = false,
+ YPosition = 5,
+ BackgroundColor = Colors.White,
+ ForegroundColor = Colors.Red,
+ };
+
+ var v1 = new V1Settings {ProgressBarAppearance = setting};
+ var v2 = Migration.MigrateSettings(v1, "0.1", "2");
+
+ Assert.Equal(v2.ProgressBarSettings.Width, setting.Width);
+ Assert.Equal(v2.ProgressBarSettings.Height, setting.Height);
+ Assert.Equal(v2.ProgressBarSettings.XPosition, setting.XPosition);
+ Assert.Equal(v2.ProgressBarSettings.YPosition, setting.YPosition);
+ Assert.Equal(v2.ProgressBarSettings.IsVisible, setting.IsVisible);
+ Assert.Equal(v2.ProgressBarSettings.BackgroundColor, setting.BackgroundColor);
+ Assert.Equal(v2.ProgressBarSettings.ForegroundColor, setting.ForegroundColor);
+ }
+
+ [Fact]
+ public void MigrateV1ToV2_CustomText()
+ {
+ var text1 = new TextAppearance
+ {
+ Color = Colors.Red,
+ Width = 1,
+ Height = 2,
+ Name = "test",
+ XPosition = 4,
+ IsVisible = true,
+ YPosition = 10,
+ ScrollSpeed = 20,
+ FontSize = 1f,
+ FontFamily = "family",
+ Alignment = CustomLabel.TextAlignment.Center,
+ FormatString = "123",
+ };
+
+ var texts = new List() {text1};
+ var v1 = new V1Settings {TextAppearances = texts};
+ var v2 = Migration.MigrateSettings(v1, "0.1", "2");
+
+ Assert.Equal(v2.CustomLabelSettings.Count, texts.Count);
+ Assert.Equal(v2.CustomLabelSettings[0].Color, text1.Color);
+ Assert.Equal(v2.CustomLabelSettings[0].Width, text1.Width);
+ Assert.Equal(v2.CustomLabelSettings[0].Height, text1.Height);
+ Assert.Equal(v2.CustomLabelSettings[0].Name, text1.Name);
+ Assert.Equal(v2.CustomLabelSettings[0].XPosition, text1.XPosition);
+ Assert.Equal(v2.CustomLabelSettings[0].IsVisible, text1.IsVisible);
+ Assert.Equal(v2.CustomLabelSettings[0].YPosition, text1.YPosition);
+ Assert.Equal(v2.CustomLabelSettings[0].ScrollSpeed, text1.ScrollSpeed);
+ Assert.Equal(v2.CustomLabelSettings[0].FontSize, text1.FontSize);
+ Assert.Equal(v2.CustomLabelSettings[0].FontFamily, text1.FontFamily);
+ Assert.Equal(v2.CustomLabelSettings[0].Alignment, text1.Alignment);
+ Assert.Equal(v2.CustomLabelSettings[0].FormatString, text1.FormatString);
+ }
+
+ [Fact]
+ public void MigrateV2ToV3_MigratesSuccessfully()
+ {
+ string settingsFile = @"Version = ""2""
+AudioSource = ""Spotify""
+
+[AudioBandSettings]
+Width = 500
+Height = 30
+
+[PreviousButtonSettings]
+ImagePath = """"
+IsVisible = false
+Width = 73
+Height = 12
+XPosition = 30
+YPosition = 15
+
+[PlayPauseButtonSettings]
+PlayButtonImagePath = """"
+PauseButtonImagePath = """"
+XPosition = 109
+YPosition = 15
+Width = 73
+Height = 12
+IsVisible = false
+
+[NextButtonSettings]
+ImagePath = """"
+IsVisible = false
+Width = 73
+Height = 12
+XPosition = 176
+YPosition = 15
+
+[ProgressBarSettings]
+ForegroundColor = ""#32ABCD""
+BackgroundColor = ""#232323""
+IsVisible = true
+XPosition = 330
+YPosition = 24
+Width = 130
+Height = 3
+
+[AlbumArtSettings]
+IsVisible = true
+Width = 30
+Height = 30
+XPosition = 260
+YPosition = 0
+PlaceholderPath = """"
+
+[AlbumArtPopupSettings]
+IsVisible = true
+Width = 300
+Height = 300
+XPosition = 125
+Margin = 4
+
+[[CustomLabelSettings]]
+IsVisible = true
+Width = 200
+Height = 20
+XPosition = 295
+YPosition = 0
+FontFamily = ""Segoe UI""
+FontSize = 11.0
+Color = ""#FFFFFF""
+FormatString = ""{*song}""
+Alignment = ""Center""
+Name = ""Song""
+ScrollSpeed = 50
+[[CustomLabelSettings]]
+IsVisible = true
+Width = 34
+Height = 12
+XPosition = 292
+YPosition = 17
+FontFamily = ""Segoe UI""
+FontSize = 8.0
+Color = ""#C3C3C3""
+FormatString = ""{time}""
+Alignment = ""Left""
+Name = ""Time""
+ScrollSpeed = 50
+[[CustomLabelSettings]]
+IsVisible = true
+Width = 35
+Height = 12
+XPosition = 460
+YPosition = 17
+FontFamily = ""Segoe UI""
+FontSize = 8.0
+Color = ""#C3C3C3""
+FormatString = ""{length}""
+Alignment = ""Right""
+Name = ""Song Length""
+ScrollSpeed = 50
+[[CustomLabelSettings]]
+IsVisible = true
+Width = 260
+Height = 15
+XPosition = 0
+YPosition = 0
+FontFamily = ""Segoe UI""
+FontSize = 9.0
+Color = ""White""
+FormatString = ""{artist}""
+Alignment = ""Right""
+Name = ""Artist""
+ScrollSpeed = 50
+[[CustomLabelSettings]]
+IsVisible = true
+Width = 260
+Height = 15
+XPosition = 0
+YPosition = 15
+FontFamily = ""Segoe UI""
+FontSize = 9.0
+Color = ""#AFAFAF""
+FormatString = ""{album}""
+Alignment = ""Right""
+Name = ""Album""
+ScrollSpeed = 50
+
+[[AudioSourceSettings]]
+AudioSourceName = ""Spotify""
+
+[[AudioSourceSettings.Settings]]
+Name = ""Spotify Client ID""
+Value = ""id""
+[[AudioSourceSettings.Settings]]
+Name = ""Spotify Client secret""
+Value = ""secret""
+";
+ var settings = TomlSettings.Create(cfg =>
+ {
+ cfg.ConfigureType(type => type.WithConversionFor(convert => convert
+ .ToToml(SerializationConversions.ColorToString)
+ .FromToml(tomlString => SerializationConversions.StringToColor(tomlString.Value))));
+ cfg.ConfigureType(type => type.WithConversionFor(convert => convert
+ .ToToml(SerializationConversions.EnumToString)
+ .FromToml(str => SerializationConversions.StringToEnum(str.Value))));
+ cfg.ConfigureType(type => type.WithConversionFor(c => c
+ .FromToml(tml => tml.Value)));
+ });
+
+ var v2 = Toml.ReadString(settingsFile, settings);
+ var v3 = Migration.MigrateSettings(v2, "2", "3");
+
+ Assert.Equal("3", v3.Version);
+ Assert.Equal(v2.AudioSource, v3.AudioSource);
+
+ Assert.Equal(v2.AlbumArtPopupSettings.Width, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtPopupSettings.Width);
+ Assert.Equal(v2.AlbumArtPopupSettings.Height, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtPopupSettings.Height);
+ Assert.Equal(v2.AlbumArtPopupSettings.IsVisible, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtPopupSettings.IsVisible);
+ Assert.Equal(v2.AlbumArtPopupSettings.Margin, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtPopupSettings.Margin);
+ Assert.Equal(v2.AlbumArtPopupSettings.XPosition, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtPopupSettings.XPosition);
+
+ Assert.Equal(v2.AlbumArtSettings.Width, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtSettings.Width);
+ Assert.Equal(v2.AlbumArtSettings.Height, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtSettings.Height);
+ Assert.Equal(v2.AlbumArtSettings.IsVisible, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtSettings.IsVisible);
+ Assert.Equal(v2.AlbumArtSettings.XPosition, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtSettings.XPosition);
+ Assert.Equal(v2.AlbumArtSettings.YPosition, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtSettings.YPosition);
+ Assert.Equal(v2.AlbumArtSettings.PlaceholderPath, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtSettings.PlaceholderPath);
+
+ Assert.Equal(v2.AudioBandSettings.Width, v3.Profiles[SettingsV3.DefaultProfileName].AudioBandSettings.Width);
+ Assert.Equal(v2.AudioBandSettings.Height, v3.Profiles[SettingsV3.DefaultProfileName].AudioBandSettings.Height);
+
+ Assert.Equal(v2.NextButtonSettings.Width, v3.Profiles[SettingsV3.DefaultProfileName].NextButtonSettings.Width);
+ Assert.Equal(v2.NextButtonSettings.Height, v3.Profiles[SettingsV3.DefaultProfileName].NextButtonSettings.Height);
+ Assert.Equal(v2.NextButtonSettings.IsVisible, v3.Profiles[SettingsV3.DefaultProfileName].NextButtonSettings.IsVisible);
+ Assert.Equal(v2.NextButtonSettings.XPosition, v3.Profiles[SettingsV3.DefaultProfileName].NextButtonSettings.XPosition);
+ Assert.Equal(v2.NextButtonSettings.YPosition, v3.Profiles[SettingsV3.DefaultProfileName].NextButtonSettings.YPosition);
+ Assert.Equal(v2.NextButtonSettings.ImagePath, v3.Profiles[SettingsV3.DefaultProfileName].NextButtonSettings.Content.ImagePath);
+
+ Assert.Equal(v2.AudioSourceSettings.Count, v3.AudioSourceSettings.Count);
+ Assert.Equal(v2.AudioSourceSettings[0].AudioSourceName, v3.AudioSourceSettings[0].AudioSourceName);
+ Assert.Equal(v2.AudioSourceSettings[0].Settings.Count, v3.AudioSourceSettings[0].Settings.Count);
+ Assert.Equal(v2.AudioSourceSettings[0].Settings[0].Name, v3.AudioSourceSettings[0].Settings[0].Name);
+ Assert.Equal(v2.AudioSourceSettings[0].Settings[0].Value, v3.AudioSourceSettings[0].Settings[0].Value);
+
+ Assert.Equal(v2.PlayPauseButtonSettings.Width, v3.Profiles[SettingsV3.DefaultProfileName].PlayPauseButtonSettings.Width);
+ Assert.Equal(v2.PlayPauseButtonSettings.Height, v3.Profiles[SettingsV3.DefaultProfileName].PlayPauseButtonSettings.Height);
+ Assert.Equal(v2.PlayPauseButtonSettings.XPosition, v3.Profiles[SettingsV3.DefaultProfileName].PlayPauseButtonSettings.XPosition);
+ Assert.Equal(v2.PlayPauseButtonSettings.YPosition, v3.Profiles[SettingsV3.DefaultProfileName].PlayPauseButtonSettings.YPosition);
+ Assert.Equal(v2.PlayPauseButtonSettings.IsVisible, v3.Profiles[SettingsV3.DefaultProfileName].PlayPauseButtonSettings.IsVisible);
+ Assert.Equal(v2.PlayPauseButtonSettings.PauseButtonImagePath, v3.Profiles[SettingsV3.DefaultProfileName].PlayPauseButtonSettings.PauseContent.ImagePath);
+ Assert.Equal(v2.PlayPauseButtonSettings.PlayButtonImagePath, v3.Profiles[SettingsV3.DefaultProfileName].PlayPauseButtonSettings.PlayContent.ImagePath);
+
+ Assert.Equal(v2.PreviousButtonSettings.Height, v3.Profiles[SettingsV3.DefaultProfileName].PreviousButtonSettings.Height);
+ Assert.Equal(v2.PreviousButtonSettings.Width, v3.Profiles[SettingsV3.DefaultProfileName].PreviousButtonSettings.Width);
+ Assert.Equal(v2.PreviousButtonSettings.XPosition, v3.Profiles[SettingsV3.DefaultProfileName].PreviousButtonSettings.XPosition);
+ Assert.Equal(v2.PreviousButtonSettings.YPosition, v3.Profiles[SettingsV3.DefaultProfileName].PreviousButtonSettings.YPosition);
+ Assert.Equal(v2.PreviousButtonSettings.IsVisible, v3.Profiles[SettingsV3.DefaultProfileName].PreviousButtonSettings.IsVisible);
+ Assert.Equal(v2.PreviousButtonSettings.ImagePath, v3.Profiles[SettingsV3.DefaultProfileName].PreviousButtonSettings.Content.ImagePath);
+
+ Assert.Equal(v2.ProgressBarSettings.Width, v3.Profiles[SettingsV3.DefaultProfileName].ProgressBarSettings.Width);
+ Assert.Equal(v2.ProgressBarSettings.Height, v3.Profiles[SettingsV3.DefaultProfileName].ProgressBarSettings.Height);
+ Assert.Equal(v2.ProgressBarSettings.XPosition, v3.Profiles[SettingsV3.DefaultProfileName].ProgressBarSettings.XPosition);
+ Assert.Equal(v2.ProgressBarSettings.YPosition, v3.Profiles[SettingsV3.DefaultProfileName].ProgressBarSettings.YPosition);
+ Assert.Equal(v2.ProgressBarSettings.IsVisible, v3.Profiles[SettingsV3.DefaultProfileName].ProgressBarSettings.IsVisible);
+ Assert.Equal(v2.ProgressBarSettings.BackgroundColor, v3.Profiles[SettingsV3.DefaultProfileName].ProgressBarSettings.BackgroundColor);
+ Assert.Equal(v2.ProgressBarSettings.ForegroundColor, v3.Profiles[SettingsV3.DefaultProfileName].ProgressBarSettings.ForegroundColor);
+
+ Assert.Equal(v2.CustomLabelSettings.Count, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings.Count);
+ Assert.Equal(v2.CustomLabelSettings[0].Color, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].Color);
+ Assert.Equal(v2.CustomLabelSettings[0].Width, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].Width);
+ Assert.Equal(v2.CustomLabelSettings[0].Height, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].Height);
+ Assert.Equal(v2.CustomLabelSettings[0].Name, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].Name);
+ Assert.Equal(v2.CustomLabelSettings[0].XPosition, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].XPosition);
+ Assert.Equal(v2.CustomLabelSettings[0].IsVisible, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].IsVisible);
+ Assert.Equal(v2.CustomLabelSettings[0].YPosition, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].YPosition);
+ Assert.Equal(v2.CustomLabelSettings[0].ScrollSpeed, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].ScrollSpeed);
+ Assert.Equal(v2.CustomLabelSettings[0].FontSize, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].FontSize);
+ Assert.Equal(v2.CustomLabelSettings[0].FontFamily, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].FontFamily);
+ Assert.Equal(v2.CustomLabelSettings[0].Alignment, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].Alignment);
+ Assert.Equal(v2.CustomLabelSettings[0].FormatString, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].FormatString);
+ }
+ }
+}
diff --git a/src/AudioBand.Test/SettingsMigrationTests.cs b/src/AudioBand.Test/SettingsMigrationTests.cs
deleted file mode 100644
index e9c82729..00000000
--- a/src/AudioBand.Test/SettingsMigrationTests.cs
+++ /dev/null
@@ -1,505 +0,0 @@
-using System.Collections.Generic;
-using System.Drawing;
-using System.Windows.Media;
-using AudioBand.Models;
-using AudioBand.Settings;
-using AudioBand.Settings.Migrations;
-using AudioBand.Settings.Models.v3;
-using AudioBand.Settings.Models.V1;
-using V1Settings = AudioBand.Settings.Models.V1.AudioBandSettings;
-using V2Settings = AudioBand.Settings.Models.V2.Settings;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Nett;
-using AudioSourceSetting = AudioBand.Settings.Models.V1.AudioSourceSetting;
-
-namespace AudioBand.Test
-{
- [TestClass]
- public class SettingsMigrationTests
- {
- [TestMethod]
- public void MigrateV1ToV2_Main()
- {
- var v1 = new V1Settings()
- {
- AudioSource = "test"
- };
-
- var v2 = Migration.MigrateSettings(v1, "0.1", "2");
-
- Assert.AreEqual(v2.Version, "2");
- Assert.AreEqual(v2.AudioSource, "test");
- }
-
- [TestMethod]
- public void MigrateV1ToV2_AlbumArtPopup()
- {
- var setting = new AlbumArtPopupAppearance
- {
- Width = 100,
- Height = 50,
- IsVisible = true,
- Margin = 100,
- XOffset = 50
- };
-
- var v1 = new V1Settings()
- {
- AlbumArtPopupAppearance = setting,
- };
-
- var v2 = Migration.MigrateSettings(v1, "0.1", "2");
-
- Assert.AreEqual(v2.AlbumArtPopupSettings.Width, setting.Width);
- Assert.AreEqual(v2.AlbumArtPopupSettings.Height, setting.Height);
- Assert.AreEqual(v2.AlbumArtPopupSettings.IsVisible, setting.IsVisible);
- Assert.AreEqual(v2.AlbumArtPopupSettings.Margin, setting.Margin);
- Assert.AreEqual(v2.AlbumArtPopupSettings.XPosition, setting.XOffset);
- }
-
- [TestMethod]
- public void MigrateV1ToV2_AlbumArt()
- {
- var setting = new AlbumArtAppearance
- {
- Width = 10,
- Height = 10,
- IsVisible = true,
- XPosition = 10,
- YPosition = 10,
- PlaceholderPath = "test"
- };
-
- var v1 = new V1Settings
- {
- AlbumArtAppearance = setting
- };
-
- var v2 = Migration.MigrateSettings(v1, "0.1", "2");
-
- Assert.AreEqual(v2.AlbumArtSettings.Width, setting.Width);
- Assert.AreEqual(v2.AlbumArtSettings.Height, setting.Height);
- Assert.AreEqual(v2.AlbumArtSettings.IsVisible, setting.IsVisible);
- Assert.AreEqual(v2.AlbumArtSettings.XPosition, setting.XPosition);
- Assert.AreEqual(v2.AlbumArtSettings.YPosition, setting.YPosition);
- Assert.AreEqual(v2.AlbumArtSettings.PlaceholderPath, setting.PlaceholderPath);
- }
-
- [TestMethod]
- public void MigrateV1ToV2_Audioband()
- {
- var setting = new AudioBandAppearance
- {
- Height = 20,
- Width = 50,
- };
-
- var v1 = new V1Settings
- {
- AudioBandAppearance = setting
- };
-
- var v2 = Migration.MigrateSettings(v1, "0.1", "2");
-
- Assert.AreEqual(v2.AudioBandSettings.Width, setting.Width);
- Assert.AreEqual(v2.AudioBandSettings.Height, setting.Height);
- }
-
- [TestMethod]
- public void MigrateV1ToV2_NextSong()
- {
- var setting = new NextSongButtonAppearance
- {
- Width = 20,
- Height = 20,
- XPosition = 10,
- IsVisible = false,
- YPosition = 30,
- ImagePath = "path"
- };
-
- var v1 = new V1Settings
- {
- NextSongButtonAppearance = setting
- };
-
- var v2 = Migration.MigrateSettings(v1, "0.1", "2");
-
- Assert.AreEqual(v2.NextButtonSettings.Width, setting.Width);
- Assert.AreEqual(v2.NextButtonSettings.Height, setting.Height);
- Assert.AreEqual(v2.NextButtonSettings.IsVisible, setting.IsVisible);
- Assert.AreEqual(v2.NextButtonSettings.XPosition, setting.XPosition);
- Assert.AreEqual(v2.NextButtonSettings.YPosition, setting.YPosition);
- Assert.AreEqual(v2.NextButtonSettings.ImagePath, setting.ImagePath);
- }
-
- [TestMethod]
- public void MigrateV1ToV2_AudioSourceSettings()
- {
- var setting1 = new AudioSourceSettingsCollection
- {
- Name = "test",
- Settings = new List {new AudioSourceSetting {Name = "key1", Value = "val1"}}
- };
-
- var setting2 = new AudioSourceSettingsCollection
- {
- Name = "test2",
- Settings = new List { new AudioSourceSetting { Name = "key2", Value = "val2" } }
- };
-
- var settings = new List {setting1,setting2};
- var v1 = new V1Settings
- {
- AudioSourceSettings = settings
- };
-
- var v2 = Migration.MigrateSettings(v1, "0.1", "2");
-
- Assert.AreEqual(v2.AudioSourceSettings.Count, settings.Count);
- Assert.AreEqual(v2.AudioSourceSettings[0].AudioSourceName, setting1.Name);
- Assert.AreEqual(v2.AudioSourceSettings[0].Settings.Count, setting1.Settings.Count);
- Assert.AreEqual(v2.AudioSourceSettings[0].Settings[0].Name, setting1.Settings[0].Name);
- Assert.AreEqual(v2.AudioSourceSettings[0].Settings[0].Value, setting1.Settings[0].Value);
-
- Assert.AreEqual(v2.AudioSourceSettings[1].AudioSourceName, setting2.Name);
- Assert.AreEqual(v2.AudioSourceSettings[1].Settings.Count, setting2.Settings.Count);
- Assert.AreEqual(v2.AudioSourceSettings[1].Settings[0].Name, setting2.Settings[0].Name);
- Assert.AreEqual(v2.AudioSourceSettings[1].Settings[0].Value, setting2.Settings[0].Value);
- }
-
- [TestMethod]
- public void MigrateV1ToV2_PlayPauseButton()
- {
- var setting = new PlayPauseButtonAppearance
- {
- Width = 1,
- Height = 2,
- XPosition = 3,
- IsVisible = true,
- YPosition = 4,
- PauseButtonImagePath = "pause",
- PlayButtonImagePath = "play"
- };
-
- var v1 = new V1Settings {PlayPauseButtonAppearance = setting};
- var v2 = Migration.MigrateSettings(v1, "0.1", "2");
-
- Assert.AreEqual(v2.PlayPauseButtonSettings.Width, setting.Width);
- Assert.AreEqual(v2.PlayPauseButtonSettings.Height, setting.Height);
- Assert.AreEqual(v2.PlayPauseButtonSettings.XPosition, setting.XPosition);
- Assert.AreEqual(v2.PlayPauseButtonSettings.YPosition, setting.YPosition);
- Assert.AreEqual(v2.PlayPauseButtonSettings.IsVisible, setting.IsVisible);
- Assert.AreEqual(v2.PlayPauseButtonSettings.PauseButtonImagePath, setting.PauseButtonImagePath);
- Assert.AreEqual(v2.PlayPauseButtonSettings.PlayButtonImagePath, setting.PlayButtonImagePath);
- }
-
- [TestMethod]
- public void MigrateV1ToV2_PreviousButton()
- {
- var setting = new PreviousSongButtonAppearance
- {
- Width = 1,
- Height = 2,
- XPosition = 3,
- IsVisible = true,
- YPosition = 4,
- ImagePath = "path"
- };
-
- var v1 = new V1Settings {PreviousSongButtonAppearance = setting};
- var v2 = Migration.MigrateSettings(v1, "0.1", "2");
-
- Assert.AreEqual(v2.PreviousButtonSettings.Height, setting.Height);
- Assert.AreEqual(v2.PreviousButtonSettings.Width, setting.Width);
- Assert.AreEqual(v2.PreviousButtonSettings.XPosition, setting.XPosition);
- Assert.AreEqual(v2.PreviousButtonSettings.YPosition, setting.YPosition);
- Assert.AreEqual(v2.PreviousButtonSettings.IsVisible, setting.IsVisible);
- Assert.AreEqual(v2.PreviousButtonSettings.ImagePath, setting.ImagePath);
- }
-
- [TestMethod]
- public void MigrateV1ToV2_ProgressBar()
- {
- var setting = new ProgressBarAppearance
- {
- Height = 1,
- Width = 2,
- XPosition = 3,
- IsVisible = false,
- YPosition = 5,
- BackgroundColor = Colors.White,
- ForegroundColor = Colors.Red,
- };
-
- var v1 = new V1Settings {ProgressBarAppearance = setting};
- var v2 = Migration.MigrateSettings(v1, "0.1", "2");
-
- Assert.AreEqual(v2.ProgressBarSettings.Width, setting.Width);
- Assert.AreEqual(v2.ProgressBarSettings.Height, setting.Height);
- Assert.AreEqual(v2.ProgressBarSettings.XPosition, setting.XPosition);
- Assert.AreEqual(v2.ProgressBarSettings.YPosition, setting.YPosition);
- Assert.AreEqual(v2.ProgressBarSettings.IsVisible, setting.IsVisible);
- Assert.AreEqual(v2.ProgressBarSettings.BackgroundColor, setting.BackgroundColor);
- Assert.AreEqual(v2.ProgressBarSettings.ForegroundColor, setting.ForegroundColor);
- }
-
- [TestMethod]
- public void MigrateV1ToV2_CustomText()
- {
- var text1 = new TextAppearance
- {
- Color = Colors.Red,
- Width = 1,
- Height = 2,
- Name = "test",
- XPosition = 4,
- IsVisible = true,
- YPosition = 10,
- ScrollSpeed = 20,
- FontSize = 1f,
- FontFamily = "family",
- Alignment = CustomLabel.TextAlignment.Center,
- FormatString = "123",
- };
-
- var texts = new List() {text1};
- var v1 = new V1Settings {TextAppearances = texts};
- var v2 = Migration.MigrateSettings(v1, "0.1", "2");
-
- Assert.AreEqual(v2.CustomLabelSettings.Count, texts.Count);
- Assert.AreEqual(v2.CustomLabelSettings[0].Color, text1.Color);
- Assert.AreEqual(v2.CustomLabelSettings[0].Width, text1.Width);
- Assert.AreEqual(v2.CustomLabelSettings[0].Height, text1.Height);
- Assert.AreEqual(v2.CustomLabelSettings[0].Name, text1.Name);
- Assert.AreEqual(v2.CustomLabelSettings[0].XPosition, text1.XPosition);
- Assert.AreEqual(v2.CustomLabelSettings[0].IsVisible, text1.IsVisible);
- Assert.AreEqual(v2.CustomLabelSettings[0].YPosition, text1.YPosition);
- Assert.AreEqual(v2.CustomLabelSettings[0].ScrollSpeed, text1.ScrollSpeed);
- Assert.AreEqual(v2.CustomLabelSettings[0].FontSize, text1.FontSize);
- Assert.AreEqual(v2.CustomLabelSettings[0].FontFamily, text1.FontFamily);
- Assert.AreEqual(v2.CustomLabelSettings[0].Alignment, text1.Alignment);
- Assert.AreEqual(v2.CustomLabelSettings[0].FormatString, text1.FormatString);
- }
-
- [TestMethod]
- public void MigrateV2ToV3()
- {
- string settingsFile = @"Version = ""2""
-AudioSource = ""Spotify""
-
-[AudioBandSettings]
-Width = 500
-Height = 30
-
-[PreviousButtonSettings]
-ImagePath = """"
-IsVisible = false
-Width = 73
-Height = 12
-XPosition = 30
-YPosition = 15
-
-[PlayPauseButtonSettings]
-PlayButtonImagePath = """"
-PauseButtonImagePath = """"
-XPosition = 109
-YPosition = 15
-Width = 73
-Height = 12
-IsVisible = false
-
-[NextButtonSettings]
-ImagePath = """"
-IsVisible = false
-Width = 73
-Height = 12
-XPosition = 176
-YPosition = 15
-
-[ProgressBarSettings]
-ForegroundColor = ""#32ABCD""
-BackgroundColor = ""#232323""
-IsVisible = true
-XPosition = 330
-YPosition = 24
-Width = 130
-Height = 3
-
-[AlbumArtSettings]
-IsVisible = true
-Width = 30
-Height = 30
-XPosition = 260
-YPosition = 0
-PlaceholderPath = """"
-
-[AlbumArtPopupSettings]
-IsVisible = true
-Width = 300
-Height = 300
-XPosition = 125
-Margin = 4
-
-[[CustomLabelSettings]]
-IsVisible = true
-Width = 200
-Height = 20
-XPosition = 295
-YPosition = 0
-FontFamily = ""Segoe UI""
-FontSize = 11.0
-Color = ""#FFFFFF""
-FormatString = ""{*song}""
-Alignment = ""Center""
-Name = ""Song""
-ScrollSpeed = 50
-[[CustomLabelSettings]]
-IsVisible = true
-Width = 34
-Height = 12
-XPosition = 292
-YPosition = 17
-FontFamily = ""Segoe UI""
-FontSize = 8.0
-Color = ""#C3C3C3""
-FormatString = ""{time}""
-Alignment = ""Left""
-Name = ""Time""
-ScrollSpeed = 50
-[[CustomLabelSettings]]
-IsVisible = true
-Width = 35
-Height = 12
-XPosition = 460
-YPosition = 17
-FontFamily = ""Segoe UI""
-FontSize = 8.0
-Color = ""#C3C3C3""
-FormatString = ""{length}""
-Alignment = ""Right""
-Name = ""Song Length""
-ScrollSpeed = 50
-[[CustomLabelSettings]]
-IsVisible = true
-Width = 260
-Height = 15
-XPosition = 0
-YPosition = 0
-FontFamily = ""Segoe UI""
-FontSize = 9.0
-Color = ""White""
-FormatString = ""{artist}""
-Alignment = ""Right""
-Name = ""Artist""
-ScrollSpeed = 50
-[[CustomLabelSettings]]
-IsVisible = true
-Width = 260
-Height = 15
-XPosition = 0
-YPosition = 15
-FontFamily = ""Segoe UI""
-FontSize = 9.0
-Color = ""#AFAFAF""
-FormatString = ""{album}""
-Alignment = ""Right""
-Name = ""Album""
-ScrollSpeed = 50
-
-[[AudioSourceSettings]]
-AudioSourceName = ""Spotify""
-
-[[AudioSourceSettings.Settings]]
-Name = ""Spotify Client ID""
-Value = ""id""
-[[AudioSourceSettings.Settings]]
-Name = ""Spotify Client secret""
-Value = ""secret""
-";
- var settings = TomlSettings.Create(cfg =>
- {
- cfg.ConfigureType(type => type.WithConversionFor(convert => convert
- .ToToml(SerializationConversions.ColorToString)
- .FromToml(tomlString => SerializationConversions.StringToColor(tomlString.Value))));
- cfg.ConfigureType(type => type.WithConversionFor(convert => convert
- .ToToml(SerializationConversions.EnumToString)
- .FromToml(str => SerializationConversions.StringToEnum(str.Value))));
- cfg.ConfigureType(type => type.WithConversionFor(c => c
- .FromToml(tml => tml.Value)));
- });
-
- var v2 = Toml.ReadString(settingsFile, settings);
- var v3 = Migration.MigrateSettings(v2, "2", "3");
-
- Assert.AreEqual("3", v3.Version);
- Assert.AreEqual(v2.AudioSource, v3.AudioSource);
-
- Assert.AreEqual(v2.AlbumArtPopupSettings.Width, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtPopupSettings.Width);
- Assert.AreEqual(v2.AlbumArtPopupSettings.Height, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtPopupSettings.Height);
- Assert.AreEqual(v2.AlbumArtPopupSettings.IsVisible, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtPopupSettings.IsVisible);
- Assert.AreEqual(v2.AlbumArtPopupSettings.Margin, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtPopupSettings.Margin);
- Assert.AreEqual(v2.AlbumArtPopupSettings.XPosition, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtPopupSettings.XPosition);
-
- Assert.AreEqual(v2.AlbumArtSettings.Width, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtSettings.Width);
- Assert.AreEqual(v2.AlbumArtSettings.Height, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtSettings.Height);
- Assert.AreEqual(v2.AlbumArtSettings.IsVisible, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtSettings.IsVisible);
- Assert.AreEqual(v2.AlbumArtSettings.XPosition, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtSettings.XPosition);
- Assert.AreEqual(v2.AlbumArtSettings.YPosition, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtSettings.YPosition);
- Assert.AreEqual(v2.AlbumArtSettings.PlaceholderPath, v3.Profiles[SettingsV3.DefaultProfileName].AlbumArtSettings.PlaceholderPath);
-
- Assert.AreEqual(v2.AudioBandSettings.Width, v3.Profiles[SettingsV3.DefaultProfileName].AudioBandSettings.Width);
- Assert.AreEqual(v2.AudioBandSettings.Height, v3.Profiles[SettingsV3.DefaultProfileName].AudioBandSettings.Height);
-
- Assert.AreEqual(v2.NextButtonSettings.Width, v3.Profiles[SettingsV3.DefaultProfileName].NextButtonSettings.Width);
- Assert.AreEqual(v2.NextButtonSettings.Height, v3.Profiles[SettingsV3.DefaultProfileName].NextButtonSettings.Height);
- Assert.AreEqual(v2.NextButtonSettings.IsVisible, v3.Profiles[SettingsV3.DefaultProfileName].NextButtonSettings.IsVisible);
- Assert.AreEqual(v2.NextButtonSettings.XPosition, v3.Profiles[SettingsV3.DefaultProfileName].NextButtonSettings.XPosition);
- Assert.AreEqual(v2.NextButtonSettings.YPosition, v3.Profiles[SettingsV3.DefaultProfileName].NextButtonSettings.YPosition);
- Assert.AreEqual(v2.NextButtonSettings.ImagePath, v3.Profiles[SettingsV3.DefaultProfileName].NextButtonSettings.Content.ImagePath);
-
- Assert.AreEqual(v2.AudioSourceSettings.Count, v3.AudioSourceSettings.Count);
- Assert.AreEqual(v2.AudioSourceSettings[0].AudioSourceName, v3.AudioSourceSettings[0].AudioSourceName);
- Assert.AreEqual(v2.AudioSourceSettings[0].Settings.Count, v3.AudioSourceSettings[0].Settings.Count);
- Assert.AreEqual(v2.AudioSourceSettings[0].Settings[0].Name, v3.AudioSourceSettings[0].Settings[0].Name);
- Assert.AreEqual(v2.AudioSourceSettings[0].Settings[0].Value, v3.AudioSourceSettings[0].Settings[0].Value);
-
- Assert.AreEqual(v2.PlayPauseButtonSettings.Width, v3.Profiles[SettingsV3.DefaultProfileName].PlayPauseButtonSettings.Width);
- Assert.AreEqual(v2.PlayPauseButtonSettings.Height, v3.Profiles[SettingsV3.DefaultProfileName].PlayPauseButtonSettings.Height);
- Assert.AreEqual(v2.PlayPauseButtonSettings.XPosition, v3.Profiles[SettingsV3.DefaultProfileName].PlayPauseButtonSettings.XPosition);
- Assert.AreEqual(v2.PlayPauseButtonSettings.YPosition, v3.Profiles[SettingsV3.DefaultProfileName].PlayPauseButtonSettings.YPosition);
- Assert.AreEqual(v2.PlayPauseButtonSettings.IsVisible, v3.Profiles[SettingsV3.DefaultProfileName].PlayPauseButtonSettings.IsVisible);
- Assert.AreEqual(v2.PlayPauseButtonSettings.PauseButtonImagePath, v3.Profiles[SettingsV3.DefaultProfileName].PlayPauseButtonSettings.PauseContent.ImagePath);
- Assert.AreEqual(v2.PlayPauseButtonSettings.PlayButtonImagePath, v3.Profiles[SettingsV3.DefaultProfileName].PlayPauseButtonSettings.PlayContent.ImagePath);
-
- Assert.AreEqual(v2.PreviousButtonSettings.Height, v3.Profiles[SettingsV3.DefaultProfileName].PreviousButtonSettings.Height);
- Assert.AreEqual(v2.PreviousButtonSettings.Width, v3.Profiles[SettingsV3.DefaultProfileName].PreviousButtonSettings.Width);
- Assert.AreEqual(v2.PreviousButtonSettings.XPosition, v3.Profiles[SettingsV3.DefaultProfileName].PreviousButtonSettings.XPosition);
- Assert.AreEqual(v2.PreviousButtonSettings.YPosition, v3.Profiles[SettingsV3.DefaultProfileName].PreviousButtonSettings.YPosition);
- Assert.AreEqual(v2.PreviousButtonSettings.IsVisible, v3.Profiles[SettingsV3.DefaultProfileName].PreviousButtonSettings.IsVisible);
- Assert.AreEqual(v2.PreviousButtonSettings.ImagePath, v3.Profiles[SettingsV3.DefaultProfileName].PreviousButtonSettings.Content.ImagePath);
-
- Assert.AreEqual(v2.ProgressBarSettings.Width, v3.Profiles[SettingsV3.DefaultProfileName].ProgressBarSettings.Width);
- Assert.AreEqual(v2.ProgressBarSettings.Height, v3.Profiles[SettingsV3.DefaultProfileName].ProgressBarSettings.Height);
- Assert.AreEqual(v2.ProgressBarSettings.XPosition, v3.Profiles[SettingsV3.DefaultProfileName].ProgressBarSettings.XPosition);
- Assert.AreEqual(v2.ProgressBarSettings.YPosition, v3.Profiles[SettingsV3.DefaultProfileName].ProgressBarSettings.YPosition);
- Assert.AreEqual(v2.ProgressBarSettings.IsVisible, v3.Profiles[SettingsV3.DefaultProfileName].ProgressBarSettings.IsVisible);
- Assert.AreEqual(v2.ProgressBarSettings.BackgroundColor, v3.Profiles[SettingsV3.DefaultProfileName].ProgressBarSettings.BackgroundColor);
- Assert.AreEqual(v2.ProgressBarSettings.ForegroundColor, v3.Profiles[SettingsV3.DefaultProfileName].ProgressBarSettings.ForegroundColor);
-
- Assert.AreEqual(v2.CustomLabelSettings.Count, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings.Count);
- Assert.AreEqual(v2.CustomLabelSettings[0].Color, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].Color);
- Assert.AreEqual(v2.CustomLabelSettings[0].Width, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].Width);
- Assert.AreEqual(v2.CustomLabelSettings[0].Height, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].Height);
- Assert.AreEqual(v2.CustomLabelSettings[0].Name, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].Name);
- Assert.AreEqual(v2.CustomLabelSettings[0].XPosition, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].XPosition);
- Assert.AreEqual(v2.CustomLabelSettings[0].IsVisible, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].IsVisible);
- Assert.AreEqual(v2.CustomLabelSettings[0].YPosition, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].YPosition);
- Assert.AreEqual(v2.CustomLabelSettings[0].ScrollSpeed, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].ScrollSpeed);
- Assert.AreEqual(v2.CustomLabelSettings[0].FontSize, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].FontSize);
- Assert.AreEqual(v2.CustomLabelSettings[0].FontFamily, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].FontFamily);
- Assert.AreEqual(v2.CustomLabelSettings[0].Alignment, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].Alignment);
- Assert.AreEqual(v2.CustomLabelSettings[0].FormatString, v3.Profiles[SettingsV3.DefaultProfileName].CustomLabelSettings[0].FormatString);
- }
- }
-}
diff --git a/src/AudioBand.Test/TextFormatting/CustomTextParsingTests.cs b/src/AudioBand.Test/TextFormatting/CustomTextParsingTests.cs
new file mode 100644
index 00000000..be90a96d
--- /dev/null
+++ b/src/AudioBand.Test/TextFormatting/CustomTextParsingTests.cs
@@ -0,0 +1,276 @@
+using System;
+using System.ComponentModel;
+using System.Linq;
+using System.Windows.Media;
+using AudioBand.AudioSource;
+using AudioBand.TextFormatting;
+using Moq;
+using Xunit;
+
+namespace AudioBand.Test
+{
+ public class CustomTextParsingTests
+ {
+ [Fact]
+ public void Parse_NormalTextFormat()
+ {
+ var format = "hello";
+ var segments = FormattedTextParser.ParseFormattedString(format, Colors.Black, new Mock().Object).ToList();
+
+ Assert.Single(segments);
+ Assert.Equal("hello", segments[0].Text);
+ Assert.True(segments[0].Flags.HasFlag(FormattedTextFlags.Normal));
+ }
+
+ [Fact]
+ public void Parse_EmptyTextFormat_CreatesNoSegments()
+ {
+ var format = "";
+ var segments = FormattedTextParser.ParseFormattedString(format, Colors.Black, new Mock().Object).ToList();
+
+ Assert.Empty(segments);
+ }
+
+ [Fact]
+ public void Parse_SinglePlaceholder_CreatesPlaceholderSegment()
+ {
+ var format = "{artist}";
+ var artist = "123";
+ var session = new Mock();
+ session.SetupGet(m => m.SongArtist).Returns(artist);
+ var segments = FormattedTextParser.ParseFormattedString(format, Colors.Black, session.Object).ToList();
+
+ Assert.Single(segments);
+ Assert.Equal(artist, segments[0].Text);
+ }
+
+ [Fact]
+ public void Parse_PlaceholderTextWithNormal_CreatesPlaceholderAndNormalSegments()
+ {
+ var format = "{artist} song";
+ var artist = "123";
+ var session = new Mock();
+ session.SetupGet(m => m.SongArtist).Returns(artist);
+ var segments = FormattedTextParser.ParseFormattedString(format, Colors.Black, session.Object).ToList();
+ Assert.Equal(2, segments.Count);
+
+ Assert.Equal(artist, segments[0].Text);
+
+ Assert.Equal(" song", segments[1].Text);
+ Assert.True(segments[1].Flags.HasFlag(FormattedTextFlags.Normal));
+ }
+
+ [Fact]
+ public void Parse_NormalWithPlaceholder_CreatesNormalAndPlaceholderSegments()
+ {
+ var format = "by {artist}";
+ var artist = "123";
+ var session = new Mock();
+ session.SetupGet(m => m.SongArtist).Returns(artist);
+ var segments = FormattedTextParser.ParseFormattedString(format, Colors.Black, session.Object).ToList();
+
+ Assert.Equal(2, segments.Count);
+
+ Assert.Equal("by ", segments[0].Text);
+ Assert.True(segments[0].Flags.HasFlag(FormattedTextFlags.Normal));
+
+ Assert.Equal(artist, segments[1].Text);
+ }
+
+ [Fact]
+ public void Parse_FormatContainsPlaceholderWithUnclosedBrace_CreatesNormalSegment()
+ {
+ var format = "{artist";
+ var segments = FormattedTextParser.ParseFormattedString(format, Colors.Black, new Mock().Object).ToList();
+
+ Assert.Single(segments);
+ Assert.Equal("{artist", segments[0].Text);
+ Assert.True(segments[0].Flags.HasFlag(FormattedTextFlags.Normal));
+ }
+
+ [Fact]
+ public void Parse_FormatOnlyClosingBrace_CreatesNormalSegment()
+ {
+ var format = "}";
+ var segments = FormattedTextParser.ParseFormattedString(format, Colors.Black, new Mock().Object).ToList();
+
+ Assert.Single(segments);
+ Assert.Equal("}", segments[0].Text);
+ Assert.True(segments[0].Flags.HasFlag(FormattedTextFlags.Normal));
+ }
+
+ [Fact]
+ public void Parse_ComplexFormat_CreatesProperSegments()
+ {
+ var format = "this is {artist} and ";
+ var artist = "123";
+ var session = new Mock();
+ session.SetupGet(m => m.SongArtist).Returns(artist);
+ var segments = FormattedTextParser
+ .ParseFormattedString(format, Colors.Black, session.Object).ToList();
+
+ Assert.Equal(3, segments.Count);
+
+ Assert.Equal("this is ", segments[0].Text);
+ Assert.True(segments[0].Flags.HasFlag(FormattedTextFlags.Normal));
+
+ Assert.Equal(artist, segments[1].Text);
+
+ Assert.Equal(" and ", segments[2].Text);
+ Assert.True(segments[2].Flags.HasFlag(FormattedTextFlags.Normal));
+ }
+
+ [Fact]
+ public void Parse_InvalidPlaceholder_CreatesSegmentWithInvalidValue()
+ {
+ var format = "{something}";
+ var segments = FormattedTextParser.ParseFormattedString(format, Colors.Black, new Mock().Object).ToList();
+
+ Assert.Single(segments);
+
+ Assert.Equal("!Invalid format!", segments[0].Text);
+ Assert.True(segments[0].Flags.HasFlag(FormattedTextFlags.Normal));
+ }
+
+ [Fact]
+ public void Parse_ArtistPlaceholder_SubstitutesText()
+ {
+ var format = "{artist}";
+ var artist = "123";
+ var artist2 = "next";
+ var mock = new Mock();
+ mock.SetupSequence(m => m.SongArtist).Returns(artist).Returns(artist2);
+ var segments = FormattedTextParser.ParseFormattedString(format, Colors.Black, mock.Object).ToList();
+
+ Assert.Single(segments);
+ Assert.Equal(artist, segments[0].Text);
+
+ mock.Raise(m => m.PropertyChanged += null, null, new PropertyChangedEventArgs(nameof(IAudioSession.SongArtist)));
+ Assert.Equal(artist2, segments[0].Text);
+ }
+
+ [Fact]
+ public void Parse_SongPlaceholder_SubstitutesText()
+ {
+ var format = "{song}";
+ var song = "the song";
+ var mock = new Mock();
+ mock.SetupGet(m => m.SongName).Returns(song);
+ var segments = FormattedTextParser.ParseFormattedString(format, Colors.Black, mock.Object).ToList();
+
+ Assert.Single(segments);
+ Assert.Equal(song, segments[0].Text);
+ }
+
+ [Fact]
+ public void Parse_AlbumPlaceholder_SubstitutesText()
+ {
+ var format = "{album}";
+ var album = "the album";
+ var mock = new Mock();
+ mock.SetupGet(m => m.AlbumName).Returns(album);
+ var segments = FormattedTextParser.ParseFormattedString(format, Colors.Black, mock.Object).ToList();
+
+ Assert.Single(segments);
+ Assert.Equal(album, segments[0].Text);
+ }
+
+ [Fact]
+ public void Parse_TimePlaceholder_SubstitutesText()
+ {
+ var format = "{time}";
+ var time = TimeSpan.FromSeconds(40);
+ var mock = new Mock();
+ mock.SetupGet(m => m.SongProgress).Returns(time);
+ var segments = FormattedTextParser.ParseFormattedString(format, Colors.Black, mock.Object).ToList();
+
+ Assert.Single(segments);
+ Assert.Equal("0:40", segments[0].Text);
+ }
+
+ [Fact]
+ public void Parse_RemainingTimePlaceholder_SubstitutesText()
+ {
+ var format = "{remaining}";
+ var time = TimeSpan.FromSeconds(40);
+ var length = TimeSpan.FromSeconds(60);
+ var mock = new Mock();
+ mock.SetupGet(m => m.SongProgress).Returns(time);
+ mock.SetupGet(m => m.SongLength).Returns(length);
+ var segments = FormattedTextParser.ParseFormattedString(format, Colors.Black, mock.Object).ToList();
+
+ Assert.Single(segments);
+ Assert.Equal("0:20", segments[0].Text);
+ }
+
+ [Fact]
+ public void Parse_LengthPlaceholder_SubstitutesText()
+ {
+ var format = "{length}";
+ var time = TimeSpan.FromSeconds(80);
+ var mock = new Mock();
+ mock.SetupGet(m => m.SongLength).Returns(time);
+ var segments = FormattedTextParser.ParseFormattedString(format, Colors.Black, mock.Object).ToList();
+
+ Assert.Single(segments);
+ Assert.Equal("1:20", segments[0].Text);
+ }
+
+ [Fact]
+ public void Parse_StyleBold_SegmentContainsBoldFlag()
+ {
+ var format = "{*artist}";
+ var mock = new Mock();
+ var segments = FormattedTextParser.ParseFormattedString(format, Colors.Black, mock.Object).ToList();
+
+ Assert.Single(segments);
+ Assert.True(segments[0].Flags.HasFlag(FormattedTextFlags.Bold));
+ }
+
+ [Fact]
+ public void Parse_StyleItalic_SegmentContainsItalicFlag()
+ {
+ var format = "{&artist}";
+ var segments = FormattedTextParser
+ .ParseFormattedString(format, Colors.Black, new Mock().Object).ToList();
+
+ Assert.Single(segments);
+ Assert.True(segments[0].Flags.HasFlag(FormattedTextFlags.Italic));
+ }
+
+ [Fact]
+ public void Parse_StyleUnderline_SegmentContainsUnderlineFlag()
+ {
+ var format = "{_artist}";
+ var segments = FormattedTextParser
+ .ParseFormattedString(format, Colors.Black, new Mock().Object).ToList();
+
+ Assert.Single(segments);
+ Assert.True(segments[0].Flags.HasFlag(FormattedTextFlags.Underline));
+ }
+
+ [Fact]
+ public void Parse_StyleWithColor_SegmentContainsColorAndStyle()
+ {
+ var format = "{_artist:#ff00ff}";
+ var segments = FormattedTextParser
+ .ParseFormattedString(format, Colors.Black, new Mock().Object).ToList();
+
+ Assert.Single(segments);
+ Assert.True(segments[0].Flags.HasFlag(FormattedTextFlags.Underline));
+ Assert.Equal(Color.FromRgb(255, 0, 255), segments[0].Color);
+ }
+
+ [Fact]
+ public void Parse_MultipleStyles_SegmentContainsMatchingStyleFlags()
+ {
+ var format = "{*_artist}";
+ var segments = FormattedTextParser
+ .ParseFormattedString(format, Colors.Black, new Mock().Object).ToList();
+
+ Assert.Single(segments);
+ Assert.True(segments[0].Flags.HasFlag(FormattedTextFlags.Underline));
+ Assert.True(segments[0].Flags.HasFlag(FormattedTextFlags.Bold));
+ }
+ }
+}
diff --git a/src/AudioBand.Test/TextRendererTests.cs b/src/AudioBand.Test/TextRendererTests.cs
deleted file mode 100644
index 73383013..00000000
--- a/src/AudioBand.Test/TextRendererTests.cs
+++ /dev/null
@@ -1,296 +0,0 @@
-using System;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System.Windows.Media;
-using AudioBand.TextFormatting;
-
-namespace AudioBand.Test
-{
- [TestClass]
- public class TextRendererTests
- {
- [TestMethod]
- public void ParseNormal()
- {
- var format = "hello";
- var r = new FormattedTextParser(format, Colors.Black);
-
- Assert.AreEqual(1, r.TextSegments.Count);
- Assert.AreEqual("hello", r.TextSegments[0].Text);
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Normal));
- }
-
- [TestMethod]
- public void ParseEmpty()
- {
- var format = "";
- var r = new FormattedTextParser(format, Colors.Black);
-
- Assert.AreEqual(0, r.TextSegments.Count);
- }
-
- [TestMethod]
- public void ParseSinglePlaceholder()
- {
- var format = "{artist}";
- var artist = "123";
- var r = new FormattedTextParser(format, Colors.Black)
- {
- Artist = artist
- };
-
- Assert.AreEqual(1, r.TextSegments.Count);
- Assert.AreEqual(artist, r.TextSegments[0].Text);
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Artist));
- }
-
- [TestMethod]
- public void ParsePlaceholderWithNormal()
- {
- var format = "{artist} song";
- var artist = "123";
- var r = new FormattedTextParser(format, Colors.Black)
- {
- Artist = artist
- };
-
- Assert.AreEqual(2, r.TextSegments.Count);
-
- Assert.AreEqual(artist, r.TextSegments[0].Text);
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Artist));
-
- Assert.AreEqual(" song", r.TextSegments[1].Text);
- Assert.IsTrue(r.TextSegments[1].Type.HasFlag(FormattedTextFlags.Normal));
- }
-
- [TestMethod]
- public void ParseSingleNormalWithPlaceholder()
- {
- var format = "by {artist}";
- var artist = "123";
- var r = new FormattedTextParser(format, Colors.Black)
- {
- Artist = artist
- };
-
- Assert.AreEqual(2, r.TextSegments.Count);
-
- Assert.AreEqual("by ", r.TextSegments[0].Text);
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Normal));
-
- Assert.AreEqual(artist, r.TextSegments[1].Text);
- Assert.IsTrue(r.TextSegments[1].Type.HasFlag(FormattedTextFlags.Artist));
- }
-
- [TestMethod]
- public void ParseUnclosed()
- {
- var format = "{artist";
- var r = new FormattedTextParser(format, Colors.Black);
-
- Assert.AreEqual(1, r.TextSegments.Count);
- Assert.AreEqual("{artist", r.TextSegments[0].Text);
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Normal));
- }
-
- [TestMethod]
- public void ParseOnlyClosing()
- {
- var format = "}";
- var r = new FormattedTextParser(format, Colors.Black);
-
- Assert.AreEqual(1, r.TextSegments.Count);
- Assert.AreEqual("}", r.TextSegments[0].Text);
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Normal));
- }
-
- [TestMethod]
- public void ParseComplex()
- {
- var format = "this is {artist} and ";
- var artist = "123";
- var r = new FormattedTextParser(format, Colors.Black)
- {
- Artist = artist
- };
-
- Assert.AreEqual(3, r.TextSegments.Count);
-
- Assert.AreEqual("this is ", r.TextSegments[0].Text);
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Normal));
-
- Assert.AreEqual(artist, r.TextSegments[1].Text);
- Assert.IsTrue(r.TextSegments[1].Type.HasFlag(FormattedTextFlags.Artist));
-
- Assert.AreEqual(" and ", r.TextSegments[2].Text);
- Assert.IsTrue(r.TextSegments[2].Type.HasFlag(FormattedTextFlags.Normal));
- }
-
- [TestMethod]
- public void ParseInvalidFormat()
- {
- var format = "{something}";
- var r = new FormattedTextParser(format, Colors.Black);
-
- Assert.AreEqual(1, r.TextSegments.Count);
-
- Assert.AreEqual("! invalid format !", r.TextSegments[0].Text);
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Normal));
- }
-
- [TestMethod]
- public void ParseArtist()
- {
- var format = "{artist}";
- var artist = "123";
- var r = new FormattedTextParser(format, Colors.Black)
- {
- Artist = artist
- };
-
- Assert.AreEqual(1, r.TextSegments.Count);
- Assert.AreEqual(artist, r.TextSegments[0].Text);
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Artist));
- }
-
- [TestMethod]
- public void ParseSong()
- {
- var format = "{song}";
- var song = "the song";
- var r = new FormattedTextParser(format, Colors.Black)
- {
- SongName = song
- };
-
- Assert.AreEqual(1, r.TextSegments.Count);
- Assert.AreEqual(song, r.TextSegments[0].Text);
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Song));
- }
-
- [TestMethod]
- public void ParseAlbum()
- {
- var format = "{album}";
- var album = "the album";
- var r = new FormattedTextParser(format, Colors.Black)
- {
- AlbumName = album
- };
-
- Assert.AreEqual(1, r.TextSegments.Count);
- Assert.AreEqual(album, r.TextSegments[0].Text);
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Album));
- }
-
- [TestMethod]
- public void ParseTime()
- {
- var format = "{time}";
- var time = TimeSpan.FromSeconds(40);
- var r = new FormattedTextParser(format, Colors.Black)
- {
- SongProgress = time,
- };
-
- Assert.AreEqual(1, r.TextSegments.Count);
- Assert.AreEqual("0:40", r.TextSegments[0].Text);
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.CurrentTime));
- }
-
- [TestMethod]
- public void ParseLength()
- {
- var format = "{length}";
- var time = TimeSpan.FromSeconds(80);
- var r = new FormattedTextParser(format, Colors.Black)
- {
- SongLength = time,
- };
-
- Assert.AreEqual(1, r.TextSegments.Count);
- Assert.AreEqual("1:20", r.TextSegments[0].Text);
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.SongLength));
- }
-
- [TestMethod]
- public void ParseStyleBold()
- {
- var format = "{*artist}";
- var artist = "123";
- var r = new FormattedTextParser(format, Colors.Black)
- {
- Artist = artist
- };
-
- Assert.AreEqual(1, r.TextSegments.Count);
- Assert.AreEqual(artist, r.TextSegments[0].Text);
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Artist));
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Bold));
- }
-
- [TestMethod]
- public void ParseStyleItalic()
- {
- var format = "{&artist}";
- var artist = "123";
- var r = new FormattedTextParser(format, Colors.Black)
- {
- Artist = artist
- };
-
- Assert.AreEqual(1, r.TextSegments.Count);
- Assert.AreEqual(artist, r.TextSegments[0].Text);
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Artist));
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Italic));
- }
-
- [TestMethod]
- public void ParseStyleUnderline()
- {
- var format = "{_artist}";
- var artist = "123";
- var r = new FormattedTextParser(format, Colors.Black)
- {
- Artist = artist
- };
-
- Assert.AreEqual(1, r.TextSegments.Count);
- Assert.AreEqual(artist, r.TextSegments[0].Text);
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Artist));
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Underline));
- }
-
- [TestMethod]
- public void ParseStyleWithColor()
- {
- var format = "{_artist:#ff00ff}";
- var artist = "123";
- var r = new FormattedTextParser(format, Colors.Black)
- {
- Artist = artist
- };
-
- Assert.AreEqual(1, r.TextSegments.Count);
- Assert.AreEqual(artist, r.TextSegments[0].Text);
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Artist));
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Underline));
- Assert.AreEqual(Color.FromRgb(255, 0, 255), r.TextSegments[0].Color);
- }
-
- [TestMethod]
- public void ParseMultipleStyles()
- {
- var format = "{*_artist}";
- var artist = "test";
- var r = new FormattedTextParser(format, Colors.Black)
- {
- Artist = artist,
- };
- Assert.AreEqual(1, r.TextSegments.Count);
- Assert.AreEqual(artist, r.TextSegments[0].Text);
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Artist));
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Underline));
- Assert.IsTrue(r.TextSegments[0].Type.HasFlag(FormattedTextFlags.Bold));
- }
- }
-}
diff --git a/src/AudioBand.Test/ValueConveters/PathToImageConverterTests.cs b/src/AudioBand.Test/ValueConveters/PathToImageConverterTests.cs
new file mode 100644
index 00000000..88a43bbf
--- /dev/null
+++ b/src/AudioBand.Test/ValueConveters/PathToImageConverterTests.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Media;
+using AudioBand.ValueConverters;
+using Xunit;
+
+namespace AudioBand.Test
+{
+ public class PathToImageConverterTests
+ {
+ private PathToImageSourceConverter _converter = new PathToImageSourceConverter();
+ private string _sampleImagePath = Path.GetFullPath("Assets/imgsource.png");
+
+ [Fact]
+ void Convert_EmptyPath_ReturnsNull()
+ {
+ Assert.Null(_converter.Convert("", typeof(ImageSource), null, CultureInfo.CurrentCulture));
+ }
+
+ [Fact]
+ void Convert_Null_ReturnsNull()
+ {
+ Assert.Null(_converter.Convert((object)null, typeof(ImageSource), null, CultureInfo.CurrentCulture));
+ }
+
+ [Fact]
+ void Convert_NoFile_ReturnsNull()
+ {
+ Assert.Null(_converter.Convert("nonexistingfile.png", typeof(ImageSource), null, CultureInfo.CurrentCulture));
+ }
+
+ [Fact]
+ void Convert_ValidFile_ReturnsImageSource()
+ {
+ var imgSource = _converter.Convert(_sampleImagePath, typeof(ImageSource), null, CultureInfo.CurrentCulture);
+
+ Assert.NotNull(imgSource);
+ Assert.IsAssignableFrom(imgSource);
+ }
+
+ [Fact]
+ void MultiConvert_InvalidFile_UsesFallback()
+ {
+ object fallback = new object();
+ var imgSource = _converter.Convert(new[] {"invalidfile.png", fallback}, typeof(ImageSource), null,
+ CultureInfo.CurrentCulture);
+
+ Assert.NotNull(imgSource);
+ Assert.Equal(fallback, imgSource);
+ }
+ }
+}
diff --git a/src/AudioBand.Test/ViewModelBaseTests.cs b/src/AudioBand.Test/ViewModelBaseTests.cs
deleted file mode 100644
index 949b57c1..00000000
--- a/src/AudioBand.Test/ViewModelBaseTests.cs
+++ /dev/null
@@ -1,161 +0,0 @@
-using System;
-using System.Windows.Controls;
-using AudioBand.Messages;
-using AudioBand.Models;
-using AudioBand.ViewModels;
-using Castle.DynamicProxy.Generators.Emitters.SimpleAST;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace AudioBand.Test
-{
- [TestClass]
- public class ViewModelBaseTests
- {
- [TestMethod]
- public void SetPropertyWithChangedFieldCallsPropertyChanged()
- {
- string propertyName = null;
- var vm = new ViewModel();
- vm.PropertyChanged += (o, e) => { propertyName = e.PropertyName; };
- vm._field = 0;
- vm.Field = 10;
-
- Assert.AreEqual(nameof(ViewModel.Field), propertyName);
- Assert.AreEqual(10, vm._field);
- }
-
- [TestMethod]
- public void SetPropertySameField()
- {
- int called = 0;
- string propertyName = null;
- var vm = new ViewModel();
- vm.PropertyChanged += (o, e) => { propertyName = e.PropertyName; called++; };
- vm._field = 0;
- vm.Field = 0;
-
- Assert.AreEqual(0, called);
- Assert.AreEqual(null, propertyName);
- Assert.AreEqual(0, vm._field);
- }
-
- [TestMethod]
- public void SetPropertyAutomaticallyStartsEdit()
- {
- var vm = new ViewModel();
- vm._field = 0;
- vm.Field = 0;
-
- Assert.IsFalse(vm.IsEditing);
- vm.Field = 1;
- Assert.IsTrue(vm.IsEditing);
- }
-
- [TestMethod]
- public void SetPropertyWithModelAutomaticallyStartsEdit()
- {
- var vm = new ViewModelWithModel();
- vm.Field = 0;
-
- Assert.IsFalse(vm.IsEditing);
- vm.Field = 1;
- Assert.IsTrue(vm.IsEditing);
- }
-
- [TestMethod]
- public void ResetViewModelWithModelStartsEdit()
- {
- var vm = new ViewModelWithModel();
- vm.Reset();
-
- Assert.IsTrue(vm.IsEditing);
- }
-
- [TestMethod]
- public void ViewModelWithModelSetupBindingsProperly()
- {
- var m = new Model();
- var vm = new ViewModelWithModel(m);
-
- bool raised = false;
- vm.PropertyChanged += (sender, e) =>
- {
- if (e.PropertyName == nameof(ViewModelWithModel.Field))
- {
- raised = true;
- }
- };
-
- m.ModelField = 10;
-
- Assert.IsTrue(raised);
- }
-
- [TestMethod]
- public void ViewModelWithModelUnbindModelProperly()
- {
- var m = new Model();
- var vm = new ViewModelWithModel(m);
-
- bool raised = false;
- vm.PropertyChanged += (sender, e) =>
- {
- if (e.PropertyName == nameof(ViewModelWithModel.Field))
- {
- raised = true;
- }
- };
-
- vm.Unbind();
-
- m.ModelField = 10;
-
- Assert.IsFalse(raised);
- }
-
- private class ViewModel : ViewModelBase
- {
- public int _field;
-
- public int Field
- {
- get => _field;
- set => SetProperty(ref _field, value);
- }
- }
-
- private class ViewModelWithModel : ViewModelBase
- {
- public ViewModelWithModel() : base(new Model())
- {
- }
-
- public ViewModelWithModel(Model m) : base(m)
- {
- }
-
- [PropertyChangeBinding(nameof(ViewModelBaseTests.Model.ModelField))]
- public int Field
- {
- get => Model.ModelField;
- set => SetProperty(nameof(ViewModelBaseTests.Model.ModelField), value);
- }
-
- public void Unbind()
- {
- UnbindModel(Model);
- }
- }
-
- private class Model : ModelBase
- {
- private int _field = 0;
-
- public int ModelField
- {
- get => _field;
- set => SetProperty(ref _field, value);
- }
- }
- }
-}
diff --git a/src/AudioBand.Test/AlbumArtPopupViewModelTests.cs b/src/AudioBand.Test/ViewModels/AlbumArtPopupViewModelTests.cs
similarity index 52%
rename from src/AudioBand.Test/AlbumArtPopupViewModelTests.cs
rename to src/AudioBand.Test/ViewModels/AlbumArtPopupViewModelTests.cs
index 1ec831e5..a4064cdd 100644
--- a/src/AudioBand.Test/AlbumArtPopupViewModelTests.cs
+++ b/src/AudioBand.Test/ViewModels/AlbumArtPopupViewModelTests.cs
@@ -1,46 +1,41 @@
using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using AudioBand.Messages;
using AudioBand.Models;
using AudioBand.Settings;
using AudioBand.ViewModels;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using Xunit;
namespace AudioBand.Test
{
- [TestClass]
public class AlbumArtPopupViewModelTests
{
private Mock _appSettings;
+ private Mock _messageBus;
- [TestInitialize]
- public void TestInit()
+ public AlbumArtPopupViewModelTests()
{
_appSettings = new Mock();
+ _messageBus = new Mock();
}
- [TestMethod]
- public void ListensForProfileChangesAndMapsProperly()
+ [Fact]
+ public void AlbumArtPopupViewModel_ProfileChangedEvent_ListensToProfileChanges()
{
var first = new AlbumArtPopup() {Height = 10};
var second = new AlbumArtPopup() {Height = 20};
_appSettings.SetupSequence(m => m.AlbumArtPopup)
.Returns(first)
+ .Returns(second)
.Returns(second);
- var vm = new AlbumArtPopupViewModel(_appSettings.Object);
- bool raise = false;
- vm.PropertyChanged += (_, __) => raise = true;
- Assert.AreEqual(first.Height, vm.Height);
+ var vm = new AlbumArtPopupViewModel(_appSettings.Object, _messageBus.Object);
+
+ Assert.Equal(first.Height, vm.Height);
_appSettings.Raise(m => m.ProfileChanged += null, EventArgs.Empty);
- Assert.IsFalse(vm.IsEditing);
- Assert.IsTrue(raise);
- Assert.AreEqual(second.Height, vm.Height);
+ Assert.False(vm.IsEditing);
+ Assert.Equal(second.Height, vm.Height);
}
}
}
diff --git a/src/AudioBand.Test/AlbumArtViewModelTests.cs b/src/AudioBand.Test/ViewModels/AlbumArtViewModelTests.cs
similarity index 62%
rename from src/AudioBand.Test/AlbumArtViewModelTests.cs
rename to src/AudioBand.Test/ViewModels/AlbumArtViewModelTests.cs
index 51d405b9..b26e3ca9 100644
--- a/src/AudioBand.Test/AlbumArtViewModelTests.cs
+++ b/src/AudioBand.Test/ViewModels/AlbumArtViewModelTests.cs
@@ -1,49 +1,46 @@
using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using AudioBand.AudioSource;
+using AudioBand.Messages;
using AudioBand.Models;
using AudioBand.Settings;
using AudioBand.ViewModels;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using Xunit;
namespace AudioBand.Test
{
- [TestClass]
public class AlbumArtViewModelTests
{
private Mock _appSettings;
private Mock _dialog;
+ private Mock _messageBus;
- [TestInitialize]
- public void TestInit()
+ public AlbumArtViewModelTests()
{
_appSettings = new Mock();
_appSettings.SetupGet(m => m.AlbumArt).Returns(new AlbumArt());
_dialog = new Mock();
+ _messageBus = new Mock();
}
- [TestMethod]
- public void ListensToProfileChanges()
+ [Fact]
+ public void AlbumArtViewModel_ProfileChangedEvent_ListensToProfileChanges()
{
var first = new AlbumArt() {Height = 10};
var second = new AlbumArt() {Height = 20};
_appSettings.SetupSequence(m => m.AlbumArt)
.Returns(first)
.Returns(second);
- var vm = new AlbumArtViewModel(_appSettings.Object, _dialog.Object);
+ var vm = new AlbumArtViewModel(_appSettings.Object, _dialog.Object, new Mock().Object, _messageBus.Object);
bool raised = false;
vm.PropertyChanged += (sender, e) => raised = true;
- Assert.AreEqual(vm.Height, first.Height);
+ Assert.Equal(vm.Height, first.Height);
_appSettings.Raise(m => m.ProfileChanged += null, EventArgs.Empty);
- Assert.IsFalse(vm.IsEditing);
- Assert.IsTrue(raised);
- Assert.AreEqual(second.Height, vm.Height);
+ Assert.False(vm.IsEditing);
+ Assert.True(raised);
+ Assert.Equal(second.Height, vm.Height);
}
}
}
diff --git a/src/AudioBand.Test/AudioBandViewModelTests.cs b/src/AudioBand.Test/ViewModels/AudioBandViewModelTests.cs
similarity index 57%
rename from src/AudioBand.Test/AudioBandViewModelTests.cs
rename to src/AudioBand.Test/ViewModels/AudioBandViewModelTests.cs
index 6f3adeaf..13cd94f4 100644
--- a/src/AudioBand.Test/AudioBandViewModelTests.cs
+++ b/src/AudioBand.Test/ViewModels/AudioBandViewModelTests.cs
@@ -1,45 +1,42 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using AudioBand.Messages;
using AudioBand.Settings;
using AudioBand.ViewModels;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using Xunit;
namespace AudioBand.Test
{
- [TestClass]
public class AudioBandViewModelTests
{
private Mock _appSettings;
+ private Mock _messageBus;
- [TestInitialize]
- public void TestInit()
+ public AudioBandViewModelTests()
{
+ _messageBus = new Mock();
_appSettings = new Mock();
}
- [TestMethod]
- public void AudioBandViewModelListensToProfileChanges()
+ [Fact]
+ public void AudioBandViewModel_ProfileChangedEvent_ListensToProfileChanges()
{
var first = new Models.AudioBand(){Height = 10};
var second = new Models.AudioBand(){Height = 20};
_appSettings.SetupSequence(m => m.AudioBand)
.Returns(first)
.Returns(second);
- var vm = new AudioBandViewModel(_appSettings.Object, new Mock().Object);
+ var vm = new AudioBandViewModel(_appSettings.Object, new Mock().Object, _messageBus.Object);
bool raised = false;
vm.PropertyChanged += (_, __) => raised = true;
- Assert.AreEqual(first.Height, vm.Height);
+ Assert.Equal(first.Height, vm.Height);
_appSettings.Raise(m => m.ProfileChanged += null, EventArgs.Empty);
- Assert.IsTrue(raised);
- Assert.IsFalse(vm.IsEditing);
- Assert.AreEqual(second.Height, vm.Height);
+ Assert.True(raised);
+ Assert.False(vm.IsEditing);
+ Assert.Equal(second.Height, vm.Height);
}
}
}
diff --git a/src/AudioBand.Test/AudioSourceSettingsCollectionTests.cs b/src/AudioBand.Test/ViewModels/AudioSourceSettingsCollectionTests.cs
similarity index 74%
rename from src/AudioBand.Test/AudioSourceSettingsCollectionTests.cs
rename to src/AudioBand.Test/ViewModels/AudioSourceSettingsCollectionTests.cs
index 43afa163..03e69864 100644
--- a/src/AudioBand.Test/AudioSourceSettingsCollectionTests.cs
+++ b/src/AudioBand.Test/ViewModels/AudioSourceSettingsCollectionTests.cs
@@ -1,31 +1,26 @@
using AudioBand.AudioSource;
using AudioBand.Models;
using AudioBand.ViewModels;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
-using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
+using AudioBand.Messages;
+using Xunit;
namespace AudioBand.Test
{
- [TestClass]
public class AudioSourceSettingsCollectionTests
{
private Mock _audioSourceMock;
+ private Mock _messageBus;
-
- [TestInitialize]
- public void Init()
+ public AudioSourceSettingsCollectionTests()
{
_audioSourceMock = new Mock();
+ _messageBus = new Mock();
}
- [TestMethod]
- public void NoMatchingSettings()
+ [Fact]
+ public void NoMatchingSettings_CreatesNoChildViewModels()
{
_audioSourceMock.SetupGet(s => s.Settings).Returns(new List());
var name = "test";
@@ -38,14 +33,14 @@ public void NoMatchingSettings()
};
var settings = new AudioSourceSettings { AudioSourceName = name, Settings = keyVals };
- var vm = new AudioSourceSettingsCollectionViewModel(_audioSourceMock.Object, settings);
+ var vm = new AudioSourceSettingsCollectionViewModel(_audioSourceMock.Object, settings, _messageBus.Object);
- Assert.AreEqual(0, vm.SettingsList.Count);
- Assert.AreEqual(name, vm.AudioSourceName);
+ Assert.Empty(vm.SettingsList);
+ Assert.Equal(name, vm.AudioSourceName);
}
- [TestMethod]
- public void MatchingSettingsShouldCreateVmsInOrder()
+ [Fact]
+ public void MatchingSettings_ShouldCreateChildViewModelsInOrder()
{
var setting1 = "Setting1";
var setting2 = "setting2";
@@ -61,7 +56,7 @@ public void MatchingSettingsShouldCreateVmsInOrder()
_audioSourceMock.SetupGet(s => s[It.Is(x => x == setting1)]).Returns(val1);
_audioSourceMock.SetupGet(s => s[It.Is(x => x == setting2)]).Returns(val2);
_audioSourceMock.Setup(s => s.GetSettingType(It.Is(x => x == setting1))).Returns(typeof(string));
- _audioSourceMock.Setup(s => s.GetSettingType(It.Is(x => x == setting2))).Returns(typeof(string));
+ _audioSourceMock.Setup(s => s.GetSettingType(It.Is(x => x == setting2))).Returns(typeof(int));
var settingModels = new List
{
@@ -70,18 +65,17 @@ public void MatchingSettingsShouldCreateVmsInOrder()
};
var settings = new AudioSourceSettings { Settings = settingModels };
- var vm = new AudioSourceSettingsCollectionViewModel(_audioSourceMock.Object, settings);
-
- Assert.AreEqual(settingModels.Count, vm.SettingsList.Count);
- Assert.AreEqual(settingModels[0].Name, vm.SettingsList[0].Name);
- Assert.AreEqual(settingModels[1].Name, vm.SettingsList[1].Name);
+ var vm = new AudioSourceSettingsCollectionViewModel(_audioSourceMock.Object, settings, _messageBus.Object);
- Assert.AreEqual(settingModels[0].Value, vm.SettingsList[0].Value);
- Assert.AreEqual(settingModels[1].Value, vm.SettingsList[1].Value);
+ Assert.Equal(settingModels.Count, vm.SettingsList.Count);
+ Assert.Equal(settingModels[0].Name, vm.SettingsList[0].Name);
+ Assert.Equal(settingModels[1].Name, vm.SettingsList[1].Name);
+ Assert.Equal(settingModels[0].Value, vm.SettingsList[0].Value);
+ Assert.Equal(settingModels[1].Value, vm.SettingsList[1].Value);
}
- [TestMethod]
- public void AudioSourceSettingUpdatesAreHandled()
+ [Fact]
+ public void AudioSourceSettingUpdate_NewValueIsWrittenBackToSettings()
{
var setting = "setting";
@@ -91,18 +85,19 @@ public void AudioSourceSettingUpdatesAreHandled()
{
Settings = new List { settingModel }
};
-
- var vm = new AudioSourceSettingsCollectionViewModel(_audioSourceMock.Object, settings);
-
object newSettingValue = 1;
_audioSourceMock.SetupGet(s => s[It.Is(x => x == setting)]).Returns(newSettingValue);
+
+ var vm = new AudioSourceSettingsCollectionViewModel(_audioSourceMock.Object, settings, _messageBus.Object);
+
_audioSourceMock.Raise(s => s.SettingChanged += null, new SettingChangedEventArgs(setting));
- Assert.AreEqual(settingModel.Value, newSettingValue);
+ vm.EndEdit();
+ Assert.Equal(newSettingValue, settingModel.Value);
}
- [TestMethod]
- public void AudioSourceSettingsCalledInPriority()
+ [Fact]
+ public void AudioSourceSettingsUpdated_AudioSourceIsUpdatedInPriority()
{
var setting1 = new AudioSourceSettingAttribute("test1") { Priority = 10 };
var setting2 = new AudioSourceSettingAttribute("test2") { Priority = 5 };
@@ -126,7 +121,7 @@ public void AudioSourceSettingsCalledInPriority()
_audioSourceMock.InSequence(s).SetupSet(source => source[It.Is(x => x == setting1.Name)] = null);
_audioSourceMock.InSequence(s).SetupSet(source => source[It.Is(x => x == setting2.Name)] = null);
- var vm = new AudioSourceSettingsCollectionViewModel(_audioSourceMock.Object, settings);
+ var vm = new AudioSourceSettingsCollectionViewModel(_audioSourceMock.Object, settings, _messageBus.Object);
_audioSourceMock.VerifySet(source => source[setting3.Name] = null);
_audioSourceMock.VerifySet(source => source[setting1.Name] = null);
diff --git a/src/AudioBand.Test/ViewModels/ButtonViewModels.cs b/src/AudioBand.Test/ViewModels/ButtonViewModels.cs
new file mode 100644
index 00000000..177e7144
--- /dev/null
+++ b/src/AudioBand.Test/ViewModels/ButtonViewModels.cs
@@ -0,0 +1,303 @@
+using System;
+using System.ComponentModel;
+using System.Threading.Tasks;
+using AudioBand.AudioSource;
+using AudioBand.Messages;
+using AudioBand.Models;
+using AudioBand.Settings;
+using AudioBand.ViewModels;
+using Moq;
+using Xunit;
+
+namespace AudioBand.Test
+{
+ public class ButtonViewModels
+ {
+ private Mock _appSettings;
+ private Mock _dialog;
+ private Mock _session;
+ private Mock _messageBus;
+
+ public ButtonViewModels()
+ {
+ _appSettings = new Mock();
+ _dialog = new Mock();
+ _session = new Mock();
+ _messageBus = new Mock();
+ }
+
+ [Fact]
+ public void NextButton_ProfilesChanged_ListensforProfileChanges()
+ {
+ var first = new NextButton() {Height = 1};
+ var second = new NextButton() {Height = 2};
+ _appSettings.SetupSequence(m => m.NextButton)
+ .Returns(first)
+ .Returns(second);
+
+ var vm = new NextButtonViewModel(_appSettings.Object, _dialog.Object, _session.Object, _messageBus.Object);
+ bool raised = false;
+ vm.PropertyChanged += (_, __) => raised = true;
+
+ Assert.Equal(first.Height, vm.Height);
+ _appSettings.Raise(m => m.ProfileChanged += null, EventArgs.Empty);
+
+ Assert.False(vm.IsEditing);
+ Assert.True(raised);
+ Assert.Equal(second.Height, vm.Height);
+ }
+
+
+ [Fact]
+ public async Task NextButton_NextCommandExecuted_CallsNextTrack()
+ {
+ _appSettings.SetupGet(m => m.NextButton).Returns(new NextButton());
+ var audioSourceMock = new Mock();
+ audioSourceMock.Setup(m => m.NextTrackAsync()).Returns(Task.CompletedTask);
+ _session.SetupGet(m => m.CurrentAudioSource).Returns(audioSourceMock.Object);
+ var vm = new NextButtonViewModel(_appSettings.Object, _dialog.Object, _session.Object, _messageBus.Object);
+
+ await vm.NextTrackCommand.ExecuteAsync(null);
+ audioSourceMock.Verify(m => m.NextTrackAsync());
+ }
+
+ [Fact]
+ public void PlayPauseButton_ProfileChanged_ListensForProfileChanges()
+ {
+ var first = new PlayPauseButton() {Height = 1};
+ var second = new PlayPauseButton() {Height = 2};
+ _appSettings.SetupSequence(m => m.PlayPauseButton)
+ .Returns(first)
+ .Returns(second);
+
+ var vm = new PlayPauseButtonViewModel(_appSettings.Object, _dialog.Object, _session.Object, _messageBus.Object);
+ bool raised = false;
+ vm.PropertyChanged += (_, __) => raised = true;
+
+ Assert.Equal(first.Height, vm.Height);
+ _appSettings.Raise(m => m.ProfileChanged += null, EventArgs.Empty);
+
+ Assert.False(vm.IsEditing);
+ Assert.True(raised);
+ Assert.Equal(second.Height, vm.Height);
+ }
+
+ [Fact]
+ public void PlayPauseButton_PropertiesInContentAreChanged_ViewModelIsMarkedAsEditing()
+ {
+ _appSettings.SetupGet(m => m.PlayPauseButton).Returns(new PlayPauseButton());
+ var viewModel = new PlayPauseButtonViewModel(_appSettings.Object, _dialog.Object, _session.Object, _messageBus.Object);
+
+ viewModel.PlayContent.Text = "";
+ Assert.True(viewModel.PlayContent.IsEditing);
+ Assert.True(viewModel.IsEditing);
+
+ viewModel.EndEdit();
+ Assert.False(viewModel.IsEditing);
+ Assert.False(viewModel.PlayContent.IsEditing);
+
+ viewModel.PauseContent.Text = "";
+ Assert.True(viewModel.IsEditing);
+ Assert.True(viewModel.PauseContent.IsEditing);
+ }
+
+ [Fact]
+ public void PlayPauseButton_AudioSessionPlayStateChanged_ListensToEvent()
+ {
+ _appSettings.SetupGet(m => m.PlayPauseButton).Returns(new PlayPauseButton());
+ _session.SetupSequence(m => m.IsPlaying).Returns(true).Returns(false);
+ var viewModel = new PlayPauseButtonViewModel(_appSettings.Object, _dialog.Object, _session.Object, _messageBus.Object);
+
+ _session.Raise(m => m.PropertyChanged+= null, null, new PropertyChangedEventArgs(nameof(IAudioSession.IsPlaying)));
+ Assert.True(viewModel.IsPlaying);
+ Assert.False(viewModel.IsPlayButtonShown);
+
+ _session.Raise(m => m.PropertyChanged += null, null, new PropertyChangedEventArgs(nameof(IAudioSession.IsPlaying)));
+ Assert.False(viewModel.IsPlaying);
+ Assert.True(viewModel.IsPlayButtonShown);
+ }
+
+ [Fact]
+ public async Task PlayPauseButton_PlayAndPauseCommandExecuted_AudioSourceIsNotified()
+ {
+ _appSettings.SetupGet(m => m.PlayPauseButton).Returns(new PlayPauseButton());
+ var audioSourceMock = new Mock();
+ var isPlayingSequence = new[] {true, false};
+ var index = 0;
+ audioSourceMock.Setup(m => m.PlayTrackAsync())
+ .Callback(() => Assert.True(isPlayingSequence[index++]))
+ .Returns(Task.CompletedTask);
+ audioSourceMock.Setup(m => m.PauseTrackAsync())
+ .Callback(() => Assert.False(isPlayingSequence[index++]))
+ .Returns(Task.CompletedTask);
+
+ _session.SetupGet(m => m.CurrentAudioSource).Returns(audioSourceMock.Object);
+ _session.SetupSequence(m => m.IsPlaying).Returns(true).Returns(false);
+
+ var viewModel = new PlayPauseButtonViewModel(_appSettings.Object, _dialog.Object, _session.Object, _messageBus.Object);
+ await viewModel.PlayPauseTrackCommand.ExecuteAsync(null);
+ _session.Raise(m => m.PropertyChanged += null, null, new PropertyChangedEventArgs(nameof(IAudioSession.IsPlaying)));
+ audioSourceMock.Raise(m => m.IsPlayingChanged += null, null, true);
+ await viewModel.PlayPauseTrackCommand.ExecuteAsync(null);
+ }
+
+ [Fact]
+ public void PreviousButton_ProfileChanged_ListensForProfileChanges()
+ {
+ var first = new PreviousButton() { Height = 1 };
+ var second = new PreviousButton() { Height = 2 };
+ _appSettings.SetupSequence(m => m.PreviousButton)
+ .Returns(first)
+ .Returns(second);
+
+ var vm = new PreviousButtonViewModel(_appSettings.Object, _dialog.Object, _session.Object, _messageBus.Object);
+ bool raised = false;
+ vm.PropertyChanged += (_, __) => raised = true;
+
+ Assert.Equal(first.Height, vm.Height);
+ _appSettings.Raise(m => m.ProfileChanged += null, EventArgs.Empty);
+
+ Assert.False(vm.IsEditing);
+ Assert.True(raised);
+ Assert.Equal(second.Height, vm.Height);
+ }
+
+ [Fact]
+ public async Task PreviousButton_PreviousCommand_CallsPreviousTrackOnAudioSource()
+ {
+ _appSettings.SetupGet(m => m.PreviousButton).Returns(new PreviousButton());
+ var audioSourceMock = new Mock();
+ audioSourceMock.Setup(m => m.PreviousTrackAsync()).Returns(Task.CompletedTask);
+ _session.SetupGet(m => m.CurrentAudioSource).Returns(audioSourceMock.Object);
+ var vm = new PreviousButtonViewModel(_appSettings.Object, _dialog.Object, _session.Object, _messageBus.Object);
+
+ await vm.PreviousTrackCommand.ExecuteAsync(null);
+ audioSourceMock.Verify(m => m.PreviousTrackAsync());
+ }
+
+ [Fact]
+ public void RepeatModeButton_ProfileChanged_ListensForProfileChanges()
+ {
+ var first = new RepeatModeButton() { Height = 1 };
+ var second = new RepeatModeButton() { Height = 2 };
+ _appSettings.SetupSequence(m => m.RepeatModeButton)
+ .Returns(first)
+ .Returns(second);
+
+ var vm = new RepeatModeButtonViewModel(_appSettings.Object, _dialog.Object, _session.Object, _messageBus.Object);
+ bool raised = false;
+ vm.PropertyChanged += (_, __) => raised = true;
+
+ Assert.Equal(first.Height, vm.Height);
+ _appSettings.Raise(m => m.ProfileChanged += null, EventArgs.Empty);
+
+ Assert.False(vm.IsEditing);
+ Assert.True(raised);
+ Assert.Equal(second.Height, vm.Height);
+ }
+
+ [Fact]
+ public void RepeatModeButton_ContentPropertiesAreModified_ViewModelIsMarkedAsEditing()
+ {
+ _appSettings.SetupGet(m => m.RepeatModeButton).Returns(new RepeatModeButton());
+ var viewModel = new RepeatModeButtonViewModel(_appSettings.Object, _dialog.Object, _session.Object, _messageBus.Object);
+
+ Assert.False(viewModel.RepeatTrackContent.IsEditing);
+ Assert.False(viewModel.IsEditing);
+
+ viewModel.RepeatTrackContent.Text = "test";
+
+ Assert.True(viewModel.RepeatTrackContent.IsEditing);
+ Assert.True(viewModel.IsEditing);
+ }
+
+ [Fact]
+ public async Task RepeatModeButton_RepeatCommandExecuted_CyclesThroughRepeatModes()
+ {
+ var repeatSequence = new[] {RepeatMode.RepeatContext, RepeatMode.RepeatTrack, RepeatMode.Off};
+ var index = 0;
+ var audiosourceMock = new Mock();
+ audiosourceMock.Setup(m => m.SetRepeatModeAsync(It.IsAny()))
+ .Callback((RepeatMode mode) => Assert.Equal(repeatSequence[index++], mode))
+ .Returns(Task.CompletedTask);
+ _appSettings.SetupGet(m => m.RepeatModeButton).Returns(new RepeatModeButton());
+ _session.SetupGet(m => m.CurrentAudioSource).Returns(audiosourceMock.Object);
+ _session.SetupSequence(m => m.RepeatMode)
+ .Returns(RepeatMode.RepeatContext)
+ .Returns(RepeatMode.RepeatTrack)
+ .Returns(RepeatMode.Off)
+ ;
+
+ var viewModel = new RepeatModeButtonViewModel(_appSettings.Object, _dialog.Object, _session.Object, _messageBus.Object);
+
+ Assert.Equal(RepeatMode.Off, viewModel.RepeatMode);
+ await viewModel.CycleRepeatModeCommand.ExecuteAsync(null);
+ _session.Raise(m => m.PropertyChanged += null, null, new PropertyChangedEventArgs(nameof(IAudioSession.RepeatMode)));
+ await viewModel.CycleRepeatModeCommand.ExecuteAsync(null);
+ _session.Raise(m => m.PropertyChanged += null, null, new PropertyChangedEventArgs(nameof(IAudioSession.RepeatMode)));
+ await viewModel.CycleRepeatModeCommand.ExecuteAsync(null);
+ }
+
+ [Fact]
+ public void ShuffleModeButton_ProfileChanged_ListensForProfileChanges()
+ {
+ var first = new ShuffleModeButton() { Height = 1 };
+ var second = new ShuffleModeButton() { Height = 2 };
+ _appSettings.SetupSequence(m => m.ShuffleModeButton)
+ .Returns(first)
+ .Returns(second);
+
+ var vm = new ShuffleModeButtonViewModel(_appSettings.Object, _dialog.Object, _session.Object, _messageBus.Object);
+ bool raised = false;
+ vm.PropertyChanged += (_, __) => raised = true;
+
+ Assert.Equal(first.Height, vm.Height);
+ _appSettings.Raise(m => m.ProfileChanged += null, EventArgs.Empty);
+
+ Assert.False(vm.IsEditing);
+ Assert.True(raised);
+ Assert.Equal(second.Height, vm.Height);
+ }
+
+ [Fact]
+ public void ShuffleModeButton_ContentIsEdited_ViewModelIsMarkedAsEditing()
+ {
+ _appSettings.SetupGet(m => m.ShuffleModeButton).Returns(new ShuffleModeButton());
+ var vm = new ShuffleModeButtonViewModel(_appSettings.Object, _dialog.Object, _session.Object, _messageBus.Object);
+
+ vm.ShuffleOnContent.Text = "A";
+ Assert.True(vm.ShuffleOnContent.IsEditing);
+ Assert.True(vm.IsEditing);
+
+ vm.EndEdit();
+ Assert.False(vm.ShuffleOnContent.IsEditing);
+ Assert.False(vm.IsEditing);
+
+ vm.ShuffleOffContent.Text = "...";
+ Assert.True(vm.ShuffleOffContent.IsEditing);
+ Assert.True(vm.IsEditing);
+ }
+
+ [Fact]
+ public async Task ShuffleModeButton_ShuffleCommandExecuted_TogglesShuffle()
+ {
+ _appSettings.SetupGet(m => m.ShuffleModeButton).Returns(new ShuffleModeButton());
+ var vm = new ShuffleModeButtonViewModel(_appSettings.Object, _dialog.Object, _session.Object, _messageBus.Object);
+ var audioSourceMock = new Mock();
+ _session.SetupGet(m => m.CurrentAudioSource).Returns(audioSourceMock.Object);
+ _session.SetupSequence(m => m.IsShuffleOn)
+ .Returns(true)
+ .Returns(false);
+
+ var sequence = new[] {true, false};
+ var index = 0;
+ audioSourceMock.Setup(m => m.SetShuffleAsync(It.IsAny()))
+ .Callback((bool shuffle) => Assert.Equal(sequence[index++], shuffle))
+ .Returns(Task.CompletedTask);
+
+ await vm.ToggleShuffleCommand.ExecuteAsync(null);
+ _session.Raise(m => m.PropertyChanged += null, null, new PropertyChangedEventArgs(nameof(IAudioSession.IsShuffleOn)));
+ await vm.ToggleShuffleCommand.ExecuteAsync(null);
+ }
+ }
+}
diff --git a/src/AudioBand.Test/ViewModels/CustomLabelViewModelTests.cs b/src/AudioBand.Test/ViewModels/CustomLabelViewModelTests.cs
new file mode 100644
index 00000000..396aef52
--- /dev/null
+++ b/src/AudioBand.Test/ViewModels/CustomLabelViewModelTests.cs
@@ -0,0 +1,77 @@
+using System.Linq;
+using System.Windows.Media;
+using AudioBand.AudioSource;
+using AudioBand.Messages;
+using AudioBand.Models;
+using AudioBand.ViewModels;
+using Moq;
+using Xunit;
+
+namespace AudioBand.Test
+{
+ public class CustomLabelViewModelTests
+ {
+ private Mock _dialogMock;
+ private Mock _messageBusMock;
+ private Mock _sessionMock;
+
+ public CustomLabelViewModelTests()
+ {
+ _dialogMock = new Mock();
+ _messageBusMock = new Mock();
+ _sessionMock = new Mock();
+ }
+
+ [Fact]
+ void CustomLabel_TextFormatStringChanged_TextSegmentsMatch()
+ {
+ var songname = "song";
+ var artist = "artist";
+ var model = new CustomLabel { FormatString = "first format" };
+ _sessionMock.SetupGet(m => m.SongName).Returns(songname);
+ _sessionMock.SetupGet(m => m.SongArtist).Returns(artist);
+ var vm = new CustomLabelViewModel(model, _dialogMock.Object, _sessionMock.Object, _messageBusMock.Object);
+
+ var firstSegment = "second format with";
+ var secondSegment = "{artist}";
+ var thirdSegment = "and";
+ var forthSegment = "{song}";
+ vm.FormatString = firstSegment + secondSegment + thirdSegment + forthSegment;
+
+ var segments = vm.TextSegments.ToList();
+ Assert.Equal(4, segments.Count);
+ Assert.Equal(firstSegment, segments[0].Text);
+ Assert.Equal(artist, segments[1].Text);
+ Assert.Equal(thirdSegment, segments[2].Text);
+ Assert.Equal(songname, segments[3].Text);
+ }
+
+ [Fact]
+ void CustomLabel_TextFormatStringChangedThenCanceled_CorrectTextSegments()
+ {
+ var songname = "song";
+ var model = new CustomLabel {FormatString = "text format {song}"};
+ _sessionMock.SetupGet(m => m.SongName).Returns(songname);
+ var vm = new CustomLabelViewModel(model, _dialogMock.Object, _sessionMock.Object, _messageBusMock.Object);
+
+ Assert.Equal(2, vm.TextSegments.Count());
+ vm.FormatString = "new format string";
+ vm.CancelEdit();
+
+ Assert.Equal(2, vm.TextSegments.Count());
+ Assert.Equal(songname, vm.TextSegments.ToList()[1].Text);
+ }
+
+ [Fact]
+ void CustomLabel_ColorChangedThenCanceled_TextSegmentsHaveCorrectColor()
+ {
+ var model = new CustomLabel { FormatString = "text format {song}", Color = Colors.Blue };
+ var vm = new CustomLabelViewModel(model, _dialogMock.Object, _sessionMock.Object, _messageBusMock.Object);
+
+ vm.Color = Colors.Black;
+ vm.CancelEdit();
+
+ Assert.All(vm.TextSegments, segment => Assert.Equal(Colors.Blue, segment.Color));
+ }
+ }
+}
diff --git a/src/AudioBand.Test/CustomLabelsViewModelTests.cs b/src/AudioBand.Test/ViewModels/CustomLabelsViewModelTests.cs
similarity index 65%
rename from src/AudioBand.Test/CustomLabelsViewModelTests.cs
rename to src/AudioBand.Test/ViewModels/CustomLabelsViewModelTests.cs
index 502b65b1..2dafa58d 100644
--- a/src/AudioBand.Test/CustomLabelsViewModelTests.cs
+++ b/src/AudioBand.Test/ViewModels/CustomLabelsViewModelTests.cs
@@ -1,103 +1,104 @@
using System;
-using System.Text;
using System.Collections.Generic;
-using System.Threading.Tasks;
using AudioBand.AudioSource;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using AudioBand.Messages;
using AudioBand.ViewModels;
using AudioBand.Models;
using Moq;
using AudioBand.Settings;
+using Xunit;
namespace AudioBand.Test
{
///
/// Summary description for CustomLabelsViewModel
///
- [TestClass]
public class CustomLabelsViewModelTests
{
private Mock _dialogMock;
private Mock _appSettingsMock;
+ private Mock _sessionMock;
+ private Mock _messageBus;
private CustomLabel _label;
private CustomLabelsViewModel _viewModel;
- [TestInitialize]
- public void Init()
+ public CustomLabelsViewModelTests()
{
_dialogMock = new Mock();
_appSettingsMock = new Mock();
_appSettingsMock.Setup(x => x.CustomLabels).Returns(new List());
_label = new CustomLabel();
- _viewModel = new CustomLabelsViewModel(_appSettingsMock.Object, _dialogMock.Object);
+ _sessionMock = new Mock();
+ _messageBus = new Mock();
+ _viewModel = new CustomLabelsViewModel(_appSettingsMock.Object, _dialogMock.Object, _sessionMock.Object, _messageBus.Object);
}
- [TestMethod]
- public void AddLabel()
+ [Fact]
+ public void AddLabel_CreatesNewViewModel()
{
_viewModel.AddLabelCommand.Execute(null);
- Assert.AreEqual(1, _viewModel.CustomLabels.Count);
+ Assert.Single(_viewModel.CustomLabels);
}
- [TestMethod]
- public void RemoveLabel_confirm()
+ [Fact]
+ public void RemoveLabel_DialogShownAndConfirmed_RemovesCorrectLabel()
{
_dialogMock.Setup(o => o.ShowConfirmationDialog(It.IsAny(), It.IsAny