-
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.
Feature/finish rework pb details frontend (#837)
* Rework pb details on DeleteConcentratorPage #833 * Rework pb details on CreateConcentratorPage #833 * Rework pb details on ConcentratorDetailPage #833 * Rework pb details on ConcentratorListPage #833 Rework pb details on ConcentratorListPage #833 * Add + update unit tests on ConcentratorDetailPageTests #833 * Add missing DialogService.Close() #833 * Add unit tests on CreateConcentratorPageTest #833 * Add unit tests on DeleteConcentratorPageTests #833 * Add unit tests on ConcentratorListPageTests #833 * Fix unit tests on ConcentratorDetailPageTests * Rework pb details on DeviceConfigurationListPage + Add unit tests #789 * Rework pb details on CreateDeviceConfigurationsPage + Add unit tests #789 * Rework pb details on DeviceConfigurationDetailPage + Add unit tests #789 * Fix unit test EdgeDeviceListPageShouldResetOnClickOnReset #827 * Rework pb details on DeleteDeviceConfiguration + Add unit tests #789 * Add unit test tests #833 #789
- Loading branch information
1 parent
68e67b2
commit 1d25ac9
Showing
17 changed files
with
1,232 additions
and
476 deletions.
There are no files selected for viewing
427 changes: 161 additions & 266 deletions
427
...ortal.Server.Tests.Unit/Pages/DeviceConfigurations/CreateDeviceConfigurationsPageTests.cs
Large diffs are not rendered by default.
Oops, something went wrong.
139 changes: 139 additions & 0 deletions
139
...Hub.Portal.Server.Tests.Unit/Pages/DeviceConfigurations/DeleteDeviceConfigurationTests.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,139 @@ | ||
// 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.LoRaWan.Concentrator | ||
{ | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Models.v10; | ||
using Helpers; | ||
using Bunit; | ||
using Client.Exceptions; | ||
using Client.Models; | ||
using Client.Pages.DeviceConfigurations; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Moq; | ||
using MudBlazor; | ||
using MudBlazor.Services; | ||
using NUnit.Framework; | ||
using RichardSzalay.MockHttp; | ||
|
||
[TestFixture] | ||
public class DeleteDeviceConfigurationTests : TestContextWrapper, IDisposable | ||
{ | ||
private MockHttpMessageHandler mockHttpClient; | ||
private MockRepository mockRepository; | ||
private DialogService dialogService; | ||
private Mock<ISnackbar> mockSnackbarService; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
TestContext = new Bunit.TestContext(); | ||
|
||
this.mockRepository = new MockRepository(MockBehavior.Strict); | ||
this.mockHttpClient = TestContext.Services.AddMockHttpClient(); | ||
|
||
this.mockSnackbarService = this.mockRepository.Create<ISnackbar>(); | ||
_ = TestContext.Services.AddSingleton(this.mockSnackbarService.Object); | ||
|
||
_ = TestContext.Services.AddMudServices(); | ||
_ = TestContext.Services.AddSingleton(new PortalSettings { IsLoRaSupported = true }); | ||
|
||
TestContext.JSInterop.Mode = JSRuntimeMode.Loose; | ||
this.mockHttpClient.AutoFlush = true; | ||
|
||
this.dialogService = TestContext.Services.GetService<IDialogService>() as DialogService; | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() => TestContext?.Dispose(); | ||
|
||
[Test] | ||
public async Task DeleteDeviceConfigurationShouldDeleteConfiguration() | ||
{ | ||
// Arrange | ||
var configurationId = Guid.NewGuid().ToString(); | ||
var configurationName = Guid.NewGuid().ToString(); | ||
|
||
_ = this.mockHttpClient | ||
.When(HttpMethod.Delete, $"/api/device-configurations/{configurationId}") | ||
.RespondText(string.Empty); | ||
|
||
var cut = RenderComponent<MudDialogProvider>(); | ||
|
||
var parameters = new DialogParameters | ||
{ | ||
{ | ||
"configurationId", configurationId | ||
}, | ||
{ | ||
"configurationName", configurationName | ||
} | ||
}; | ||
|
||
_ = this.mockSnackbarService.Setup(c => c.Add(It.IsAny<string>(), Severity.Success, null)).Returns((Snackbar)null); | ||
|
||
IDialogReference dialogReference = null; | ||
|
||
await cut.InvokeAsync(() => dialogReference = this.dialogService?.Show<DeleteDeviceConfiguration>(string.Empty, parameters)); | ||
cut.WaitForAssertion(() => cut.Find("#delete-device-configuration")); | ||
|
||
// Act | ||
cut.Find("#delete-device-configuration").Click(); | ||
var result = await dialogReference.Result; | ||
|
||
// Assert | ||
_ = result.Cancelled.Should().BeFalse(); | ||
cut.WaitForAssertion(() => this.mockHttpClient.VerifyNoOutstandingRequest()); | ||
cut.WaitForAssertion(() => this.mockHttpClient.VerifyNoOutstandingExpectation()); | ||
cut.WaitForAssertion(() => this.mockRepository.VerifyAll()); | ||
} | ||
|
||
[Test] | ||
public async Task DeleteConcentratorPageShouldProcessProblemDetailsExceptionWhenIssueOccursOnDeletingConcentrator() | ||
{ | ||
// Arrange | ||
var configurationId = Guid.NewGuid().ToString(); | ||
var configurationName = Guid.NewGuid().ToString(); | ||
|
||
_ = this.mockHttpClient | ||
.When(HttpMethod.Delete, $"/api/device-configurations/{configurationId}") | ||
.Throw(new ProblemDetailsException(new ProblemDetailsWithExceptionDetails())); | ||
|
||
var cut = RenderComponent<MudDialogProvider>(); | ||
|
||
var parameters = new DialogParameters | ||
{ | ||
{ | ||
"configurationId", configurationId | ||
}, | ||
{ | ||
"configurationName", configurationName | ||
} | ||
}; | ||
|
||
await cut.InvokeAsync(() => this.dialogService?.Show<DeleteDeviceConfiguration>(string.Empty, parameters)); | ||
cut.WaitForAssertion(() => cut.Find("#delete-device-configuration")); | ||
|
||
// Act | ||
cut.Find("#delete-device-configuration").Click(); | ||
|
||
// Assert | ||
cut.WaitForAssertion(() => this.mockHttpClient.VerifyNoOutstandingRequest()); | ||
cut.WaitForAssertion(() => this.mockHttpClient.VerifyNoOutstandingExpectation()); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
} | ||
} | ||
} |
Oops, something went wrong.