Example #1
0
 public void CuratorRecommended_LimitedSongs()
 {
     var reader = new BeastSaberReader("Zingabopp", DefaultMaxConcurrency) { StoreRawData = true };
     int maxSongs = 60;
     var settings = new BeastSaberFeedSettings((int)BeastSaberFeedName.CuratorRecommended) { MaxSongs = maxSongs };
     var result = reader.GetSongsFromFeedAsync(settings).Result;
     Assert.IsTrue(result.Count == maxSongs);
     Assert.IsFalse(result.Songs.Any(s => string.IsNullOrEmpty(s.Key)));
     Assert.IsFalse(result.Songs.Any(s => s.Value.DownloadUri == null));
     try
     {
         Assert.AreEqual(2, result.PagesChecked);
     }
     catch (AssertFailedException)
     {
         for(int i = 0; i < result.PageResults.Count(); i++)
         {
             var page = result.PageResults[i];
             Console.WriteLine($"Page {i + 1}: {page.Count} songs. {page.Uri}");
         }
         Assert.AreEqual(3, result.PagesChecked);
     }
     var firstSong = result.Songs.First().Value;
     Assert.IsFalse(string.IsNullOrEmpty(firstSong.RawData));
     var firstRawData = JToken.Parse(firstSong.RawData);
     Assert.IsTrue(firstRawData["hash"]?.Value<string>().ToUpper() == firstSong.Hash);
 }
        public void Followings_Exception_NullSettings()
        {
            var reader = GetDefaultReader();
            BeastSaberFeedSettings settings = null;

            Assert.ThrowsException <ArgumentNullException>(() => reader.GetSongsFromFeed(settings));
        }
        public void Following_Username()
        {
            var settings = new BeastSaberFeedSettings(BeastSaberFeedName.Following, "TestUser");
            var feed     = new BeastSaberFeed(settings);

            feed.EnsureValidSettings();
            Assert.IsTrue(feed.HasValidSettings);
        }
        public void CuratorRecommended_Username()
        {
            var settings = new BeastSaberFeedSettings(BeastSaberFeedName.CuratorRecommended, "TestUser");
            var feed     = new BeastSaberFeed(settings);

            feed.EnsureValidSettings();
            Assert.IsTrue(feed.HasValidSettings);
        }
        public void Following_NoUsername()
        {
            var settings = new BeastSaberFeedSettings(BeastSaberFeedName.Following);
            var feed     = new BeastSaberFeed(settings);
            var ex       = Assert.ThrowsException <InvalidFeedSettingsException>(() => feed.EnsureValidSettings());

            Console.WriteLine(ex.Message);
            Assert.IsFalse(feed.HasValidSettings);
        }
Example #6
0
 public void Bookmarks_UnlimitedSongs()
 {
     var reader = new BeastSaberReader("Zingabopp", DefaultMaxConcurrency);
     int maxSongs = 0;
     var settings = new BeastSaberFeedSettings((int)BeastSaberFeedName.Bookmarks) { MaxSongs = maxSongs };
     var songList = reader.GetSongsFromFeedAsync(settings).Result;
     Assert.IsTrue(songList.Count > 0);
     Assert.IsFalse(songList.Songs.Any(s => string.IsNullOrEmpty(s.Key)));
 }
Example #7
0
 public void Followings_LimitedSongs()
 {
     var reader = new BeastSaberReader("Zingabopp", DefaultMaxConcurrency) { StoreRawData = true };
     int maxSongs = 60;
     var settings = new BeastSaberFeedSettings((int)BeastSaberFeedName.Following) { MaxSongs = maxSongs };
     var result = reader.GetSongsFromFeedAsync(settings).Result;
     Assert.IsTrue(result.Count == maxSongs);
     //Assert.IsFalse(songList.Count > maxSongs);
     Assert.IsFalse(result.Songs.Any(s => string.IsNullOrEmpty(s.Key)));
 }
