Skip to content

Commit

Permalink
Import simple NodeSet2 file is incomplete #510
Browse files Browse the repository at this point in the history
- cleanup code - removed useless comments - unimportant changes
- UT 👎
  • Loading branch information
mpostol committed Feb 20, 2021
1 parent 45891b0 commit 98d7e2b
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,6 @@ public void ImportUANodeSetTest()
UANodeSet newNodeSet = TestData.CreateNodeSetModel();
newNodeSet.Items = new UANode[]
{
//<UAObjectType NodeId="ns=1;i=12" BrowseName="1:VehicleType">
// <DisplayName>VehicleType</DisplayName>
// <References>
// <Reference ReferenceType="HasSubtype" IsForward="false">i=58</Reference>
// </References>
//</UAObjectType>
new UAObjectType()
{
NodeId = "ns=1;i=12",
Expand All @@ -112,14 +106,6 @@ public void ImportUANodeSetTest()
new Reference() { ReferenceType = ReferenceTypeIds.HasSubtype.ToString(), IsForward = false, Value = "i=58" }
},
},
//<UAVariable DataType="DateTime" NodeId="ns=1;i=13" BrowseName="buildDate" ParentNodeId="ns=1;i=12">
// <DisplayName>buildDate</DisplayName>
// <References>
// <Reference ReferenceType="HasProperty" IsForward="false">ns=1; i = 12 </Reference>
// <Reference ReferenceType = "HasTypeDefinition" > i = 63 </ Reference >
// <Reference ReferenceType = "HasModellingRule" > i = 78 </ Reference >
// </ References >
//</ UAVariable >
new UAVariable()
{
NodeId = "ns=1;i=13",
Expand Down Expand Up @@ -209,12 +195,6 @@ public void GetMyReferencesTest()
UANodeSet newNodeSet = TestData.CreateNodeSetModel();
newNodeSet.Items = new UANode[]
{
//<UAObjectType NodeId="ns=1;i=12" BrowseName="1:VehicleType">
// <DisplayName>VehicleType</DisplayName>
// <References>
// <Reference ReferenceType="HasSubtype" IsForward="false">i=58</Reference>
// </References>
//</UAObjectType>
new UAObjectType()
{
NodeId = "ns=1;i=12",
Expand All @@ -224,14 +204,6 @@ public void GetMyReferencesTest()
new Reference() { ReferenceType = ReferenceTypeIds.HasSubtype.ToString(), IsForward = false, Value = "i=58" }
},
},
//<UAVariable DataType="DateTime" NodeId="ns=1;i=13" BrowseName="buildDate" ParentNodeId="ns=1;i=12">
// <DisplayName>buildDate</DisplayName>
// <References>
// <Reference ReferenceType="HasProperty" IsForward="false">ns=1; i = 12 </Reference>
// <Reference ReferenceType = "HasTypeDefinition" > i = 63 </ Reference >
// <Reference ReferenceType = "HasModellingRule" > i = 78 </ Reference >
// </ References >
//</ UAVariable >
new UAVariable()
{
NodeId = "ns=1;i=13",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@ public void CreateNamespace(string uri, string publicationDate, string version)
internal IEnumerable<NodeFactoryBase> Export()
{
List<NodeFactoryBase> nodes = new List<NodeFactoryBase>();
Export(x => nodes.Add(x));
base.Export(x => nodes.Add(x));
return nodes;
}

//public int NumberOfSelectedNodes<type>()
// where type : NodeFactoryBase
//{
// return m_Nodes.Where<NodeFactoryBase>(x => x.GetType() == typeof(type)).Count<NodeFactoryBase>();
//}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void eoursel510Test()
Assert.AreEqual(21, nodes.Count< NodeFactoryBase>());
Dictionary<string, NodeFactoryBase> nodesDictionary = nodes.ToDictionary<NodeFactoryBase, string>(x => x.SymbolicName.Name);
AddressSpaceContext asContext = addressSpace as AddressSpaceContext;
//TODO Add a warning that the AS contains nodes orphaned and inaccessible for browsing starting from the Root node #529
IEnumerable<IUANodeContext> allNodes = null;
asContext.UTValidateAndExportModel(1, x => allNodes = x);
Assert.IsNotNull(allNodes);
Expand All @@ -83,9 +84,6 @@ public void eoursel510Test()
Debug.WriteLine($"{item.ToString()}");
}
}
//Assert.AreEqual(4, testingModelFixture.NumberOfSelectedNodes<ObjectTypeFactoryBase>());
//Assert.AreEqual(3, testingModelFixture.NumberOfSelectedNodes<DataTypeFactoryBase>());
//Assert.AreEqual(1, testingModelFixture.NumberOfSelectedNodes<VariableTypeFactoryBase>());
Debug.WriteLine($"After removing inherited and instance declaration nodes the recovered information model contains {nodes.Count<NodeFactoryBase>()}");
}
}
Expand Down
70 changes: 40 additions & 30 deletions SemanticData/UAModelDesignExport.UnitTest/NodeSetUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

