Ejemplo n.º 1
0
        public void Create_ModelIsValid_ReturnsCreatedAtAction()
        {
            //Arrange
            _topicService.Setup(s => s.CreateEntityAsync(_topic));

            //Act
            var actionResult = _topicController.Create(_topic);

            //Assert
            actionResult.Result.Should().BeOfType <CreatedAtActionResult>();
        }
Ejemplo n.º 2
0
        public void CreateShoudCreateTopic()
        {
            //ARRANGE
            var model = new TopicEntity
            {
                Description = "Topic one"
            };

            var logic = new Mock <ITopicLogic>();

            logic
            .Setup(x => x.Create(It.IsAny <TopicEntity>()))
            .Verifiable("should save topic");

            var controller = new TopicController(logic.Object, null, null, null);

            //ACT
            var result = controller.Create(model) as RedirectToRouteResult;

            //ASSERT
            logic.Verify();

            Assert.NotNull(result);
            Assert.AreEqual("Index", result.RouteValues["Action"]);
        }
Ejemplo n.º 3
0
        public void CreateShouldDisplayTheCorrectView()
        {
            //ARRANGE
            var controller = new TopicController(null, null, null, null);

            //ACT
            var result = controller.Create() as ViewResult;

            //ASSERT
            Assert.NotNull(result);
            Assert.NotNull(result.Model);
            Assert.That(result.ViewName, Is.EqualTo("Create"));
        }
Ejemplo n.º 4
0
        public void ShouldCreateTopicAndNotifyTheUser()
        {
            var professionalDevelopment = new Topic {
                Id = 3, Colour = ColorTranslator.FromHtml("#000000"), Name = "Professional Development"
            };
            var formValues = new FormCollection
            {
                { "Id", professionalDevelopment.Id.ToString() },
                { "Name", professionalDevelopment.Name },
                { "Colour", professionalDevelopment.ColourInWebHex().Trim('#') }
            };

            var controller = new TopicController();

            var result = (RedirectToRouteResult)controller.Create(formValues);

            Assert.Contains(professionalDevelopment, Topic.Topics);
            Assert.AreEqual("Index", result.RouteValues["action"]);
            Assert.AreEqual("Your topic has been added successfully.", controller.TempData["message"]);
        }