public async Task DeleteAndSaveTest() { var coach1 = new Coach() { Id = 1, Name = "test coach 1", Email = "*****@*****.**" }; var coach2 = new Coach() { Id = 2, Name = "test coach 2", Email = "*****@*****.**" }; var coaches = new List <Coach> { coach1, coach2 }; var fakeRepositoryMock = new Mock <ICoachRepository>(); fakeRepositoryMock.Setup(x => x.Delete(It.IsAny <long>())).Callback <long>(arg => coaches.RemoveAt(1)); var coachService = new CoachService(fakeRepositoryMock.Object); await coachService.DeleteAndSave(coach2.Id); Assert.Single(coaches); Assert.Equal("*****@*****.**", coaches[0].Email); }
public async Task <IActionResult> DeleteConfirmed(long id) { await _coachService.DeleteAndSave(id); return(RedirectToAction(nameof(Index))); }