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); }
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); }
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); }
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") }; }