Esempio n. 1
0
        public void TestValidFile_TestFileNameAllDays()
        {
            // Check the file is OK
            string singleDayPath = PathUtilities.GetPathToFile(PathUtilities.TestFileNameAllDays);

            Assert.IsTrue(File.Exists(singleDayPath));

            // Get the albums
            List <AlbumPlayed> albums = SongFileParser.GetAlbumsPlayedFromFile(singleDayPath);

            Assert.IsNotNull(albums);
            Assert.IsTrue(albums.Count > 900);

            // Check the first Day's LP
            CheckAlbum_0(albums[0]);
            CheckAlbum_1(albums[1]);
            CheckAlbum_2(albums[2]);

            // Check the second Day's LP
            CheckAlbum_3(albums[3]);
            CheckAlbum_4(albums[4]);
            CheckAlbum_5(albums[5]);

            // Check the third Day's LP
            CheckAlbum_6(albums[6]);
            CheckAlbum_7(albums[7]);
            CheckAlbum_8(albums[8]);


            // Check the last LP
            CheckAlbum_Last(albums.Last());
        }
Esempio n. 2
0
        public void TestInvalidFile()
        {
            Assert.IsTrue(File.Exists(TestFilePathAllDays));

            string invalidFile = PathUtilities.TestFileNameAllDays + ".nothing";

            Assert.IsFalse(File.Exists(invalidFile));

            var albums = SongFileParser.GetAlbumsPlayedFromFile(invalidFile);

            Assert.IsNotNull(albums);
            Assert.AreEqual(0, albums.Count);
        }
Esempio n. 3
0
        public void TestValidFile_SingleAlbumDay()
        {
            // Check the file is OK
            string singleAlbumPath = PathUtilities.GetPathToFile(PathUtilities.TestFileNameSingleAlbum);

            Assert.IsTrue(File.Exists(singleAlbumPath));

            // Get the album
            List <AlbumPlayed> albums = SongFileParser.GetAlbumsPlayedFromFile(singleAlbumPath);

            Assert.IsNotNull(albums);
            Assert.AreEqual(1, albums.Count);

            // Check the first LP
            CheckAlbum_0(albums[0]);
        }
Esempio n. 4
0
        public void TestValidFile_TestFileNameMultipleSongsSingleDay()
        {
            // Check the file is OK
            string singleDayPath = PathUtilities.GetPathToFile(PathUtilities.TestFileNameMultipleSongsSingleDay);

            Assert.IsTrue(File.Exists(singleDayPath));

            // Get the albums
            List <AlbumPlayed> albums = SongFileParser.GetAlbumsPlayedFromFile(singleDayPath);

            Assert.IsNotNull(albums);
            Assert.AreEqual(3, albums.Count);

            // Check the first LP
            CheckAlbum_0(albums[0]);

            // Check the second LP
            CheckAlbum_1(albums[1]);

            // Check the third LP
            CheckAlbum_2(albums[2]);
        }
Esempio n. 5
0
        public SongsFilesDetailsResponse GetAllAlbumsPlayedFromFile(string key)
        {
            SongsFilesDetailsResponse resp = new SongsFilesDetailsResponse
            {
                FileName  = key,
                ErrorCode = (int)SongsFilesResponseCode.Success
            };

            string fullPath =
                FileUtilities.GetFullSongsDetailsFilePath(key, _uploaderSettings.UploadFilesDirectory);

            if (System.IO.File.Exists(fullPath))
            {
                List <AlbumPlayed> albums = new List <AlbumPlayed>();

                if (fullPath.ToLower().EndsWith(".txt"))
                {
                    albums = SongFileParser.GetAlbumsPlayedFromFile(fullPath);
                }
                else if (fullPath.ToLower().EndsWith(".csv"))
                {
                    albums = SongFileParserCsv.GetAlbumsPlayedFromFile(fullPath);
                }
                else if (fullPath.ToLower().EndsWith(".json"))
                {
                    albums = SongFileParserJson.GetAlbumsPlayedFromFile(fullPath);
                }

                if (albums == null || !albums.Any())
                {
                    resp.ErrorCode  = (int)SongsFilesResponseCode.NoSongsInFile;
                    resp.FailReason = "No songs in file.";
                }
                else
                {
                    resp.AlbumsPlayed = new DisplayAlbum[albums.Count];
                    for (int i = 0; i < albums.Count; i++)
                    {
                        resp.AlbumsPlayed[i] = new DisplayAlbum
                        {
                            Date       = albums[i].Date,
                            Location   = albums[i].Location,
                            Artist     = albums[i].Artist,
                            Album      = albums[i].Album,
                            ImagePath  = albums[i].ImagePath,
                            PlayerLink = albums[i].PlayerLink,
                            UserName   = albums[i].UserName,
                            Id         = albums[i].Id.ToString()
                        }
                    }
                    ;
                }
            }
            else
            {
                resp.ErrorCode  = (int)SongsFilesResponseCode.InvalidFile;
                resp.FailReason = "No such file exists.";
            }

            return(resp);
        }