Skip to content

Commit

Permalink
Visual changes on device details (#474)
Browse files Browse the repository at this point in the history
* Moved button and tabs, added expansion panels

* New display on LoRaWAN details page

* Changed tabs' titles

* Fixed validation issues

* Added unit tests on LoraDeviceDetailsValidator

* Removed useless function
  • Loading branch information
audserraCGI authored Mar 22, 2022
1 parent 882c0b7 commit 4fd449f
Show file tree
Hide file tree
Showing 7 changed files with 468 additions and 290 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace AzureIoTHub.Portal.Server.Tests.Unit.Services
using NUnit.Framework;

[TestFixture]
public class DeviceTagServiceTest
public class DeviceTagServiceTests
{
private MockRepository mockRepository;
private Mock<IDeviceTagMapper> mockDeviceTagMapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// 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.Validators
{
using System;
using AzureIoTHub.Portal.Client.Validators;
using AzureIoTHub.Portal.Models.v10.LoRaWAN;
using NUnit.Framework;

[TestFixture]
internal class LoRaDeviceDetailsValidatorTests
{
[Test]
public void ValidateValidOTAAModel()
{

// Arrange
var loraValidator = new LoRaDeviceDetailsValidator();
var loraDevice = new LoRaDeviceDetails()
{
ModelId = Guid.NewGuid().ToString(),
UseOTAA = true,
AppEUI = Guid.NewGuid().ToString(),
AppKey = Guid.NewGuid().ToString()
};

// Act
var loraValidation = loraValidator.Validate(loraDevice);

// Assert
Assert.IsTrue(loraValidation.IsValid);
Assert.AreEqual(0, loraValidation.Errors.Count);
}

[Test]
public void ValidateValidAPBModel()
{

// Arrange
var loraValidator = new LoRaDeviceDetailsValidator();
var loraDevice = new LoRaDeviceDetails()
{
ModelId = Guid.NewGuid().ToString(),
UseOTAA = false,
AppSKey = Guid.NewGuid().ToString(),
NwkSKey = Guid.NewGuid().ToString(),
DevAddr = Guid.NewGuid().ToString()
};

// Act
var loraValidation = loraValidator.Validate(loraDevice);

// Assert
Assert.IsTrue(loraValidation.IsValid);
Assert.AreEqual(0, loraValidation.Errors.Count);
}

[Test]
public void ValidateMissingModelIdShouldReturnError()
{
// Arrange
var loraValidator = new LoRaDeviceDetailsValidator();
var loraDevice = new LoRaDeviceDetails()
{
UseOTAA = false,
AppSKey = Guid.NewGuid().ToString(),
NwkSKey = Guid.NewGuid().ToString(),
DevAddr = Guid.NewGuid().ToString()
};

// Act
var loraValidation = loraValidator.Validate(loraDevice);

// Assert
Assert.IsFalse(loraValidation.IsValid);
Assert.AreEqual(1, loraValidation.Errors.Count);
Assert.AreEqual(loraValidation.Errors[0].ErrorMessage, "ModelId is required.");
}

[TestCase("AppSKey", "", "NwkSKeyValue", "DevAddrValue")]
[TestCase("NwkSKey", "AppSKeyValue", "", "DevAddrValue")]
[TestCase("DevAddr", "AppSKeyValue", "NwkSKeyValue", "")]
public void ValidateMissingAPBFieldShouldReturnError(
string testedValue,
string AppSkeyValue,
string NwkSKeyValue,
string DevAddrValue)
{
// Arrange
var loraValidator = new LoRaDeviceDetailsValidator();
var loraDevice = new LoRaDeviceDetails()
{
ModelId = Guid.NewGuid().ToString(),
UseOTAA = false,
AppSKey = AppSkeyValue,
NwkSKey = NwkSKeyValue,
DevAddr = DevAddrValue
};

// Act
var loraValidation = loraValidator.Validate(loraDevice);

// Assert
Assert.IsFalse(loraValidation.IsValid);
Assert.AreEqual(1, loraValidation.Errors.Count);
Assert.AreEqual(loraValidation.Errors[0].ErrorMessage, $"{testedValue} is required.");
}

[TestCase("AppEUI", "", "AppKeyValue")]
[TestCase("AppKey", "AppEUIValue", "")]
public void ValidateMissingOTAAFieldShouldReturnError(
string testedValue,
string AppEUIValue,
string AppKeyValue)
{
// Arrange
var loraValidator = new LoRaDeviceDetailsValidator();
var loraDevice = new LoRaDeviceDetails()
{
ModelId = Guid.NewGuid().ToString(),
UseOTAA = true,
AppEUI = AppEUIValue,
AppKey = AppKeyValue
};

// Act
var loraValidation = loraValidator.Validate(loraDevice);

// Assert
Assert.IsFalse(loraValidation.IsValid);
Assert.AreEqual(1, loraValidation.Errors.Count);
Assert.AreEqual(loraValidation.Errors[0].ErrorMessage, $"{testedValue} is required.");
}
}
}
Loading

0 comments on commit 4fd449f

Please sign in to comment.