public void TransferSubscription(bool sendInitialData, bool useSecurity) { var serverTestServices = new ServerTestServices(m_server); // save old security context, test fixture can only work with one session var securityContext = SecureChannelContext.Current; try { var namespaceUris = m_server.CurrentInstance.NamespaceUris; NodeId[] testSet = CommonTestWorkers.NodeIdTestSetStatic.Select(n => ExpandedNodeId.ToNodeId(n, namespaceUris)).ToArray(); CommonTestWorkers.CreateSubscriptionForTransfer(serverTestServices, m_requestHeader, testSet, out var subscriptionIds); RequestHeader transferRequestHeader = m_server.CreateAndActivateSession("TransferSession", useSecurity); var transferSecurityContext = SecureChannelContext.Current; CommonTestWorkers.TransferSubscriptionTest(serverTestServices, transferRequestHeader, subscriptionIds, sendInitialData, !useSecurity); if (useSecurity) { //restore security context SecureChannelContext.Current = securityContext; CommonTestWorkers.VerifySubscriptionTransferred(serverTestServices, m_requestHeader, subscriptionIds, true); } transferRequestHeader.Timestamp = DateTime.UtcNow; SecureChannelContext.Current = transferSecurityContext; m_server.CloseSession(transferRequestHeader); } finally { //restore security context, that close connection can work SecureChannelContext.Current = securityContext; } }
public void TransferSubscriptionSessionClosed(bool sendInitialData, bool useSecurity) { var serverTestServices = new ServerTestServices(m_server); // save old security context, test fixture can only work with one session var securityContext = SecureChannelContext.Current; try { RequestHeader transferRequestHeader = m_server.CreateAndActivateSession("ClosedSession", useSecurity); var transferSecurityContext = SecureChannelContext.Current; var namespaceUris = m_server.CurrentInstance.NamespaceUris; NodeId[] testSet = CommonTestWorkers.NodeIdTestSetStatic.Select(n => ExpandedNodeId.ToNodeId(n, namespaceUris)).ToArray(); transferRequestHeader.Timestamp = DateTime.UtcNow; CommonTestWorkers.CreateSubscriptionForTransfer(serverTestServices, transferRequestHeader, testSet, out var subscriptionIds); transferRequestHeader.Timestamp = DateTime.UtcNow; m_server.CloseSession(transferRequestHeader, false); //restore security context, transfer abandoned subscription SecureChannelContext.Current = securityContext; CommonTestWorkers.TransferSubscriptionTest(serverTestServices, m_requestHeader, subscriptionIds, sendInitialData, !useSecurity); if (useSecurity) { // subscription was deleted, expect 'BadNoSubscription' var sre = Assert.Throws <ServiceResultException>(() => { m_requestHeader.Timestamp = DateTime.UtcNow; CommonTestWorkers.VerifySubscriptionTransferred(serverTestServices, m_requestHeader, subscriptionIds, true); }); Assert.AreEqual(StatusCodes.BadNoSubscription, sre.StatusCode); } } finally { //restore security context, that close connection can work SecureChannelContext.Current = securityContext; } }