Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visual changes on device details #474

Merged
merged 6 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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