diff --git a/Protocol/Error Messages/Protocol/Params/Param/Display/Decimals/CheckDecimalsTag.cs b/Protocol/Error Messages/Protocol/Params/Param/Display/Decimals/CheckDecimalsTag.cs new file mode 100644 index 0000000..aad81c9 --- /dev/null +++ b/Protocol/Error Messages/Protocol/Params/Param/Display/Decimals/CheckDecimalsTag.cs @@ -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 InvalidDecimalsForDateTime(IValidate test, IReadable referenceNode, IReadable positionNode, string paramId) + { + return new ValidationResult + { + Test = test, + CheckId = CheckId.CheckDecimalsTag, + ErrorId = ErrorIds.InvalidDecimalsForDateTime, + 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 the Protocol/Params/Param/Display/Decimals tag with value 8.", + 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 + "", + 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 + "", + HasCodeFix = false, + + PositionNode = positionNode, + ReferenceNode = referenceNode, + }; + } + } + + internal static class ErrorIds + { + public const uint InvalidDecimalsForDateTime = 1; + } + + /// <summary> + /// Contains the identifiers of the checks. + /// </summary> + public static class CheckId + { + /// <summary> + /// The check identifier. + /// </summary> + public const uint CheckDecimalsTag = 75; + } +} \ No newline at end of file diff --git a/Protocol/ErrorMessages.xml b/Protocol/ErrorMessages.xml index b5df2b7..177e7d8 100644 --- a/Protocol/ErrorMessages.xml +++ b/Protocol/ErrorMessages.xml @@ -9643,6 +9643,31 @@ </ErrorMessage> </ErrorMessages> </Check> + <Check id="75"> + <Name namespace="Protocol.Params.Param.Display.Decimals">CheckDecimalsTag</Name> + <ErrorMessages> + <ErrorMessage id="1"> + <Name>InvalidDecimalsForDateTime</Name> + <GroupDescription /> + <Description templateId="1010"> + <InputParameters> + <InputParameter id="0" value="Display/Decimals">tagName</InputParameter> + <InputParameter id="1" value="8">expectedValue</InputParameter> + <InputParameter id="2" value="Param">itemKind</InputParameter> + <InputParameter id="3">paramId</InputParameter> + </InputParameters> + </Description> + <Severity>Major</Severity> + <Certainty>Certain</Certainty> + <Source>Validator</Source> + <FixImpact>NonBreaking</FixImpact> + <HasCodeFix>False</HasCodeFix> + <HowToFix><![CDATA[Add the Protocol/Params/Param/Display/Decimals tag with value 8.]]></HowToFix> + <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> + <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> + </ErrorMessage> + </ErrorMessages> + </Check> </Checks> </Category> <Category id="3"> diff --git a/Protocol/Tests/Protocol/Params/Param/Display/Decimals/CheckDecimalsTag.cs b/Protocol/Tests/Protocol/Params/Param/Display/Decimals/CheckDecimalsTag.cs new file mode 100644 index 0000000..2bb84b7 --- /dev/null +++ b/Protocol/Tests/Protocol/Params/Param/Display/Decimals/CheckDecimalsTag.cs @@ -0,0 +1,69 @@ +namespace Skyline.DataMiner.CICD.Validators.Protocol.Tests.Protocol.Params.Param.Display.Decimals.CheckDecimalsTag +{ + using System; + using System.Collections.Generic; + + 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()) + { + // Early Return pattern. Only check number types. + if (!param.IsNumber()) continue; + + // Only check if there are options. + var allOptions = param.Measurement?.Type?.Options?.Value?.Split(';'); + if (allOptions == null) continue; + + // Is there an option involving date or datetime? + List<string> possibleLowerCaseDateSyntax = new List<string>() { "date", "datetime", "datetime:minute" }; + bool foundDateTime = Array.Exists(allOptions, option => possibleLowerCaseDateSyntax.Contains(option.ToLower())); + + // Verify valid decimals. + var decimalsTag = param.Display?.Decimals; + if (foundDateTime && decimalsTag?.Value != 8) + { + results.Add(Error.InvalidDecimalsForDateTime(this, param, decimalsTag, 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; + ////} + } +} \ No newline at end of file diff --git a/ProtocolTests/Protocol/Params/Param/Display/Decimals/CheckDecimalsTag/CheckDecimalsTag.cs b/ProtocolTests/Protocol/Params/Param/Display/Decimals/CheckDecimalsTag/CheckDecimalsTag.cs new file mode 100644 index 0000000..4f34e4a --- /dev/null +++ b/ProtocolTests/Protocol/Params/Param/Display/Decimals/CheckDecimalsTag/CheckDecimalsTag.cs @@ -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_InvalidDecimalsForDateTime() + { + Generic.ValidateData data = new Generic.ValidateData + { + TestType = Generic.TestType.Invalid, + FileName = "InvalidDecimalsForDateTime", + ExpectedResults = new List<IValidationResult> + { + Error.InvalidDecimalsForDateTime(null, null, null, "10"), + } + }; + + Generic.Validate(check, data); + } + + #endregion + } + + [TestClass] + public class ErrorMessages + { + [TestMethod] + public void Param_CheckDecimalsTag_InvalidDecimalsForDateTime() + { + // Create ErrorMessage + var message = Error.InvalidDecimalsForDateTime(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." + Environment.NewLine + "", + 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); + } +} \ No newline at end of file diff --git a/ProtocolTests/Protocol/Params/Param/Display/Decimals/CheckDecimalsTag/Samples/Validate/Invalid/InvalidDecimalsForDateTime.xml b/ProtocolTests/Protocol/Params/Param/Display/Decimals/CheckDecimalsTag/Samples/Validate/Invalid/InvalidDecimalsForDateTime.xml new file mode 100644 index 0000000..8fc6541 --- /dev/null +++ b/ProtocolTests/Protocol/Params/Param/Display/Decimals/CheckDecimalsTag/Samples/Validate/Invalid/InvalidDecimalsForDateTime.xml @@ -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> \ No newline at end of file diff --git a/ProtocolTests/Protocol/Params/Param/Display/Decimals/CheckDecimalsTag/Samples/Validate/Valid/Valid.xml b/ProtocolTests/Protocol/Params/Param/Display/Decimals/CheckDecimalsTag/Samples/Validate/Valid/Valid.xml new file mode 100644 index 0000000..a9490bd --- /dev/null +++ b/ProtocolTests/Protocol/Params/Param/Display/Decimals/CheckDecimalsTag/Samples/Validate/Valid/Valid.xml @@ -0,0 +1,12 @@ +<Protocol xmlns="http://www.skyline.be/validatorProtocolUnitTest"> + <Params> + <Param id="10"> + <Display> + <Decimals>8</Decimals> + </Display> + <Measurment> + <Type options="datetime">number</Type> + </Measurment> + </Param> + </Params> +</Protocol> \ No newline at end of file diff --git a/README.md b/README.md index 9191886..aba7a83 100644 --- a/README.md +++ b/README.md @@ -310,6 +310,7 @@ This will inform the owners that you suggested additions and changes. Those can For this exercise, this will trigger an automatic pipeline that closes your pull request and forwards the results to Skyline. + > [!NOTE] > Skyline will review your submission. Upon successful review, you will be awarded the appropriate DevOps points as a token of your accomplishment.