public void Edit_WhenCalledWithIntParameter_ShouldNotReturnNull()
        {
            // Arrange
            RoomController controller = new RoomController(_userManager, _roomRepository, _timeTaskRepository,
                                                           _authorizationService, _mapper);

            // Act
            ViewResult viewResult = controller.Edit(1).GetAwaiter().GetResult() as ViewResult;

            // Assert
            Assert.NotNull(viewResult);
        }
Esempio n. 2
0
        public void RoomEditGet_InvalidIdProvided_ReturnsNullViewResultModel()
        {
            // Arrange
            var mockUoW             = new Mock <IUnitOfWork>();
            var mockRoomRepository  = new Mock <IRepository <Room> >();
            var mockPlaceRepository = new Mock <IRepository <Place> >();
            var id = -1;

            mockUoW.Setup(x => x.RoomRepository).Returns(mockRoomRepository.Object);
            mockUoW.Setup(x => x.PlaceRepository).Returns(mockPlaceRepository.Object);

            var controller = new RoomController(mockUoW.Object);

            // Act
            var result = controller.Edit(id) as ViewResult;

            // Assert
            Assert.IsNull(result.Model);
        }
Esempio n. 3
0
        public void RoomEditPost_ValidRoomIdProvided_ReturnsErrorViewResult()
        {
            // Arrange
            var mockUoW            = new Mock <IUnitOfWork>();
            var mockRoomRepository = new Mock <IRepository <Room> >();
            var httpRequest        = new Mock <HttpRequest>();
            var httpContext        = new Mock <HttpContext>();
            var connection         = new Mock <ConnectionInfo>();
            var ipAddress          = IPAddress.Parse("127.0.0.1");
            var roomId             = 1;

            httpContext.Setup(x => x.Request).Returns(httpRequest.Object);
            httpContext.Setup(x => x.Request.HttpContext).Returns(httpContext.Object);
            httpContext.Setup(x => x.Request.HttpContext.Connection).Returns(connection.Object);
            httpContext.Setup(x => x.Request.HttpContext.Connection.RemoteIpAddress).Returns(ipAddress);

            var room = CreateRoomWithoutPlaceAndReservations();

            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext.Object,
            };

            var controller = new RoomController(mockUoW.Object)
            {
                ControllerContext = controllerContext
            };

            var fields         = new Dictionary <string, StringValues>();
            var formCollection = new FormCollection(fields);

            mockUoW.Setup(x => x.RoomRepository.Get(It.IsAny <long>())).Returns(room);
            mockUoW.Setup(x => x.RoomRepository.Update(It.IsAny <Room>()));

            // Act
            var result = controller.Edit(roomId, formCollection) as RedirectToActionResult;

            // Assert
            Assert.AreEqual("Index", result.ActionName);
        }
Esempio n. 4
0
        public void RoomEditGet_ValidRoomIdProvided_ReturnsViewResultModel()
        {
            // Arrange
            var mockUoW             = new Mock <IUnitOfWork>();
            var mockRoomRepository  = new Mock <IRepository <Room> >();
            var mockPlaceRepository = new Mock <IRepository <Place> >();
            var id       = 1;
            var room     = CreateRoomWithoutPlaceAndReservations();
            var roomList = new List <Room>()
            {
                room
            };

            mockUoW.Setup(x => x.RoomRepository.GetAll()).Returns(roomList.AsQueryable());
            mockUoW.Setup(x => x.PlaceRepository).Returns(mockPlaceRepository.Object);

            var controller = new RoomController(mockUoW.Object);

            // Act
            var result = controller.Edit(id) as ViewResult;

            // Assert
            Assert.IsNotNull(result.Model);
        }