Microsoft.Protocols.TestSuites.MS_OXCMAPIHTTP.S01_RequestTypesForMailboxServerEndpoint.MSOXCMAPIHTTP_S01_TC09_NotificationWaitWithPendingEvent C# (CSharp) Method

MSOXCMAPIHTTP_S01_TC09_NotificationWaitWithPendingEvent() private method

        public void MSOXCMAPIHTTP_S01_TC09_NotificationWaitWithPendingEvent()
        {
            this.CheckMapiHttpIsSupported();
            WebHeaderCollection headers = new WebHeaderCollection();

            #region Send a valid Connect request type to establish a Session Context with the server.
            ConnectSuccessResponseBody connectResponse = this.ConnectToServer(out headers);
            Site.Assert.AreEqual<uint>(0, connectResponse.StatusCode, "The server should return a Status 0 in X-ResponseCode header if client connect to server succeeded.");
            #endregion

            #region Send an Execute request that includes Logon ROP to server.
            WebHeaderCollection executeHeaders = AdapterHelper.InitializeHTTPHeader(RequestType.Execute, AdapterHelper.ClientInstance, AdapterHelper.Counter);

            ExecuteRequestBody requestBody = this.InitializeExecuteRequestBody(this.GetRopLogonRequest());
            List<string> metaTags = new List<string>();

            ExecuteSuccessResponseBody executeSuccessResponse = this.SendExecuteRequest(requestBody, ref executeHeaders, out metaTags) as ExecuteSuccessResponseBody;

            ulong folderId;
            RopLogonResponse logonResponse = new RopLogonResponse();
            uint logonHandle = this.ParseLogonResponse(executeSuccessResponse.RopBuffer, out folderId, out logonResponse);
            Site.Assert.AreEqual<uint>(0, logonResponse.ReturnValue, "Client logon to the server should be succeed and 0 is expected to be returned for the RopLogon. The returned value is {0}.", logonResponse.ReturnValue);

            #endregion

            #region Call RopRegisterNotification to register an event on server.
            executeHeaders = AdapterHelper.InitializeHTTPHeader(RequestType.Execute, AdapterHelper.ClientInstance, AdapterHelper.Counter);
            requestBody = this.InitializeExecuteRequestBody(this.RegisterNotificationRequest(folderId));
            metaTags = new List<string>();

            executeSuccessResponse = this.SendExecuteRequest(requestBody, ref executeHeaders, out metaTags) as ExecuteSuccessResponseBody;
            Site.Assert.AreEqual<uint>((uint)0, executeSuccessResponse.StatusCode, "Execute method should succeed.");
            #endregion

            #region Send a new mail to trigger the event.
            bool isSendSuccess = this.SUTControlAdapter.SendMailItem();
            this.Site.Assert.IsTrue(isSendSuccess, "Send a mail should successfully.");
            this.isReceiveNewMail = isSendSuccess;
            #endregion

            #region Call NotificationWait Request Type to get the pending event.
            NotificationWaitRequestBody notificationWaitRequestBody = this.NotificationWaitRequest();
            WebHeaderCollection notificationWaitWebHeaderCollection = AdapterHelper.InitializeHTTPHeader(RequestType.NotificationWait, AdapterHelper.ClientInstance, AdapterHelper.Counter);
            MailboxResponseBodyBase responseBody;
            Dictionary<string, string> addtionalHeaders = new Dictionary<string, string>();

            uint result = this.Adapter.NotificationWait(notificationWaitRequestBody, ref notificationWaitWebHeaderCollection, out responseBody, out metaTags, out addtionalHeaders);

            NotificationWaitSuccessResponseBody notificationWaitResponseBody = new NotificationWaitSuccessResponseBody();
            notificationWaitResponseBody = (NotificationWaitSuccessResponseBody)responseBody;
            Site.Assert.AreEqual<uint>((uint)0, notificationWaitResponseBody.StatusCode, "NotificationWait method should succeed and 0 is expected to be returned. The returned value is {0}.", notificationWaitResponseBody.StatusCode);

            #region Capture code
            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R1371");

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1371
            // A pending event is registered in step 3 and triggered in step 4, so MS-OXCMAPIHTTP_R1371 can be verified if the value of EventPending flag is 0x00000001.
            this.Site.CaptureRequirementIfAreEqual<uint>(
                0x00000001,
                notificationWaitResponseBody.EventPending,
                1371,
                @"[In NotificationWait Request Type Success Response Body] [EventPending] The value 0x00000001 indicates that an event is pending.");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R1375");

            // The pending event is registered and triggered in the above steps, so MS-OXCMAPIHTTP_R1258 can be verified if code can reach here.
            this.Site.CaptureRequirement(
                1258,
                @"[In Responding to a NotificationWait Request Type Request] This response [NotificationWait request type response] is not sent until the current server event completes.");

            #endregion
            #endregion

            #region Call Execute Request Type with no ROP in rgbIn to get the notify information.
            executeHeaders = AdapterHelper.InitializeHTTPHeader(RequestType.Execute, AdapterHelper.ClientInstance, AdapterHelper.Counter);
            byte[] ropBuffer = this.RopBufferHelper.BuildRequestBufferWithoutRop();
            metaTags = new List<string>();

            requestBody = new ExecuteRequestBody();
            requestBody.Flags = 0x00000003;
            requestBody.RopBufferSize = (uint)ropBuffer.Length;
            requestBody.RopBuffer = ropBuffer;
            requestBody.MaxRopOut = 0x10008;
            requestBody.AuxiliaryBufferSize = 0;
            requestBody.AuxiliaryBuffer = new byte[] { };

            executeSuccessResponse = this.SendExecuteRequest(requestBody, ref executeHeaders, out metaTags) as ExecuteSuccessResponseBody;
            Site.Assert.AreEqual<uint>((uint)0, executeSuccessResponse.StatusCode, "Execute method should succeed.");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R318");
        
            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R318
            // No ROP is included in the request, so if the RopBuffer in the response is not null, it indicates that the event details are included in the Execute request type response buffer.
            this.Site.CaptureRequirementIfIsNotNull(
                executeSuccessResponse.RopBuffer,
                318,
                @"[In NotificationWait Request Type Success Response Body] [EventPending] The server will return the event details in the Execute request type response body.");
            #endregion

            #region Send a Disconnect request to destroy the Session Context.
            MailboxResponseBodyBase response;
            this.Adapter.Disconnect(out response);
            #endregion
        }