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

MSOXCMAPIHTTP_S01_TC01_ConnectToMailboxServerSucceeded() private method

        public void MSOXCMAPIHTTP_S01_TC01_ConnectToMailboxServerSucceeded()
        {
            this.CheckMapiHttpIsSupported();

            WebHeaderCollection headers = new WebHeaderCollection();
            MailboxResponseBodyBase responseBody;

            #region Send a valid Connect request type to establish a Session Context with the server.
            ConnectSuccessResponseBody connectResponse = this.ConnectToServer(out headers);
            uint connectResult = AdapterHelper.GetFinalResponseCode(headers["X-ResponseCode"]);
            string firstGUIDPortionOfRequestId = headers["X-RequestId"].Substring(0, headers["X-RequestId"].IndexOf(":"));
            int firstCounterOfRequestId = int.Parse(headers["X-RequestId"].Substring(headers["X-RequestId"].IndexOf(":") + 1));

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R215: the DnPrefix field in Connect response is {0}.", connectResponse.DNPrefix.Replace("\0", string.Empty));
        
            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R215
            this.Site.CaptureRequirementIfIsTrue(
                connectResponse.DNPrefix.EndsWith("\0"),
                215,
                @"[In Connect Request Type Success Response Body] DnPrefix (variable): A null-terminated ASCII string that specifies the DN (1) prefix to be used for building message recipients (1).");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R216: the DisplayName field in Connect success response should is {0} and actual is  {1}", this.AdminUserName.Replace("\0", string.Empty), connectResponse.DisplayName.Replace("\0", string.Empty));

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R216
            this.Site.CaptureRequirementIfIsTrue(
                string.Compare(this.AdminUserName, connectResponse.DisplayName, true) == 0,
                216,
                @"[In Connect Request Type Success Response Body] DisplayName (variable): A null-terminated Unicode string that specifies the display name of the user who is specified in the UserDn field of the Connect request type request body.");

            Site.Assert.IsNotNull(
                headers["Set-Cookie"],
                "The Set-Cookie header should be returned from server if establishing a Session Context with server successfully");

            Site.Assert.IsNotNull(
                connectResponse,
                "The Connect request type success response body should be return from server if establish a Session Context with server successful.");
            
            // According to steps above, the Set-Cookie and Connect request type successful response body are included in the response.
            // So the requirement R1219 is verified.
            this.Site.CaptureRequirement(
                1219,
                @"[In Responding to a Connect or Bind Request Type Request] The server creates a new Session Context and associates it with a session context cookie.");

            // According to steps above, the server returned the Connect success response body are included in the response.
            // So the requirement R2224 is verified.
            this.Site.CaptureRequirement(
                2224,
                @"[In Responding to a Connect or Bind Request Type Request] If successful, the server's response includes the Connect request type success response body, as specified in section 2.2.4.1.2.");

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

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R2226
            this.Site.CaptureRequirementIfAreEqual<uint>(
                0,
                connectResult,
                2226,
                @"[In Responding to All Request Type Requests] After the request has been authorized, authenticated, parsed, and validated, the server MUST return a X-ResponseCode with a value of 0 (zero) to indicate that the request has been accepted.");
            #endregion

            #region Send an Execute request type that is used to send Logon ROP to server.
            WebHeaderCollection executeHeaders = AdapterHelper.InitializeHTTPHeader(RequestType.Execute, AdapterHelper.ClientInstance, AdapterHelper.Counter);
            string expectClientInfo = executeHeaders["X-ClientInfo"];

            ExecuteRequestBody requestBody = this.InitializeExecuteRequestBody(this.GetRopLogonRequest());
            List<string> metaTags = new List<string>();
            ExecuteSuccessResponseBody executeSuccessResponse = this.SendExecuteRequest(requestBody, ref executeHeaders, out metaTags) as ExecuteSuccessResponseBody;
            uint executeResult = AdapterHelper.GetFinalResponseCode(executeHeaders["X-ResponseCode"]);
            string actualClientInfo = executeHeaders["X-ClientInfo"];

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R181: the X-ResponseCode header in Connect response is {0} and the X-ResponseCode header in Execute response is {1}.", connectResult, executeResult);

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R181
            bool isVerifiedR181 = connectResult == 0 && executeResult == 0;

            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR181,
                181,
                @"[In Connect Request Type] The Connect request type is used to establish a Session Context with the server, as specified in section 3.1.5.1 and section 3.1.5.7.");

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

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R156
            this.Site.CaptureRequirementIfAreEqual<string>(
                expectClientInfo,
                actualClientInfo,
                156,
                @"[In X-ClientInfo Header Field] The server MUST return this header [X-ClientInfo] with the same information in the response back to the client.");

            string secondGUIDPortionOfRequestId = executeHeaders["X-RequestId"].Substring(0, executeHeaders["X-RequestId"].IndexOf(":"));
            int secondCounterOfRequestId = int.Parse(executeHeaders["X-RequestId"].Substring(executeHeaders["X-RequestId"].IndexOf(":") + 1));

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

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1432
            this.Site.CaptureRequirementIfAreEqual<string>(
                firstGUIDPortionOfRequestId,
                secondGUIDPortionOfRequestId,
                1432,
                @"[In X-RequestId Header Field] The GUID portion of the X-RequestId header is same in two different responses in one Session Contexts.");

            Site.Assert.AreEqual<int>(firstCounterOfRequestId + 1, secondCounterOfRequestId, "The counter portion of X-RequesutId header value should increase with every new HTTP request.");

            // If code can reach here, then the GUID portion of the X-RequestId header is same and counter portion of X-RequesutId header is increased. 
            // So R1330 is verified.
            this.Site.CaptureRequirement(
                1330,
                @"[In X-RequestId Header Field] In one client instance, the value of X-RequestId header field is different for two different responses and in the format of a GUID followed by an increasing decimal counter which MUST increase with every new HTTP request.");
            
            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R1147: the Set-Cookie header in Connect response is {0}.", headers["Set-Cookie"]);
        
            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1147
            bool isVerifiedR1147 = headers["Set-Cookie"] != null && executeSuccessResponse.ErrorCode == 0;
            
            this.Site.CaptureRequirementIfIsTrue(
                isVerifiedR1147,
                1147,
                @"[[In Creating a Session Context by Using the Connect or Bind Request Type] As specified in section 3.2.5.1, the server returns cookies used to identify the Session Context that has been created.");
            #endregion

            #region Send a Disconnect request type request to destroy the Session Context.
            this.Adapter.Disconnect(out responseBody);
            DisconnectSuccessResponseBody disconnectResponseBody = (DisconnectSuccessResponseBody)responseBody;
            Site.Assert.AreEqual<uint>(0, disconnectResponseBody.ErrorCode, "Disconnect should succeed and 0 is expected to be returned. The returned value is {0}.", disconnectResponseBody.ErrorCode);

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

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1250
            // The above assert ensures that the Disconnect request type executes successfully, so R1250 can be verified if the Disconnect response body is not null.
            this.Site.CaptureRequirementIfIsNotNull(
                responseBody,
                1250,
                @"[In Responding to a Disconnect or Unbind Request Type Request] The server sends a response, as specified in section 2.2.2.2, to a Disconnect request type or Unbind request type request.");

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

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R2234
            this.Site.CaptureRequirementIfIsInstanceOfType(
                responseBody,
                typeof(DisconnectSuccessResponseBody),
                2234,
                @"[In Responding to a Disconnect or Unbind Request Type Request] If successful, the server's response includes the Disconnect request type success response body, as specified in section 2.2.4.3.2.");
            #endregion

            #region Send an Execute request after disconnect with server.
            uint responseCodeAfterDisconenct = this.ExecuteLogonROP(AdapterHelper.SessionContextCookies);

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

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R304
            this.Site.CaptureRequirementIfAreNotEqual<uint>(
                0,
                responseCodeAfterDisconenct,
                304,
                @"[In Disconnect Request Type] The Disconnect request type is used by the client to delete a Session Context with the server, as specified in section 3.1.5.4.");

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

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R146
            this.Site.CaptureRequirementIfAreEqual<uint>(
                10,
                responseCodeAfterDisconenct,
                146,
                @"[In X-ResponseCode Header Field] Context Not Found (10): The Session Context is not found.");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R1225");
        
            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1225
            this.Site.CaptureRequirementIfAreEqual<uint>(
                10,
                responseCodeAfterDisconenct,
                1225,
                @"[In Responding to a Connect or Bind Request Type Request] If the authentication context differs, the server MUST fail the request with a value of 10 (""Context Not Found"" error) in the X-ResponseCode header.");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R1253");
        
            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1253
            this.Site.CaptureRequirementIfAreEqual<uint>(
                10,
                responseCodeAfterDisconenct,
                1253,
                @"[In Responding to a Disconnect or Unbind Request Type Request] If the client attempts to use an invalid session context cookie [which is released by server] in a request, the server MUST fail the request to indicate to the client that the Session Context is not valid.");

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

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R2236
            this.Site.CaptureRequirementIfAreEqual<uint>(
                10,
                responseCodeAfterDisconenct,
                2236,
                @"[In Responding to a Disconnect or Unbind Request Type Request] Once the session context cookie has been invalidated by the server, the client cannot use it in subsequent requests.");
            #endregion

            #region Send a valid Connect request type to establish a Session Context with the server.
            ConnectSuccessResponseBody connectResponse2 = this.ConnectToServer(out headers);
            string thirdGUIDPortionOfRequestId = headers["X-RequestId"].Substring(0, headers["X-RequestId"].IndexOf(":"));

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R1464");
        
            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1464
            this.Site.CaptureRequirementIfAreNotEqual<string>(
                firstGUIDPortionOfRequestId,
                thirdGUIDPortionOfRequestId,
                1464,
                @"[In X-RequestId Header Field] The GUID portion of the X-RequestId header is different for different Session Contexts.");
            #endregion

            #region Send a Disconnect request type request to destroy the Session Context.
            this.Adapter.Disconnect(out responseBody);
            disconnectResponseBody = (DisconnectSuccessResponseBody)responseBody;
            Site.Assert.AreEqual<uint>(0, disconnectResponseBody.ErrorCode, "Disconnect should succeed and 0 is expected to be returned. The returned value is {0}.", disconnectResponseBody.ErrorCode);
            #endregion
        }