diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221005134349_Add Concentrator.Designer.cs b/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221005134349_Add Concentrator.Designer.cs
new file mode 100644
index 000000000..72a712257
--- /dev/null
+++ b/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221005134349_Add Concentrator.Designer.cs
@@ -0,0 +1,427 @@
+//
+using System;
+using AzureIoTHub.Portal.Infrastructure;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+
+#nullable disable
+
+namespace AzureIoTHub.Portal.Infrastructure.Migrations
+{
+ [DbContext(typeof(PortalDbContext))]
+ [Migration("20221005134349_Add Concentrator")]
+ partial class AddConcentrator
+ {
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "6.0.9")
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.Concentrator", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("text");
+
+ b.Property("ClientThumbprint")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("DeviceType")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("IsConnected")
+ .HasColumnType("boolean");
+
+ b.Property("IsEnabled")
+ .HasColumnType("boolean");
+
+ b.Property("LoraRegion")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Version")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.ToTable("Concentrators");
+ });
+
+ modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.Device", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("text");
+
+ b.Property("DeviceModelId")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("IsConnected")
+ .HasColumnType("boolean");
+
+ b.Property("IsEnabled")
+ .HasColumnType("boolean");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("StatusUpdatedTime")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("Version")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.ToTable("Devices");
+ });
+
+ modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.DeviceModel", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("text");
+
+ b.Property("ABPRelaxMode")
+ .HasColumnType("boolean");
+
+ b.Property("AppEUI")
+ .HasColumnType("text");
+
+ b.Property("ClassType")
+ .HasColumnType("integer");
+
+ b.Property("Deduplication")
+ .HasColumnType("integer");
+
+ b.Property("Description")
+ .HasColumnType("text");
+
+ b.Property("Downlink")
+ .HasColumnType("boolean");
+
+ b.Property("IsBuiltin")
+ .HasColumnType("boolean");
+
+ b.Property("KeepAliveTimeout")
+ .HasColumnType("integer");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("PreferredWindow")
+ .HasColumnType("integer");
+
+ b.Property("RXDelay")
+ .HasColumnType("integer");
+
+ b.Property("SensorDecoder")
+ .HasColumnType("text");
+
+ b.Property("SupportLoRaFeatures")
+ .HasColumnType("boolean");
+
+ b.Property("UseOTAA")
+ .HasColumnType("boolean");
+
+ b.HasKey("Id");
+
+ b.ToTable("DeviceModels");
+ });
+
+ modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.DeviceModelCommand", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("text");
+
+ b.Property("Confirmed")
+ .HasColumnType("boolean");
+
+ b.Property("DeviceModelId")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Frame")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("IsBuiltin")
+ .HasColumnType("boolean");
+
+ b.Property("Port")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.ToTable("DeviceModelCommands");
+ });
+
+ modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.DeviceModelProperty", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("text");
+
+ b.Property("DisplayName")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("IsWritable")
+ .HasColumnType("boolean");
+
+ b.Property("ModelId")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Order")
+ .HasColumnType("integer");
+
+ b.Property("PropertyType")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.ToTable("DeviceModelProperties");
+ });
+
+ modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.DeviceTag", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("text");
+
+ b.Property("Label")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Required")
+ .HasColumnType("boolean");
+
+ b.Property("Searchable")
+ .HasColumnType("boolean");
+
+ b.HasKey("Id");
+
+ b.ToTable("DeviceTags");
+ });
+
+ modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.DeviceTagValue", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("text");
+
+ b.Property("DeviceId")
+ .HasColumnType("text");
+
+ b.Property("LorawanDeviceId")
+ .HasColumnType("text");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Value")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.HasIndex("DeviceId");
+
+ b.HasIndex("LorawanDeviceId");
+
+ b.ToTable("DeviceTagValues");
+ });
+
+ modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.EdgeDeviceModel", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("text");
+
+ b.Property("Description")
+ .HasColumnType("text");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("EdgeDeviceModels");
+ });
+
+ modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.EdgeDeviceModelCommand", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("text");
+
+ b.Property("EdgeDeviceModelId")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("ModuleName")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("EdgeDeviceModelCommands");
+ });
+
+ modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.LorawanDevice", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("text");
+
+ b.Property("ABPRelaxMode")
+ .HasColumnType("boolean");
+
+ b.Property("AlreadyLoggedInOnce")
+ .HasColumnType("boolean");
+
+ b.Property("AppEUI")
+ .HasColumnType("text");
+
+ b.Property("AppKey")
+ .HasColumnType("text");
+
+ b.Property("AppSKey")
+ .HasColumnType("text");
+
+ b.Property("ClassType")
+ .HasColumnType("integer");
+
+ b.Property("DataRate")
+ .HasColumnType("text");
+
+ b.Property("Deduplication")
+ .HasColumnType("integer");
+
+ b.Property("DevAddr")
+ .HasColumnType("text");
+
+ b.Property("DeviceModelId")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Downlink")
+ .HasColumnType("boolean");
+
+ b.Property("FCntDownStart")
+ .HasColumnType("integer");
+
+ b.Property("FCntResetCounter")
+ .HasColumnType("integer");
+
+ b.Property("FCntUpStart")
+ .HasColumnType("integer");
+
+ b.Property("GatewayID")
+ .HasColumnType("text");
+
+ b.Property("IsConnected")
+ .HasColumnType("boolean");
+
+ b.Property("IsEnabled")
+ .HasColumnType("boolean");
+
+ b.Property("KeepAliveTimeout")
+ .HasColumnType("integer");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("NbRep")
+ .HasColumnType("text");
+
+ b.Property("NwkSKey")
+ .HasColumnType("text");
+
+ b.Property("PreferredWindow")
+ .HasColumnType("integer");
+
+ b.Property("RX1DROffset")
+ .HasColumnType("integer");
+
+ b.Property("RX2DataRate")
+ .HasColumnType("integer");
+
+ b.Property("RXDelay")
+ .HasColumnType("integer");
+
+ b.Property("ReportedRX1DROffset")
+ .HasColumnType("text");
+
+ b.Property("ReportedRX2DataRate")
+ .HasColumnType("text");
+
+ b.Property("ReportedRXDelay")
+ .HasColumnType("text");
+
+ b.Property("SensorDecoder")
+ .HasColumnType("text");
+
+ b.Property("StatusUpdatedTime")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("Supports32BitFCnt")
+ .HasColumnType("boolean");
+
+ b.Property("TxPower")
+ .HasColumnType("text");
+
+ b.Property("UseOTAA")
+ .HasColumnType("boolean");
+
+ b.Property("Version")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.ToTable("LorawanDevices");
+ });
+
+ modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.DeviceTagValue", b =>
+ {
+ b.HasOne("AzureIoTHub.Portal.Domain.Entities.Device", null)
+ .WithMany("Tags")
+ .HasForeignKey("DeviceId");
+
+ b.HasOne("AzureIoTHub.Portal.Domain.Entities.LorawanDevice", null)
+ .WithMany("Tags")
+ .HasForeignKey("LorawanDeviceId");
+ });
+
+ modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.Device", b =>
+ {
+ b.Navigation("Tags");
+ });
+
+ modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.LorawanDevice", b =>
+ {
+ b.Navigation("Tags");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221005134349_Add Concentrator.cs b/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221005134349_Add Concentrator.cs
new file mode 100644
index 000000000..426cbddea
--- /dev/null
+++ b/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221005134349_Add Concentrator.cs
@@ -0,0 +1,39 @@
+// Copyright (c) CGI France. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+#nullable disable
+
+namespace AzureIoTHub.Portal.Infrastructure.Migrations
+{
+ using Microsoft.EntityFrameworkCore.Migrations;
+
+ public partial class AddConcentrator : Migration
+ {
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ _ = migrationBuilder.CreateTable(
+ name: "Concentrators",
+ columns: table => new
+ {
+ Id = table.Column(type: "text", nullable: false),
+ Name = table.Column(type: "text", nullable: false),
+ LoraRegion = table.Column(type: "text", nullable: false),
+ DeviceType = table.Column(type: "text", nullable: false),
+ ClientThumbprint = table.Column(type: "text", nullable: false),
+ IsConnected = table.Column(type: "boolean", nullable: false),
+ IsEnabled = table.Column(type: "boolean", nullable: false),
+ Version = table.Column(type: "integer", nullable: false)
+ },
+ constraints: table =>
+ {
+ _ = table.PrimaryKey("PK_Concentrators", x => x.Id);
+ });
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ _ = migrationBuilder.DropTable(
+ name: "Concentrators");
+ }
+ }
+}
diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/PortalDbContextModelSnapshot.cs b/src/AzureIoTHub.Portal.Infrastructure/Migrations/PortalDbContextModelSnapshot.cs
index 9636dcf32..195f59bb7 100644
--- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/PortalDbContextModelSnapshot.cs
+++ b/src/AzureIoTHub.Portal.Infrastructure/Migrations/PortalDbContextModelSnapshot.cs
@@ -22,6 +22,41 @@ protected override void BuildModel(ModelBuilder modelBuilder)
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+ modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.Concentrator", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("text");
+
+ b.Property("ClientThumbprint")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("DeviceType")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("IsConnected")
+ .HasColumnType("boolean");
+
+ b.Property("IsEnabled")
+ .HasColumnType("boolean");
+
+ b.Property("LoraRegion")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Version")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.ToTable("Concentrators");
+ });
+
modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.Device", b =>
{
b.Property("Id")
diff --git a/src/AzureIoTHub.Portal.Infrastructure/PortalDbContext.cs b/src/AzureIoTHub.Portal.Infrastructure/PortalDbContext.cs
index c1ba83b23..b84c9a7fc 100644
--- a/src/AzureIoTHub.Portal.Infrastructure/PortalDbContext.cs
+++ b/src/AzureIoTHub.Portal.Infrastructure/PortalDbContext.cs
@@ -3,13 +3,9 @@
namespace AzureIoTHub.Portal.Infrastructure
{
- using AzureIoTHub.Portal.Domain;
using AzureIoTHub.Portal.Domain.Entities;
- using AzureIoTHub.Portal.Infrastructure.Seeds;
using Microsoft.EntityFrameworkCore;
- using Microsoft.EntityFrameworkCore.Infrastructure;
- using Microsoft.Extensions.Logging;
- using Newtonsoft.Json;
+
public class PortalDbContext : DbContext
{
@@ -22,6 +18,7 @@ public class PortalDbContext : DbContext
public DbSet DeviceTagValues { get; set; }
public DbSet EdgeDeviceModels { get; set; }
public DbSet EdgeDeviceModelCommands { get; set; }
+ public DbSet Concentrators { get; set; }
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public PortalDbContext(DbContextOptions options)
diff --git a/src/AzureIoTHub.Portal.Infrastructure/Repositories/ConcentratorRepository.cs b/src/AzureIoTHub.Portal.Infrastructure/Repositories/ConcentratorRepository.cs
new file mode 100644
index 000000000..811468e0e
--- /dev/null
+++ b/src/AzureIoTHub.Portal.Infrastructure/Repositories/ConcentratorRepository.cs
@@ -0,0 +1,15 @@
+// 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.Infrastructure.Repositories
+{
+ using AzureIoTHub.Portal.Domain.Repositories;
+ using Domain.Entities;
+
+ public class ConcentratorRepository : GenericRepository, IConcentratorRepository
+ {
+ public ConcentratorRepository(PortalDbContext context) : base(context)
+ {
+ }
+ }
+}
diff --git a/src/AzureIoTHub.Portal.Tests.Unit/Client/Pages/LoRaWan/Concentrator/ConcentratorDetailPageTests.cs b/src/AzureIoTHub.Portal.Tests.Unit/Client/Pages/LoRaWan/Concentrator/ConcentratorDetailPageTests.cs
index b23445c9e..ed3f2d56f 100644
--- a/src/AzureIoTHub.Portal.Tests.Unit/Client/Pages/LoRaWan/Concentrator/ConcentratorDetailPageTests.cs
+++ b/src/AzureIoTHub.Portal.Tests.Unit/Client/Pages/LoRaWan/Concentrator/ConcentratorDetailPageTests.cs
@@ -54,7 +54,7 @@ public void ReturnButtonMustNavigateToPreviousPage()
{
// Arrange
_ = this.mockLoRaWanConcentratorsClientService.Setup(service => service.GetConcentrator(this.mockDeviceId))
- .ReturnsAsync(new Concentrator());
+ .ReturnsAsync(new ConcentratorDto());
_ = this.mockLoRaWanConcentratorsClientService.Setup(service => service.GetFrequencyPlans())
.ReturnsAsync(new[]
@@ -98,7 +98,7 @@ public void ConcentratorDetailPageShouldProcessProblemDetailsExceptionWhenIssueO
public void ClickOnSaveShouldPutConcentratorDetails()
{
// Arrange
- var mockConcentrator = new Concentrator()
+ var mockConcentrator = new ConcentratorDto()
{
DeviceId = "1234567890123456",
DeviceName = Guid.NewGuid().ToString(),
@@ -133,7 +133,7 @@ public void ClickOnSaveShouldPutConcentratorDetails()
public void ConcentratorShouldNotBeUpdatedWhenModelIsNotValid()
{
// Arrange
- var mockConcentrator = new Concentrator()
+ var mockConcentrator = new ConcentratorDto()
{
DeviceId = string.Empty,
DeviceName = Guid.NewGuid().ToString(),
@@ -163,7 +163,7 @@ public void ConcentratorShouldNotBeUpdatedWhenModelIsNotValid()
public void ClickOnSaveShouldProcessProblemDetailsExceptionWhenIssueOccursOnUpdatingConcentratorDetails()
{
// Arrange
- var mockConcentrator = new Concentrator()
+ var mockConcentrator = new ConcentratorDto()
{
DeviceId = "1234567890123456",
DeviceName = Guid.NewGuid().ToString(),
diff --git a/src/AzureIoTHub.Portal.Tests.Unit/Client/Pages/LoRaWan/Concentrator/ConcentratorListPageTests.cs b/src/AzureIoTHub.Portal.Tests.Unit/Client/Pages/LoRaWan/Concentrator/ConcentratorListPageTests.cs
index 02ff94ad7..f2d971ac0 100644
--- a/src/AzureIoTHub.Portal.Tests.Unit/Client/Pages/LoRaWan/Concentrator/ConcentratorListPageTests.cs
+++ b/src/AzureIoTHub.Portal.Tests.Unit/Client/Pages/LoRaWan/Concentrator/ConcentratorListPageTests.cs
@@ -50,9 +50,9 @@ public void ConcentratorListPageShouldLoadAndShowConcentrators()
_ = this.mockLoRaWanConcentratorsClientService.Setup(service =>
service.GetConcentrators(It.Is(s => expectedUri.Equals(s, StringComparison.Ordinal))))
- .ReturnsAsync(new PaginationResult
+ .ReturnsAsync(new PaginationResult
{
- Items = new List
+ Items = new List
{
new(),
new(),
@@ -100,9 +100,9 @@ public void ClickToItemShouldRedirectToConcentratorDetailsPage()
_ = this.mockLoRaWanConcentratorsClientService.Setup(service =>
service.GetConcentrators(It.Is(s => expectedUri.Equals(s, StringComparison.Ordinal))))
- .ReturnsAsync(new PaginationResult
+ .ReturnsAsync(new PaginationResult
{
- Items = new List
+ Items = new List
{
new()
{
@@ -130,9 +130,9 @@ public void ClickOnAddNewDeviceShouldNavigateToNewDevicePage()
_ = this.mockLoRaWanConcentratorsClientService.Setup(service =>
service.GetConcentrators(It.Is(s => expectedUri.Equals(s, StringComparison.Ordinal))))
- .ReturnsAsync(new PaginationResult
+ .ReturnsAsync(new PaginationResult
{
- Items = new List
+ Items = new List
{
new(),
new(),
@@ -159,9 +159,9 @@ public void ClickOnRefreshShouldReloadConcentrators()
_ = this.mockLoRaWanConcentratorsClientService.Setup(service =>
service.GetConcentrators(It.Is(s => expectedUri.Equals(s, StringComparison.Ordinal))))
- .ReturnsAsync(new PaginationResult
+ .ReturnsAsync(new PaginationResult
{
- Items = Array.Empty()
+ Items = Array.Empty()
});
var cut = RenderComponent();
diff --git a/src/AzureIoTHub.Portal.Tests.Unit/Client/Pages/LoRaWan/Concentrator/CreateConcentratorPageTest.cs b/src/AzureIoTHub.Portal.Tests.Unit/Client/Pages/LoRaWan/Concentrator/CreateConcentratorPageTest.cs
index acec8f60e..66c6a5a96 100644
--- a/src/AzureIoTHub.Portal.Tests.Unit/Client/Pages/LoRaWan/Concentrator/CreateConcentratorPageTest.cs
+++ b/src/AzureIoTHub.Portal.Tests.Unit/Client/Pages/LoRaWan/Concentrator/CreateConcentratorPageTest.cs
@@ -54,7 +54,7 @@ public override void Setup()
public void ClickOnSaveShouldPostConcentratorDetails()
{
// Arrange
- var mockConcentrator = new Concentrator
+ var mockConcentrator = new ConcentratorDto
{
DeviceId = "1234567890123456",
DeviceName = Guid.NewGuid().ToString(),
@@ -68,7 +68,7 @@ public void ClickOnSaveShouldPostConcentratorDetails()
});
_ = this.mockLoRaWanConcentratorsClientService.Setup(service =>
- service.CreateConcentrator(It.Is(concentrator =>
+ service.CreateConcentrator(It.Is(concentrator =>
mockConcentrator.DeviceId.Equals(concentrator.DeviceId, StringComparison.Ordinal))))
.Returns(Task.CompletedTask);
@@ -78,8 +78,8 @@ public void ClickOnSaveShouldPostConcentratorDetails()
cut.WaitForAssertion(() => cut.Find("#saveButton"));
- cut.Find($"#{nameof(Concentrator.DeviceId)}").Change(mockConcentrator.DeviceId);
- cut.Find($"#{nameof(Concentrator.DeviceName)}").Change(mockConcentrator.DeviceName);
+ cut.Find($"#{nameof(ConcentratorDto.DeviceId)}").Change(mockConcentrator.DeviceId);
+ cut.Find($"#{nameof(ConcentratorDto.DeviceName)}").Change(mockConcentrator.DeviceName);
cut.Instance.ChangeRegion(mockConcentrator.LoraRegion);
// Act
@@ -94,7 +94,7 @@ public void ClickOnSaveShouldPostConcentratorDetails()
public void ClickOnSaveShouldProcessProblemDetailsExceptionWhenIssueOccursOnCreatingConcentratorDetails()
{
// Arrange
- var mockConcentrator = new Concentrator
+ var mockConcentrator = new ConcentratorDto
{
DeviceId = "1234567890123456",
DeviceName = Guid.NewGuid().ToString(),
@@ -108,7 +108,7 @@ public void ClickOnSaveShouldProcessProblemDetailsExceptionWhenIssueOccursOnCrea
});
_ = this.mockLoRaWanConcentratorsClientService.Setup(service =>
- service.CreateConcentrator(It.Is(concentrator =>
+ service.CreateConcentrator(It.Is(concentrator =>
mockConcentrator.DeviceId.Equals(concentrator.DeviceId, StringComparison.Ordinal))))
.ThrowsAsync(new ProblemDetailsException(new ProblemDetailsWithExceptionDetails()));
@@ -116,8 +116,8 @@ public void ClickOnSaveShouldProcessProblemDetailsExceptionWhenIssueOccursOnCrea
cut.WaitForAssertion(() => cut.Find("#saveButton"));
- cut.Find($"#{nameof(Concentrator.DeviceId)}").Change(mockConcentrator.DeviceId);
- cut.Find($"#{nameof(Concentrator.DeviceName)}").Change(mockConcentrator.DeviceName);
+ cut.Find($"#{nameof(ConcentratorDto.DeviceId)}").Change(mockConcentrator.DeviceId);
+ cut.Find($"#{nameof(ConcentratorDto.DeviceName)}").Change(mockConcentrator.DeviceName);
cut.Instance.ChangeRegion(mockConcentrator.LoraRegion);
// Act
diff --git a/src/AzureIoTHub.Portal.Tests.Unit/Client/Services/LoRaWanConcentratorsClientServiceTests.cs b/src/AzureIoTHub.Portal.Tests.Unit/Client/Services/LoRaWanConcentratorsClientServiceTests.cs
index 51890b31c..e9f411e3c 100644
--- a/src/AzureIoTHub.Portal.Tests.Unit/Client/Services/LoRaWanConcentratorsClientServiceTests.cs
+++ b/src/AzureIoTHub.Portal.Tests.Unit/Client/Services/LoRaWanConcentratorsClientServiceTests.cs
@@ -36,9 +36,9 @@ public override void Setup()
public async Task GetConcentratorsShouldReturnConcentrators()
{
// Arrange
- var expectedConcentrators = new PaginationResult
+ var expectedConcentrators = new PaginationResult
{
- Items = new List()
+ Items = new List()
{
new ()
}
@@ -64,7 +64,7 @@ public async Task GetConcentratorShouldReturnConcentrator()
// Arrange
var deviceId = Fixture.Create();
- var expectedConcentrator = new Concentrator();
+ var expectedConcentrator = new ConcentratorDto();
_ = MockHttpClient.When(HttpMethod.Get, $"/api/lorawan/concentrators/{deviceId}")
.RespondJson(expectedConcentrator);
@@ -82,13 +82,13 @@ public async Task GetConcentratorShouldReturnConcentrator()
public async Task CreateConcentratorShouldCreateConcentrator()
{
// Arrange
- var concentrator = new Concentrator();
+ var concentrator = new ConcentratorDto();
_ = MockHttpClient.When(HttpMethod.Post, "/api/lorawan/concentrators")
.With(m =>
{
- _ = m.Content.Should().BeAssignableTo>();
- var body = m.Content as ObjectContent;
+ _ = m.Content.Should().BeAssignableTo>();
+ var body = m.Content as ObjectContent;
_ = body.Value.Should().BeEquivalentTo(concentrator);
return true;
})
@@ -106,13 +106,13 @@ public async Task CreateConcentratorShouldCreateConcentrator()
public async Task UpdateConcentratorShouldUpdateConcentrator()
{
// Arrange
- var concentrator = new Concentrator();
+ var concentrator = new ConcentratorDto();
_ = MockHttpClient.When(HttpMethod.Put, "/api/lorawan/concentrators")
.With(m =>
{
- _ = m.Content.Should().BeAssignableTo>();
- var body = m.Content as ObjectContent;
+ _ = m.Content.Should().BeAssignableTo>();
+ var body = m.Content as ObjectContent;
_ = body.Value.Should().BeEquivalentTo(concentrator);
return true;
})
diff --git a/src/AzureIoTHub.Portal.Tests.Unit/Client/Validators/ConcentratorValidatorTests.cs b/src/AzureIoTHub.Portal.Tests.Unit/Client/Validators/ConcentratorValidatorTests.cs
index 772810fc6..5aba646c6 100644
--- a/src/AzureIoTHub.Portal.Tests.Unit/Client/Validators/ConcentratorValidatorTests.cs
+++ b/src/AzureIoTHub.Portal.Tests.Unit/Client/Validators/ConcentratorValidatorTests.cs
@@ -15,7 +15,7 @@ public void ValidateValidConcentrator()
{
// Arrange
var concentratorValidator = new ConcentratorValidator();
- var concentrator = new Concentrator()
+ var concentrator = new ConcentratorDto()
{
DeviceId = "0123456789abcdef",
DeviceName = Guid.NewGuid().ToString(),
@@ -39,7 +39,7 @@ public void ValidateMissingFieldShouldReturnError(
{
// Arrange
var concentratorValidator = new ConcentratorValidator();
- var concentrator = new Concentrator()
+ var concentrator = new ConcentratorDto()
{
DeviceId = "0123456789abcdef",
DeviceName =DeviceNameValue,
@@ -60,7 +60,7 @@ public void ValidateMissingDeviceIdShouldReturnError()
{
// Arrange
var concentratorValidator = new ConcentratorValidator();
- var concentrator = new Concentrator()
+ var concentrator = new ConcentratorDto()
{
DeviceId = "",
DeviceName = Guid.NewGuid().ToString(),
@@ -83,7 +83,7 @@ public void ValidateBadFormatDeviceIdShouldReturnError()
{
// Arrange
var concentratorValidator = new ConcentratorValidator();
- var concentrator = new Concentrator()
+ var concentrator = new ConcentratorDto()
{
DeviceId = Guid.NewGuid().ToString(),
DeviceName = Guid.NewGuid().ToString(),
@@ -104,7 +104,7 @@ public void ValidateBadFormatClientThumbprintShouldReturnError()
{
// Arrange
var concentratorValidator = new ConcentratorValidator();
- var concentrator = new Concentrator()
+ var concentrator = new ConcentratorDto()
{
DeviceId = "0123456789abcdef",
DeviceName = Guid.NewGuid().ToString(),
@@ -126,7 +126,7 @@ public void ValidateAllFieldsEmptyShouldReturnError()
{
// Arrange
var concentratorValidator = new ConcentratorValidator();
- var concentrator = new Concentrator();
+ var concentrator = new ConcentratorDto();
// Act
var concentratorValidation = concentratorValidator.Validate(concentrator);
diff --git a/src/AzureIoTHub.Portal.Tests.Unit/Server/Controllers/v1.0/LoRaWAN/LoRaWANConcentratorsControllerTest.cs b/src/AzureIoTHub.Portal.Tests.Unit/Server/Controllers/v1.0/LoRaWAN/LoRaWANConcentratorsControllerTest.cs
index c97875da4..17a61f1dd 100644
--- a/src/AzureIoTHub.Portal.Tests.Unit/Server/Controllers/v1.0/LoRaWAN/LoRaWANConcentratorsControllerTest.cs
+++ b/src/AzureIoTHub.Portal.Tests.Unit/Server/Controllers/v1.0/LoRaWAN/LoRaWANConcentratorsControllerTest.cs
@@ -83,9 +83,9 @@ public async Task GetAllDeviceConcentratorWithDeviceTypeShouldReturnNotEmptyList
});
_ = this.mockLoRaWANConcentratorService.Setup(c => c.GetAllDeviceConcentrator(It.IsAny>(), It.IsAny()))
- .Returns((PaginationResult r, IUrlHelper h) => new PaginationResult
+ .Returns((PaginationResult r, IUrlHelper h) => new PaginationResult
{
- Items = r.Items.Select(x => new Concentrator { DeviceId = x.DeviceId }),
+ Items = r.Items.Select(x => new ConcentratorDto { DeviceId = x.DeviceId }),
NextPage = r.NextPage,
TotalItems = r.TotalItems
});
@@ -101,7 +101,7 @@ public async Task GetAllDeviceConcentratorWithDeviceTypeShouldReturnNotEmptyList
Assert.IsNotNull(okObjectResult);
Assert.AreEqual(200, okObjectResult.StatusCode);
Assert.IsNotNull(okObjectResult.Value);
- var deviceList = okObjectResult.Value as PaginationResult;
+ var deviceList = okObjectResult.Value as PaginationResult;
Assert.IsNotNull(deviceList);
Assert.AreEqual(count, deviceList.Items.Count());
@@ -116,9 +116,9 @@ public async Task GetAllDeviceConcentratorWithNoDeviceTypeShouldReturnEmptyList(
var concentratorsController = CreateLoRaWANConcentratorsController();
_ = this.mockLoRaWANConcentratorService.Setup(c => c.GetAllDeviceConcentrator(It.IsAny>(), It.IsAny()))
- .Returns((PaginationResult r, IUrlHelper h) => new PaginationResult
+ .Returns((PaginationResult r, IUrlHelper h) => new PaginationResult
{
- Items = r.Items.Select(x => new Concentrator { DeviceId = x.DeviceId }),
+ Items = r.Items.Select(x => new ConcentratorDto { DeviceId = x.DeviceId }),
NextPage = r.NextPage,
TotalItems = r.TotalItems
});
@@ -147,7 +147,7 @@ public async Task GetAllDeviceConcentratorWithNoDeviceTypeShouldReturnEmptyList(
Assert.IsNotNull(okObjectResult);
Assert.AreEqual(200, okObjectResult.StatusCode);
- var deviceList = okObjectResult.Value as IEnumerable;
+ var deviceList = okObjectResult.Value as IEnumerable;
Assert.IsNull(deviceList);
@@ -186,7 +186,7 @@ public async Task GetDeviceConcentratorWithValidArgumentShouldReturnConcentrator
// Arrange
var twin = new Twin("aaa");
twin.Tags["deviceType"] = "LoRa Concentrator";
- var concentrator = new Concentrator
+ var concentrator = new ConcentratorDto
{
DeviceId = twin.DeviceId,
DeviceType = "LoRa Concentrator"
@@ -211,8 +211,8 @@ public async Task GetDeviceConcentratorWithValidArgumentShouldReturnConcentrator
Assert.IsNotNull(okObjectResult);
Assert.AreEqual(200, okObjectResult.StatusCode);
Assert.IsNotNull(okObjectResult.Value);
- Assert.IsAssignableFrom(okObjectResult.Value);
- var device = okObjectResult.Value as Concentrator;
+ Assert.IsAssignableFrom(okObjectResult.Value);
+ var device = okObjectResult.Value as ConcentratorDto;
Assert.IsNotNull(device);
Assert.AreEqual(twin.DeviceId, device.DeviceId);
Assert.AreEqual("LoRa Concentrator", device.DeviceType);
@@ -246,7 +246,7 @@ public async Task CreateDeviceAsyncWithValidArgumentShouldReturnOkResult()
{
// Arrange
var concentratorController = CreateLoRaWANConcentratorsController();
- var concentrator = new Concentrator
+ var concentrator = new ConcentratorDto
{
DeviceId = "4512457896451156",
LoraRegion = Guid.NewGuid().ToString(),
@@ -272,7 +272,7 @@ public async Task WhenDeviceCreationFailedShouldReturnBadRequest()
{
// Arrange
var concentratorController = CreateLoRaWANConcentratorsController();
- var concentrator = new Concentrator
+ var concentrator = new ConcentratorDto
{
DeviceId = "4512457896451156",
LoraRegion = Guid.NewGuid().ToString(),
@@ -300,7 +300,7 @@ public async Task WhenDeviceAlreadyExistsShouldReturnBadRequestWithAltreadyExist
{
// Arrange
var concentratorController = CreateLoRaWANConcentratorsController();
- var concentrator = new Concentrator
+ var concentrator = new ConcentratorDto
{
DeviceId = "4512457896451156",
LoraRegion = Guid.NewGuid().ToString(),
@@ -329,7 +329,7 @@ public async Task UpdateDeviceAsyncWithValidArgumentShouldReturnOkResult()
{
// Arrange
var concentratorController = CreateLoRaWANConcentratorsController();
- var concentrator = new Concentrator
+ var concentrator = new ConcentratorDto
{
DeviceId = "4512457896451156",
LoraRegion = Guid.NewGuid().ToString(),
@@ -337,7 +337,7 @@ public async Task UpdateDeviceAsyncWithValidArgumentShouldReturnOkResult()
RouterConfig = new RouterConfig()
};
- _ = this.mockLoRaWANConcentratorService.Setup(x => x.UpdateDeviceAsync(It.Is(c => c == concentrator)))
+ _ = this.mockLoRaWANConcentratorService.Setup(x => x.UpdateDeviceAsync(It.Is(c => c == concentrator)))
.ReturnsAsync(true);
// Act
diff --git a/src/AzureIoTHub.Portal.Tests.Unit/Server/Helpers/DeviceHelperTests.cs b/src/AzureIoTHub.Portal.Tests.Unit/Server/Helpers/DeviceHelperTests.cs
index 9957c0934..036d22f7a 100644
--- a/src/AzureIoTHub.Portal.Tests.Unit/Server/Helpers/DeviceHelperTests.cs
+++ b/src/AzureIoTHub.Portal.Tests.Unit/Server/Helpers/DeviceHelperTests.cs
@@ -5,6 +5,8 @@ namespace AzureIoTHub.Portal.Tests.Unit.Server.Helpers
{
using System;
using System.Collections.Generic;
+ using AzureIoTHub.Portal.Domain.Entities;
+ using AzureIoTHub.Portal.Server.Extensions;
using AzureIoTHub.Portal.Server.Helpers;
using FluentAssertions;
using Microsoft.Azure.Devices.Provisioning.Service;
@@ -437,5 +439,75 @@ public void RetrievePropertyValueEmptyTwinReturnsNull()
// Assert
Assert.IsNull(result);
}
+
+ [Test]
+ public void RetrieveClientThumbprintShouldReturnClientThumbprintValue()
+ {
+ // Arrange
+ var expectedThumbprint = Guid.NewGuid().ToString();
+ var twin = new Twin
+ {
+ DeviceId = Guid.NewGuid().ToString()
+ };
+ twin.Properties.Desired[nameof(Concentrator.ClientThumbprint).ToCamelCase()] = new List() { expectedThumbprint };
+
+
+ // Act
+ var result = DeviceHelper.RetrieveClientThumbprintValue(twin);
+
+ // Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual(expectedThumbprint, result);
+ }
+
+ [Test]
+ public void RetrieveClientThumbprintValueNotExistShouldReturnNull()
+ {
+ // Arrange
+ var twin = new Twin
+ {
+ DeviceId = Guid.NewGuid().ToString()
+ };
+
+ // Act
+ var result = DeviceHelper.RetrieveClientThumbprintValue(twin);
+
+ // Assert
+ Assert.IsNull(result);
+ }
+
+ [Test]
+ public void RetrieveClientThumbprintValueEmptyArrayShouldReturnNull()
+ {
+ // Arrange
+ var twin = new Twin
+ {
+ DeviceId = Guid.NewGuid().ToString()
+ };
+ twin.Properties.Desired[nameof(Concentrator.ClientThumbprint).ToCamelCase()] = new List();
+
+ // Act
+ var result = DeviceHelper.RetrieveClientThumbprintValue(twin);
+
+ // Assert
+ Assert.IsNull(result);
+ }
+
+ [Test]
+ public void CreateDeviceDetailsClientThumbprintBadFormatShouldReturnNull()
+ {
+ // Arrange
+ var twin = new Twin
+ {
+ DeviceId = Guid.NewGuid().ToString()
+ };
+ twin.Properties.Desired[nameof(Concentrator.ClientThumbprint).ToCamelCase()] = Guid.NewGuid().ToString();
+
+ // Act
+ var result = DeviceHelper.RetrieveClientThumbprintValue(twin);
+
+ // Assert
+ Assert.IsNull(result);
+ }
}
}
diff --git a/src/AzureIoTHub.Portal.Tests.Unit/Server/Jobs/SyncConcentratorsJobTests.cs b/src/AzureIoTHub.Portal.Tests.Unit/Server/Jobs/SyncConcentratorsJobTests.cs
new file mode 100644
index 000000000..a19f81b66
--- /dev/null
+++ b/src/AzureIoTHub.Portal.Tests.Unit/Server/Jobs/SyncConcentratorsJobTests.cs
@@ -0,0 +1,215 @@
+// 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.Server.Jobs
+{
+ using System.Collections.Generic;
+ using System.Threading.Tasks;
+ using AutoFixture;
+ using AzureIoTHub.Portal.Domain;
+ using AzureIoTHub.Portal.Domain.Repositories;
+ using AzureIoTHub.Portal.Server.Jobs;
+ using AzureIoTHub.Portal.Server.Services;
+ using Microsoft.Azure.Devices.Shared;
+ using Microsoft.Extensions.DependencyInjection;
+ using Moq;
+ using NUnit.Framework;
+ using Portal.Domain.Entities;
+ using Quartz;
+ using UnitTests.Bases;
+
+ public class SyncConcentratorsTests : BackendUnitTest
+ {
+ private IJob syncConcentratorsJob;
+
+ private Mock mockExternalDeviceService;
+ private Mock mockConcentratorRepository;
+ private Mock mockUnitOfWork;
+
+ public override void Setup()
+ {
+ base.Setup();
+
+ this.mockExternalDeviceService = MockRepository.Create();
+ this.mockConcentratorRepository = MockRepository.Create();
+ this.mockUnitOfWork = MockRepository.Create();
+
+ _ = ServiceCollection.AddSingleton(this.mockExternalDeviceService.Object);
+ _ = ServiceCollection.AddSingleton(this.mockConcentratorRepository.Object);
+ _ = ServiceCollection.AddSingleton(this.mockUnitOfWork.Object);
+ _ = ServiceCollection.AddSingleton();
+
+ Services = ServiceCollection.BuildServiceProvider();
+
+ this.syncConcentratorsJob = Services.GetRequiredService();
+ }
+
+ [Test]
+ public async Task ExecuteNewConcentratorShouldCreateEntity()
+ {
+ // Arrange
+ var mockJobExecutionContext = MockRepository.Create();
+
+ var expectedTwinConcentrator = new Twin
+ {
+ DeviceId = Fixture.Create(),
+ Tags = new TwinCollection
+ {
+ ["deviceName"] = Fixture.Create(),
+ ["loraRegion"] = Fixture.Create(),
+ ["deviceType"] = Fixture.Create(),
+ ["clientThumbprint"] = Fixture.Create()
+ }
+ };
+
+ _ = this.mockExternalDeviceService
+ .Setup(x => x.GetAllDevice(
+ It.IsAny(),
+ It.Is(x => x == "LoRa Concentrator"),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny>(),
+ It.Is(x => x == 100)))
+ .ReturnsAsync(new PaginationResult
+ {
+ Items = new List
+ {
+ expectedTwinConcentrator
+ },
+ TotalItems = 1
+ });
+
+ _ = this.mockConcentratorRepository.Setup(repository => repository.GetByIdAsync(expectedTwinConcentrator.DeviceId))
+ .ReturnsAsync((Concentrator)null);
+
+ _ = this.mockConcentratorRepository.Setup(repository => repository.InsertAsync(It.IsAny()))
+ .Returns(Task.CompletedTask);
+
+ _ = this.mockUnitOfWork.Setup(work => work.SaveAsync())
+ .Returns(Task.CompletedTask);
+
+ // Act
+ await this.syncConcentratorsJob.Execute(mockJobExecutionContext.Object);
+
+ // Assert
+ MockRepository.VerifyAll();
+ }
+
+ [Test]
+ public async Task ExecuteExistingConcentratorWithGreaterVersionShouldUpdateEntity()
+ {
+ // Arrange
+ var mockJobExecutionContext = MockRepository.Create();
+
+ var expectedTwinConcentrator = new Twin
+ {
+ DeviceId = Fixture.Create(),
+ Tags = new TwinCollection
+ {
+ ["deviceName"] = Fixture.Create(),
+ ["loraRegion"] = Fixture.Create(),
+ ["deviceType"] = Fixture.Create()
+ },
+ Version = 2
+ };
+
+ var existingConcentrator = new Concentrator
+ {
+ Id = expectedTwinConcentrator.DeviceId,
+ Version = 1,
+ };
+
+ _ = this.mockExternalDeviceService
+ .Setup(x => x.GetAllDevice(
+ It.IsAny(),
+ It.Is(x => x == "LoRa Concentrator"),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny>(),
+ It.Is(x => x == 100)))
+ .ReturnsAsync(new PaginationResult
+ {
+ Items = new List
+ {
+ expectedTwinConcentrator
+ },
+ TotalItems = 1
+ });
+
+ _ = this.mockConcentratorRepository.Setup(repository => repository.GetByIdAsync(expectedTwinConcentrator.DeviceId))
+ .ReturnsAsync(existingConcentrator);
+
+ this.mockConcentratorRepository.Setup(repository => repository.Update(It.IsAny()))
+ .Verifiable();
+
+ _ = this.mockUnitOfWork.Setup(work => work.SaveAsync())
+ .Returns(Task.CompletedTask);
+
+ // Act
+ await this.syncConcentratorsJob.Execute(mockJobExecutionContext.Object);
+
+ // Assert
+ MockRepository.VerifyAll();
+ }
+
+ [Test]
+ public async Task ExecuteExistingConcentratorWithLowerOrEqualVersionShouldReturn()
+ {
+ // Arrange
+ var mockJobExecutionContext = MockRepository.Create();
+
+ var expectedTwinConcentrator = new Twin
+ {
+ DeviceId = Fixture.Create(),
+ Tags = new TwinCollection
+ {
+ ["deviceName"] = Fixture.Create(),
+ ["loraRegion"] = Fixture.Create(),
+ ["deviceType"] = Fixture.Create()
+ },
+ Version = 1
+ };
+
+ var existingConcentrator = new Concentrator
+ {
+ Id = expectedTwinConcentrator.DeviceId,
+ Version = 1,
+ };
+
+ _ = this.mockExternalDeviceService
+ .Setup(x => x.GetAllDevice(
+ It.IsAny(),
+ It.Is(x => x == "LoRa Concentrator"),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny>(),
+ It.Is(x => x == 100)))
+ .ReturnsAsync(new PaginationResult
+ {
+ Items = new List
+ {
+ expectedTwinConcentrator
+ },
+ TotalItems = 1
+ });
+
+ _ = this.mockConcentratorRepository.Setup(repository => repository.GetByIdAsync(expectedTwinConcentrator.DeviceId))
+ .ReturnsAsync(existingConcentrator);
+
+ _ = this.mockUnitOfWork.Setup(work => work.SaveAsync())
+ .Returns(Task.CompletedTask);
+
+ // Act
+ await this.syncConcentratorsJob.Execute(mockJobExecutionContext.Object);
+
+ // Assert
+ MockRepository.VerifyAll();
+ }
+ }
+}
diff --git a/src/AzureIoTHub.Portal.Tests.Unit/Server/Jobs/SyncDeviceJobTests.cs b/src/AzureIoTHub.Portal.Tests.Unit/Server/Jobs/SyncDevicesJobTests.cs
similarity index 99%
rename from src/AzureIoTHub.Portal.Tests.Unit/Server/Jobs/SyncDeviceJobTests.cs
rename to src/AzureIoTHub.Portal.Tests.Unit/Server/Jobs/SyncDevicesJobTests.cs
index 495236d18..8d47d9203 100644
--- a/src/AzureIoTHub.Portal.Tests.Unit/Server/Jobs/SyncDeviceJobTests.cs
+++ b/src/AzureIoTHub.Portal.Tests.Unit/Server/Jobs/SyncDevicesJobTests.cs
@@ -18,7 +18,7 @@ namespace AzureIoTHub.Portal.Tests.Unit.Server.Jobs
using Quartz;
using UnitTests.Bases;
- public class SyncDeviceJobTests : BackendUnitTest
+ public class SyncDevicesJobTests : BackendUnitTest
{
private IJob syncDevicesJob;
diff --git a/src/AzureIoTHub.Portal.Tests.Unit/Server/Mappers/ConcentratorTwinMapperTests.cs b/src/AzureIoTHub.Portal.Tests.Unit/Server/Mappers/ConcentratorTwinMapperTests.cs
index a5ccfe7d2..617441cdb 100644
--- a/src/AzureIoTHub.Portal.Tests.Unit/Server/Mappers/ConcentratorTwinMapperTests.cs
+++ b/src/AzureIoTHub.Portal.Tests.Unit/Server/Mappers/ConcentratorTwinMapperTests.cs
@@ -53,13 +53,13 @@ public void CreateDeviceDetailsStateUnderTestExpectedBehavior()
DeviceId = Guid.NewGuid().ToString()
};
- twin.Tags[nameof(Concentrator.DeviceType).ToCamelCase()] = Guid.NewGuid().ToString();
- twin.Tags[nameof(Concentrator.DeviceName).ToCamelCase()] = Guid.NewGuid().ToString();
- twin.Tags[nameof(Concentrator.LoraRegion).ToCamelCase()] = Guid.NewGuid().ToString();
+ twin.Tags[nameof(ConcentratorDto.DeviceType).ToCamelCase()] = Guid.NewGuid().ToString();
+ twin.Tags[nameof(ConcentratorDto.DeviceName).ToCamelCase()] = Guid.NewGuid().ToString();
+ twin.Tags[nameof(ConcentratorDto.LoraRegion).ToCamelCase()] = Guid.NewGuid().ToString();
twin.Properties.Reported["DevAddr"] = Guid.NewGuid().ToString();
- twin.Properties.Desired[nameof(Concentrator.ClientThumbprint).ToCamelCase()] = new List() { Guid.NewGuid().ToString() };
+ twin.Properties.Desired[nameof(ConcentratorDto.ClientThumbprint).ToCamelCase()] = new List() { Guid.NewGuid().ToString() };
// Act
var result = concentratorTwinMapper.CreateDeviceDetails(twin);
@@ -70,72 +70,13 @@ public void CreateDeviceDetailsStateUnderTestExpectedBehavior()
Assert.IsFalse(result.IsConnected);
Assert.IsFalse(result.IsEnabled);
- Assert.AreEqual(twin.Tags[nameof(Concentrator.DeviceName).ToCamelCase()].ToString(), result.DeviceName);
- Assert.AreEqual(twin.Tags[nameof(Concentrator.LoraRegion).ToCamelCase()].ToString(), result.LoraRegion);
- Assert.AreEqual(twin.Tags[nameof(Concentrator.DeviceType).ToCamelCase()].ToString(), result.DeviceType);
+ Assert.AreEqual(twin.Tags[nameof(ConcentratorDto.DeviceName).ToCamelCase()].ToString(), result.DeviceName);
+ Assert.AreEqual(twin.Tags[nameof(ConcentratorDto.LoraRegion).ToCamelCase()].ToString(), result.LoraRegion);
+ Assert.AreEqual(twin.Tags[nameof(ConcentratorDto.DeviceType).ToCamelCase()].ToString(), result.DeviceType);
Assert.IsTrue(result.AlreadyLoggedInOnce);
- Assert.AreEqual(twin.Properties.Desired[nameof(Concentrator.ClientThumbprint).ToCamelCase()][0].ToString(), result.ClientThumbprint);
- this.mockRepository.VerifyAll();
- }
-
- [Test]
- public void CreateDeviceDetailsClientThumbprintNotExistExpectedBehavior()
- {
- // Arrange
- var concentratorTwinMapper = CreateConcentratorTwinMapper();
- var twin = new Twin
- {
- DeviceId = Guid.NewGuid().ToString()
- };
-
- // Act
- var result = concentratorTwinMapper.CreateDeviceDetails(twin);
-
- // Assert
- Assert.IsNotNull(result);
- Assert.IsNull(result.ClientThumbprint);
- this.mockRepository.VerifyAll();
- }
-
- [Test]
- public void CreateDeviceDetailsClientThumbprintEmptyArrayExpectedBehavior()
- {
- // Arrange
- var concentratorTwinMapper = CreateConcentratorTwinMapper();
- var twin = new Twin
- {
- DeviceId = Guid.NewGuid().ToString()
- };
- twin.Properties.Desired[nameof(Concentrator.ClientThumbprint).ToCamelCase()] = new List();
-
- // Act
- var result = concentratorTwinMapper.CreateDeviceDetails(twin);
-
- // Assert
- Assert.IsNotNull(result);
- Assert.IsNull(result.ClientThumbprint);
- this.mockRepository.VerifyAll();
- }
-
- [Test]
- public void CreateDeviceDetailsClientThumbprintBadFormatExpectedBehavior()
- {
- // Arrange
- var concentratorTwinMapper = CreateConcentratorTwinMapper();
- var twin = new Twin
- {
- DeviceId = Guid.NewGuid().ToString()
- };
- twin.Properties.Desired[nameof(Concentrator.ClientThumbprint).ToCamelCase()] = Guid.NewGuid().ToString();
-
- // Act
- var result = concentratorTwinMapper.CreateDeviceDetails(twin);
-
- // Assert
- Assert.IsNotNull(result);
- Assert.IsNull(result.ClientThumbprint);
+ Assert.AreEqual(twin.Properties.Desired[nameof(ConcentratorDto.ClientThumbprint).ToCamelCase()][0].ToString(), result.ClientThumbprint);
this.mockRepository.VerifyAll();
}
@@ -147,7 +88,7 @@ public void UpdateTwinStateUnderTestExpectedBehavior()
var twin = new Twin();
- var item = new Concentrator
+ var item = new ConcentratorDto
{
LoraRegion = Guid.NewGuid().ToString(),
DeviceName = Guid.NewGuid().ToString(),
@@ -173,17 +114,17 @@ public void UpdateTwinStateUnderTestExpectedBehavior()
DeviceHelper.SetTagValue(twin, nameof(item.DeviceType), item.DeviceType);
DeviceHelper.SetTagValue(twin, nameof(item.LoraRegion), item.LoraRegion);
- twin.Properties.Desired[nameof(Concentrator.ClientThumbprint).ToCamelCase()] = new List() { item.ClientThumbprint };
+ twin.Properties.Desired[nameof(ConcentratorDto.ClientThumbprint).ToCamelCase()] = new List() { item.ClientThumbprint };
// Act
concentratorTwinMapper.UpdateTwin(twin, item);
// Assert
- Assert.AreEqual(item.DeviceName, twin.Tags[nameof(Concentrator.DeviceName).ToCamelCase()].ToString());
- Assert.AreEqual(item.DeviceType, twin.Tags[nameof(Concentrator.DeviceType).ToCamelCase()].ToString());
- Assert.AreEqual(item.LoraRegion, twin.Tags[nameof(Concentrator.LoraRegion).ToCamelCase()].ToString());
+ Assert.AreEqual(item.DeviceName, twin.Tags[nameof(ConcentratorDto.DeviceName).ToCamelCase()].ToString());
+ Assert.AreEqual(item.DeviceType, twin.Tags[nameof(ConcentratorDto.DeviceType).ToCamelCase()].ToString());
+ Assert.AreEqual(item.LoraRegion, twin.Tags[nameof(ConcentratorDto.LoraRegion).ToCamelCase()].ToString());
- Assert.AreEqual(item.ClientThumbprint, twin.Properties.Desired[nameof(Concentrator.ClientThumbprint).ToCamelCase()][0].ToString());
+ Assert.AreEqual(item.ClientThumbprint, twin.Properties.Desired[nameof(ConcentratorDto.ClientThumbprint).ToCamelCase()][0].ToString());
this.mockRepository.VerifyAll();
}
diff --git a/src/AzureIoTHub.Portal.Tests.Unit/Server/Services/LoRaWANConcentratorServiceTests.cs b/src/AzureIoTHub.Portal.Tests.Unit/Server/Services/LoRaWANConcentratorServiceTests.cs
index 792d0521b..feee15180 100644
--- a/src/AzureIoTHub.Portal.Tests.Unit/Server/Services/LoRaWANConcentratorServiceTests.cs
+++ b/src/AzureIoTHub.Portal.Tests.Unit/Server/Services/LoRaWANConcentratorServiceTests.cs
@@ -58,7 +58,7 @@ public async Task CreateDeviceAsyncWithValidArgumentShouldReturnOkResult()
{
// Arrange
var concentratorController = CreateLoRaWANConcentratorService();
- var concentrator = new Concentrator
+ var concentrator = new ConcentratorDto
{
DeviceId = "4512457896451156",
LoraRegion = Guid.NewGuid().ToString(),
@@ -86,7 +86,7 @@ public async Task CreateDeviceAsyncWithValidArgumentShouldReturnOkResult()
_ = this.mockRouterConfigManager.Setup(x => x.GetRouterConfig(It.Is(c => c == concentrator.LoraRegion)))
.ReturnsAsync(routerConfig);
- _ = this.mockConcentratorTwinMapper.Setup(x => x.UpdateTwin(It.Is(c => c.DeviceId == twin.DeviceId), It.Is(c => c.DeviceId == concentrator.DeviceId)));
+ _ = this.mockConcentratorTwinMapper.Setup(x => x.UpdateTwin(It.Is(c => c.DeviceId == twin.DeviceId), It.Is(c => c.DeviceId == concentrator.DeviceId)));
// Act
var result = await concentratorController.CreateDeviceAsync(concentrator);
@@ -103,7 +103,7 @@ public void WhenDeviceAlreadyExistCreateDeviceAsyncWithValidArgumentShouldThrowA
{
// Arrange
var concentratorController = CreateLoRaWANConcentratorService();
- var concentrator = new Concentrator
+ var concentrator = new ConcentratorDto
{
DeviceId = "4512457896451156",
LoraRegion = Guid.NewGuid().ToString(),
@@ -127,7 +127,7 @@ public void WhenDeviceAlreadyExistCreateDeviceAsyncWithValidArgumentShouldThrowA
_ = this.mockRouterConfigManager.Setup(x => x.GetRouterConfig(It.Is(c => c == concentrator.LoraRegion)))
.ReturnsAsync(routerConfig);
- _ = this.mockConcentratorTwinMapper.Setup(x => x.UpdateTwin(It.Is(c => c.DeviceId == twin.DeviceId), It.Is(c => c.DeviceId == concentrator.DeviceId)));
+ _ = this.mockConcentratorTwinMapper.Setup(x => x.UpdateTwin(It.Is(c => c.DeviceId == twin.DeviceId), It.Is(c => c.DeviceId == concentrator.DeviceId)));
_ = this.mockLogger.Setup(x => x.Log(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>()));
// Act
@@ -142,7 +142,7 @@ public async Task WhenDeviceCreationFailedWithInvalidOperationExceptionShouldRet
{
// Arrange
var concentratorController = CreateLoRaWANConcentratorService();
- var concentrator = new Concentrator
+ var concentrator = new ConcentratorDto
{
DeviceId = "4512457896451156",
LoraRegion = Guid.NewGuid().ToString(),
@@ -166,7 +166,7 @@ public async Task WhenDeviceCreationFailedWithInvalidOperationExceptionShouldRet
_ = this.mockRouterConfigManager.Setup(x => x.GetRouterConfig(It.Is(c => c == concentrator.LoraRegion)))
.ReturnsAsync(routerConfig);
- _ = this.mockConcentratorTwinMapper.Setup(x => x.UpdateTwin(It.Is