Microsoft.Protocols.TestSuites.MS_OXCROPS.S03_TableROPs.MSOXCROPS_S03_TC06_TestCollapseAndExpandRow C# (CSharp) Method

MSOXCROPS_S03_TC06_TestCollapseAndExpandRow() private method

private MSOXCROPS_S03_TC06_TestCollapseAndExpandRow ( ) : void
return void
        public void MSOXCROPS_S03_TC06_TestCollapseAndExpandRow()
        {
            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: Prepare Table object, which will be used in the following ROPs.
            #region PrepareTable

            ulong folderID;

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Step 1: Begin to call CreateFolder method to open a folder and create a subfolder.");

            // Call CreateFolder method to open a folder and create a subfolder.
            uint folderHandle = this.CreateFolder(out folderID);

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Step 1: Begin to call GetContentsTableHandle method to Get ContentsTable Handle.");

            // Call GetContentsTableHandle method to get contents table handle.
            uint tableHandle = GetContentsTableHandle(folderHandle);

            // Preparing the table: RopCreateAndSaveMessages
            for (int i = 0; i < 5; i++)
            {
                this.CreateAndSaveMessage(folderID);
            }

            #region RopSetColumns

            RopSetColumnsRequest setColumnsRequest;
            RopSetColumnsResponse setColumnsResponse;

            PropertyTag[] propertyTags = CreateSampleContentsTablePropertyTags();
            setColumnsRequest.RopId = (byte)RopId.RopSetColumns;
            
            setColumnsRequest.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.
            setColumnsRequest.InputHandleIndex = TestSuiteBase.InputHandleIndex0;

            setColumnsRequest.SetColumnsFlags = (byte)AsynchronousFlags.None;
            setColumnsRequest.PropertyTagCount = (ushort)propertyTags.Length;
            setColumnsRequest.PropertyTags = propertyTags;

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

            // Send the RopSetColumns request to the server and verify the success response.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                setColumnsRequest,
                tableHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            setColumnsResponse = (RopSetColumnsResponse)response;

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

            #endregion

            #endregion

            // Step 2: Send the RopFindRows request to the server and verify the success response.
            #region RopFindRows success response with the field Origin value is Beginning

            RopFindRowRequest findRowRequest;
            RopFindRowResponse findRowResponse;

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

            findRowRequest.FindRowFlags = (byte)FindRowFlags.Forwards;

            // Set RestrictionDataSize, which specifies the length of the RestrictionData field.
            findRowRequest.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));
            findRowRequest.RestrictionData = restrictionData;
            findRowRequest.Origin = (byte)Origin.Beginning;

            // Set BookmarkSize, which specifies the size of the Bookmark field.
            findRowRequest.BookmarkSize = TestSuiteBase.BookmarkSize;

            // Set Bookmark, which specifies the bookmark to use as the origin.
            findRowRequest.Bookmark = null;

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

            // Send the RopFindRows request to the server and verify the success response.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                findRowRequest,
                tableHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            findRowResponse = (RopFindRowResponse)response;

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

            #endregion

            #region RopFindRows success response with the field Origin value is Current

            findRowRequest.Origin = (byte)Origin.Current;

            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                findRowRequest,
                tableHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            findRowResponse = (RopFindRowResponse)response;

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

            #endregion

            #region RopFindRows success response with the field Origin value is End

            findRowRequest.FindRowFlags = (byte)FindRowFlags.Backwards;
            findRowRequest.Origin = (byte)Origin.End;

            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                findRowRequest,
                tableHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            findRowResponse = (RopFindRowResponse)response;

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

            if (findRowResponse.HasRowData != 0)
            {
                // Add the debug information
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCROPS_R1484");

                // Verify MS-OXCROPS requirement: MS-OXCROPS_R1484
                // RowData is not null means present.
                Site.CaptureRequirementIfIsNotNull(
                    findRowResponse.RowData,
                    1484,
                    @"[In RopFindRow ROP Success Response Buffer] RowData (variable): This field is present only when the HasRowData field is set to a nonzero value.");
            }

            #endregion

            // Step 3: Send the RopFindRows request to the server and verify the failure response.
            #region RopFindRows failure response

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

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

            // Send the RopFindRows request to the server and verify the failure response.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                findRowRequest,
                tableHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.FailureResponse);
            findRowResponse = (RopFindRowResponse)response;

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

            #endregion

            // Step 4: Send the RopSortTable request to the server and verify the success response.
            #region RopSortTable

            RopSortTableRequest sortTableRequest;

            // Call CreateSampleSortOrders method to Create Sample SortOrders.
            SortOrder[] sortOrders = this.CreateSampleSortOrders();

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

            sortTableRequest.SortTableFlags = (byte)AsynchronousFlags.None;
            sortTableRequest.SortOrderCount = (ushort)sortOrders.Length;
            sortTableRequest.CategoryCount = (ushort)(sortOrders.Length - 1);
            sortTableRequest.ExpandedCount = sortTableRequest.CategoryCount;
            sortTableRequest.SortOrders = sortOrders;

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

            // Send the RopSortTable request to the server and verify the success response.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                sortTableRequest,
                tableHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            RopSortTableResponse sortTableResponse = (RopSortTableResponse)response;

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

            #endregion

            // Step 5: Send the RopQueryRows request to the server and verify the success response.
            #region RopQueryRows: send RopSetColumns and RopQueryRows in a request buffer

            RopQueryRowsRequest queryRowsRequest;
            RopQueryRowsResponse queryRowsResponse;

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

            queryRowsRequest.QueryRowsFlags = (byte)QueryRowsFlags.Advance;

            // Set ForwardRead to 0xff(TRUE), which specifies the direction to read rows (forwards).
            queryRowsRequest.ForwardRead = TestSuiteBase.NonZero;

            // Set RowCount to 0x0032, which the number of requested rows.
            queryRowsRequest.RowCount = TestSuiteBase.RowCount;

            List<ISerializable> ropRequests = new List<ISerializable>
            {
                setColumnsRequest, queryRowsRequest
            };
            List<uint> inputObjects = new List<uint>
            {
                tableHandle
            };
            List<IDeserializable> ropResponses = new List<IDeserializable>();

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Step 5: Begin to send the requests, including RopQueryRows and RopSetColumns requests.");

            // Send RopQueryRows and RopSetColumns requests and verify the success response.
            this.responseSOHs = cropsAdapter.ProcessMutipleRops(
                ropRequests,
                inputObjects,
                ref ropResponses,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            queryRowsResponse = (RopQueryRowsResponse)ropResponses[1];

            #endregion

            #region GetCategoryId

            byte[] pidTagInstValue = queryRowsResponse.RowData.PropertyRows[0].PropertyValues[2].Value;
            ulong index = 1;
            ulong categoryId = 0;

            foreach (byte a in pidTagInstValue)
            {
                categoryId += (ulong)a * index;
                index *= 0x100;
            }

            #endregion

            // Step 6: Send the RopCollapseRow request to the server and verify the success response.
            #region RopCollapseRow success response

            RopCollapseRowRequest collapseRowRequest;
            RopCollapseRowResponse collapseRowResponse;

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

            // Set CategoryId, which specifies the category to be collapsed.
            collapseRowRequest.CategoryId = categoryId;

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

            // Send the RopCollapseRow request to the server and verify the success response.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                collapseRowRequest,
                tableHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            collapseRowResponse = (RopCollapseRowResponse)response;

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

            #endregion

            // Step 7: Send the RopCollapseRow request to the server and verify the failure response.
            #region RopCollapseRow failure response

            // Set CategoryId to 0x00, which cannot be found and will lead to a failure response.
            collapseRowRequest.CategoryId = TestSuiteBase.WrongCategoryId;

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

            // Send the RopCollapseRow request to the server and verify the failure response.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                collapseRowRequest,
                tableHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.FailureResponse);
            collapseRowResponse = (RopCollapseRowResponse)response;

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

            #endregion

            // Step 8: Send the RopExpandRows request to the server and verify the success response.
            #region RopExpandRows success response: send RopSetColumns and RopExpandRows in a request buffer

            RopExpandRowRequest expandRowRequest;
            RopExpandRowResponse expandRowResponse;

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

            // Set MaxRowCount, which specifies the maximum number of expanded rows to return data for.
            expandRowRequest.MaxRowCount = TestSuiteBase.MaxRowCount;

            expandRowRequest.CategoryId = categoryId;
            ropRequests = new List<ISerializable>
            {
                setColumnsRequest, expandRowRequest
            };

            inputObjects = new List<uint>
            {
                tableHandle
            };
            ropResponses = new List<IDeserializable>();

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Step 8: Begin to send the requests, including RopSetColumns and RopExpandRows requests.");

            // Refer to MS-OXCTABL endnote<15>: Exchange 2013 does not support a value greater than 0 for the MaxRowCount field.
            if (Common.IsRequirementEnabled(74801, this.Site))
            {
                // Send the RopSetColumns and RopExpandRows request and verify the success response of RopExpandRows.
                this.responseSOHs = cropsAdapter.ProcessMutipleRops(
                    ropRequests,
                    inputObjects,
                    ref ropResponses,
                    ref this.rawData,
                RopResponseType.SuccessResponse);
                expandRowResponse = (RopExpandRowResponse)ropResponses[1];

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

                // Verify MS-OXCROPS requirement: MS-OXCROPS_R74801
                Site.CaptureRequirementIfAreEqual<uint>(
                    TestSuiteBase.SuccessReturnValue,
                    expandRowResponse.ReturnValue,
                    74801,
                    @"[In Appendix A: Product Behavior] For RopExpandRow, implementation does support a value greater than 0 for the MaxRowCount field. (Exchange 2007 and Exchange 2010 follow this behavior.)");

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

            #endregion

            // Step 9: Send the RopExpandRows request to the server and verify the failure response.
            #region RopExpandRows failure response

            // Set CategoryId to 0x00, which cannot be found and will lead to a failure response.
            expandRowRequest.CategoryId = TestSuiteBase.WrongCategoryId;

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

            // Send the RopExpandRows request to the server and verify the failure response.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                expandRowRequest,
                tableHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.FailureResponse);
            expandRowResponse = (RopExpandRowResponse)response;

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

            #endregion

            // Step 10: Send the RopGetCollapseState request to the server and verify the failure response.
            #region RopGetCollapseState failure response

            RopGetCollapseStateRequest getCollapseStateRequest;
            RopGetCollapseStateResponse getCollapseStateResponse;

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

            // Set RowId, which specifies the row to be preserved as the cursor.
            getCollapseStateRequest.RowId = categoryId;

            // Set RowInstanceNumber, which specifies the instance number of the row that is to be preserved as the cursor.
            getCollapseStateRequest.RowInstanceNumber = TestSuiteBase.RowInstanceNumber;

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

            // Send the RopGetCollapseState request to the server and verify the failure response.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                getCollapseStateRequest,
                this.inputObjHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.FailureResponse);
            getCollapseStateResponse = (RopGetCollapseStateResponse)response;

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

            #endregion

            // Step 11: Send the RopGetCollapseState request to the server and verify the success response.
            #region RopGetCollapseState success response

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

            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                getCollapseStateRequest,
                tableHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            getCollapseStateResponse = (RopGetCollapseStateResponse)response;

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

            #endregion

            // Step 12: Send the RopSetCollapseState request to the server and verify the success response.
            #region RopSetCollapseState success response

            RopSetCollapseStateRequest setCollapseStateRequest;
            RopSetCollapseStateResponse setCollapseStateResponse;

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

            // Set CollapseStateSize, which specifies the size of the CollapseState field.
            setCollapseStateRequest.CollapseStateSize = getCollapseStateResponse.CollapseStateSize;

            // Set CollapseState, which specifies a collapse state for a categorized table.
            setCollapseStateRequest.CollapseState = (byte[])getCollapseStateResponse.CollapseState;

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

            // Send the RopSetCollapseState request to the server and verify the success response.
            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                setCollapseStateRequest,
                tableHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.SuccessResponse);
            setCollapseStateResponse = (RopSetCollapseStateResponse)response;

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

            #endregion

            // Step 13: Send the RopSetCollapseState request to the server and verify the failure response.
            #region RopSetCollapseState failure response

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

            this.responseSOHs = cropsAdapter.ProcessSingleRop(
                setCollapseStateRequest,
                this.inputObjHandle,
                ref this.response,
                ref this.rawData,
                RopResponseType.FailureResponse);
            setCollapseStateResponse = (RopSetCollapseStateResponse)response;

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

            #endregion
        }