public async Task When_POST_blog_post_Then_200_OK_with_non_default_id_is_returned()
        {
            var user = UserFactory.CreateUser("User 1");

            using (var context = CreateContext())
            {
                context.Users.Add(user);
                await context.SaveChangesAsync();
            }

            var createRequest = new CreateBlogPostRequest
            {
                Authors = new[] { user.Name },
                Title   = "Post 1"
            };

            var request = new CreateBlogPostsRequest
            {
                Posts = new[] { createRequest }
            };

            var(createBlogPostsResponse, httpResponse) = await _client.PostWithResponseAsync <CreateBlogPostsResponse>($"{BASE_ROUTE}", request);

            Assert.Multiple(() =>
            {
                Assert.That(httpResponse.StatusCode, Is.EqualTo(HttpStatusCode.OK), "Invalid status code");
                Assert.That(createBlogPostsResponse, Is.Not.Null, "Response is null");
                Assert.That(createBlogPostsResponse.PostIds, Is.Not.Null, "Post ids result is null");
                Assert.That(createBlogPostsResponse.PostIds.Count(), Is.EqualTo(1), "Invalid post ids count");
                Assert.That(createBlogPostsResponse.PostIds.Single(), Is.Not.EqualTo(default), "Post id has default value");
Exemplo n.º 2
0
        public async Task <ActionResult <CreateBlogPostsResponse> > PostAsync([FromBody] CreateBlogPostsRequest request)
        {
            var result = await _blogPostsProcess.CreatePostsAsync(request.Posts.Select(MapToDto));

            return(Ok(new CreateBlogPostsResponse
            {
                PostIds = result.Select(p => p.PostId)
            }));
        }