< 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: 231_14069517506
Line coverage
47%
Covered lines: 26
Uncovered lines: 29
Coverable lines: 55
Total lines: 199
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-check form-check-inline">
 25            <input class="form-check-input" type="checkbox" value="@removeDashes" id="chkRemoveDashesZero"
 426                   @onchange="@(eventArgs => { removeDashes = (bool)eventArgs.Value; Update(); })"/>
 27            <label class="form-check-label" for="chkRemoveDashesZero">
 28                Remove Dashes
 29            </label>
 30        </div>
 31        &nbsp;|&nbsp;
 32        <div class="form-check form-check-inline">
 33            <input class="form-check-input" type="checkbox" value="@addBraces" id="chkAddBracesZero"
 434                   @onchange="@(eventArgs => { addBraces = (bool)eventArgs.Value; Update(); })"/>
 35            <label class="form-check-label" for="chkAddBracesZero">
 36                Add Braces
 37            </label>
 38        </div>
 39    </div>
 40    <div class="row">
 41        <label class="label-control">New:</label>
 42        <div class="input-group">
 43            <span class="input-group-btn">
 44                <button class="btn btn-info" type="button" id="btnGuidNewCreate" name="btnGuidNewCreate" @onclick="Gener
 45            </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-info" type="button" id="btnNewGuidCopy" name="btnNewGuidCopy" @onclick="CopyNewGu
 50            </span>
 51        </div>
 52    </div>
 53    <div class="row">
 54        <div class="form-check">
 55            <input class="form-check-input" type="checkbox" value="@removeDashesNew" id="chkRemoveDashes"
 056                   @onchange="@(eventArgs => { removeDashesNew = (bool)eventArgs.Value; RemoveDashesFromNewGuid(); })">
 57            <label class="form-check-label" for="chkRemoveDashes">
 58                Remove Dashes
 59            </label>
 60        </div>
 61    </div>
 62    <hr/>
 63    <div class="row">
 64        <label class="label-control">How many Guids do you wish to generate:</label>
 65        <div class="input-group">
 66            <div class="form-check">
 67                <input class="form-check-input" type="checkbox" value="" id="chkRemoveDashesMultiple">
 68                <label class="form-check-label" for="chkRemoveDashesMultiple">
 69                    Remove Dashes
 70                </label>
 71            </div>
 72        </div>
 73        <div class="input-group">
 74            <input type="number" class="form-control" id="guidCount" name="guidCount" @bind="@guidCount">
 75            <span class="input-group-btn">
 76                <button class="btn btn-success" type="button" id="btnGuidNewCreateMultiple" name="btnGuidNewCreateMultip
 77                        @onclick="GenerateMultipleGuids">Go!</button>
 78                <button class="btn btn-info" type="button" id="btnGuidMultipleCopy" name="btnGuidMultipleCopy"
 79                        @onclick="CopyMultipleGuids">
 80                    <i class="far fa-copy"></i>
 81                </button>
 82                <button class="btn btn-danger" type="button" id="btnGuidMultipleClear" name="btnGuidMultipleClear"
 83                        @onclick="DeleteMultipleGuids">
 84                    <i class="far fa-trash-alt"></i>
 85                </button>
 86            </span>
 87        </div>
 88    </div>
 89    <div class="row">
 90        <textarea id="guids" class="form-control" @bind="NewGuids"></textarea>
 91    </div>
 92</div>
 93
 94@code {
 95
 96    private string newGuid;
 97    private Guid newGuidHidden;
 98    private int guidCount;
 99
 100    protected override async Task OnInitializedAsync()
 5101    {
 5102        var guid = Guid.NewGuid();
 5103        newGuid = guid.ToString();
 5104        newGuidHidden = guid;
 105
 5106        guidCount = 5;
 5107    }
 108
 109    #region Zero
 110
 5111    private Guid defaultZeroGuid = new Guid(); //"00000000000000000000000000000000" //"00000000-0000-0000-0000-000000000
 5112    private string zeroGuid = new Guid().ToString();
 113
 114    async Task CopyZeroGuid()
 0115    {
 0116        await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", zeroGuid);
 0117    }
 118
 5119    private bool removeDashes = false;
 120    void RemoveDashesFromZeroGuid()
 2121    {
 2122        zeroGuid = (removeDashes) ? defaultZeroGuid.ToString().Replace("-", "") : defaultZeroGuid.ToString();
 2123    }
 124
 5125    private bool addBraces = false;
 126    void AddBracesToZeroGuid()
 2127    {
 2128        zeroGuid = (addBraces) ? $"{{{zeroGuid}}}" : zeroGuid.Replace("{", "").Replace("}", "");
 2129    }
 130
 131    void Update()
 2132    {
 2133        RemoveDashesFromZeroGuid();
 2134        AddBracesToZeroGuid();
 2135    }
 136
 137    #endregion Zero
 138
 139    #region New
 140
 141    void GenerateNewGuid()
 0142    {
 0143        var guid = Guid.NewGuid();
 0144        newGuid = guid.ToString();
 0145        newGuidHidden = guid;
 0146        RemoveDashesFromNewGuid();
 0147    }
 148
 5149    private bool removeDashesNew = false;
 150    void RemoveDashesFromNewGuid()
 0151    {
 0152        newGuid = (removeDashesNew) ? newGuidHidden.ToString().Replace("-", "") : newGuidHidden.ToString();
 153        //removeDashes = !removeDashes;
 0154    }
 155
 156    async Task CopyNewGuid()
 0157    {
 0158        await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", newGuid);
 0159    }
 160
 161    #endregion New
 162
 163    #region Multiple
 164
 165    string NewGuids;
 166
 167    async Task GenerateMultipleGuids()
 0168    {
 0169        NewGuids = string.Empty; //Checkbox to append?
 170
 0171        StringBuilder builder = new StringBuilder();
 0172        for (int i = 0; i < guidCount; i++)
 0173        {
 0174            var guid = System.Guid.NewGuid().ToString() + System.Environment.NewLine;
 175
 176            //if (RemoveDashesMultiple)
 177            ///{
 178            //    guid = Regex.Replace(guid, @"\-", "");
 179            //}
 180
 0181            builder.Append(guid);
 0182        }
 183
 0184        NewGuids = builder.ToString();
 0185    }
 186
 187    async Task CopyMultipleGuids()
 0188    {
 0189        await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", NewGuids);
 0190    }
 191
 192    async Task DeleteMultipleGuids()
 1193    {
 1194        NewGuids = string.Empty;
 1195    }
 196
 197    #endregion Multiple
 198
 199}