public void PostCreateNewRoomWithInvalidRoomNameCausesValidationError(string roomName)
        {
            var controller = CreateController();

            var viewModel = new CreateRoomViewModel { NewRoomName = roomName };

            var context = new ValidationContext(viewModel, serviceProvider: null, items: null);
            var results = new List<ValidationResult>();

            var isValid = Validator.TryValidateObject(viewModel, context, results);

            Assert.That(isValid, Is.False);
        }
        public void PostCreateNewRoomWithInvalidRoomNameShowsCreateView(string roomName)
        {
            var controller = CreateController();

            var viewModel = new CreateRoomViewModel { NewRoomName = roomName };
            controller.ViewData.ModelState.AddModelError("Room Name", "Room name is required");
            var result = controller.Create(viewModel);

            Assert.That(result, Is.InstanceOf<ViewResult>());

            var viewResult = result as ViewResult;
            Assert.That(viewResult.View, Is.Null);
            Assert.That(viewResult.Model, Is.EqualTo(viewModel));
        }
        public ActionResult Create(CreateRoomViewModel model)
        {
            ActionResult result;
 
            if(ModelState.IsValid)
            {
                roomRepository.CreateRoom(model.NewRoomName);

                result = RedirectToAction("List");
            }
            else
            {
                result = View("Create", model);
            }

            return result;
        }
        public void PostCreateNewRoomRedirectsToViewResult()
        {
            var controller = CreateController();

            var viewModel = new CreateRoomViewModel { NewRoomName = "Test Room" };
            var result = controller.Create(viewModel);

            Assert.That(result, Is.InstanceOf<RedirectToRouteResult>());
            
            var redirectResult = result as RedirectToRouteResult;
            Assert.That(redirectResult.RouteValues["Action"], Is.EqualTo("List"));
        }
        public void PostCreateNewRoomDelegatesToRoomRepository()
        {
            var controller = CreateController();

            var viewModel = new CreateRoomViewModel { NewRoomName = "Test Room" };
            controller.Create(viewModel);

            mockRoomRepository.Verify(repository => repository.CreateRoom("Test Room"));
        }