Microsoft.Protocols.TestSuites.MS_OXCROPS.S04_MessageROPs.MSOXCROPS_S04_TC05_TestRopOpenAndDeleteAttachment C# (CSharp) Method

MSOXCROPS_S04_TC05_TestRopOpenAndDeleteAttachment() private method

private MSOXCROPS_S04_TC05_TestRopOpenAndDeleteAttachment ( ) : void
return void
        public void MSOXCROPS_S04_TC05_TestRopOpenAndDeleteAttachment()
        {
            this.CheckTransportIsSupported();

            this.cropsAdapter.RpcConnect(
                Common.GetConfigurationPropertyValue("SutComputerName", this.Site),
                ConnectionType.PrivateMailboxServer,
                Common.GetConfigurationPropertyValue("UserEssdn", this.Site),
                Common.GetConfigurationPropertyValue("Domain", this.Site),
                Common.GetConfigurationPropertyValue("AdminUserName", this.Site),
                Common.GetConfigurationPropertyValue("PassWord", this.Site));

            // Step 1: Create and save message.
            #region Create and save message

            // Log on to the private mailbox.
            RopLogonResponse logonResponse = Logon(LogonType.Mailbox, this.userDN, out inputObjHandle);

            // Create a message
            #region Create a message

            RopCreateMessageRequest createMessageRequest = new RopCreateMessageRequest();
            RopCreateMessageResponse createMessageResponse;

            createMessageRequest.RopId = (byte)RopId.RopCreateMessage;

            createMessageRequest.LogonId = TestSuiteBase.LogonId;

            // Set InputHandleIndex to 0x0, which specifies the location in the Server object handle table where the handle for the input Server object is stored.
            createMessageRequest.InputHandleIndex = TestSuiteBase.InputHandleIndex0;

            // Set OutputHandleIndex to 0x01, which specifies the location in the Server object handle table where the handle for the output Server object will be stored.
            createMessageRequest.OutputHandleIndex = TestSuiteBase.OutputHandleIndex1;

            // Set CodePageId to 0x0FFF, which specified the code page of Logon object will be used.
            createMessageRequest.CodePageId = TestSuiteBase.CodePageId;

            // Set FolderId to the 5th of logonResponse(INBOX), which identifies the parent folder.
            createMessageRequest.FolderId = logonResponse.FolderIds[4];

            // Set AssociatedFlag to 0x00, which specified this message is not a folder associated information (FAI) message.
            createMessageRequest.AssociatedFlag = Convert.ToByte(TestSuiteBase.Zero);

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Step 1: Begin to send the RopCreateMessage request.");

            // Send the RopCreateMessage request and verify the success response.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                createMessageRequest,
                this.inputObjHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            createMessageResponse = (RopCreateMessageResponse)response;

            Site.Assert.AreEqual<uint>(
                TestSuiteBase.SuccessReturnValue,
                createMessageResponse.ReturnValue,
                "if ROP succeeds, the ReturnValue of its response is 0(success)");
            uint targetMessageHandle = responseSOHs[0][createMessageResponse.OutputHandleIndex];

            #endregion

            // Save message.
            #region Save message

            RopSaveChangesMessageRequest saveChangesMessageRequest;
            RopSaveChangesMessageResponse saveChangesMessageResponse;

            saveChangesMessageRequest.RopId = (byte)RopId.RopSaveChangesMessage;
            saveChangesMessageRequest.LogonId = TestSuiteBase.LogonId;

            // Set InputHandleIndex to 0x00, which specifies the location in the Server object handle table where the handle for the input Server object is stored.
            saveChangesMessageRequest.InputHandleIndex = TestSuiteBase.InputHandleIndex0;

            // Set ResponseHandleIndex to 0x01, which specifies the location in the Server object handle table that is referenced
            // in the response.
            saveChangesMessageRequest.ResponseHandleIndex = TestSuiteBase.ResponseHandleIndex1;

            saveChangesMessageRequest.SaveFlags = (byte)SaveFlags.ForceSave;

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Step 1: Begin to send the RopSaveChangesMessage request.");

            // Send the RopSaveChangesMessage request to the server and verify the success response.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                saveChangesMessageRequest,
                targetMessageHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            saveChangesMessageResponse = (RopSaveChangesMessageResponse)response;

            Site.Assert.AreEqual<uint>(
                TestSuiteBase.SuccessReturnValue,
                saveChangesMessageResponse.ReturnValue,
                "If ROP succeeds, the ReturnValue of its response is 0 (success)");

            #endregion

            #endregion

            // Step 2: Send the RopCreateAttachment request and verify the success response.
            #region RopCreateAttachment success response

            RopCreateAttachmentRequest createAttachmentRequest;
            RopCreateAttachmentResponse createAttachmentResponse;

            createAttachmentRequest.RopId = (byte)RopId.RopCreateAttachment;
            createAttachmentRequest.LogonId = TestSuiteBase.LogonId;

            // Set InputHandleIndex to 0x00, which specifies the location in the Server object handle table where the handle for the input Server object is stored.
            createAttachmentRequest.InputHandleIndex = TestSuiteBase.InputHandleIndex0;

            // Set OutputHandleIndex to 0x01, which specifies the location in the Server object handle table where the handle for the output Server object will be stored.
            createAttachmentRequest.OutputHandleIndex = TestSuiteBase.OutputHandleIndex1;

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Step 2: Begin to send the RopCreateAttachment request.");

            // Send the RopCreateAttachment request to the server and verify the success response.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                createAttachmentRequest,
                targetMessageHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            createAttachmentResponse = (RopCreateAttachmentResponse)response;

            Site.Assert.AreEqual<uint>(
                TestSuiteBase.SuccessReturnValue,
                createAttachmentResponse.ReturnValue,
                "if ROP succeeds, the ReturnValue of its response is 0(success)");
            uint attachmentHandle = responseSOHs[0][createAttachmentResponse.OutputHandleIndex];
            uint attachmentId = createAttachmentResponse.AttachmentID;

            #endregion

            // Step 3: Send the RopSaveChangesAttachment request and verify the success response.
            #region RopSaveChangesAttachment success response

            RopSaveChangesAttachmentRequest saveChangesAttachmentRequest;
            RopSaveChangesAttachmentResponse saveChangesAttachmentReponse;

            saveChangesAttachmentRequest.RopId = (byte)RopId.RopSaveChangesAttachment;
            saveChangesAttachmentRequest.LogonId = TestSuiteBase.LogonId;

            // Set ResponseHandleIndex to 0x01, which specifies the location in the Server object handle table that is referenced
            // in the response.
            saveChangesAttachmentRequest.ResponseHandleIndex = TestSuiteBase.ResponseHandleIndex1;

            // Set InputHandleIndex to 0x00, which specifies the location in the Server object handle table where the handle for the input Server object is stored.
            saveChangesAttachmentRequest.InputHandleIndex = TestSuiteBase.InputHandleIndex0;

            saveChangesAttachmentRequest.SaveFlags = (byte)SaveFlags.ForceSave;

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Step 3: Begin to send the RopSaveChangesAttachment request.");

            // Send the RopSaveChangesAttachment request to the server and verify the success response.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                saveChangesAttachmentRequest,
                attachmentHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            saveChangesAttachmentReponse = (RopSaveChangesAttachmentResponse)response;

            Site.Assert.AreEqual<uint>(
                TestSuiteBase.SuccessReturnValue,
                saveChangesAttachmentReponse.ReturnValue,
                "if ROP succeeds, the ReturnValue of its response is 0(success)");

            #endregion

            // Step 4: Send the RopGetPropertiesAll request and verify the success response.
            #region RopGetPropertiesAll success response

            RopGetPropertiesAllRequest getPropertiesAllRequest;
            RopGetPropertiesAllResponse getPropertiesAllResponse;

            getPropertiesAllRequest.RopId = (byte)RopId.RopGetPropertiesAll;

            getPropertiesAllRequest.LogonId = TestSuiteBase.LogonId;
            getPropertiesAllRequest.InputHandleIndex = TestSuiteBase.InputHandleIndex0;

            // Set PropertySizeLimit, which specifies the maximum size allowed for a property value returned.
            getPropertiesAllRequest.PropertySizeLimit = TestSuiteBase.PropertySizeLimit;

            getPropertiesAllRequest.WantUnicode = (ushort)Zero;

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Step 1: Begin to send the RopGetPropertiesAll request.");

            // Send the RopGetPropertiesAll request and verify the success response.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                getPropertiesAllRequest,
                attachmentHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            getPropertiesAllResponse = (RopGetPropertiesAllResponse)response;

            Site.Assert.AreEqual<uint>(
                TestSuiteBase.SuccessReturnValue,
                getPropertiesAllResponse.ReturnValue,
                "if ROP succeeds, ReturnValue of its response will be 0 (success)");

            int counter = 0;
            byte[] tempArray = BitConverter.GetBytes(attachmentId);
            foreach (TaggedPropertyValue item in getPropertiesAllResponse.PropertyValues)
            {
                // Refer to MS-OXPROPS, the Property ID of PidTagAttachNumber is 0x0E21.
                if (item.PropertyTag.PropertyId == 0x0E21)
                {
                    if (item.Value == null || tempArray == null)
                    {
                        break;
                    }
                    else if (item.Value.Length == 0 || tempArray.Length == 0)
                    {
                        break;
                    }
                    else if (item.Value.Length != tempArray.Length)
                    {
                        break;
                    }
                    else
                    {
                        for (int i = 0; i < tempArray.Length; i++)
                        {
                            if (item.Value[i] == tempArray[i])
                            {
                                counter++;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    break;
                }
            }

            bool isVerifyR2175 = counter == tempArray.Length;

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

            // Verify MS-OXCROPS requirement: MS-OXCROPS_R2175
            Site.CaptureRequirementIfIsTrue(
                isVerifyR2175,
                2175,
                @"[In RopCreateAttachment ROP Success Response Buffer,AttachmentID (4 bytes)] The value of this field is equivalent to the value of the PidTagAttachNumber property ([MS-OXCMSG] section 2.2.2.6).");
            #endregion

            // Step 5: Send the RopSaveChangesAttachment request and verify the success response.
            #region RopOpenAttachment success response

            RopOpenAttachmentRequest openAttachmentRequest;
            RopOpenAttachmentResponse openAttachmentResponse;

            openAttachmentRequest.RopId = (byte)RopId.RopOpenAttachment;
            openAttachmentRequest.LogonId = TestSuiteBase.LogonId;

            // Set InputHandleIndex to 0x00, which specifies the location in the Server object handle table where the handle for the input Server object is stored.
            openAttachmentRequest.InputHandleIndex = TestSuiteBase.InputHandleIndex0;

            // Set OutputHandleIndex to 0x01, which specifies the location in the Server object handle table where the handle for the output Server object will be stored.
            openAttachmentRequest.OutputHandleIndex = TestSuiteBase.OutputHandleIndex1;

            openAttachmentRequest.OpenAttachmentFlags = (byte)OpenAttachmentFlags.ReadOnly;

            // Set AttachmentID, which identifies the attachment to be opened.
            openAttachmentRequest.AttachmentID = attachmentId;

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Step 4: Begin to send the RopOpenAttachment request.");

            // Send the RopOpenAttachment request and verify the success response.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                openAttachmentRequest,
                targetMessageHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            openAttachmentResponse = (RopOpenAttachmentResponse)response;

            Site.Assert.AreEqual<uint>(
                TestSuiteBase.SuccessReturnValue,
                openAttachmentResponse.ReturnValue,
                "if ROP succeeds, the ReturnValue of its response is 0(success)");

            #endregion

            // Step 6: Send the RopSaveChangesAttachment request and verify the success response.
            #region  RopDeleteAttachment success response

            RopDeleteAttachmentRequest deleteAttachmentRequest;
            RopDeleteAttachmentResponse deleteAttachmentResponse;

            deleteAttachmentRequest.RopId = (byte)RopId.RopDeleteAttachment;
            deleteAttachmentRequest.LogonId = TestSuiteBase.LogonId;

            // Set InputHandleIndex to 0x00, which specifies the location in the Server object handle table where the handle for the input Server object is stored.
            deleteAttachmentRequest.InputHandleIndex = TestSuiteBase.InputHandleIndex0;

            // Set AttachmentID, which e identifies the attachment to be deleted.
            deleteAttachmentRequest.AttachmentID = attachmentId;

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Step 5: Begin to send the RopDeleteAttachment request.");

            // Send the RopDeleteAttachment request and verify the success response.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                deleteAttachmentRequest,
                targetMessageHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            deleteAttachmentResponse = (RopDeleteAttachmentResponse)response;

            Site.Assert.AreEqual<uint>(
                TestSuiteBase.SuccessReturnValue,
                deleteAttachmentResponse.ReturnValue,
                "if ROP succeeds, the ReturnValue of its response is 0(success)");

            #endregion

            // Step 7: Send the RopCreateAttachment request and verify the failure response.
            #region RopCreateAttachment failure response

            // Set InputHandleIndex to 0x01, which is an invalid index and will lead to a failure response.
            createAttachmentRequest.InputHandleIndex = TestSuiteBase.InputHandleIndex1;

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Step 6: Begin to send the RopCreateAttachment request.");

            // Send the RopCreateAttachment request and verify the failure response.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                createAttachmentRequest,
                targetMessageHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.FailureResponse);
            createAttachmentResponse = (RopCreateAttachmentResponse)response;

            Site.Assert.AreNotEqual<uint>(
                TestSuiteBase.SuccessReturnValue,
                createAttachmentResponse.ReturnValue,
                "If ROP fails, the ReturnValue of its response is set to a value other than 0x00000000(failure)");

            #endregion
        }