Skip to content

Commit

Permalink
UAObjectTypeTestMethod - fix UT errors #679
Browse files Browse the repository at this point in the history
fixes #679
  • Loading branch information
mpostol committed Sep 10, 2022
1 parent 4213bfd commit 39b484b
Showing 1 changed file with 41 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -62,52 +63,12 @@ internal TracedAddressSpaceContext(string path) : this()
/// </summary>
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<TraceMessage> TraceList = new List<TraceMessage>();

#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<IAddressSpaceContext> addressSpaceContext = new Lazy<IAddressSpaceContext>(() =>
{
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<IUANodeContext> action)
{
Expand Down Expand Up @@ -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<TraceMessage> TraceList = new List<TraceMessage>();

#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
}
}

0 comments on commit 39b484b

Please sign in to comment.