AdaptationTesting

This commit is contained in:
Mike Phares 2022-02-22 14:11:41 -07:00
parent 258433fabb
commit 536652a91e
3 changed files with 45 additions and 60 deletions

View File

@ -69,7 +69,7 @@ public class FileRead : Shared.FileRead, IFileRead
foreach (ModelObjectParameterDefinition modelObjectParameterDefinition in cellInstanceCollection) foreach (ModelObjectParameterDefinition modelObjectParameterDefinition in cellInstanceCollection)
_CellNames.Add(modelObjectParameterDefinition.Name.Split('.')[1], modelObjectParameterDefinition.Value); _CellNames.Add(modelObjectParameterDefinition.Name.Split('.')[1], modelObjectParameterDefinition.Value);
_LincPDFCFileName = string.Concat(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), @"\LincPDFC.exe"); _LincPDFCFileName = string.Concat(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), @"\LincPDFC.exe");
if (_IsEAFHosted && _IsXToOpenInsightMetrologyViewerAttachments && !File.Exists(_LincPDFCFileName)) if (_IsXToOpenInsightMetrologyViewerAttachments && !File.Exists(_LincPDFCFileName))
throw new Exception("LincPDFC FileName doesn't Exist!"); throw new Exception("LincPDFC FileName doesn't Exist!");
if (_IsDummy) if (_IsDummy)
{ {

View File

@ -30,7 +30,7 @@ public class FileRead : Shared.FileRead, IFileRead
if (_IsDuplicator) if (_IsDuplicator)
throw new Exception(cellInstanceConnectionName); throw new Exception(cellInstanceConnectionName);
_GhostPCLFileName = string.Concat(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), @"\gpcl6win64.exe"); _GhostPCLFileName = string.Concat(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), @"\gpcl6win64.exe");
if (_IsEAFHosted && !File.Exists(_GhostPCLFileName)) if (!File.Exists(_GhostPCLFileName))
throw new Exception("Ghost PCL FileName doesn't Exist!"); throw new Exception("Ghost PCL FileName doesn't Exist!");
} }

View File

