diff --git a/src/AzureIoTHub.Portal.Server.Tests.Unit/Controllers/v1.0/LoRaWAN/LoRaWANConcentratorsControllerTest.cs b/src/AzureIoTHub.Portal.Server.Tests.Unit/Controllers/v1.0/LoRaWAN/LoRaWANConcentratorsControllerTest.cs index c26736dc0..7cf1e7f60 100644 --- a/src/AzureIoTHub.Portal.Server.Tests.Unit/Controllers/v1.0/LoRaWAN/LoRaWANConcentratorsControllerTest.cs +++ b/src/AzureIoTHub.Portal.Server.Tests.Unit/Controllers/v1.0/LoRaWAN/LoRaWANConcentratorsControllerTest.cs @@ -32,7 +32,6 @@ public class LoRaWANConcentratorsControllerTest private Mock mockDeviceService; private Mock mockRouterConfigManager; private Mock mockConcentratorTwinMapper; - private Mock mockConfigHandler; private Mock mockUrlHelper; [SetUp] @@ -43,7 +42,6 @@ public void SetUp() this.mockDeviceService = this.mockRepository.Create(); this.mockRouterConfigManager = this.mockRepository.Create(); this.mockConcentratorTwinMapper = this.mockRepository.Create(); - this.mockConfigHandler = this.mockRepository.Create(); this.mockUrlHelper = this.mockRepository.Create(); } @@ -303,10 +301,6 @@ public async Task WhenDeviceAlreadyExistCreateDeviceAsyncWithValidArgumentShould }; var routerConfig = new RouterConfig(); - var mockResult = new BulkRegistryOperationResult - { - IsSuccessful = true - }; var twin = new Twin { @@ -402,8 +396,6 @@ public async Task WhenGetDeviceThrowAnErrorUpdateDeviceAsyncWithValidArgumentSho DeviceId = concentrator.DeviceId, }; - var device = new Device(concentrator.DeviceId); - _ = this.mockDeviceService.Setup(x => x.GetDevice(It.Is(c => c == concentrator.DeviceId))) .ThrowsAsync(new InternalServerErrorException("")); diff --git a/src/AzureIoTHub.Portal.Server.Tests.Unit/Pages/LoRaWan/Concentrator/ConcentratorListPageTests.cs b/src/AzureIoTHub.Portal.Server.Tests.Unit/Pages/LoRaWan/Concentrator/ConcentratorListPageTests.cs index 5772dc4ff..1544ea1ff 100644 --- a/src/AzureIoTHub.Portal.Server.Tests.Unit/Pages/LoRaWan/Concentrator/ConcentratorListPageTests.cs +++ b/src/AzureIoTHub.Portal.Server.Tests.Unit/Pages/LoRaWan/Concentrator/ConcentratorListPageTests.cs @@ -120,5 +120,34 @@ public void ClickToItemShouldRedirectToConcentratorDetailsPage() // Assert cut.WaitForAssertion(() => Services.GetService()?.Uri.Should().EndWith($"/lorawan/concentrators/{deviceId}")); } + + [Test] + public void ClickOnAddNewDeviceShouldNavigateToNewDevicePage() + { + // Arrange + const string expectedUri = "api/lorawan/concentrators?pageSize=10"; + + _ = this.mockLoRaWanConcentratorsClientService.Setup(service => + service.GetConcentrators(It.Is(s => expectedUri.Equals(s, StringComparison.Ordinal)))) + .ReturnsAsync(new PaginationResult + { + Items = new List + { + new(), + new(), + new() + } + }); + + // Act + var cut = RenderComponent(); + cut.WaitForAssertion(() => cut.Find("#concentrators-listing")); + cut.WaitForAssertion(() => cut.Markup.Should().NotContain("Loading...")); + cut.WaitForElement("#add-concentrator").Click(); + + // Assert + cut.WaitForAssertion(() => MockRepository.VerifyAll()); + cut.WaitForAssertion(() => Services.GetService()?.Uri.Should().EndWith("/lorawan/concentrators/new")); + } } } diff --git a/src/AzureIoTHub.Portal/Client/Pages/LoRaWAN/Concentrator/ConcentratorListPage.razor b/src/AzureIoTHub.Portal/Client/Pages/LoRaWAN/Concentrator/ConcentratorListPage.razor index e5ff9d220..dac899f27 100644 --- a/src/AzureIoTHub.Portal/Client/Pages/LoRaWAN/Concentrator/ConcentratorListPage.razor +++ b/src/AzureIoTHub.Portal/Client/Pages/LoRaWAN/Concentrator/ConcentratorListPage.razor @@ -4,7 +4,7 @@ @attribute [Authorize] @inject IDialogService DialogService -@inject NavigationManager navigationManager +@inject NavigationManager NavigationManager @inject ILoRaWanConcentratorsClientService LoRaWanConcentratorsClientService @@ -25,7 +25,7 @@ - + @@ -99,7 +99,7 @@ private MudTable table; - private Dictionary Pages { get; set; } = new(); + private Dictionary Pages { get; } = new(); private bool IsLoading { get; set; } = true; @@ -141,7 +141,7 @@ private void AddDevice() { - navigationManager.NavigateTo("lorawan/concentrators/new"); + NavigationManager.NavigateTo("lorawan/concentrators/new"); } private async Task DeleteDevice(Concentrator device) @@ -168,6 +168,6 @@ private void GoToDetails(Concentrator item) { - navigationManager.NavigateTo($"/lorawan/concentrators/{item.DeviceId}"); + NavigationManager.NavigateTo($"/lorawan/concentrators/{item.DeviceId}"); } } diff --git a/src/AzureIoTHub.Portal/Server/Controllers/v1.0/LoRaWAN/LoRaWANConcentratorsController.cs b/src/AzureIoTHub.Portal/Server/Controllers/v1.0/LoRaWAN/LoRaWANConcentratorsController.cs index 05858f7c3..034d5f983 100644 --- a/src/AzureIoTHub.Portal/Server/Controllers/v1.0/LoRaWAN/LoRaWANConcentratorsController.cs +++ b/src/AzureIoTHub.Portal/Server/Controllers/v1.0/LoRaWAN/LoRaWANConcentratorsController.cs @@ -7,10 +7,10 @@ namespace AzureIoTHub.Portal.Server.Controllers.V10.LoRaWAN using System.Linq; using System.Threading.Tasks; using AzureIoTHub.Portal.Models.v10.LoRaWAN; - using AzureIoTHub.Portal.Server.Filters; - using AzureIoTHub.Portal.Server.Managers; - using AzureIoTHub.Portal.Server.Mappers; - using AzureIoTHub.Portal.Server.Services; + using Filters; + using Managers; + using Mappers; + using Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -72,10 +72,16 @@ public LoRaWANConcentratorsController( /// [HttpGet(Name = "GET LoRaWAN Concentrator list")] [ProducesResponseType(StatusCodes.Status200OK)] - public async Task>> GetAllDeviceConcentrator() + public async Task>> GetAllDeviceConcentrator( + string continuationToken = null, + int pageSize = 10) { // Gets all the twins from this devices - var result = await this.devicesService.GetAllDevice(filterDeviceType: "LoRa Concentrator"); + var result = await this.devicesService.GetAllDevice( + continuationToken: continuationToken, + filterDeviceType: "LoRa Concentrator", + pageSize: pageSize); + string nextPage = null; if (!string.IsNullOrEmpty(result.NextPage))