diff --git a/src/AzureIoTHub.Portal.Client/Pages/Devices/DeleteDevicePage.razor b/src/AzureIoTHub.Portal.Client/Pages/Devices/DeleteDevicePage.razor
index b161dbc7b..e223ebb28 100644
--- a/src/AzureIoTHub.Portal.Client/Pages/Devices/DeleteDevicePage.razor
+++ b/src/AzureIoTHub.Portal.Client/Pages/Devices/DeleteDevicePage.razor
@@ -1,5 +1,6 @@
@inject ISnackbar Snackbar
@inject IDeviceClientService DeviceClientService
+@inject ILoRaWanDeviceClientService LoRaWanDeviceClientService
@@ -16,17 +17,18 @@
Cancel
- Delete
+ Delete
@code {
[CascadingParameter]
public Error Error {get; set;}
-
+
[CascadingParameter] MudDialogInstance MudDialog { get; set; }
[Parameter] public string deviceID { get; set; }
[Parameter] public string deviceName { get; set; }
+ [Parameter] public bool IsLoRaWan { get; set; }
void Submit() => MudDialog.Close(DialogResult.Ok(true));
void Cancel() => MudDialog.Cancel();
@@ -39,7 +41,14 @@
{
try
{
- await DeviceClientService.DeleteDevice(deviceID);
+ if (IsLoRaWan)
+ {
+ await LoRaWanDeviceClientService.DeleteDevice(deviceID);
+ }
+ else
+ {
+ await DeviceClientService.DeleteDevice(deviceID);
+ }
Snackbar.Add($"Device {deviceName} has been successfully deleted!", Severity.Success);
}
diff --git a/src/AzureIoTHub.Portal.Client/Pages/Devices/DeviceDetailPage.razor b/src/AzureIoTHub.Portal.Client/Pages/Devices/DeviceDetailPage.razor
index ea7d3cd48..4cb7560fe 100644
--- a/src/AzureIoTHub.Portal.Client/Pages/Devices/DeviceDetailPage.razor
+++ b/src/AzureIoTHub.Portal.Client/Pages/Devices/DeviceDetailPage.razor
@@ -399,7 +399,8 @@
var parameters = new DialogParameters
{
{"deviceID", Device.DeviceID},
- {"deviceName", Device.DeviceName}
+ {"deviceName", Device.DeviceName},
+ {"IsLoRaWan", IsLoRa}
};
var result = await DialogService.Show("Confirm Deletion", parameters).Result;
diff --git a/src/AzureIoTHub.Portal.Client/Pages/Devices/DeviceListPage.razor b/src/AzureIoTHub.Portal.Client/Pages/Devices/DeviceListPage.razor
index 7cf38daa5..de18d4eb5 100644
--- a/src/AzureIoTHub.Portal.Client/Pages/Devices/DeviceListPage.razor
+++ b/src/AzureIoTHub.Portal.Client/Pages/Devices/DeviceListPage.razor
@@ -323,6 +323,8 @@
var parameters = new DialogParameters();
parameters.Add("deviceID", device.DeviceID);
parameters.Add("deviceName", device.DeviceName);
+ parameters.Add("IsLoRaWan", device.SupportLoRaFeatures);
+
var result = await DialogService.Show("Confirm Deletion", parameters).Result;
if (result.Cancelled)
diff --git a/src/AzureIoTHub.Portal.Client/Services/ILoRaWanDeviceClientService.cs b/src/AzureIoTHub.Portal.Client/Services/ILoRaWanDeviceClientService.cs
index d405c9d1c..92eb423b8 100644
--- a/src/AzureIoTHub.Portal.Client/Services/ILoRaWanDeviceClientService.cs
+++ b/src/AzureIoTHub.Portal.Client/Services/ILoRaWanDeviceClientService.cs
@@ -15,6 +15,8 @@ public interface ILoRaWanDeviceClientService
Task UpdateDevice(LoRaDeviceDetails device);
+ Task DeleteDevice(string deviceId);
+
Task ExecuteCommand(string deviceId, string commandId);
Task GetGatewayIdList();
diff --git a/src/AzureIoTHub.Portal.Client/Services/LoRaWanDeviceClientService.cs b/src/AzureIoTHub.Portal.Client/Services/LoRaWanDeviceClientService.cs
index bb3102027..8383e4cab 100644
--- a/src/AzureIoTHub.Portal.Client/Services/LoRaWanDeviceClientService.cs
+++ b/src/AzureIoTHub.Portal.Client/Services/LoRaWanDeviceClientService.cs
@@ -33,6 +33,11 @@ public Task UpdateDevice(LoRaDeviceDetails device)
return this.http.PutAsJsonAsync("api/lorawan/devices", device);
}
+ public Task DeleteDevice(string deviceId)
+ {
+ return this.http.DeleteAsync($"api/lorawan/devices/{deviceId}");
+ }
+
public Task ExecuteCommand(string deviceId, string commandId)
{
return this.http.PostAsJsonAsync($"api/lorawan/devices/{deviceId}/_command/{commandId}", string.Empty);
diff --git a/src/AzureIoTHub.Portal.Tests.Unit/Client/Pages/Devices/DeleteDevicePageTests.cs b/src/AzureIoTHub.Portal.Tests.Unit/Client/Pages/Devices/DeleteDevicePageTests.cs
new file mode 100644
index 000000000..0b3216dfa
--- /dev/null
+++ b/src/AzureIoTHub.Portal.Tests.Unit/Client/Pages/Devices/DeleteDevicePageTests.cs
@@ -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 mockDeviceClientService;
+ private Mock mockLoRaWanDeviceClientService;
+
+ public override void Setup()
+ {
+ base.Setup();
+
+ this.mockDeviceClientService = MockRepository.Create();
+ this.mockLoRaWanDeviceClientService = MockRepository.Create();
+
+ _ = 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();
+ var service = Services.GetService() as DialogService;
+
+ var parameters = new DialogParameters
+ {
+ {"deviceID", deviceId},
+ };
+
+ // Act
+ await cut.InvokeAsync(() => service?.Show(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();
+ var service = Services.GetService() as DialogService;
+
+ var parameters = new DialogParameters
+ {
+ {"deviceID", deviceId},
+ {"IsLoRaWan", true}
+ };
+
+ // Act
+ await cut.InvokeAsync(() => service?.Show(string.Empty, parameters));
+ cut.WaitForElement("#delete-device").Click();
+
+ // Assert
+ cut.WaitForAssertion(() => MockRepository.VerifyAll());
+ }
+ }
+}
diff --git a/src/AzureIoTHub.Portal.Tests.Unit/Client/Services/LoRaWanDeviceClientServiceTests.cs b/src/AzureIoTHub.Portal.Tests.Unit/Client/Services/LoRaWanDeviceClientServiceTests.cs
index d758909bd..f852ee310 100644
--- a/src/AzureIoTHub.Portal.Tests.Unit/Client/Services/LoRaWanDeviceClientServiceTests.cs
+++ b/src/AzureIoTHub.Portal.Tests.Unit/Client/Services/LoRaWanDeviceClientServiceTests.cs
@@ -137,5 +137,22 @@ public async Task GetGatewayIdListShouldReturnGatewayIdList()
MockHttpClient.VerifyNoOutstandingRequest();
MockHttpClient.VerifyNoOutstandingExpectation();
}
+
+ [Test]
+ public async Task DeleteDevice_ExistingDevice_DevicDeleted()
+ {
+ // Arrange
+ var deviceId = Fixture.Create();
+
+ _ = MockHttpClient.When(HttpMethod.Delete, $"/api/lorawan/devices/{deviceId}")
+ .Respond(HttpStatusCode.NoContent);
+
+ // Act
+ await this.loRaWanDeviceClientService.DeleteDevice(deviceId);
+
+ // Assert
+ MockHttpClient.VerifyNoOutstandingRequest();
+ MockHttpClient.VerifyNoOutstandingExpectation();
+ }
}
}