コード例 #1
0
        public void PostShouldValidateModelState()
        {
            AutoMapperConfig.RegisterMappings(Assembly.Load("ForumSystem.Api"));

            var controller = new ThreadsController(this.threadService);
            controller.Configuration = new HttpConfiguration();

            var model = new ThreadRequestModel
            {
                Content = "Content"
            };

            controller.Validate(model);
            var result = controller.Post(model);

            Assert.IsFalse(controller.ModelState.IsValid);
        }
コード例 #2
0
        public void PostShouldReturnCorrectThread()
        {
            AutoMapperConfig.RegisterMappings(Assembly.Load("ForumSystem.Api"));

            var controller = new ThreadsController(this.threadService);

            var okResponse = controller.Post(new ThreadRequestModel
            {
                Title = "Title",
                Content = "Content"
            });

            var okResult = okResponse as OkNegotiatedContentResult<ThreadResponseModel>;

            Assert.IsNotNull(okResponse);
            Assert.AreEqual(1, okResult.Content.Id);
            Assert.AreEqual("Some Content", okResult.Content.Content);
            Assert.AreEqual("Test Title", okResult.Content.Title);
        }