예제 #1
0
        public async Task CanSearchAllMusic()
        {
            // ARRANGE
            MusicDocument doc1 = new MusicDocument
            {
                Id     = Guid.NewGuid().ToString(),
                Artist = "Linkin Park",
                Album  = "Meteora",
                ArtistAlphabetIndex = AlphabetType.L,
                IsFavorite          = true,
                Length      = 185, // 3 mins and 5 secs
                Title       = "Numb",
                Path        = "www.google.com/numb.mp3",
                CreatedDate = DateTime.UtcNow,
                UpdatedDate = DateTime.UtcNow
            };

            MusicDocument doc2 = new MusicDocument
            {
                Id     = Guid.NewGuid().ToString(),
                Artist = "Vanessa Carlton",
                Album  = "Legally Blonde",
                ArtistAlphabetIndex = AlphabetType.V,
                IsFavorite          = true,
                Length      = 240, // 4 mins
                Title       = "A Thousand Miles",
                Path        = "/music/1000Miles.mp3",
                CreatedDate = DateTime.UtcNow,
                UpdatedDate = DateTime.UtcNow
            };

            List <MusicDocument> expectedResponse = new List <MusicDocument>
            {
                doc1,
                doc2
            };

            MusicSearchRequest request = new MusicSearchRequest
            {
                IsFavorite = null
            };

            this._repo
            .Setup(m => m.SearchMusicAsync(It.IsAny <SearchMusicRequest>()))
            .ReturnsAsync(expectedResponse);

            // ACT
            List <MusicResponse> response = await this._service.SearchMusicAsync(request : request);

            // ASSERT
            Assert.NotNull(response);
            Assert.Collection(response,
                              x => AssertEqual(x, expectedResponse),
                              x => AssertEqual(x, expectedResponse)
                              );
            this._repo.Verify(m => m.SearchMusicAsync(It.IsAny <SearchMusicRequest>()), Times.Once);
        }
예제 #2
0
 public async Task <IActionResult> SearchMusicAsync([FromQuery] MusicSearchRequest request)
 {
     return(this.Ok(await this._service.SearchMusicAsync(request: request)));
 }
예제 #3
0
        public async Task <List <MusicResponse> > SearchMusicAsync(MusicSearchRequest request)
        {
            List <MusicDocument> musics = await this._musicRepo.SearchMusicAsync(request : request.ToDataLayer());

            return(MusicMapper.Map(musics: musics));
        }