From 39b484bfe6fad17d9d4033c357657aceb13e4641 Mon Sep 17 00:00:00 2001 From: MPostol Date: Sat, 10 Sep 2022 12:24:34 +0200 Subject: [PATCH] UAObjectTypeTestMethod - fix UT errors #679 fixes #679 --- .../Helpers/TracedAddressSpaceContext.cs | 84 +++++++++---------- 1 file changed, 41 insertions(+), 43 deletions(-) diff --git a/SemanticData/Tests/USNodeSetValidationUnitTestProject/Helpers/TracedAddressSpaceContext.cs b/SemanticData/Tests/USNodeSetValidationUnitTestProject/Helpers/TracedAddressSpaceContext.cs index 1cd1e33e..02fd126f 100644 --- a/SemanticData/Tests/USNodeSetValidationUnitTestProject/Helpers/TracedAddressSpaceContext.cs +++ b/SemanticData/Tests/USNodeSetValidationUnitTestProject/Helpers/TracedAddressSpaceContext.cs @@ -52,6 +52,7 @@ internal TracedAddressSpaceContext(string path) : this() FileInfo testDataFileInfo = new FileInfo(path); Assert.IsTrue(testDataFileInfo.Exists); IUANodeSet iUANodeSet = UANodeSet.ReadModelFile(testDataFileInfo); + Assert.IsNotNull(iUANodeSet); AddressSpace.ImportUANodeSet(iUANodeSet); } @@ -62,52 +63,12 @@ internal TracedAddressSpaceContext(string path) : this() /// internal TracedAddressSpaceContext() { - Log.Clear(); - AddressSpace = addressSpaceContext.Value; + AddressSpace = AddressSpaceFactory.AddressSpace(Log); + AddressSpace.ImportUANodeSet(UANodeSet.ReadUADefinedTypes()); } - private class BuildErrorsHandling : IBuildErrorsHandling - { - internal void Clear() - { - Errors = 0; - TraceList.Clear(); - } - - internal List TraceList = new List(); - - #region IBuildErrorsHandling - - public int Errors { get; set; } = 0; - - public void TraceData(TraceEventType eventType, int id, object data) - { - throw new NotImplementedException($"{nameof(TraceData)} must not be used"); - } - - public void WriteTraceMessage(TraceMessage traceMessage) - { - Console.WriteLine(traceMessage.ToString()); - if (traceMessage.BuildError.Focus == Focus.Diagnostic) - return; - Errors++; - TraceList.Add(traceMessage); - } - - #endregion IBuildErrorsHandling - } - - private static BuildErrorsHandling Log = new BuildErrorsHandling(); - - private static Lazy addressSpaceContext = new Lazy(() => - { - var x = AddressSpaceFactory.AddressSpace(Log); - x.ImportUANodeSet(UANodeSet.ReadUADefinedTypes()); - return x; - }); - internal TraceMessage this[int i] => Log.TraceList[i]; - internal IAddressSpaceContext AddressSpace = null; + internal IAddressSpaceContext AddressSpace { get; private set; } internal void UTAddressSpaceCheckConsistency(Action action) { @@ -163,5 +124,42 @@ internal void Clear() { Log.Clear(); } + + #region private instrumentation + + private class BuildErrorsHandling : IBuildErrorsHandling + { + internal void Clear() + { + Errors = 0; + TraceList.Clear(); + } + + internal List TraceList = new List(); + + #region IBuildErrorsHandling + + public int Errors { get; set; } = 0; + + public void TraceData(TraceEventType eventType, int id, object data) + { + throw new NotImplementedException($"{nameof(TraceData)} must not be used"); + } + + public void WriteTraceMessage(TraceMessage traceMessage) + { + Console.WriteLine(traceMessage.ToString()); + if (traceMessage.BuildError.Focus == Focus.Diagnostic) + return; + Errors++; + TraceList.Add(traceMessage); + } + + #endregion IBuildErrorsHandling + } + + private BuildErrorsHandling Log = new BuildErrorsHandling(); + + #endregion private instrumentation } } \ No newline at end of file