< Summary

Information
Class: Utility.Components.GuidGenerator.GuidGenerator
Assembly: Utility
File(s): /home/runner/work/Utility-Blazor/Utility-Blazor/src/Utility/Components/GuidGenerator/GuidGenerator.razor
Tag: 327_19881906754
Line coverage
47%
Covered lines: 26
Uncovered lines: 29
Coverable lines: 55
Total lines: 210
Line coverage: 47.2%
Branch coverage
50%
Covered branches: 4
Total branches: 8
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
OnInitializedAsync()100%11100%
.ctor()100%11100%
CopyZeroGuid()100%210%
RemoveDashesFromZeroGuid()100%22100%
AddBracesToZeroGuid()100%22100%
Update()100%11100%
GenerateNewGuid()100%210%
RemoveDashesFromNewGuid()0%620%
CopyNewGuid()100%210%
GenerateMultipleGuids()0%620%
CopyMultipleGuids()100%210%
DeleteMultipleGuids()100%11100%

File(s)

/home/runner/work/Utility-Blazor/Utility-Blazor/src/Utility/Components/GuidGenerator/GuidGenerator.razor

#LineLine coverage
 1@using System.Text;
 2@inject IJSRuntime JSRuntime
 3
 4@*@inject ClipboardService ClipboardService*@
 5
 6<div class="container">
 7
 8    <div class="row">
 9        <div class="class">
 10            <h2>Guid</h2>
 11        </div>
 12    </div>
 13
 14    <div class="row">
 15        <label class="label-control">Zero:</label>
 16        <div class="input-group">
 17            <input type="text" id="guidZero" name="guidZero" class="form-control" @bind="@zeroGuid" placeholder="0000000
 18            <span class="input-group-btn">
 19                <button class="btn btn-info" type="button" id="btnGuidZeroCopy" name="btnGuidZeroCopy" @onclick="CopyZer
 20            </span>
 21        </div>
 22    </div>
 23    <div class="row">
 24        <div class="form-group">
 25            <div class="form-check form-check-inline">
 26                <input class="form-check-input" type="checkbox" value="@removeDashes" id="chkRemoveDashesZero"
 427                       @onchange="@(eventArgs => { removeDashes = (bool)eventArgs.Value; Update(); })"/>
 28                <label class="form-check-label" for="chkRemoveDashesZero">
 29                    Remove Dashes
 30                </label>
 31            </div>
 32            @* &nbsp;|&nbsp; *@
 33            <div class="form-check form-check-inline">
 34                <input class="form-check-input" type="checkbox" value="@addBraces" id="chkAddBracesZero"
 435                       @onchange="@(eventArgs => { addBraces = (bool)eventArgs.Value; Update(); })"/>
 36                <label class="form-check-label" for="chkAddBracesZero">
 37                    Add Braces
 38                </label>
 39            </div>
 40        </div>
 41    </div>
 42    <div class="row">
 43        <label class="label-control">New:</label>
 44        <div class="input-group">
 45            @* <span class="input-group-btn"></span> *@
 46            <input type="text" id="newGuid" name="newGuid" class="form-control" value="@newGuid" placeholder="00000000-0
 47            <input type="hidden" id="newGuidHidden" name="newGuidHidden" class="form-control" value="@newGuidHidden" pla
 48            <span class="input-group-btn">
 49                <button class="btn btn-success" type="button" id="btnGuidNewCreate" name="btnGuidNewCreate" @onclick="Ge
 50                <button class="btn btn-info" type="button" id="btnNewGuidCopy" name="btnNewGuidCopy" @onclick="CopyNewGu
 51            </span>
 52        </div>
 53    </div>
 54    <div class="row">
 55        <div class="form-group">
 56            <div class="form-check">
 57                <input class="form-check-input" type="checkbox" value="@removeDashesNew" id="chkRemoveDashes"
 058                       @onchange="@(eventArgs => { removeDashesNew = (bool)eventArgs.Value; RemoveDashesFromNewGuid(); }
 59                <label class="form-check-label" for="chkRemoveDashes">
 60                    Remove Dashes
 61                </label>
 62            </div>
 63        </div>
 64    </div>
 65    <hr/>
 66    <div class="row">
 67        <label class="label-control">How many Guids do you wish to generate:</label>
 68        <div class="input-group">
 69            <div class="form-check">
 70                <input class="form-check-input" type="checkbox" value="" id="chkRemoveDashesMultiple" />
 71                @* <input class="form-check-input" type="checkbox" value="@removeMultipleDashesNew" id="chkRemoveDashesM
 72                @*        @onchange="@(eventArgs => { removeMultipleDashesNew = (bool)eventArgs.Value; RemoveDashesFromN
 73                <label class="form-check-label" for="chkRemoveDashesMultiple">
 74                    Remove Dashes
 75                </label>
 76            </div>
 77        </div>
 78        <div class="input-group">
 79            <input type="number" class="form-control" id="guidCount" name="guidCount" @bind="@guidCount">
 80            <span class="input-group-btn">
 81                <button class="btn btn-success" type="button" id="btnGuidNewCreateMultiple" name="btnGuidNewCreateMultip
 82                        @onclick="GenerateMultipleGuids">Go!</button>
 83                <button class="btn btn-info" type="button" id="btnGuidMultipleCopy" name="btnGuidMultipleCopy"
 84                        @onclick="CopyMultipleGuids">
 85                    <i class="far fa-copy"></i>
 86                </button>
 87                <button class="btn btn-danger" type="button" id="btnGuidMultipleClear" name="btnGuidMultipleClear"
 88                        @onclick="DeleteMultipleGuids">
 89                    <i class="far fa-trash-alt"></i>
 90                </button>
 91            </span>
 92        </div>
 93    </div>
 94    <div class="row">
 95        <textarea id="guids" class="form-control" @bind="NewGuids" rows="@guidCount"></textarea>
 96    </div>
 97</div>
 98
 99@code {
 100
 101    private string newGuid;
 102    private Guid newGuidHidden;
 103    private int guidCount;
 104
 105    protected override async Task OnInitializedAsync()
 5106    {
 5107        var guid = Guid.NewGuid();
 5108        newGuid = guid.ToString();
 5109        newGuidHidden = guid;
 110
 5111        guidCount = 5;
 5112    }
 113
 114    #region Zero
 115
 5116    private Guid defaultZeroGuid = new Guid(); //"00000000000000000000000000000000" //"00000000-0000-0000-0000-000000000
 5117    private string zeroGuid = new Guid().ToString();
 118
 119    async Task CopyZeroGuid()
 0120    {
 0121        await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", zeroGuid);
 0122    }
 123
 5124    private bool removeDashes = false;
 125    void RemoveDashesFromZeroGuid()
 2126    {
 2127        zeroGuid = (removeDashes) ? defaultZeroGuid.ToString().Replace("-", "") : defaultZeroGuid.ToString();
 2128    }
 129
 5130    private bool addBraces = false;
 131    void AddBracesToZeroGuid()
 2132    {
 2133        zeroGuid = (addBraces) ? $"{{{zeroGuid}}}" : zeroGuid.Replace("{", "").Replace("}", "");
 2134    }
 135
 136    void Update()
 2137    {
 2138        RemoveDashesFromZeroGuid();
 2139        AddBracesToZeroGuid();
 2140    }
 141
 142    #endregion Zero
 143
 144    #region New
 145
 146    void GenerateNewGuid()
 0147    {
 0148        var guid = Guid.NewGuid();
 0149        newGuid = guid.ToString();
 0150        newGuidHidden = guid;
 0151        RemoveDashesFromNewGuid();
 0152    }
 153
 5154    private bool removeDashesNew = false;
 155    void RemoveDashesFromNewGuid()
 0156    {
 0157        newGuid = (removeDashesNew) ? newGuidHidden.ToString().Replace("-", "") : newGuidHidden.ToString();
 0158    }
 159
 160    async Task CopyNewGuid()
 0161    {
 0162        await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", newGuid);
 0163    }
 164
 165    #endregion New
 166
 167    #region Multiple
 168
 169    string NewGuids;
 170
 171    async Task GenerateMultipleGuids()
 0172    {
 0173        NewGuids = string.Empty; //Checkbox to append?
 174
 0175        StringBuilder builder = new StringBuilder();
 0176        for (int i = 0; i < guidCount; i++)
 0177        {
 0178            var guid = System.Guid.NewGuid().ToString() + System.Environment.NewLine;
 179
 180            // if (RemoveDashesMultiple)
 181            // {
 182            //    guid = Regex.Replace(guid, @"\-", "");
 183            // }
 184            // guid = (RemoveDashesMultiple) ? guid.ToString().Replace("-", "") : guid.ToString();
 185
 0186            builder.Append(guid);
 0187        }
 188
 0189        NewGuids = builder.ToString();
 0190    }
 191
 192    // private bool removeMultipleDashesNew = false;
 193    // void RemoveDashesFromNewMultipleGuid()
 194    // {
 195    //     newGuid = (removeMultipleDashesNew) ? newGuidHidden.ToString().Replace("-", "") : newGuidHidden.ToString();
 196    // }
 197
 198    async Task CopyMultipleGuids()
 0199    {
 0200        await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", NewGuids);
 0201    }
 202
 203    async Task DeleteMultipleGuids()
 1204    {
 1205        NewGuids = string.Empty;
 1206    }
 207
 208    #endregion Multiple
 209
 210}