Exemple #1
0
        public PagedResponse <TrackDto> Execute(TrackSearch search)
        {
            var query = _context.Track.AsQueryable();

            if (!string.IsNullOrEmpty(search.Name) || !string.IsNullOrWhiteSpace(search.Name))
            {
                query = query.Where(x => x.Name.ToLower().Contains(search.Name.ToLower()));
            }

            var skipCount = search.PerPage * (search.Page - 1);

            var response = new PagedResponse <TrackDto>
            {
                CurrentPage  = search.Page,
                ItemsPerPage = search.PerPage,
                TotalCount   = query.Count(),
                Items        = query.Skip(skipCount).Take(search.PerPage).Select(x => new TrackDto
                {
                    Id           = x.TrackId,
                    AlbumId      = x.AlbumId,
                    Name         = x.Name,
                    Bytes        = x.Bytes,
                    Composer     = x.Composer,
                    GenreId      = x.GenreId,
                    MediaTypeId  = x.MediaTypeId,
                    Milliseconds = x.Milliseconds,
                    UnitPrice    = x.Milliseconds
                }).ToList()
            };

            return(response);
        }
Exemple #2
0
        public void Can_hit_endpoint()
        {
            TrackSearch release = Api <TrackSearch> .Create
                                  .WithParameter("q", "Happy")
                                  .Please();

            Assert.That(release, Is.Not.Null);
            Assert.That(release.Results.Count, Is.GreaterThan(0));
            Assert.That(release.Results.FirstOrDefault().Type, Is.EqualTo(TrackType.track));
        }
Exemple #3
0
        public void Search()
        {
            var trackSearch = new TrackSearch("пилот", Session);
            trackSearch.SpecifyItemsPerPage(100);

            for (int i = 1; i < 10; i++)
            {
                var tracks = trackSearch.GetPage(i);
            }
        }
Exemple #4
0
        public void Can_hit_endpoint_with_paging()
        {
            TrackSearch artistBrowse = Api <TrackSearch> .Create
                                       .WithParameter("q", "Happy")
                                       .WithParameter("page", "2")
                                       .WithParameter("pageSize", "20")
                                       .Please();

            Assert.That(artistBrowse, Is.Not.Null);
            Assert.That(artistBrowse.Page, Is.EqualTo(2));
            Assert.That(artistBrowse.PageSize, Is.EqualTo(20));
        }
Exemple #5
0
    /// <summary>
    /// Perform search based on artist name and 
    /// one of the track titles from the album.
    /// </summary>
    /// <param name="maxMaxResults">Number of MaxResults to return</param>
    /// <returns>Collection of album tags</returns>
    private List<Metadata> TrackLookup()
    {
      Trace.WriteLine("Performing track lookup. Artist: "
                      + Tokens["artist"]
                      + " Track Title: "
                      + Tokens["title"]);

      
      TrackSearch search = new TrackSearch(Tokens["artist"], Tokens["title"], session);
      search.SpecifyItemsPerPage(MaxResults);
      List<Metadata> tmp = (from track in search.GetPage((int)Pages.FIRST)
                       select track.GetAlbum().ToTag()).ToList<Metadata>();
      MaxResults = MaxResults - tmp.Count();

      Trace.WriteLine("MaxResults: " + tmp.Count());
      return tmp;
    }
 public IActionResult Get([FromBody] TrackSearch search,
                          [FromServices] IGetTracksQuery query)
 {
     return(Ok(_executor.ExecuteQuery(query, search)));
 }