Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the Decimals check on DateTime parameters #24

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 InvalidTagForDateTime(IValidate test, IReadable referenceNode, IReadable positionNode, string paramId)
{
return new ValidationResult
{
Test = test,
CheckId = CheckId.CheckDecimalsTag,
ErrorId = ErrorIds.InvalidTagForDateTime,
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 a 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>",
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.",
HasCodeFix = false,

PositionNode = positionNode,
ReferenceNode = referenceNode,
};
}
}

internal static class ErrorIds
{
public const uint InvalidTagForDateTime = 1;
}

/// <summary>
/// Contains the identifiers of the checks.
/// </summary>
public static class CheckId
{
/// <summary>
/// The check identifier.
/// </summary>
public const uint CheckDecimalsTag = 75;
}
}
25 changes: 25 additions & 0 deletions Protocol/ErrorMessages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9643,6 +9643,31 @@
</ErrorMessage>
</ErrorMessages>
</Check>
<Check id="75">
<Name namespace="Protocol.Params.Param.Display.Decimals">CheckDecimalsTag</Name>
<ErrorMessages>
<ErrorMessage id="1">
<Name>InvalidTagForDateTime</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 a 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>]]></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.]]></Details>
</ErrorMessage>
</ErrorMessages>
</Check>
</Checks>
</Category>
<Category id="3">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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.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())
{
var displayTag = param.Display;

// Early return pattern. Only check when there is a Display tag.
if (displayTag == null) continue;

// Only check number types.
if (!param.IsNumber()) continue;

// Only check if date or datetime parameter
if (!param.IsDateTime()) continue;

// Verify valid decimals.
var decimalsTag = param.Display?.Decimals;
if (decimalsTag?.Value != 8)
{
var positionNode = decimalsTag ?? (IReadable)displayTag;
results.Add(Error.InvalidTagForDateTime(this, param, positionNode, 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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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_InvalidTagForDateTime()
{
Generic.ValidateData data = new Generic.ValidateData
{
TestType = Generic.TestType.Invalid,
FileName = "InvalidTagForDateTime",
ExpectedResults = new List<IValidationResult>
{
Error.InvalidTagForDateTime(null, null, null, "10"),
}
};

Generic.Validate(check, data);
}

#endregion
}

[TestClass]
public class ErrorMessages
{
[TestMethod]
public void Param_CheckDecimalsTag_InvalidTagForDateTime()
{
// Create ErrorMessage
var message = Error.InvalidTagForDateTime(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.",
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);
}
}
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Protocol xmlns="http://www.skyline.be/validatorProtocolUnitTest">
<Params>
<Param id="10">
<Display>
<RTDisplay>true</RTDisplay>
<Decimals>8</Decimals>
</Display>
<Measurement>
<Type options="datetime">number</Type>
</Measurement>
</Param>
</Params>
</Protocol>
Loading