Exemple #1
0
        public void Index_ShouldReturnSameCountOfGuests()
        {
            var context = new TestHotelContext();

            var controller = new RacunController(context);

            controller.Create(new Racun(), new Rezervacija(), ID);
            controller.Create(new Racun(), new Rezervacija(), ID);
            controller.Create(new Racun(), new Rezervacija(), ID);
            var result      = controller.Index() as ViewResult;
            var receiptData = (IList <Racun>)result.ViewData.Model;

            Assert.IsNotNull(receiptData, "There's no receipt data");
            Assert.AreEqual(3, receiptData.Count, "The count does not match");
        }
Exemple #2
0
        public void Create_ShouldCreateReceipt()
        {
            mockContext = new Mock <IHotelAC>();
            mockSet     = new Mock <DbSet <Racun> >();
            mockContext.Setup(m => m.Racuni).Returns(mockSet.Object);

            var controller = new RacunController(mockContext.Object);

            controller.Create(new Racun(), new Rezervacija(), ID);

            mockSet.Verify(m => m.Add(It.IsAny <Racun>()), Times.Once, "Could not add the guest to the database");
            mockContext.Verify(m => m.SaveChanges(), Times.Once, "Could not save the changes to the database");
        }
Exemple #3
0
        public void Create_ShouldRedirect()
        {
            mockContext = new Mock <IHotelAC>();
            mockSet     = new Mock <DbSet <Racun> >();
            mockContext.Setup(m => m.Racuni).Returns(mockSet.Object);

            var controller = new RacunController(mockContext.Object);
            RedirectToRouteResult result =
                (RedirectToRouteResult)controller.Create(new Racun(), new Rezervacija(), ID);

            Assert.AreEqual("Index", result.RouteValues["action"],
                            "The index route does not match the controllers route");
            Assert.IsNull(result.RouteValues["RacunController"], "The receipts controller is not null");
        }
Exemple #4
0
        public void Delete_ShouldDeleteReceipt()
        {
            mockContext = new Mock <IHotelAC>();
            mockSet     = new Mock <DbSet <Racun> >();
            mockContext.Setup(m => m.Racuni).Returns(mockSet.Object);
            mockSet.Setup(m => m.Remove(It.IsAny <Racun>()));
            var controller = new RacunController(mockContext.Object);

            controller.Create(new Racun {
                RacunID = 1
            }, new Rezervacija(), ID);
            controller.Delete(1);
            controller.DeleteConfirmed(1);

            mockSet.Verify(m => m.Remove(It.IsAny <Racun>()), Times.Once, "Could not remove the receipt");
            mockContext.Verify(m => m.SaveChanges(), Times.Exactly(2), "Could not save the changes to the database");
        }
Exemple #5
0
        public void Delete_ShouldReturnNotFound()
        {
            mockContext = new Mock <IHotelAC>();
            mockSet     = new Mock <DbSet <Racun> >();
            mockContext.Setup(m => m.Racuni).Returns(mockSet.Object);

            var controller = new RacunController(mockContext.Object);

            controller.Create(new Racun()
            {
                RacunID = 1
            }, new Rezervacija(), ID);
            controller.Delete(2);
            controller.DeleteConfirmed(2);
            ActionResult result = controller.Delete(2);

            Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult), "Guest does not exist");
        }
Exemple #6
0
        public void Update_ShouldUpdateReceipt()
        {
            mockContext = new Mock <IHotelAC>();
            mockSet     = new Mock <DbSet <Racun> >();
            mockContext.Setup(m => m.Racuni).Returns(mockSet.Object);

            var controller = new RacunController(mockContext.Object);
            var newReceipt = new Racun()
            {
                RacunID       = 1,
                IznosUkupno   = 0,
                Placeno       = false,
                RezervacijaID = -1,
            };

            controller.Create(newReceipt, new Rezervacija(), ID);
            newReceipt.Placeno = true;
            controller.Edit(newReceipt);

            Assert.IsTrue(true == newReceipt.Placeno, "The receipt did not update");
        }
Exemple #7
0
        public void Create_ShouldReturnInvalidModelState()
        {
            mockContext = new Mock <IHotelAC>();
            mockSet     = new Mock <DbSet <Racun> >();
            mockContext.Setup(m => m.Racuni).Returns(mockSet.Object);

            var controller = new RacunController(mockContext.Object);

            controller.ModelState.AddModelError("RezervacijaID", "Reservation id must contain a valid value");

            var newReceipt = new Racun()
            {
                RacunID       = 1,
                IznosUkupno   = 0,
                Placeno       = false,
                RezervacijaID = -1,
            };

            controller.Create(newReceipt, new Rezervacija(), ID);

            Assert.IsNotNull(newReceipt, "There is no data in the receipts");
            Assert.IsTrue(controller.ViewData.ModelState.IsValid == false, "Reservation id is required");
        }