Skip to content

Commit b592a4a

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

File tree

6 files changed

+273
-0
lines changed

6 files changed

+273
-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 InvalidDecimalsForDateTime(IValidate test, IReadable referenceNode, IReadable positionNode, string paramId)
16+
{
17+
return new ValidationResult
18+
{
19+
Test = test,
20+
CheckId = CheckId.CheckDecimalsTag,
21+
ErrorId = ErrorIds.InvalidDecimalsForDateTime,
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", paramId),
30+
HowToFix = "Add the Protocol/Params/Param/Display/Decimals tag with value 8.",
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>" + Environment.NewLine + "",
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." + Environment.NewLine + "",
33+
HasCodeFix = false,
34+
35+
PositionNode = positionNode,
36+
ReferenceNode = referenceNode,
37+
};
38+
}
39+
}
40+
41+
internal static class ErrorIds
42+
{
43+
public const uint InvalidDecimalsForDateTime = 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>InvalidDecimalsForDateTime</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">paramId</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 the Protocol/Params/Param/Display/Decimals tag with value 8.]]></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>[NewLine]]]></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.[NewLine]]]></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,72 @@
1+
namespace Skyline.DataMiner.CICD.Validators.Protocol.Tests.Protocol.Params.Param.Display.Decimals.CheckDecimalsTag
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
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+
using Skyline.DataMiner.CICD.Models.Protocol.Read;
13+
14+
15+
[Test(CheckId.CheckDecimalsTag, Category.Param)]
16+
internal class CheckDecimalsTag : IValidate /*, ICodeFix, ICompare*/
17+
{
18+
// Please comment out the interfaces that aren't used together with the respective methods.
19+
20+
public List<IValidationResult> Validate(ValidatorContext context)
21+
{
22+
List<IValidationResult> results = new List<IValidationResult>();
23+
24+
foreach (var param in context.EachParamWithValidId())
25+
{
26+
var displayTag = param.Display;
27+
28+
// Early return pattern. Only check when there is a Display tag.
29+
if (displayTag == null) continue;
30+
31+
// Only check number types.
32+
if (!param.IsNumber()) continue;
33+
34+
// Only check if date or datetime parameter
35+
if (!param.IsDateTime()) continue;
36+
37+
// Verify valid decimals.
38+
var decimalsTag = param.Display?.Decimals;
39+
if (decimalsTag?.Value != 8)
40+
{
41+
var positionNode = decimalsTag ?? (IReadable)displayTag;
42+
results.Add(Error.InvalidDecimalsForDateTime(this, param, decimalsTag, param.Id.RawValue));
43+
}
44+
}
45+
46+
return results;
47+
}
48+
49+
50+
public ICodeFixResult Fix(CodeFixContext context)
51+
{
52+
CodeFixResult result = new CodeFixResult();
53+
54+
switch (context.Result.ErrorId)
55+
{
56+
57+
default:
58+
result.Message = $"This error ({context.Result.ErrorId}) isn't implemented.";
59+
break;
60+
}
61+
62+
return result;
63+
}
64+
65+
public List<IValidationResult> Compare(MajorChangeCheckContext context)
66+
{
67+
List<IValidationResult> results = new List<IValidationResult>();
68+
69+
return results;
70+
}
71+
}
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
public void Param_CheckDecimalsTag_Valid()
25+
{
26+
Generic.ValidateData data = new Generic.ValidateData
27+
{
28+
TestType = Generic.TestType.Valid,
29+
FileName = "Valid",
30+
ExpectedResults = new List<IValidationResult>()
31+
};
32+
33+
Generic.Validate(check, data);
34+
}
35+
36+
#endregion
37+
38+
#region Invalid Checks
39+
40+
[TestMethod]
41+
public void Param_CheckDecimalsTag_InvalidDecimalsForDateTime()
42+
{
43+
Generic.ValidateData data = new Generic.ValidateData
44+
{
45+
TestType = Generic.TestType.Invalid,
46+
FileName = "InvalidDecimalsForDateTime",
47+
ExpectedResults = new List<IValidationResult>
48+
{
49+
Error.InvalidDecimalsForDateTime(null, null, null, "10"),
50+
}
51+
};
52+
53+
Generic.Validate(check, data);
54+
}
55+
56+
#endregion
57+
}
58+
59+
[TestClass]
60+
public class ErrorMessages
61+
{
62+
[TestMethod]
63+
public void Param_CheckDecimalsTag_InvalidDecimalsForDateTime()
64+
{
65+
// Create ErrorMessage
66+
var message = Error.InvalidDecimalsForDateTime(null, null, null, "paramId");
67+
68+
var expected = new ValidationResult
69+
{
70+
Severity = Severity.Major,
71+
Certainty = Certainty.Certain,
72+
FixImpact = FixImpact.NonBreaking,
73+
GroupDescription = "",
74+
Description = "Missing tag 'Display/Decimals' with expected value '8' for Param 'paramId'.",
75+
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." + Environment.NewLine + "",
76+
HasCodeFix = false,
77+
};
78+
79+
// Assert
80+
message.Should().BeEquivalentTo(expected, Generic.ExcludePropertiesForErrorMessages);
81+
}
82+
}
83+
84+
[TestClass]
85+
public class Attribute
86+
{
87+
private readonly IRoot check = new CheckDecimalsTag();
88+
89+
[TestMethod]
90+
public void Param_CheckDecimalsTag_CheckCategory() => Generic.CheckCategory(check, Category.Param);
91+
92+
[TestMethod]
93+
public void Param_CheckDecimalsTag_CheckId() => Generic.CheckId(check, CheckId.CheckDecimalsTag);
94+
}
95+
}
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)