-
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 Model pages (#496)
* Visual changes on general tab * Visual changes on LoRa tab * Id on MudExpansionPanel rather than MudGrid * Unit tests on DeviceModelValidator * Fixed property valdiation when fields are empty * Added unit test * Added unit test on LoRaDeviceModelValidator * Visual changes on create device model * Added delete model button on DeviceModelDetailPage * Larger columns for picture on DeviceModel pages + Fix title on CreateDeviceModelPage * WhenLoraDeviceModelDetailsShouldCallLoRaAPIs() temporarily commented, waited for issue to be fixed * Fixed unused variable
- Loading branch information
1 parent
3c207d7
commit 51bba13
Showing
13 changed files
with
884 additions
and
592 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
47 changes: 47 additions & 0 deletions
47
src/AzureIoTHub.Portal.Server.Tests.Unit/Validators/DeviceModelValidatorTests.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,47 @@ | ||
// 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; | ||
using NUnit.Framework; | ||
|
||
internal class DeviceModelValidatorTests | ||
{ | ||
[Test] | ||
public void ValidateValidModel() | ||
{ | ||
|
||
// Arrange | ||
var standardModelValidator = new DeviceModelValidator(); | ||
var deviceModel = new DeviceModel() | ||
{ | ||
Name = Guid.NewGuid().ToString(), | ||
}; | ||
|
||
// Act | ||
var standardModelValidation = standardModelValidator.Validate(deviceModel); | ||
|
||
// Assert | ||
Assert.IsTrue(standardModelValidation.IsValid); | ||
Assert.AreEqual(0, standardModelValidation.Errors.Count); | ||
} | ||
|
||
[Test] | ||
public void ValidateMissingNameShouldReturnError() | ||
{ | ||
// Arrange | ||
var standardModelValidator = new DeviceModelValidator(); | ||
var deviceModel = new DeviceModel(); | ||
|
||
// Act | ||
var standardModelValidation = standardModelValidator.Validate(deviceModel); | ||
|
||
// Assert | ||
Assert.IsFalse(standardModelValidation.IsValid); | ||
Assert.AreEqual(standardModelValidation.Errors[0].ErrorMessage, $"Model name is required."); | ||
} | ||
} | ||
} |
146 changes: 146 additions & 0 deletions
146
src/AzureIoTHub.Portal.Server.Tests.Unit/Validators/DevicePropertyValidatorTests.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,146 @@ | ||
// 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 System.Collections.Generic; | ||
using AzureIoTHub.Portal.Client.Validators; | ||
using AzureIoTHub.Portal.Models; | ||
using AzureIoTHub.Portal.Models.v10; | ||
using NUnit.Framework; | ||
|
||
internal class DevicePropertyValidatorTests | ||
{ | ||
[Test] | ||
public void ValidateValidProperties() | ||
{ | ||
|
||
// Arrange | ||
var propertiesValidator = new DevicePropertyValidator(); | ||
var properties = new List<DeviceProperty>(){ | ||
new DeviceProperty() | ||
{ | ||
DisplayName = Guid.NewGuid().ToString(), | ||
Name = Guid.NewGuid().ToString(), | ||
PropertyType = DevicePropertyType.Integer, | ||
IsWritable = true | ||
}, | ||
new DeviceProperty() | ||
{ | ||
DisplayName = Guid.NewGuid().ToString(), | ||
Name = Guid.NewGuid().ToString(), | ||
PropertyType = DevicePropertyType.Integer, | ||
IsWritable = true | ||
} | ||
}; | ||
|
||
// Act | ||
var propertiesValidation = propertiesValidator.Validate(properties); | ||
|
||
// Assert | ||
Assert.IsTrue(propertiesValidation.IsValid); | ||
Assert.AreEqual(0, propertiesValidation.Errors.Count); | ||
} | ||
|
||
[TestCase("DisplayName", "", "NameValue")] | ||
[TestCase("Name", "DisplayNameValue", "")] | ||
public void ValidateMissingFieldShouldReturnError( | ||
string testedValue, | ||
string DisplayNameValue, | ||
string NameValue) | ||
{ | ||
|
||
// Arrange | ||
var propertiesValidator = new DevicePropertyValidator(); | ||
var properties = new List<DeviceProperty>(){ | ||
new DeviceProperty() | ||
{ | ||
DisplayName = DisplayNameValue, | ||
Name = NameValue, | ||
PropertyType = DevicePropertyType.Integer, | ||
IsWritable = true | ||
} | ||
}; | ||
|
||
// Act | ||
var propertiesValidation = propertiesValidator.Validate(properties); | ||
|
||
// Assert | ||
Assert.IsFalse(propertiesValidation.IsValid); | ||
Assert.AreEqual(1, propertiesValidation.Errors.Count); | ||
Assert.AreEqual(propertiesValidation.Errors[0].ErrorMessage, $"Property {testedValue} is required."); | ||
} | ||
|
||
[Test] | ||
public void ValidateAllFieldsEmptyShouldReturnError() | ||
{ | ||
|
||
// Arrange | ||
var propertiesValidator = new DevicePropertyValidator(); | ||
var properties = new List<DeviceProperty>(){ | ||
new DeviceProperty(), | ||
}; | ||
|
||
// Act | ||
var propertiesValidation = propertiesValidator.Validate(properties); | ||
|
||
// Assert | ||
Assert.IsFalse(propertiesValidation.IsValid); | ||
Assert.AreEqual(4, propertiesValidation.Errors.Count); | ||
} | ||
|
||
[Test] | ||
public void ValidateNullPropertyShouldReturnError() | ||
{ | ||
|
||
// Arrange | ||
var propertiesValidator = new DevicePropertyValidator(); | ||
var properties = new List<DeviceProperty>(){ | ||
null, | ||
}; | ||
|
||
// Act | ||
var propertiesValidation = propertiesValidator.Validate(properties); | ||
|
||
// Assert | ||
Assert.IsFalse(propertiesValidation.IsValid); | ||
Assert.AreEqual(1, propertiesValidation.Errors.Count); | ||
Assert.AreEqual(propertiesValidation.Errors[0].ErrorMessage, "Property cannot be null."); | ||
|
||
} | ||
|
||
[Test] | ||
public void ValidateDuplicateNamesShouldReturnError() | ||
{ | ||
|
||
// Arrange | ||
var propertiesValidator = new DevicePropertyValidator(); | ||
var properties = new List<DeviceProperty>(){ | ||
new DeviceProperty() | ||
{ | ||
DisplayName = Guid.NewGuid().ToString(), | ||
Name = "PropertyWithSameName", | ||
PropertyType = DevicePropertyType.Integer, | ||
IsWritable = true | ||
}, | ||
new DeviceProperty() | ||
{ | ||
DisplayName = Guid.NewGuid().ToString(), | ||
Name = "PropertyWithSameName", | ||
PropertyType = DevicePropertyType.Integer, | ||
IsWritable = true | ||
} | ||
}; | ||
|
||
// Act | ||
var propertiesValidation = propertiesValidator.Validate(properties); | ||
|
||
// Assert | ||
Assert.IsFalse(propertiesValidation.IsValid); | ||
Assert.AreEqual(1, propertiesValidation.Errors.Count); | ||
Assert.AreEqual(propertiesValidation.Errors[0].ErrorMessage, "Properties should have unique name."); | ||
|
||
} | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
src/AzureIoTHub.Portal.Server.Tests.Unit/Validators/LoRaDeviceModelValidatorTests.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,55 @@ | ||
// 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; | ||
|
||
internal class LoRaDeviceModelValidatorTests | ||
{ | ||
[Test] | ||
public void ValidateValidOTAAModel() | ||
{ | ||
|
||
// Arrange | ||
var loraModelValidator = new LoRaDeviceModelValidator(); | ||
var loraModel = new LoRaDeviceModel() | ||
{ | ||
UseOTAA = true, | ||
AppEUI = Guid.NewGuid().ToString(), | ||
}; | ||
|
||
// Act | ||
var loraModelValidation = loraModelValidator.Validate(loraModel); | ||
|
||
// Assert | ||
Assert.IsTrue(loraModelValidation.IsValid); | ||
Assert.AreEqual(0, loraModelValidation.Errors.Count); | ||
} | ||
|
||
[Test] | ||
public void ValidateMissingAppEUIFieldShouldReturnError() | ||
{ | ||
|
||
// Arrange | ||
var loraModelValidator = new LoRaDeviceModelValidator(); | ||
var loraModel = new LoRaDeviceModel() | ||
{ | ||
UseOTAA = true, | ||
AppEUI = "", | ||
}; | ||
|
||
// Act | ||
var loraModelValidation = loraModelValidator.Validate(loraModel); | ||
|
||
// Assert | ||
Assert.IsFalse(loraModelValidation.IsValid); | ||
Assert.AreEqual(1, loraModelValidation.Errors.Count); | ||
Assert.AreEqual(loraModelValidation.Errors[0].ErrorMessage, "AppEUI is required."); | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.