public void OnCreate_Throw_FileNotFoundWhenDirectoryPathPassed() { Assert.That(() => { var dir = Directory.CreateDirectory(Guid.NewGuid().ToString()); MusicFolderLocation.Parse(dir.FullName); }, Throws.TypeOf <FileNotFoundException>()); }
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)); }
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); }
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(); }
private MusicFolderLocation GetSimilarLocation(MusicFolderLocation fileLocation, bool saveStructure) { var newLocation = GetLastLocation(fileLocation.Year); if (saveStructure || newLocation.InnerFolder >= fileLocation.InnerFolder) { newLocation.InnerFolder = fileLocation.InnerFolder; } return(newLocation); }
private MusicFolderLocation GetLastLocation(int year) { var lastLocation = new MusicFolderLocation { RootPath = Path, Year = year }; lastLocation.InnerFolder = GetLastInnerFolder(lastLocation); return(lastLocation); }
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)); }
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()); }
public void OnCreateThrow_FileNotFoundException() { Assert.That(() => { MusicFolderLocation.Parse(Guid.NewGuid().ToString()); }, Throws.TypeOf <FileNotFoundException>()); }