-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QAction - CheckDataMinerDependency - Check DevPacks (#74)
* Adding new check for checking DevPacks compared to the MinimumRequiredVersion tag. * Smaller tweaks
- Loading branch information
1 parent
f3af4ca
commit 9192a49
Showing
29 changed files
with
792 additions
and
1 deletion.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
Protocol/Error Messages/Protocol/QActions/QAction/CheckDataMinerDependency.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.QActions.QAction.CheckDataMinerDependency | ||
{ | ||
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 MismatchDevPack(IValidate test, IReadable referenceNode, IReadable positionNode, string packageName, string packageVersion, string minimumRequiredVersion, string qactionId) | ||
{ | ||
return new ValidationResult | ||
{ | ||
Test = test, | ||
CheckId = CheckId.CheckDataMinerDependency, | ||
ErrorId = ErrorIds.MismatchDevPack, | ||
FullId = "3.42.1", | ||
Category = Category.QAction, | ||
Severity = Severity.Major, | ||
Certainty = Certainty.Certain, | ||
Source = Source.Validator, | ||
FixImpact = FixImpact.NonBreaking, | ||
GroupDescription = "", | ||
Description = String.Format("Package '{0}' version '{1}' does not meet the minimum required version '{2}'. QAction ID '{3}'.", packageName, packageVersion, minimumRequiredVersion, qactionId), | ||
HowToFix = "Either increase version in the MinimumRequiredVersion tag or downgrade the package so it matches with the minimum required version.", | ||
ExampleCode = "", | ||
Details = "Using a higher version of the DevPack may introduce new features that are not compatible with the specified version of DataMiner." + Environment.NewLine + "This can lead to unexpected behavior or errors. Make sure that the DevPack version used in the solution does not exceed the MinimumRequiredVersion.", | ||
HasCodeFix = false, | ||
|
||
PositionNode = positionNode, | ||
ReferenceNode = referenceNode, | ||
}; | ||
} | ||
} | ||
|
||
internal static class ErrorIds | ||
{ | ||
public const uint MismatchDevPack = 1; | ||
} | ||
|
||
/// <summary> | ||
/// Contains the identifiers of the checks. | ||
/// </summary> | ||
public static class CheckId | ||
{ | ||
/// <summary> | ||
/// The check identifier. | ||
/// </summary> | ||
public const uint CheckDataMinerDependency = 42; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
Protocol/Tests/Protocol/QActions/QAction/CheckDataMinerDependency.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
namespace Skyline.DataMiner.CICD.Validators.Protocol.Tests.Protocol.QActions.QAction.CheckDataMinerDependency | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
using Skyline.DataMiner.CICD.Common; | ||
using Skyline.DataMiner.CICD.Models.Protocol; | ||
using Skyline.DataMiner.CICD.Models.Protocol.Read; | ||
using Skyline.DataMiner.CICD.Parsers.Common.VisualStudio.Projects; | ||
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.Helpers; | ||
using Skyline.DataMiner.CICD.Validators.Protocol.Interfaces; | ||
|
||
[Test(CheckId.CheckDataMinerDependency, Category.QAction)] | ||
internal class CheckDataMinerDependency : IValidate/*, ICodeFix, ICompare*/ | ||
{ | ||
public List<IValidationResult> Validate(ValidatorContext context) | ||
{ | ||
List<IValidationResult> results = new List<IValidationResult>(); | ||
|
||
if (!context.HasQActionsAndIsSolution) | ||
{ | ||
// Early skip when no QActions are present or when it is not solution based. | ||
return results; | ||
} | ||
|
||
ValidateHelper helper = new ValidateHelper(this, context, results); | ||
foreach ((CompiledQActionProject projectData, IQActionsQAction qaction) in context.EachQActionProject(true)) | ||
{ | ||
// Load csproj | ||
var project = Project.Load(projectData.Project.FilePath, projectData.Project.Name); | ||
if (!project.PackageReferences.Any()) | ||
{ | ||
// No NuGet packages being used | ||
// Should not happen, but is covered by the banner in DIS. | ||
continue; | ||
} | ||
|
||
helper.CheckDevPack(project.PackageReferences, qaction); | ||
} | ||
|
||
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; | ||
////} | ||
} | ||
|
||
internal class ValidateHelper : ValidateHelperBase | ||
{ | ||
private readonly string minReqVersionTag; | ||
private readonly Version minVersion; | ||
|
||
public ValidateHelper(IValidate test, ValidatorContext context, List<IValidationResult> results) : base(test, context, results) | ||
{ | ||
minReqVersionTag = context.ProtocolModel.Protocol?.Compliancies?.MinimumRequiredVersion?.Value; | ||
if (!DataMinerVersion.TryParse(minReqVersionTag, out DataMinerVersion version)) | ||
{ | ||
// Default in case tag is not present. | ||
version = context.ValidatorSettings.MinimumSupportedDataMinerVersion; | ||
} | ||
|
||
minVersion = new Version(version.Major, version.Minor, version.Build); | ||
} | ||
|
||
public void CheckDevPack(IEnumerable<PackageReference> packageReferences, IQActionsQAction qAction) | ||
{ | ||
// Filter out DevPacks & the Files | ||
var dmPacks = packageReferences.Where(IsDevPackOrPartOf).ToList(); | ||
|
||
foreach (PackageReference dmPack in dmPacks) | ||
{ | ||
if (!Version.TryParse(dmPack.Version, out Version v)) | ||
{ | ||
// Unable to parse the version of the DevPack. | ||
continue; | ||
} | ||
|
||
Version packageVersion = new Version(v.Major, v.Minor, v.Build); | ||
|
||
/* | ||
* MinimumRequiredVersion = 10.2.0.0 - XXXXX | ||
* minVersion == 10.2.0 | ||
* | ||
* Package Reference = 10.2.0.5 (CU or rerun of package creation) | ||
* packageVersion == 10.2.0 | ||
*/ | ||
|
||
if (minVersion < packageVersion) | ||
{ | ||
results.Add(Error.MismatchDevPack(test, qAction, qAction, dmPack.Name, dmPack.Version, minReqVersionTag, qAction.Id?.RawValue)); | ||
} | ||
} | ||
|
||
return; | ||
bool IsDevPackOrPartOf(PackageReference packageReference) | ||
{ | ||
return packageReference.Name.StartsWith("Skyline.DataMiner.Dev.") || | ||
packageReference.Name.StartsWith("Skyline.DataMiner.Files"); | ||
} | ||
} | ||
} | ||
} |
129 changes: 129 additions & 0 deletions
129
ProtocolTests/Protocol/QActions/QAction/CheckDataMinerDependency/CheckDataMinerDependency.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
namespace ProtocolTests.Protocol.QActions.QAction.CheckDataMinerDependency | ||
{ | ||
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.QActions.QAction.CheckDataMinerDependency; | ||
|
||
[TestClass] | ||
public class Validate | ||
{ | ||
private readonly IValidate check = new CheckDataMinerDependency(); | ||
|
||
#region Valid Checks | ||
|
||
[TestMethod] | ||
[Ignore("Check can only be done on a solution")] | ||
public void QAction_CheckDataMinerDependency_Valid_XmlBased() | ||
{ | ||
Generic.ValidateData data = new Generic.ValidateData | ||
{ | ||
TestType = Generic.TestType.Valid, | ||
FileName = "Valid", | ||
ExpectedResults = new List<IValidationResult>() | ||
}; | ||
|
||
Generic.Validate(check, data); | ||
} | ||
|
||
[TestMethod] | ||
public void QAction_CheckDataMinerDependency_Valid() | ||
{ | ||
Generic.ValidateData data = new Generic.ValidateData | ||
{ | ||
TestType = Generic.TestType.Valid, | ||
FileName = "Valid", | ||
IsSolution = true, | ||
ExpectedResults = new List<IValidationResult>() | ||
}; | ||
|
||
Generic.Validate(check, data); | ||
} | ||
|
||
#endregion | ||
|
||
#region Invalid Checks | ||
|
||
[TestMethod] | ||
[Ignore("Check can only be done on a solution")] | ||
public void QAction_CheckDataMinerDependency_MismatchDevPack_Xml() | ||
{ | ||
Generic.ValidateData data = new Generic.ValidateData | ||
{ | ||
TestType = Generic.TestType.Invalid, | ||
FileName = "MismatchDevPack", | ||
ExpectedResults = new List<IValidationResult>() | ||
}; | ||
|
||
Generic.Validate(check, data); | ||
} | ||
|
||
[TestMethod] | ||
public void QAction_CheckDataMinerDependency_MismatchDevPack() | ||
{ | ||
Generic.ValidateData data = new Generic.ValidateData | ||
{ | ||
TestType = Generic.TestType.Invalid, | ||
FileName = "MismatchDevPack", | ||
IsSolution = true, | ||
ExpectedResults = new List<IValidationResult> | ||
{ | ||
Error.MismatchDevPack(null, null, null, "Skyline.DataMiner.Dev.Protocol", "10.4.7", "10.2.0.0 - 11517", "1"), | ||
|
||
Error.MismatchDevPack(null, null, null, "Skyline.DataMiner.Dev.Protocol", "10.4.7", "10.2.0.0 - 11517", "2"), | ||
Error.MismatchDevPack(null, null, null, "Skyline.DataMiner.Files.SLMediationSnippets", "10.4.7", "10.2.0.0 - 11517", "2"), | ||
} | ||
}; | ||
|
||
Generic.Validate(check, data); | ||
} | ||
|
||
#endregion | ||
} | ||
|
||
[TestClass] | ||
public class ErrorMessages | ||
{ | ||
[TestMethod] | ||
public void QAction_CheckDataMinerDependency_MismatchDevPack() | ||
{ | ||
// Create ErrorMessage | ||
var message = Error.MismatchDevPack(null, null, null, "packageName", "packageVersion", "minimumRequiredVersion", "qactionId"); | ||
|
||
var expected = new ValidationResult | ||
{ | ||
Severity = Severity.Major, | ||
Certainty = Certainty.Certain, | ||
FixImpact = FixImpact.NonBreaking, | ||
GroupDescription = "", | ||
Description = "Package 'packageName' version 'packageVersion' does not meet the minimum required version 'minimumRequiredVersion'. QAction ID 'qactionId'.", | ||
Details = "Using a higher version of the DevPack may introduce new features that are not compatible with the specified version of DataMiner." + Environment.NewLine + | ||
"This can lead to unexpected behavior or errors. Make sure that the DevPack version used in the solution does not exceed the MinimumRequiredVersion.", | ||
HasCodeFix = false, | ||
}; | ||
|
||
// Assert | ||
message.Should().BeEquivalentTo(expected, Generic.ExcludePropertiesForErrorMessages); | ||
} | ||
} | ||
|
||
[TestClass] | ||
public class Attribute | ||
{ | ||
private readonly IRoot check = new CheckDataMinerDependency(); | ||
|
||
[TestMethod] | ||
public void QAction_CheckDataMinerDependency_CheckCategory() => Generic.CheckCategory(check, Category.QAction); | ||
|
||
[TestMethod] | ||
public void QAction_CheckDataMinerDependency_CheckId() => Generic.CheckId(check, CheckId.CheckDataMinerDependency); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...ol/QActions/QAction/CheckDataMinerDependency/Samples/Validate/Invalid/MismatchDevPack.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<Protocol xmlns="http://www.skyline.be/validatorProtocolUnitTest"> | ||
<QActions> | ||
<QAction> | ||
</QAction> | ||
</QActions> | ||
</Protocol> |
9 changes: 9 additions & 0 deletions
9
...n/CheckDataMinerDependency/Samples/Validate/Invalid/MismatchDevPack/Directory.Build.props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<PlatformTarget>x86</PlatformTarget> | ||
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch($(MSBuildProjectName), '^QAction_([0-9]+)$'))"> | ||
<DefineConstants>$(DefineConstants);DCFv1;DBInfo;ALARM_SQUASHING</DefineConstants> | ||
</PropertyGroup> | ||
</Project> |
11 changes: 11 additions & 0 deletions
11
.../CheckDataMinerDependency/Samples/Validate/Invalid/MismatchDevPack/Internal/.editorconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
indent_size = 4 | ||
tab_width = 4 | ||
end_of_line = crlf | ||
trim_trailing_whitespace = true | ||
|
||
[*.cs] | ||
dotnet_sort_system_directives_first = true |
Oops, something went wrong.