public async Task DeleteAndSaveTest() { var author1 = new Authors() { Author_id = "1", Author_name = "test author 1" }; var author2 = new Authors() { Author_id = "2", Author_name = "test author 2" }; var authors = new List <Authors> { author1, author2 }; var fakeRepositoryMock = new Mock <IAuthorsRepository>(); fakeRepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Callback <int>(arg => authors.RemoveAt(1)); var coachService = new AuthorsService(fakeRepositoryMock.Object); await coachService.DeleteAndSave(author2.Author_id); Assert.Single(authors); Assert.Equal("test author 1", authors[0].Author_name); }
public async Task <IActionResult> DeleteConfirmed(string id) { await _context.DeleteAndSave(id); return(RedirectToAction(nameof(Index))); }