Skip to content

Commit 9e2c666

Browse files
committed
Added the Decimals check on DateTime parameters
1 parent 3597b37 commit 9e2c666

File tree

6 files changed

+276
-0
lines changed

6 files changed

+276
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// <auto-generated>This is auto-generated code by Validator Management Tool. Do not modify.</auto-generated>
2+
namespace Skyline.DataMiner.CICD.Validators.Protocol.Tests.Protocol.Params.Param.Display.Decimals.CheckDecimalsTag
3+
{
4+
using System;
5+
using System.Collections.Generic;
6+
7+
using Skyline.DataMiner.CICD.Models.Protocol.Read;
8+
using Skyline.DataMiner.CICD.Validators.Common.Interfaces;
9+
using Skyline.DataMiner.CICD.Validators.Common.Model;
10+
using Skyline.DataMiner.CICD.Validators.Protocol.Common;
11+
using Skyline.DataMiner.CICD.Validators.Protocol.Interfaces;
12+
13+
internal static class Error
14+
{
15+
public static IValidationResult InvalidTagForDateTime(IValidate test, IReadable referenceNode, IReadable positionNode, string itemId)
16+
{
17+
return new ValidationResult
18+
{
19+
Test = test,
20+
CheckId = CheckId.CheckDecimalsTag,
21+
ErrorId = ErrorIds.InvalidTagForDateTime,
22+
FullId = "2.75.1",
23+
Category = Category.Param,
24+
Severity = Severity.Major,
25+
Certainty = Certainty.Certain,
26+
Source = Source.Validator,
27+
FixImpact = FixImpact.NonBreaking,
28+
GroupDescription = "",
29+
Description = String.Format("Missing tag '{0}' with expected value '{1}' for {2} '{3}'.", "Display/Decimals", "8", "Param", itemId),
30+
HowToFix = "Add a Protocol/Params/Param/Display/Decimals tag with value 8." + Environment.NewLine + "",
31+
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>",
32+
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.",
33+
HasCodeFix = false,
34+
35+
PositionNode = positionNode,
36+
ReferenceNode = referenceNode,
37+
};
38+
}
39+
}
40+
41+
internal static class ErrorIds
42+
{
43+
public const uint InvalidTagForDateTime = 1;
44+
}
45+
46+
/// <summary>
47+
/// Contains the identifiers of the checks.
48+
/// </summary>
49+
public static class CheckId
50+
{
51+
/// <summary>
52+
/// The check identifier.
53+
/// </summary>
54+
public const uint CheckDecimalsTag = 75;
55+
}
56+
}

Protocol/ErrorMessages.xml

