1+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
2+ using System ;
3+ using System . IO ;
4+ using Aml . Engine . AmlObjects ;
5+ using Aml . Engine . CAEX ;
6+ using Aml . Engine . CAEX . Extensions ;
7+ using Opc . Ua ;
8+ using Microsoft . VisualStudio . TestPlatform . ObjectModel ;
9+
10+
11+ namespace SystemTest
12+ {
13+ [ TestClass ]
14+ public class TestInverseNameNodeId
15+ {
16+ // Test is to address issue 94 -
17+ // The Namespaces of BrowseNames differ between the generated AML file and the original Nodeset file.
18+ // Test Both NodeId NamespaceUris and BrowseNameUris
19+
20+ private const string FxIdPrefix = "nsu%3Dhttp%3A%2F%2Fopcfoundation.org%2FUA%2FFX%2FAC%2F%3Bi%3D" ;
21+ private const string AmlFxTestPrefix = "nsu%3Dhttp%3A%2F%2Fopcfoundation.org%2FUA%2FFX%2FAML%2FTESTING%2FAmlFxTest%2F%3Bi%3D" ;
22+ public const string TestAmlUri = "http://opcfoundation.org/UA/FX/AML/TESTING/AmlFxTest/" ;
23+ private const string FxAcUri = "http://opcfoundation.org/UA/FX/AC/" ;
24+ private const string DiUri = "http://opcfoundation.org/UA/DI/" ;
25+
26+ CAEXDocument m_document = null ;
27+
28+ #region Tests
29+
30+ [ TestMethod ]
31+ public void TestAll ( )
32+ {
33+ CAEXDocument document = GetDocument ( ) ;
34+
35+ int counter = 0 ;
36+ foreach ( InterfaceClassLibType classLibType in document . InterfaceClassLib )
37+ {
38+ foreach ( InterfaceFamilyType interfaceType in classLibType )
39+ {
40+ AttributeType inverse = interfaceType . Attribute [ "InverseName" ] ;
41+ if ( inverse != null )
42+ {
43+ Assert . IsNull ( inverse . Attribute [ "NodeId" ] ) ;
44+ counter ++ ;
45+ }
46+ }
47+ }
48+ Console . WriteLine ( "Tested " + counter . ToString ( ) + " interface types" ) ;
49+ }
50+
51+ [ TestMethod , Timeout ( TestHelper . UnitTestTimeout ) ]
52+ [ DataRow ( "41" , TestHelper . Uris . Root , DisplayName = "GeneratesEvent" ) ]
53+ // [DataRow("6467", TestHelper.Uris.Di, DisplayName = "ConnectsToParent = Does not have inverse name!")]
54+ [ DataRow ( "6031" , TestHelper . Uris . Di , DisplayName = "IsOnline" ) ]
55+ [ DataRow ( "35" , TestHelper . Uris . Ac , DisplayName = "HasPart" ) ]
56+
57+ public void TestInterfaceEntity ( string nodeId , TestHelper . Uris uriEnum )
58+ {
59+ InterfaceFamilyType testObject = GetTestObject ( nodeId , uriEnum ) ;
60+
61+ // Node Id Attribute should be correct.
62+ AttributeType nodeIdAttribute = GetAttribute ( testObject . Attribute , "NodeId" ) ;
63+ AttributeType root = GetAttribute ( nodeIdAttribute . Attribute , "RootNodeId" ) ;
64+
65+ Assert . AreEqual (
66+ TestHelper . GetUri ( uriEnum ) ,
67+ GetAttributeValue ( root . Attribute , "NamespaceUri" ) ) ;
68+
69+ Assert . AreEqual ( nodeId , GetAttributeValue ( root . Attribute , "NumericId" ) ) ;
70+
71+ AttributeType inverse = GetAttribute ( testObject . Attribute , "InverseName" ) ;
72+
73+ // Inverse Name should not have nodeId
74+ Assert . IsNull ( inverse . Attribute [ "NodeId" ] , "Inverse Name should not have a nodeId" ) ;
75+ }
76+
77+ #endregion
78+
79+ #region Helpers
80+
81+ public string GetAttributeValue ( AttributeSequence sequence , string attributeName )
82+ {
83+ AttributeType attribute = GetAttribute ( sequence , attributeName ) ;
84+ Assert . IsNotNull ( attribute . Value ) ;
85+ return attribute . Value ;
86+ }
87+
88+ public AttributeType GetAttribute ( AttributeSequence sequence , string attributeName )
89+ {
90+ AttributeType attribute = sequence [ attributeName ] ;
91+ Assert . IsNotNull ( attribute ) ;
92+ return attribute ;
93+ }
94+
95+ private CAEXDocument GetDocument ( )
96+ {
97+ if ( m_document == null )
98+ {
99+ m_document = TestHelper . GetReadOnlyDocument ( "AmlFxTest.xml.amlx" ) ;
100+ }
101+ Assert . IsNotNull ( m_document , "Unable to retrieve Document" ) ;
102+ return m_document ;
103+ }
104+
105+ public InterfaceFamilyType GetTestObject ( string nodeId , TestHelper . Uris uriEnum )
106+ {
107+ CAEXDocument document = GetDocument ( ) ;
108+ string id = TestHelper . BuildAmlId ( "f" , uriEnum , nodeId ) ;
109+ CAEXObject initialObject = document . FindByID ( id ) ;
110+ Assert . IsNotNull ( initialObject , "Unable to find Initial Object" ) ;
111+ InterfaceFamilyType theObject = initialObject as InterfaceFamilyType ;
112+ Assert . IsNotNull ( theObject , "Unable to Cast Initial Object" ) ;
113+ return theObject ;
114+ }
115+
116+ #endregion
117+ }
118+ }
0 commit comments