@ -432,12 +432,6 @@ public class AdaptationTesting : ISMTP
loopName = "CreateSelfDescription"; loopName = "CreateSelfDescription";
else else
throw new Exception(); throw new Exception();
if (i == 2)
_ = stringBuilder.
AppendLine("using Microsoft.VisualStudio.TestTools.UnitTesting;").
AppendLine("using Shared;").
AppendLine("using System.Diagnostics;");
else if (i == 1)
_ = stringBuilder. _ = stringBuilder.
AppendLine("using Adaptation.Shared.Methods;"). AppendLine("using Adaptation.Shared.Methods;").
AppendLine("using Microsoft.Extensions.Logging;"). AppendLine("using Microsoft.Extensions.Logging;").
@ -450,11 +444,8 @@ public class AdaptationTesting : ISMTP
AppendLine("using System.Reflection;"). AppendLine("using System.Reflection;").
AppendLine("using System.Text.Json;"). AppendLine("using System.Text.Json;").
AppendLine("using System.Threading;"); AppendLine("using System.Threading;");
else
throw new Exception();
_ = stringBuilder.AppendLine(). _ = stringBuilder.AppendLine().
Append("namespace _Tests.").Append(loopName).Append('.').Append(_Environment).Append('.').AppendLine(cellInstanceVersionNameAsCode). Append("namespace _Tests.").Append(loopName).Append('.').Append(_Environment).Append('.').Append(cellInstanceVersionNameAsCode).AppendLine(";").
AppendLine("{").
AppendLine(). AppendLine().
AppendLine("[TestClass]"); AppendLine("[TestClass]");
if (i == 2) if (i == 2)
@ -462,14 +453,19 @@ public class AdaptationTesting : ISMTP
Append("public class ").AppendLine(cellInstanceNameWithoutHyphen). Append("public class ").AppendLine(cellInstanceNameWithoutHyphen).
AppendLine("{"). AppendLine("{").
AppendLine(). AppendLine().
AppendLine("#pragma warning disable CA2254").
AppendLine("#pragma warning disable IDE0060").
AppendLine().
Append("private static CreateSelfDescription.").Append(_Environment).Append('.').Append(cellInstanceVersionNameAsCode).Append('.').Append(cellInstanceNameWithoutHyphen).Append(" _").Append(cellInstanceNameWithoutHyphen).AppendLine(";"); Append("private static CreateSelfDescription.").Append(_Environment).Append('.').Append(cellInstanceVersionNameAsCode).Append('.').Append(cellInstanceNameWithoutHyphen).Append(" _").Append(cellInstanceNameWithoutHyphen).AppendLine(";");
else if (i == 1) else if (i == 1)
_ = stringBuilder. _ = stringBuilder.
Append("public class ").Append(cellInstanceNameWithoutHyphen).AppendLine(" : EAFLoggingUnitTesting"). Append("public class ").Append(cellInstanceNameWithoutHyphen).AppendLine(" : EAFLoggingUnitTesting").
AppendLine("{"). AppendLine("{").
AppendLine(). AppendLine().
Append("private static ").Append(cellInstanceNameWithoutHyphen).AppendLine(" _EAFLoggingUnitTesting;"). AppendLine("#pragma warning disable CA2254").
Append("internal static ").Append(cellInstanceNameWithoutHyphen).AppendLine(" EAFLoggingUnitTesting => _EAFLoggingUnitTesting;"); AppendLine("#pragma warning disable IDE0060").
AppendLine().
Append("internal static ").Append(cellInstanceNameWithoutHyphen).AppendLine(" EAFLoggingUnitTesting { get; private set; }");
else else
throw new Exception(); throw new Exception();
if (i == 2) if (i == 2)
@ -479,7 +475,7 @@ public class AdaptationTesting : ISMTP
AppendLine(). AppendLine().
Append("public ").Append(cellInstanceNameWithoutHyphen).AppendLine("() : base(testContext: null, declaringType: null, skipEquipmentDictionary: false)"). Append("public ").Append(cellInstanceNameWithoutHyphen).AppendLine("() : base(testContext: null, declaringType: null, skipEquipmentDictionary: false)").
AppendLine("{"). AppendLine("{").
AppendLine("if (_EAFLoggingUnitTesting is null)"). AppendLine("if (EAFLoggingUnitTesting is null)").
AppendLine("throw new Exception();"). AppendLine("throw new Exception();").
AppendLine("}"). AppendLine("}").
AppendLine(). AppendLine().
@ -500,10 +496,10 @@ public class AdaptationTesting : ISMTP
AppendLine("}"); AppendLine("}");
else if (i == 1) else if (i == 1)
_ = stringBuilder. _ = stringBuilder.
AppendLine("if (_EAFLoggingUnitTesting is null)"). AppendLine("if (EAFLoggingUnitTesting is null)").
Append("_EAFLoggingUnitTesting = new ").Append(cellInstanceNameWithoutHyphen).AppendLine("(testContext);"). Append("EAFLoggingUnitTesting = new ").Append(cellInstanceNameWithoutHyphen).AppendLine("(testContext);").
AppendLine("_EAFLoggingUnitTesting.Logger.LogInformation(string.Concat(testContext.TestName, \" - ClassInitialize\"));"). AppendLine("EAFLoggingUnitTesting.Logger.LogInformation(string.Concat(testContext.TestName, \" - ClassInitialize\"));").
AppendLine("string[] fileNameAndText = _EAFLoggingUnitTesting.AdaptationTesting.GetCSharpText(testContext.TestName);"). AppendLine("string[] fileNameAndText = EAFLoggingUnitTesting.AdaptationTesting.GetCSharpText(testContext.TestName);").
AppendLine("File.WriteAllText(fileNameAndText[0], fileNameAndText[1]);"). AppendLine("File.WriteAllText(fileNameAndText[0], fileNameAndText[1]);").
AppendLine("File.WriteAllText(fileNameAndText[2], fileNameAndText[3]);"). AppendLine("File.WriteAllText(fileNameAndText[2], fileNameAndText[3]);").
AppendLine("}"); AppendLine("}");
@ -517,10 +513,10 @@ public class AdaptationTesting : ISMTP
AppendLine("[ClassCleanup()]"). AppendLine("[ClassCleanup()]").
AppendLine("public static void ClassCleanup()"). AppendLine("public static void ClassCleanup()").
AppendLine("{"). AppendLine("{").
AppendLine("if (!(_EAFLoggingUnitTesting.Logger is null))"). AppendLine("if (EAFLoggingUnitTesting.Logger is not null)").
AppendLine("_EAFLoggingUnitTesting.Logger.LogInformation(\"Cleanup\");"). AppendLine("EAFLoggingUnitTesting.Logger.LogInformation(\"Cleanup\");").
AppendLine("if (!(_EAFLoggingUnitTesting is null))"). AppendLine("if (EAFLoggingUnitTesting is not null)").
AppendLine("_EAFLoggingUnitTesting.Dispose();"). AppendLine("EAFLoggingUnitTesting.Dispose();").
AppendLine("}"). AppendLine("}").
AppendLine(); AppendLine();
else else
@ -541,46 +537,35 @@ public class AdaptationTesting : ISMTP
check = (from l in componentsCellComponentCellComponent.Equipment.ConnectionSettings.Setting where l.Name == sourceDirectoryCloaking select l.Value).FirstOrDefault(); check = (from l in componentsCellComponentCellComponent.Equipment.ConnectionSettings.Setting where l.Name == sourceDirectoryCloaking select l.Value).FirstOrDefault();
if (string.IsNullOrEmpty(check)) if (string.IsNullOrEmpty(check))
check = componentsCellComponentCellComponent.Equipment.SourceFileFilter; check = componentsCellComponentCellComponent.Equipment.SourceFileFilter;
if (i == 2)
{
_ = stringBuilder. _ = stringBuilder.
AppendLine("[TestMethod]"). AppendLine("[TestMethod]").
Append("public void ").Append(methodName).AppendLine("()"). Append("public void ").Append(methodName).Append("() => ").Append('_').Append(cellInstanceNameWithoutHyphen).Append('.').Append(methodName).AppendLine("();");
AppendLine("{"); }
if (i == 2)
_ = stringBuilder.Append('_').Append(cellInstanceNameWithoutHyphen).Append('.').Append(methodName).AppendLine("();");
else if (i == 1) else if (i == 1)
{ {
if (componentsCellComponentCellComponent.Equipment.EquipmentType.Version != cellInstanceVersionName) if (componentsCellComponentCellComponent.Equipment.EquipmentType.Version != cellInstanceVersionName)
throw new Exception("Versions should match!"); throw new Exception("Versions should match!");
equipmentTypeName = componentsCellComponentCellComponent.Equipment.EquipmentType.Name; equipmentTypeName = componentsCellComponentCellComponent.Equipment.EquipmentType.Name;
_ = stringBuilder. _ = stringBuilder.
AppendLine("[TestMethod]").
Append("public void ").Append(methodName).AppendLine("()").
AppendLine("{").
Append("string check = \"").Append(check.Split('\\').Last()).AppendLine("\";"). Append("string check = \"").Append(check.Split('\\').Last()).AppendLine("\";").
AppendLine("MethodBase methodBase = new StackFrame().GetMethod();"). AppendLine("MethodBase methodBase = new StackFrame().GetMethod();").
AppendLine("_EAFLoggingUnitTesting.Logger.LogInformation(string.Concat(methodBase.Name, \" - Getting configuration\"));"). AppendLine("EAFLoggingUnitTesting.Logger.LogInformation(string.Concat(methodBase.Name, \" - Getting configuration\"));").
AppendLine("string[] fileNameAndJson = _EAFLoggingUnitTesting.AdaptationTesting.GetConfiguration(methodBase);"). AppendLine("_ = Helpers.Metrology.GetWriteConfigurationGetFileRead(methodBase, check, EAFLoggingUnitTesting.AdaptationTesting);").
AppendLine("Assert.IsTrue(fileNameAndJson[1].Contains(check));"). AppendLine("EAFLoggingUnitTesting.Logger.LogInformation(string.Concat(methodBase.Name, \" - Exit\"));").
AppendLine("File.WriteAllText(fileNameAndJson[0], fileNameAndJson[1]);");
if (componentsCellComponentCellComponent.Equipment.EquipmentType.Name == componentsCellComponentCellComponentEquipmentTypeNames[0])
_ = stringBuilder.
AppendLine("IFileRead fileRead = _EAFLoggingUnitTesting.AdaptationTesting.Get(methodBase, sourceFileLocation: string.Empty, sourceFileFilter: string.Empty, useCyclicalForDescription: false);").
AppendLine("Assert.IsFalse(string.IsNullOrEmpty(fileRead.CellInstanceConnectionName));");
_ = stringBuilder.
AppendLine("_EAFLoggingUnitTesting.Logger.LogInformation(string.Concat(methodBase.Name, \" - Exit\"));");
}
else
throw new Exception();
_ = stringBuilder.
AppendLine("}"). AppendLine("}").
AppendLine(); AppendLine();
} }
else
throw new Exception();
}
_ = stringBuilder. _ = stringBuilder.
AppendLine("}"). AppendLine("}").
AppendLine(). AppendLine();
AppendLine("}").
AppendLine().
AppendLine("// dotnet build --runtime win-x64").
Append("// dotnet test --runtime win-x64 --no-build --filter \"FullyQualifiedName~_Tests.").Append(loopName).Append('.').Append(_Environment).Append('.').Append(cellInstanceVersionNameAsCode).AppendLine("\" --% -- TestRunParameters.Parameter(name=\\\"Debug\\\", value=\\\"Debugger.IsAttached\\\")").
Append("// dotnet test --runtime win-x64 --no-build --filter \"FullyQualifiedName~_Tests.").Append(loopName).Append('.').Append(_Environment).Append('.').Append(cellInstanceVersionNameAsCode).Append(" & ClassName~").Append(cellInstanceNameWithoutHyphen).AppendLine("\" --% -- TestRunParameters.Parameter(name=\\\"Debug\\\", value=\\\"Debugger.IsAttached\\\")").
Append("// dotnet test --runtime win-x64 --no-build --filter \"FullyQualifiedName~_Tests.").Append(loopName).Append('.').Append(_Environment).Append('.').Append(cellInstanceVersionNameAsCode).Append(" & ClassName~").Append(cellInstanceNameWithoutHyphen).Append(" & ").Append(methodName).AppendLine("\" --% -- TestRunParameters.Parameter(name=\\\"Debug\\\", value=\\\"Debugger.IsAttached\\\")");
if (i == 2) if (i == 2)
extractText = stringBuilder.ToString().Trim(); extractText = stringBuilder.ToString().Trim();
else if (i == 1) else if (i == 1)