/// <summary>
        /// A method used to verify whether all copy results are successful. If there is any non-success copy result, it raise an exception.
        /// </summary>
        /// <param name="copyResults">A parameter represents the copy results collection.</param>
        /// <param name="raiseAssertEx">A parameter indicates the method whether raise an assert exception, if not all the copy result are successful. The 'true' means raise an exception.</param>
        /// <returns>Return 'true' indicating all copy results are success, otherwise return 'false'. If the "raiseAssertEx" is set to true, the method will raise a exception instead of returning 'false'.</returns>
        protected bool VerifyAllCopyResultsSuccess(CopyResult[] copyResults, bool raiseAssertEx = true)
        {
           if (null == copyResults)
           {
               throw new ArgumentNullException("copyResults");
           }

           if (0 == copyResults.Length)
           {
               throw new ArgumentException("The copy results collection should contain at least one item", "copyResults");
           }

           var notSuccessResultItem = from resultItem in copyResults
                                     where CopyErrorCode.Success != resultItem.ErrorCode
                                     select resultItem;

           bool verifyResult = false;
           if (notSuccessResultItem.Count() > 0)
           {
               StringBuilder strBuilderOfErrorResult = new StringBuilder();
               foreach (CopyResult resultItem in notSuccessResultItem)
               {   
                   string errorMsgItem = string.Format(
                               "ErrorCode:[{0}]\r\nErrorMessage:[{1}]\r\nDestinationUrl:[{2}]",
                               resultItem.ErrorCode,
                               string.IsNullOrEmpty(resultItem.ErrorMessage) ? "None" : resultItem.ErrorMessage,
                               resultItem.DestinationUrl);

                   strBuilderOfErrorResult.AppendLine(errorMsgItem);
                   strBuilderOfErrorResult.AppendLine("===========");
               }

               this.Site.Log.Add(
                               LogEntryKind.Debug,
                               "Total non-successful copy results:[{0}]\r\n{1}",
                               notSuccessResultItem.Count(),
                               strBuilderOfErrorResult.ToString());

               if (raiseAssertEx)
               {
                  this.Site.Assert.Fail("Not all copy result are successful.");
               }
           }
           else
           {
               verifyResult = true;
           }

           return verifyResult;
        }
