Skip to content

Commit

Permalink
Write initial test for library search
Browse files Browse the repository at this point in the history
  • Loading branch information
anaisbetts committed Apr 14, 2012
1 parent a6dbdf2 commit 279c5f4
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions Play.Tests/Play.Tests.csproj
Expand Up @@ -117,6 +117,7 @@
<Compile Include="Models\PlayApiTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ViewModels\PlayViewModel.cs" />
<Compile Include="ViewModels\SearchViewModel.cs" />
<Compile Include="ViewModels\WelcomeViewModel.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
63 changes: 63 additions & 0 deletions Play.Tests/ViewModels/SearchViewModel.cs
@@ -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; }
}
}

0 comments on commit 279c5f4

Please sign in to comment.