public void CreateRoomDelegatesToRepository()
        {
            var service = CreateService();
            var roomViewModel = new RoomViewModel { Name = "Test Room" };
            var roomRecord = new RoomRecord("Test Room");
            mockRoomViewModelMapper.Setup(mapper => mapper.MapRoomViewModelToRoomRecord(roomViewModel)).Returns(roomRecord);

            service.CreateRoom(roomViewModel);

            mockRoomRepository.Verify(repository => repository.CreateRoom(roomRecord.Name));
        }
コード例 #2
0
        public void PostCreateNewRoomWithBlacklistedWordsCausesValidationError(string roomName)
        {
            var controller = CreateController();

            var viewModel = new RoomViewModel { Name = roomName };
            var context = new ValidationContext(viewModel, serviceProvider: null, items: null);
            var results = new List<ValidationResult>();

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

            Assert.That(isValid, Is.False);
        }
コード例 #3
0
        public void PostCreateNewRoomWithInvalidRoomNameShowsCreateView(string roomName)
        {
            var controller = CreateController();

            var viewModel = new RoomViewModel { Name = 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));
        }
コード例 #4
0
        public ActionResult Create(RoomViewModel model)
        {
            ActionResult result;
 
            if(ModelState.IsValid)
            {
                writer.CreateRoom(model.Name);

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

            return result;
        }
コード例 #5
0
 public void CreateRoom(RoomViewModel roomViewModel)
 {
     var roomRecord = mapper.MapRoomViewModelToRoomRecord(roomViewModel);
     roomRepository.CreateRoom(roomRecord.Name);
 }
コード例 #6
0
        public void PostCreateNewRoomRedirectsToViewResult()
        {
            var controller = CreateController();

            var viewModel = new RoomViewModel { Name = "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"));
        }
コード例 #7
0
        public void PostCreateNewRoomDelegatesToWriter()
        {
            var controller = CreateController();

            var viewModel = new RoomViewModel { Name = "Test Room" };
            controller.Create(viewModel);

            mockWriter.Verify(writer => writer.CreateRoom(viewModel));
        }
コード例 #8
0
 public RoomRecord MapRoomViewModelToRoomRecord(RoomViewModel roomViewModel)
 {
     return new RoomRecord(roomViewModel.Name);
 }
コード例 #9
0
 public void CreateRoom(RoomViewModel roomViewModel)
 {
     var roomsCollection = GetRoomsCollection();
     roomsCollection.Save(roomViewModel);
 }