public void Save(Topic topic) { if (topic.Id == Guid.Empty) { topic.Id = Guid.NewGuid(); topics.Add(topic); } else { var editTopic = ReadById(topic.Id); editTopic.Value = topic.Value; } }
public void Create_deve_gravar_um_topico_valido() { //Arrange var topic = new Topic() { Value = "gradiente" }; var mock = new Mock<ITopicRepository>(); var controller = new TopicController(mock.Object); //Act var result = controller.Create(topic); //Assert mock.Verify(m => m.Save(topic)); }
public ActionResult Delete(Topic topic) { try { topicRepository.Delete(topic); return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Create(Topic topic) { if (ModelState.IsValid) { topicRepository.Save(topic); return RedirectToAction("Index"); } else { return View(); } }
public void Edit_deve_gravar_um_topico_valido() { //Arrange var guidBase = Guid.NewGuid(); var topic = new Topic() { Id = guidBase, Value = "gradiente" }; var mock = new Mock<ITopicRepository>(); mock. Setup(m => m.ReadById(guidBase)). Returns(new Topic()); var controller = new TopicController(mock.Object); //Act var result = controller.Edit(topic); //Assert mock.Verify(m => m.Save(topic)); }
public void Delete_deve_perguntar_para_excluir_um_tópico_válido() { //Arrange var guidBase = Guid.NewGuid(); var topic = new Topic() { Id = guidBase, Value = "gradiente" }; var mock = new Mock<ITopicRepository>(); mock. Setup(m => m.ReadById(guidBase)). Returns(topic); var controller = new TopicController(mock.Object); //Act var result = (ViewResult)controller.Delete(topic.Id); //Assert Assert.AreEqual("", result.ViewName); }
public void Delete(Topic topic) { topics.Remove(topic); }
public void Edit_deve_retornar_o_topico_para_edição() { //Arrange var guidBase = Guid.NewGuid(); var topic = new Topic() { Id = guidBase, Value = "gradiente" }; var mock = new Mock<ITopicRepository>(); mock. Setup(m => m.ReadById(guidBase)). Returns(topic); var controller = new TopicController(mock.Object); //Act var result = (ViewResult)controller.Edit(guidBase); //Assert Assert.AreEqual(topic, result.Model); }
public void Edit_não_deve_gravar_um_tópico_não_cadastrado() { //Arrange var guidBase = Guid.NewGuid(); var topic = new Topic() { Id = guidBase, Value = "gradiente" }; var mock = new Mock<ITopicRepository>(); mock. Setup(m => m.ReadById(guidBase)). Returns((Topic) null); var controller = new TopicController(mock.Object); //Act var result = (ViewResult)controller.Edit(topic); //Assert Assert.AreEqual("", result.ViewName); }
public ActionResult Edit(Topic topic) { if ((ModelState.IsValid) && (topicRepository.ReadById(topic.Id) != null)) { topicRepository.Save(topic); return RedirectToAction("Index"); } else { return View(); } }