Skip to content

Commit

Permalink
Fix #811 - Add available frequency plans from API and remove hardcode…
Browse files Browse the repository at this point in the history
…d frequency plans from Web pages
  • Loading branch information
kbeaugrand committed Aug 8, 2022
1 parent 74a6ab8 commit 169f1a5
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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.Controllers.V10.LoRaWAN
{
using System.Collections.Generic;
using AzureIoTHub.Portal.Server.Controllers.V10.LoRaWAN;
using AzureIoTHub.Portal.Shared.Models.v10.LoRaWAN;
using Microsoft.AspNetCore.Mvc;
using NUnit.Framework;

[TestFixture]
public class LoRaWANFrequencyPlansControllerTests : BackendUnitTest
{
private static LoRaWANFrequencyPlansController CreateLoRaWANFrequencyPlansController()
{
return new LoRaWANFrequencyPlansController();
}

[Test]
public void GetFrequencyPlans()
{
// Arrange
var loRaWANFrequencyPlansController = CreateLoRaWANFrequencyPlansController();

// Act
var result = loRaWANFrequencyPlansController.GetFrequencyPlans();

// Assert
Assert.NotNull(result);
Assert.IsAssignableFrom<ActionResult<IEnumerable<FrequencyPlan>>>(result);
base.MockRepository.VerifyAll();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace AzureIoTHub.Portal.Server.Tests.Unit.Pages.LoRaWan.Concentrator
using MudBlazor;
using MudBlazor.Services;
using NUnit.Framework;
using AzureIoTHub.Portal.Shared.Models.v10.LoRaWAN;

[TestFixture]
public class ConcentratorDetailPageTests : BlazorUnitTest
Expand Down Expand Up @@ -54,6 +55,12 @@ public void ReturnButtonMustNavigateToPreviousPage()
_ = this.mockLoRaWanConcentratorsClientService.Setup(service => service.GetConcentrator(this.mockDeviceId))
.ReturnsAsync(new Concentrator());

_ = this.mockLoRaWanConcentratorsClientService.Setup(service => service.GetFrequencyPlans())
.ReturnsAsync(new[]
{
new FrequencyPlan()
});

var cut = RenderComponent<ConcentratorDetailPage>(ComponentParameter.CreateParameter("DeviceID", this.mockDeviceId));
cut.WaitForAssertion(() => cut.Find("#returnButton"));

Expand All @@ -72,6 +79,12 @@ public void ConcentratorDetailPageShouldProcessProblemDetailsExceptionWhenIssueO
_ = this.mockLoRaWanConcentratorsClientService.Setup(service => service.GetConcentrator(this.mockDeviceId))
.ThrowsAsync(new ProblemDetailsException(new ProblemDetailsWithExceptionDetails()));

_ = this.mockLoRaWanConcentratorsClientService.Setup(service => service.GetFrequencyPlans())
.ReturnsAsync(new[]
{
new FrequencyPlan()
});

// Act
var cut = RenderComponent<ConcentratorDetailPage>(ComponentParameter.CreateParameter("DeviceID", this.mockDeviceId));
cut.WaitForAssertion(() => cut.Find("#returnButton"));
Expand All @@ -91,6 +104,12 @@ public void ClickOnSaveShouldPutConcentratorDetails()
LoraRegion = Guid.NewGuid().ToString()
};

_ = this.mockLoRaWanConcentratorsClientService.Setup(service => service.GetFrequencyPlans())
.ReturnsAsync(new[]
{
new FrequencyPlan()
});

_ = this.mockLoRaWanConcentratorsClientService.Setup(service => service.GetConcentrator(mockConcentrator.DeviceId))
.ReturnsAsync(mockConcentrator);

Expand Down Expand Up @@ -120,6 +139,12 @@ public void ConcentratorShouldNotBeUpdatedWhenModelIsNotValid()
LoraRegion = Guid.NewGuid().ToString()
};

_ = this.mockLoRaWanConcentratorsClientService.Setup(service => service.GetFrequencyPlans())
.ReturnsAsync(new[]
{
new FrequencyPlan()
});

_ = this.mockLoRaWanConcentratorsClientService.Setup(service => service.GetConcentrator(mockConcentrator.DeviceId))
.ReturnsAsync(mockConcentrator);

Expand All @@ -144,6 +169,12 @@ public void ClickOnSaveShouldProcessProblemDetailsExceptionWhenIssueOccursOnUpda
LoraRegion = Guid.NewGuid().ToString()
};

