Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write initial test for library search
- Loading branch information
1 parent
a6dbdf2
commit 279c5f4
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reactive; | ||
using System.Reactive.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Moq; | ||
using Ninject; | ||
using Ninject.MockingKernel.Moq; | ||
using Play.Models; | ||
using ReactiveUI; | ||
using ReactiveUI.Routing; | ||
using ReactiveUI.Xaml; | ||
using Xunit; | ||
|
||
namespace Play.Tests.ViewModels | ||
{ | ||
public class SearchViewModelTests | ||
{ | ||
[Fact] | ||
public void PlayApiShouldBeCalledOnPerformSearch() | ||
{ | ||
var kernel = new MoqMockingKernel(); | ||
|
||
kernel.GetMock<IPlayApi>() | ||
.Setup(x => x.Search("Foo")) | ||
.Returns(Observable.Return(new List<Song>() { new Song() { id = "12345" } })) | ||
.Verifiable(); | ||
|
||
var fixture = kernel.Get<ISearchViewModel>(); | ||
fixture.PerformSearch.CanExecute(null).Should().BeFalse(); | ||
|
||
fixture.SearchQuery = "Foo"; | ||
fixture.PerformSearch.CanExecute(null).Should().BeTrue(); | ||
fixture.PerformSearch.Execute(null); | ||
|
||
kernel.GetMock<IPlayApi>().Verify(x => x.Search("Foo"), Times.Once()); | ||
|
||
fixture.SearchResults.Count.Should().Be(1); | ||
fixture.SearchResults[0].Model.id.Should().Be("12345"); | ||
} | ||
} | ||
|
||
public interface ISearchViewModel : IRoutableViewModel | ||
{ | ||
string SearchQuery { get; set; } | ||
|
||
ReactiveCollection<ISearchResultTileViewModel> SearchResults { get; } | ||
ReactiveAsyncCommand PerformSearch { get; } | ||
} | ||
|
||
public interface ISearchResultTileViewModel : IReactiveNotifyPropertyChanged | ||
{ | ||
Song Model { get; } | ||
|
||
ReactiveCommand QueueSong { get; } | ||
ReactiveCommand QueueAlbum { get; } | ||
ReactiveCommand ShowSongsFromArtist { get; } | ||
ReactiveCommand ShowSongsFromAlbum { get; } | ||
} | ||
} |