< Summary

Information
Class: TestUtilities.RandomExtensions
Assembly: GistBackend.TestUtilities
File(s): /home/runner/work/the-gist-of-it-sec/the-gist-of-it-sec/backend/GistBackend.TestUtilities/RandomExtensions.cs
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 31
Line coverage: 100%
Branch coverage
87%
Covered branches: 7
Total branches: 8
Branch coverage: 87.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
NextString(...)100%11100%
NextUri(...)100%11100%
NextArrayOfStrings(...)100%22100%
NextDateTime(...)83.33%66100%
NextFeedType(...)100%11100%

File(s)

/home/runner/work/the-gist-of-it-sec/the-gist-of-it-sec/backend/GistBackend.TestUtilities/RandomExtensions.cs

#LineLine coverage
 1using GistBackend.Types;
 2
 3namespace TestUtilities;
 4
 5public static class RandomExtensions {
 6    private const string Characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
 7
 8    extension(Random random)
 9    {
 682110        public string NextString(int length = 50) => new(
 34105011            Enumerable.Repeat(Characters, length).Select(s => s[random.Next(s.Length)]).ToArray()
 682112        );
 13
 14        public Uri NextUri(int partLength = 50) =>
 60715            new($"https://www.{random.NextString(partLength)}.com/{random.NextString(partLength)}");
 16
 28117        public string[] NextArrayOfStrings(int? length = null) => Enumerable
 183918            .Repeat("", length ?? random.Next(1, 11)).Select(_ => random.NextString()).ToArray();
 19
 20        public DateTime NextDateTime(DateTime? min = null, DateTime? max = null)
 21        {
 92622            min ??= DateTime.UnixEpoch;
 92623            max ??= DateTime.UnixEpoch.AddYears(100);
 92624            var maxSeconds = (int)(max - min).Value.TotalSeconds;
 92625            return min.Value.AddSeconds(random.Next(maxSeconds));
 26        }
 27
 28        public FeedType NextFeedType() =>
 12029            (FeedType)random.Next(Enum.GetValues<FeedType>().Length);
 30    }
 31}