Example #8
0
 public void CuratorRecommended_UnlimitedSongs()
 {
     var reader = new BeastSaberReader("Zingabopp", DefaultMaxConcurrency) { StoreRawData = true };
     int maxSongs = 0;
     var settings = new BeastSaberFeedSettings((int)BeastSaberFeedName.CuratorRecommended) { MaxSongs = maxSongs };
     var result = reader.GetSongsFromFeedAsync(settings).Result;
     Assert.IsTrue(result.Count != 0);
     Assert.IsFalse(result.Songs.Any(s => string.IsNullOrEmpty(s.Key)));
     Assert.IsFalse(result.Songs.Any(s => s.Value.DownloadUri == null));
     Assert.IsTrue(result.PagesChecked >= 26);
     var firstSong = result.Songs.First().Value;
     var firstRawData = JToken.Parse(firstSong.RawData);
     Assert.IsTrue(firstRawData["hash"]?.Value<string>().ToUpper() == firstSong.Hash);
 }
        public void Followings_LimitedSongs()
        {
            var reader   = GetDefaultReader();
            int maxSongs = 60;
            var settings = new BeastSaberFeedSettings((int)BeastSaberFeedName.Following)
            {
                MaxSongs = maxSongs
            };
            var songList = reader.GetSongsFromFeed(settings);

            Assert.IsTrue(songList.Count == maxSongs);
            //Assert.IsFalse(songList.Count > maxSongs);
            Assert.IsFalse(songList.Songs.Any(s => string.IsNullOrEmpty(s.Key)));
        }
Example #10
0
        public void GetSongsFromFeed_Bookmarks()
        {
            var reader   = new BeastSaberReader("Zingabopp", DefaultMaxConcurrency);
            int maxSongs = 60;
            var settings = new BeastSaberFeedSettings((int)BeastSaberFeed.Bookmarks)
            {
                MaxSongs = maxSongs
            };
            var songList = reader.GetSongsFromFeed(settings);

            Assert.IsTrue(songList.Count > 0);
            Assert.IsFalse(songList.Count > maxSongs);
            Assert.IsFalse(songList.Any(s => string.IsNullOrEmpty(s.Key)));
        }
        public void CancelledInProgress()
        {
            var         cts      = new CancellationTokenSource(500);
            IFeedReader reader   = new BeastSaberReader("Zingabopp", 1);
            int         maxSongs = 300;
            var         settings = new BeastSaberFeedSettings((int)BeastSaberFeedName.CuratorRecommended)
            {
                MaxSongs = maxSongs
            };
            var result = reader.GetSongsFromFeed(settings, cts.Token);

            Assert.IsFalse(result.Successful);
            Assert.AreEqual(FeedResultError.Cancelled, result.ErrorCode);
            cts.Dispose();
        }
Example #12
0
        public void GetSongsFromFeed_CuratorRecommended_LimitedPages()
        {
            var reader   = new BeastSaberReader("Zingabopp", DefaultMaxConcurrency);
            int maxSongs = 30;
            int maxPages = 2;
            var settings = new BeastSaberFeedSettings((int)BeastSaberFeed.CuratorRecommended)
            {
                MaxPages = maxPages, MaxSongs = maxSongs
            };
            var songList = reader.GetSongsFromFeed(settings);

            Assert.IsTrue(songList.Count == maxSongs);
            Assert.IsFalse(songList.Any(s => string.IsNullOrEmpty(s.Key)));
            Assert.IsFalse(songList.Any(s => s.Value.DownloadUri == null));
        }
        public void CuratorRecommended_LimitedPages()
        {
            var reader   = GetDefaultReader();
            int maxSongs = 55;
            int maxPages = 2;
            var settings = new BeastSaberFeedSettings((int)BeastSaberFeedName.CuratorRecommended)
            {
                MaxPages = maxPages, MaxSongs = maxSongs
            };
            var result = reader.GetSongsFromFeed(settings);

            Assert.IsTrue(result.Count == maxSongs);
            Assert.IsFalse(result.Songs.Any(s => string.IsNullOrEmpty(s.Key)));
            Assert.IsFalse(result.Songs.Any(s => s.Value.DownloadUri == null));
            Assert.AreEqual(2, result.PagesChecked);
        }
        public void CancelledImmediate()
        {
            var cts = new CancellationTokenSource();

            cts.Cancel();
            IFeedReader reader   = GetDefaultReader();
            int         maxSongs = 60;
            var         settings = new BeastSaberFeedSettings((int)BeastSaberFeedName.Following)
            {
                MaxSongs = maxSongs
            };
            var result = reader.GetSongsFromFeed(settings, cts.Token);

            Assert.IsFalse(result.Successful);
            Assert.AreEqual(FeedResultError.Cancelled, result.ErrorCode);
            cts.Dispose();
        }
        public void Followings_SinglePage()
        {
            var reader   = GetDefaultReader();
            int maxSongs = 150;
            int maxPages = 1;
            var settings = new BeastSaberFeedSettings((int)BeastSaberFeedName.Following)
            {
                MaxSongs = maxSongs,
                MaxPages = maxPages
            };
            var songList = reader.GetSongsFromFeed(settings);

            Assert.IsTrue(songList.Count > 0);
            Assert.IsTrue(songList.Count <= 100);
            //Assert.IsFalse(songList.Count > maxSongs);
            Assert.IsFalse(songList.Songs.Any(s => string.IsNullOrEmpty(s.Key)));
        }
