< Summary

Class:JekyllBlogCommentsAzure.PostCommentToPullRequestFunction
Assembly:JekyllBlogCommentsAzure
File(s):C:\Users\Teknikaali\Source\Repos\jekyll-blog-comments\JekyllBlogCommentsAzure\PostCommentToPullRequestFunction.cs
Covered lines:22
Uncovered lines:0
Coverable lines:22
Total lines:56
Line coverage:100% (22 of 22)
Covered branches:9
Total branches:12
Branch coverage:75% (9 of 12)

Coverage History

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
.ctor(...)10100%100%
Run()120100%75%

File(s)

C:\Users\Teknikaali\Source\Repos\jekyll-blog-comments\JekyllBlogCommentsAzure\PostCommentToPullRequestFunction.cs

#LineLine coverage
 1using System;
 2using System.Net;
 3using System.Threading.Tasks;
 4using ApplicationCore;
 5using Microsoft.AspNetCore.Http;
 6using Microsoft.AspNetCore.Mvc;
 7using Microsoft.Azure.WebJobs;
 8using Microsoft.Azure.WebJobs.Extensions.Http;
 9using Microsoft.Extensions.Logging;
 10
 11namespace JekyllBlogCommentsAzure
 12{
 13    public class PostCommentToPullRequestFunction
 14    {
 15        private readonly IPostCommentService _postCommentService;
 16
 817        public PostCommentToPullRequestFunction(IPostCommentService postCommentService)
 818        {
 819            _postCommentService = postCommentService;
 820        }
 21
 22        [FunctionName("PostComment")]
 23        public async Task<IActionResult> Run(
 24            [HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest request,
 25            ILogger logger)
 826        {
 827            if (request is null)
 128            {
 129                logger.LogError(CommentResources.ParameterCannotBeNull, nameof(request));
 130                return new BadRequestResult();
 31            }
 32
 33            try
 734            {
 735                var form = await request.ReadFormAsync().ConfigureAwait(false);
 736                var result = await _postCommentService.PostCommentAsync(form).ConfigureAwait(false);
 37
 638                switch (result.HttpStatusCode)
 39                {
 40                    case HttpStatusCode.OK:
 141                        return new OkResult();
 42                    case HttpStatusCode.Redirect:
 143                        return new RedirectResult(result.RedirectUrl?.AbsoluteUri);
 44                    default:
 445                        logger.LogError(result.Exception, result.Error);
 446                        return new BadRequestResult();
 47                }
 48            }
 149            catch (Exception e)
 150            {
 151                logger.LogError(e, CommentResources.PostCommentExceptionMessage, e.Message);
 152                throw;
 53            }
 754        }
 55    }
 56}