Microsoft.Protocols.TestSuites.MS_OXCROPS.S02_FolderROPs.MSOXCROPS_S02_TC03_TestRopGetSearchCriteria C# (CSharp) Method

MSOXCROPS_S02_TC03_TestRopGetSearchCriteria() private method

private MSOXCROPS_S02_TC03_TestRopGetSearchCriteria ( ) : void
return void
        public void MSOXCROPS_S02_TC03_TestRopGetSearchCriteria()
        {
            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));

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

            // Step 1: Open a folder.
            #region Open folder

            RopOpenFolderRequest openFolderRequest;
            RopOpenFolderResponse openFolderResponse;

            openFolderRequest.RopId = (byte)RopId.RopOpenFolder;

            openFolderRequest.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.
            openFolderRequest.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.
            openFolderRequest.OutputHandleIndex = TestSuiteBase.OutputHandleIndex1;

            // Set FolderId to the 5th of logonResponse. This folder is to be opened.
            openFolderRequest.FolderId = logonResponse.FolderIds[4];

            openFolderRequest.OpenModeFlags = (byte)FolderOpenModeFlags.None;

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

            // Send the RopOpenFolder request to the server.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                openFolderRequest,
                this.inputObjHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            openFolderResponse = (RopOpenFolderResponse)response;
            uint folderHandler = responseSOHs[0][openFolderResponse.OutputHandleIndex];

            #endregion

            // Step 2: Create a search folder.
            #region Create folder

            RopCreateFolderRequest createFolderRequest;
            RopCreateFolderResponse createFolderResponse;

            createFolderRequest.RopId = (byte)RopId.RopCreateFolder;
            createFolderRequest.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.
            createFolderRequest.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.
            createFolderRequest.OutputHandleIndex = TestSuiteBase.OutputHandleIndex1;

            createFolderRequest.FolderType = (byte)FolderType.Searchfolder;

            // Set UseUnicodeStrings to 0x0(FALSE), which specifies the DisplayName field and the Comment field
            // does not contain Unicode characters or multi-byte characters.
            createFolderRequest.UseUnicodeStrings = Convert.ToByte(TestSuiteBase.Zero);

            // Set OpenExisting to 0xFF(TRUE), which means the folder to be created will be opened when it is already existed.
            createFolderRequest.OpenExisting = TestSuiteBase.NonZero;

            // Set Reserved to 0x0. This field is reserved and MUST be set to 0x00.
            createFolderRequest.Reserved = TestSuiteBase.Reserved;

            // Set DisplayName, which specifies the name of the created folder.
            createFolderRequest.DisplayName = Encoding.ASCII.GetBytes(TestSuiteBase.DisplayNameAndCommentForSearchFolder + "\0");

            // Set Comment, which specifies the folder comment that is associated with the created folder.
            createFolderRequest.Comment = Encoding.ASCII.GetBytes(TestSuiteBase.DisplayNameAndCommentForSearchFolder + "\0");

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

            // Send RopCreateFolder request to the server and verify the response.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                createFolderRequest,
                folderHandler,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            createFolderResponse = (RopCreateFolderResponse)response;
            Site.Assert.AreEqual<uint>(
                TestSuiteBase.SuccessReturnValue,
                createFolderResponse.ReturnValue,
                "If ROP succeeds, the ReturnValue of its response is 0(success)");
            uint searchFolderHandler = responseSOHs[0][createFolderResponse.OutputHandleIndex];

            #endregion

            // Step 3: Send a RopSetSearchCriteria request to the server and verify the response.
            #region RopSetSearchCriteria Response

            RopSetSearchCriteriaRequest setSearchCriteriaRequest;
            RopSetSearchCriteriaResponse setSearchCriteriaResponse;

            setSearchCriteriaRequest.RopId = (byte)RopId.RopSetSearchCriteria;
            setSearchCriteriaRequest.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.
            setSearchCriteriaRequest.InputHandleIndex = TestSuiteBase.InputHandleIndex0;

            // Set RestrictionDataSize to 0x0005, which specifies the length of the RestrictionData field.
            setSearchCriteriaRequest.RestrictionDataSize = TestSuiteBase.RestrictionDataSize1;

            byte[] restrictionData = new byte[5];
            ushort pidTagMessageClassID = this.propertyDictionary[PropertyNames.PidTagMessageClass].PropertyId;
            ushort typeOfPidTagMessageClass = this.propertyDictionary[PropertyNames.PidTagMessageClass].PropertyType;
            restrictionData[0] = (byte)Restrictions.ExistRestriction;
            Array.Copy(BitConverter.GetBytes(typeOfPidTagMessageClass), 0, restrictionData, 1, sizeof(ushort));
            Array.Copy(BitConverter.GetBytes(pidTagMessageClassID), 0, restrictionData, 3, sizeof(ushort));
            setSearchCriteriaRequest.RestrictionData = restrictionData;

            ulong[] tempFolderIds = new ulong[1];
            tempFolderIds[0] = logonResponse.FolderIds[4];

            // Set FolderIdCount to the length of FolderIds, which specifies the number of IDs in the FolderIds field.
            setSearchCriteriaRequest.FolderIdCount = (ushort)tempFolderIds.Length;

            // Set FolderIds to that of logonResponse, which contains identifiers that specify which folders are searched. 
            setSearchCriteriaRequest.FolderIds = tempFolderIds;

            setSearchCriteriaRequest.SearchFlags = (uint)SetSearchFlags.RestartSearch;

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

            // Send RopSetSearchCriteria request to the server and verify the response.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                setSearchCriteriaRequest,
                searchFolderHandler,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            setSearchCriteriaResponse = (RopSetSearchCriteriaResponse)response;
            Site.Assert.AreEqual<uint>(
                TestSuiteBase.SuccessReturnValue,
                setSearchCriteriaResponse.ReturnValue,
                "If ROP succeeds, the ReturnValue of its response is 0(success)");

            #endregion

            // Step 4: Send a RopGetSearchCriteria request to the server and verify the response.
            #region RopGetSearchCriteria Success Response

            RopGetSearchCriteriaRequest getSearchCriteriaRequest;
            RopGetSearchCriteriaResponse getSearchCriteriaResponse;

            getSearchCriteriaRequest.RopId = (byte)RopId.RopGetSearchCriteria;
            getSearchCriteriaRequest.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.
            getSearchCriteriaRequest.InputHandleIndex = TestSuiteBase.InputHandleIndex0;

            // Set UseUnicodeStrings to 0x0(FALSE), which specifies the DisplayName and Comment are not specified in Unicode.
            getSearchCriteriaRequest.UseUnicode = Convert.ToByte(TestSuiteBase.Zero);

            // Set IncludeRestriction to 0x00(FALSE), which specifies restriction data is NOT required in the response.
            getSearchCriteriaRequest.IncludeRestriction = Convert.ToByte(TestSuiteBase.Zero);

            // Set IncludeFolders to 0xFF(TRUE), which specifies the folders list is required in the response.
            getSearchCriteriaRequest.IncludeFolders = TestSuiteBase.NonZero;

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

            // Send a RopGetSearchCriteria request to the server and verify the success response.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                getSearchCriteriaRequest,
                searchFolderHandler,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            getSearchCriteriaResponse = (RopGetSearchCriteriaResponse)response;
            Site.Assert.AreEqual<uint>(
                TestSuiteBase.SuccessReturnValue,
                getSearchCriteriaResponse.ReturnValue,
                "If ROP succeeds, the ReturnValue of its response is 0(success)");

            #endregion

            // Step 5: Send a RopGetSearchCriteria request to the server and verify the failure response.
            #region RopGetSearchCriteria Failure Response

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

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

            // Send a RopGetSearchCriteria request to the server and verify the failure response.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                getSearchCriteriaRequest,
                searchFolderHandler,
                ref this.response,
                ref this.rawData,
                RopResponseType.FailureResponse);
            getSearchCriteriaResponse = (RopGetSearchCriteriaResponse)response;
            Site.Assert.AreNotEqual<uint>(
                TestSuiteBase.SuccessReturnValue,
                getSearchCriteriaResponse.ReturnValue,
                "If ROP fails, the ReturnValue of its response is set to a value other than 0x00000000(failure)");

            #endregion

            // Step 6: Release all resources associated with the Server object.
            #region RopRelease

            RopReleaseRequest releaseRequest;

            releaseRequest.RopId = (byte)RopId.RopRelease;
            releaseRequest.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.
            releaseRequest.InputHandleIndex = TestSuiteBase.InputHandleIndex0;

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

            // Send a RopRelease request to release all resources associated with the Server object.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                releaseRequest,
                this.inputObjHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);

            #endregion
        }