Skip to content

Commit ad1a0ac

Browse files
committed
Added the Decimals check on DateTime.
1 parent 3597b37 commit ad1a0ac

File tree

6 files changed

+243
-0
lines changed

6 files changed

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

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">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 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,45 @@
1+
namespace Skyline.DataMiner.CICD.Validators.Protocol.Tests.Protocol.Params.Param.Display.Decimals.CheckDecimalsTag
2+
{
3+
using System.Collections.Generic;
4+
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
15+
{
16+
public List<IValidationResult> Validate(ValidatorContext context)
17+
{
18+
List<IValidationResult> results = new List<IValidationResult>();
19+
20+
foreach (var param in context.EachParamWithValidId())
21+
{
22+
var displayTag = param.Display;
23+
24+
// Early return pattern. Only check when there is a Display tag.
25+
if (displayTag == null) continue;
26+
27+
// Only check number types.
28+
if (!param.IsNumber()) continue;
29+
30+
// Only check if date or datetime parameter
31+
if (!param.IsDateTime()) continue;
32+
33+
// Verify valid decimals.
34+
var decimalsTag = param.Display?.Decimals;
35+
if (decimalsTag?.Value != 8)
36+
{
37+
var positionNode = decimalsTag ?? (IReadable)displayTag;
38+
results.Add(Error.InvalidDecimalsForDatetime(this, param, positionNode, param.Id.RawValue));
39+
}
40+
}
41+
42+
return results;
43+
}
44+
}
45+
}
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, "itemId");
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 'itemId'.",
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,11 @@
1+
<Protocol xmlns="http://www.skyline.be/validatorProtocolUnitTest">
2+
<Params>
3+
<Param id="10">
4+
<Display>
5+
</Display>
6+
<Measurement>
7+
<Type options="datetime">number</Type>
8+
</Measurement>
9+
</Param>
10+
</Params>
11+
</Protocol>
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+
<Decimals>8</Decimals>
6+
</Display>
7+
<Measurement>
8+
<Type options="datetime">number</Type>
9+
</Measurement>
10+
</Param>
11+
</Params>
12+
</Protocol>

0 commit comments

Comments
 (0)