public void NodeCache_LoadUaDefinedTypes() { INodeCache nodeCache = Session.NodeCache; Assert.IsNotNull(nodeCache); // load the predefined types nodeCache.LoadUaDefinedTypes(Session.SystemContext); // reload the predefined types nodeCache.LoadUaDefinedTypes(Session.SystemContext); }
public void NodeCache_References() { INodeCache nodeCache = Session.NodeCache; Assert.IsNotNull(nodeCache); // ensure the predefined types are loaded nodeCache.LoadUaDefinedTypes(Session.SystemContext); // check on all reference type ids var refTypeDictionary = typeof(ReferenceTypeIds).GetFields(BindingFlags.Public | BindingFlags.Static) .Where(f => f.FieldType == typeof(NodeId)) .ToDictionary(f => f.Name, f => (NodeId)f.GetValue(null)); TestContext.Out.WriteLine("Testing {0} references", refTypeDictionary.Count); foreach (var property in refTypeDictionary) { TestContext.Out.WriteLine("FindReferenceTypeName({0})={1}", property.Value, property.Key); // find the Qualified Name var qn = nodeCache.FindReferenceTypeName(property.Value); Assert.NotNull(qn); Assert.AreEqual(property.Key, qn.Name); // find the node by name var refId = nodeCache.FindReferenceType(new QualifiedName(property.Key)); Assert.NotNull(refId); Assert.AreEqual(property.Value, refId); // is the node id known? var isKnown = nodeCache.IsKnown(property.Value); Assert.IsTrue(isKnown); // is it a reference? var isTypeOf = nodeCache.IsTypeOf( NodeId.ToExpandedNodeId(refId, Session.NamespaceUris), NodeId.ToExpandedNodeId(ReferenceTypeIds.References, Session.NamespaceUris)); Assert.IsTrue(isTypeOf); // negative test isTypeOf = nodeCache.IsTypeOf( NodeId.ToExpandedNodeId(refId, Session.NamespaceUris), NodeId.ToExpandedNodeId(DataTypeIds.Byte, Session.NamespaceUris)); Assert.IsFalse(isTypeOf); var subTypes = nodeCache.FindSubTypes(NodeId.ToExpandedNodeId(refId, Session.NamespaceUris)); Assert.NotNull(subTypes); } }