public void Test_Changer() { var file = new TestMp3File("[1999] 1. art1 - ttl1.mp3") { TrackId = "5", Artist = "art5", Title = "ttl5", Year = "1995" }; const string mask = "[{year}] {id}. {artist} - {title}"; var changer = new Mp3TagChanger(file, mask, new TestRollbackSaver(new List <string>())); changer.ChangeTags(); Assert.AreEqual(file.Artist, "art1"); Assert.AreEqual(file.TrackId, "1"); Assert.AreEqual(file.Year, "1999"); Assert.AreEqual(file.Title, "ttl1"); }
public static void Main(string[] args) { /*try * {*/ var argsManager = new ArgsManager(args); argsManager.CheckArgsValidity(); var data = argsManager.ExtactArgs(); Mp3File mp3; IEnumerable <IMp3File> mp3Files; switch (data.Action) { case ProgramAction.Analyse: mp3Files = Directory.GetFiles(data.Path, "*.mp3").Select(file => new Mp3File(file, new FileSaver(file))).ToArray(); var pathAnalyser = new Mp3FileAnalyser(mp3Files, data.Mask); var differences = pathAnalyser.GetDifferences(); new CommunicationWithUser().ShowDifferences(differences, new ConsoleCommunication()); foreach (var mp3File in mp3Files) { mp3File?.Dispose(); } break; case ProgramAction.Mp3Edit: using (mp3 = new Mp3File(data.Path, new FileSaver(data.Path))) { var tagsChanger = new Mp3TagChanger(mp3, data.Mask, new FileSaver(RollbackData)); tagsChanger.ChangeTags(); } break; case ProgramAction.FileRename: using (mp3 = new Mp3File(data.Path, new FileSaver(data.Path))) { var renamer = new Mp3FileNameChanger(mp3, data.Mask, new FileSaver(RollbackData)); var newFileName = renamer.GetNewFileName(); mp3.ChangeFileName(newFileName); } break; case ProgramAction.Sync: mp3Files = Directory.GetFiles(data.Path, "*.mp3").Select(file => new Mp3File(file, new FileSaver(file))).ToArray(); var syncer = new Mp3Syncing(mp3Files, data.Mask, new ConsoleCommunication(), new FileSaver(RollbackData)); syncer.SyncFiles(); foreach (var mp3File in mp3Files) { mp3File?.Dispose(); } break; case ProgramAction.Rollback: using (var rollbackSystem = new RollbackManager(new FileSaver(RollbackData))) { var state = rollbackSystem.Rollback(); Console.WriteLine( state.State == RollbackState.Fail ? $"Error occured while trying doing rollback. Details : \n\tError:{state.FailReason}" : $"Rollback success."); } break; default: throw new ArgumentOutOfRangeException(); } Console.WriteLine("Done!"); /*} * catch (Exception e) * { #if DEBUG * Console.WriteLine("Exeption: \r\n{0} \r\n\nAt:\n{1}", e.Message, e.StackTrace); #else * Console.WriteLine("Error occured: {0}", e.Message); #endif * } * finally * { * Console.ReadKey(); * }*/ }