Beispiel #1
0
 public void OnCreate_Throw_FileNotFoundWhenDirectoryPathPassed()
 {
     Assert.That(() => {
         var dir = Directory.CreateDirectory(Guid.NewGuid().ToString());
         MusicFolderLocation.Parse(dir.FullName);
     }, Throws.TypeOf <FileNotFoundException>());
 }
Beispiel #2
0
        public void ReturnsValid_RootPath()
        {
            var musicFolder    = new MusicFolder("test", true);
            var newFilePath    = musicFolder.MoveFile(CreateFile()).NewFilePath;
            var folderLocation = MusicFolderLocation.Parse(newFilePath);

            Assert.True(folderLocation.RootPath.Equals(musicFolder.Path, StringComparison.OrdinalIgnoreCase));
        }
Beispiel #3
0
        public void ReturnsValid_Year()
        {
            var musicFolder    = new MusicFolder("test", true);
            var newFilePath    = musicFolder.MoveFile(CreateFile()).NewFilePath;
            var expectedYear   = DateTime.Now.Year;
            var folderLocation = MusicFolderLocation.Parse(newFilePath);

            Assert.AreEqual(expectedYear, folderLocation.Year);
        }
Beispiel #4
0
        public void ReturnsValid_InnerFolderNumber()
        {
            var       musicFolder         = new MusicFolder("test", true);
            var       newFilePath         = musicFolder.MoveFile(CreateFile()).NewFilePath;
            const int expectedInnerFolder = 0;
            var       folderLocation      = MusicFolderLocation.Parse(newFilePath);

            Assert.AreEqual(expectedInnerFolder, folderLocation.InnerFolder);
        }
            public Parser(string path)
            {
                file = new FileInfo(path);
                if (!file.Exists)
                {
                    throw new FileNotFoundException("not found", path);
                }

                folderLocation = new MusicFolderLocation();
            }
Beispiel #6
0
        private MusicFolderLocation GetSimilarLocation(MusicFolderLocation fileLocation, bool saveStructure)
        {
            var newLocation = GetLastLocation(fileLocation.Year);

            if (saveStructure || newLocation.InnerFolder >= fileLocation.InnerFolder)
            {
                newLocation.InnerFolder = fileLocation.InnerFolder;
            }

            return(newLocation);
        }
Beispiel #7
0
        private MusicFolderLocation GetLastLocation(int year)
        {
            var lastLocation = new MusicFolderLocation
            {
                RootPath = Path,
                Year     = year
            };

            lastLocation.InnerFolder = GetLastInnerFolder(lastLocation);

            return(lastLocation);
        }
Beispiel #8
0
        private MusicFolderLocation GetNewLocation(string filePath, bool saveStructure)
        {
            var fileLocation = MusicFolderLocation.TryParse(filePath);

            if (fileLocation == null)
            {
                return(CalcLastLocation());
            }

            if (fileLocation.RootPath.Equals(Path, StringComparison.OrdinalIgnoreCase))
            {
                return(fileLocation);
            }

            return(GetSimilarLocation(fileLocation, saveStructure));
        }
Beispiel #9
0
        private static int GetLastInnerFolder(MusicFolderLocation location)
        {
            if (!Directory.Exists(location.YearPath))
            {
                return(0);
            }

            int lastInnerFolderNumber;

            var folderNumbers = Directory.GetDirectories(location.YearPath)
                                .Select(IOPath.GetFileName)
                                .Where(innerFolder => Int32.TryParse(innerFolder, out lastInnerFolderNumber))
                                .Select(Int32.Parse)
                                .OrderBy(n => n)
                                .ToList();

            return(folderNumbers.LastOrDefault());
        }
Beispiel #10
0
 public void OnCreateThrow_FileNotFoundException()
 {
     Assert.That(() => {
         MusicFolderLocation.Parse(Guid.NewGuid().ToString());
     }, Throws.TypeOf <FileNotFoundException>());
 }