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

            var controller = new HotelController(context);

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

            Assert.IsNotNull(hotelsData, "There is no data in the hotels list");
            Assert.AreEqual(3, hotelsData.Count(), "The data does not corespond to the expected data count");
        }
        public void Task_Create_Hotel_Return_OkResult()
        {
            //Arrange
            var controller = new HotelController(context);

            //Act
            var data = controller.Create();

            //Assert
            Assert.IsType <ViewResult>(data);
        }
Ejemplo n.º 3
0
        public void Create_ShouldCreateOneHotel()
        {
            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());

            mockSet.Verify(m => m.Add(It.IsAny <Hotel>()), Times.Once, "Could not add a hotel");
            mockContext.Verify(m => m.SaveChanges(), Times.Once, "Could not add the hotel to the database");
        }
Ejemplo n.º 4
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.º 5
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");
        }
Ejemplo n.º 6
0
        public void Update_ShouldUpdateHotel()
        {
            mockContext = new Mock <IHotelAC>();
            mockSet     = new Mock <DbSet <Hotel> >();
            mockContext.Setup(m => m.Hoteli).Returns(mockSet.Object);

            var controller = new HotelController(mockContext.Object);
            var newHotel   = new Hotel
            {
                HotelID  = 1,
                Adresa   = "FF",
                Lokacija = "BB",
                Ime      = "BB"
            };

            controller.Create(newHotel);
            newHotel.Ime = "OO";
            controller.Edit(newHotel);

            Assert.IsTrue("OO" == newHotel.Ime, "The hotel did not update");
        }
Ejemplo n.º 7
0
        public void Create_ShouldReturnInvalidModelState()
        {
            mockContext = new Mock <IHotelAC>();
            mockSet     = new Mock <DbSet <Hotel> >();
            mockContext.Setup(m => m.Hoteli).Returns(mockSet.Object);

            var controller = new HotelController(mockContext.Object);

            controller.ModelState.AddModelError("Name", "Name cannot be null");

            var newHotel = new Hotel
            {
                Ime      = null,
                Adresa   = "AA",
                HotelID  = 1,
                Lokacija = "BB"
            };

            controller.Create(newHotel);

            Assert.IsTrue(controller.ViewData.ModelState.IsValid == false, "Name is required");
        }
        public void Task_Add_Hotel_Return_OkResult()
        {//Arrange
            var controller = new HotelController(context);
            //Act
            var hotel = new Hotel()
            {
                HotelName          = "Lila",
                HotelAddress       = "Delhi",
                HotelDistrict      = "Delhi",
                HotelCity          = "Delhi",
                HotelState         = "Delhi",
                HotelCountry       = "India",
                HotelEmailId       = "*****@*****.**",
                HotelRating        = "1",
                HotelContactNumber = 123654789,
                HotelImage         = "jkewhffj",
                HotelDescription   = "Description",
                HotelTypeId        = 2
            };
            var data = controller.Create(hotel);

            //Assert
            Assert.IsType <RedirectToActionResult>(data);
        }