_ = this.mockLoRaWanConcentratorsClientService.Setup(service => service.GetFrequencyPlans())
.ReturnsAsync(new[]
{
new FrequencyPlan()
});

_ = this.mockLoRaWanConcentratorsClientService.Setup(service => service.GetConcentrator(mockConcentrator.DeviceId))
.ReturnsAsync(mockConcentrator);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace AzureIoTHub.Portal.Server.Tests.Unit.Pages.LoRaWan.Concentrator
using MudBlazor;
using MudBlazor.Services;
using NUnit.Framework;
using AzureIoTHub.Portal.Shared.Models.v10.LoRaWAN;

[TestFixture]
public class CreateConcentratorPageTest : BlazorUnitTest
Expand Down Expand Up @@ -59,6 +60,12 @@ public void ClickOnSaveShouldPostConcentratorDetails()
LoraRegion = "CN_470_510_RP2"
};

_ = this.mockLoRaWanConcentratorsClientService.Setup(service => service.GetFrequencyPlans())
.ReturnsAsync(new[]
{
new FrequencyPlan()
});

_ = this.mockLoRaWanConcentratorsClientService.Setup(service =>
service.CreateConcentrator(It.Is<Concentrator>(concentrator =>
mockConcentrator.DeviceId.Equals(concentrator.DeviceId, StringComparison.Ordinal))))
Expand Down Expand Up @@ -93,6 +100,12 @@ public void ClickOnSaveShouldProcessProblemDetailsExceptionWhenIssueOccursOnCrea
LoraRegion = "CN_470_510_RP2"
};

_ = this.mockLoRaWanConcentratorsClientService.Setup(service => service.GetFrequencyPlans())
.ReturnsAsync(new[]
{
new FrequencyPlan()
});

