164 lines
8.6 KiB
C#

// using Adaptation.Shared.Deposition;
// using Microsoft.VisualStudio.TestTools.UnitTesting;
// using System;
// using System.Collections.Generic;
// using System.Diagnostics;
// using System.IO;
// using System.Linq;
// using System.Reflection;
// using System.Runtime.InteropServices;
// using System.Text;
// using System.Text.Json;
// namespace _Tests.Helpers
// {
// public class Helper
// {
// public static string GetLaunchText()
// {
// StringBuilder result = new();
// _ = result.
// AppendLine("{").
// AppendLine(" \"configurations\": [").
// AppendLine(" {").
// AppendLine(" \"name\": \".NET Core Attach\",").
// AppendLine(" \"type\": \"coreclr\",").
// AppendLine(" \"request\": \"attach\",").
// AppendLine($" \"processId\": {System.Diagnostics.Process.GetCurrentProcess().Id}").
// AppendLine(" }").
// AppendLine(" ]").
// AppendLine("}");
// return result.ToString();
// }
// public static string GetProjectDirectory()
// {
// string result;
// string[] checkFiles = null;
// Assembly assembly = Assembly.GetExecutingAssembly();
// result = Path.GetDirectoryName(assembly.Location);
// for (int i = 0; i < int.MaxValue; i++)
// {
// if (string.IsNullOrEmpty(result))
// break;
// checkFiles = Directory.GetFiles(result, "*.Tests.csproj", SearchOption.TopDirectoryOnly);
// if (checkFiles.Any())
// break;
// result = Path.GetDirectoryName(result);
// }
// if (string.IsNullOrEmpty(result) || checkFiles is null || !checkFiles.Any())
// throw new Exception(result);
// return result;
// }
// public static string[] GetVariables(string jsonFile, string sourceDirectoryCloaking)
// {
// string[] results;
// string sourceFileFilter = string.Empty;
// string sourceFileLocation = string.Empty;
// string projectDirectory = GetProjectDirectory();
// string equipmentTypeDirectory = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(projectDirectory)));
// string testResultsDirectory = Path.Combine(equipmentTypeDirectory, "05_TestResults");
// FileInfo fileInfo = new(string.Concat(testResultsDirectory, jsonFile));
// if (!Directory.Exists(fileInfo.Directory.FullName))
// _ = Directory.CreateDirectory(fileInfo.Directory.FullName);
// if (!fileInfo.Exists)
// _ = Process.Start("explorer.exe", fileInfo.Directory.FullName);
// string json = File.ReadAllText(fileInfo.FullName);
// Assert.IsTrue(json.Contains(sourceDirectoryCloaking));
// JsonElement jsonElement = JsonSerializer.Deserialize<JsonElement>(json);
// foreach (JsonProperty jsonProperty in jsonElement.EnumerateObject())
// {
// if (jsonProperty.Name == "SourceFileLocation")
// sourceFileLocation = jsonProperty.Value.ToString();
// else if (jsonProperty.Name == "SourceFileFilter")
// sourceFileFilter = jsonProperty.Value.ToString();
// }
// results = new string[] { jsonFile, json, sourceFileLocation, sourceFileFilter };
// Assert.IsFalse(string.IsNullOrEmpty(results[0]));
// Assert.IsFalse(string.IsNullOrEmpty(results[1]));
// Assert.IsFalse(string.IsNullOrEmpty(results[2]));
// Assert.IsFalse(string.IsNullOrEmpty(results[3]));
// return results;
// }
// public static Tuple<string, string[], string[]> GetLogisticsColumnsAndBody(string searchDirectory, string searchPattern)
// {
// Tuple<string, string[], string[]> results;
// string[] pdsfFiles;
// pdsfFiles = Directory.GetFiles(searchDirectory, searchPattern, SearchOption.TopDirectoryOnly);
// if (!pdsfFiles.Any())
// _ = Process.Start("explorer.exe", searchDirectory);
// Assert.IsTrue(pdsfFiles.Any(), "GetFiles check");
// results = ProcessDataStandardFormat.GetLogisticsColumnsAndBody(pdsfFiles[0]);
// Assert.IsFalse(string.IsNullOrEmpty(results.Item1));
// Assert.IsTrue(results.Item2.Length > 0, "Column check");
// Assert.IsTrue(results.Item3.Length > 0, "Body check");
// return results;
// }
// public static Tuple<string, string[], string[]> GetLogisticsColumnsAndBody(ConfigDataBase configDataBase, ILogic logic, Tuple<string, JsonElement?, List<FileInfo>> extractResult, Tuple<string, string[], string[]> pdsf)
// {
// Tuple<string, string[], string[]> results;
// string text = ProcessDataStandardFormat.GetPDSFText(logic, configDataBase.GetEventName(), configDataBase.GetEquipmentType(), extractResult.Item2.Value, logisticsText: pdsf.Item1);
// string[] lines = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
// results = ProcessDataStandardFormat.GetLogisticsColumnsAndBody(logic.Logistics.ReportFullPath, lines);
// Assert.IsFalse(string.IsNullOrEmpty(results.Item1));
// Assert.IsTrue(results.Item2.Length > 0, "Column check");
// Assert.IsTrue(results.Item3.Length > 0, "Body check");
// return results;
// }
// public static string[] GetItem2(Tuple<string, string[], string[]> pdsf, Tuple<string, string[], string[]> pdsfNew)
// {
// JsonSerializerOptions jsonSerializerOptions = new() { WriteIndented = true };
// string jsonOld = JsonSerializer.Serialize(pdsf.Item2, pdsf.Item2.GetType(), jsonSerializerOptions);
// string jsonNew = JsonSerializer.Serialize(pdsfNew.Item2, pdsfNew.Item2.GetType(), jsonSerializerOptions);
// return new string[] { jsonOld, jsonNew };
// }
// public static string[] GetItem3(Tuple<string, string[], string[]> pdsf, Tuple<string, string[], string[]> pdsfNew)
// {
// string joinOld = string.Join(Environment.NewLine, from l in pdsf.Item3 select string.Join('\t', from t in l.Split('\t') where !t.Contains(@"\\") select t));
// string joinNew = string.Join(Environment.NewLine, from l in pdsfNew.Item3 select string.Join('\t', from t in l.Split('\t') where !t.Contains(@"\\") select t));
// return new string[] { joinOld, joinNew };
// }
// public static void UpdatePassDirectory(string[] variables, MethodBase methodBase)
// {
// string passDirectory = Path.Combine(variables[2], methodBase.Name);
// if (!Directory.Exists(passDirectory))
// _ = Directory.CreateDirectory(passDirectory);
// else
// Directory.SetLastWriteTime(variables[2], DateTime.Now);
// }
// public static string GetFileName(MethodBase methodBase)
// {
// string result;
// string[] segments = methodBase.Name.Split(new string[] { "__" }, StringSplitOptions.None);
// string environment = segments[0];
// string rawVersionName = segments[1];
// string equipmentTypeDirectory = segments[2];
// string ticks = DateTime.Now.Ticks.ToString();
// string comment = segments[segments.Length - 1];
// string versionName = segments[1].Replace('_', '.');
// string before = string.Concat(environment, "__", rawVersionName, "__", equipmentTypeDirectory, "__");
// string after = methodBase.Name.Substring(before.Length);
// string connectionNameAndTicks = after.Substring(0, after.Length - 2 - comment.Length);
// string connectionName = connectionNameAndTicks.Substring(0, connectionNameAndTicks.Length - ticks.Length);
// ticks = connectionNameAndTicks.Substring(connectionName.Length);
// result = Path.Combine(environment, equipmentTypeDirectory, versionName, $"{environment}__{rawVersionName}__{equipmentTypeDirectory}__{connectionName}", ticks, $"{connectionName.Replace('_', '-')}.json");
// if (result.Contains('/'))
// result = string.Concat('/', result);
// else
// result = string.Concat('\\', result);
// return result;
// }
// }
// }