-
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.
Browse files
Browse the repository at this point in the history
* Fix missing delete lorawan device on client side #1592 * Add unit test on DeleteDevicePage
- Loading branch information
1 parent
c741cd8
commit 517fade
Showing
7 changed files
with
131 additions
and
4 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
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
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
91 changes: 91 additions & 0 deletions
91
src/AzureIoTHub.Portal.Tests.Unit/Client/Pages/Devices/DeleteDevicePageTests.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,91 @@ | ||
// 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.Devices | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using AzureIoTHub.Portal.Client.Pages.Devices; | ||
using AzureIoTHub.Portal.Client.Services; | ||
using AzureIoTHub.Portal.Models.v10; | ||
using AzureIoTHub.Portal.Tests.Unit.UnitTests.Bases; | ||
using Bunit; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Moq; | ||
using MudBlazor; | ||
using NUnit.Framework; | ||
|
||
[TestFixture] | ||
public class DeleteDevicePageTests : BlazorUnitTest | ||
{ | ||
private Mock<IDeviceClientService> mockDeviceClientService; | ||
private Mock<ILoRaWanDeviceClientService> mockLoRaWanDeviceClientService; | ||
|
||
public override void Setup() | ||
{ | ||
base.Setup(); | ||
|
||
this.mockDeviceClientService = MockRepository.Create<IDeviceClientService>(); | ||
this.mockLoRaWanDeviceClientService = MockRepository.Create<ILoRaWanDeviceClientService>(); | ||
|
||
_ = Services.AddSingleton(this.mockDeviceClientService.Object); | ||
_ = Services.AddSingleton(this.mockLoRaWanDeviceClientService.Object); | ||
} | ||
|
||
[Test] | ||
public async Task DeleteDevice_NonLoRaDevice_DeviceDeleted() | ||
{ | ||
// Arrange | ||
var deviceId = Guid.NewGuid().ToString(); | ||
|
||
_ = this.mockDeviceClientService.Setup(service => service.DeleteDevice(deviceId)) | ||
.Returns(Task.CompletedTask); | ||
|
||
var cut = RenderComponent<MudDialogProvider>(); | ||
var service = Services.GetService<IDialogService>() as DialogService; | ||
|
||
var parameters = new DialogParameters | ||
{ | ||
{"deviceID", deviceId}, | ||
}; | ||
|
||
// Act | ||
await cut.InvokeAsync(() => service?.Show<DeleteDevicePage>(string.Empty, parameters)); | ||
cut.WaitForElement("#delete-device").Click(); | ||
|
||
// Assert | ||
cut.WaitForAssertion(() => MockRepository.VerifyAll()); | ||
} | ||
|
||
[Test] | ||
public async Task DeleteDevice_LoRaDevice_LoRaDeviceDeleted() | ||
{ | ||
// Arrange | ||
var deviceId = Guid.NewGuid().ToString(); | ||
|
||
_ = this.mockLoRaWanDeviceClientService.Setup(service => service.DeleteDevice(deviceId)) | ||
.Returns(Task.CompletedTask); | ||
|
||
var cut = RenderComponent<MudDialogProvider>(); | ||
var service = Services.GetService<IDialogService>() as DialogService; | ||
|
||
var parameters = new DialogParameters | ||
{ | ||
{"deviceID", deviceId}, | ||
{"IsLoRaWan", true} | ||
}; | ||
|
||
// Act | ||
await cut.InvokeAsync(() => service?.Show<DeleteDevicePage>(string.Empty, parameters)); | ||
cut.WaitForElement("#delete-device").Click(); | ||
|
||
// Assert | ||
cut.WaitForAssertion(() => 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