-
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.
Rework problem details on device views (#774)
* Rework pb details exceptions on devices listing #765 * Rework pb details exceptions on ConnectionStringDialog #765 * Rework pb details exceptions on DeleteDevicePage #765 * Rework pb details exceptions on DeviceDetailPage #765 * Rework pb details exceptions on CreateDevicePage #765 * Rework pb details exceptions on EditLoraDevice #765 * Add unit tests on pb details on devices views * Add unit tests on ConnectionStringDialog * Add mac os gitignore * Update ConnectionStringDialogTests.cs Remove OnClickCancelConnectionStringDialogMustBeCanceled unit test * Rework pb details exceptions on devices listing #765 * Rework pb details exceptions on ConnectionStringDialog #765 * Rework pb details exceptions on DeleteDevicePage #765 * Rework pb details exceptions on DeviceDetailPage #765 * Rework pb details exceptions on CreateDevicePage #765 * Rework pb details exceptions on EditLoraDevice #765 * Add unit tests on pb details on devices views * Add unit tests on ConnectionStringDialog * Add mac os gitignore * Update ConnectionStringDialogTests.cs Remove OnClickCancelConnectionStringDialogMustBeCanceled unit test
- Loading branch information
1 parent
c8931a0
commit 002b61e
Showing
11 changed files
with
706 additions
and
159 deletions.
There are no files selected for viewing
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
134 changes: 134 additions & 0 deletions
134
src/AzureIoTHub.Portal.Server.Tests.Unit/Pages/Devices/ConnectionStringDialogTests.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,134 @@ | ||
// 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.Server.Tests.Unit.Pages | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Bunit; | ||
using Client.Exceptions; | ||
using Client.Models; | ||
using Client.Pages.Devices; | ||
using Client.Services; | ||
using FluentAssertions; | ||
using Helpers; | ||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.JSInterop; | ||
using Models.v10; | ||
using Moq; | ||
using MudBlazor; | ||
using MudBlazor.Interop; | ||
using MudBlazor.Services; | ||
using NUnit.Framework; | ||
using RichardSzalay.MockHttp; | ||
|
||
[TestFixture] | ||
public class ConnectionStringDialogTests : IDisposable | ||
{ | ||
private Bunit.TestContext testContext; | ||
private MockHttpMessageHandler mockHttpClient; | ||
|
||
private MockRepository mockRepository; | ||
private Mock<IJSRuntime> mockJSRuntime; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
this.testContext = new Bunit.TestContext(); | ||
|
||
this.mockRepository = new MockRepository(MockBehavior.Strict); | ||
this.mockJSRuntime = this.mockRepository.Create<IJSRuntime>(); | ||
this.mockHttpClient = this.testContext.Services | ||
.AddMockHttpClient(); | ||
|
||
_ = this.testContext.Services.AddSingleton(new ClipboardService(this.mockJSRuntime.Object)); | ||
|
||
_ = this.testContext.Services.AddMudServices(); | ||
|
||
_ = this.testContext.JSInterop.SetupVoid("mudKeyInterceptor.connect", _ => true); | ||
_ = this.testContext.JSInterop.SetupVoid("mudPopover.connect", _ => true); | ||
_ = this.testContext.JSInterop.SetupVoid("Blazor._internal.InputFile.init", _ => true); | ||
_ = this.testContext.JSInterop.Setup<BoundingClientRect>("mudElementRef.getBoundingClientRect", _ => true); | ||
_ = this.testContext.JSInterop.Setup<IEnumerable<BoundingClientRect>>("mudResizeObserver.connect", _ => true); | ||
|
||
this.mockHttpClient.AutoFlush = true; | ||
} | ||
|
||
private IRenderedComponent<TComponent> RenderComponent<TComponent>(params ComponentParameter[] parameters) | ||
where TComponent : IComponent | ||
{ | ||
return this.testContext.RenderComponent<TComponent>(parameters); | ||
} | ||
|
||
[Test] | ||
public async Task ConnectionStringDialogMustBeRenderedOnShow() | ||
{ | ||
// Arrange | ||
var deviceId = Guid.NewGuid().ToString(); | ||
|
||
_ = this.mockHttpClient.When(HttpMethod.Get, $"/api/devices/{deviceId}/credentials") | ||
.RespondJson(new EnrollmentCredentials()); | ||
|
||
var cut = RenderComponent<MudDialogProvider>(); | ||
var service = this.testContext.Services.GetService<IDialogService>() as DialogService; | ||
|
||
var parameters = new DialogParameters | ||
{ | ||
{ | ||
"deviceId", deviceId | ||
} | ||
}; | ||
|
||
// Act | ||
await cut.InvokeAsync(() => service?.Show<ConnectionStringDialog>(string.Empty, parameters)); | ||
|
||
// Assert | ||
_ = cut.Find("div.mud-dialog-container").Should().NotBeNull(); | ||
this.mockHttpClient.VerifyNoOutstandingExpectation(); | ||
} | ||
|
||
[Test] | ||
public async Task OnInitializedAsyncShouldProcessProblemDetailsExceptionWhenIssueOccursOnGettingCredentials() | ||
{ | ||
// Arrange | ||
var deviceId = Guid.NewGuid().ToString(); | ||
|
||
_ = this.mockHttpClient.When(HttpMethod.Get, $"/api/devices/{deviceId}/credentials") | ||
.Throw(new ProblemDetailsException(new ProblemDetailsWithExceptionDetails())); | ||
|
||
var cut = RenderComponent<MudDialogProvider>(); | ||
var service = this.testContext.Services.GetService<IDialogService>() as DialogService; | ||
|
||
var parameters = new DialogParameters | ||
{ | ||
{ | ||
"deviceId", deviceId | ||
} | ||
}; | ||
|
||
IDialogReference dialogReference = null; | ||
|
||
// Act | ||
await cut.InvokeAsync(() => dialogReference = service?.Show<ConnectionStringDialog>(string.Empty, parameters)); | ||
|
||
var result = await dialogReference.Result; | ||
|
||
// Assert | ||
_ = result.Cancelled.Should().BeFalse(); | ||
this.mockHttpClient.VerifyNoOutstandingExpectation(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
} | ||
} | ||
} |
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
Oops, something went wrong.