_ = this.mockLoRaWanConcentratorsClientService.Setup(service =>
service.CreateConcentrator(It.Is<Concentrator>(concentrator =>
mockConcentrator.DeviceId.Equals(concentrator.DeviceId, StringComparison.Ordinal))))
Expand All @@ -118,6 +131,11 @@ public void ClickOnSaveShouldNotCreateConcentratorWhenModelIsNotValid()
{
// Arrange
_ = this.mockSnackbarService.Setup(c => c.Add(It.IsAny<string>(), Severity.Error, null)).Returns((Snackbar)null);
_ = this.mockLoRaWanConcentratorsClientService.Setup(service => service.GetFrequencyPlans())
.ReturnsAsync(new[]
{
new FrequencyPlan()
});

var cut = RenderComponent<CreateConcentratorPage>();
cut.WaitForAssertion(() => cut.Find("#saveButton"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace AzureIoTHub.Portal.Server.Tests.Unit.Services
using System.Threading.Tasks;
using AutoFixture;
using AzureIoTHub.Portal.Client.Services;
using AzureIoTHub.Portal.Shared.Models.v10.LoRaWAN;
using FluentAssertions;
using Helpers;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -140,5 +141,28 @@ public async Task DeleteConcentratorShouldDeleteConcentrator()
MockHttpClient.VerifyNoOutstandingRequest();
MockHttpClient.VerifyNoOutstandingExpectation();
}

[Test]
public async Task GetLoRaWANFrequencyPlansShouldQueryTheController()
{
// Arrange
var expectedFrequencyPlans = new []
{
new FrequencyPlan(),
new FrequencyPlan(),
new FrequencyPlan()
};

_ = MockHttpClient.When(HttpMethod.Get, "/api/lorawan/freqencyplans")
.RespondJson(expectedFrequencyPlans);

// Act
var result = await this.loRaWanConcentratorsClientService.GetFrequencyPlans();

// Assert
_ = result.Should().BeEquivalentTo(expectedFrequencyPlans);
MockHttpClient.VerifyNoOutstandingRequest();
MockHttpClient.VerifyNoOutstandingExpectation();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@page "/lorawan/concentrators/{DeviceID}"
@using AzureIoTHub.Portal.Client.Validators
@using AzureIoTHub.Portal.Models.v10.LoRaWAN
@using AzureIoTHub.Portal.Shared.Models.v10.LoRaWAN

@attribute [Authorize]
@inject IDialogService DialogService
Expand All @@ -9,10 +10,10 @@
@inject ILoRaWanConcentratorsClientService LoRaWanConcentratorsClientService

<MudTooltip Text="Return" Placement="Placement.Left">
<MudFab Icon="@Icons.Outlined.ArrowBack" Color="Color.Secondary" Size="Size.Small" OnClick="Return" id = "returnButton" />
<MudFab Icon="@Icons.Outlined.ArrowBack" Color="Color.Secondary" Size="Size.Small" OnClick="Return" id="returnButton" />
</MudTooltip>
<MudTooltip Placement="Placement.Top">
<MudText Typo="Typo.h5" Color="Color.Primary" Class="mb-4"> LoRaWAN Concentrator</MudText>
<MudText Typo="Typo.h5" Color="Color.Primary" Class="mb-4"> LoRaWAN Concentrator</MudText>
</MudTooltip>

<MudForm Model="@concentrator" @ref="form">
Expand All @@ -22,8 +23,8 @@
<MudCardHeader>
<CardHeaderContent>
<MudText Typo="Typo.h5" Align="Align.Center">@(string.IsNullOrEmpty(concentrator.DeviceName) ? concentrator.DeviceId : concentrator.DeviceName)</MudText>
</CardHeaderContent>
<CardHeaderAvatar>
</CardHeaderContent>
<CardHeaderAvatar>
@if (concentrator.IsConnected)
{
<MudTooltip Text="Concentrator is connected">
Expand Down Expand Up @@ -75,19 +76,10 @@
</MudItem>
<MudItem xs="12" md="6">
<MudSelect T="string" Label="Region" Variant="Variant.Outlined" @bind-Value="@concentrator.LoraRegion" Required="true">
<MudSelectItem Value="@("AS_923_925_1")">Asia 923-925 MHz, Group 1</MudSelectItem>
<MudSelectItem Value="@("AS_923_925_2")">Asia 923-925 MHz, Group 2</MudSelectItem>
<MudSelectItem Value="@("AS_923_925_3")">Asia 923-925 MHz, Group 3</MudSelectItem>
<MudSelectItem Value="@("EU_863_870")">Europe 863-870 MHz</MudSelectItem>
<MudSelectItem Value="@("CN_470_510_RP1")">China 470-510 MHz, RP 1</MudSelectItem>
<MudSelectItem Value="@("CN_470_510_RP2")">China 470-510 MHz, RP 2</MudSelectItem>
<MudSelectItem Value="@("US_902_928_FSB_1")">United States 902-928 MHz, FSB 1</MudSelectItem>
<MudSelectItem Value="@("US_902_928_FSB_2")">United States 902-928 MHz, FSB 2</MudSelectItem>
<MudSelectItem Value="@("US_902_928_FSB_3")">United States 902-928 MHz, FSB 3</MudSelectItem>
<MudSelectItem Value="@("US_902_928_FSB_4")">United States 902-928 MHz, FSB 4</MudSelectItem>
<MudSelectItem Value="@("US_902_928_FSB_5")">United States 902-928 MHz, FSB 5</MudSelectItem>
<MudSelectItem Value="@("US_902_928_FSB_6")">United States 902-928 MHz, FSB 6</MudSelectItem>
<MudSelectItem Value="@("US_902_928_FSB_7")">United States 902-928 MHz, FSB 7</MudSelectItem>
@foreach (var frequencyPlan in FrequencyPlans.OrderBy(c => c.Name))
{
<MudSelectItem Value="@(frequencyPlan.FrequencyPlanID)">@frequencyPlan.Name</MudSelectItem>
}
</MudSelect>
</MudItem>
<MudItem xs="12">
Expand Down Expand Up @@ -119,25 +111,26 @@

@code {
[CascadingParameter]
public Error Error {get; set;}
public Error Error { get; set; }

[Parameter]
public string DeviceID { get; set; }

private Concentrator concentrator { get; set; } = new();
private MudForm form;
private ConcentratorValidator concentratorValidator = new();
private List<FrequencyPlan> FrequencyPlans = new List<FrequencyPlan>();

private bool isProcessing;

private void Return() => NavigationManager.NavigateTo("/lorawan/concentrators");

public PatternMask maskThumbprint = new PatternMask("XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX")
{
{
MaskChars = new[] { new MaskChar('X', @"[0-9a-fA-F]") },
CleanDelimiters = false,
Transformation = AllUpperCase
};
};

private static char AllUpperCase(char c) => c.ToString().ToUpperInvariant()[0];

Expand All @@ -146,7 +139,7 @@
try
{
isProcessing = true;
// Sends a GET request to the DevicesController, to retrieve the specific device from Azure IoT Hub
this.FrequencyPlans.AddRange(await this.LoRaWanConcentratorsClientService.GetFrequencyPlans());
concentrator = await LoRaWanConcentratorsClientService.GetConcentrator(DeviceID);
}
catch (ProblemDetailsException exception)
Expand Down Expand Up @@ -204,7 +197,7 @@
{
isProcessing = true;

var parameters = new DialogParameters {{"deviceId", concentrator.DeviceId}};
var parameters = new DialogParameters { { "deviceId", concentrator.DeviceId } };
var result = await DialogService.Show<DeleteConcentratorPage>("Confirm Deletion", parameters).Result;

isProcessing = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@page "/lorawan/concentrators/new"
@using AzureIoTHub.Portal.Models.v10.LoRaWAN
@using AzureIoTHub.Portal.Client.Validators
@using AzureIoTHub.Portal.Shared.Models.v10.LoRaWAN

@attribute [Authorize]
@inject ISnackbar Snackbar
Expand Down Expand Up @@ -57,19 +58,10 @@
</MudItem>
<MudItem xs="12" md="6">
<MudSelect T="string" For="@(()=> concentrator.LoraRegion)" Label="Region" Variant="Variant.Outlined" @bind-Value="@concentrator.LoraRegion" Required="true" id="@nameof(Concentrator.LoraRegion)">
<MudSelectItem Value="@("AS_923_925_1")">Asia 923-925 MHz, Group 1</MudSelectItem>
<MudSelectItem Value="@("AS_923_925_2")">Asia 923-925 MHz, Group 2</MudSelectItem>
<MudSelectItem Value="@("AS_923_925_3")">Asia 923-925 MHz, Group 3</MudSelectItem>
<MudSelectItem Value="@("EU_863_870")">Europe 863-870 MHz</MudSelectItem>
<MudSelectItem Value="@("CN_470_510_RP1")">China 470-510 MHz, RP 1</MudSelectItem>
<MudSelectItem Value="@("CN_470_510_RP2")">China 470-510 MHz, RP 2</MudSelectItem>
<MudSelectItem Value="@("US_902_928_FSB_1")">United States 902-928 MHz, FSB 1</MudSelectItem>
<MudSelectItem Value="@("US_902_928_FSB_2")">United States 902-928 MHz, FSB 2</MudSelectItem>
<MudSelectItem Value="@("US_902_928_FSB_3")">United States 902-928 MHz, FSB 3</MudSelectItem>
<MudSelectItem Value="@("US_902_928_FSB_4")">United States 902-928 MHz, FSB 4</MudSelectItem>
<MudSelectItem Value="@("US_902_928_FSB_5")">United States 902-928 MHz, FSB 5</MudSelectItem>
<MudSelectItem Value="@("US_902_928_FSB_6")">United States 902-928 MHz, FSB 6</MudSelectItem>
<MudSelectItem Value="@("US_902_928_FSB_7")">United States 902-928 MHz, FSB 7</MudSelectItem>
@foreach (var frequencyPlan in FrequencyPlans.OrderBy(c => c.Name))
{
<MudSelectItem Value="@(frequencyPlan.FrequencyPlanID)">@frequencyPlan.Name</MudSelectItem>
}
</MudSelect>
</MudItem>
<MudItem xs="12">
Expand Down Expand Up @@ -100,14 +92,16 @@
</MudForm>


@code {
@code {
[CascadingParameter]
public Error Error {get; set;}

private Concentrator concentrator = new();
private MudForm form;
private ConcentratorValidator concentratorValidator = new();

private List<FrequencyPlan> FrequencyPlans = new List<FrequencyPlan>();

private bool isProcessing;

public PatternMask maskThumbprint = new("XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX")
Expand All @@ -117,6 +111,13 @@
Transformation = AllUpperCase
};

protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();

this.FrequencyPlans.AddRange(await this.LoRaWanConcentratorsClientService.GetFrequencyPlans());
}

private static char AllUpperCase(char c) => c.ToString().ToUpperInvariant()[0];

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

namespace AzureIoTHub.Portal.Client.Services
{
using System.Collections.Generic;
using System.Threading.Tasks;
using AzureIoTHub.Portal.Shared.Models.v10.LoRaWAN;
using Portal.Models.v10.LoRaWAN;

public interface ILoRaWanConcentratorsClientService
Expand All @@ -17,5 +19,7 @@ public interface ILoRaWanConcentratorsClientService
Task UpdateConcentrator(Concentrator concentrator);

Task DeleteConcentrator(string deviceId);

Task<IEnumerable<FrequencyPlan>> GetFrequencyPlans();
}
}
Loading

0 comments on commit 169f1a5

Please sign in to comment.