public ActionResult DeleteSport(int id) { var service = new SportService(); if (service.DeleteSport(id)) { return(RedirectToAction("Index")); } TempData["SaveResult"] = "The sporting event was deleted."; return(RedirectToAction("Delete", new { id })); }
public void InvokeSaveChangesMethod_WhenSportscardWithCompanyNameThatExists() { //Arrange var dbContextMock = new Mock <ISportscardSystemDbContext>(); var mapperMock = new Mock <IMapper>(); var expectedCompany = new Sport() { Name = "Gym", IsDeleted = true }; var data = new List <Sport> { new Sport { Name = "Gym", IsDeleted = false, } }; var mockSet = new Mock <DbSet <Sport> >(); mockSet.SetupData(data); dbContextMock .Setup(x => x.Sports) .Returns(mockSet.Object); var sportService = new SportService(dbContextMock.Object, mapperMock.Object); //Act sportService.DeleteSport(expectedCompany.Name); //Assert dbContextMock.Verify(x => x.SaveChanges(), Times.Once); Assert.AreEqual(expectedCompany.IsDeleted, true); }