コード例 #1
0
        public void AddTopic_ExpectOk()
        {
            topicLogic.Setup(a => a.Add(topic)).Returns(topic.Id);
            topicLogic.Setup(a => a.GetByName(topic.Name)).Returns(topic);

            var result        = topicController.Post(topicModelIn);
            var createdResult = result as CreatedResult;
            var modelOut      = createdResult.Value as TopicModelOut;

            topicLogic.VerifyAll();

            Assert.IsNotNull(createdResult);
            Assert.AreEqual(201, createdResult.StatusCode);
            Assert.AreEqual(topicModelIn.Name, modelOut.Name);
        }
        public void TopicController_Post_WhenTheTopicIsAddedSuccessfully_WillReturnANavigationProperty()
        {
            TopicController.GetTopicsCollection = () =>
            {
                return(new List <Topic>
                {
                    new Topic {
                        topic = "ASP.NET Core", id = 1
                    },
                    new Topic {
                        topic = "Docker for .NET Developers", id = 2
                    }
                });
            };
            TopicController.Init();
            var controller = new TopicController();

            SetUpHttpRequestParameters(controller);
            var response = controller.Post(new Topic
            {
                topic     = "Visual Studio on a Mac",
                tutorials = (new List <Tutorial> {
                }).ToArray()
            });

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            ExpandoObject expando;

            Assert.IsTrue(response.TryGetContentValue(out expando));
            var expandoDict = (IDictionary <string, object>)expando;

            Assert.AreEqual(3, expandoDict["id"]);
            Assert.AreEqual("http://localhost/api/Topic/3", expandoDict["url"]);
        }
コード例 #3
0
        public void TopicController_Post_WhenTheTopicIsAddedSuccessfully_WillReturnAnOKStatusAndANavigationProperty()
        {
            var controller = new TopicController(_topicsRepository.Object);

            SetUpHttpRequestParameters(controller);
            var response = controller.Post(new Topic
            {
                Name      = "Visual Studio on a Mac",
                Tutorials = new List <Tutorial> {
                }
            });

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            ExpandoObject expando;

            Assert.IsTrue(response.TryGetContentValue(out expando));
            var expandoDict = (IDictionary <string, object>)expando;

            Assert.AreEqual(0, expandoDict["id"]);
            Assert.AreEqual("http://localhost/api/Topic/0", expandoDict["url"]);
            _topicsRepository.Verify(t => t.Insert(It.IsAny <Topic>()), Times.Once());
            _topicsRepository.Verify(c => c.Save(), Times.Once());
        }
コード例 #4
0
        public void PostReturnsBadRequest()
        {
            var result = controller.Post("   ");

            Assert.IsType <BadRequestObjectResult>(result.Result);
        }