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

MSOXCMAPIHTTP_S01_TC10_NotificationWaitWithoutPendingEvent() private method

        public void MSOXCMAPIHTTP_S01_TC10_NotificationWaitWithoutPendingEvent()
        {
            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;
            #region Capture code
            string pendingPeriodHeader = executeHeaders["X-PendingPeriod"];

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

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1182
            this.Site.CaptureRequirementIfIsFalse(
                string.IsNullOrEmpty(pendingPeriodHeader),
                1182,
                @"[In Handling a Chunked Response] The immediate response includes an X-PendingPeriod header, specified in section 2.2.3.3.5, to tell the client the number of milliseconds to be expected between keep-alive PENDING meta-tags in the response stream during the time a request is currently being processed on the server.");

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

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1183
            this.Site.CaptureRequirementIfAreEqual<string>(
                "15000",
                pendingPeriodHeader,
                1183,
                @"[In Handling a Chunked Response] The default value for the keep-alive interval is 15 seconds, until the request is done.");
            #endregion
            #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>();
            DateTime startTime = DateTime.Now;
            uint result = this.Adapter.NotificationWait(notificationWaitRequestBody, ref notificationWaitWebHeaderCollection, out responseBody, out metaTags, out addtionalHeaders);
            DateTime endTime = DateTime.Now;
            TimeSpan interval = endTime.Subtract(startTime);

            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
            bool isPendingMetaTag = false;
            for (int i = 1; i < metaTags.Count - 1; i++)
            {
                if (string.Compare(metaTags[i], "PENDING", true) == 0)
                {
                    isPendingMetaTag = true;
                }
                else
                {
                    this.Site.Log.Add(LogEntryKind.Debug, "Expect the Meta-Tag is PENDING, actually the Meta-Tag is {0}", metaTags[i]);
                    isPendingMetaTag = false;
                    break;
                }
            }

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

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1135
            // No pending event exists in this case, so NotificationWait needs to wait 5 minutes and the PENDING meta-tag will be returned before the DONE meta-tag is returned.
            this.Site.CaptureRequirementIfIsTrue(
                isPendingMetaTag,
                1135,
                @"[In Response Meta-Tags] PENDING: The server is processing the request.");

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

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1178
            // Server keeps the response alive by sending response to client including PENDING meta-tag. So if the PENDING meta-tag is included in the returned meta-tags, R1178 can be verified.
            this.Site.CaptureRequirementIfIsTrue(
                isPendingMetaTag,
                1178,
                @"[In Handling a Chunked Response] The keep-alive response contains the PENDING meta-tag.");

            // R1178 ensures that the keep-alive response includes the PENDING meta-tags, so R1241 can be verified directly.
            this.Site.CaptureRequirement(
                1241,
                @"[In Responding to All Request Type Requests] The keep-alive response includes the PENDING meta-tag, as specified in section 2.2.7.");

            // Add the debug information
            this.Site.Log.Add(
                LogEntryKind.Debug,
                "Verify MS-OXCMAPIHTTP_R1185. The first meta-tag is {0}, the meta-tag before the last one is {1}, the last one is {2}.",
                metaTags[0],
                metaTags[metaTags.Count - 2],
                metaTags[metaTags.Count - 1]);

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1185
            // Server uses the "PENDING" meta-tag to keep the transmission alive with client. So R1185 can be verified if all the three kinds of meta-tags exist.
            bool isVerifiedR1185 = metaTags[0] == "PROCESSING" && metaTags[metaTags.Count - 2] == "PENDING" && metaTags[metaTags.Count - 1] == "DONE";
            
            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR1185,
                1185,
                @"[In Handling a Chunked Response] The initial response, plus the intermediate keep-alive transmissions, and the final response body are all part of the inner response stream.");

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

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1372
            // No pending event is registered in this case. So MS-OXCMAPIHTTP_R1372 can be verified if the value of EventPending field is 0x00000000.
            this.Site.CaptureRequirementIfAreEqual<uint>(
                0x00000000,
                notificationWaitResponseBody.EventPending,
                1372,
                @"[In NotificationWait Request Type Success Response Body] [EventPending] The value 0x00000000 indicates that no event is pending.");

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

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1256
            this.Site.CaptureRequirementIfIsNotNull(
                notificationWaitResponseBody,
                1256,
                @"[In Responding to a NotificationWait Request Type Request] The server creates a NotificationWait request type response, as specified in section 2.2.2.2, including the NotificationWait request type response body as specified in section 2.2.4.4.2 if the request was successful.");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R1259. No pending event exists on the server. The NotificationWait request type execute time is {0}.", interval.TotalMinutes);

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1259
            // Because above step does not trigger any event, so if EventPending is false and the execute time of NotificationWait is larger than 5 minutes, R1930 will be verified.
            bool isVerifiedR1259 = interval.TotalSeconds >= 300 && notificationWaitResponseBody.EventPending == 0x00000000;

            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR1259,
                1259,
                @"[In Responding to a NotificationWait Request Type Request] This response [NotificationWait request type response] is not sent until the 5-minute maximum time limit expires.");

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

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R308
            // If the response body is not null, it indicates that method NotificationWait has been completed because server will return the event details in the ROP response buffer.
            this.Site.CaptureRequirementIfIsNotNull(
                notificationWaitResponseBody,
                308,
                @"[In NotificationWait Request Type] The NotificationWait request type is used by the client to request that the server notify the client when a processing request that takes an extended amount of time completes.");
            #endregion
            #endregion

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