public async Task CreatePost_ViewName_Ok() { var result = await Task.FromResult(_controller.CreatePost(1)); var viewResult = Assert.IsType <ViewResult>(result); Assert.IsAssignableFrom <CreatePostViewModel>(viewResult.Model); }
public async Task WhenCreatePostGetsCalled() { Setup(); _createPostRequest = new Fixture().Create <CreatePostRequest>(); AuthService.Setup(service => service.AuthorizeSelf(It.IsAny <string>(), It.IsAny <Guid>())) .Returns(false); _result = await PostsController.CreatePost(_createPostRequest); }
public void CreatePost_UnauthorizedUserClaims_ReturnsUnauthorized() { // Arrange int userId = 1; var postForCreation = new PostForCreationDto { NameOfDish = "Katsu curry", Description = "chicken and rice", Ingredients = "chicken, rice", Method = "fry chicken, boil rice", PrepTime = "20 min", CookingTime = "20 min", Feeds = "3", Cuisine = "Japanese" }; // Act var result = _postsController.CreatePost(userId, postForCreation) .Result; // Assert Assert.IsType <UnauthorizedResult>(result); }
public async Task WhenCreatePostGetsCalled() { Setup(); _createPostRequest = new Fixture().Create <CreatePostRequest>(); AuthService.Setup(service => service.AuthorizeSelf(It.IsAny <string>(), It.IsAny <Guid>())) .Returns(true); AuthService.Setup(service => service.AuthorizeFriend(It.IsAny <string>(), It.IsAny <Guid>())) .ReturnsAsync(true); PostsService.Setup(service => service.CreatePost(It.IsAny <Post>())) .Callback <Post>(post => _usedPost = post); _result = await PostsController.CreatePost(_createPostRequest); }
public async Task Add_InvalidPost_Returns_BadRequest() { //Arrange PostInputDto x = null; //Act var result = await postsController.CreatePost(x); //Assert Assert.IsType <BadRequestResult>(result.Result); }
public void CreateAndVerifyPost() { Post newPost = new Post(Guid.NewGuid().ToString(), "New Post title 4", "Post content 4", DateTime.UtcNow, DateTime.UtcNow, true); Post createdPost = controller.CreatePost(newPost); Assert.IsNotNull(createdPost); // Asset fields are correct. Assert.AreEqual(createdPost._id, newPost._id); Assert.AreEqual(createdPost.title, newPost.title); Assert.AreEqual(createdPost.content, newPost.content); Assert.AreEqual(createdPost.createdAt, newPost.createdAt); Assert.AreEqual(createdPost.updatedAt, newPost.updatedAt); Assert.AreEqual(createdPost.published, newPost.published); // Now get all posts and verify that there are 4. string postsJson = controller.GetByTitle(""); Assert.IsFalse(string.IsNullOrEmpty(postsJson)); List <Post> posts = JsonConvert.DeserializeObject <List <Post> >(postsJson); Assert.AreEqual(posts.Count, 4); // Only get posts with a title containing "New". This should only be 1. postsJson = controller.GetByTitle("New"); Assert.IsFalse(string.IsNullOrEmpty(postsJson)); posts = JsonConvert.DeserializeObject <List <Post> >(postsJson); Assert.AreEqual(posts.Count, 1); // Finally, get the post by id and verify it matches. string postJson = controller.GetById(newPost._id); Assert.IsFalse(string.IsNullOrEmpty(postJson)); Post post = JsonConvert.DeserializeObject <Post>(postJson); Assert.IsNotNull(post); Assert.AreEqual(post._id, newPost._id); Assert.AreEqual(post.title, newPost.title); Assert.AreEqual(post.content, newPost.content); Assert.AreEqual(post.createdAt, newPost.createdAt); Assert.AreEqual(post.updatedAt, newPost.updatedAt); Assert.AreEqual(post.published, newPost.published); }