public void SongRootObjectSetterTest()
        {
            SongRoot sr1 = new SongRoot()
            {
                ID      = 1,
                Name    = "name of song root",
                GenreID = 50
            };

            ApiSong api1 = new ApiSong()
            {
                ID     = 5,
                Name   = "name of api song",
                Artist = "artist of api song",
                Album  = "album of api song",
                Genre  = "slow song"
            };

            List <ApiSong> apiList1 = new List <ApiSong>();

            apiList1.Add(api1);
            sr1.Songs = apiList1;

            sr1.ID              = 20;
            sr1.Name            = "new name of api song";
            sr1.GenreID         = 80;
            sr1.Songs[0].Artist = "name of a new artist here";

            Assert.Equal(20, sr1.ID);
            Assert.Equal("new name of api song", sr1.Name);
            Assert.Equal(80, sr1.GenreID);
            Assert.Equal("name of a new artist here", sr1.Songs[0].Artist);
        }
        public void SongRootObjectGetterTest()
        {
            SongRoot sr = new SongRoot()
            {
                ID      = 1,
                Name    = "name of song root",
                GenreID = 50
            };

            ApiSong api = new ApiSong()
            {
                ID     = 5,
                Name   = "name of api song",
                Artist = "artist of api song",
                Album  = "album of api song",
                Genre  = "slow song"
            };

            List <ApiSong> apiList = new List <ApiSong>();

            apiList.Add(api);
            sr.Songs = apiList;

            Assert.Equal(1, sr.ID);
            Assert.Equal("name of song root", sr.Name);
            Assert.Equal(50, sr.GenreID);
            Assert.Equal("name of api song", sr.Songs[0].Name);
        }
Example #3
0
        public void ApiSongGetterandSetters()
        {
            DbContextOptions <MusicDbContext> options = new DbContextOptionsBuilder <MusicDbContext>()
                                                        .UseInMemoryDatabase("GetterSetterSongDB").Options;

            using (MusicDbContext context = new MusicDbContext(options))
            {
                //Arrange
                ApiSong testApiSong1 = new ApiSong();
                testApiSong1.Name       = "Gonna Give You Up";
                testApiSong1.Artist     = "Slick Rick";
                testApiSong1.Genre      = "oldies";
                testApiSong1.PlaylistID = 37;

                testApiSong1.Name        = "Just Testing API Songs";
                testApiSong1.Artist      = "Ron Testmaster";
                testApiSong1.Genre       = "top 40 hits";
                testApiSong1.PlaylistID  = 40;
                testApiSong1.ReleaseDate = new DateTime(2018, 05, 5, 14, 1, 1, 111);

                Assert.False(testApiSong1.Equals("Gonna Give You Up"));
                Assert.Equal("Just Testing API Songs", testApiSong1.Name);
                Assert.Equal("Ron Testmaster", testApiSong1.Artist);
                Assert.Equal("top 40 hits", testApiSong1.Genre);
                Assert.Equal(40, testApiSong1.PlaylistID = 40);
                Assert.Equal(new DateTime(2018, 05, 5, 14, 1, 1, 111), testApiSong1.ReleaseDate);
            }
        }
        public void CheckingForApiSongClassGetter()
        {
            PlaylistViewModel plVM = new PlaylistViewModel();

            plVM.User = new User
            {
                Id         = 1,
                Name       = "username",
                GenreID    = 27,
                PlaylistID = 1
            };


            Playlist pl = new Playlist()
            {
                Id      = 1,
                Name    = "playlist name",
                GenreID = 27,
                UserID  = 1
            };

            List <Playlist> plList = new List <Playlist>();

            plList.Add(pl);
            plVM.Playlists = plList;

            ApiSong apiSong = new ApiSong()
            {
                ID     = 1,
                Name   = "Api song name",
                Artist = "API song artist",
                Album  = "API Song Alubm"
            };

            List <ApiSong> apiList = new List <ApiSong>();

            apiList.Add(apiSong);
            plVM.ApiSongs = apiList;

            Song song = new Song()
            {
                ID        = 1,
                Name      = "Song name",
                Artist    = "song artist",
                Album     = "Song Album",
                Genre     = "Blues",
                OurListId = 1
            };

            List <Song> songList = new List <Song>();

            songList.Add(song);
            plVM.Songs = songList;

            Assert.Equal("username", plVM.User.Name);
            Assert.Equal("playlist name", plVM.Playlists[0].Name);
            Assert.Equal("Api song name", plVM.ApiSongs[0].Name);
            Assert.Equal(song, plVM.Songs[0]);
        }
