Skip to content

Commit

Permalink
Added check for use of exceptions tag with write params. (#40)
Browse files Browse the repository at this point in the history
* Added check for use of exceptions tag with write params.

* Moved check for parameter type on parameters with exceptions to CheckExceptionsTag

* Reordered CheckExceptionsTag

* Moved ErrorMessage for write param type combination with exceptions tag to CheckExceptionsTag in ErrorMessages.xml

* Updated FullId of Error.ExceptionIncompatibleWithParamType

* Update ProtocolTests/Protocol/Params/Param/Interprete/Exceptions/CheckExceptionsTag/CheckExceptionsTag.cs

Co-authored-by: Michiel Oda <[email protected]>

---------

Co-authored-by: Michiel Oda <[email protected]>
  • Loading branch information
EdibSU and MichielOda authored Apr 8, 2024
1 parent f8dbf6f commit 8442829
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,40 @@ public static IValidationResult AddedException(IReadable referenceNode, IReadabl
}
}

internal static class Error
{
public static IValidationResult ExceptionIncompatibleWithParamType(IValidate test, IReadable referenceNode, IReadable positionNode, string paramType, string paramId)
{
return new ValidationResult
{
Test = test,
CheckId = CheckId.CheckExceptionsTag,
ErrorId = ErrorIds.ExceptionIncompatibleWithParamType,
FullId = "2.36.4",
Category = Category.Param,
Severity = Severity.Minor,
Certainty = Certainty.Certain,
Source = Source.Validator,
FixImpact = FixImpact.NonBreaking,
GroupDescription = "",
Description = String.Format("Interprete/Exceptions is incompatible with Param/Type '{0}'. Param ID '{1}'.", paramType, paramId),
HowToFix = "Use Measurement.Discreets.Discreet tags.",
ExampleCode = "",
Details = "Do not use Exception tags to add exceptions to write parameters.",
HasCodeFix = false,

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

internal static class ErrorIds
{
public const uint UpdatedExceptionValueTag = 1;
public const uint RemovedException = 2;
public const uint AddedException = 3;
public const uint ExceptionIncompatibleWithParamType = 4;
}

/// <summary>
Expand Down
19 changes: 19 additions & 0 deletions Protocol/ErrorMessages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6322,6 +6322,25 @@
<ExampleCode><![CDATA[]]></ExampleCode>
<Details><![CDATA[Adding an exception will have impact on existing alarm templates as an exception value is preceded by a '$' sign in the alarm template.]]></Details>
</ErrorMessage>
<ErrorMessage id="4">
<Name>ExceptionIncompatibleWithParamType</Name>
<GroupDescription />
<Description>
<Format>Interprete/Exceptions is incompatible with Param/Type '{0}'. Param ID '{1}'.</Format>
<InputParameters>
<InputParameter id="0">paramType</InputParameter>
<InputParameter id="1">paramId</InputParameter>
</InputParameters>
</Description>
<Severity>Minor</Severity>
<Certainty>Certain</Certainty>
<Source>Validator</Source>
<FixImpact>NonBreaking</FixImpact>
<HasCodeFix>False</HasCodeFix>
<HowToFix><![CDATA[Use Measurement.Discreets.Discreet tags.]]></HowToFix>
<ExampleCode><![CDATA[]]></ExampleCode>
<Details><![CDATA[Do not use Exception tags to add exceptions to write parameters.]]></Details>
</ErrorMessage>
</ErrorMessages>
</Check>
<Check id="37">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,23 @@ namespace Skyline.DataMiner.CICD.Validators.Protocol.Tests.Protocol.Params.Param
using Skyline.DataMiner.CICD.Validators.Protocol.Interfaces;

[Test(CheckId.CheckExceptionsTag, Category.Param)]
internal class CheckExceptionsTag : ICompare
internal class CheckExceptionsTag : IValidate, ICompare
{
public List<IValidationResult> Validate(ValidatorContext context)
{
List<IValidationResult> results = new List<IValidationResult>();

foreach (var param in context.EachParamWithValidId())
{
if (param.IsWrite() && param.Interprete?.Exceptions != null)
{
results.Add(Error.ExceptionIncompatibleWithParamType(this, param, param.Interprete.Exceptions, param.Type.RawValue, param.Id.RawValue));
}
}

return results;
}

public List<IValidationResult> Compare(MajorChangeCheckContext context)
{
var results = new List<IValidationResult>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,61 @@
namespace ProtocolTests.Protocol.Params.Param.Interprete.Exceptions.CheckExceptionsTag
{
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.Interprete.Exceptions.CheckExceptionsTag;

[TestClass]
public class Validate
{
private readonly IValidate check = new CheckExceptionsTag();

#region Valid Checks

[TestMethod]
public void Param_CheckExceptionsTag_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_CheckExceptionsTag_Type()
{
Generic.ValidateData data = new Generic.ValidateData
{
TestType = Generic.TestType.Invalid,
FileName = "ExceptionIncompatibleWithParamType",
ExpectedResults = new List<IValidationResult>
{
Error.ExceptionIncompatibleWithParamType(null, null, null, "write", "1"),
Error.ExceptionIncompatibleWithParamType(null, null, null, "write bit", "2"),
}
};

Generic.Validate(check, data);
}

#endregion
}

[TestClass]
public class Compare
{
Expand Down Expand Up @@ -92,6 +139,31 @@ public void Param_CheckExceptionsTag_UpdatedExceptionValueTag()
#endregion
}

[TestClass]
public class ErrorMessages
{
[TestMethod]
public void Param_CheckExceptionsTag_ExceptionIncompatibleWithParamType()
{
// Create ErrorMessage
var message = Error.ExceptionIncompatibleWithParamType(null, null, null, "paramType", "paramId");

var expected = new ValidationResult
{
Severity = Severity.Minor,
Certainty = Certainty.Certain,
FixImpact = FixImpact.NonBreaking,
GroupDescription = "",
Description = "Interprete/Exceptions is incompatible with Param/Type 'paramType'. Param ID 'paramId'.",
Details = "Do not use Exception tags to add exceptions to write parameters.",
HasCodeFix = false,
};

// Assert
message.Should().BeEquivalentTo(expected, Generic.ExcludePropertiesForErrorMessages);
}
}

[TestClass]
public class Attribute
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Protocol xmlns="http://www.skyline.be/validatorProtocolUnitTest">
<Params>
<Param id="1">
<Type>write</Type>
<Interprete>
<Exceptions>
</Exceptions>
</Interprete>
</Param>
<Param id="2">
<Type>write bit</Type>
<Interprete>
<Exceptions>
</Exceptions>
</Interprete>
</Param>
</Params>
</Protocol>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Protocol xmlns="http://www.skyline.be/validatorProtocolUnitTest">
<Params>
<Param id="1">
<Type>write</Type>
</Param>
<Param id="2">
<Type>write bit</Type>
</Param>
</Params>
</Protocol>

0 comments on commit 8442829

Please sign in to comment.