public async Task <IActionResult> UnapprovedSongs(int page = 1) { GetUnapprovedSongs getSongsQuery = new GetUnapprovedSongs() { PageInfo = new PageInfo(page, DefaultPageSize) }; IEnumerable <Song> unapprovedSongs = await this.getUnapprovedSongs.ExecuteAsync(getSongsQuery); GetSongsCount getSongsCountQuery = new GetSongsCount() { Approved = false, SearchInfo = new SearchInfo(null) }; int songsCount = await this.getSongsCount.ExecuteAsync(getSongsCountQuery); IEnumerable <SongListingViewModel> songsModel = Mapper.Map <IEnumerable <SongListingViewModel> >(unapprovedSongs); PaginatedViewModel <SongListingViewModel> model = ViewModelFactory.CreatePaginatedViewModel <SongListingViewModel>( songsModel, page, DefaultPageSize, songsCount); return(View(model)); }
public async Task ReturnTheCorrectCountOfUnapprovedSongsOnlyWhenInvoked() { int expectedSongsCount = 3; var songs = new[] { new Song() { IsApproved = false, Title = string.Empty }, new Song() { IsApproved = false, Title = string.Empty }, new Song() { IsApproved = false, 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); GetSongsCount query = new GetSongsCount() { Approved = false, SearchInfo = new SearchInfo(null) }; // Arrange GetSongsCountQueryService sut = new GetSongsCountQueryService(songRepositoryStub.Object); // Act int actualSongsCount = await sut.ExecuteAsync(query); // Assert Assert.AreEqual(expectedSongsCount, actualSongsCount); }
public async Task ReturnCorrectCountOfSongsWhenThePassedQueryContainsNonEmptySearchTerm() { int expectedSongsCount = 1; var songs = new[] { new Song() { IsApproved = false, Title = "Aenean tempus" }, new Song() { IsApproved = false, Title = "Odio lacus" }, new Song() { IsApproved = false, Title = "Fusce eu libero" }, new Song() { IsApproved = true, Title = "Aenean elementum" } } .AsQueryable() .BuildMock(); var songRepositoryStub = new Mock <IEfRepository <Song> >(); songRepositoryStub .Setup(x => x.All(It.IsAny <bool>())) .Returns(songs.Object); GetSongsCount query = new GetSongsCount() { Approved = false, SearchInfo = new SearchInfo("aenean") }; // Arrange GetSongsCountQueryService sut = new GetSongsCountQueryService(songRepositoryStub.Object); // Act int actualSongsCount = await sut.ExecuteAsync(query); // Assert Assert.AreEqual(expectedSongsCount, actualSongsCount); }
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)); }