public async Task ReturnTheCorrectSongsWhenThePassedQueryContainsNonEmptySearchTerm() { var expectedSongs = new[] { new Song() { IsApproved = true, Title = "Aenean tempus" }, new Song() { IsApproved = true, Title = "Aenean elementum" } }; var songs = new List <Song>() { new Song() { IsApproved = true, Title = "Odio lacus" }, new Song() { IsApproved = false, Title = "Fusce eu libero" } }; songs.AddRange(expectedSongs); var songsStub = songs.AsQueryable() .BuildMock(); var songRepositoryStub = new Mock <IEfRepository <Song> >(); songRepositoryStub .Setup(x => x.All(It.IsAny <bool>())) .Returns(songsStub.Object); GetSongs query = new GetSongs() { PageInfo = new PageInfo(1, 5), SearchInfo = new SearchInfo("aenean") }; // Arrange GetSongsQueryService sut = new GetSongsQueryService(songRepositoryStub.Object); // Act IEnumerable <Song> actualSongs = await sut.ExecuteAsync(query); // Assert Assert.AreEqual(2, actualSongs.Count()); CollectionAssert.AreEqual(expectedSongs, actualSongs); }
public async Task ReturnTheSongsOrderedByPublishDateDescendingWhenInvoked() { var expectedSongs = new[] { new Song() { IsApproved = true, Title = string.Empty, PublishedOn = new DateTime(2000, 1, 3) }, new Song() { IsApproved = true, Title = string.Empty, PublishedOn = new DateTime(2000, 1, 2) }, new Song() { IsApproved = true, Title = string.Empty, PublishedOn = new DateTime(2000, 1, 1) } }; var songs = expectedSongs.OrderBy(s => s.PublishedOn) .AsQueryable() .BuildMock(); var songRepositoryStub = new Mock <IEfRepository <Song> >(); songRepositoryStub .Setup(x => x.All(It.IsAny <bool>())) .Returns(songs.Object); GetSongs query = new GetSongs() { PageInfo = new PageInfo(1, 5), SearchInfo = new SearchInfo(null) }; // Arrange GetSongsQueryService sut = new GetSongsQueryService(songRepositoryStub.Object); // Act IEnumerable <Song> actualSongs = await sut.ExecuteAsync(query); // Assert CollectionAssert.AreEqual(expectedSongs, actualSongs); }
public async Task ReturnApprovedSongsOnlyWhenInvoked() { var songs = new[] { new Song() { IsApproved = false, Title = string.Empty }, new Song() { IsApproved = true, Title = string.Empty }, new Song() { IsApproved = true, Title = string.Empty }, new Song() { IsApproved = true, Title = string.Empty }, } .AsQueryable() .BuildMock(); var songRepositoryStub = new Mock <IEfRepository <Song> >(); songRepositoryStub .Setup(x => x.All(It.IsAny <bool>())) .Returns(songs.Object); GetSongs query = new GetSongs() { PageInfo = new PageInfo(1, 5), SearchInfo = new SearchInfo(null) }; // Arrange GetSongsQueryService sut = new GetSongsQueryService(songRepositoryStub.Object); // Act IEnumerable <Song> actualSongs = await sut.ExecuteAsync(query); // Assert Assert.That(actualSongs.All(s => s.IsApproved = true)); }
public async Task <IActionResult> FilteredSongsAjax(string searchTerm) { IEnumerable <Song> songs = null; GetSongs songsQuery = new GetSongs() { PageInfo = new PageInfo(1, DefaultPageSize), SearchInfo = new SearchInfo(searchTerm) }; string message = await this.CallServiceAsync( async() => songs = await this.getSongs.ExecuteAsync(songsQuery)); IEnumerable <SongListingViewModel> model = Mapper.Map <IEnumerable <SongListingViewModel> >(songs); return(PartialView("_SongListing", model)); }
public async Task Play(string url) { if (!IsBound) { await Join(); } await Context.Channel.SendMessageAsync($"**:musical_note: Searching :mag_right: `{url}`**"); if (!Enqueue(url, out string err)) { await Context.Channel.SendEmbedAsync($"An error has occured", err); return; } Song song = GetSongs.Last(); EmbedBuilder embed = new EmbedBuilder { Color = Color.Purple, Author = new EmbedAuthorBuilder { IconUrl = Context.User.GetAvatarUrl(), Name = "Added to queue" }, ThumbnailUrl = song.Thumbnail, Title = song.Title, Url = song.Url }; embed.AddField("Channel", song.Artist, true); embed.AddField("Song Duration", $"{song.Duration / 60}:{song.Duration % 60}", true); embed.AddField("Estimated Time Until Playing", $"TBI", true); embed.AddField("Position in queue", IsPlaying ? (GetSongs.Count() - 1).ToString() : "Now"); await Context.Channel.SendMessageAsync("", false, embed.Build()); if (!IsPlaying) { await PlayAsync(); } }
public async Task <IActionResult> All(int page = 1, string searchTerm = null) { IEnumerable <Song> songs = null; GetSongs songsQuery = new GetSongs() { PageInfo = new PageInfo(page, DefaultPageSize), SearchInfo = new SearchInfo(searchTerm) }; string message = await this.CallServiceAsync( async() => songs = await this.getSongs.ExecuteAsync(songsQuery)); if (message != null) { return(RedirectToAction( nameof(HomeController.Index), "Home", new { area = "" }) .WithErrorMessage(message)); } GetSongsCount songsCountQuery = new GetSongsCount() { Approved = true, SearchInfo = new SearchInfo(searchTerm) }; int songsCount = await this.getSongsCount.ExecuteAsync(songsCountQuery); IEnumerable <SongListingViewModel> songsModel = Mapper.Map <IEnumerable <SongListingViewModel> >(songs); SearchViewModel <PaginatedViewModel <SongListingViewModel> > model = ViewModelFactory.CreateSearchPaginatedViewModel <SongListingViewModel>( songsModel, page, DefaultPageSize, songsCount, searchTerm, "songs"); return(View(model)); }
public void GetSongsTest() { GetSongs request = new GetSongs(); var result = JsonConvert.DeserializeObject <KodiJSON.AudioLibrary.Response.GetSongsResponse>(ExecuteTest.GetResponse(request)); }