2024-10-31 09:53:26 -07:00

128 lines
4.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Adaptation._Tests.Shared;
using Microsoft.Extensions.Logging;
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.Text;
namespace Adaptation._Tests.Static;
[TestClass]
public class MET08RESIHGCV : LoggingUnitTesting, IDisposable
{
#pragma warning disable CA2254
#pragma warning disable IDE0060
internal static MET08RESIHGCV LoggingUnitTesting { get; private set; }
public MET08RESIHGCV() : base(testContext: null, declaringType: null)
{
if (LoggingUnitTesting is null)
throw new Exception();
}
public MET08RESIHGCV(TestContext testContext) : base(testContext, new StackFrame().GetMethod().DeclaringType)
{
}
[ClassInitialize]
public static void ClassInitialize(TestContext testContext) => LoggingUnitTesting ??= new MET08RESIHGCV(testContext);
[ClassCleanup()]
public static void ClassCleanup()
{
LoggingUnitTesting?.Logger?.LogInformation("Cleanup");
LoggingUnitTesting?.Dispose();
}
private static void NonThrowTryCatch()
{
try
{ throw new Exception(); }
catch (Exception) { }
}
[TestMethod]
public void TestDateTime()
{
DateTime dateTime = DateTime.Now;
Assert.IsTrue(dateTime.ToString("M/d/yyyy h:mm:ss tt") == dateTime.ToString());
}
#if DEBUG
[Ignore]
#endif
[TestMethod]
public void Production()
{
MethodBase methodBase = new StackFrame().GetMethod();
StringBuilder results = new();
(string cellInstanceName, string cellInstanceVersionName)[] collection = new (string, string)[]
{
new("MET08RESIHGCV", "v2.57.0"),
};
string production = "http://messa08ec.infineon.com:9003/CellInstanceServiceV2";
Shared.PasteSpecialXml.EAF.XML.API.CellInstance.CellInstanceVersion cellInstanceVersion;
LoggingUnitTesting.Logger.LogInformation(string.Concat(methodBase.Name, " - Getting configuration"));
foreach ((string cellInstanceName, string cellInstanceVersionName) in collection)
{
cellInstanceVersion = AdaptationTesting.GetCellInstanceVersion($"{production}/{cellInstanceName}/{cellInstanceVersionName}/configuration");
_ = results.AppendLine($"{cellInstanceName}\t{cellInstanceVersionName}\t{cellInstanceVersion.EdaConnection.PortNumber}");
}
string sourceDirectory = "D:/Tmp/cellInstanceVersion.EdaConnection.PortNumber";
if (!Directory.Exists(sourceDirectory))
_ = Directory.CreateDirectory(sourceDirectory);
File.WriteAllText(Path.Combine(sourceDirectory, $"{methodBase.Module.Name}-{methodBase.ReflectedType.Name}-{methodBase.Name}.tsv"), results.ToString());
LoggingUnitTesting.Logger.LogInformation(string.Concat(methodBase.Name, " - Exit"));
}
[TestMethod]
public void CellInstanceVersionEdaConnectionPortNumber()
{
MethodBase methodBase = new StackFrame().GetMethod();
string sourceDirectory = "D:/Tmp/cellInstanceVersion.EdaConnection.PortNumber";
if (Directory.Exists(sourceDirectory))
{
string destinationDirectory = Path.Combine(sourceDirectory, "All");
if (!Directory.Exists(destinationDirectory))
_ = Directory.CreateDirectory(destinationDirectory);
List<string> lines = new();
string[] files = Directory.GetFiles(sourceDirectory, "*.tsv", SearchOption.TopDirectoryOnly);
foreach (string file in files)
lines.AddRange(File.ReadAllLines(file));
File.WriteAllLines(Path.Combine(destinationDirectory, $"{DateTime.Now.Ticks}.tsv"), lines.Distinct().OrderBy(l => l));
}
LoggingUnitTesting.Logger.LogInformation(string.Concat(methodBase.Name, " - Exit"));
NonThrowTryCatch();
}
[TestMethod]
public void TestDeltaMean()
{
// (0.3864 0.4286) / 0.4286 * 100 = -9.846 %
float a = 0.4286f;
float b = 0.3864f;
float c = 100;
float d = -9.84601f;
Assert.IsTrue((b - a) / a * c == d);
NonThrowTryCatch();
}
[TestMethod]
public void TestSubgroupId()
{
int subgroupId = 1715715363;
DateTime ticksDateTime = new(638512869386943434);
DateTime epicDateTime = new(1970, 01, 01, 0, 0, 0, DateTimeKind.Utc);
DateTime subgroupIdDateTime = epicDateTime.AddSeconds(subgroupId).ToLocalTime();
TimeSpan timeSpan = new(ticksDateTime.Ticks - subgroupIdDateTime.Ticks);
Assert.IsTrue(timeSpan.TotalHours is < 1 and > (-1));
NonThrowTryCatch();
}
}