public void Can_Delete_Valid_Events() { // Arrange - create an event Event @event = new Event { Id = 2, Name = "Test2" }; mockRepo.Setup(m => m.GetAllEvents()).Returns(new List <Event> { new Event { Id = 1, Name = "Test1" }, @event, new Event { Id = 3, Name = "Test3" }, }); var deletemodel = new DeleteEventModel(mockRepo.Object); deletemodel.Event = @event; // Act - var result = deletemodel.OnPost(); // Assert - ensure that the repository delete method was invoked var redirectToActionResult = Assert.IsType <RedirectToPageResult>(result); Assert.Equal("Index", redirectToActionResult.PageName); mockRepo.Verify(m => m.DeleteEvent(@event), Times.Once); Assert.NotNull(result); }
public DeleteEventUnitTest() { mockRepo = new Mock <IEventRepository>(); deletemodel = new DeleteEventModel(mockRepo.Object); }