public void Test()
        {
            var song1 = "song1";
            var song2 = "song2";
            var song3 = "song3";
            var song4 = "song4";

            _songs = new MusicInfo[] {
                    new MusicInfo() { FullPath = song1 },
                    new MusicInfo() { FullPath = song2 },
                    new MusicInfo() { FullPath = song3 },
                    new MusicInfo() { FullPath = song4 }
                };

            var library = new MemoryLibraryRepository();
            library.ClearLibrary();
            library.AddMusicToLibrary(_songs);

            var loopingWatcher = new RandomSongPlaylistWatcher(2);
            _playlist = new Playlist(loopingWatcher);
            _dummyAudio = new DummyAudioInteractor();

            var player = new Player(_playlist, _dummyAudio, library);

            loopingWatcher.AttachToPlaylist(_playlist, library);

            player.MaxPlayCount = 3;
            player.Play();
        }
예제 #2
0
        public void AddMusicToLibrary()
        {
            var music = new MusicInfo()
            {
                Album = "Test Album",
                Artist = "Test Artist",
                FullPath = "Test Path",
                Title = "Test Title"
            };

            var pubnubStub = MockRepository.GenerateStub<IRealTimeMessaging>();
            pubnubStub.Stub(X => X.SendSongsAdded(null));

            var repository = new MemoryLibraryRepository(pubnubStub);
            repository.ClearLibrary();

            repository.AddMusicToLibrary(new MusicInfo[] {music});

            List<MusicInfo> result = repository.GetAllMusic();

            Assert.IsNotNull(result, "The result must not be null.");
            Assert.AreEqual(1, result.Count, "There must only be one song.");
            Assert.AreEqual(music.Album, result[0].Album, "The result must be for the correct album.");
            Assert.AreEqual(music.Artist, result[0].Artist, "The artist must be correct.");
            Assert.AreEqual(music.Title, result[0].Title, "The title must be correct.");
            Assert.AreEqual(music.FullPath, result[0].FullPath, "The full path must be correct.");

            pubnubStub.AssertWasCalled(X => X.SendSongsAdded(null), Y => Y.IgnoreArguments());
        }
예제 #3
0
        public void MemoryLibraryShouldBeSingleton()
        {
            var music = new MusicInfo()
            {
                Album = "Test Album",
                Artist = "Test Artist",
                FullPath = "Test Path",
                Title = "Test Title"
            };

            var repository = new MemoryLibraryRepository();
            repository.ClearLibrary();

            repository.AddMusicToLibrary(new MusicInfo[] { music });

            List<MusicInfo> result = repository.GetAllMusic();

            Assert.IsNotNull(result, "The result must not be null.");
            Assert.AreEqual(1, result.Count, "There must only be one song.");

            var repository2 = new MemoryLibraryRepository();

            music.FullPath += 2;

            repository2.AddMusicToLibrary(new MusicInfo[] { music });
            result = repository2.GetAllMusic();

            Assert.AreEqual(2, result.Count, "There must two songs.");
        }
예제 #4
0
        public void PlayerCanBeGivenANewPlaylist()
        {
            var library = new MemoryLibraryRepository();
            var playlist = new Playlist();
            var dummyAudio = new DummyAudioInteractor();
            var player = new Player(playlist, dummyAudio, null);

            var song = "song1";

            library.ClearLibrary();
            library.AddMusicToLibrary(new MusicInfo[] { new MusicInfo() { FullPath = song } });

            playlist.AddRange(library.GetAllMusic());

            player.Play();

            Assert.AreEqual(song, playlist.CurrentSong.FullPath, "The last song played must be the only one in the library.");

            var song2 = "song 2";

            library.ClearLibrary();
            library.AddMusicToLibrary(new MusicInfo[] { new MusicInfo() { FullPath = song2 } });

            playlist.AddRange(library.GetAllMusic());

            player.PlayCount = 0;
            player.Play();

            Assert.AreEqual(song, playlist.PreviousSong.FullPath, "The previous played must be new song in the library.");
            Assert.AreEqual(song2, playlist.CurrentSong.FullPath, "The current played must be new song in the library.");
        }
