< Summary

Class:MUNity.Util.IdGenerator
Assembly:MUNity.Base
File(s):C:\Users\aeuke\source\repos\PeerConradi\munity\src\MUNityBase\Util\IdGenerator.cs
Covered lines:13
Uncovered lines:0
Coverable lines:13
Total lines:41
Line coverage:100% (13 of 13)
Covered branches:0
Total branches:0
Covered methods:3
Total methods:3
Method coverage:100% (3 of 3)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.cctor()100%1100%
RandomString(...)100%1100%
AsPrimaryKey(...)100%1100%

File(s)

C:\Users\aeuke\source\repos\PeerConradi\munity\src\MUNityBase\Util\IdGenerator.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text.RegularExpressions;
 5using System.Threading.Tasks;
 6
 7namespace MUNity.Util
 8{
 9    public class IdGenerator
 10    {
 211        private static readonly Random _random = new Random();
 12        /// <summary>
 13        /// Gemerates a Random string with all characters form A-Z, a-z and 0-9
 14        /// Total length is 62
 15        /// </summary>
 16        /// <param name="length"></param>
 17        /// <returns></returns>
 18        public static string RandomString(int length)
 319        {
 20            const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
 321            return new string(Enumerable.Repeat(chars, length)
 5122                .Select(s => s[_random.Next(s.Length)]).ToArray());
 323        }
 24
 25        /// <summary>
 26        /// Turns the text into a lower case verison and removes all special characters
 27        /// so the value can be used as primary key (of string) that can also be used for an URL
 28        /// </summary>
 29        /// <param name="input"></param>
 30        /// <returns></returns>
 31        public static string AsPrimaryKey(string input)
 7832        {
 7833            input = input.ToLower();
 7834            input = input.Replace("ä", "ae");
 7835            input = input.Replace("ö", "oe");
 7836            input = input.Replace("ü", "ue");
 7837            input = Regex.Replace(input, "[^a-z0-9]", "");
 7838            return input;
 7839        }
 40    }
 41}