< 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: 254_14892742572
Line coverage
47%
Covered lines: 26
Uncovered lines: 29
Coverable lines: 55
Total lines: 198
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"></span> *@
 44            <input type="text" id="newGuid" name="newGuid" class="form-control" value="@newGuid" placeholder="00000000-0
 45            <input type="hidden" id="newGuidHidden" name="newGuidHidden" class="form-control" value="@newGuidHidden" pla
 46            <span class="input-group-btn">
 47                <button class="btn btn-info" type="button" id="btnGuidNewCreate" name="btnGuidNewCreate" @onclick="Gener
 48                <button class="btn btn-info" type="button" id="btnNewGuidCopy" name="btnNewGuidCopy" @onclick="CopyNewGu
 49            </span>
 50        </div>
 51    </div>
 52    <div class="row">
 53        <div class="form-check">
 54            <input class="form-check-input" type="checkbox" value="@removeDashesNew" id="chkRemoveDashes"
 055                   @onchange="@(eventArgs => { removeDashesNew = (bool)eventArgs.Value; RemoveDashesFromNewGuid(); })">
 56            <label class="form-check-label" for="chkRemoveDashes">
 57                Remove Dashes
 58            </label>
 59        </div>
 60    </div>
 61    <hr/>
 62    <div class="row">
 63        <label class="label-control">How many Guids do you wish to generate:</label>
 64        <div class="input-group">
 65            <div class="form-check">
 66                <input class="form-check-input" type="checkbox" value="" id="chkRemoveDashesMultiple">
 67                <label class="form-check-label" for="chkRemoveDashesMultiple">
 68                    Remove Dashes
 69                </label>
 70            </div>
 71        </div>
 72        <div class="input-group">
 73            <input type="number" class="form-control" id="guidCount" name="guidCount" @bind="@guidCount">
 74            <span class="input-group-btn">
 75                <button class="btn btn-success" type="button" id="btnGuidNewCreateMultiple" name="btnGuidNewCreateMultip
 76                        @onclick="GenerateMultipleGuids">Go!</button>
 77                <button class="btn btn-info" type="button" id="btnGuidMultipleCopy" name="btnGuidMultipleCopy"
 78                        @onclick="CopyMultipleGuids">
 79                    <i class="far fa-copy"></i>
 80                </button>
 81                <button class="btn btn-danger" type="button" id="btnGuidMultipleClear" name="btnGuidMultipleClear"
 82                        @onclick="DeleteMultipleGuids">
 83                    <i class="far fa-trash-alt"></i>
 84                </button>
 85            </span>
 86        </div>
 87    </div>
 88    <div class="row">
 89        <textarea id="guids" class="form-control" @bind="NewGuids" rows="@guidCount"></textarea>
 90    </div>
 91</div>
 92
 93@code {
 94
 95    private string newGuid;
 96    private Guid newGuidHidden;
 97    private int guidCount;
 98
 99    protected override async Task OnInitializedAsync()
 5100    {
 5101        var guid = Guid.NewGuid();
 5102        newGuid = guid.ToString();
 5103        newGuidHidden = guid;
 104
 5105        guidCount = 5;
 5106    }
 107
 108    #region Zero
 109
 5110    private Guid defaultZeroGuid = new Guid(); //"00000000000000000000000000000000" //"00000000-0000-0000-0000-000000000
 5111    private string zeroGuid = new Guid().ToString();
 112
 113    async Task CopyZeroGuid()
 0114    {
 0115        await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", zeroGuid);
 0116    }
 117
 5118    private bool removeDashes = false;
 119    void RemoveDashesFromZeroGuid()
 2120    {
 2121        zeroGuid = (removeDashes) ? defaultZeroGuid.ToString().Replace("-", "") : defaultZeroGuid.ToString();
 2122    }
 123
 5124    private bool addBraces = false;
 125    void AddBracesToZeroGuid()
 2126    {
 2127        zeroGuid = (addBraces) ? $"{{{zeroGuid}}}" : zeroGuid.Replace("{", "").Replace("}", "");
 2128    }
 129
 130    void Update()
 2131    {
 2132        RemoveDashesFromZeroGuid();
 2133        AddBracesToZeroGuid();
 2134    }
 135
 136    #endregion Zero
 137
 138    #region New
 139
 140    void GenerateNewGuid()
 0141    {
 0142        var guid = Guid.NewGuid();
 0143        newGuid = guid.ToString();
 0144        newGuidHidden = guid;
 0145        RemoveDashesFromNewGuid();
 0146    }
 147
 5148    private bool removeDashesNew = false;
 149    void RemoveDashesFromNewGuid()
 0150    {
 0151        newGuid = (removeDashesNew) ? newGuidHidden.ToString().Replace("-", "") : newGuidHidden.ToString();
 152        //removeDashes = !removeDashes;
 0153    }
 154
 155    async Task CopyNewGuid()
 0156    {
 0157        await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", newGuid);
 0158    }
 159
 160    #endregion New
 161
 162    #region Multiple
 163
 164    string NewGuids;
 165
 166    async Task GenerateMultipleGuids()
 0167    {
 0168        NewGuids = string.Empty; //Checkbox to append?
 169
 0170        StringBuilder builder = new StringBuilder();
 0171        for (int i = 0; i < guidCount; i++)
 0172        {
 0173            var guid = System.Guid.NewGuid().ToString() + System.Environment.NewLine;
 174
 175            //if (RemoveDashesMultiple)
 176            ///{
 177            //    guid = Regex.Replace(guid, @"\-", "");
 178            //}
 179
 0180            builder.Append(guid);
 0181        }
 182
 0183        NewGuids = builder.ToString();
 0184    }
 185
 186    async Task CopyMultipleGuids()
 0187    {
 0188        await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", NewGuids);
 0189    }
 190
 191    async Task DeleteMultipleGuids()
 1192    {
 1193        NewGuids = string.Empty;
 1194    }
 195
 196    #endregion Multiple
 197
 198}