-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the Decimals check on datetime parameters
- Loading branch information
1 parent
3597b37
commit c50ca52
Showing
6 changed files
with
271 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
Protocol/Error Messages/Protocol/Params/Param/Display/Decimals/CheckDecimalsTag.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,56 @@ | ||
// <auto-generated>This is auto-generated code by Validator Management Tool. Do not modify.</auto-generated> | ||
namespace Skyline.DataMiner.CICD.Validators.Protocol.Tests.Protocol.Params.Param.Display.Decimals.CheckDecimalsTag | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using Skyline.DataMiner.CICD.Models.Protocol.Read; | ||
using Skyline.DataMiner.CICD.Validators.Common.Interfaces; | ||
using Skyline.DataMiner.CICD.Validators.Common.Model; | ||
using Skyline.DataMiner.CICD.Validators.Protocol.Common; | ||
using Skyline.DataMiner.CICD.Validators.Protocol.Interfaces; | ||
|
||
internal static class Error | ||
{ | ||
public static IValidationResult InvalidTagForDateTime(IValidate test, IReadable referenceNode, IReadable positionNode, string paramId) | ||
{ | ||
return new ValidationResult | ||
{ | ||
Test = test, | ||
CheckId = CheckId.CheckDecimalsTag, | ||
ErrorId = ErrorIds.InvalidTagForDateTime, | ||
FullId = "2.75.1", | ||
Category = Category.Param, | ||
Severity = Severity.Major, | ||
Certainty = Certainty.Certain, | ||
Source = Source.Validator, | ||
FixImpact = FixImpact.NonBreaking, | ||
GroupDescription = "", | ||
Description = String.Format("Missing tag '{0}' with expected value '{1}' for {2} '{3}'.", "Display/Decimals", "8", "Param", paramId), | ||
HowToFix = "Add a Protocol/Param/Display/Decimals tag with value8.", | ||
ExampleCode = "<Display>" + Environment.NewLine + " <RTDisplay>true</RTDisplay>" + Environment.NewLine + " <Decimals>8</Decimals>" + Environment.NewLine + "</Display>" + Environment.NewLine + "<Measurement>" + Environment.NewLine + " <Type options=\"datetime\">number</Type>" + Environment.NewLine + "</Measurement>", | ||
Details = "By default, only 6 decimals are saved in memory. Parameters holding datetime values need at least 8 decimals to be accurate." + Environment.NewLine + "Otherwise, there might be rounding issues when retrieving the parameter from an external source like an Automation script.", | ||
HasCodeFix = false, | ||
|
||
PositionNode = positionNode, | ||
ReferenceNode = referenceNode, | ||
}; | ||
} | ||
} | ||
|
||
internal static class ErrorIds | ||
{ | ||
public const uint InvalidTagForDateTime = 1; | ||
} | ||
|
||
/// <summary> | ||
/// Contains the identifiers of the checks. | ||
/// </summary> | ||
public static class CheckId | ||
{ | ||
/// <summary> | ||
/// The check identifier. | ||
/// </summary> | ||
public const uint CheckDecimalsTag = 75; | ||
} | ||
} |
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
70 changes: 70 additions & 0 deletions
70
Protocol/Tests/Protocol/Params/Param/Display/Decimals/CheckDecimalsTag.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,70 @@ | ||
namespace Skyline.DataMiner.CICD.Validators.Protocol.Tests.Protocol.Params.Param.Display.Decimals.CheckDecimalsTag | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using Skyline.DataMiner.CICD.Models.Protocol.Read; | ||
using Skyline.DataMiner.CICD.Validators.Common.Interfaces; | ||
using Skyline.DataMiner.CICD.Validators.Common.Model; | ||
using Skyline.DataMiner.CICD.Validators.Protocol.Common; | ||
using Skyline.DataMiner.CICD.Validators.Protocol.Common.Attributes; | ||
using Skyline.DataMiner.CICD.Validators.Protocol.Common.Extensions; | ||
using Skyline.DataMiner.CICD.Validators.Protocol.Interfaces; | ||
|
||
[Test(CheckId.CheckDecimalsTag, Category.Param)] | ||
internal class CheckDecimalsTag : IValidate/*, ICodeFix, ICompare*/ | ||
{ | ||
// Please comment out the interfaces that aren't used together with the respective methods. | ||
|
||
public List<IValidationResult> Validate(ValidatorContext context) | ||
{ | ||
List<IValidationResult> results = new List<IValidationResult>(); | ||
|
||
foreach (var param in context.EachParamWithValidId()) | ||
{ | ||
var displayTag = param.Display; | ||
|
||
// Early return pattern. Only check when there is a Display tag. | ||
if (displayTag == null) continue; | ||
|
||
// Only check number types. | ||
if (!param.IsNumber()) continue; | ||
|
||
// Only check if date or datetime parameter | ||
if (!param.IsDateTime()) continue; | ||
|
||
// Verify valid decimals. | ||
var decimalsTag = param.Display?.Decimals; | ||
if (decimalsTag?.Value != 8) | ||
{ | ||
var positionNode = decimalsTag ?? (IReadable)displayTag; | ||
results.Add(Error.InvalidTagForDateTime(this, param, positionNode, param.Id.RawValue)); | ||
} | ||
} | ||
|
||
return results; | ||
} | ||
|
||
////public ICodeFixResult Fix(CodeFixContext context) | ||
////{ | ||
//// CodeFixResult result = new CodeFixResult(); | ||
|
||
//// switch (context.Result.ErrorId) | ||
//// { | ||
|
||
//// default: | ||
//// result.Message = $"This error ({context.Result.ErrorId}) isn't implemented."; | ||
//// break; | ||
//// } | ||
|
||
//// return result; | ||
////} | ||
|
||
////public List<IValidationResult> Compare(MajorChangeCheckContext context) | ||
////{ | ||
//// List<IValidationResult> results = new List<IValidationResult>(); | ||
|
||
//// return results; | ||
////} | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
ProtocolTests/Protocol/Params/Param/Display/Decimals/CheckDecimalsTag/CheckDecimalsTag.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,95 @@ | ||
namespace ProtocolTests.Protocol.Params.Param.Display.Decimals.CheckDecimalsTag | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using FluentAssertions; | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
using Skyline.DataMiner.CICD.Validators.Common.Interfaces; | ||
using Skyline.DataMiner.CICD.Validators.Common.Model; | ||
using Skyline.DataMiner.CICD.Validators.Protocol.Common; | ||
using Skyline.DataMiner.CICD.Validators.Protocol.Interfaces; | ||
using Skyline.DataMiner.CICD.Validators.Protocol.Tests.Protocol.Params.Param.Display.Decimals.CheckDecimalsTag; | ||
|
||
[TestClass] | ||
public class Validate | ||
{ | ||
private readonly IValidate check = new CheckDecimalsTag(); | ||
|
||
#region Valid Checks | ||
|
||
[TestMethod] | ||
public void Param_CheckDecimalsTag_Valid() | ||
{ | ||
Generic.ValidateData data = new Generic.ValidateData | ||
{ | ||
TestType = Generic.TestType.Valid, | ||
FileName = "Valid", | ||
ExpectedResults = new List<IValidationResult>() | ||
}; | ||
|
||
Generic.Validate(check, data); | ||
} | ||
|
||
#endregion | ||
|
||
#region Invalid Checks | ||
|
||
[TestMethod] | ||
public void Param_CheckDecimalsTag_InvalidTagForDateTime() | ||
{ | ||
Generic.ValidateData data = new Generic.ValidateData | ||
{ | ||
TestType = Generic.TestType.Invalid, | ||
FileName = "InvalidTagForDateTime", | ||
ExpectedResults = new List<IValidationResult> | ||
{ | ||
Error.InvalidTagForDateTime(null, null, null, "10"), | ||
} | ||
}; | ||
|
||
Generic.Validate(check, data); | ||
} | ||
|
||
#endregion | ||
} | ||
|
||
[TestClass] | ||
public class ErrorMessages | ||
{ | ||
[TestMethod] | ||
public void Param_CheckDecimalsTag_InvalidTagForDateTime() | ||
{ | ||
// Create ErrorMessage | ||
var message = Error.InvalidTagForDateTime(null, null, null, "paramId"); | ||
|
||
var expected = new ValidationResult | ||
{ | ||
Severity = Severity.Major, | ||
Certainty = Certainty.Certain, | ||
FixImpact = FixImpact.NonBreaking, | ||
GroupDescription = "", | ||
Description = "Missing tag 'Display/Decimals' with expected value '8' for Param 'paramId'.", | ||
Details = "By default, only 6 decimals are saved in memory. Parameters holding datetime values need at least 8 decimals to be accurate." + Environment.NewLine + "Otherwise, there might be rounding issues when retrieving the parameter from an external source like an Automation script.", | ||
HasCodeFix = false, | ||
}; | ||
|
||
// Assert | ||
message.Should().BeEquivalentTo(expected, Generic.ExcludePropertiesForErrorMessages); | ||
} | ||
} | ||
|
||
[TestClass] | ||
public class Attribute | ||
{ | ||
private readonly IRoot check = new CheckDecimalsTag(); | ||
|
||
[TestMethod] | ||
public void Param_CheckDecimalsTag_CheckCategory() => Generic.CheckCategory(check, Category.Param); | ||
|
||
[TestMethod] | ||
public void Param_CheckDecimalsTag_CheckId() => Generic.CheckId(check, CheckId.CheckDecimalsTag); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...aram/Display/Decimals/CheckDecimalsTag/Samples/Validate/Invalid/InvalidTagForDateTime.xml
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,12 @@ | ||
<Protocol xmlns="http://www.skyline.be/validatorProtocolUnitTest"> | ||
<Params> | ||
<Param id="10"> | ||
<Display> | ||
<RTDisplay>true</RTDisplay> | ||
</Display> | ||
<Measurement> | ||
<Type options="datetime">number</Type> | ||
</Measurement> | ||
</Param> | ||
</Params> | ||
</Protocol> |
13 changes: 13 additions & 0 deletions
13
.../Protocol/Params/Param/Display/Decimals/CheckDecimalsTag/Samples/Validate/Valid/Valid.xml
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,13 @@ | ||
<Protocol xmlns="http://www.skyline.be/validatorProtocolUnitTest"> | ||
<Params> | ||
<Param id="10"> | ||
<Display> | ||
<RTDisplay>true</RTDisplay> | ||
<Decimals>8</Decimals> | ||
</Display> | ||
<Measurement> | ||
<Type options="datetime">number</Type> | ||
</Measurement> | ||
</Param> | ||
</Params> | ||
</Protocol> |