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 void Delete_não_deve_perguntar_para_excluir_um_tópico_inexistente() { //Arrange var guidBase = Guid.NewGuid(); var mock = new Mock<ITopicRepository>(); mock. Setup(m => m.ReadById(guidBase)). Returns((Topic) null); var controller = new TopicController(mock.Object); //Act var result = (RedirectToRouteResult) controller.Delete(guidBase); //Assert Assert.AreEqual("Index", result.RouteValues["action"]); }
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 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 Index_deve_listar_os_tópicos_cadastrados() { //Arrange var mock = new Mock<ITopicRepository>(); mock. Setup(m => m.ReadAll()). Returns(new List<Topic>()); var controller = new TopicController(mock.Object); //Act var result = (ViewResult) controller.Index(); //Assert Assert.IsInstanceOfType(result.Model, typeof(IEnumerable<Topic>)); }
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); }