예제 #2
0
        /// <summary>
        /// A method used to verify the CopyResultCollection type.
        /// </summary>
        /// <param name="copyResultCollection">A parameter represents the CopyResultCollection type instance which will be validated.</param>
        /// <param name="destinationUrlsInRequest">A parameter represents the destination URL items which is used to test destination URL mappings.</param>
        private void VerifyCopyResultCollection(CopyResult[] copyResultCollection, string[] destinationUrlsInRequest)
        {
            if (null == copyResultCollection || 0 == copyResultCollection.Length)
            {
                return;
            }

            // if the CopyResult is not null, then capture R59
            this.Site.CaptureRequirement(
                                        59,
                                        @"[In CopyResultCollection] CopyResult: Specifies the copy status for each destination location, as defined in section 2.2.4.2.");
            
            // if the schema validation is successful, then capture R58
            this.Site.CaptureRequirement(
                                       58,
                                       @"[In CopyResultCollection] [The schema of complex type CopyResultCollection is defined as:] <s:complexType name=""CopyResultCollection"">
  <s:sequence>
    <s:element minOccurs=""0"" maxOccurs=""unbounded"" name=""CopyResult"" nillable=""true"" type=""tns:CopyResult"" />
  </s:sequence>
</s:complexType>");

            // if the schema validation is successful, all CopyResult items in the CopyResult collection should match the schema definition of CopyResult type.
            this.Site.CaptureRequirement(
                                        46,
                                        @"[In CopyResult] [The schema of complex type CopyResult is defined as:] <s:complexType name=""CopyResult"">
  <s:attribute name=""ErrorCode"" type=""tns:CopyErrorCode"" use=""required""/>
  <s:attribute name=""ErrorMessage"" type=""s:string""/>
  <s:attribute name=""DestinationUrl"" type=""s:string"" use=""required""/>
</s:complexType>");

            // if the schema validation is successful, all CopyResult items in the CopyResult collection should match the schema definition of CopyResult type.
            this.Site.CaptureRequirement(
                                        47,
                                        "[In CopyResult] ErrorCode: The success or failure status code of the operation for a specific DestinationUrl, as defined in section 2.2.5.1.");

            // if the schema validation is successful, all CopyResult items in the CopyResult collection should match the schema definition of CopyResult type.
            this.Site.CaptureRequirement(
                                        55,
                                        "[In CopyResult] DestinationUrl: The destination location for which the CopyResult element specifies the result of the operation.");

            // if the schema validation is successful, all CopyResult items in the CopyResult collection should match the schema definition of CopyResult type, the requirements: MS-COPYS_R84 and MS-COPYS_R85 can be directly captured.
            this.Site.CaptureRequirement(
                84,
                @"[In CopyErrorCode] [The schema of simple  type CopyErrorCode is defined as:] <s:simpleType name=""CopyErrorCode"">
  <s:restriction base=""s:string"">
    <s:enumeration value=""Success""/>
    <s:enumeration value=""DestinationInvalid""/>
    <s:enumeration value=""DestinationMWS""/>
    <s:enumeration value=""SourceInvalid""/>
    <s:enumeration value=""DestinationCheckedOut""/>
    <s:enumeration value=""InvalidUrl""/>
    <s:enumeration value=""Unknown""/>
  </s:restriction>
</s:simpleType>");

            // Verified requirement: MS-COPYS_R85
            this.Site.CaptureRequirement(
                85,
                @"[In CopyErrorCode] The following table lists the allowed values of the CopyErrorCode simple type[Success, DestinationInvalid, DestinationMWS, SourceInvalid, DestinationCheckedOut, InvalidUrl, Unknown].");
            
            #region validate each CopyResult item.
            // Validate the destinationUrl property in each CopyResult item whether match each item in DestinationUrlCollection instance in the request.
            if (null == destinationUrlsInRequest || 0 == destinationUrlsInRequest.Length)
            {
                throw new ArgumentNullException("detinationUrlsInRequest");
            }

            if (copyResultCollection.Length != destinationUrlsInRequest.Length)
            {
                this.Site.Assert.Fail(
                         "The number of URL items in DestinationUrlCollection instance should equal to the number of copyResult items in CopyResultCollection instance. Urls in request:[{0}], copyResult items[{1}]",
                         destinationUrlsInRequest.Length,
                         copyResultCollection.Length);
            }

            StringBuilder errorMsgOfValidateDestinationUrl = new StringBuilder();
            for (int itemIndex = 0; itemIndex < destinationUrlsInRequest.Length; itemIndex++)
            {
                if (!string.Equals(destinationUrlsInRequest[itemIndex], copyResultCollection[itemIndex].DestinationUrl, StringComparison.OrdinalIgnoreCase))
                {
                    // record information for un-equal destination Urls.
                    string errorMsg = string.Format(
                                                   @"Not matched item--Index:[{0}] URL in request:[{1}], URL in CopyResult:[{2}]\r\n",
                                                   itemIndex,
                                                   string.IsNullOrEmpty(destinationUrlsInRequest[itemIndex]) ? "None/Empty" : destinationUrlsInRequest[itemIndex],
                                                   string.IsNullOrEmpty(copyResultCollection[itemIndex].DestinationUrl) ? "None/Empty" : copyResultCollection[itemIndex].DestinationUrl);
                    errorMsgOfValidateDestinationUrl.AppendLine(errorMsg);
                }

                // If the "ErrorMessage" attribute has of current CopyResult item, then capture R48 for CopyResult item
                if (!string.IsNullOrEmpty(copyResultCollection[itemIndex].ErrorMessage))
                {
                    // Verified requirement: MS-COPYS_R48
                    this.Site.CaptureRequirement(
                                             48,
                                             "[In CopyResult] ErrorMessage: The user-readable message that explains the failure specified by the ErrorCode attribute.");
                }
            }

            if (errorMsgOfValidateDestinationUrl.Length != 0)
            {
                this.Site.Log.Add(
                               LogEntryKind.Debug,
                               @"Not all the destination URLs are matched between the DestinationUrl property of CopyResult item and the URL item in DestinationUrlCollection instance in the request:\r\n{0}",
                               errorMsgOfValidateDestinationUrl.ToString());
            }

            #endregion validate each CopyResult item.

            // If all the URLs values are matched between CopyResult collection and DestinationUrlCollection, then capture R57.
            this.Site.CaptureRequirementIfAreEqual(
                                               0,
                                               errorMsgOfValidateDestinationUrl.Length,
                                               57,
                                               "[In CopyResultCollection] This collection MUST contain exactly one entry for each IRI in the DestinationUrlCollection complex type (section 2.2.4.1).");
        }