public void Delete_ShouldReturnNotFound() { mockContext = new Mock <IHotelAC>(); mockSet = new Mock <DbSet <Usluga> >(); mockContext.Setup(m => m.Usluge).Returns(mockSet.Object); var controller = new UslugaController(mockContext.Object); controller.Create(new Usluga { UslugaID = 1 }); controller.Delete(2); controller.DeleteConfirmed(2); ActionResult result = controller.Delete(2); Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult), "Service does not exist"); }
public void Delete_ShouldDeleteService() { mockContext = new Mock <IHotelAC>(); mockSet = new Mock <DbSet <Usluga> >(); mockContext.Setup(m => m.Usluge).Returns(mockSet.Object); mockSet.Setup(m => m.Remove(It.IsAny <Usluga>())); var controller = new UslugaController(mockContext.Object); controller.Create(new Usluga() { UslugaID = 1 }); controller.Delete(1); controller.DeleteConfirmed(1); mockSet.Verify(m => m.Remove(It.IsAny <Usluga>()), Times.Once, "Could not remove the service"); mockContext.Verify(m => m.SaveChanges(), Times.Exactly(2), "Could not save the changes to the database"); }