< Summary

Class:ApplicationCore.Model.Comment
Assembly:ApplicationCore
File(s):C:\Users\Teknikaali\Source\Repos\jekyll-blog-comments\ApplicationCore\Model\Comment.cs
Covered lines:54
Uncovered lines:0
Coverable lines:54
Total lines:94
Line coverage:100% (54 of 54)
Covered branches:6
Total branches:6
Branch coverage:100% (6 of 6)

Coverage History

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
.cctor()10100%100%
.ctor(...)40100%100%
.ctor(...)20100%100%
WithScore(...)10100%100%

File(s)

C:\Users\Teknikaali\Source\Repos\jekyll-blog-comments\ApplicationCore\Model\Comment.cs

#LineLine coverage
 1using System;
 2using System.Globalization;
 3using System.Text.RegularExpressions;
 4using YamlDotNet.Serialization;
 5
 6namespace ApplicationCore.Model
 7{
 8    /// <summary>
 9    /// Represents a Comment to be written to the repository in YML format.
 10    /// </summary>
 11    public class Comment
 12    {
 13        /// <summary>
 14        /// Valid characters when mapping from the blog post slug to a file path
 15        /// </summary>
 116        static readonly Regex _validPathChars = new Regex(@"[^a-zA-Z0-9-]");
 17
 18        [YamlIgnore]
 2419        public string PostId { get; }
 20
 521        public string Id { get; }
 22
 2323        public DateTime Date { get; }
 24
 2425        public string Name { get; }
 26
 2627        public string Message { get; }
 28
 429        public string? Email { get; }
 30
 831        public string Score { get; }
 32
 33        [YamlMember(SerializeAs = typeof(string))]
 634        public Uri? Avatar { get; }
 35
 36        [YamlMember(SerializeAs = typeof(string))]
 337        public Uri? Url { get; }
 38
 1939        public Comment(
 1940            string postId,
 1941            string message,
 1942            string name,
 1943            string? email = null,
 1944            Uri? url = null,
 1945            string? avatar = null,
 1946            string? score = null)
 1947        {
 1948            PostId = _validPathChars.Replace(postId, "-");
 49
 1950            Message = message;
 1951            Name = name;
 1952            Email = email;
 1953            Url = url;
 54
 1955            Date = DateTime.UtcNow;
 1956            Id = new { PostId, Name, Message, Date }.GetHashCode().ToString("x8", CultureInfo.InvariantCulture);
 57
 1958            if (Uri.TryCreate(avatar, UriKind.Absolute, out var avatarUrl))
 159                Avatar = avatarUrl;
 60
 1961            Score = score ?? "Not configured";
 1962        }
 63
 64        /// <summary>
 65        /// Copy constructor for internal use only
 66        /// </summary>
 367        private Comment(
 368            string postId,
 369            string message,
 370            string name,
 371            string? email,
 372            Uri? url,
 373            DateTime date,
 374            string id,
 375            Uri? avatar,
 376            string? score)
 377        {
 378            PostId = postId;
 379            Message = message;
 380            Name = name;
 381            Email = email;
 382            Url = url;
 383            Date = date;
 384            Id = id;
 385            Avatar = avatar;
 386            Score = score ?? "Not configured";
 387        }
 88
 89        public Comment WithScore(string score)
 390        {
 391            return new Comment(PostId, Message, Name, Email, Url, Date, Id, Avatar, score);
 392        }
 93    }
 94}