namespace UAOOI.SemanticData.UAModelDesignExport
{

[TestClass]
[DeploymentItem(@"Models\", @"Models\")]
public class NodeSetUnitTest
{

#region TestContext

private TestContext testContextInstance;

/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
Expand All @@ -34,9 +34,11 @@ public TestContext TestContext
get => testContextInstance;
set => testContextInstance = value;
}
#endregion

#endregion TestContext

#region TestMethod

[TestMethod]
[ExpectedExceptionAttribute(typeof(FileNotFoundException))]
public void FileNotFoundTestMethod()
Expand All @@ -47,6 +49,7 @@ public void FileNotFoundTestMethod()
int _diagnosticCounter = 0;
ModelDesign _actual = AddressSpaceContextService.CreateInstance(_testDataFileInfo, String.Empty, z => TraceDiagnostic(z, _trace, ref _diagnosticCounter));
}

[TestMethod]
[ExpectedExceptionAttribute(typeof(System.InvalidOperationException))]
public void WrongFileNFormatTestMethod()
Expand All @@ -58,6 +61,7 @@ public void WrongFileNFormatTestMethod()
string uri = "http://cas.eu/UA/CommServer/UnitTests/ReferenceTest";
ModelDesign _actual = AddressSpaceContextService.CreateInstance(_testDataFileInfo, uri, z => TraceDiagnostic(z, _trace, ref _diagnosticCounter));
}

[TestMethod]
public void UAReferenceTestMethod()
{
Expand All @@ -72,6 +76,7 @@ public void UAReferenceTestMethod()
Assert.AreEqual<int>(1, _expected.Items.Length);
CompareModelDesign(_expected, _actual);
}

[TestMethod]
public void UAObjectTypeTestMethod()
{
Expand All @@ -86,6 +91,7 @@ public void UAObjectTypeTestMethod()
Assert.AreEqual<int>(3, _expected.Items.Length);
CompareModelDesign(_expected, _actual);
}

[TestMethod]
public void UAVariableTypeTestMethod()
{
Expand All @@ -100,6 +106,7 @@ public void UAVariableTypeTestMethod()
Assert.AreEqual<int>(3, _expected.Items.Length);
CompareModelDesign(_expected, _actual);
}

[TestMethod]
public void UADataTypeTestMethod()
{
Expand All @@ -114,10 +121,13 @@ public void UADataTypeTestMethod()
Assert.AreEqual<int>(4, _expected.Items.Length);
CompareModelDesign(_expected, _actual);
}
#endregion

#endregion TestMethod

#region Test instrumentation

#region ModelDesign

private static void CompareModelDesign(ModelDesign expected, ModelDesign actual)
{
Assert.AreEqual<int>(expected.Items.Length, actual.Items.Length);
Expand All @@ -126,6 +136,7 @@ private static void CompareModelDesign(ModelDesign expected, ModelDesign actual)
foreach (NodeDesign _node in actual.Items)
CompareNode(_items[_node.SymbolicName.ToString()], _node);
}

public static void CompareNode(NodeDesign expected, NodeDesign actual)
{
if (expected.GetType() == typeof(ObjectTypeDesign))
Expand Down Expand Up @@ -156,6 +167,7 @@ private static void CompareDataTypeDesign(DataTypeDesign expected, DataTypeDesig
Compare(expected.Fields, actual.Fields);
CompareTypeDesign(expected, actual);
}

private static void CompareReferenceTypeDesign(ReferenceTypeDesign expected, ReferenceTypeDesign actual)
{
CompareTypeDesign(expected, actual);
Expand All @@ -164,6 +176,7 @@ private static void CompareReferenceTypeDesign(ReferenceTypeDesign expected, Ref
Assert.AreEqual<bool>(expected.SymmetricSpecified, actual.SymmetricSpecified);
Assert.AreEqual<bool>(expected.Symmetric, actual.Symmetric);
}

private static void CompareObjectTypeDesign(ObjectTypeDesign expected, ObjectTypeDesign actual)
{
CompareTypeDesign(expected, actual);
Expand All @@ -172,6 +185,7 @@ private static void CompareObjectTypeDesign(ObjectTypeDesign expected, ObjectTyp
Assert.IsFalse(expected.SupportsEvents, "Field not supported for types - should always be false");
Assert.IsFalse(actual.SupportsEvents, "Field not supported for types - should always be false");
}

private static void CompareVariableTypeDesign(VariableTypeDesign expected, VariableTypeDesign actual)
{
CompareTypeDesign(expected, actual);
Expand All @@ -183,7 +197,7 @@ private static void CompareVariableTypeDesign(VariableTypeDesign expected, Varia
if (expected.ValueRankSpecified)
Assert.AreEqual<ValueRank>(expected.ValueRank, actual.ValueRank);
Assert.AreEqual<string>(expected.ArrayDimensions, actual.ArrayDimensions);
//Not supported by the VariableType NodeClass
//Not supported by the VariableType NodeClass
Assert.IsFalse(expected.ExposesItsChildren);
Assert.IsFalse(actual.ExposesItsChildren);
Assert.IsFalse(expected.AccessLevelSpecified);
Expand All @@ -193,6 +207,7 @@ private static void CompareVariableTypeDesign(VariableTypeDesign expected, Varia
Assert.IsFalse(expected.MinimumSamplingIntervalSpecified);
Assert.IsFalse(actual.MinimumSamplingIntervalSpecified);
}

//Instances
private static void CompareObjectDesign(ObjectDesign expected, ObjectDesign actual)
{
Expand All @@ -201,6 +216,7 @@ private static void CompareObjectDesign(ObjectDesign expected, ObjectDesign actu
Assert.AreEqual<bool>(expected.SupportsEvents, actual.SupportsEvents);
CompareInstanceDesign(expected, actual);
}

private static void CompareVariableDesign(VariableDesign expected, VariableDesign actual)
{
Compare(expected.DefaultValue, actual.DefaultValue);
Expand All @@ -222,12 +238,14 @@ private static void CompareVariableDesign(VariableDesign expected, VariableDesig
Assert.AreEqual<bool>(expected.Historizing, actual.Historizing);
CompareInstanceDesign(expected, actual);
}

private static void ComparePropertyDesign(PropertyDesign expected, PropertyDesign actual)
{
Assert.IsNotNull(expected);
Assert.IsNotNull(actual);
CompareVariableDesign((VariableDesign)expected, (VariableDesign)actual);
}

private static void CompareMethodDesign(MethodDesign expected, MethodDesign actual)
{
Compare(expected.InputArguments, actual.InputArguments);
Expand All @@ -236,6 +254,7 @@ private static void CompareMethodDesign(MethodDesign expected, MethodDesign actu
Assert.IsFalse(actual.NonExecutable);
CompareInstanceDesign(expected, actual);
}

//base types
private static void CompareTypeDesign(TypeDesign expected, TypeDesign actual)
{
Expand All @@ -246,6 +265,7 @@ private static void CompareTypeDesign(TypeDesign expected, TypeDesign actual)
Assert.IsNotNull(actual.BaseType);
Assert.AreEqual<string>(expected.BaseType.ToString(), actual.BaseType.ToString());
}

private static void CompareInstanceDesign(InstanceDesign expected, InstanceDesign actual)
{
Assert.IsTrue(expected.GetType() == actual.GetType());
Expand All @@ -262,6 +282,7 @@ private static void CompareInstanceDesign(InstanceDesign expected, InstanceDesig
Assert.AreEqual<uint>(0, actual.MaxCardinality);
Assert.IsFalse(actual.PreserveDefaultAttributes);
}

private static void CompareNodeDesign(NodeDesign expected, NodeDesign actual)
{
Assert.IsTrue(expected.BrowseName.AreEqual(actual.BrowseName));
Expand All @@ -279,16 +300,18 @@ private static void CompareNodeDesign(NodeDesign expected, NodeDesign actual)
Assert.AreEqual<string>(expected.StringId, actual.StringId);
Assert.AreEqual<uint>(expected.PartNo, actual.PartNo);
}
#endregion

#endregion ModelDesign

#region private helper

/// <summary>
/// Compares the parameters of a method.
/// </summary>
/// <remarks>
/// ModelCompiler doesn't generate parameters if TypeDefinition for the method is not set.
/// TypeDefinition is not defined in the specification, but has to refer to a method defined top most level.
/// The ModelDesign contains parameters but the UANodeSet doesn't have.
/// The ModelDesign contains parameters but the UANodeSet doesn't have.
/// </remarks>
/// <param name="expected">The expected.</param>
/// <param name="actual">The actual.</param>
Expand All @@ -309,6 +332,7 @@ private static void Compare(Parameter[] expected, Parameter[] actual)
Assert.AreEqual<ValueRank>(expected[i].ValueRank, actual[i].ValueRank);
}
}

private static void CompareListOfChildren(ListOfChildren expected, ListOfChildren actual)
{
if (expected == null && actual == null)
Expand All @@ -327,28 +351,9 @@ private static void CompareListOfChildren(ListOfChildren expected, ListOfChildre
Type _actualType = _actualList[i].GetType();
Assert.AreSame(_expectedType, _actualType);
CompareNode(_expectedList[i], _actualList[i]);
//TODO #40, ValidateAndExportModel shall export also instances #40
//string nodeType = _expectedType.Name;
//switch (nodeType)
//{
// case "MethodDesign":
// Compare((MethodDesign)_expectedList[i], (MethodDesign)_actualList[i]);
// break;
// case "PropertyDesign":
// Compare((PropertyDesign)_expectedList[i], (PropertyDesign)_actualList[i]);
// break;
// case "VariableDesign":
// Compare((VariableDesign)_expectedList[i], (VariableDesign)_actualList[i]);
// break;
// case "ObjectDesign":
// Compare((ObjectDesign)_expectedList[i], (ObjectDesign)_actualList[i]);
// break;
// default:
// Assert.Fail("Wrong node type");
// break;
//}
}
}

private static void Compare(Reference[] expected, Reference[] actual)
{
if (expected == null && actual == null)
Expand All @@ -368,6 +373,7 @@ private static void Compare(Reference[] expected, Reference[] actual)
Assert.IsFalse(_actualDictionary[_rf.Key()].IsOneWay, _rf.Key());
}
}

private static void Compare(XmlQualifiedName expected, XmlQualifiedName actual, string parameter)
{
if ((expected == null || expected.IsEmpty) && (actual == null || actual.IsEmpty))
Expand All @@ -379,6 +385,7 @@ private static void Compare(XmlQualifiedName expected, XmlQualifiedName actual,
Assert.AreEqual<string>(expected.Name, actual.Name.Replace("_", ""), parameter);
Assert.AreEqual<string>(expected.Namespace, actual.Namespace, parameter);
}

private static void Compare(XmlElement expected, XmlElement actual)
{
if (expected == null && actual == null)
Expand All @@ -388,6 +395,7 @@ private static void Compare(XmlElement expected, XmlElement actual)
Assert.AreEqual<string>(expected.InnerText, actual.InnerText);
Compare(expected.Attributes, actual.Attributes);
}

private static void Compare(XmlAttributeCollection expected, XmlAttributeCollection actual)
{
if (expected == null && actual == null)
Expand All @@ -401,6 +409,7 @@ private static void Compare(XmlAttributeCollection expected, XmlAttributeCollect
Assert.AreEqual<string>(_ad[_atr.Name].InnerText, _atr.InnerText);
}
}

private void TraceDiagnostic(TraceMessage msg, List<TraceMessage> errors, ref int diagnosticCounter)
{
Console.WriteLine(msg.ToString());
Expand All @@ -411,8 +420,9 @@ private void TraceDiagnostic(TraceMessage msg, List<TraceMessage> errors, ref in
else
errors.Add(msg);
}
#endregion
#endregion

#endregion private helper

#endregion Test instrumentation
}
}
}
Loading

0 comments on commit 98d7e2b

Please sign in to comment.