Microsoft.Protocols.TestSuites.SharedAdapter.MsfsshttpAdapterCapture.ValidateSubResponseToken C# (CSharp) Method

ValidateSubResponseToken() public static method

Capture requirements related with SubRequestToken within SubResponse element
public static ValidateSubResponseToken ( ITestSite site ) : void
site ITestSite Instance of ITestSite
return void
        public static void ValidateSubResponseToken(ITestSite site)
        {
            // All there requirements can be directly captured when the code runs here successfully.
            // Verify MS-FSSHTTP requirement: MS-FSSHTTP_R143
            // If the SubRequestToken values in Request element equals the values in Response element, then capture MS-FSSHTTP_R143.
            site.CaptureRequirement(
                     "MS-FSSHTTP",
                     143,
                     @"[In SubResponse] Within a Response element for each SubRequest element that is in a Request element of a cell storage service request message, there MUST be a corresponding SubResponse element.");

            // Verify MS-FSSHTTP requirement: MS-FSSHTTP_R930
            // If the protocol server returns subResponse for each subRequest, then capture MS-FSSHTTP_R930.
            site.CaptureRequirement(
                     "MS-FSSHTTP",
                     930,
                     @"[In Common Message Processing Rules and Events][The protocol server MUST follow the following common processing rules for all types of subrequests] and [The protocol server sends] a SubResponse element corresponding to each SubRequest element contained within a Request element.");
        }

Usage Example

        /// <summary>
        /// This method is used to validate the sub response according to the current record sub request token and sub request type.
        /// </summary>
        /// <param name="rawResponse">Specify the raw XML string response returned by the protocol server.</param>
        /// <param name="site">An object provides logging, assertions, and SUT adapters for test code onto its execution context.</param>
        public void Validate(string rawResponse, ITestSite site)
        {
            // Extract the sub response whose token equals the SubToken value.
            XmlDocument subResponseDocument = this.ExtractSubResponseNode(rawResponse);

            // De-serialize the sub response to instance
            object subResponse = this.SerializeSubResponse(subResponseDocument, site);

            // Try to parse the MS-FSSHTTPB structure
            if (subResponse is CellSubResponseType)
            {
                // If the sub request type is CellSubRequestType, then indicating that there is one MS-FSSHTTPB response embedded. Try parse this an capture all the related requirements.
                CellSubResponseType cellSubResponse = subResponse as CellSubResponseType;
                if (cellSubResponse.SubResponseData != null && cellSubResponse.SubResponseData.Text.Length == 1)
                {
                    string           subResponseBase64 = cellSubResponse.SubResponseData.Text[0];
                    byte[]           subResponseBinary = Convert.FromBase64String(subResponseBase64);
                    FsshttpbResponse fsshttpbResponse  = FsshttpbResponse.DeserializeResponseFromByteArray(subResponseBinary, 0);

                    if (fsshttpbResponse.DataElementPackage != null && fsshttpbResponse.DataElementPackage.DataElements != null)
                    {
                        // If the response data elements is complete, then try to verify the requirements related in the MS-FSSHTPD
                        foreach (DataElement storageIndex in fsshttpbResponse.DataElementPackage.DataElements.Where(dataElement => dataElement.DataElementType == DataElementType.StorageIndexDataElementData))
                        {
                            // Just build the root node to try to parse the signature related requirements, no need to restore the result.
                            new RootNodeObject.RootNodeObjectBuilder().Build(
                                fsshttpbResponse.DataElementPackage.DataElements,
                                storageIndex.DataElementExtendedGUID);
                        }
                    }

                    if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
                    {
                        new MsfsshttpbAdapterCapture().VerifyTransport(site);

                        // Capture the response related requirements
                        new MsfsshttpbAdapterCapture().VerifyFsshttpbResponse(fsshttpbResponse, site);
                    }
                }
            }

            // Validating the fragment of the sub response
            // Record the validation errors and warnings.
            ValidationResult result = SchemaValidation.ValidateXml(subResponseDocument.OuterXml);

            if (!SharedContext.Current.IsMsFsshttpRequirementsCaptured)
            {
                if (result != ValidationResult.Success)
                {
                    // Add error log
                    site.Assert.Fail("Schema validation fails, the reason is " + SchemaValidation.GenerateValidationResult());
                }

                // No need to run the capture code, just return.
                return;
            }

            if (result == ValidationResult.Success)
            {
                // Capture the requirement related to the sub response token.
                MsfsshttpAdapterCapture.ValidateSubResponseToken(site);

                // Call corresponding sub response capture code.
                this.InvokeCaptureCode(subResponse, site);
            }
            else
            {
                // Add error log
                site.Assert.Fail("Schema validation fails, the reason is " + SchemaValidation.GenerateValidationResult());
            }
        }