Example #16
0
        public void GetSongsFromFeed_Followings_SinglePage()
        {
            var reader   = new BeastSaberReader("Zingabopp", DefaultMaxConcurrency);
            int maxSongs = 150;
            int maxPages = 1;
            var settings = new BeastSaberFeedSettings((int)BeastSaberFeed.Following)
            {
                MaxSongs = maxSongs,
                MaxPages = maxPages
            };
            var songList = reader.GetSongsFromFeed(settings);

            Assert.IsTrue(songList.Count > 0);
            Assert.IsTrue(songList.Count <= 100);
            //Assert.IsFalse(songList.Count > maxSongs);
            Assert.IsFalse(songList.Any(s => string.IsNullOrEmpty(s.Key)));
        }
        public void Followings_SinglePage_LimitedSongs()
        {
            var reader = GetDefaultReader();

            reader.StoreRawData = true;
            int maxSongs = 20;
            int maxPages = 1;
            var settings = new BeastSaberFeedSettings((int)BeastSaberFeedName.Following)
            {
                MaxSongs = maxSongs,
                MaxPages = maxPages
            };
            var songList     = reader.GetSongsFromFeed(settings);
            var pagesChecked = songList.Songs.Values.GroupBy(s => s.SourceUri);

            Assert.IsTrue(pagesChecked.Count() == 1);
            Assert.IsTrue(songList.Count > 0);
            Assert.IsTrue(songList.Count <= 20);
            //Assert.IsFalse(songList.Count > maxSongs);
            Assert.IsFalse(songList.Songs.Any(s => string.IsNullOrEmpty(s.Key)));
        }
        public void Success_XML()
        {
            //var reader = new BeastSaberReader("Zingabopp", DefaultMaxConcurrency) { StoreRawData = true };
            var feedSettings = new BeastSaberFeedSettings(BeastSaberFeedName.Following, "Zingabopp");
            var feed         = new BeastSaberFeed(feedSettings);
            var text         = File.ReadAllText("Data\\BeastSaberXMLPage.xml");
            Uri uri          = null;
            var songList     = BeastSaberFeed.GetSongsFromPageText(text, uri, ContentType.XML, true);

            Assert.IsTrue(songList.Count == 50);
            var firstHash        = "74575254ae759f3f836eb521b4b80093ca52cd3d".ToUpper();
            var firstKey         = "56ff";
            var firstLevelAuthor = "Rustic";
            var firstTitle       = "Xilent – Code Blood";
            var firstDownloadUrl = "https://beatsaver.com/api/download/key/56ff";
            var firstUrl         = "https://beatsaver.com/api/download/key/56ff";
            var firstSong        = songList.First();

            Assert.IsTrue(firstSong.Hash == firstHash);
            Assert.IsTrue(firstSong.DownloadUri.ToString() == firstUrl);
            // Raw Data test
            JToken firstRawData = JToken.Parse(firstSong.RawData);

            Assert.IsTrue(firstRawData["Hash"]?.Value <string>().ToUpper() == firstHash);
            Assert.IsTrue(firstRawData["SongKey"]?.Value <string>() == firstKey);
            Assert.IsTrue(firstRawData["LevelAuthorName"]?.Value <string>() == firstLevelAuthor);
            Assert.IsTrue(firstRawData["SongTitle"]?.Value <string>() == firstTitle);
            Assert.IsTrue(firstRawData["DownloadURL"]?.Value <string>() == firstDownloadUrl);



            var lastHash = "e3487474b70d969927e459a1590e93b7ad25a436".ToUpper();
            var lastUrl  = "https://beatsaver.com/api/download/key/5585";

            Assert.IsTrue(songList.Last().Hash == lastHash);
            Assert.IsTrue(songList.Last().DownloadUri.ToString() == lastUrl);
            Assert.IsFalse(songList.Any(s => string.IsNullOrEmpty(s.Hash)));
            Assert.IsFalse(songList.Any(s => s.DownloadUri == null));
        }