// GET: /Groups/Details/5 public ActionResult Details(int id, UsersDetailsViewModel usersDetails, MoviesDetailsViewModel moviesDetails, IPrincipal user) { var group = this._groupsService.Get(id); if (group == null) { return View("NotFound", new NotFoundViewModel(id, "Group")); } else { if (!String.IsNullOrEmpty(usersDetails.AddUsersButton)) { var allUsers = this._groupsService.GetAllUsersExceptLoggedUser(user.Identity.Name); var usersNotEnrolled = allUsers.Where(u => group.EnrolledUsers.Any(e => e.UserId == u.UserId) == false); ViewBag.UsersNotEnrolled = usersNotEnrolled; return View("_AddUsers", group); } if (!String.IsNullOrEmpty(usersDetails.DeleteUsersButton)) { ViewBag.DeleteEnrolledUsers = usersDetails.DeleteEnrolledUsers; return View("_DeleteUsers", group); } if (!String.IsNullOrEmpty(moviesDetails.AddMoviesButton)) { var ownedMovies = this._moviesService.GetMoviesCreatedByUser(user.Identity.Name); var moviesNotShared = ownedMovies.Where(m => group.SharedMovies.Any(s => s.ID == m.ID) == false); ViewBag.MoviesNotShared = moviesNotShared; return View("_AddMovies", group); } if (!String.IsNullOrEmpty(moviesDetails.DeleteMoviesButton)) { List<Movie> moviesBuffer = moviesDetails.DeleteSharedMovies.Select(deleteMovieId => this._moviesService.Get(deleteMovieId)).ToList(); ViewBag.DeleteSharedMovies = moviesBuffer; return View("_DeleteMovies", group); } } return View(group); }
public void ShouldRenderTheDetailsForAnExistingGroup() { // Arrange const int id = 1; Group group = _inMemoryGroupsService.Get(id); UsersDetailsViewModel usersDetailsViewModel = new UsersDetailsViewModel(); MoviesDetailsViewModel moviesDetailsViewModel = new MoviesDetailsViewModel(); IPrincipal fakeUser = new GenericPrincipal(new GenericIdentity("User1", "Forms"), null); // Act ActionResult actual = _controller.Details(id, usersDetailsViewModel, moviesDetailsViewModel, fakeUser); // Assert Assert.IsNotNull(actual, "The returned ActionResult is Null"); Assert.IsInstanceOf<ViewResult>(actual, "The returned ActionResult was not an instance of ViewResult"); ViewResult viewResult = (ViewResult) actual; Assert.IsNotNull(viewResult.ViewData.Model, "The value of viewResult.ViewData.Model is Null"); Assert.IsInstanceOf<Group>(viewResult.ViewData.Model, "The value of viewResult.ViewData.Model is not an instance of Group"); Group model = (Group) viewResult.ViewData.Model; Assert.IsTrue(model.ID == group.ID, string.Format("The value of Model.ID should be '{0}' but it is '{1}'", group.ID, model.ID)); Assert.IsTrue(model.Name == group.Name, string.Format("The value of Model.Name should be '{0}' but it is '{1}'", group.Name, model.Name)); Assert.IsTrue(model.Description == group.Description, string.Format("The value of Model.Description should be '{0}' but it is '{1}'", group.Description, model.Description)); }