Ejemplo n.º 1
0
        public void Delete_ShouldReturnNotFound()
        {
            mockContext = new Mock <IHotelAC>();
            mockSet     = new Mock <DbSet <Hotel> >();
            mockContext.Setup(m => m.Hoteli).Returns(mockSet.Object);

            var controller = new HotelController(mockContext.Object);

            controller.Create(new Hotel {
                HotelID = 1
            });
            controller.Delete(2);
            controller.DeleteConfirmed(2);
            ActionResult result = controller.Delete(2);

            Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult), "Hotel does not exist");
        }
Ejemplo n.º 2
0
        public void Delete_ShouldDeleteHotel()
        {
            mockContext = new Mock <IHotelAC>();
            mockSet     = new Mock <DbSet <Hotel> >();
            mockContext.Setup(m => m.Hoteli).Returns(mockSet.Object);

            var controller = new HotelController(mockContext.Object);

            controller.Create(new Hotel {
                HotelID = 1
            });
            controller.Delete(1);
            controller.DeleteConfirmed(1);

            mockSet.Verify(m => m.Remove(It.IsAny <Hotel>()), Times.Once, "There are no hotels");
            mockContext.Verify(m => m.SaveChanges(), Times.Exactly(2), "Could not remove the hotel from the database");
        }