-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Visual changes on device details (#474)
* 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
1 parent
882c0b7
commit 4fd449f
Showing
7 changed files
with
468 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
src/AzureIoTHub.Portal.Server.Tests.Unit/Validators/LoRaDeviceDetailsValidatorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} | ||
} |
Oops, something went wrong.