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

MSOXCMAPIHTTP_S01_TC11_HTTPStatusCode() private method

private MSOXCMAPIHTTP_S01_TC11_HTTPStatusCode ( ) : void
return void
        public void MSOXCMAPIHTTP_S01_TC11_HTTPStatusCode()
        {
            this.CheckMapiHttpIsSupported();

            WebHeaderCollection headers = new WebHeaderCollection();
            CookieCollection cookies = new CookieCollection();
            MailboxResponseBodyBase response;

            #region Send a Connect request type request which misses X-RequestId header.
            HttpStatusCode httpStatusCodeFailed;
            AdapterHelper.ClientInstance = Guid.NewGuid().ToString();
            AdapterHelper.Counter = 1;
            headers = AdapterHelper.InitializeHTTPHeader(RequestType.Connect, AdapterHelper.ClientInstance, AdapterHelper.Counter);
            headers.Remove("X-RequestId");
            this.Adapter.Connect(this.AdminUserName, this.AdminUserPassword, this.AdminUserDN, ref cookies, out response, ref headers, out httpStatusCodeFailed);

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

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R143
            this.Site.CaptureRequirementIfAreEqual<uint>(
                7,
                AdapterHelper.GetFinalResponseCode(headers["X-ResponseCode"]),
                143,
                @"[In X-ResponseCode Header Field] Missing Header (7): The request has a missing required header.");

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

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R49
            this.Site.CaptureRequirementIfAreEqual<HttpStatusCode>(
                HttpStatusCode.OK,
                httpStatusCodeFailed,
                49,
                @"[In Common Response Format] The server returns a ""200 OK"" HTTP status code when the request failed for all non-exceptional failures.");
            #endregion

            #region Send a valid Connect request type to estabish a Session Context with the server.
            HttpStatusCode httpStatusCodeSucceed;
            AdapterHelper.ClientInstance = Guid.NewGuid().ToString();
            AdapterHelper.Counter = 1;
            headers = AdapterHelper.InitializeHTTPHeader(RequestType.Connect, AdapterHelper.ClientInstance, AdapterHelper.Counter);
            string requestIdValue = headers["X-RequestId"];
            cookies = new CookieCollection();
            this.Adapter.Connect(this.AdminUserName, this.AdminUserPassword, this.AdminUserDN, ref cookies, out response, ref headers, out httpStatusCodeSucceed);
            Site.Assert.AreEqual<uint>(0, uint.Parse(headers["X-ResponseCode"]), "The server should return a Status 0 in X-ResponseCode header if client connect to server succeeded.");

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

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R48
            this.Site.CaptureRequirementIfAreEqual<HttpStatusCode>(
                HttpStatusCode.OK,
                httpStatusCodeSucceed,
                48,
                @"[In Common Response Format] The server returns a ""200 OK"" HTTP status code when the request succeeds.");

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

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R2040
            this.Site.CaptureRequirementIfAreEqual<string>(
                requestIdValue,
                headers["X-RequestId"],
                2040,
                @"[In X-RequestId Header Field] the server MUST return this header [X-RequestId] with the same information in the response back to the client.");
            #endregion

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

            #region Send an anonymous request that includes a Connect request type.

            System.Threading.Thread.Sleep(60000);

            HttpStatusCode httpStatusCodeUnauthorized;
            AdapterHelper.ClientInstance = Guid.NewGuid().ToString();
            AdapterHelper.Counter = 1;
            headers = AdapterHelper.InitializeHTTPHeader(RequestType.Connect, AdapterHelper.ClientInstance, AdapterHelper.Counter);
            cookies = new CookieCollection();

            this.Adapter.Connect(string.Empty, string.Empty, string.Empty, ref cookies, out response, ref headers, out httpStatusCodeUnauthorized);
            
            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R1331");

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1331
            this.Site.CaptureRequirementIfAreEqual<HttpStatusCode>(
                HttpStatusCode.Unauthorized,
                httpStatusCodeUnauthorized,
                1331,
                @"[In Common Response Format] The server deviates from a ""200 OK"" HTTP status code for authentication (""401 Access Denied"").");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R36");
        
            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R36
            this.Site.CaptureRequirementIfAreNotEqual<HttpStatusCode>(
                HttpStatusCode.OK,
                httpStatusCodeUnauthorized,
                36,
                @"[In POST Method] No anonymous requests are allowed.");
            #endregion
        }
        #endregion Test Cases