public async Task CreatePostTest() { // arrange var newPost = new PostCreation { Title = Guid.NewGuid().ToString("N"), Body = Guid.NewGuid().ToString("N"), UserId = new Random().Next() }; // act var createdPost = await _jsonPlaceholderService.CreatePost(newPost); // assert createdPost.Should().NotBeNull(); var retrievedPost = await _jsonPlaceholderService.GetPostAsync(createdPost.Id); createdPost.Title.Should().Be(newPost.Title); createdPost.Body.Should().Be(newPost.Body); createdPost.UserId.Should().Be(newPost.UserId); retrievedPost.Title.Should().Be(newPost.Title); retrievedPost.Body.Should().Be(newPost.Body); retrievedPost.UserId.Should().Be(newPost.UserId); }
public async Task <Post> CreatePost(PostCreation post) { var response = await _apiService.PostAsync("posts", post); return(JsonConvert.DeserializeObject <Post>(await response.Content.ReadAsStringAsync())); }