diff --git a/SemanticData/Tests/USNodeSetValidationUnitTestProject/AddressSpaceContextUnitTest.cs b/SemanticData/Tests/USNodeSetValidationUnitTestProject/AddressSpaceContextUnitTest.cs index edcb39b2..ba0b58ed 100644 --- a/SemanticData/Tests/USNodeSetValidationUnitTestProject/AddressSpaceContextUnitTest.cs +++ b/SemanticData/Tests/USNodeSetValidationUnitTestProject/AddressSpaceContextUnitTest.cs @@ -97,12 +97,6 @@ public void ImportUANodeSetTest() UANodeSet newNodeSet = TestData.CreateNodeSetModel(); newNodeSet.Items = new UANode[] { - // - // VehicleType - // - // i=58 - // - // new UAObjectType() { NodeId = "ns=1;i=12", @@ -112,14 +106,6 @@ public void ImportUANodeSetTest() new Reference() { ReferenceType = ReferenceTypeIds.HasSubtype.ToString(), IsForward = false, Value = "i=58" } }, }, - // - // buildDate - // - // ns=1; i = 12 - // i = 63 - // i = 78 - // - // new UAVariable() { NodeId = "ns=1;i=13", @@ -209,12 +195,6 @@ public void GetMyReferencesTest() UANodeSet newNodeSet = TestData.CreateNodeSetModel(); newNodeSet.Items = new UANode[] { - // - // VehicleType - // - // i=58 - // - // new UAObjectType() { NodeId = "ns=1;i=12", @@ -224,14 +204,6 @@ public void GetMyReferencesTest() new Reference() { ReferenceType = ReferenceTypeIds.HasSubtype.ToString(), IsForward = false, Value = "i=58" } }, }, - // - // buildDate - // - // ns=1; i = 12 - // i = 63 - // i = 78 - // - // new UAVariable() { NodeId = "ns=1;i=13", diff --git a/SemanticData/Tests/USNodeSetValidationUnitTestProject/ModelFactoryTestingFixture/InformationModelFactoryBase.cs b/SemanticData/Tests/USNodeSetValidationUnitTestProject/ModelFactoryTestingFixture/InformationModelFactoryBase.cs index 01d2f92e..be53aa27 100644 --- a/SemanticData/Tests/USNodeSetValidationUnitTestProject/ModelFactoryTestingFixture/InformationModelFactoryBase.cs +++ b/SemanticData/Tests/USNodeSetValidationUnitTestProject/ModelFactoryTestingFixture/InformationModelFactoryBase.cs @@ -31,14 +31,10 @@ public void CreateNamespace(string uri, string publicationDate, string version) internal IEnumerable Export() { List nodes = new List(); - Export(x => nodes.Add(x)); + base.Export(x => nodes.Add(x)); return nodes; } - //public int NumberOfSelectedNodes() - // where type : NodeFactoryBase - //{ - // return m_Nodes.Where(x => x.GetType() == typeof(type)).Count(); - //} + } } \ No newline at end of file diff --git a/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsProblemsToReportUnitTest.cs b/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsProblemsToReportUnitTest.cs index b349abd2..3bfc8eb7 100644 --- a/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsProblemsToReportUnitTest.cs +++ b/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsProblemsToReportUnitTest.cs @@ -71,6 +71,7 @@ public void eoursel510Test() Assert.AreEqual(21, nodes.Count< NodeFactoryBase>()); Dictionary nodesDictionary = nodes.ToDictionary(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 allNodes = null; asContext.UTValidateAndExportModel(1, x => allNodes = x); Assert.IsNotNull(allNodes); @@ -83,9 +84,6 @@ public void eoursel510Test() Debug.WriteLine($"{item.ToString()}"); } } - //Assert.AreEqual(4, testingModelFixture.NumberOfSelectedNodes()); - //Assert.AreEqual(3, testingModelFixture.NumberOfSelectedNodes()); - //Assert.AreEqual(1, testingModelFixture.NumberOfSelectedNodes()); Debug.WriteLine($"After removing inherited and instance declaration nodes the recovered information model contains {nodes.Count()}"); } } diff --git a/SemanticData/UAModelDesignExport.UnitTest/NodeSetUnitTest.cs b/SemanticData/UAModelDesignExport.UnitTest/NodeSetUnitTest.cs index d3ac7386..f092cac9 100644 --- a/SemanticData/UAModelDesignExport.UnitTest/NodeSetUnitTest.cs +++ b/SemanticData/UAModelDesignExport.UnitTest/NodeSetUnitTest.cs @@ -17,14 +17,14 @@ namespace UAOOI.SemanticData.UAModelDesignExport { - [TestClass] [DeploymentItem(@"Models\", @"Models\")] public class NodeSetUnitTest { - #region TestContext + private TestContext testContextInstance; + /// ///Gets or sets the test context which provides ///information about and functionality for the current test run. @@ -34,9 +34,11 @@ public TestContext TestContext get => testContextInstance; set => testContextInstance = value; } - #endregion + + #endregion TestContext #region TestMethod + [TestMethod] [ExpectedExceptionAttribute(typeof(FileNotFoundException))] public void FileNotFoundTestMethod() @@ -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() @@ -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() { @@ -72,6 +76,7 @@ public void UAReferenceTestMethod() Assert.AreEqual(1, _expected.Items.Length); CompareModelDesign(_expected, _actual); } + [TestMethod] public void UAObjectTypeTestMethod() { @@ -86,6 +91,7 @@ public void UAObjectTypeTestMethod() Assert.AreEqual(3, _expected.Items.Length); CompareModelDesign(_expected, _actual); } + [TestMethod] public void UAVariableTypeTestMethod() { @@ -100,6 +106,7 @@ public void UAVariableTypeTestMethod() Assert.AreEqual(3, _expected.Items.Length); CompareModelDesign(_expected, _actual); } + [TestMethod] public void UADataTypeTestMethod() { @@ -114,10 +121,13 @@ public void UADataTypeTestMethod() Assert.AreEqual(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(expected.Items.Length, actual.Items.Length); @@ -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)) @@ -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); @@ -164,6 +176,7 @@ private static void CompareReferenceTypeDesign(ReferenceTypeDesign expected, Ref Assert.AreEqual(expected.SymmetricSpecified, actual.SymmetricSpecified); Assert.AreEqual(expected.Symmetric, actual.Symmetric); } + private static void CompareObjectTypeDesign(ObjectTypeDesign expected, ObjectTypeDesign actual) { CompareTypeDesign(expected, actual); @@ -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); @@ -183,7 +197,7 @@ private static void CompareVariableTypeDesign(VariableTypeDesign expected, Varia if (expected.ValueRankSpecified) Assert.AreEqual(expected.ValueRank, actual.ValueRank); Assert.AreEqual(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); @@ -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) { @@ -201,6 +216,7 @@ private static void CompareObjectDesign(ObjectDesign expected, ObjectDesign actu Assert.AreEqual(expected.SupportsEvents, actual.SupportsEvents); CompareInstanceDesign(expected, actual); } + private static void CompareVariableDesign(VariableDesign expected, VariableDesign actual) { Compare(expected.DefaultValue, actual.DefaultValue); @@ -222,12 +238,14 @@ private static void CompareVariableDesign(VariableDesign expected, VariableDesig Assert.AreEqual(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); @@ -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) { @@ -246,6 +265,7 @@ private static void CompareTypeDesign(TypeDesign expected, TypeDesign actual) Assert.IsNotNull(actual.BaseType); Assert.AreEqual(expected.BaseType.ToString(), actual.BaseType.ToString()); } + private static void CompareInstanceDesign(InstanceDesign expected, InstanceDesign actual) { Assert.IsTrue(expected.GetType() == actual.GetType()); @@ -262,6 +282,7 @@ private static void CompareInstanceDesign(InstanceDesign expected, InstanceDesig Assert.AreEqual(0, actual.MaxCardinality); Assert.IsFalse(actual.PreserveDefaultAttributes); } + private static void CompareNodeDesign(NodeDesign expected, NodeDesign actual) { Assert.IsTrue(expected.BrowseName.AreEqual(actual.BrowseName)); @@ -279,16 +300,18 @@ private static void CompareNodeDesign(NodeDesign expected, NodeDesign actual) Assert.AreEqual(expected.StringId, actual.StringId); Assert.AreEqual(expected.PartNo, actual.PartNo); } - #endregion + + #endregion ModelDesign #region private helper + /// /// Compares the parameters of a method. /// /// /// 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. /// /// The expected. /// The actual. @@ -309,6 +332,7 @@ private static void Compare(Parameter[] expected, Parameter[] actual) Assert.AreEqual(expected[i].ValueRank, actual[i].ValueRank); } } + private static void CompareListOfChildren(ListOfChildren expected, ListOfChildren actual) { if (expected == null && actual == null) @@ -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) @@ -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)) @@ -379,6 +385,7 @@ private static void Compare(XmlQualifiedName expected, XmlQualifiedName actual, Assert.AreEqual(expected.Name, actual.Name.Replace("_", ""), parameter); Assert.AreEqual(expected.Namespace, actual.Namespace, parameter); } + private static void Compare(XmlElement expected, XmlElement actual) { if (expected == null && actual == null) @@ -388,6 +395,7 @@ private static void Compare(XmlElement expected, XmlElement actual) Assert.AreEqual(expected.InnerText, actual.InnerText); Compare(expected.Attributes, actual.Attributes); } + private static void Compare(XmlAttributeCollection expected, XmlAttributeCollection actual) { if (expected == null && actual == null) @@ -401,6 +409,7 @@ private static void Compare(XmlAttributeCollection expected, XmlAttributeCollect Assert.AreEqual(_ad[_atr.Name].InnerText, _atr.InnerText); } } + private void TraceDiagnostic(TraceMessage msg, List errors, ref int diagnosticCounter) { Console.WriteLine(msg.ToString()); @@ -411,8 +420,9 @@ private void TraceDiagnostic(TraceMessage msg, List errors, ref in else errors.Add(msg); } - #endregion - #endregion + #endregion private helper + + #endregion Test instrumentation } -} +} \ No newline at end of file diff --git a/SemanticData/UAModelDesignExport/ModelFactory.cs b/SemanticData/UAModelDesignExport/ModelFactory.cs index b7815807..d9124672 100644 --- a/SemanticData/UAModelDesignExport/ModelFactory.cs +++ b/SemanticData/UAModelDesignExport/ModelFactory.cs @@ -1,15 +1,13 @@ //___________________________________________________________________________________ // -// Copyright (C) 2019, Mariusz Postol LODZ POLAND. +// Copyright (C) 2021, Mariusz Postol LODZ POLAND. // // To be in touch join the community at GITTER: https://gitter.im/mpostol/OPC-UA-OOI //___________________________________________________________________________________ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; -using System.Xml; using UAOOI.SemanticData.InformationModelFactory; using UAOOI.SemanticData.UAModelDesignExport.XML; using TraceMessage = UAOOI.SemanticData.BuildingErrorsHandling.TraceMessage; @@ -25,7 +23,6 @@ namespace UAOOI.SemanticData.UAModelDesignExport /// internal class ModelFactory : NodesContainer, IModelFactory { - /// /// Initializes a new instance of the class. /// @@ -69,13 +66,6 @@ internal ModelDesign Export() List _mdNodes = new List(); List path = new List(); base.ExportNodes(_mdNodes, path, (x, y) => CreateInstanceType(x, y, _mdNodes)); - //TODO add warnings to the model as the Property Nodes. - //ModelDesign.NodeDesign _newNode = CreateNodeDesign((x, y) => { return CreateInstanceType(x, y, _mdNodes, _item.UAModelContext, traceEvent); }, null, _item, y => - // { - // if (y.TraceLevel != TraceEventType.Verbose) - // _errors.Add(y.BuildError); - // traceEvent(y); - // }); return new ModelDesign() { Items = _mdNodes.ToArray(), @@ -90,58 +80,14 @@ internal ModelDesign Export() }; } - //private + //private private List m_Namespaces = new List(); + private static int m_Count = 0; + private void CreateInstanceType(InstanceDesign instance, List browsePath, List mdNodes) { return; - //TODO #40: ValidateAndExportModel shall export also instances #40 - //Debug.Assert(instance != null, "CreateInstanceType.instance cannot be null"); - //InstanceDesign _ret = null; - //if (instance is MethodDesign _src) - //{ - // XmlQualifiedName _newSymbolicName = new XmlQualifiedName(browsePath.SymbolicName(), instance.SymbolicName.Namespace); - // MethodDesign _method = new MethodDesign - // { - // BrowseName = _src.BrowseName, - // Children = null, - // Declaration = _src.Declaration, - // Description = _src.Description, - // DisplayName = _src.DisplayName, - // InputArguments = _src.InputArguments, - // IsDeclaration = _src.IsDeclaration, - // MaxCardinality = _src.MaxCardinality, - // MinCardinality = _src.MinCardinality, - // ModellingRule = ModellingRule.None, - // ModellingRuleSpecified = false, - // NonExecutable = _src.NonExecutable, - // NonExecutableSpecified = _src.NonExecutableSpecified, - // NumericId = _src.NumericId, - // NumericIdSpecified = _src.NumericIdSpecified, - // OutputArguments = _src.OutputArguments, - // PartNo = _src.PartNo, - // PreserveDefaultAttributes = _src.PreserveDefaultAttributes, - // References = _src.References, - // ReferenceType = _src.ReferenceType, - // StringId = _src.StringId, - // SymbolicId = _src.SymbolicId, - // SymbolicName = _newSymbolicName, - // TypeDefinition = null, - // WriteAccess = _src.WriteAccess, - // }; - // _src.InputArguments = null; - // _src.OutputArguments = null; - // if (instance.Children == null || instance.Children.Items == null || instance.Children.Items.Length == 0) - // instance.Children = null; - // _src.TypeDefinition = _newSymbolicName; - // _ret = _method; - //} - //else - // Debug.Fail("In this release expected Method"); - //if (_ret != null) - // mdNodes.Add(_ret); } - } -} +} \ No newline at end of file diff --git a/SemanticData/UANodeSetValidation/AddressSpaceContext.cs b/SemanticData/UANodeSetValidation/AddressSpaceContext.cs index c44767ab..44bb9bb6 100644 --- a/SemanticData/UANodeSetValidation/AddressSpaceContext.cs +++ b/SemanticData/UANodeSetValidation/AddressSpaceContext.cs @@ -226,42 +226,6 @@ public Parameter ExportArgument(DataSerialization.Argument argument) return ExportArgument(argument, _dataType); } - //TODO #40 remove commented functionality - ///// - ///// Gets an instance of the representing selected by base type node if applicable, null otherwise. - ///// - ///// The node class selector. - ///// An instance of representing base type for selected node class. - ///// If is equal - //IUANodeBase IAddressSpaceBuildContext.GetBaseTypeNode(NodeClassEnum nodeClass) - //{ - // IUANodeContext _ret = null; - // switch (nodeClass) - // { - // case NodeClassEnum.UADataType: - // m_NodesDictionary.TryGetValue(DataTypeIds.BaseDataType.ToString(), out _ret); - // break; - // case NodeClassEnum.UAMethod: - // break; - // case NodeClassEnum.UAObjectType: - // case NodeClassEnum.UAObject: - // m_NodesDictionary.TryGetValue(ObjectTypeIds.BaseObjectType.ToString(), out _ret); - // break; - // case NodeClassEnum.UAReferenceType: - // m_NodesDictionary.TryGetValue(ReferenceTypeIds.References.ToString(), out _ret); - // break; - // case NodeClassEnum.UAVariable: - // case NodeClassEnum.UAVariableType: - // m_NodesDictionary.TryGetValue(VariableTypeIds.BaseVariableType.ToString(), out _ret); - // break; - // case NodeClassEnum.UAView: - // break; - // case NodeClassEnum.Unknown: - // throw new ApplicationException($"In {nameof(IAddressSpaceBuildContext.GetBaseTypeNode)} the {nameof(NodeClass)} must not be {nameof(NodeClassEnum.Unknown)}"); - // } - // return _ret; - //} - #endregion IAddressSpaceBuildContext #region IAddressSpaceValidationContext diff --git a/SemanticData/UANodeSetValidation/UANodeContext.cs b/SemanticData/UANodeSetValidation/UANodeContext.cs index 788b6bd1..775e32e8 100644 --- a/SemanticData/UANodeSetValidation/UANodeContext.cs +++ b/SemanticData/UANodeSetValidation/UANodeContext.cs @@ -53,7 +53,7 @@ public void BuildSymbolicId(List path) return; } IEnumerable _parentConnector = m_AddressSpaceContext.GetReferences2Me(this).Where(x => x.ChildConnector); - Debug.Assert(_parentConnector.Count() <= 1); //TODO #40; ValidateAndExportModel shall export also instances #40 + Debug.Assert(_parentConnector.Count() <= 1); UAReferenceContext _connector = _parentConnector.FirstOrDefault(); if (_connector != null) _connector.BuildSymbolicId(path); @@ -169,12 +169,10 @@ void IUANodeBase.CalculateNodeReferences(INodeFactory nodeFactory, IValidator va break; case ReferenceKindEnum.HasComponent: - //if (_rfx.SourceNode == this) _children.Add(_rfx); break; case ReferenceKindEnum.HasProperty: - //if ((_rfx.SourceNode == this) && (_rfx.SourceNode.UANode.NodeClassEnum != NodeClassEnum.UADataType)) _children.Add(_rfx); break; @@ -334,10 +332,15 @@ public bool Equals(IUANodeBase other) #endregion IEquatable + #region object + public override string ToString() { return $"Node: {this.GetType().Name}, {nameof(UANodeContext.BrowseName)}={ExportNodeBrowseName()}, NodeId={this.NodeIdContext}"; } + + #endregion object + #region private private IUANodeBase m_BaseTypeNode; @@ -362,6 +365,7 @@ private void TraceErrorUndefinedBaseType(NodeId target, bool type, Action _TraceEvent = null; #endregion private