예제 #5
0
        public void Loop()
        {
            var song1 = "song1";
            var song2 = "song2";

            var library = new MemoryLibraryRepository();
            library.ClearLibrary();
            library.AddMusicToLibrary(
                new MusicInfo[] {
                    new MusicInfo() { FullPath = song1 },
                    new MusicInfo() { FullPath = song2 }
                });

            var loopingWatcher = new LoopingPlaylistWatcher();
            var playlist = new Playlist(loopingWatcher);
            var dummyAudio = new DummyAudioInteractor();

            var player = new Player(playlist, dummyAudio, library);

            loopingWatcher.AttachToPlaylist(playlist, library);

            playlist.AddRange(library.GetAllMusic());

            player.MaxPlayCount = 3;
            player.Play();

            Assert.AreEqual(3, dummyAudio.PlayHistory.Count, "There must be three songs in the history.");
            Assert.AreEqual(song1, dummyAudio.PlayHistory[0], "The first song must play first.");
            Assert.AreEqual(song2, dummyAudio.PlayHistory[1], "The second song must play second.");
            Assert.AreEqual(song1, dummyAudio.PlayHistory[2], "The first song must play third.");

            Assert.AreEqual(2, playlist.RemainingSongs, "After playing three songs there must still be 2 songs in the playlist.");
        }
예제 #6
0
        public void AddFolderToLibrary()
        {
            var testDirectory = @"..\..\..\TestFiles";
            var title = "one";

            var repository = new MemoryLibraryRepository();
            repository.ClearLibrary();

            repository.AddDirectoryToLibrary(testDirectory);

            List<MusicInfo> result = repository.GetAllMusic();

            Assert.IsNotNull(result, "The result must not be null.");
            Assert.Greater(result.Count, 0, "There must many songs.");
            Assert.AreEqual(title, result[0].Title, "The title must be correct.");
        }
예제 #7
0
        public void TranscodesOtherFormats()
        {
            var fakeFiles = new string[] { "test.m4a" };
            var fakeMusicInfo = new MusicInfo()
            {
                Album = "Test",
                Artist = "Test2"
            };

            var transcodedFile = "test.mp3";
            var fakeMusicInfoReader = new FakeMusicInfoReader(fakeMusicInfo);
            var importFolderInteractor = new FakeFolderInteractor(fakeFiles);
            var fakeTranscoder = new FakeTranscoder();
            var library = new MemoryLibraryRepository();
            library.ClearLibrary();
            var importFolderWatcher = new ImportFolderWatcher(importFolderInteractor, fakeMusicInfoReader, library, fakeTranscoder);

            importFolderWatcher.ProcessFiles();

            var expectedLibraryPath = @"c:\temp\" + fakeMusicInfo.Artist + "\\" + fakeMusicInfo.Album + "\\" + transcodedFile;

            Assert.AreEqual(1, importFolderInteractor.MovedFiles.Count(), "There must one moved file");
            Assert.AreEqual(transcodedFile, importFolderInteractor.MovedFiles[0].SourceFile, "The file to move must be correct.");
            Assert.AreEqual(expectedLibraryPath, importFolderInteractor.MovedFiles[0].DestinationFile, "The file must be moved to the correct folder.");
            Assert.IsTrue(importFolderInteractor.DeletedFiles.Contains(fakeFiles[0]), "The original file must be deleted.");
            Assert.IsTrue(importFolderInteractor.DeletedFiles.Contains(expectedLibraryPath), "The library path must be deleted.");
            Assert.AreEqual(2, importFolderInteractor.DeletedFiles.Count(), "There must be 2 attempted file deletes.");
        }
예제 #8
0
        public void OneMp3file()
        {
            var fakeFiles = new string[] { "one.mp3" };
            var fakeMusicInfo = new MusicInfo() {
                Album = "onealbum",
                Artist = "oneartist"
            };

            var fakeMusicInfoReader = new FakeMusicInfoReader(fakeMusicInfo);
            var importFolderInteractor = new FakeFolderInteractor(fakeFiles);
            var library = new MemoryLibraryRepository();
            library.ClearLibrary();
            var importFolderWatcher = new ImportFolderWatcher(importFolderInteractor, fakeMusicInfoReader, library, null);

            importFolderWatcher.ProcessFiles();

            var expectedLibraryPath = @"c:\temp\" + fakeMusicInfo.Artist + "\\" + fakeMusicInfo.Album + "\\" + fakeFiles[0];

            Assert.AreEqual(1, importFolderInteractor.MovedFiles.Count(), "There must one moved file");
            Assert.AreEqual(fakeFiles[0], importFolderInteractor.MovedFiles[0].SourceFile, "The file to move must be correct.");
            Assert.AreEqual(expectedLibraryPath, importFolderInteractor.MovedFiles[0].DestinationFile, "The file must be moved to the correct folder.");

            var libraryFiles = library.GetAllMusic();

            Assert.AreEqual(1, libraryFiles.Count(), "There must be one file in the library.");
            Assert.AreEqual(fakeMusicInfo.Artist, libraryFiles[0].Artist, "The artist added to the library must be correct.");
            Assert.AreEqual(expectedLibraryPath, libraryFiles[0].FullPath, "The full path of the file in the library must be correct.");
        }