public async Task AttemptingToCreateSimpleContentWithIdAlreadyInUse() { await s_repo.CreateContentAsync(new SimpleContent { Id = "existing", Title = "Exists", Content = "Already here" }); var toAdd = new SimpleContent { Id = "existing", Title = "Usurper", Content = "Trying to overwrite" }; var controller = new ManageSimpleController(s_repo, s_mapRepo); var result = await controller.Create(toAdd) as ViewResult; Assert.AreEqual("Create", result.ViewName, "Shows Create view again"); Assert.AreSame(toAdd, result.Model, "Passes model back to view"); Assert.AreEqual("Content with this id already exists", controller.ModelState["Id"].Errors.Single().ErrorMessage); }
public void AddingSimpleContent() { //Assemble var controller = new ManageSimpleController(s_repo, s_mapRepo); SimpleContent content = new SimpleContent { Title = "Added", Content = "<b>Added</b>" }; //Act var result = controller.Create(content).GetAwaiter().GetResult() as ViewResult; var items = s_repo.GetListOfItemsAsync(ContentType.Simple.ToString()).GetAwaiter().GetResult(); var targetItem = items.Where((i) => i.Title == "Added").FirstOrDefault(); //Assert Assert.AreEqual <string>("Confirm", result.ViewName, "Confirmation view not returned"); Assert.IsNotNull(targetItem, "Item not found after adding"); }