public void PlayAndRemoveSelectedTest() { // Add music files to playlist Assert.IsFalse(playlistManager.Items.Any()); viewModel.InsertMusicFilesAction(0, musicFiles); Assert.AreEqual(2, playlistManager.Items.Count); // Select the first playlist item Assert.IsFalse(viewModel.PlaySelectedCommand.CanExecute(null)); Assert.IsFalse(viewModel.RemoveSelectedCommand.CanExecute(null)); AssertHelper.CanExecuteChangedEvent(viewModel.PlaySelectedCommand, () => SetSelection(viewModel, playlistManager.Items.First())); Assert.IsTrue(viewModel.PlaySelectedCommand.CanExecute(null)); Assert.IsTrue(viewModel.RemoveSelectedCommand.CanExecute(null)); // Play the selected item var playerService = Container.GetExportedValue <PlayerService>(); playerService.IsPlayCommand = true; bool playPauseCalled = false; playerService.PlayPauseCommand = new DelegateCommand(() => playPauseCalled = true); Assert.IsNull(playlistManager.CurrentItem); viewModel.PlaySelectedCommand.Execute(null); Assert.IsTrue(playPauseCalled); Assert.AreEqual(playlistManager.Items.First(), playlistManager.CurrentItem); // Remove the selected item var selectedItem = viewModel.SelectedPlaylistItem; viewModel.RemoveSelectedCommand.Execute(null); Assert.AreNotEqual(selectedItem, playlistManager.Items.Single()); Assert.AreEqual(playlistManager.Items.Single(), viewModel.SelectedPlaylistItem); // -- simulate the WPF behavior of updating the SelectedPlaylistItems as well SetSelection(viewModel, viewModel.SelectedPlaylistItem); // Play the next selected item viewModel.PlaySelectedCommand.Execute(null); // Remove the last item as well AssertHelper.CanExecuteChangedEvent(viewModel.RemoveSelectedCommand, () => viewModel.RemoveSelectedCommand.Execute(null)); Assert.IsFalse(viewModel.RemoveSelectedCommand.CanExecute(null)); Assert.IsFalse(playlistManager.Items.Any()); Assert.IsNull(viewModel.SelectedPlaylistItem); }