public void Delete_Removes_Song() { // arrange var songId = 1; var deletedSong = new Song(1, "First Song", "3:12", "song.com", 1); var songList = new List <Song>() { deletedSong, new Song(2, "Second Song", "3:12", "song.com", 1) }; // our controller's Delete() action is dependent on the Repository's // GetById(), Delete(), and GetAll() actions- they all need to be mocked songRepo.GetById(songId).Returns(deletedSong); songRepo.When(d => d.Delete(deletedSong)) .Do(d => songList.Remove(deletedSong)); songRepo.GetAll().Returns(songList); // act var result = underTest.DeleteSong(songId); // assert // Below is an alternative to Assert.DoesNotContain(deletedTodo, result), // which does not work in all cases Assert.All(result, item => Assert.Contains("Second Song", item.Title)); }
/// <summary> /// delete option for API /// </summary> /// <param name="table">the table(API)</param> private static void delAPICall(string table) { if (table.Equals("songs")) { Console.WriteLine(""); Console.WriteLine("Input Id of song to delete:"); string choice = Console.ReadLine(); SongsController cont = new SongsController(); string result = cont.DeleteSong(choice); Console.WriteLine(result); } else if (table.Equals("reviews")) { Console.WriteLine(""); Console.WriteLine("Input Id of review to delete:"); string choice = Console.ReadLine(); ReviewsController cont = new ReviewsController(); string result = cont.DeleteReview(choice); Console.WriteLine(result); } }
public async Task CanDeleteSong() { var result = await _controller.DeleteSong(2); result.Should().BeOfType <OkObjectResult>(); }