public void EditSimpleContentReturnsItem() { //assemble var content = new SimpleContent { Id = "EditMe", Title = "To be edited" }; s_repo.CreateContentAsync(content).GetAwaiter().GetResult(); var controller = new ManageSimpleController(s_repo, s_mapRepo); //act var result = controller.Edit(content.Id).GetAwaiter().GetResult() as ViewResult; var model = result.Model as SimpleContent; //assert Assert.IsNotNull(model, "Item should be set as the model from repository"); Assert.AreEqual <string>(content.Id, model.Id); Assert.AreEqual <string>(content.Title, model.Title); }
public void EditSimpleContent() { //Assemble var controller = new ManageSimpleController(s_repo, s_mapRepo); controller.ControllerContext = new ControllerContext(new FakeHttpContext(), new System.Web.Routing.RouteData(), controller); SimpleContent content = new SimpleContent { Id = "Edit", Title = "Edit", Content = "<b>Edit</b>" }; s_repo.CreateContentAsync(content); content.Title = "Edited"; content.Content = "<i>Edited</i>"; //Act var result = controller.Edit(content.Id, content).GetAwaiter().GetResult() as ViewResult; var items = s_repo.GetListOfItemsAsync(ContentType.Simple.ToString()).GetAwaiter().GetResult(); var targetItem = items.Where((i) => i.Id == "Edit").FirstOrDefault(); //Assert Assert.AreEqual <string>("Confirm", result.ViewName, "Confirmation view not returned"); Assert.IsNotNull(targetItem, "Item not found after editing"); Assert.AreEqual <string>("Edited", targetItem.Title, "Title does not reflect edits"); }