Ejemplo n.º 1
0
        public TrackPagedList FilterTracks(TrackPagedList pagedTracks)
        {
            IList<Track> filteredTracks = pagedTracks.Tracks.Where(track => !searchTrackRules.Any(s => s.IsTrackRestricted(track))).ToList();

            pagedTracks.Tracks = filteredTracks;
            pagedTracks.Total = pagedTracks.Tracks.Count();
            return pagedTracks;
        }
Ejemplo n.º 2
0
        public void Check_that_we_dont_get_a_track_back_when_track_is_restricted()
        {
            // Arrange
            var trackPagedList = new TrackPagedList { Tracks = new List<Track> { track }, Total = 1 };

            var rule = new Mock<ISearchTrackRule>();
            rule.Setup(r => r.IsTrackRestricted(track)).Returns(true);

            var listOfTrackRules = new List<ISearchTrackRule> { rule.Object };
            var listOfAlbumRules = new Mock<IEnumerable<ISearchAlbumRule>>();
            var listOfArtistRules = new Mock<IEnumerable<ISearchArtistRule>>();

            var classUnderTest = new SearchRuleHelper(listOfTrackRules, listOfAlbumRules.Object, listOfArtistRules.Object);

            // Act
            var result = classUnderTest.FilterTracks(trackPagedList);

            // Assert
            Assert.That(result.Tracks.FirstOrDefault() == null);
            Assert.That(result.Total == 0);
        }
Ejemplo n.º 3
0
        public SearchResults SearchAll(string searchTerm, string user)
        {
            Login();
            using (var search = session.Search(searchTerm, 0, 30, 0, 15, 0, 15, 0, 0, sp_search_type.STANDARD))
            {
                search.WaitForCompletion();
                if (!search.IsComplete)
                {
                    logger.Error("Search for {0} timed out", searchTerm);
                    return null;
                }
                var results = new SearchResults();

                //set up artists
                var pagedArtists = new ArtistPagedList
                {
                    Total = search.TotalArtists,
                    Artists = search.Artists.Select(a => new ArtistMapper().Map(a, this)).ToArray()
                };

                //set up albums
                var pagedAlbums = new AlbumPagedList
                {
                    Total = search.TotalAlbums,
                    Albums = search.Albums.Where(a => a.IsAvailable)
                        .Select(a => albumMapper.Map(a, this, true))
                        .ToArray()
                };

                ////set up tracks
                var pagedTracks = new TrackPagedList
                {
                    Total = search.TotalTracks,
                    Tracks = search.Tracks
                        .Select(t => trackMapper.Map(t, this, user, true, true))
                        .Where(t => t.IsAvailable)
                        .ToArray()
                };

                results.PagedArtists = pagedArtists;
                results.PagedAlbums = pagedAlbums;
                results.PagedTracks = pagedTracks;

                return results;
            }
        }