public void CanEnsureChannelCreationIsValid() { Channel ChannelFromForm = new Channel(); ViewResult result = controller.Create(ChannelFromForm).AssertViewRendered(); result.ViewData.Model.ShouldNotBeNull(); result.ViewData.Model.ShouldBeOfType(typeof(ChannelsController.ChannelFormViewModel)); }
public void CanCompareChannels() { Channel instance = new Channel(); EntityIdSetter.SetIdOf<int>(instance, 1); Channel instanceToCompareTo = new Channel(); EntityIdSetter.SetIdOf<int>(instanceToCompareTo, 1); instance.ShouldEqual(instanceToCompareTo); }
public ActionResult Create(Channel Channel) { Channel.owner = UserRepository.FindOne( new { Username = User.Identity.Name } ); if (ViewData.ModelState.IsValid && Channel.IsValid()) { ChannelRepository.SaveOrUpdate(Channel); TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = "The Channel was successfully created."; return RedirectToAction("Index"); } ChannelFormViewModel viewModel = ChannelFormViewModel.CreateChannelFormViewModel(); viewModel.Channel = Channel; return View(viewModel); }
/// <summary> /// Creates a valid, transient Channel; typical of something retrieved back from a form submission /// </summary> private Channel CreateTransientChannel() { Channel Channel = new Channel() { name = "TheChannel", owner = new User(), }; return Channel; }
private void TransferFormValuesTo(Channel ChannelToUpdate, Channel ChannelFromForm) { ChannelToUpdate.name = ChannelFromForm.name; }
public IList<Post> GetPostsForChannel(Channel c, int Page) { SoulsController sc = new SoulsController(SoulRepository, PostRepository, null, null); List<Post> p = new List<Post>(); foreach (var u in c.users) { p.AddRange(sc.GetPostsForSoul(u.Id, Page, 10)); } return p.OrderBy(x => x.lastedit).Reverse().ToList(); }
public ActionResult Edit(Channel Channel) { Channel ChannelToUpdate = ChannelRepository.Get(Channel.Id); TransferFormValuesTo(ChannelToUpdate, Channel); if (ChannelToUpdate.owner.Username != User.Identity.Name) { throw new HttpException(401, "HTTP/1.1 401 Unauthorized"); } if (ViewData.ModelState.IsValid && Channel.IsValid()) { TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = "The Channel was successfully updated."; return RedirectToAction("Index"); } else { ChannelRepository.DbContext.RollbackTransaction(); ChannelFormViewModel viewModel = ChannelFormViewModel.CreateChannelFormViewModel(); viewModel.Channel = Channel; return View(viewModel); } }