public void Delete_Post_RemovesRecordFromDb() { // Arrange _context.Lunches.Add(new Lunch { Host = "Brent", Restaurants = new List <Restaurant> { new Restaurant { Name = "Lunchbox Labs", Latitude = 55, Longitude = 99 } }, MeetingTime = new DateTime(1999, 12, 31) }); _context.SaveChanges(); var controller = new LunchesController(_context); var recordId = _context.Lunches.First().Id; var recordDeleteGetResult = controller.Delete(recordId) as ViewResult; var recordToDelete = recordDeleteGetResult.Model as Lunch; // Act var result = controller.DeleteConfirmed(recordToDelete.Id) as RedirectToRouteResult; // Assert _context.Lunches.Count().ShouldBe(0); result.RouteValues["action"].ShouldBe("Index"); }
public void Delete_Get_ReturnsViewWithRecord() { // Arrange _context.Lunches.Add(new Lunch { Host = "Brent", Restaurants = new List <Restaurant> { new Restaurant { Name = "Lunchbox Labs", Latitude = 55, Longitude = 99 } }, MeetingTime = new DateTime(1999, 12, 31) }); _context.SaveChanges(); var controller = new LunchesController(_context); // Act var Id = _context.Lunches.First().Id; var result = controller.Delete(Id) as ViewResult; // Assert result.Model.ShouldNotBeNull(); result.Model.ShouldBeOfType <Lunch>(); }
public void Delete_ThrowsWhenRecordCannotBeFound() { // Arrange var controller = new LunchesController(_context); // Act var result = controller.Delete(999) as HttpStatusCodeResult; // Assert result.ShouldBeOfType <HttpNotFoundResult>(); result.StatusCode.ShouldBe(404); }
public void Delete_ThrowsWhenIdIsNull() { // Arrange var controller = new LunchesController(_context); // Act var result = controller.Delete(null) as HttpStatusCodeResult; // Assert result.ShouldBeOfType <HttpStatusCodeResult>(); result.StatusCode.ShouldBe(400); }