From fcff3141e703860a921bef5089aafbb0d887208b Mon Sep 17 00:00:00 2001 From: mpostol Date: Sun, 4 Apr 2021 22:02:52 +0200 Subject: [PATCH] UAReferenceContext - causes circular references #558 - removed IsSubtypeOf - it is not longer used. - UT :+1: - fixes #558 --- .../UAReferenceContextTestClass.cs | 40 ------------------- .../UANodeSetValidation/UANodeContext.cs | 1 - .../UANodeSetValidation/UAReferenceContext.cs | 26 ++++++------ 3 files changed, 12 insertions(+), 55 deletions(-) diff --git a/SemanticData/Tests/USNodeSetValidationUnitTestProject/UAReferenceContextTestClass.cs b/SemanticData/Tests/USNodeSetValidationUnitTestProject/UAReferenceContextTestClass.cs index 7f6694ac..594e35f1 100644 --- a/SemanticData/Tests/USNodeSetValidationUnitTestProject/UAReferenceContextTestClass.cs +++ b/SemanticData/Tests/USNodeSetValidationUnitTestProject/UAReferenceContextTestClass.cs @@ -226,46 +226,6 @@ private bool ListContainingAggregatesTypesFixture(List reference return true; } - [TestMethod] - public void IsSubtypeOfReferenceTypeTest() - { - XML.Reference reference = new XML.Reference() { IsForward = true, ReferenceType = ReferenceTypeIds.HasOrderedComponent.ToString(), Value = "ns=1;i=11" }; - reference.RecalculateNodeIds(x => NodeId.Parse(x)); - - Mock sourceMock = new Mock(); - Mock asMock = new Mock(); - asMock.Setup(x => x.GetOrCreateNodeContext(It.Is(z => z == ReferenceTypeIds.HasOrderedComponent), It.IsAny>())); - asMock.Setup(x => x.GetOrCreateNodeContext(It.Is(z => z == NodeId.Parse(reference.Value)), It.IsAny>())); - asMock.Setup(x => x.GetBaseTypes(It.IsAny(), It.Is>(z => ListOTypesFixture(z)))); - - UAReferenceContext instance2Test = new UAReferenceContext(reference, asMock.Object, sourceMock.Object); - - asMock.Verify(x => x.GetOrCreateNodeContext(It.Is(z => z == ReferenceTypeIds.HasOrderedComponent), It.IsAny>()), Times.Once); - asMock.Verify(x => x.GetOrCreateNodeContext(It.Is(z => z == NodeId.Parse(reference.Value)), It.IsAny>()), Times.Once); - - Assert.IsTrue(instance2Test.IsSubtypeOf(NodeId.Parse("i=123"))); - Assert.IsFalse(instance2Test.IsSubtypeOf(NodeId.Parse("i=124"))); - } - - private bool ListOTypesFixture(List references) - { - Assert.AreEqual(0, references.Count); - Mock node1 = new Mock(); - references.Add(node1.Object); - references.Add(node1.Object); - references.Add(node1.Object); - Mock node2 = new Mock(); - node2.Setup(x => x.NodeIdContext).Returns(NodeId.Parse("i=123")); - references.Add(node2.Object); - Mock node3 = new Mock(); - references.Add(node3.Object); - references.Add(node3.Object); - references.Add(node3.Object); - references.Add(node1.Object); - references.Add(node1.Object); - return true; - } - private bool CreatePathFixture(List z) { z.Add("2P8ZkTA2Ccahvs"); diff --git a/SemanticData/UANodeSetValidation/UANodeContext.cs b/SemanticData/UANodeSetValidation/UANodeContext.cs index 27fdb0a8..731ca320 100644 --- a/SemanticData/UANodeSetValidation/UANodeContext.cs +++ b/SemanticData/UANodeSetValidation/UANodeContext.cs @@ -167,7 +167,6 @@ void IUANodeBase.CalculateNodeReferences(INodeFactory nodeFactory, IValidator va _TraceEvent(TraceMessage.DiagnosticTraceMessage($"Removed the graph of nodes at {_ReferenceType.ToString()} from the model")); return; } - //TODO UAReferenceContext - causes circular references #558 IReferenceFactory _or = nodeFactory.NewReference(); _or.IsInverse = !_rfx.IsForward; _or.ReferenceType = _ReferenceType; diff --git a/SemanticData/UANodeSetValidation/UAReferenceContext.cs b/SemanticData/UANodeSetValidation/UAReferenceContext.cs index 012509a0..ac5e6bae 100644 --- a/SemanticData/UANodeSetValidation/UAReferenceContext.cs +++ b/SemanticData/UANodeSetValidation/UAReferenceContext.cs @@ -22,7 +22,6 @@ namespace UAOOI.SemanticData.UANodeSetValidation /// public class UAReferenceContext { - //TODO UAReferenceContext - causes circular references #558 #region constructor @@ -30,10 +29,10 @@ internal UAReferenceContext(Reference reference, IAddressSpaceBuildContext addre { if (reference == null) throw new ArgumentNullException(nameof(reference)); - this.m_AddressSpace = addressSpaceContext ?? throw new ArgumentNullException(nameof(addressSpaceContext)); + this._AddressSpace = addressSpaceContext ?? throw new ArgumentNullException(nameof(addressSpaceContext)); if (parentNode == null) throw new ArgumentNullException(nameof(parentNode)); - IUANodeContext targetNode = m_AddressSpace.GetOrCreateNodeContext(reference.ValueNodeId, parentNode.CreateUANodeContext); + IUANodeContext targetNode = _AddressSpace.GetOrCreateNodeContext(reference.ValueNodeId, parentNode.CreateUANodeContext); this.IsForward = reference.IsForward; this.SourceNode = reference.IsForward ? parentNode : targetNode; this.TargetNode = reference.IsForward ? targetNode : parentNode; @@ -55,7 +54,7 @@ internal ReferenceKindEnum ReferenceKind get { if (_ReferenceKindEnum == null) - _ReferenceKindEnum = CalculateReferenceKind(this.TypeNode); + _ReferenceKindEnum = CalculateReferenceKind(); return _ReferenceKindEnum.Value; } } @@ -63,7 +62,7 @@ internal ReferenceKindEnum ReferenceKind /// /// Gets the modeling rule. /// - /// System.Nullable<ModelingRules>. + /// System.Nullable{ModelingRules}. internal ModelingRules? GetModelingRule() { Debug.Assert(TargetNode.NodeIdContext.IdType == IdType.Numeric_0); @@ -86,7 +85,7 @@ internal ReferenceKindEnum ReferenceKind /// /// Gets a value indicating whether the reference has been derived form or . /// - /// true if is child reference; otherwise, false. + /// true if it is child reference; otherwise, false. internal bool ChildConnector => (ReferenceKind == ReferenceKindEnum.HasProperty) || (ReferenceKind == ReferenceKindEnum.HasComponent); #endregion semantics @@ -96,14 +95,14 @@ internal ReferenceKindEnum ReferenceKind /// /// Gets the name of the reference type. /// - /// XmlQualifiedName. + /// An instance of capturing name of the reference type. internal XmlQualifiedName GetReferenceTypeName() { - return m_AddressSpace.ExportBrowseName(this.TypeNode.NodeIdContext, GetDefault()); + return _AddressSpace.ExportBrowseName(this.TypeNode.NodeIdContext, GetDefault()); } /// - /// Calculates the browse path starting from the node pointed out by this reference. If is true is use, otherwise. + /// Calculates the browse path starting from the node pointed out by this reference. If the is use, otherwise. /// /// An instance of representing the browse path. internal XmlQualifiedName BrowsePath() @@ -112,7 +111,7 @@ internal XmlQualifiedName BrowsePath() IUANodeContext _startingNode = this.IsForward ? TargetNode : SourceNode; _startingNode.BuildSymbolicId(_path); string _symbolicId = _path.SymbolicName(); - return new XmlQualifiedName(_symbolicId, m_AddressSpace.GetNamespace(_startingNode.NodeIdContext.NamespaceIndex)); + return new XmlQualifiedName(_symbolicId, _AddressSpace.GetNamespace(_startingNode.NodeIdContext.NamespaceIndex)); } /// @@ -171,19 +170,18 @@ internal void BuildSymbolicId(List path) #region private //fields - private IAddressSpaceBuildContext m_AddressSpace; + private IAddressSpaceBuildContext _AddressSpace; private ReferenceKindEnum? _ReferenceKindEnum = new Nullable(); //methods - private ReferenceKindEnum CalculateReferenceKind(IUANodeContext typeNode) + private ReferenceKindEnum CalculateReferenceKind() { if ((TypeNode == null) || TypeNode.NodeIdContext.NamespaceIndex != 0) return ReferenceKindEnum.Custom; ReferenceKindEnum _ret = default(ReferenceKindEnum); List inheritanceChain = new List(); - m_AddressSpace.GetBaseTypes(TypeNode, inheritanceChain); - //HierarchicalReferences + _AddressSpace.GetBaseTypes(TypeNode, inheritanceChain); if (inheritanceChain.Where(x => x.NodeIdContext == ReferenceTypeIds.HasProperty).Any()) _ret = ReferenceKindEnum.HasProperty; else if (inheritanceChain.Where(x => x.NodeIdContext == ReferenceTypeIds.HasComponent).Any())