public void MSOXCFOLD_S05_TC03_RopEmptyFolderPartialCompleteValidation()
        {
            if (!Common.IsRequirementEnabled(1131, this.Site))
            {
                this.NeedCleanup = false;
                Site.Assert.Inconclusive("The implementation does not support to set nonzero value to PartialCompletion field of the RopEmptyFolder ROP response if the server fails to delete any message or subfolder by RopEmptyFolder ROP.");
            }

            this.CheckWhetherSupportTransport();
            this.Adapter.DoConnect(ConnectionType.PrivateMailboxServer);
            uint pidTagMemberRights = 0;
            uint logonHandle = 0;
            this.GenericFolderInitialization();

            #region Step 1. Assign access permission for common user on the inbox and the root folder.
            uint inboxHandle = 0;
            this.OpenFolder(this.LogonHandle, this.DefaultFolderIds[this.inboxIndex], ref inboxHandle);

            // Add folder visible permission for the inbox.
            pidTagMemberRights = (uint)PidTagMemberRightsEnum.FolderVisible | (uint)PidTagMemberRightsEnum.ReadAny;
            this.AddPermission(this.commonUserEssdn, pidTagMemberRights, inboxHandle);

            // Add folder visible permission for the root folder.
            pidTagMemberRights = (uint)PidTagMemberRightsEnum.FolderVisible | (uint)PidTagMemberRightsEnum.ReadAny;
            this.AddPermission(this.commonUserEssdn, pidTagMemberRights, this.RootFolderHandle);
            #endregion

            #region Step 2. Create a subfolder [MSOXCFOLDSubfolder1] in the root folder and assign full permission for common user on the new folder.
            uint adminSubfolderHandle1 = 0;
            ulong adminSubfolderId1 = 0;
            this.CreateFolder(this.RootFolderHandle, Constants.Subfolder1, ref adminSubfolderId1, ref adminSubfolderHandle1);

            pidTagMemberRights = (uint)PidTagMemberRightsEnum.FolderVisible | (uint)PidTagMemberRightsEnum.ReadAny | (uint)PidTagMemberRightsEnum.DeleteOwned | (uint)PidTagMemberRightsEnum.CreateSubFolder;
            this.AddPermission(this.commonUserEssdn, pidTagMemberRights, adminSubfolderHandle1);
            #endregion

            #region Step 3. Create a subfolder [MSOXCFOLDSubfolder2] in the root folder and assign full permission for common user on the new folder.
            uint adminSubfolderHandle2 = 0;
            ulong adminSubfolderId2 = 0;
            this.CreateFolder(this.RootFolderHandle, Constants.Subfolder2, ref adminSubfolderId2, ref adminSubfolderHandle2);

            pidTagMemberRights = (uint)PidTagMemberRightsEnum.FullPermission;
            this.AddPermission(this.commonUserEssdn, pidTagMemberRights, adminSubfolderHandle2);
            #endregion

            #region Step 4. Create a subfolder [MSOXCFOLDSubfolder3] in the [MSOXCFOLDSubfolder1] and assign full permission for common user on the new folder.
            uint adminSubfolderHandle3 = 0;
            ulong adminSubfolderId3 = 0;
            this.CreateFolder(adminSubfolderHandle1, Constants.Subfolder3, ref adminSubfolderId3, ref adminSubfolderHandle3);

            pidTagMemberRights = (uint)PidTagMemberRightsEnum.FullPermission;
            this.AddPermission(this.commonUserEssdn, pidTagMemberRights, adminSubfolderHandle3);
            #endregion

            #region Step 5. Create a subfolder [MSOXCFOLDSubfolder4] in the root folder.
            uint adminSubfolderHandle4 = 0;
            ulong adminSubfolderId4 = 0;
            this.CreateFolder(adminSubfolderHandle1, Constants.Subfolder4, ref adminSubfolderId4, ref adminSubfolderHandle4);
            #endregion

            #region Step 6. Logon to the private mailbox use common user.
            this.Adapter.DoDisconnect();
            this.Adapter.DoConnect(this.sutServer, ConnectionType.PrivateMailboxServer, this.commonUserEssdn, this.domain, this.commonUser, this.commonUserPassword);
            RopLogonResponse logonResponse = this.Logon(LogonFlags.Private, out logonHandle, (uint)OpenFlags.UsePerMDBReplipMapping);
            #endregion

            #region Step 7. The common user open the root folder, [MSOXCFOLDSubfolder1], [MSOXCFOLDSubfolder2] and [MSOXCFOLDSubfolder3].

            // Find and open the root folder.
            ulong commonUserRootFolderId = this.GetSubfolderIDByName(logonResponse.FolderIds[this.inboxIndex], logonHandle, this.RootFolder);
            uint commonUserRootFolderHandle = 0;
            this.OpenFolder(logonHandle, commonUserRootFolderId, ref commonUserRootFolderHandle);

            // Find and open the folder named [MSOXCFOLDSubfolder1].
            ulong commonUserSubfolder1 = this.GetSubfolderIDByName(commonUserRootFolderId, commonUserRootFolderHandle, Constants.Subfolder1);
            uint commonUserRootSubfolderHandle1 = 0;
            this.OpenFolder(logonHandle, commonUserSubfolder1, ref commonUserRootSubfolderHandle1);

            // Find and open the folder named [MSOXCFOLDSubfolder2].
            ulong commonUserSubfolder2 = this.GetSubfolderIDByName(commonUserRootFolderId, commonUserRootFolderHandle, Constants.Subfolder2);
            uint commonUserRootSubfolderHandle2 = 0;
            this.OpenFolder(logonHandle, commonUserSubfolder2, ref commonUserRootSubfolderHandle2);
            #endregion

            #region Step 5. Create a subfolder [MSOXCFOLDSubfolder4] in the root folder.
            uint commonUserSubfolderHandle5 = 0;
            ulong commonUserSubfolderId5 = 0;
            this.CreateFolder(commonUserRootSubfolderHandle1, Constants.Subfolder5, ref commonUserSubfolderId5, ref commonUserSubfolderHandle5);
            #endregion

            #region Step 8. The client calls RopEmptyFolder clear the root folder.
            RopEmptyFolderRequest emptyFolderRequest = new RopEmptyFolderRequest
            {
                RopId = (byte)RopId.RopEmptyFolder,
                LogonId = Constants.CommonLogonId,
                InputHandleIndex = Constants.CommonInputHandleIndex,
                WantAsynchronous = 0x00,
                WantDeleteAssociated = 0x00
            };

            // Invoke RopEmptyFolder operation to soft delete Subfolder3 from Subfolder1 without deleting Subfolder1.
            RopEmptyFolderResponse emptyFolderResponse = this.Adapter.EmptyFolder(emptyFolderRequest, commonUserRootSubfolderHandle1, ref this.responseHandles);
            Site.Assert.AreEqual<uint>(0, emptyFolderResponse.ReturnValue, "The RopEmptyFolder Rop operation performs successfully on [MSOXCFOLDSubfolder1]");

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

            // Verify MS-OXCFOLD requirement: MS-OXCFOLD_R980.
            Site.CaptureRequirementIfAreNotEqual<byte>(
                0,
                emptyFolderResponse.PartialCompletion,
                980,
                @"[In RopEmptyFolder ROP Response Buffer] If the ROP [RopEmptyFolder] fails for a subset of targets, the value of this field [PartialCompletion] is nonzero (TRUE).");

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

            // Verify MS-OXCFOLD requirement: MS-OXCFOLD_R1131
            Site.CaptureRequirementIfAreNotEqual<byte>(
                0,
                emptyFolderResponse.PartialCompletion,
                1131,
                @"[In Processing a RopEmptyFolder ROP Request] If the server fails to delete any message or subfolder, it sets the PartialCompletion field of the RopEmptyFolder ROP response buffer to nonzero (TRUE), as specified in section 2.2.1.9.2.");
            #endregion
        }
        /// <summary>
        /// This ROP deletes all messages and subfolders from a folder. 
        /// </summary>
        /// <param name="handle">The handle to operate.</param>
        /// <param name="wantAsynchronous">This value specifies whether the operation is to be executed asynchronously with status reported via RopProgress.</param>
        /// <param name="needVerify">Whether need to verify the response.</param>
        /// <returns>The response of this ROP.</returns>
        private RopEmptyFolderResponse RopEmptyFolder(uint handle, byte wantAsynchronous, bool needVerify)
        {
            this.rawDataValue = null;
            this.responseValue = null;
            this.responseSOHsValue = null;

            RopEmptyFolderRequest emptyFolderRequest = new RopEmptyFolderRequest()
            {
                RopId = (byte)RopId.RopEmptyFolder,
                LogonId = LogonId,
                InputHandleIndex = (byte)HandleIndex.FirstIndex,
                WantAsynchronous = wantAsynchronous,
                WantDeleteAssociated = Convert.ToByte(true),
            };

            this.responseSOHsValue = this.ProcessSingleRop(emptyFolderRequest, handle, ref this.responseValue, ref this.rawDataValue, RopResponseType.SuccessResponse);
            RopEmptyFolderResponse emptyFolderResponse = (RopEmptyFolderResponse)this.responseValue;
            if (needVerify)
            {
                Site.Assert.AreEqual((uint)RopResponseType.SuccessResponse, emptyFolderResponse.ReturnValue, string.Format("RopEmptyFolder Failed! Error: 0x{0:X8}", emptyFolderResponse.ReturnValue));
            }

            return emptyFolderResponse;
        }
        public void MSOXCFOLD_S04_TC07_RopEmptyPublicFolder()
        {
            if (!Common.IsRequirementEnabled(97501002, this.Site))
            {
                this.NeedCleanup = false;
                Site.Assert.Inconclusive("The server does not support the RopEmptyFolder ROP ([MS-OXCROPS] section 2.2.4.9) for public folders.");
            }

            this.CheckWhetherSupportTransport();
            this.Logon();
            this.PublicFolderInitialization();

            #region Step 1. The client calls RopCreateFolder to create [MSOXCFOLDSubfolder1] under the root public folder.

            RopCreateFolderRequest createFolderRequest = new RopCreateFolderRequest
            {
                RopId = (byte)RopId.RopCreateFolder,
                LogonId = Constants.CommonLogonId,
                InputHandleIndex = Constants.CommonInputHandleIndex,
                OutputHandleIndex = Constants.CommonOutputHandleIndex,
                FolderType = (byte)FolderType.Genericfolder,
                UseUnicodeStrings = 0x0,
                OpenExisting = 0x01,
                Reserved = 0x0,
                DisplayName = Encoding.ASCII.GetBytes(Constants.Subfolder1),
                Comment = Encoding.ASCII.GetBytes(Constants.Subfolder1)
            };

            RopCreateFolderResponse createFolderResponse = this.Adapter.CreateFolder(createFolderRequest, this.publicRootFolderHandle, ref this.responseHandles);
            Site.Assert.AreEqual<uint>(0, createFolderResponse.ReturnValue, "RopCreateFolder ROP operation performs successfully.");
            uint subfolderHandle1 = this.responseHandles[0][createFolderResponse.OutputHandleIndex];
            #endregion

            #region Step 2. The client creates a message in [MSOXCFOLDSubfolder1].

            uint messageHandle = 0;
            ulong messageId = 0;
            this.CreateSaveMessage(this.publicRootFolderHandle, this.publicRootFolderId, ref messageId, ref messageHandle);

            #endregion

            #region Step 3. The client creates a subfolder in [MSOXCFOLDSubfolder1].

            createFolderRequest.DisplayName = Encoding.ASCII.GetBytes(Constants.Subfolder2);
            createFolderRequest.Comment = Encoding.ASCII.GetBytes(Constants.Subfolder2);

            createFolderResponse = this.Adapter.CreateFolder(createFolderRequest, subfolderHandle1, ref this.responseHandles);
            Site.Assert.AreEqual<uint>(0, createFolderResponse.ReturnValue, "RopCreateFolder ROP operation performs successfully.");
            #endregion

            #region Step 4. The client calls RopEmptyFolder to empty [MSOXCFOLDSubfolder1].

            RopEmptyFolderRequest emptyFolderRequest = new RopEmptyFolderRequest
            {
                RopId = (byte)RopId.RopEmptyFolder,
                LogonId = Constants.CommonLogonId,
                InputHandleIndex = Constants.CommonInputHandleIndex,
                WantAsynchronous = 0x00,
                WantDeleteAssociated = 0x00
            };

            // Invoke RopEmptyFolder operation to soft delete Subfolder3 from Subfolder1 without deleting Subfolder1.
            RopEmptyFolderResponse emptyFolderResponse = this.Adapter.EmptyFolder(emptyFolderRequest, subfolderHandle1, ref this.responseHandles);

            Site.Assert.AreEqual<uint>(0, emptyFolderResponse.ReturnValue, "RopEmptyFolder ROP operation performs successfully on [MSOXCFOLDSubfolder1].");

            #endregion

            #region Step 5. The client calls RopGetContentsTable to retrieve the contents table of [MSOXCFOLDSubfolder1].

            RopGetContentsTableRequest getContentsTableRequest = new RopGetContentsTableRequest
            {
                RopId = (byte)RopId.RopGetContentsTable,
                LogonId = Constants.CommonLogonId,
                InputHandleIndex = Constants.CommonInputHandleIndex,
                OutputHandleIndex = Constants.CommonOutputHandleIndex,
                TableFlags = (byte)FolderTableFlags.None
            };

            RopGetContentsTableResponse getContentsTableResponse = this.Adapter.GetContentsTable(getContentsTableRequest, subfolderHandle1, ref this.responseHandles);
            Site.Assert.AreEqual<uint>(Constants.SuccessCode, getContentsTableResponse.ReturnValue, "RopGetContentsTable ROP operation performs successfully!");

            #endregion

            #region Step 6. The client calls RopGetHierarchyTable to retrieve the hierarchy table of [MSOXCFOLDSubfolder1].

            RopGetHierarchyTableRequest getHierarchyTableRequest = new RopGetHierarchyTableRequest
            {
                RopId = (byte)RopId.RopGetHierarchyTable,
                LogonId = Constants.CommonLogonId,
                InputHandleIndex = Constants.CommonInputHandleIndex,
                OutputHandleIndex = Constants.CommonOutputHandleIndex,
                TableFlags = (byte)FolderTableFlags.None
            };

            RopGetHierarchyTableResponse getHierarchyTableResponse = this.Adapter.GetHierarchyTable(getHierarchyTableRequest, subfolderHandle1, ref this.responseHandles);
            Site.Assert.AreEqual<uint>(Constants.SuccessCode, getHierarchyTableResponse.ReturnValue, "RopGetHierarchyTable ROP operation performs successfully!");

            // Add the debug information
            Site.Log.Add(
                LogEntryKind.Debug,
                "Verify MS-OXCFOLD_R97501002: The message count of the target folder after RopEmptyFolder is {0}, the subfolder count of the target folder after RopEmptyFolder is {1}",
                getContentsTableResponse.RowCount,
                getHierarchyTableResponse.RowCount);

            bool isVerifyR97501002 = getContentsTableResponse.RowCount == 0 && getHierarchyTableResponse.RowCount == 0;

            // Verify MS-OXCFOLD requirement: MS-OXCFOLD_R97501002.
            Site.CaptureRequirementIfIsTrue(
                isVerifyR97501002,
                97501002,
                @"[In Appendix A: Product Behavior] Implementation does support the RopEmptyFolder ROP ([MS-OXCROPS] section 2.2.4.9) for public folders. (Microsoft Exchange Server 2007 and Microsoft Exchange Server 2010 follow this behavior.)");
            #endregion
        }
        public void MSOXCFOLD_S02_TC02_RopEmptyFolderSuccess()
        {
            this.CheckWhetherSupportTransport();
            this.Adapter.DoConnect(ConnectionType.PrivateMailboxServer);
            this.GenericFolderInitialization();

            #region Step 1. Call RopCreateFolder to create [MSOXCFOLDSubfolder1] under the root folder.
            uint subfolderHandle1 = 0;
            ulong subfolderId1 = 0;
            this.CreateFolder(this.RootFolderHandle, Constants.Subfolder1, ref subfolderId1, ref subfolderHandle1);
            #endregion

            #region  Step 2. Call RopCreateFolder to create [MSOXCFOLDSubfolder3] under [MSOXCFOLDSubfolder1].
            uint subfolderHandle3 = 0;
            ulong subfolderId3 = 0;
            this.CreateFolder(subfolderHandle1, Constants.Subfolder3, ref subfolderId3, ref subfolderHandle3);
            #endregion

            #region Step 3. Creates a message in [MSOXCFOLDSubfolder1].
            ulong messageId = 0;
            uint messageHandle = 0;
            this.CreateSaveMessage(subfolderHandle1, subfolderId1, ref messageId, ref messageHandle);
            #endregion

            #region Step 4. Call RopEmptyFolder to empty [MSOXCFOLDSubfolder1] synchronously.
            RopEmptyFolderRequest emptyFolderRequest = new RopEmptyFolderRequest
            {
                RopId = (byte)RopId.RopEmptyFolder,
                LogonId = Constants.CommonLogonId,
                InputHandleIndex = Constants.CommonInputHandleIndex,
                WantAsynchronous = 0x00,
                WantDeleteAssociated = 0x00
            };

            // Invoke RopEmptyFolder operation to soft delete Subfolder3 from Subfolder1 without deleting Subfolder1.
            RopEmptyFolderResponse emptyFolderResponse = this.Adapter.EmptyFolder(emptyFolderRequest, subfolderHandle1, ref this.responseHandles);

            Site.Assert.AreEqual<uint>(0, emptyFolderResponse.ReturnValue, "The RopEmptyFolder Rop operation performs successfully on [MSOXCFOLDSubfolder1]");

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

            // Verify MS-OXCFOLD requirement: MS-OXCFOLD_R1126.
            Site.CaptureRequirementIfAreEqual<Type>(
                typeof(RopEmptyFolderResponse),
                emptyFolderResponse.GetType(),
                1126,
                @"[In Processing a RopEmptyFolder ROP Request] The server responds with a RopEmptyFolder ROP response buffer.");

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

            // Verify MS-OXCFOLD requirement: MS-OXCFOLD_R235.
            // The WantAsynchronous was set to zero and the server responds a RopEmptyFolder ROP response indicates the ROP is processed synchronously, MS-OXCFOLD_R235 can be verified directly.
            Site.CaptureRequirement(
                235,
                @"[In RopEmptyFolder ROP Request Buffer] WantAsynchronous (1 byte): [A Boolean value that is] zero (FALSE) if the ROP is to be processed synchronously.");

            #region Verify MS-OXCFOLD_R97502 and MS-OXCFOLD_R243 and MS-OXCFOLD_R225.
            // Add the debug information.
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCFOLD_R97502");

            // Verify MS-OXCFOLD requirement: MS-OXCFOLD_R97502
            // The RopEmptyFolder ROP operation performs successfully on a private mailbox, MS-OXCFOLD_R97502 can be verified directly.
            Site.CaptureRequirement(
                97502,
                @"[In RopEmptyFolder ROP] This ROP [RopEmptyFolder] applies to [both public folders and] private mailboxes.");

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

            // Verify MS-OXCFOLD requirement: MS-OXCFOLD_R243
            Site.CaptureRequirementIfAreEqual<byte>(
                0x00,
                emptyFolderResponse.PartialCompletion,
                243,
                @"[In RopEmptyFolder ROP Response Buffer]PartialCompletion (1 byte): Otherwise [if the ROP successes for a subset of targets], the value [of PartialCompletion field] is zero (FALSE).");

            bool isDelete = this.IsFolderDeleted(subfolderId1);
            
            // Add the debug information.
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCFOLD_R225");

            // Verify MS-OXCFOLD requirement: MS-OXCFOLD_R235.
            Site.CaptureRequirementIfIsFalse(
                isDelete,
                225,
                @"[In RopEmptyFolder ROP] The RopEmptyFolder ROP ([MS-OXCROPS] section 2.2.4.9) is used to soft delete messages and subfolders from a folder without deleting the folder itself.");

            #endregion

            #endregion

            #region Step 5. Call RopCreateFolder to create [MSOXCFOLDSubfolder2] under the root folder.
            uint subfolderHandle2 = 0;
            ulong subfolderId2 = 0;
            this.CreateFolder(this.RootFolderHandle, Constants.Subfolder2, ref subfolderId2, ref subfolderHandle2);
            #endregion

            #region Step 6. Call RopCreateFolder to create [MSOXCFOLDSubfolder3] under [MSOXCFOLDSubfolder2].
            this.CreateFolder(subfolderHandle2, Constants.Subfolder3, ref subfolderId3, ref subfolderHandle3);
            #endregion

            #region Step 7. Creates a message in [MSOXCFOLDSubfolder2].
            this.CreateSaveMessage(subfolderHandle2, subfolderId2, ref messageId, ref messageHandle);
            #endregion

            #region Step 8. Creates a FAI message in [MSOXCFOLDSubfolder2].
            uint faiMessageHandle = 0;
            ulong faiMessageId = 0;
            this.CreateSaveMessage(subfolderHandle2, subfolderId2, 0x01, ref faiMessageId, ref faiMessageHandle);
            #endregion

            #region Step 9. The client calls RopEmptyFolder on [MSOXCFOLDSubfolder2] with WantDeleteAssociated set to zero (FALSE).
            object ropResponse = null;
            emptyFolderRequest.RopId = (byte)RopId.RopEmptyFolder;
            emptyFolderRequest.LogonId = Constants.CommonLogonId;
            emptyFolderRequest.InputHandleIndex = Constants.CommonInputHandleIndex;
            emptyFolderRequest.WantAsynchronous = 0x00;
            emptyFolderRequest.WantDeleteAssociated = 0x00;
            this.Adapter.DoRopCall(emptyFolderRequest, subfolderHandle2, ref ropResponse, ref this.responseHandles);
            emptyFolderResponse = (RopEmptyFolderResponse)ropResponse;

            Site.Assert.AreEqual<uint>(0, emptyFolderResponse.ReturnValue, "The RopEmptyFolder ROP operation performs successfully on [MSOXCFOLDSubfolder2].");
            Site.Assert.AreEqual<uint>(0, emptyFolderResponse.PartialCompletion, "The ROP successes for all subsets of targets, the value of PartialCompletion field is zero (FALSE).");

            bool isSubfolerRemovedWithoutWantDeleteAssociated = this.IsFolderDeleted(subfolderId3);
            bool isNormalMessageRemovedWithoutWantDeleteAssociated = this.IsMessageDeleted(messageId, subfolderId2);

            bool faiMessageDeleted = this.IsMessageDeleted(faiMessageId, subfolderId2);

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

            // Verify MS-OXCFOLD requirement: MS-OXCFOLD_R239.
            Site.CaptureRequirementIfIsFalse(
                faiMessageDeleted,
                239,
                @"[In RopEmptyFolder ROP Request Buffer] WantDeleteAssociated (1 byte): The value is zero (FALSE) otherwise [if the folder associated information (FAI) messages are not to be included in the deletion].");
            #endregion

            #region Step 10. Creates a message in [MSOXCFOLDSubfolder2].
            this.CreateSaveMessage(subfolderHandle2, subfolderId2, ref messageId, ref messageHandle);
            #endregion

            #region Step 11. Call RopCreateFolder to create [MSOXCFOLDSubfolder3] under [MSOXCFOLDSubfolder2].
            this.CreateFolder(subfolderHandle2, Constants.Subfolder3, ref subfolderId3, ref subfolderHandle3);
            #endregion

            #region Step 12. The client calls RopEmptyFolder on [MSOXCFOLDSubfolder2] with WantDeleteAssociated set to nonzero (TRUE).
            ropResponse = null;
            emptyFolderRequest.RopId = (byte)RopId.RopEmptyFolder;
            emptyFolderRequest.LogonId = Constants.CommonLogonId;
            emptyFolderRequest.InputHandleIndex = Constants.CommonInputHandleIndex;
            emptyFolderRequest.WantAsynchronous = 0x00;
            emptyFolderRequest.WantDeleteAssociated = 0x01;
            this.Adapter.DoRopCall(emptyFolderRequest, subfolderHandle2, ref ropResponse, ref this.responseHandles);
            emptyFolderResponse = (RopEmptyFolderResponse)ropResponse;
            Site.Assert.AreEqual<uint>(0, emptyFolderResponse.ReturnValue, "RopEmptyFolder ROP operation performs Successfully.");
            Site.Assert.AreEqual<uint>(0, emptyFolderResponse.PartialCompletion, "The RopEmptyFolder ROP operation performs Successfully for all subset of targets, the value of PartialCompletion field is zero (FALSE).");

            #region Verify MS-OXCFOLD_R617 and MS-OXCFOLD_238, MS-OXCFOLD_R618 and MS-OXCFOLD_R43201.

            faiMessageDeleted = this.IsMessageDeleted(faiMessageId, subfolderId2);
            bool isNormalMessageRemovedWithWantDeleteAssociated = this.IsMessageDeleted(messageId, subfolderId2);

            // Add the debug information.
            Site.Log.Add(
                LogEntryKind.Debug,
                @"Verify MS-OXCFOLD_R617: The validation result of whether the fai message is existed is {0}",
                faiMessageDeleted);

            // Verify MS-OXCFOLD requirement: MS-OXCFOLD_R617.
            Site.CaptureRequirementIfIsTrue(
                faiMessageDeleted,
                617,
                @"[In Processing a RopEmptyFolder ROP Request]If the WantDeleteAssociated field of the RopEmptyFolder ROP request buffer is set to nonzero (TRUE), as specified in section 2.2.1.9.1, then the server removes all FAI messages in addition to the normal messages.");

            // Add the debug information.
            Site.Log.Add(
                LogEntryKind.Debug,
                @"Verify MS-OXCFOLD_R238:
                The validation result of whether the normal message was deleted when the WantDeleteAssociated was not set is: {0};
                The validation result of whether the normal message was deleted when the WantDeleteAssociated was set is: {1};
                The validation result of whether the FAI message was deleted when the WantDeleteAssociated was set is: {2};",
                isNormalMessageRemovedWithoutWantDeleteAssociated,
                isNormalMessageRemovedWithWantDeleteAssociated,
                faiMessageDeleted);

            bool isVerifiedR238 = isNormalMessageRemovedWithoutWantDeleteAssociated && isNormalMessageRemovedWithWantDeleteAssociated && faiMessageDeleted;

            // Verify MS-OXCFOLD requirement: MS-OXCFOLD_R238.
            Site.CaptureRequirementIfIsTrue(
                isVerifiedR238,
                238,
                @"[In RopEmptyFolder ROP Request Buffer] WantDeleteAssociated (1 byte): A Boolean value that is nonzero (TRUE) if the folder associated information (FAI) messages are to be included in the deletion.");

            bool isSubfolerRemovedWithWantDeleteAssociated = this.IsFolderDeleted(subfolderId3);

            // Add the debug information
            Site.Log.Add(
                LogEntryKind.Debug,
                @"Verify MS-OXCFOLD_R618: The validation result of whether the subfolder was removed when the faiMessageDeleted was not set is {0}; The validation result of whether the subfolder was removed when the faiMessageDeleted was set is {1};",
                isSubfolerRemovedWithoutWantDeleteAssociated,
                isSubfolerRemovedWithWantDeleteAssociated);

            // Verify MS-OXCFOLD requirement: MS-OXCFOLD_R618.
            Site.CaptureRequirementIfIsTrue(
                isSubfolerRemovedWithoutWantDeleteAssociated && isSubfolerRemovedWithWantDeleteAssociated,
                618,
                @"[In Processing a RopEmptyFolder ROP Request]The server removes all subfolders regardless of the value of the WantDeleteAssociated field.");

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

            // Verify MS-OXCFOLD requirement: MS-OXCFOLD_R43201.
            // The RopEmptyFolder ROP operation is verified, MS-OXCFOLD_R43201 can be verified directly.
            Site.CaptureRequirement(
                43201,
                @"[In Deleting the Contents of a Folder] To delete all messages and subfolders from a folder without deleting the folder itself, the client sends either a RopEmptyFolder ROP request ([MS-OXCROPS] section 2.2.4.9) [or a RopHardDeleteMessagesAndSubfolders ROP request ([MS-OXCROPS] section 2.2.4.10)].");
            #endregion
            #endregion
        }
        public void MSOXCFOLD_S02_TC07_RopEmptyFolderFailure()
        {
            this.CheckWhetherSupportTransport();
            this.Adapter.DoConnect(ConnectionType.PrivateMailboxServer);
            this.GenericFolderInitialization();

            #region Step 1. Calls RopEmptyfolder using a logon handle rather than a folder handle.
            RopEmptyFolderRequest emptyFolderRequest = new RopEmptyFolderRequest
            {
                RopId = (byte)RopId.RopEmptyFolder,
                LogonId = Constants.CommonLogonId,
                InputHandleIndex = Constants.CommonInputHandleIndex,
                WantAsynchronous = 0x00,
                WantDeleteAssociated = 0xFF
            };

            // Using a logon object handle to refer a logon object in which case is purposed to test error code ecNotSupported [0x80040102].  
            RopEmptyFolderResponse emptyFolderResponse = this.Adapter.EmptyFolder(emptyFolderRequest, this.LogonHandle, ref this.responseHandles);

            #region Verify MS-OXCFOLD_R624 and MS-OXCFOLD_R625.

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

            // Verify MS-OXCFOLD requirement: MS-OXCFOLD_R624.
            Site.CaptureRequirementIfAreEqual<uint>(
                0x80040102,
                emptyFolderResponse.ReturnValue,
                624,
                @"[In Processing a RopEmptyFolder ROP Request]The value of error code ecNotSupported is 0x80040102.");

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

            // The MS-OXCFOLD_R624 captured error code [ecNotSupported], capture this requirement directly.
            Site.CaptureRequirement(
                625,
                @"[In Processing a RopEmptyFolder ROP Request] When the error code is ecNotSupported, it indicates that the object that this ROP [RopEmptyFolder ROP] was called on is not a Folder object.");
            #endregion

            #endregion

            #region Step 2. The client calls RopCreateFolder to create the search folder [MSOXCFOLDSearchFolder1] under the root folder.
            RopCreateFolderRequest createFolderRequest = new RopCreateFolderRequest
            {
                RopId = (byte)RopId.RopCreateFolder,
                LogonId = Constants.CommonLogonId,
                InputHandleIndex = Constants.CommonInputHandleIndex,
                OutputHandleIndex = Constants.CommonOutputHandleIndex,
                FolderType = (byte)FolderType.Searchfolder,
                DisplayName = Encoding.ASCII.GetBytes(Constants.SearchFolder),
                Comment = Encoding.ASCII.GetBytes(Constants.SearchFolder)
            };
            RopCreateFolderResponse createFolderResponse = this.Adapter.CreateFolder(createFolderRequest, this.RootFolderHandle, ref this.responseHandles);
            Site.Assert.AreEqual<uint>(Constants.SuccessCode, createFolderResponse.ReturnValue, "RopCreateFolder ROP operation performs successfully!");
            uint searchFolderHandle1 = this.responseHandles[0][createFolderResponse.OutputHandleIndex];
            #endregion

            #region Step 3. The client calls RopEmptyFolder on the search folder created in step 2.
            emptyFolderResponse = this.Adapter.EmptyFolder(emptyFolderRequest, searchFolderHandle1, ref this.responseHandles);

            if (Common.IsRequirementEnabled(124901, this.Site))
            {
                // Add the debug information.
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCFOLD_R124901");

                // Verify MS-OXCFOLD requirement: MS-OXCFOLD_R124901.
                // If the client attempt to empty a search folder, the server will return ecNotSupported in the ReturnValue.
                Site.CaptureRequirementIfAreEqual<uint>(
                    0x80040102,
                    emptyFolderResponse.ReturnValue,
                    124901,
                    @"[In Appendix A: Product Behavior] Implementation does return ecNotSupported (0x80040102) in the ReturnValue field of the RopEmptyFolder ROP response buffer, if the client attempts to empty a search folder. (Exchange 2007 and above follow this behavior.)");

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

                // Verify MS-OXCFOLD requirement: MS-OXCFOLD_R3012.
                // If the client attempt to empty a search folder, the server will return ecNotSupported in the ReturnValue.
                // Because the error code 0x80040102 has been captured by R124901, so R3012 can be captured directly. 
                Site.CaptureRequirement(
                    3012,
                    @"[In Processing a RopEmptyFolder ROP Request] When the error code is ecNotSupported, it indicates that a folder that this ROP [RopEmptyFolder ROP] was called on is not allowed to be emptied.");
            }
            #endregion

            #region Step 4. The client calls RopOpenFolder to open the root folder.
            uint rootFolderHandle = 0;
            this.OpenFolder(this.LogonHandle, this.DefaultFolderIds[0], ref rootFolderHandle); 
            #endregion

            #region Step 5. The client calls RopEmptyFolder on the root folder.
            emptyFolderResponse = this.Adapter.EmptyFolder(emptyFolderRequest, rootFolderHandle, ref this.responseHandles);

            if (Common.IsRequirementEnabled(124801, this.Site))
            {
                // Add the debug information
                this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCFOLD_R124801");

                // Verify MS-OXCFOLD requirement: MS-OXCFOLD_R124801
                this.Site.CaptureRequirementIfAreNotEqual<uint>(
                    0x80040102,
                    emptyFolderResponse.ReturnValue,
                    124801,
                    @"[In Appendix A: Product Behavior] Implementation does not return ecNotSupported when the RopEmptyFolder ROP is called on the Root folder. <18> Section 3.2.5.9: Exchange 2007 do not return ecNotSupported (0x80040102) when the RopEmptyFolder ROP ([MS-OXCROPS] section 2.2.4.9) is called on the Root folder.");
            }

            if (Common.IsRequirementEnabled(124802, this.Site))
            {
                // Add the debug information
                this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCFOLD_R124802");

                // Verify MS-OXCFOLD requirement: MS-OXCFOLD_R124802
                this.Site.CaptureRequirementIfAreEqual<uint>(
                    0x80040102,
                    emptyFolderResponse.ReturnValue,
                    124802,
                    @"[In Appendix A: Product Behavior] Implementation does return ecNotSupported when the RopEmptyFolder ROP is called on the Root folder. <18> Section 3.2.5.9: Update Rollup 4 for Exchange Server 2010 Service Pack 2 (SP2), Exchange 2013 and Exchange 2016 return ecNotSupported when the RopEmptyFolder ROP is called on the Root folder.");
            }
            #endregion
        }
        /// <summary>
        /// Soft deletes all messages and subfolders from a folder without deleting the folder itself. 
        /// </summary>
        /// <param name="ropEmptyFolderRequest">RopEmptyFolderRequest object.</param>
        /// <param name="insideObjHandle">Server object handle in EmptyFolderRequest.</param>
        /// <param name="responseSOHTable">Server objects handles in RopEmptyFolderResponse.</param>
        /// <returns>RopEmptyFolderResponse object.</returns>
        public RopEmptyFolderResponse EmptyFolder(RopEmptyFolderRequest ropEmptyFolderRequest, uint insideObjHandle, ref List<List<uint>> responseSOHTable)
        {
            object temp = new object();
            this.ExcuteRopCall((ISerializable)ropEmptyFolderRequest, insideObjHandle, ref temp, ref responseSOHTable, ref this.rawData);
            RopEmptyFolderResponse ropEmptyFolderResponse = (RopEmptyFolderResponse)temp;

            #region Capture Code
            // The ReturnValue equal to 0x00000000 indicate ROP operation success
            if (0x00000000 == ropEmptyFolderResponse.ReturnValue)
            {
                this.VerifyRopEmptyFolder(ropEmptyFolderResponse);
            }
            #endregion

            return ropEmptyFolderResponse;
        }