Microsoft.Protocols.TestSuites.MS_OXCNOTIF.S01_ReceivePendingNotifications.MSOXCNOTIF_S01_TC02_VerifyRopPendingForLinkedSession C# (CSharp) Method

MSOXCNOTIF_S01_TC02_VerifyRopPendingForLinkedSession() private method

        public void MSOXCNOTIF_S01_TC02_VerifyRopPendingForLinkedSession()
        {
            this.CheckWhetherSupportMAPIHTTP();
            this.NotificationInitialize();
            Site.Assume.IsTrue(Common.IsRequirementEnabled(342, this.Site), "This case runs only under Exchange 2007, since Exchange 2010,Exchange 2013 and Exchange 2016 do not support Session Context linking.");
       
            #region Subscribe ObjectCreated event on server using receiver context handle.
            this.CNOTIFAdapter.RegisterNotification(NotificationType.ObjectCreated);
            #endregion

            #region Client connects to server and logs on the linked session.
            bool isLinkedSessionConnected = this.CNOTIFAdapter.DoConnect(ConnectionType.PrivateMailboxServer);
            this.Site.Assert.IsTrue(isLinkedSessionConnected, "If is connected, the ReturnValue of its response is true(success)");
            IntPtr rpcContextForLinkedSession = this.CNOTIFAdapter.RPCContext;

            this.CNOTIFAdapter.Logon();
            uint logonHandleForLinkedSession = this.CNOTIFAdapter.LogonHandle;
            #endregion

            #region Subscribe ObjectCreated event on server using the linked session context handle.
            this.CNOTIFAdapter.RegisterNotification(NotificationType.ObjectCreated);
            #endregion

            #region Trigger many server event using sender context handle to fill the response buffer fully.

            this.CNOTIFAdapter.RPCContext = this.RpcContextForReceive;
            this.CNOTIFAdapter.LogonHandle = this.ReceiverContextLogonHandle;

            // Trigger 200 ObjectCreated events to fill the response buffer fully.
            for (int i = 0; i < 200; ++i)
            {
                this.TriggerObjectCreatedEvent();
            }

            #endregion

            #region Get notification details and a pending notification using receiver context handle.
            IList<IDeserializable> response = this.CNOTIFAdapter.GetNotification(true);
            RopNotifyResponse notifyResponse = (RopNotifyResponse)response.First(x => x is RopNotifyResponse);
            Site.Assert.AreEqual<NotificationType>(NotificationType.ObjectCreated, notifyResponse.NotificationData.NotificationType, "ObjectCreated event should be returned successfully.");
            Site.Assert.AreEqual<string>("RopPendingResponse", response.Last().GetType().Name, "There should be a RopPending response.");

            #endregion

            #region Get all the left notification details on the receiver context handle.
            // The retry times to try getting all left notifications.
            int retryCount = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site));

            List<List<uint>> responseSOHs;
            do
            {
                response = this.CNOTIFAdapter.Process(
                        null,
                        this.CNOTIFAdapter.LogonHandle,
                        out responseSOHs);
                retryCount--;
            }
            while (response.Count != 0 && retryCount > 0);
            Site.Assert.IsTrue(
                response.Count == 0,
                "The left notifications aren't all received in {0} retry times. Try to configure RetryCount property in configure file.",
                Common.GetConfigurationPropertyValue("RetryCount", this.Site));
            #endregion

            #region Get pending notification and notification details using the linked session context handle.
            this.CNOTIFAdapter.RPCContext = rpcContextForLinkedSession;
            this.CNOTIFAdapter.LogonHandle = logonHandleForLinkedSession;
            IList<IDeserializable> response2 = this.CNOTIFAdapter.GetNotification(true);
            RopNotifyResponse notifyResponse2 = (RopNotifyResponse)response2.First(x => x is RopNotifyResponse);
            Site.Assert.AreEqual<NotificationType>(NotificationType.ObjectCreated, notifyResponse2.NotificationData.NotificationType, "ObjectCreated event should be returned successfully.");

            #endregion

            #region Verify that the pending notification is returned on the linked session context handle.
            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCNOTIF_R342: the last response buffer for notification is {0}", response2.Last().GetType().Name);

            // Verify MS-OXCNOTIF requirement: MS-OXCNOTIF_R342 
            this.Site.CaptureRequirementIfAreEqual<string>(
                "RopPendingResponse",
                response2.Last().GetType().Name,
                342,
                @"[In Sending a RopPending ROP Response] The server sends a RopPending ROP response to the client whenever there are pending notifications on any linked session contexts.");
            #endregion

            #region Get all the left notification details on the linked session context handle.
            // The retry times to try getting all left notifications.
            retryCount = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site));

            do
            {
                response = this.CNOTIFAdapter.Process(
                        null,
                        this.CNOTIFAdapter.LogonHandle,
                        out responseSOHs);
                retryCount--;
            }
            while (response.Count != 0 && retryCount > 0);
            Site.Assert.IsTrue(
                response.Count == 0,
                "The left notifications aren't all received in {0} retry times. Try to configure RetryCount property in configure file.",
                Common.GetConfigurationPropertyValue("RetryCount", this.Site));
            #endregion

            #region Disconnect the linked session connection.

            bool isDisconnected = this.CNOTIFAdapter.DoDisconnect();
            this.Site.Assert.IsTrue(isDisconnected, "If is disconnected, the ReturnValue of its response is true(success)");

            // Switch to the receiver connection.
            this.CNOTIFAdapter.RPCContext = this.RpcContextForReceive;
            this.CNOTIFAdapter.LogonHandle = this.ReceiverContextLogonHandle;
            this.CNOTIFAdapter.IsConnected = this.IsReceiverContextConnected;

            #endregion
        }