public void AutoFillFromFileNameTest() { var viewModel = Container.GetExportedValue <MusicPropertiesViewModel>(); Assert.IsFalse(viewModel.AutoFillFromFileNameCommand.CanExecute(null)); var musicFile = MockMusicFile.CreateEmpty(@"C:\Users\Public\Music\Dancefloor\Culture Beat - Serenity.mp3"); viewModel.MusicFile = musicFile; Assert.IsTrue(viewModel.AutoFillFromFileNameCommand.CanExecute(null)); viewModel.AutoFillFromFileNameCommand.Execute(null); Assert.AreEqual("Culture Beat", musicFile.Metadata.Artists.First()); Assert.AreEqual("Serenity", musicFile.Metadata.Title); Assert.IsFalse(viewModel.AutoFillFromFileNameCommand.CanExecute(null)); musicFile = MockMusicFile.CreateEmpty(@"\\server\share\Culture Beat Serenity.wma"); viewModel.MusicFile = musicFile; viewModel.AutoFillFromFileNameCommand.Execute(null); Assert.IsFalse(musicFile.Metadata.Artists.Any()); Assert.AreEqual("Culture Beat Serenity", musicFile.Metadata.Title); musicFile = MockMusicFile.CreateEmpty(@"C:\Culture Beat - Serenity - Epilog.wma"); viewModel.MusicFile = musicFile; viewModel.AutoFillFromFileNameCommand.Execute(null); Assert.AreEqual("Culture Beat", musicFile.Metadata.Artists.First()); Assert.AreEqual("Serenity - Epilog", musicFile.Metadata.Title); // CanExecute returns false when metadata are not supported. musicFile = new MockMusicFile(MusicMetadata.CreateUnsupported(TimeSpan.FromSeconds(55), 1411000), @"C:\Test.wav"); viewModel.MusicFile = musicFile; Assert.IsFalse(viewModel.AutoFillFromFileNameCommand.CanExecute(null)); }
public void LaodAndSaveSettings() { var environmentService = Container.GetExportedValue <MockEnvironmentService>(); environmentService.AppSettingsPath = Environment.CurrentDirectory; controller.Initialize(); controller.Run(); var playerController = Container.GetExportedValue <PlayerController>(); shellService.Settings.Height = 42; playerController.PlaylistManager.CurrentItem = new PlaylistItem(MockMusicFile.CreateEmpty("Test")); controller.Shutdown(); shellService.Settings.Height = 0; playerController.PlaylistSettings.LastPlayedFileName = null; controller.Initialize(); controller.Run(); Assert.AreEqual(42, shellService.Settings.Height); Assert.AreEqual("Test", playerController.PlaylistSettings.LastPlayedFileName); File.Delete(Path.Combine(environmentService.AppSettingsPath, "Settings.xml")); File.Delete(Path.Combine(environmentService.AppSettingsPath, "Playlist.xml")); }
public void PlayAllAndSelected() { controller.Run(); Assert.IsTrue(viewModel.PlayerService.PlayAllCommand.CanExecute(null)); Assert.IsFalse(viewModel.PlayerService.PlaySelectedCommand.CanExecute(null)); // Select first music file AssertHelper.CanExecuteChangedEvent(viewModel.PlayerService.PlaySelectedCommand, () => selectionService.SelectedMusicFiles.Add(selectionService.MusicFiles[0])); Assert.IsTrue(viewModel.PlayerService.PlaySelectedCommand.CanExecute(null)); // Insert a dummy playlist item which will be replaced by Play playlistManager.AddAndReplaceItems(new[] { new PlaylistItem(MockMusicFile.CreateEmpty("empty.mp3")) }); Assert.AreEqual(1, playlistManager.Items.Count); // Play all var playerService = Container.GetExportedValue <PlayerService>(); playerService.IsPlayCommand = true; bool playPauseCommandCalled = false; playerService.PlayPauseCommand = new DelegateCommand(() => playPauseCommandCalled = true); bool showPlaylistViewCalled = false; shellService.ShowPlaylistViewAction = () => showPlaylistViewCalled = true; viewModel.PlayerService.PlayAllCommand.Execute(null); Assert.IsTrue(playPauseCommandCalled); Assert.IsTrue(showPlaylistViewCalled); AssertHelper.SequenceEqual(musicFiles, playlistManager.Items.Select(x => x.MusicFile)); Assert.AreEqual(musicFiles.First(), playlistManager.CurrentItem.MusicFile); }
public MusicFile Create(string fileName) { if (!musicFilesCache.TryGetValue(fileName, out MusicFile musicFile)) { musicFile = MockMusicFile.CreateEmpty(fileName); musicFilesCache.Add(fileName, musicFile); } return(musicFile); }
public void SearchTextTest() { var viewModel = Container.GetExportedValue <PlaylistViewModel>(); var view = Container.GetExportedValue <MockPlaylistView>(); PlaylistItem scrollIntoViewItem = null; view.ScrollIntoViewStub = x => scrollIntoViewItem = x; bool focusSearchBoxCalled = false; view.FocusSearchBoxStub = () => focusSearchBoxCalled = true; var musicFiles = new[] { MockMusicFile.CreateEmpty(@"C:\Users\Public\Music\Dancefloor\Culture Beat - Serenity.wav"), MockMusicFile.CreateEmpty(@"C:\Future Breeze - Why don't you dance with me.mp3"), MockMusicFile.CreateEmpty(@"C:\Culture Beat - Serenity - Epilog.wma"), }; var playlistManager = new PlaylistManager(); playlistManager.AddAndReplaceItems(musicFiles.Select(x => new PlaylistItem(x))); viewModel.PlaylistManager = playlistManager; viewModel.SearchText = "Bill"; Assert.IsNull(viewModel.SelectedPlaylistItem); Assert.IsNull(scrollIntoViewItem); Assert.IsTrue(focusSearchBoxCalled); viewModel.SearchText = "Cul"; Assert.AreEqual(playlistManager.Items[0], viewModel.SelectedPlaylistItem); Assert.AreEqual(playlistManager.Items[0], scrollIntoViewItem); // Selection stays on the same item viewModel.SearchText = "Cultur"; Assert.AreEqual(playlistManager.Items[0], viewModel.SelectedPlaylistItem); Assert.AreEqual(playlistManager.Items[0], scrollIntoViewItem); viewModel.SearchText = "Epi"; Assert.AreEqual(playlistManager.Items[2], viewModel.SelectedPlaylistItem); Assert.AreEqual(playlistManager.Items[2], scrollIntoViewItem); // Selection stays on the same item scrollIntoViewItem = null; viewModel.SearchText = ""; Assert.AreEqual(playlistManager.Items[2], viewModel.SelectedPlaylistItem); Assert.IsNull(scrollIntoViewItem); viewModel.SelectedPlaylistItem = playlistManager.Items[1]; // Search starts from selection viewModel.SearchText = "Cul"; Assert.AreEqual(playlistManager.Items[2], viewModel.SelectedPlaylistItem); Assert.AreEqual(playlistManager.Items[2], scrollIntoViewItem); }
public void CopyFileNameToClipboardTest() { var clipboardService = Container.GetExportedValue <MockClipboardService>(); var viewModel = Container.GetExportedValue <MusicPropertiesViewModel>(); string clipboardText = null; clipboardService.SetTextAction = txt => clipboardText = txt; viewModel.CopyFileNameCommand.Execute(null); Assert.IsNull(clipboardText); var musicFile = MockMusicFile.CreateEmpty(@"C:\Users\Public\Music\Dancefloor\Culture Beat - Serenity.mp3"); viewModel.MusicFile = musicFile; viewModel.CopyFileNameCommand.Execute(null); Assert.AreEqual("Culture Beat - Serenity", clipboardText); }
public void UpdateAutoFillFromFileNameTestCommand() { var viewModel = Container.GetExportedValue <MusicPropertiesViewModel>(); Assert.IsFalse(viewModel.AutoFillFromFileNameCommand.CanExecute(null)); var musicFile = MockMusicFile.CreateEmpty(@"C:\Users\Public\Music\Dancefloor\Culture Beat - Serenity.mp3"); viewModel.MusicFile = musicFile; Assert.IsTrue(viewModel.AutoFillFromFileNameCommand.CanExecute(null)); AssertHelper.CanExecuteChangedEvent(viewModel.AutoFillFromFileNameCommand, () => musicFile.Metadata.Title = "Serenity"); Assert.IsFalse(viewModel.AutoFillFromFileNameCommand.CanExecute(null)); AssertHelper.CanExecuteChangedEvent(viewModel.AutoFillFromFileNameCommand, () => musicFile.Metadata.Title = ""); Assert.IsTrue(viewModel.AutoFillFromFileNameCommand.CanExecute(null)); AssertHelper.CanExecuteChangedEvent(viewModel.AutoFillFromFileNameCommand, () => musicFile.Metadata.Artists = new[] { "Culture Beat" }); Assert.IsFalse(viewModel.AutoFillFromFileNameCommand.CanExecute(null)); }
public void LaodAndSaveSettings() { var appSettings = new AppSettings(); var playlistSettings = new PlaylistSettings(); var settingsService = Container.GetExportedValue <MockSettingsService>(); settingsService.GetStub = type => { if (type == typeof(AppSettings)) { return(appSettings); } if (type == typeof(PlaylistSettings)) { return(playlistSettings); } return(null); }; controller.Initialize(); controller.Run(); var playerController = Container.GetExportedValue <PlayerController>(); shellService.Settings.Height = 42; playerController.PlaylistManager.CurrentItem = new PlaylistItem(MockMusicFile.CreateEmpty("Test")); controller.Shutdown(); shellService.Settings = null; playerController.PlaylistSettings = null; controller.Initialize(); controller.Run(); Assert.AreEqual(42, shellService.Settings.Height); Assert.AreEqual("Test", playerController.PlaylistSettings.LastPlayedFileName); }
public void SearchNextAndPrevious() { var viewModel = Container.GetExportedValue <PlaylistViewModel>(); var view = Container.GetExportedValue <MockPlaylistView>(); var musicFiles = new[] { MockMusicFile.CreateEmpty(@"C:\Culture Beat"), MockMusicFile.CreateEmpty(@"C:\Culture Beat"), MockMusicFile.CreateEmpty(@"C:\Culture Beat"), MockMusicFile.CreateEmpty(@"C:\Foo"), }; var playlistManager = new PlaylistManager(); playlistManager.AddAndReplaceItems(musicFiles.Select(x => new PlaylistItem(x))); viewModel.PlaylistManager = playlistManager; viewModel.SearchText = "Culture"; Assert.AreEqual(playlistManager.Items[0], viewModel.SelectedPlaylistItem); viewModel.SearchNextCommand.Execute(null); Assert.AreEqual(playlistManager.Items[1], viewModel.SelectedPlaylistItem); viewModel.SearchNextCommand.Execute(null); Assert.AreEqual(playlistManager.Items[2], viewModel.SelectedPlaylistItem); viewModel.SearchNextCommand.Execute(null); Assert.AreEqual(playlistManager.Items[0], viewModel.SelectedPlaylistItem); viewModel.SearchPreviousCommand.Execute(null); Assert.AreEqual(playlistManager.Items[2], viewModel.SelectedPlaylistItem); viewModel.SearchPreviousCommand.Execute(null); Assert.AreEqual(playlistManager.Items[1], viewModel.SelectedPlaylistItem); viewModel.SearchPreviousCommand.Execute(null); Assert.AreEqual(playlistManager.Items[0], viewModel.SelectedPlaylistItem); }