-
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/1118_-_Select the edge model at device creation (#1125)
* create edge device with model selection * resolve #1118 select edge model when creating a device * redirect to edge device list after creating edge device * IoTEdgeDevice is now enable by default * isEnable is true by default * add of tags in edge device detail * fix image url * fix unit test * fix error with get enrollment credential * add new test on edgeDeviceDetailPage * fix unit test error * add new test in createEdgeDevicePage
- Loading branch information
Showing
23 changed files
with
4,020 additions
and
336 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
79 changes: 0 additions & 79 deletions
79
src/AzureIoTHub.Portal.Tests.Unit/Client/Pages/EdgeDevices/CreateEdgeDeviceDialogTests.cs
This file was deleted.
Oops, something went wrong.
145 changes: 145 additions & 0 deletions
145
src/AzureIoTHub.Portal.Tests.Unit/Client/Pages/EdgeDevices/CreateEdgeDevicePageTest.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,145 @@ | ||
// 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.Tests.Unit.Client.Pages.EdgeDevices | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using AzureIoTHub.Portal.Client.Exceptions; | ||
using AzureIoTHub.Portal.Client.Models; | ||
using AzureIoTHub.Portal.Client.Pages.EdgeDevices; | ||
using AzureIoTHub.Portal.Client.Services; | ||
using AzureIoTHub.Portal.Models.v10; | ||
using AzureIoTHub.Portal.Tests.Unit.UnitTests.Bases; | ||
using Bunit; | ||
using Bunit.TestDoubles; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Moq; | ||
using MudBlazor; | ||
using NUnit.Framework; | ||
|
||
[TestFixture] | ||
public class CreateEdgeDevicePageTest : BlazorUnitTest | ||
{ | ||
private Mock<ISnackbar> mockSnackbarService; | ||
private Mock<IEdgeDeviceClientService> mockEdgeDeviceClientService; | ||
private Mock<IEdgeModelClientService> mockIEdgeModelClientService; | ||
private Mock<IDeviceTagSettingsClientService> mockDeviceTagSettingsClientService; | ||
|
||
private FakeNavigationManager mockNavigationManager; | ||
|
||
public override void Setup() | ||
{ | ||
base.Setup(); | ||
|
||
this.mockSnackbarService = MockRepository.Create<ISnackbar>(); | ||
this.mockEdgeDeviceClientService = MockRepository.Create<IEdgeDeviceClientService>(); | ||
this.mockIEdgeModelClientService = MockRepository.Create<IEdgeModelClientService>(); | ||
this.mockDeviceTagSettingsClientService = MockRepository.Create<IDeviceTagSettingsClientService>(); | ||
|
||
_ = Services.AddSingleton(this.mockEdgeDeviceClientService.Object); | ||
_ = Services.AddSingleton(this.mockIEdgeModelClientService.Object); | ||
_ = Services.AddSingleton(this.mockDeviceTagSettingsClientService.Object); | ||
_ = Services.AddSingleton(this.mockSnackbarService.Object); | ||
|
||
this.mockNavigationManager = Services.GetRequiredService<FakeNavigationManager>(); | ||
} | ||
|
||
[Test] | ||
public async Task SaveShouldCreateEdgeDeviceAndRedirectToEdgeDeviceList() | ||
{ | ||
// Arrange | ||
var edgeModel = new IoTEdgeModelListItem(){ Name = "model01", ModelId = "model01"}; | ||
|
||
var edgeDevice = new IoTEdgeDevice() | ||
{ | ||
DeviceId = Guid.NewGuid().ToString() | ||
}; | ||
|
||
_ = this.mockIEdgeModelClientService.Setup(x => x.GetIoTEdgeModelList()) | ||
.ReturnsAsync(new List<IoTEdgeModelListItem>() { edgeModel }); | ||
|
||
_ = this.mockDeviceTagSettingsClientService.Setup(x => x.GetDeviceTags()) | ||
.ReturnsAsync(new List<DeviceTag>() | ||
{ | ||
new DeviceTag(){ Name = "tag01", Required = true} | ||
}); | ||
|
||
_ = this.mockEdgeDeviceClientService | ||
.Setup(x => x.CreateDevice(It.Is<IoTEdgeDevice>(c => c.DeviceId.Equals(edgeDevice.DeviceId, StringComparison.Ordinal)))) | ||
.Returns(Task.CompletedTask); | ||
|
||
_ = this.mockSnackbarService.Setup(c => c.Add(It.IsAny<string>(), Severity.Success, null)).Returns(value: null); | ||
|
||
var cut = RenderComponent<CreateEdgeDevicePage>(); | ||
var saveButton = cut.WaitForElement("#SaveButton"); | ||
|
||
cut.WaitForElement($"#{nameof(IoTEdgeDevice.DeviceName)}").Change("testName"); | ||
cut.WaitForElement($"#{nameof(IoTEdgeDevice.DeviceId)}").Change(edgeDevice.DeviceId); | ||
cut.WaitForElement($"#tag01").Change("testTag01"); | ||
await cut.Instance.ChangeModel(edgeModel); | ||
|
||
saveButton.Click(); | ||
|
||
// Assert | ||
cut.WaitForAssertion(() => MockRepository.VerifyAll()); | ||
cut.WaitForAssertion(() => this.mockNavigationManager.Uri.Should().EndWith("/edge/devices")); | ||
} | ||
|
||
[Test] | ||
public async Task CreateEdgeDevicePageSaveShouldProcessProblemDetailsExceptionWhenIssueOccurs() | ||
{ | ||
// Arrange | ||
var edgeModel = new IoTEdgeModelListItem(){ Name = "model01", ModelId = "model01"}; | ||
|
||
var edgeDevice = new IoTEdgeDevice() | ||
{ | ||
DeviceId = Guid.NewGuid().ToString() | ||
}; | ||
|
||
_ = this.mockIEdgeModelClientService.Setup(x => x.GetIoTEdgeModelList()) | ||
.ReturnsAsync(new List<IoTEdgeModelListItem>() { edgeModel }); | ||
|
||
_ = this.mockDeviceTagSettingsClientService.Setup(x => x.GetDeviceTags()) | ||
.ReturnsAsync(new List<DeviceTag>() | ||
{ | ||
new DeviceTag(){ Name = "tag01", Required = true} | ||
}); | ||
|
||
_ = this.mockEdgeDeviceClientService | ||
.Setup(x => x.CreateDevice(It.Is<IoTEdgeDevice>(c => c.DeviceId.Equals(edgeDevice.DeviceId, StringComparison.Ordinal)))) | ||
.ThrowsAsync(new ProblemDetailsException(new ProblemDetailsWithExceptionDetails())); | ||
|
||
var cut = RenderComponent<CreateEdgeDevicePage>(); | ||
var saveButton = cut.WaitForElement("#SaveButton"); | ||
|
||
cut.WaitForElement($"#{nameof(IoTEdgeDevice.DeviceName)}").Change("testName"); | ||
cut.WaitForElement($"#{nameof(IoTEdgeDevice.DeviceId)}").Change(edgeDevice.DeviceId); | ||
cut.WaitForElement($"#tag01").Change("testTag01"); | ||
await cut.Instance.ChangeModel(edgeModel); | ||
|
||
saveButton.Click(); | ||
|
||
// Assert | ||
cut.WaitForAssertion(() => MockRepository.VerifyAll()); | ||
//cut.WaitForAssertion(() => this.mockNavigationManager.Uri.Should().EndWith("/edge/devices")); | ||
} | ||
|
||
[Test] | ||
public void WhenAnErrorOccurInOnInitializedAsyncShouldProcessProblemDetailsException() | ||
{ | ||
// Arrange | ||
_ = this.mockIEdgeModelClientService.Setup(x => x.GetIoTEdgeModelList()) | ||
.ThrowsAsync(new ProblemDetailsException(new ProblemDetailsWithExceptionDetails())); | ||
|
||
// Act | ||
var cut = RenderComponent<CreateEdgeDevicePage>(); | ||
|
||
// Assert | ||
cut.WaitForAssertion(() => cut.Markup.Should().NotBeNullOrEmpty()); | ||
cut.WaitForAssertion(() => MockRepository.VerifyAll()); | ||
} | ||
} | ||
} |
Oops, something went wrong.