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)
_CellNames.Add(modelObjectParameterDefinition.Name.Split('.')[1], modelObjectParameterDefinition.Value);
_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!");
if (_IsDummy)
{

View File

@ -30,7 +30,7 @@ public class FileRead : Shared.FileRead, IFileRead
if (_IsDuplicator)
throw new Exception(cellInstanceConnectionName);
_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!");
}

View File

@ -432,29 +432,20 @@ public class AdaptationTesting : ISMTP
loopName = "CreateSelfDescription";
else
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.
AppendLine("using Adaptation.Shared.Methods;").
AppendLine("using Microsoft.Extensions.Logging;").
AppendLine("using Microsoft.VisualStudio.TestTools.UnitTesting;").
AppendLine("using Shared;").
AppendLine("using System;").
AppendLine("using System.Collections.Generic;").
AppendLine("using System.Diagnostics;").
AppendLine("using System.IO;").
AppendLine("using System.Reflection;").
AppendLine("using System.Text.Json;").
AppendLine("using System.Threading;");
else
throw new Exception();
_ = stringBuilder.
AppendLine("using Adaptation.Shared.Methods;").
AppendLine("using Microsoft.Extensions.Logging;").
AppendLine("using Microsoft.VisualStudio.TestTools.UnitTesting;").
AppendLine("using Shared;").
AppendLine("using System;").
AppendLine("using System.Collections.Generic;").
AppendLine("using System.Diagnostics;").
AppendLine("using System.IO;").
AppendLine("using System.Reflection;").
AppendLine("using System.Text.Json;").
AppendLine("using System.Threading;");
_ = stringBuilder.AppendLine().
Append("namespace _Tests.").Append(loopName).Append('.').Append(_Environment).Append('.').AppendLine(cellInstanceVersionNameAsCode).
AppendLine("{").
Append("namespace _Tests.").Append(loopName).Append('.').Append(_Environment).Append('.').Append(cellInstanceVersionNameAsCode).AppendLine(";").
AppendLine().
AppendLine("[TestClass]");
if (i == 2)
@ -462,14 +453,19 @@ public class AdaptationTesting : ISMTP
Append("public class ").AppendLine(cellInstanceNameWithoutHyphen).
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(";");
else if (i == 1)
_ = stringBuilder.
Append("public class ").Append(cellInstanceNameWithoutHyphen).AppendLine(" : EAFLoggingUnitTesting").
AppendLine("{").
AppendLine().
Append("private static ").Append(cellInstanceNameWithoutHyphen).AppendLine(" _EAFLoggingUnitTesting;").
Append("internal static ").Append(cellInstanceNameWithoutHyphen).AppendLine(" EAFLoggingUnitTesting => _EAFLoggingUnitTesting;");
AppendLine("#pragma warning disable CA2254").
AppendLine("#pragma warning disable IDE0060").
AppendLine().
Append("internal static ").Append(cellInstanceNameWithoutHyphen).AppendLine(" EAFLoggingUnitTesting { get; private set; }");
else
throw new Exception();
if (i == 2)
@ -479,7 +475,7 @@ public class AdaptationTesting : ISMTP
AppendLine().
Append("public ").Append(cellInstanceNameWithoutHyphen).AppendLine("() : base(testContext: null, declaringType: null, skipEquipmentDictionary: false)").
AppendLine("{").
AppendLine("if (_EAFLoggingUnitTesting is null)").
AppendLine("if (EAFLoggingUnitTesting is null)").
AppendLine("throw new Exception();").
AppendLine("}").
AppendLine().
@ -500,10 +496,10 @@ public class AdaptationTesting : ISMTP
AppendLine("}");
else if (i == 1)
_ = stringBuilder.
AppendLine("if (_EAFLoggingUnitTesting is null)").
Append("_EAFLoggingUnitTesting = new ").Append(cellInstanceNameWithoutHyphen).AppendLine("(testContext);").
AppendLine("_EAFLoggingUnitTesting.Logger.LogInformation(string.Concat(testContext.TestName, \" - ClassInitialize\"));").
AppendLine("string[] fileNameAndText = _EAFLoggingUnitTesting.AdaptationTesting.GetCSharpText(testContext.TestName);").
AppendLine("if (EAFLoggingUnitTesting is null)").
Append("EAFLoggingUnitTesting = new ").Append(cellInstanceNameWithoutHyphen).AppendLine("(testContext);").
AppendLine("EAFLoggingUnitTesting.Logger.LogInformation(string.Concat(testContext.TestName, \" - ClassInitialize\"));").
AppendLine("string[] fileNameAndText = EAFLoggingUnitTesting.AdaptationTesting.GetCSharpText(testContext.TestName);").
AppendLine("File.WriteAllText(fileNameAndText[0], fileNameAndText[1]);").
AppendLine("File.WriteAllText(fileNameAndText[2], fileNameAndText[3]);").
AppendLine("}");
@ -517,10 +513,10 @@ public class AdaptationTesting : ISMTP
AppendLine("[ClassCleanup()]").
AppendLine("public static void ClassCleanup()").
AppendLine("{").
AppendLine("if (!(_EAFLoggingUnitTesting.Logger is null))").
AppendLine("_EAFLoggingUnitTesting.Logger.LogInformation(\"Cleanup\");").
AppendLine("if (!(_EAFLoggingUnitTesting is null))").
AppendLine("_EAFLoggingUnitTesting.Dispose();").
AppendLine("if (EAFLoggingUnitTesting.Logger is not null)").
AppendLine("EAFLoggingUnitTesting.Logger.LogInformation(\"Cleanup\");").
AppendLine("if (EAFLoggingUnitTesting is not null)").
AppendLine("EAFLoggingUnitTesting.Dispose();").
AppendLine("}").
AppendLine();
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();
if (string.IsNullOrEmpty(check))
check = componentsCellComponentCellComponent.Equipment.SourceFileFilter;
_ = stringBuilder.
AppendLine("[TestMethod]").
Append("public void ").Append(methodName).AppendLine("()").
AppendLine("{");
if (i == 2)
_ = stringBuilder.Append('_').Append(cellInstanceNameWithoutHyphen).Append('.').Append(methodName).AppendLine("();");
{
_ = stringBuilder.
AppendLine("[TestMethod]").
Append("public void ").Append(methodName).Append("() => ").Append('_').Append(cellInstanceNameWithoutHyphen).Append('.').Append(methodName).AppendLine("();");
}
else if (i == 1)
{
if (componentsCellComponentCellComponent.Equipment.EquipmentType.Version != cellInstanceVersionName)
throw new Exception("Versions should match!");
equipmentTypeName = componentsCellComponentCellComponent.Equipment.EquipmentType.Name;
_ = stringBuilder.
AppendLine("[TestMethod]").
Append("public void ").Append(methodName).AppendLine("()").
AppendLine("{").
Append("string check = \"").Append(check.Split('\\').Last()).AppendLine("\";").
AppendLine("MethodBase methodBase = new StackFrame().GetMethod();").
AppendLine("_EAFLoggingUnitTesting.Logger.LogInformation(string.Concat(methodBase.Name, \" - Getting configuration\"));").
AppendLine("string[] fileNameAndJson = _EAFLoggingUnitTesting.AdaptationTesting.GetConfiguration(methodBase);").
AppendLine("Assert.IsTrue(fileNameAndJson[1].Contains(check));").
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\"));");
AppendLine("EAFLoggingUnitTesting.Logger.LogInformation(string.Concat(methodBase.Name, \" - Getting configuration\"));").
AppendLine("_ = Helpers.Metrology.GetWriteConfigurationGetFileRead(methodBase, check, EAFLoggingUnitTesting.AdaptationTesting);").
AppendLine("EAFLoggingUnitTesting.Logger.LogInformation(string.Concat(methodBase.Name, \" - Exit\"));").
AppendLine("}").
AppendLine();
}
else
throw new Exception();
_ = stringBuilder.
AppendLine("}").
AppendLine();
}
_ = stringBuilder.
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\\\")");
AppendLine();
if (i == 2)
extractText = stringBuilder.ToString().Trim();
else if (i == 1)