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;
     }
 }
Example #2
0
        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));
        }
Example #3
0
        public ActionResult Delete(Topic topic)
        {
            try
            {
                topicRepository.Delete(topic);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Example #4
0
        public ActionResult Create(Topic topic)
        {
            if (ModelState.IsValid)
            {
                topicRepository.Save(topic);

                return RedirectToAction("Index");
            }
            else
            {
                return View();
            }
        }
Example #5
0
        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));
        }
Example #6
0
        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);
 }
Example #8
0
        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);
        }
Example #9
0
        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);
        }
Example #10
0
        public ActionResult Edit(Topic topic)
        {
            if ((ModelState.IsValid) && (topicRepository.ReadById(topic.Id) != null))
            {
                topicRepository.Save(topic);

                return RedirectToAction("Index");
            }
            else
            {
                return View();
            }
        }