private void GeneratePlaylist(string musicDirectory, string songFile)
        {
            var songProvider = File
             .ReadAllLines(Path.Combine(musicDirectory, songFile))
             .Select(JsonConvert.DeserializeObject<Song>);

             songProvider = FilterSongs(songProvider);

             var addAllsongs = Playlist.SongsInPlaylist(@"F:\Music\Zune\Playlists\Always Add.zpl");

             var songs = new PlaylistGenerator().GeneratePlayList(
             songProvider,
             _totalSongCount,
             addAllsongs)
             .ToArray();

             Func<Song, bool> isJazz = x => string.Equals(x.PrimaryGenre, "Jazz", StringComparison.OrdinalIgnoreCase);
             Func<Song, bool> isClassical = x => string.Equals(x.PrimaryGenre, "Classical", StringComparison.OrdinalIgnoreCase);

             Playlist.SavePlaylist(
            songs.Where(x => ! isJazz(x) && ! isClassical(x)),
            "My Everything Else");
             Playlist.SavePlaylist(songs.Where(isClassical),
            "My Classical");
             Playlist.SavePlaylist(songs.Where(isJazz),
            "My Jazz");
        }
        public void FillsInWithSongsWhenNotEnoughSpecified()
        {
            var all = new List<Song>(GetRandomSongs(75000));
            var songs = new PlaylistGenerator(new List<ICriteriaCounter<Song>>())
                .GeneratePlayList(all, 100, all.Take(50));

            Assert.AreEqual(songs.Count(), 100);
        }
        public void TestAlwaysAdd()
        {
            var alwaysAdd = new List<Song>(GetRandomSongs(250));
            var all = new List<Song>(GetRandomSongs(7500));

            all.AddRange(alwaysAdd);

            var songs = new PlaylistGenerator(new List<ICriteriaCounter<Song>>()).GeneratePlayList(all, alwaysAdd.Count, alwaysAdd);
            CollectionAssert.AreEquivalent(songs.ToArray(), alwaysAdd);
        }
        public void TestCriteriaFilter()
        {
            var firstCat = "one";

            var firstCriteria = new List<Song>(GetRandomSongs(10));
            firstCriteria.ForEach(x => x.Category = firstCat);

            var all = new List<Song>(GetRandomSongs(75000));
            all.AddRange(firstCriteria);

            var criteria = new List<ICriteriaCounter<Song>>() { new CriteriaCounter(song => song.Category == firstCat, firstCriteria.Count() + 100) };

            var songs = new PlaylistGenerator(criteria).GeneratePlayList(all, firstCriteria.Count, new List<Song>());

            CollectionAssert.AreEquivalent(songs.ToArray(), firstCriteria);
        }
        public void TestMultipleCriteriaFilter()
        {
            var firstCat = "one";
            var secondCat = "two";
            var thirdCat = "three";

            var firstCriteria = new List<Song>(GetRandomSongs(10));
            firstCriteria.ForEach(x => x.Category = firstCat);
            var secondCriteria = new List<Song>(GetRandomSongs(50));
            secondCriteria.ForEach(x => x.Category = secondCat);
            var thirdCriteria = new List<Song>(GetRandomSongs(150));
            thirdCriteria.ForEach(x => x.Category = thirdCat);

            var criteriaList = new List<Song>();
            criteriaList.AddRange(firstCriteria);
            criteriaList.AddRange(secondCriteria);
            criteriaList.AddRange(thirdCriteria);

            var all = new List<Song>(GetRandomSongs(75000));
            all.AddRange(criteriaList);

            var criteria = new List<ICriteriaCounter<Song>>()
            {
                new CriteriaCounter(song => song.Category == firstCat, firstCriteria.Count()),
                new CriteriaCounter(song => song.Category == secondCat, secondCriteria.Count()),
                new CriteriaCounter(song => song.Category == thirdCat, thirdCriteria.Count()),
            };

            var songs = new PlaylistGenerator(criteria).GeneratePlayList(all, criteriaList.Count, new List<Song>());

            CollectionAssert.AreEqual(
                songs.OrderBy(x => x.GetHashCode()).ToArray(),
                criteriaList.OrderBy(x => x.GetHashCode()).ToArray());
        }