Example #1
0
        public void GetPostById_ReturnOnePost(int id)
        {
            // Arrange
            var testProducts   = GetTestPosts();
            var postService    = new Mock <IPostService>();
            var commentService = new Mock <ICommentService>();
            var controller     = new PostApiController(postService.Object, commentService.Object);

            // Act
            postService.Setup(service => service.GetPostEntity(id)).Returns(testProducts.Find(p => p.Id == id));
            var result = controller.Get(id);

            // Assert
            Assert.AreEqual(id, result.Id);
        }
Example #2
0
        public void GetAllPosts_ReturnAllPosts()
        {
            // Arrange
            var testProducts   = GetTestPosts();
            var postService    = new Mock <IPostService>();
            var commentService = new Mock <ICommentService>();
            var controller     = new PostApiController(postService.Object, commentService.Object);

            // Act
            postService.Setup(service => service.GetAllPostEntities()).Returns(testProducts);
            var result = controller.AllPosts();

            // Assert
            Assert.AreEqual(testProducts.Count, result.ToList().Count);
        }
Example #3
0
        public void Post_ShouldReturnUnauth()
        {
            _post = TestDbPopulator.GetPost(3, 1);
            PostDTO postDto = _mapper.Map <Post, PostDTO>(_post);
            var     req     = new HttpRequestMessage {
                RequestUri = new Uri("http://localhost:50268/api/Post")
            };

            req.Properties[HttpPropertyKeys.HttpConfigurationKey] = new HttpConfiguration();
            _controller = new PostApiController(TestContext)
            {
                Request = req
            };
            var response = _controller.Post(postDto);
            var result   = TestHelper.ParsePostResponse(response);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
Example #4
0
        public void PostApiControllerTestInitialize()
        {
            _config = Mapping.Mapping.GetConfiguration();
            _mapper = _config.CreateMapper();
            TestDbPopulator.PopulateDb(2, 1);
            string token   = BaseAuth.CreateToken("u1");
            var    config  = new HttpConfiguration();
            var    request = new HttpRequestMessage {
                RequestUri = new Uri("http://localhost:50268/api/Post")
            };

            request.Headers.Add("x-zumo-auth", token);
            request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
            _controller = new PostApiController(TestContext)
            {
                Request = request,
                User    = TestHelper.GetUser("u1")
            };
        }