Skip to content

Commit

Permalink
Version 0.9.0 Preview 2
Browse files Browse the repository at this point in the history
  • Loading branch information
dsafa committed May 23, 2019
2 parents 565d4a1 + 3d740c5 commit 8f8cdbd
Show file tree
Hide file tree
Showing 132 changed files with 3,986 additions and 2,190 deletions.
2 changes: 1 addition & 1 deletion src/AudioBand.Test/AlbumArtPopupViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void ListensForProfileChangesAndMapsProperly()
_appSettings.SetupSequence(m => m.AlbumArtPopup)
.Returns(first)
.Returns(second);
var vm = new AlbumArtPopupVM(_appSettings.Object);
var vm = new AlbumArtPopupViewModel(_appSettings.Object);
bool raise = false;
vm.PropertyChanged += (_, __) => raise = true;

Expand Down
2 changes: 1 addition & 1 deletion src/AudioBand.Test/AlbumArtViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void ListensToProfileChanges()
_appSettings.SetupSequence(m => m.AlbumArt)
.Returns(first)
.Returns(second);
var vm = new AlbumArtVM(_appSettings.Object, _dialog.Object);
var vm = new AlbumArtViewModel(_appSettings.Object, _dialog.Object);
bool raised = false;
vm.PropertyChanged += (sender, e) => raised = true;

Expand Down
3 changes: 3 additions & 0 deletions src/AudioBand.Test/AudioBand.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
<Reference Include="System.Web" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Unosquare.Swan.Lite">
<HintPath>C:\Users\bdonc\.nuget\packages\unosquare.swan.lite\0.38.1\lib\net452\Unosquare.Swan.Lite.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AlbumArtPopupViewModelTests.cs" />
Expand Down
2 changes: 1 addition & 1 deletion src/AudioBand.Test/AudioBandViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void AudioBandViewModelListensToProfileChanges()
_appSettings.SetupSequence(m => m.AudioBand)
.Returns(first)
.Returns(second);
var vm = new AudioBandVM(_appSettings.Object);
var vm = new AudioBandViewModel(_appSettings.Object);

bool raised = false;
vm.PropertyChanged += (_, __) => raised = true;
Expand Down
235 changes: 232 additions & 3 deletions src/AudioBand.Test/ButtonViewModels.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Drawing;
using System.Threading.Tasks;
using AudioBand.AudioSource;
using AudioBand.Models;
using AudioBand.Settings;
using AudioBand.ViewModels;
Expand Down Expand Up @@ -30,7 +32,7 @@ public void NextButtonListensforProfileChanges()
.Returns(first)
.Returns(second);

var vm = new NextButtonVM(_appSettings.Object, _dialog.Object);
var vm = new NextButtonViewModel(_appSettings.Object, _dialog.Object);
bool raised = false;
vm.PropertyChanged += (_, __) => raised = true;

Expand All @@ -42,6 +44,20 @@ public void NextButtonListensforProfileChanges()
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<IAudioSource>();
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()
{
Expand All @@ -51,7 +67,7 @@ public void PlayPauseButtonListensForProfileChanges()
.Returns(first)
.Returns(second);

var vm = new PlayPauseButtonVM(_appSettings.Object, _dialog.Object);
var vm = new PlayPauseButtonViewModel(_appSettings.Object, _dialog.Object);
bool raised = false;
vm.PropertyChanged += (_, __) => raised = true;

Expand All @@ -63,6 +79,63 @@ public void PlayPauseButtonListensForProfileChanges()
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<IAudioSource>();

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<IAudioSource>();
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()
{
Expand All @@ -72,7 +145,111 @@ public void PreviousButtonListensForProfileChanges()
.Returns(first)
.Returns(second);

var vm = new PreviousButtonVM(_appSettings.Object, _dialog.Object);
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<IAudioSource>();
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<IAudioSource>();
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<IAudioSource>();
var repeatSequence = new[] {RepeatMode.RepeatContext, RepeatMode.RepeatTrack, RepeatMode.Off};
var index = 0;
audiosourceMock.Setup(m => m.SetRepeatModeAsync(It.IsAny<RepeatMode>()))
.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;

Expand All @@ -83,5 +260,57 @@ public void PreviousButtonListensForProfileChanges()
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<IAudioSource>();
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<IAudioSource>();
var sequence = new[] {true, false};
var index = 0;
audioSourceMock.Setup(m => m.SetShuffleAsync(It.IsAny<bool>()))
.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);
}
}
}
Loading

0 comments on commit 8f8cdbd

Please sign in to comment.