Microsoft.Protocols.TestSuites.MS_ASCON.TestSuiteHelper.TruncateData C# (CSharp) Method

TruncateData() static private method

Truncate data according to the specified length.
static private TruncateData ( string originalData, int length ) : string
originalData string The original data.
length int The length of the byte array.
return string
        internal static string TruncateData(string originalData, int length)
        {
            byte[] bytes = System.Text.Encoding.ASCII.GetBytes(originalData);
            byte[] truncatedBytes = new byte[length];
            for (int i = 0; i < length; i++)
            {
                truncatedBytes[i] = bytes[i];
            }

            return System.Text.Encoding.ASCII.GetString(truncatedBytes);
        }

Usage Example

        /// <summary>
        /// Verify the message part when the request contains only BodyPartPreference element.
        /// </summary>
        /// <param name="email">The email item server returned.</param>
        /// <param name="truncatedData">The truncated email data returned in BodyPart.</param>
        /// <param name="allData">All email data without being truncated.</param>
        /// <param name="truncationSize">The TruncationSize element specified in BodyPartPreference.</param>
        protected void VerifyMessagePartWithBodyPartPreference(Email email, string truncatedData, string allData, int truncationSize)
        {
            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCON_R239");

            // Verify MS-ASCON requirement: MS-ASCON_R239
            bool isVerifiedR239 = email.BodyPart.TruncatedSpecified && email.BodyPart.Truncated &&
                                  truncatedData == TestSuiteHelper.TruncateData(allData, truncationSize);

            Site.CaptureRequirementIfIsTrue(
                isVerifiedR239,
                239,
                @"[In Sending a Message Part] The client's preferences affect the server response as follows: If the size of the message part exceeds the value specified in the airsyncbase:TruncationSize element ([MS-ASAIRS] section 2.2.2.40.1) of the request, then the server truncates the message part.");

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

            // Verify MS-ASCON requirement: MS-ASCON_R240
            bool isVerifiedR240 = email.BodyPart.TruncatedSpecified && email.BodyPart.Truncated && email.BodyPart.EstimatedDataSize > 0;

            Site.CaptureRequirementIfIsTrue(
                isVerifiedR240,
                240,
                @"[In Sending a Message Part] The server includes the airsyncbase:Truncated element ([MS-ASAIRS] section 2.2.2.39.1) and the airsyncbase:EstimatedDataSize element ([MS-ASAIRS] section 2.2.2.23.2) in the response when it truncates the message part.");

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

            // Verify MS-ASCON requirement: MS-ASCON_R247
            bool isVerifiedR247 = email.Body == null && email.BodyPart != null;

            Site.CaptureRequirementIfIsTrue(
                isVerifiedR247,
                247,
                @"[In Sending a Message Part] If request contains only airsyncbase:BodyPartPreference element, then the response contains only airsyncbase:BodyPart element.");
        }