Esempio n. 1
0
        public void TestInvalidFile()
        {
            Assert.IsTrue(File.Exists(TestFilePathAllDays));

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

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

            var albums = SongFileParserJson.GetAlbumsPlayedFromFile(invalidFile);

            Assert.IsNotNull(albums);
            Assert.AreEqual(0, albums.Count);
        }
Esempio n. 2
0
        public void TestValidFile_TestFileNameSingleDay()
        {
            // Check the file is OK
            string singleDayPath = PathUtilities.GetPathToFile(PathUtilities.TestFileNameSingleDayJson);

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

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

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

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

            // Check the second LP
            CheckAlbum_1(albums[1]);
        }
Esempio n. 3
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);
        }