Skip to content

Commit a0d6acc

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

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