Esempio n. 1
0
        private static void TestFine()
        {
            string path = VirtualDrive.VirtualFileName(@"TestAlbumExplorerProcessor\TestFine\");
            TestTags.CreateDemoTags(path, 6, n => n.Album = "Album");

            AlbumExplorerProcessor processor = new AlbumExplorerProcessor();

            bool succeded = false;
            bool failed = false;

            processor.FineCallback += delegate(AlbumExplorer.AlbumResult album)
            {
                UnitTest.Test(album.Album.Result == AlbumExplorer.ParseResult.Fine);
                UnitTest.Test(album.Album[FrameMeaning.Artist] == "Artist");
                UnitTest.Test(album.Album[FrameMeaning.Album] == "Album");
                UnitTest.Test(album.Album[FrameMeaning.ReleaseYear] == "1993");

                succeded = true;
            };
            processor.BadCallback += delegate(AlbumExplorer.AlbumResult album)
            {
                failed = true;
            };

            processor.Process(new DirectoryInfo(path));

            UnitTest.Test(succeded);
            UnitTest.Test(!failed);

            VirtualDrive.DeleteDirectory(path, true);
        }
Esempio n. 2
0
        private static void TestFileProcessorRecordAndPlay()
        {
            string undoFileName = VirtualDrive.VirtualFileName(
                @"TestFileProcessorRecordAndPlay\UndoFile.txt");

            FileInfo[] fileInfos =
                (from x in TestTags.Demotags select VirtualDrive.CreateVirtualFileInfo(
                     @"TestFileProcessorRecordAndPlay\TestFileProcessor" + x + ".mp3")).ToArray();

            fileInfos.ForEach((n) => TagUtils.WriteTag(TestTags.CreateDemoTag(Version.v2_0), n));

            using (UndoFileWriter undoFileWriter = new UndoFileWriter(undoFileName))
            {
                FileProcessor processor = new FileProcessor(new TagVersionProcessor(Version.v2_3));
                processor.UndoFile = undoFileWriter;

                foreach (var obj in fileInfos)
                {
                    processor.Process(obj);
                }
            }

            fileInfos.ForEach((n) => UnitTest.Test(TagUtils.ReadVersion(n) == Version.v2_3));

            UndoFilePlayer.Undo(undoFileName);

            fileInfos.ForEach((n) => UnitTest.Test(TagUtils.ReadVersion(n) == Version.v2_0));

            UndoFilePlayer.Redo(undoFileName);

            fileInfos.ForEach((n) => UnitTest.Test(TagUtils.ReadVersion(n) == Version.v2_3));

            VirtualDrive.DeleteDirectory(VirtualDrive.VirtualFileName(
                                             @"TestFileProcessorRecordAndPlay"), true);
        }
Esempio n. 3
0
        private static void TestFine_NoReleaseYearRequired()
        {
            string path = VirtualDrive.VirtualFileName(@"TestAlbumExplorerProcessor\TestFine_NoReleaseYearRequired\");
            TestTags.CreateDemoTags(path, 6, n => n.ReleaseYear = "");

            AlbumExplorerProcessor processor = new AlbumExplorerProcessor();
            processor.Explorer.ReleaseYearRequired = false;

            TestSuccess(path, processor);
        }
Esempio n. 4
0
        private static void TestFailingPattern()
        {
            string path = VirtualDrive.VirtualFileName(@"TestAlbumTagToFilenameProcessor\TestFailingPattern\");

            TestTags.CreateDemoTags(path, 6, n => n.Artist = null);

            string[] filesBefore = VirtualDrive.GetFiles(path, "*.mp3");

            AlbumTagToFilenameProcessor processor = new AlbumTagToFilenameProcessor(
                "Artist - Album - TrackNumber - Title");

            processor.Process(new DirectoryInfo(path));

            string[] filesAfter = VirtualDrive.GetFiles(path, "*.mp3");

            UnitTest.Test(filesBefore.SequenceEqual(filesAfter));

            VirtualDrive.DeleteDirectory(path, true);
        }
Esempio n. 5
0
        static void TestCreateTrackNumbers()
        {
            Tag[] tags =
            {
                TestTags.CreateDemoTag(Version.v2_3),
                TestTags.CreateDemoTag(Version.v2_3),
                TestTags.CreateDemoTag(Version.v2_3)
            };

            string[] patterns =
            {
                "0",
                "00",
                "0/0",
                "00/00",
                "0 0",
            };
            string[,] expected =
            {
                { "1",     "2",     "3"     },
                { "01",    "02",    "03"    },
                { "1/3",   "2/3",   "3/3"   },
                { "01/03", "02/03", "03/03" },
                { "1 3",   "2 3",   "3 3"   },
            };

            for (int i = 0; i < patterns.Length; i++)
            {
                TagProcessorTrackNumber processor = new TagProcessorTrackNumber(
                    new TrackNumberGenerator(patterns[i]));

                for (int j = 0; j < tags.Length; j++)
                {
                    processor.ProcessMessage(new DirectoryProcessor.Message(tags.Length, j));
                    processor.Process(tags[j]);
                }

                for (int j = 0; j < tags.Length; j++)
                {
                    UnitTest.Test(new TagEditor(tags[j]).TrackNumber == expected[i, j]);
                }
            }
        }
Esempio n. 6
0
        private static void TestBad()
        {
            string path = VirtualDrive.VirtualFileName(@"TestAlbumExplorerProcessor\TestBadArtistMissing\");

            TestTags.CreateDemoTags(path, 6, n => n.Artist = "");
            TestFailure(path, AlbumExplorer.ParseResult.ArtistNameFailed);

            TestTags.CreateDemoTags(path, 6, n => n.Album = "");
            TestFailure(path, AlbumExplorer.ParseResult.AlbumNameFailed);

            TestTags.CreateDemoTags(path, 6, n => n.Title = "");
            TestFailure(path, AlbumExplorer.ParseResult.TrackNameMissing);

            TestTags.CreateDemoTags(path, 6, n => n.TrackNumber = "");
            TestFailure(path, AlbumExplorer.ParseResult.TrackIndexFailed);

            TestTags.CreateDemoTags(path, 6, n => n.Title = "Track");
            TestFailure(path, AlbumExplorer.ParseResult.TrackNameDummy);

            TestTags.CreateDemoTags(path, 6, n => n.ReleaseYear = "");
            TestFailure(path, AlbumExplorer.ParseResult.YearFailed);
        }
Esempio n. 7
0
        private static void TestFullPattern()
        {
            string path = VirtualDrive.VirtualFileName(@"TestAlbumTagToFilenameProcessor\TestFullPattern\");

            TestTags.CreateDemoTags(path, 6, n => n.Album = "Album");

            AlbumTagToFilenameProcessor processor = new AlbumTagToFilenameProcessor(
                "Artist - Album - TrackNumber - Title");

            processor.Process(new DirectoryInfo(path));

            string[] files = VirtualDrive.GetFiles(path, "*.mp3");

            UnitTest.Test(files.Length == 6);
            for (int i = 0; i < files.Length; i++)
            {
                string expected = Path.Combine(path, "Artist - Album - " + (i + 1) + " - Song No. " + (i + 1) + ".mp3");
                UnitTest.Test(files[i] == expected);
            }

            VirtualDrive.DeleteDirectory(path, true);
        }
        private static void TestFullPattern()
        {
            string path = VirtualDrive.VirtualFileName(@"TestAlbumTagToDirectoryProcessor\TestFullPattern\");

            TestTags.CreateDemoTags(path, 6, n => n.ReleaseYear = "1993");

            AlbumTagToDirectoryProcessor processor = new AlbumTagToDirectoryProcessor(
                "Artist - Album{ (ReleaseYear)}");

            AlbumExplorer.AlbumResult obj =
                new AlbumExplorer.AlbumResult(new DirectoryInfo(path));
            obj.Album[FrameMeaning.Artist]      = "Artist";
            obj.Album[FrameMeaning.Album]       = "Album";
            obj.Album[FrameMeaning.ReleaseYear] = "1993";

            processor.Process(obj);

            string expectedPath = VirtualDrive.VirtualFileName(
                @"TestAlbumTagToDirectoryProcessor\Artist - Album (1993)\");

            VirtualDrive.ExistsDirectory(expectedPath);
            VirtualDrive.DeleteDirectory(expectedPath, true);
        }
Esempio n. 9
0
        private static void TestCopy()
        {
            string pathSrc     = VirtualDrive.VirtualFileName(@"TestAlbumToLibraryProcessor\TestCopy\Src\");
            string pathLibrary = VirtualDrive.VirtualFileName(@"TestAlbumToLibraryProcessor\TestCopy\Lib\");

            VirtualDrive.Store(Path.Combine(pathLibrary, "test.mp3"), new byte[] {});
            TestTags.CreateDemoTags(pathSrc, 3, n => n.ReleaseYear = "1993");

            AlbumToLibraryProcessor processor = new AlbumToLibraryProcessor(
                pathLibrary, FileOperationProcessor.FileOperation.Copy, FileOperationProcessor.ConflictSolving.Skip);

            AlbumExplorer.AlbumResult obj =
                new AlbumExplorer.AlbumResult(new DirectoryInfo(pathSrc));
            obj.Album[FrameMeaning.Artist]      = "Artist";
            obj.Album[FrameMeaning.Album]       = "Album";
            obj.Album[FrameMeaning.ReleaseYear] = "1993";

            processor.Process(obj);

            VirtualDrive.ExistsDirectory(pathSrc);

            string expectedDst = Path.Combine(pathLibrary, "Artist - Album (1993)");

            VirtualDrive.ExistsDirectory(expectedDst);

            string[] files = VirtualDrive.GetFiles(expectedDst, "*.mp3");

            UnitTest.Test(files.Length == 3);
            for (int i = 0; i < files.Length; i++)
            {
                string expected = Path.Combine(expectedDst, "Test" + i + ".mp3");
                UnitTest.Test(files[i] == expected);
            }

            VirtualDrive.DeleteDirectory(pathSrc, true);
            VirtualDrive.DeleteDirectory(pathLibrary, true);
        }