+25
Original file line numberDiff line numberDiff line change
@@ -9643,6 +9643,31 @@
96439643
</ErrorMessage>
96449644
</ErrorMessages>
96459645
</Check>
9646+
<Check id="75">
9647+
<Name namespace="Protocol.Params.Param.Display.Decimals">CheckDecimalsTag</Name>
9648+
<ErrorMessages>
9649+
<ErrorMessage id="1">
9650+
<Name>InvalidTagForDateTime</Name>
9651+
<GroupDescription />
9652+
<Description templateId="1010">
9653+
<InputParameters>
9654+
<InputParameter id="0" value="Display/Decimals">tagName</InputParameter>
9655+
<InputParameter id="1" value="8">expectedValue</InputParameter>
9656+
<InputParameter id="2" value="Param">itemKind</InputParameter>
9657+
<InputParameter id="3">itemId</InputParameter>
9658+
</InputParameters>
9659+
</Description>
9660+
<Severity>Major</Severity>
9661+
<Certainty>Certain</Certainty>
9662+
<Source>Validator</Source>
9663+
<FixImpact>NonBreaking</FixImpact>
9664+
<HasCodeFix>False</HasCodeFix>
9665+
<HowToFix><![CDATA[Add a Protocol/Params/Param/Display/Decimals tag with value 8.[NewLine]]]></HowToFix>
9666+
<ExampleCode><![CDATA[<Display>[NewLine] <RTDisplay>true</RTDisplay>[NewLine] <Decimals>8</Decimals>[NewLine]</Display>[NewLine]<Measurement>[NewLine] <Type options="datetime">number</Type>[NewLine]</Measurement>]]></ExampleCode>
9667+
<Details><![CDATA[By default, only 6 decimals are saved in memory. Parameters holding datetime values need at least 8 decimals to be accurate.[NewLine]Otherwise, there might be rounding issues when retrieving the parameter from an external source like an Automation script.]]></Details>
9668+
</ErrorMessage>
9669+
</ErrorMessages>
9670+
</Check>
96469671
</Checks>
96479672
</Category>
96489673
<Category id="3">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
namespace Skyline.DataMiner.CICD.Validators.Protocol.Tests.Protocol.Params.Param.Display.Decimals.CheckDecimalsTag
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using Skyline.DataMiner.CICD.Models.Protocol.Read;
6+
using Skyline.DataMiner.CICD.Validators.Common.Interfaces;
7+
using Skyline.DataMiner.CICD.Validators.Common.Model;
8+
using Skyline.DataMiner.CICD.Validators.Protocol.Common;
9+
using Skyline.DataMiner.CICD.Validators.Protocol.Common.Attributes;
10+
using Skyline.DataMiner.CICD.Validators.Protocol.Common.Extensions;
11+
using Skyline.DataMiner.CICD.Validators.Protocol.Interfaces;
12+
13+
[Test(CheckId.CheckDecimalsTag, Category.Param)]
14+
internal class CheckDecimalsTag : IValidate/*, ICodeFix, ICompare*/
15+
{
16+
// Please comment out the interfaces that aren't used together with the respective methods.
17+
18+
public List<IValidationResult> Validate(ValidatorContext context)
19+
{
20+
List<IValidationResult> results = new List<IValidationResult>();
21+
22+
foreach (var param in context.EachParamWithValidId())
23+
{
24+
var displayTag = param.Display;
25+
26+
// Early return pattern. Only check when there is a Display tag.
27+
if (displayTag == null) continue;
28+
29+
// Only check number types.
30+
if (!param.IsNumber()) continue;
31+
32+
// Only check if date or datetime parameter
33+
if (!param.IsDateTime()) continue;
34+
35+
// Verify valid decimals.
36+
var decimalsTag = param.Display?.Decimals;
37+
if (decimalsTag?.Value != 8)
38+
{
39+
var positionNode = decimalsTag ?? (IReadable)displayTag;
40+
results.Add(Error.InvalidTagForDateTime(this, param, positionNode, param.Id.RawValue));
41+
}
42+
}
43+
44+
return results;
45+
}
46+
47+
48+
////public ICodeFixResult Fix(CodeFixContext context)
49+
////{
50+
//// CodeFixResult result = new CodeFixResult();
51+
52+
//// switch (context.Result.ErrorId)
53+
//// {
54+
55+
//// default:
56+
//// result.Message = $"This error ({context.Result.ErrorId}) isn't implemented.";
57+
//// break;
58+
//// }
59+
60+
//// return result;
61+
////}
62+
63+
////public List<IValidationResult> Compare(MajorChangeCheckContext context)
64+
////{
65+
//// List<IValidationResult> results = new List<IValidationResult>();
66+
67+
//// return results;
68+
////}
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
namespace ProtocolTests.Protocol.Params.Param.Display.Decimals.CheckDecimalsTag
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
6+
using FluentAssertions;
7+
8+
using Microsoft.VisualStudio.TestTools.UnitTesting;
9+
10+
using Skyline.DataMiner.CICD.Validators.Common.Interfaces;
11+
using Skyline.DataMiner.CICD.Validators.Common.Model;
12+
using Skyline.DataMiner.CICD.Validators.Protocol.Common;
13+
using Skyline.DataMiner.CICD.Validators.Protocol.Interfaces;
14+
using Skyline.DataMiner.CICD.Validators.Protocol.Tests.Protocol.Params.Param.Display.Decimals.CheckDecimalsTag;
15+
16+
[TestClass]
17+
public class Validate
18+
{
19+
private readonly IValidate check = new CheckDecimalsTag();
20+
21+
#region Valid Checks
22+
23+
[TestMethod]
24+
25+
public void Param_CheckDecimalsTag_Valid()
26+
{
27+
Generic.ValidateData data = new Generic.ValidateData
28+
{
29+
TestType = Generic.TestType.Valid,
30+
FileName = "Valid",
31+
ExpectedResults = new List<IValidationResult>()
32+
};
33+
34+
Generic.Validate(check, data);
35+
}
36+
37+
#endregion
38+
39+
#region Invalid Checks
40+
41+
[TestMethod]
42+
43+
public void Param_CheckDecimalsTag_InvalidTagForDateTime()
44+
{
45+
Generic.ValidateData data = new Generic.ValidateData
46+
{
47+
TestType = Generic.TestType.Invalid,
48+
FileName = "InvalidTagForDateTime",
49+
ExpectedResults = new List<IValidationResult>
50+
{
51+
Error.InvalidTagForDateTime(null, null, null, "10"),
52+
53+
}
54+
};
55+
56+
Generic.Validate(check, data);
57+
}
58+
59+
#endregion
60+
}
61+
62+
[TestClass]
63+
public class ErrorMessages
64+
{
65+
[TestMethod]
66+
67+
public void Param_CheckDecimalsTag_InvalidTagForDateTime()
68+
{
69+
// Create ErrorMessage
70+
var message = Error.InvalidTagForDateTime(null, null, null, "itemId");
71+
72+
var expected = new ValidationResult
73+
{
74+
Severity = Severity.Major,
75+
Certainty = Certainty.Certain,
76+
FixImpact = FixImpact.NonBreaking,
77+
GroupDescription = "",
78+
Description = "Missing tag 'Display/Decimals' with expected value '8' for Param 'itemId'.",
79+
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.",
80+
HasCodeFix = false,
81+
};
82+
83+
// Assert
84+
message.Should().BeEquivalentTo(expected, Generic.ExcludePropertiesForErrorMessages);
85+
}
86+
}
87+
88+
[TestClass]
89+
90+
public class Attribute
91+
{
92+
private readonly IRoot check = new CheckDecimalsTag();
93+
94+
[TestMethod]
95+
public void Param_CheckDecimalsTag_CheckCategory() => Generic.CheckCategory(check, Category.Param);
96+
97+
[TestMethod]
98+
public void Param_CheckDecimalsTag_CheckId() => Generic.CheckId(check, CheckId.CheckDecimalsTag);
99+
}
100+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Protocol xmlns="http://www.skyline.be/validatorProtocolUnitTest">
2+
<Params>
3+
<Param id="10">
4+
<Display>
5+
<RTDisplay>true</RTDisplay>
6+
</Display>
7+
<Measurement>
8+
<Type options="datetime">number</Type>
9+
</Measurement>
10+
</Param>
11+
</Params>
12+
</Protocol>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Protocol xmlns="http://www.skyline.be/validatorProtocolUnitTest">
2+
<Params>
3+
<Param id="10">
4+
<Display>
5+
<RTDisplay>true</RTDisplay>
6+
<Decimals>8</Decimals>
7+
</Display>
8+
<Measurement>
9+
<Type options="datetime">number</Type>
10+
</Measurement>
11+
</Param>
12+
</Params>
13+
</Protocol>

0 commit comments

Comments
 (0)