Exemplo n.º 1
0
        public void Delete_ShouldDeleteGuest()
        {
            mockContext = new Mock <IHotelAC>();
            mockSet     = new Mock <DbSet <Gost> >();
            mockContext.Setup(m => m.Gosti).Returns(mockSet.Object);
            mockSet.Setup(m => m.Remove(It.IsAny <Gost>()));
            var controller = new GostController(mockContext.Object);

            controller.Create(new Gost {
                GostID = 1
            });
            controller.Delete(1);
            controller.DeleteConfirmed(1);

            mockSet.Verify(m => m.Remove(It.IsAny <Gost>()), Times.Once, "Could not remove the guest");
            mockContext.Verify(m => m.SaveChanges(), Times.Exactly(2), "Could not save the changes to the database");
        }
Exemplo n.º 2
0
        public void Delete_ShouldReturnNotFound()
        {
            mockContext = new Mock <IHotelAC>();
            mockSet     = new Mock <DbSet <Gost> >();
            mockContext.Setup(m => m.Gosti).Returns(mockSet.Object);

            var controller = new GostController(mockContext.Object);

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

            Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult), "Guest does not exist");
        }