-
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.
Adding unit tests + part of SLDisUnitTestsShared (Common.Testing)
- Loading branch information
1 parent
463cba3
commit 85f8286
Showing
1,990 changed files
with
175,860 additions
and
8 deletions.
There are no files selected for viewing
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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net472</TargetFramework> | ||
<AssemblyName>Skyline.DataMiner.CICD.Validators.Common.Testing</AssemblyName> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Common\Common.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="QActionHelper"> | ||
<HintPath>..\DLLs\QActionHelper.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
|
||
</Project> |
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,71 @@ | ||
namespace SLDisUnitTestsShared | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading; | ||
|
||
using Skyline.DataMiner.CICD.Validators.Common.Interfaces; | ||
using Skyline.DataMiner.Scripting; | ||
|
||
public class ProtocolQActionHelperProvider : IProtocolQActionHelperProvider | ||
{ | ||
private const string AutoGeneratedCodeByDis = "// <auto-generated>This is auto-generated code by DIS. Do not modify.</auto-generated>"; | ||
private static readonly Mutex _mutex; | ||
|
||
static ProtocolQActionHelperProvider() | ||
{ | ||
string mutexId = $"Global\\{typeof(ProtocolQActionHelperProvider).GUID}"; | ||
_mutex = new Mutex(false, mutexId); | ||
} | ||
|
||
public string GetProtocolQActionHelper(string protocolCode, bool ignoreErrors = false) | ||
{ | ||
var tempPath = Path.GetTempPath(); | ||
var tempName = Guid.NewGuid().ToString("N"); | ||
var tempFile = Path.Combine(tempPath, tempName + ".txt"); | ||
|
||
List<XMLParseError> result; | ||
|
||
// prevent System.IO.IOException: The process cannot access the file 'C:\Skyline DataMiner\logging\SLQActionHelper.txt' | ||
try | ||
{ | ||
_mutex.WaitOne(); | ||
result = QActionHelper.CreateProtocolQActionHelperFromString(protocolCode, tempPath, tempName); | ||
} | ||
finally | ||
{ | ||
_mutex.ReleaseMutex(); | ||
} | ||
|
||
if (!ignoreErrors && result != null && result.Count > 0) | ||
{ | ||
StringBuilder error = new StringBuilder(); | ||
error.Append("Couldn't generate QAction helper:"); | ||
|
||
foreach (var err in result) | ||
{ | ||
error.Append("\n Line " + err.Line + ": " + err.Description); | ||
} | ||
|
||
throw new Exception(error.ToString()); | ||
} | ||
|
||
var csContent = new StringBuilder(); | ||
csContent.AppendLine(AutoGeneratedCodeByDis); | ||
|
||
if (File.Exists(tempFile)) | ||
{ | ||
csContent.Append(File.ReadAllText(tempFile)); | ||
File.Delete(tempFile); | ||
} | ||
else | ||
{ | ||
csContent.Append("namespace Skyline.DataMiner.Scripting { public class SLProtocolExt : SLProtocol { } }"); | ||
} | ||
|
||
return csContent.ToString(); | ||
} | ||
} | ||
} |
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,80 @@ | ||
namespace SLDisUnitTestsShared | ||
{ | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
|
||
using Skyline.DataMiner.CICD.Models.Common; | ||
using Skyline.DataMiner.CICD.Models.Protocol; | ||
using Skyline.DataMiner.CICD.Models.Protocol.Read; | ||
using Skyline.DataMiner.CICD.Models.Protocol.Read.Interfaces; | ||
using Skyline.DataMiner.CICD.Parsers.Common.Xml; | ||
using Skyline.DataMiner.CICD.Validators.Common.Data; | ||
using Skyline.DataMiner.CICD.Validators.Common.Interfaces; | ||
using EditModel = Skyline.DataMiner.CICD.Models.Protocol.Edit; | ||
using EditXml = Skyline.DataMiner.CICD.Parsers.Common.XmlEdit; | ||
|
||
public static class ProtocolTestsHelper | ||
{ | ||
public static (IProtocolModel model, XmlDocument document, string protocolCode) ReadProtocol(string fileName, [CallerFilePath] string pathToClassFile = "") | ||
{ | ||
string filePath = Path.Combine(Path.GetDirectoryName(pathToClassFile), fileName); | ||
|
||
string code; | ||
var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); | ||
using (var textReader = new StreamReader(fileStream)) | ||
{ | ||
code = textReader.ReadToEnd(); | ||
} | ||
|
||
return ParseProtocol(code); | ||
} | ||
|
||
public static (IProtocolModel model, XmlDocument document, string protocolCode) ParseProtocol(string protocolCode) | ||
{ | ||
Parser parser = new Parser(new StringBuilder(protocolCode)); | ||
|
||
return (new ProtocolModel(parser.Document), parser.Document, protocolCode); | ||
} | ||
|
||
public static QActionCompilationModel GetQActionCompilationModel(string xmlCode) | ||
{ | ||
var document = new Parser(xmlCode).Document; | ||
var model = new ProtocolModel(document); | ||
|
||
return GetQActionCompilationModel(model, xmlCode); | ||
} | ||
|
||
public static QActionCompilationModel GetQActionCompilationModel(IProtocolModel model, string xmlCode) | ||
{ | ||
var baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
baseDir = Path.GetFullPath(Path.Combine(baseDir, @"..\..\..\..\DLLs")); | ||
|
||
var dllImportResolver = new InternalFilesAssemblyResolver(baseDir); | ||
var qactionHelperProvider = new ProtocolQActionHelperProvider(); | ||
|
||
string qactionHelperSourceCode = qactionHelperProvider.GetProtocolQActionHelper(xmlCode, ignoreErrors: true); | ||
return new QActionCompilationModel(qactionHelperSourceCode, model, dllImportResolver); | ||
} | ||
|
||
public static IProtocolInputData GetProtocolInputData(string fileName, [CallerFilePath] string pathToClassFile = "") | ||
{ | ||
(IProtocolModel model, XmlDocument document, string protocolCode) = ReadProtocol(fileName, pathToClassFile); | ||
|
||
var qactionCompilationModel = GetQActionCompilationModel(model, protocolCode); | ||
|
||
return new ProtocolInputData(model, document, qactionCompilationModel); | ||
} | ||
|
||
public static EditModel.Protocol GetEditProtocol(IProtocolModel model) | ||
{ | ||
return new EditModel.Protocol(model.Protocol); | ||
} | ||
|
||
public static EditModel.Protocol GetEditProtocol(IProtocolModel model, EditXml.XmlElement xmlElement) | ||
{ | ||
return new EditModel.Protocol(model.Protocol, xmlElement); | ||
} | ||
} | ||
} |
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
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
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,4 @@ | ||
This folder should contain files from latest main release: | ||
S:\Public\DataMiner Software\DataMiner Files\Release\ | ||
|
||
These DLLs are only to be used for unit tests. They should never be included in the actual NuGet packages. |
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
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,41 @@ | ||
namespace SLDisDmFeatureCheckUnitTests.Features | ||
{ | ||
using System.Linq; | ||
|
||
using FluentAssertions; | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
using Skyline.DataMiner.CICD.Validators.Common.Data; | ||
|
||
using SLDisDmFeatureCheck.Common; | ||
using SLDisDmFeatureCheck.Common.Results; | ||
using SLDisDmFeatureCheck.Features; | ||
|
||
[TestClass] | ||
public class DashboardTests | ||
{ | ||
private static Dashboard check; | ||
|
||
[ClassInitialize] | ||
public static void ClassInitialize(TestContext testContext) | ||
{ | ||
check = new Dashboard(); | ||
} | ||
|
||
[TestMethod] | ||
public void CheckIsUsed() | ||
{ | ||
const string code = "<Protocol><Params><Param><Dashboard></Dashboard></Param></Params></Protocol>"; | ||
var input = new ProtocolInputData(code); | ||
|
||
FeatureCheckContext context = new FeatureCheckContext(input); | ||
|
||
var result = check.CheckIfUsed(context); | ||
var expected = context.Model.Protocol.Params.Select(x => new FeatureCheckResultItem(x)); | ||
|
||
Assert.IsTrue(result.IsUsed); | ||
result.FeatureItems.Should().BeEquivalentTo(expected); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
Protocol.FeaturesTests/Features/10.0/DynamicParameterReplicationTests.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,41 @@ | ||
namespace SLDisDmFeatureCheckUnitTests.Features | ||
{ | ||
using System.Linq; | ||
|
||
using FluentAssertions; | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
using Skyline.DataMiner.CICD.Validators.Common.Data; | ||
|
||
using SLDisDmFeatureCheck.Common; | ||
using SLDisDmFeatureCheck.Common.Results; | ||
using SLDisDmFeatureCheck.Features; | ||
|
||
[TestClass] | ||
public class DynamicParameterReplicationTests | ||
{ | ||
private static DynamicParameterReplication check; | ||
|
||
[ClassInitialize] | ||
public static void ClassInitialize(TestContext testContext) | ||
{ | ||
check = new DynamicParameterReplication(); | ||
} | ||
|
||
[TestMethod] | ||
public void CheckIsUsed() | ||
{ | ||
const string code = "<Protocol><Params><Param><Replication><Element dynamic='1'/></Replication></Param></Params></Protocol>"; | ||
var input = new ProtocolInputData(code); | ||
|
||
FeatureCheckContext context = new FeatureCheckContext(input); | ||
|
||
var result = check.CheckIfUsed(context); | ||
var expected = context.Model.Protocol.Params.Select(x => new FeatureCheckResultItem(x)); | ||
|
||
Assert.IsTrue(result.IsUsed); | ||
result.FeatureItems.Should().BeEquivalentTo(expected); | ||
} | ||
} | ||
} |
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,41 @@ | ||
namespace SLDisDmFeatureCheckUnitTests.Features | ||
{ | ||
using System.Linq; | ||
|
||
using FluentAssertions; | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
using Skyline.DataMiner.CICD.Validators.Common.Data; | ||
|
||
using SLDisDmFeatureCheck.Common; | ||
using SLDisDmFeatureCheck.Common.Results; | ||
using SLDisDmFeatureCheck.Features; | ||
|
||
[TestClass] | ||
public class ExposerTests | ||
{ | ||
private static Exposer check; | ||
|
||
[ClassInitialize] | ||
public static void ClassInitialize(TestContext testContext) | ||
{ | ||
check = new Exposer(); | ||
} | ||
|
||
[TestMethod] | ||
public void CheckIsUsed() | ||
{ | ||
const string code = "<Protocol><Topologies><Topology><Cell><Exposer /></Cell></Topology></Topologies></Protocol>"; | ||
|
||
var input = new ProtocolInputData(code); | ||
var context = new FeatureCheckContext(input); | ||
|
||
var result = check.CheckIfUsed(context); | ||
var expected = context.Model.Protocol.Topologies.Select(x => new FeatureCheckResultItem(x)); | ||
|
||
Assert.IsTrue(result.IsUsed); | ||
result.FeatureItems.Should().BeEquivalentTo(expected); | ||
} | ||
} | ||
} |
Oops, something went wrong.