Skip to content

Commit

Permalink
Merge branch 'library'
Browse files Browse the repository at this point in the history
  • Loading branch information
cwl157 committed Jun 16, 2021
2 parents ce6ad96 + d7d85ca commit 35915bb
Show file tree
Hide file tree
Showing 25 changed files with 1,799 additions and 602 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
using NUnit.Framework.Constraints;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace MusicPlayer.Tests
{
internal class QueueLoaderStub : IQueueLoader
internal class LibraryLoaderStub : ILibraryLoader
{
public List<Song> Load(string path)
public void Load(DirectoryInfo root, List<Song> result, DateTime lastSyncTime)
{
var tmp = new List<Song>();
tmp.Add(new Song()
// var tmp = new List<Song>();
result.Add(new Song()
{
Artist = "Test",
Title = "Title",
Expand All @@ -22,7 +23,7 @@ public List<Song> Load(string path)
FilePath = @"C:\tmp\1",
Year = "2018"
});
tmp.Add(new Song()
result.Add(new Song()
{
Artist = "Test",
Title = "Title Two",
Expand All @@ -33,7 +34,7 @@ public List<Song> Load(string path)
Year = "2019"
});

return tmp;
// return tmp;
}
}
}
172 changes: 172 additions & 0 deletions src/MusicPlayer.Tests/PlayerViewModelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
using MusicPlayer.Model;
using MusicPlayer.Services;
using MusicPlayer.ViewModels;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Runtime.Intrinsics.X86;
using System.Threading;
using System.Windows;

namespace MusicPlayer.Tests
{
public class PlayerViewModelTests
{
public PlayerViewModelTests()
{
var app = new Application();
}
[SetUp]
public void Setup()
{

}

[Test]
public void AddToQueueMethod_Test()
{
IMusicPlayer mp = new MusicPlayerStub();
ILibraryLoader ql = new LibraryLoaderStub();
PlayerViewModel vm = new PlayerViewModel(mp);

List<Song> songs = new List<Song>();
ql.Load(null, songs, DateTime.Now.AddDays(-1));
vm.AddToQueue(songs);
Assert.AreEqual(2, vm.SongList.Count);
Assert.AreEqual("2 songs - 00:30", vm.QueueInfo);
}

[Test]
public void ClearQueueCommand_Test()
{

IMusicPlayer mp = new MusicPlayerStub();
ILibraryLoader ql = new LibraryLoaderStub();
PlayerViewModel vm = new PlayerViewModel(mp);

List<Song> songs = new List<Song>();
ql.Load(null, songs, DateTime.Now.AddDays(-1));
vm.AddToQueue(songs);
vm.ClearQueueCommand.Execute(null);
Assert.AreEqual(0, vm.SongList.Count);
Assert.AreEqual("", vm.QueueInfo);
}

[Test]
public void PlayCommand_Test()
{

IMusicPlayer mp = new MusicPlayerStub();
ILibraryLoader ql = new LibraryLoaderStub();
PlayerViewModel vm = new PlayerViewModel(mp);

List<Song> songs = new List<Song>();
ql.Load(null, songs, DateTime.Now.AddDays(-1));
vm.AddToQueue(songs);

vm.SelectedIndex = 0;
vm.SelectedSong = vm.SongList[vm.SelectedIndex];
vm.PlayingSong = vm.SongList[1];
vm.PlaySong.Execute(null);

// Assert playing song properties match selected song properties
Assert.AreEqual("Test", vm.PlayingSong.Artist);
Assert.AreEqual("Title Two", vm.PlayingSong.Title);
Assert.AreEqual("Test Album", vm.PlayingSong.Album);
// Assert viewmodel state
Assert.AreEqual("Test - Test Album [2019]", vm.ArtistAlbumInfo);
Assert.AreEqual("2. Title Two", vm.TrackTitleInfo);
}

//[Test]
//public void PauseCommand_Test()
//{

// IMusicPlayer mp = new MusicPlayerStub();
// IQueueLoader ql = new QueueLoaderStub();
// SongCollection col = new SongCollection(ql);
// PlayerViewModel vm = new PlayerViewModel(mp, col);

// vm.AddToQueueCommand.Execute(null);

// vm.SelectedIndex = 0;
// vm.SelectedSong = vm.SongList[vm.SelectedIndex];
// vm.PlayingSong = vm.SongList[1];
// vm.PlaySong.Execute(null);

// vm.PauseSong.Execute(null);
//}

//[Test]
//public void StopCommand_Test()
//{

// IMusicPlayer mp = new MusicPlayerStub();
// IQueueLoader ql = new QueueLoaderStub();
// SongCollection col = new SongCollection(ql);
// PlayerViewModel vm = new PlayerViewModel(mp, col);

// vm.AddToQueueCommand.Execute(null);

// vm.SelectedIndex = 0;
// vm.SelectedSong = vm.SongList[vm.SelectedIndex];
// vm.PlayingSong = vm.SongList[1];
// vm.PlaySong.Execute(null);

// vm.StopSong.Execute(null);

// // Assert viewmodel state
// Assert.AreEqual(0, vm.PlayingProgress);
// Assert.AreEqual("00:00 / 00:10", vm.ElapsedTime);
//}

//[Test]
//public void FastForwardCommand_Test()
//{

// IMusicPlayer mp = new MusicPlayerStub();
// IQueueLoader ql = new QueueLoaderStub();
// SongCollection col = new SongCollection(ql);
// PlayerViewModel vm = new PlayerViewModel(mp, col);

// vm.AddToQueueCommand.Execute(null);

// vm.SelectedIndex = 1;
// vm.SelectedSong = vm.SongList[vm.SelectedIndex];
// vm.PlayingSong = vm.SongList[0];
// vm.PlaySong.Execute(null);

// vm.FastForwardCommand.Execute(null);

// // Assert viewmodel state
// Assert.AreEqual(10000, vm.PlayingProgress);
// Assert.AreEqual("00:10 / 00:20", vm.ElapsedTime);
//}

//[Test]
//public void RewindCommand_Test()
//{

// IMusicPlayer mp = new MusicPlayerStub();
// IQueueLoader ql = new QueueLoaderStub();
// SongCollection col = new SongCollection(ql);
// PlayerViewModel vm = new PlayerViewModel(mp, col);

// vm.AddToQueueCommand.Execute(null);

// vm.SelectedIndex = 1;
// vm.SelectedSong = vm.SongList[vm.SelectedIndex];
// vm.PlayingSong = vm.SongList[0];
// vm.PlaySong.Execute(null);

// //vm.StopSong.Execute(null);
// vm.FastForwardCommand.Execute(null);

// vm.RewindCommand.Execute(null);

// // Assert viewmodel state
// Assert.AreEqual(0, vm.PlayingProgress);
// Assert.AreEqual("00:00 / 00:20", vm.ElapsedTime);
//}
}
}
167 changes: 0 additions & 167 deletions src/MusicPlayer.Tests/QueueViewModelTests.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/MusicPlayer/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
xmlns:local="clr-namespace:MusicPlayer"
StartupUri="MainWindow.xaml">
<Application.Resources>
<BooleanToVisibilityConverter x:Key="BoolToVis"/>
</Application.Resources>
</Application>
Loading

0 comments on commit 35915bb

Please sign in to comment.