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)); }
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); }
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)); }
public ActionResult Create(RoomViewModel model) { ActionResult result; if(ModelState.IsValid) { writer.CreateRoom(model.Name); result = RedirectToAction("List"); } else { result = View("Create", model); } return result; }
public void CreateRoom(RoomViewModel roomViewModel) { var roomRecord = mapper.MapRoomViewModelToRoomRecord(roomViewModel); roomRepository.CreateRoom(roomRecord.Name); }
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")); }
public void PostCreateNewRoomDelegatesToWriter() { var controller = CreateController(); var viewModel = new RoomViewModel { Name = "Test Room" }; controller.Create(viewModel); mockWriter.Verify(writer => writer.CreateRoom(viewModel)); }
public RoomRecord MapRoomViewModelToRoomRecord(RoomViewModel roomViewModel) { return new RoomRecord(roomViewModel.Name); }
public void CreateRoom(RoomViewModel roomViewModel) { var roomsCollection = GetRoomsCollection(); roomsCollection.Save(roomViewModel); }