-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hide symmetric keys on connection page + Create Copy to Clipboard but…
…ton (#382) * not display Symmetric key * Use Clipboard service to write to clipboard * Add unit test to Clipboard Service * Not_display_Symmetric_key_suite * not_display_symmetric_key_suite2 Co-authored-by: crib <[email protected]> Co-authored-by: Beaugrand, Kevin <[email protected]>
- Loading branch information
1 parent
38489f1
commit 0c6efa6
Showing
5 changed files
with
88 additions
and
9 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/AzureIoTHub.Portal.Server.Tests.Unit/Services/ClipboardServiceTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using AzureIoTHub.Portal.Client.Services; | ||
using Microsoft.JSInterop; | ||
using Moq; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Linq; | ||
using Microsoft.JSInterop.Infrastructure; | ||
|
||
namespace AzureIoTHub.Portal.Server.Tests.Unit.Services | ||
{ | ||
[TestFixture] | ||
public class ClipboardServiceTests | ||
{ | ||
private MockRepository mockRepository; | ||
|
||
private Mock<IJSRuntime> mockJSRuntime; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
this.mockRepository = new MockRepository(MockBehavior.Strict); | ||
|
||
this.mockJSRuntime = this.mockRepository.Create<IJSRuntime>(); | ||
} | ||
|
||
private ClipboardService CreateService() | ||
{ | ||
return new ClipboardService( | ||
this.mockJSRuntime.Object); | ||
} | ||
|
||
[Test] | ||
public void WriteTextAsync_StateUnderTest_ExpectedBehavior() | ||
{ | ||
// Arrange | ||
var service = this.CreateService(); | ||
string text = Guid.NewGuid().ToString(); | ||
|
||
// Act | ||
var result = service.WriteTextAsync(text); | ||
|
||
// Assert | ||
this.mockJSRuntime.Verify(c => c.InvokeAsync<IJSVoidResult>( | ||
It.Is<string>(x => x == "navigator.clipboard.writeText"), | ||
It.Is<object?[]>(x => x.Single().ToString() == text)), Times.Once); | ||
|
||
this.mockRepository.VerifyAll(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/AzureIoTHub.Portal/Client/Services/ClipboardService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) CGI France. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace AzureIoTHub.Portal.Client.Services | ||
{ | ||
using Microsoft.JSInterop; | ||
using System.Threading.Tasks; | ||
|
||
public class ClipboardService | ||
{ | ||
private readonly IJSRuntime _jsRuntime; | ||
|
||
public ClipboardService(IJSRuntime jsRuntime) | ||
{ | ||
_jsRuntime = jsRuntime; | ||
} | ||
|
||
public ValueTask WriteTextAsync(string text) | ||
{ | ||
return _jsRuntime.InvokeVoidAsync("navigator.clipboard.writeText", text); | ||
} | ||
} | ||
} |