示例#1
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));
        }
示例#2
0
        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"]);
        }
示例#3
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));
        }
示例#4
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);
        }
示例#5
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);
        }
示例#6
0
        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>));
        }
示例#7
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);
        }