Beispiel #1
0
        public void IndexTest()
        {
            var context       = new Mock <System.Web.Mvc.ControllerContext>();
            var mockPrincipal = new Mock <IPrincipal>();
            var mockIdentity  = new Mock <IIdentity>();

            mockPrincipal.Setup(p => p.Identity).Returns(mockIdentity.Object);
            mockIdentity.Setup(ob => ob.Name).Returns("name");

            context.SetupGet(x => x.HttpContext.User).Returns(mockPrincipal.Object);
            context.SetupGet(x => x.HttpContext.User.Identity).Returns(mockIdentity.Object);

            _roomsController.ControllerContext = context.Object;
            var rooms = _mockRoomRepo.Setup(x => x.GetAll()).Returns(new List <Room>());
            var user  = _mockUserRepo.Setup(x => x.Find("1")).Returns(new ApplicationUser());

            RoomsViewModel roomvm = new RoomsViewModel()
            {
                Rooms = new List <Room>(),
                User  = new ApplicationUser()
            };

            var result = _roomsController.Index() as ViewResult;

            Assert.AreEqual("Index", result.ViewName);
        }
Beispiel #2
0
        public void Index_ReturnsViewResultWithCorrectListOfRooms()
        {
            // Act
            var result    = controller.Index() as ViewResult;
            var roomsList = result.Model as IList <Room>;
            var noOfRooms = roomsList.Count;

            // Assert
            Assert.Equal(2, noOfRooms);
        }
Beispiel #3
0
        public void Index()
        {
            // Arrange
            RoomsController controller = new RoomsController();

            // Act
            ViewResult result = controller.Index() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
Beispiel #4
0
        public void TestIndexViewModel()
        {
            List <Room> rooms = new List <Room>();

            rooms.Add(new Room()
            {
                Id           = 1,
                Description  = "Lorem lorem",
                Name         = "Test Chamber",
                OpenFrom     = 4,
                OpenTo       = 16,
                Reservations = null
            });

            rooms.Add(new Room()
            {
                Id           = 2,
                Description  = "Lorem lorem",
                Name         = "UCL Room 1.1",
                OpenFrom     = 0,
                OpenTo       = 24,
                Reservations = null
            });

            rooms.Add(new Room()
            {
                Id           = 3,
                Description  = "Lorem lorem",
                Name         = "2 hour room",
                OpenFrom     = 10,
                OpenTo       = 12,
                Reservations = null
            });

            var mock = new Mock <IRoomRepository>();

            mock.Setup(repo => repo.GetAll()).Returns(rooms);

            RoomsController roomsController = new RoomsController(mock.Object);
              
            IActionResult result = roomsController.Index();

            Assert.IsInstanceOfType(result, typeof(ViewResult));
            ViewResult viewResult = (ViewResult)result;

            Assert.IsInstanceOfType(viewResult.ViewData.Model, typeof(IndexViewModel));
            IndexViewModel viewModel = (IndexViewModel)viewResult.ViewData.Model;

            Assert.AreEqual(3, viewModel.Rooms.Count());
        }
        public void Index_ReturnsListOfRooms()
        {
            var mockDal = new Mock <IRoomDAL>();

            mockDal.Setup(m => m.GetOpenRooms()).Returns(new List <RoomModel>());
            var controller = new RoomsController(mockDal.Object, null);

            var result = controller.Index();

            Assert.IsNotNull(result);
            Assert.IsTrue(result is ViewResult);
            Assert.AreEqual("Index", (result as ViewResult).ViewName);
            Assert.IsNotNull((result as ViewResult).Model);
        }
        public void Index_ReturnsView()
        {
            ViewResult result = _controller.Index() as ViewResult;

            Assert.AreEqual("Index", result.ViewName);
        }