Example #5
0
        /// <summary>
        /// Downloads any data from the GensokyoRadio JSON API and stores it in the class.
        /// </summary>
        /// <returns></returns>
        public async Task FetchRawApiData()
        {
            using (HttpClient client = new HttpClient())
                using (HttpResponseMessage response = await client.GetAsync(ApiUrl))
                    using (HttpContent content = response.Content)
                    {
                        var rawJsonResult = await content.ReadAsStringAsync();

                        var jsonSong = JsonConvert.DeserializeObject <ApiSong>(rawJsonResult, new UnixDateTimeConverter());

                        CurrentApiSong = jsonSong;
                    }
        }
Example #6
0
        /// <summary>
        /// Generating a custom playlist based on the picking the random songs
        /// </summary>
        /// <param name="id"> selected user ID </param>
        /// <returns></returns>
        public async Task <IActionResult> CreateCustomPlaylist(int id)
        {
            var user = await _context.Users.FirstOrDefaultAsync(u => u.Id == id);

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://musicparserapi.azurewebsites.net");
                var songsResponse = client.GetAsync("/api/song").Result;
                if (songsResponse.EnsureSuccessStatusCode().IsSuccessStatusCode)
                {
                    var jsonDataSongs = await songsResponse.Content.ReadAsStringAsync();

                    List <ApiSong> rawAllSongs = JsonConvert.DeserializeObject <List <ApiSong> >(jsonDataSongs);


                    var allSongs = from a in rawAllSongs
                                   select a;

                    // Creating place holders of custom song.id
                    var         sortedSongs = allSongs.ToList();
                    List <int>  idRef       = new List <int>();
                    List <Song> customList  = new List <Song>();
                    Playlist    playlist    = new Playlist();

                    playlist.UserID = user.Id;

                    await _context.Playlists.AddAsync(playlist);

                    await _context.SaveChangesAsync();

                    user.PlaylistID = playlist.Id.Value;


                    _context.Users.Update(user);
                    await _context.SaveChangesAsync();

                    // Picking random 25 songs from the song list
                    for (int i = 0; i < 24; i++)
                    {
                        Random rdm = new Random();
                        int    idX = rdm.Next(0, sortedSongs.Count());
                        if (!idRef.Contains(idX))
                        {
                            ApiSong apiSong = sortedSongs.Find(s => s.ID == idX);

                            if (apiSong != null)
                            {
                                // Moving ApiSong objec to Song object to save onto db
                                idRef.Add(idX);
                                Song newsong = new Song();
                                newsong.Name = apiSong.Name;

                                newsong.ApiListId = user.PlaylistID;
                                newsong.OurListId = user.PlaylistID;

                                newsong.ReleaseDate = apiSong.ReleaseDate;
                                newsong.Album       = apiSong.Album;
                                newsong.Artist      = apiSong.Artist;
                                newsong.Genre       = apiSong.Genre;
                                await _context.Songs.AddAsync(newsong);

                                await _context.SaveChangesAsync();
                            }
                            // if condition is not applied, minus one from i to repeat the process
                            else
                            {
                                i--;
                            }
                        }
                        else
                        {
                            i--;
                        }
                    }
                    return(RedirectToAction("Get", "Playlist", new { id = user.Id }));
                }
                return(NotFound());
            }
        }