< Summary

Information
Class: Elsa.Identity.Services.DefaultRandomStringGenerator
Assembly: Elsa.Identity
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Services/DefaultRandomStringGenerator.cs
Line coverage
33%
Covered lines: 3
Uncovered lines: 6
Coverable lines: 9
Total lines: 35
Line coverage: 33.3%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
Generate(...)0%2040%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Services/DefaultRandomStringGenerator.cs

#LineLine coverage
 1using System.Text;
 2using Elsa.Identity.Constants;
 3using Elsa.Identity.Contracts;
 4
 5namespace Elsa.Identity.Services;
 6
 7/// <inheritdoc />
 8public class DefaultRandomStringGenerator : IRandomStringGenerator
 9{
 10    private readonly Random _random;
 11
 12    /// <summary>
 13    /// Initializes a new instance of the <see cref="DefaultRandomStringGenerator"/> class.
 14    /// </summary>
 115    public DefaultRandomStringGenerator()
 16    {
 117        _random = new Random();
 118    }
 19
 20    /// <inheritdoc />
 21    public string Generate(int length = 32, char[]? chars = null)
 22    {
 023        var identifierBuilder = new StringBuilder(length);
 24
 025        chars ??= CharacterSequences.AlphanumericSequence;
 26
 027        for (var i = 0; i < length; i++)
 28        {
 029            var randomIndex = _random.Next(chars.Length);
 030            identifierBuilder.Append(chars[randomIndex]);
 31        }
 32
 033        return identifierBuilder.ToString();
 34    }
 35}