Exemplo n.º 1
0
        public void Index_ShouldReturnSameCountOfService()
        {
            var context = new TestHotelContext();

            var controller = new UslugaController(context);

            controller.Create(new Usluga());
            controller.Create(new Usluga());
            controller.Create(new Usluga());
            var result  = controller.Index() as ViewResult;
            var service = (IList <Usluga>)result.ViewData.Model;

            Assert.IsNotNull(service, "There's no service data");
            Assert.AreEqual(3, service.Count, "The count does not match");
        }
Exemplo n.º 2
0
        public void Create_ShouldRedirect()
        {
            mockContext = new Mock <IHotelAC>();
            mockSet     = new Mock <DbSet <Usluga> >();
            mockContext.Setup(m => m.Usluge).Returns(mockSet.Object);

            var controller = new UslugaController(mockContext.Object);
            RedirectToRouteResult result = (RedirectToRouteResult)controller.Create(new Usluga());

            Assert.AreEqual("Index", result.RouteValues["action"], "The index route does not match the controllers route");
            Assert.IsNull(result.RouteValues["UslugaController"], "The room type controller is not null");
        }
Exemplo n.º 3
0
        public void Create_ShouldCreateService()
        {
            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());

            mockSet.Verify(m => m.Add(It.IsAny <Usluga>()), Times.Once, "Could not add the service to the database");
            mockContext.Verify(m => m.SaveChanges(), Times.Once, "Could not save the changes to the database");
        }
Exemplo n.º 4
0
        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");
        }
Exemplo n.º 5
0
        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");
        }
Exemplo n.º 6
0
        public void Update_ShouldUpdateService()
        {
            mockContext = new Mock <IHotelAC>();
            mockSet     = new Mock <DbSet <Usluga> >();
            mockContext.Setup(m => m.Usluge).Returns(mockSet.Object);

            var controller = new UslugaController(mockContext.Object);
            var service    = new Usluga
            {
                ImeUsluge    = "test",
                UslugaID     = 1,
                CijenaUsluge = 10
            };

            controller.Create(service);
            service.CijenaUsluge = 20;
            controller.Edit(service);

            Assert.IsTrue(20 == service.CijenaUsluge, "The service did not update");
        }
Exemplo n.º 7
0
        public void Create_ShouldReturnInvalidModelState()
        {
            mockContext = new Mock <IHotelAC>();
            mockSet     = new Mock <DbSet <Usluga> >();
            mockContext.Setup(m => m.Usluge).Returns(mockSet.Object);

            var controller = new UslugaController(mockContext.Object);

            controller.ModelState.AddModelError("CijenaUsluge", "Service price needs to have a value");

            var service = new Usluga
            {
                ImeUsluge    = "test",
                UslugaID     = 1,
                CijenaUsluge = 0
            };

            controller.Create(service);

            Assert.IsTrue(controller.ViewData.ModelState.IsValid == false, "Service price cannot be zero");
        }