/// <summary>
        /// A method used to verify field information related requirements.
        /// </summary>
        /// <param name="fieldInformationItem">A parameter represents the field information.</param>
        private void VerifyFieldInformation(FieldInformation fieldInformationItem)
        {
            if (null == fieldInformationItem)
            {
                throw new ArgumentNullException("fieldInformationItem");
            }

            if (!string.IsNullOrEmpty(fieldInformationItem.Value))
            {
                // If the value attribute presents, then capture R70
                this.Site.CaptureRequirement(
                    70,
                    "[In FieldInformation] Value: The value of the field.");
            }

            // If the display name is non-empty and fewer than 256 characters. then capture R66.
            // The unicode encoding format can present all possible chars, all string are unicode string.
            this.Site.Log.Add(
                LogEntryKind.Debug,
                @"The DisplayName[{0}] length is [{1}]",
                string.IsNullOrEmpty(fieldInformationItem.DisplayName) ? "Null/Empty" : fieldInformationItem.DisplayName,
                string.IsNullOrEmpty(fieldInformationItem.DisplayName) ? "NUll/Zero" : fieldInformationItem.DisplayName.Length.ToString());

            this.Site.CaptureRequirementIfIsTrue(
                !string.IsNullOrEmpty(fieldInformationItem.DisplayName) && fieldInformationItem.DisplayName.Length < 256,
                66,
                "[In FieldInformation] [DisplayName] This value MUST be a non-empty Unicode string that is fewer than 256 characters.");

            // If the internal name is a ASCII string ,capture R68
            this.Site.CaptureRequirementIfIsTrue(
                this.VerifyInternalNameOfField(fieldInformationItem.InternalName),
                68,
                "[In FieldInformation] [InternalName] The value MUST be a non-empty ASCII string that does not contain spaces and is fewer than 256 characters.");
        }
        public void MSCOPYS_S02_TC07_CopyIntoItemsLocal_EncodedAbsUrlField()
        {
            this.Site.Assume.IsTrue(Common.IsRequirementEnabled(232, this.Site), @"This is executed only when R232Enable is set to true.");

            // Get the value of the source file URL.
            string sourceFileUrl = this.GetSourceFileUrl(SourceFileUrlType.SourceFileOnDesSUT);

            // Get the first destination location.
            string desFileUrl = this.GetDestinationFileUrl(DestinationFileUrlType.NormalDesLibraryOnDesSUT);

            string[] desUrls = new string[] { desFileUrl };

            // Retrieve the contents and metadata for a file from the specified location.
            GetItemResponse getitemsResponse = MSCopysAdapter.GetItem(sourceFileUrl);

            this.Site.Assert.IsNotNull(getitemsResponse, "GetItem operation should succeed");

            // Select a field by specified field attribute value.
            FieldInformation fieldInfoScource = this.SelectFieldBySpecifiedAtrribute(
                getitemsResponse.Fields,
                "EncodedAbsUrl",
                FieldAttributeType.InternalName);

            // Copy a file to the destination server.
            CopyIntoItemsLocalResponse copyIntoItemsLocalResponse = MSCopysAdapter.CopyIntoItemsLocal(
                sourceFileUrl,
                desUrls);

            // Verify whether all copy results are successful.
            bool isVerifyCopySuccess = VerifyAllCopyResultsSuccess(copyIntoItemsLocalResponse.Results, true);

            this.Site.Assert.IsTrue(isVerifyCopySuccess, "CopyIntoItemsLocal operation should succeed.");

            // Collect files from specified file URLs.
            this.CollectFileByUrl(desUrls);

            // Retrieve content and metadata for a file that is stored in a source location with first destination URL.
            GetItemResponse getitemsResponseDes = MSCopysAdapter.GetItem(copyIntoItemsLocalResponse.Results[0].DestinationUrl);

            // Select a field by specified field attribute value.
            FieldInformation fieldInfoDes = this.SelectFieldBySpecifiedAtrribute(
                getitemsResponseDes.Fields,
                "EncodedAbsUrl",
                FieldAttributeType.InternalName);

            if (Common.IsRequirementEnabled(232, this.Site))
            {
                // Verify MS-COPYS requirement: MS-COPYS_R232
                this.Site.CaptureRequirementIfAreNotEqual(
                    fieldInfoScource.Value.ToLower(),
                    fieldInfoDes.Value.ToLower(),
                    232,
                    @"[In Appendix B: Product Behavior] CopyIntoItemsLocal operation does not copy the EncodedAbsUrl field.(Windows SharePoint Services 3.0, SharePoint Foundation 2010 and SharePoint Foundation 2013 follow this behavior.)");
            }
        }
        /// <summary>
        /// A method used to select a field by specified field attribute value. The "DisplayName" is not a unique identifier for a field, so the method return the first match item when using "DisplayName" attribute value. If there are no any fields are found, this method will raise an InvalidOperationException.
        /// </summary>
        /// <param name="fields">A parameter represents the fields array.</param>
        /// <param name="expectedAttributeValue">A parameter represents the expected attribute value which is used to match field item.</param>
        /// <param name="usedAttribute">A parameter represents the attribute type which is used to compare with the expected attribute value.</param>
        /// <returns>A return value represents the selected field.</returns>
        protected FieldInformation SelectFieldBySpecifiedAtrribute(FieldInformation[] fields, string expectedAttributeValue, FieldAttributeType usedAttribute)
        {
            FieldInformation selectedField = this.FindOutTheField(fields, expectedAttributeValue, usedAttribute);

            if (null == selectedField)
            {
                string errorMsg = string.Format(
                    "Could not find the expected field by specified value:[{0}] of [{1}] attribute.",
                    expectedAttributeValue,
                    usedAttribute);

                throw new InvalidOperationException(errorMsg);
            }

            return(selectedField);
        }
Example #4
0
        public void MSCOPYS_S02_TC08_CopyIntoItemsLocal_CopySourceField()
        {
            this.Site.Assume.IsTrue(Common.IsRequirementEnabled(149, this.Site), @"This is executed only when R149Enable is set to true.");

            // Get the value of the source file URL.
            string sourceFileUrl = this.GetSourceFileUrl(SourceFileUrlType.SourceFileOnDesSUT);

            // Get the first destination location.
            string desFileUrl = this.GetDestinationFileUrl(DestinationFileUrlType.NormalDesLibraryOnDesSUT);

            string[] desUrls = new string[] { desFileUrl };

            // Copy a file to the destination server.
            CopyIntoItemsLocalResponse copyIntoItemsLocalResponse = MSCopysAdapter.CopyIntoItemsLocal(
                sourceFileUrl,
                desUrls);

            // Verify whether all copy results are successful.
            bool isVerifyCopySuccess = VerifyAllCopyResultsSuccess(copyIntoItemsLocalResponse.Results, true);

            this.Site.Assert.IsTrue(isVerifyCopySuccess, "CopyIntoItemsLocal operation should succeed.");

            // Collect files from specified file URLs.
            this.CollectFileByUrl(desUrls);

            // Retrieve content and metadata for a file that is stored in a source location with first destination URL.
            GetItemResponse getitemsResponseDes = MSCopysAdapter.GetItem(copyIntoItemsLocalResponse.Results[0].DestinationUrl);

            // Select a field by specified field attribute value.
            FieldInformation fieldInfoDes = this.SelectFieldBySpecifiedAtrribute(
                getitemsResponseDes.Fields,
                "_CopySource",
                FieldAttributeType.InternalName);

            // Verify MS-COPYS requirement: MS-COPYS_R149
            this.Site.CaptureRequirementIfAreEqual(
                sourceFileUrl.ToLower(),
                fieldInfoDes.Value.ToLower(),
                149,
                @"[In Appendix B: Product Behavior] [For CopyIntoItemsLocation operation] Implementation [the value of field with internal name _CopySource ] does equal to the value of source location.(SharePoint Foundation 2010 follow this behavior.)");
        }
        /// <summary>
        /// A method used to copy a file to a destination server that is different from the source location.
        /// </summary>
        /// <param name="sourceUrl">A parameter represents the absolute URL of the file in the source location.</param>
        /// <param name="destinationUrls">A parameter represents a collection of locations on the destination server.</param>
        /// <param name="fields">A parameter represents a collection of the metadata for the file.</param>
        /// <param name="rawStreamValue">A parameter represents the contents of the file. The contents will be encoded in Base64 format and sent in request.</param>
        /// <returns>A return value represents the result of the operation.</returns>
        public CopyIntoItemsResponse CopyIntoItems(string sourceUrl, string[] destinationUrls, FieldInformation[] fields, byte[] rawStreamValue)
        {
            CopyIntoItemsResponse copyIntoItemsResponse;
            uint copyIntoItemsResult;
            CopyResult[] results;
            try
            {   
                copyIntoItemsResult = this.copySoapService.CopyIntoItems(sourceUrl, destinationUrls, fields, rawStreamValue, out results);
                copyIntoItemsResponse = new CopyIntoItemsResponse(copyIntoItemsResult, results);
            }
            catch (SoapException soapEx)
            {
                this.VerifySoapExceptionDetailCapture(soapEx);
                throw;
            }

            this.VerifyCopyIntoItemsOperationCapture(copyIntoItemsResponse, destinationUrls);
            return copyIntoItemsResponse;
        }
        /// <summary>
        /// A method used to find out a field by specified field attribute value. The "DisplayName" is not a unique identifier for a field, so the method return the first match item when using "DisplayName" attribute value.
        /// </summary>
        /// <param name="fields">A parameter represents the fields array.</param>
        /// <param name="expectedAttributeValue">A parameter represents the expected attribute value which is used to match field item.</param>
        /// <param name="usedAttribute">A parameter represents the attribute type which is used to compare with the expected attribute value.</param>
        /// <returns>A return value represents the selected field.</returns>
        private FieldInformation FindOutTheField(FieldInformation[] fields, string expectedAttributeValue, FieldAttributeType usedAttribute)
        {
            #region validate parameters
            if (null == fields)
            {
                throw new ArgumentNullException("fields");
            }

            if (string.IsNullOrEmpty(expectedAttributeValue))
            {
                throw new ArgumentNullException("attributeValue");
            }

            if (0 == fields.Length)
            {
                throw new ArgumentException("The fields' array should contain at least one item.");
            }

            #endregion validate parameters

            FieldInformation selectedField = null;

            #region select the field by specified attribute value
            switch (usedAttribute)
            {
                case FieldAttributeType.InternalName:
                    {
                        var selectResult = from fieldItem in fields
                                           where expectedAttributeValue.Equals(fieldItem.InternalName, StringComparison.OrdinalIgnoreCase)
                                           select fieldItem;

                        selectedField = 1 == selectResult.Count() ? selectResult.ElementAt<FieldInformation>(0) : null;
                        break;
                    }

                case FieldAttributeType.Id:
                    {
                        Guid expectedGuidValue;
                        if (!Guid.TryParse(expectedAttributeValue, out expectedGuidValue))
                        {
                            throw new InvalidOperationException(
                                        string.Format(
                                                       @"The attributeValue parameter value should be a valid GUID value when select field by using [Id] attribute. Current attributeValue parameter:[{0}].",
                                                       expectedAttributeValue));
                        }

                        var selectResult = from fieldItem in fields
                                           where expectedGuidValue.Equals(fieldItem.Id)
                                           select fieldItem;

                        selectedField = 1 == selectResult.Count() ? selectResult.ElementAt<FieldInformation>(0) : null;
                        break;
                    }

                case FieldAttributeType.DisplayName:
                    {
                        var selectResult = from fieldItem in fields
                                           where expectedAttributeValue.Equals(fieldItem.InternalName, StringComparison.OrdinalIgnoreCase)
                                           select fieldItem;

                        // The DisplayName attribute is not unique.
                        selectedField = selectResult.Count() > 0 ? selectResult.ElementAt<FieldInformation>(0) : null;
                        break;
                    }
            }
            #endregion select the field by specified attribute value

            if (null == selectedField)
            {
                string errorMsg = string.Format(
                         "Could not find the expected field by specified vale:[{0}] of [{1}] attribute.",
                         expectedAttributeValue,
                         usedAttribute);

                #region log the fields information

                StringBuilder logBuilder = new StringBuilder();
                logBuilder.AppendLine(errorMsg);
                logBuilder.AppendLine("Fields in current field collection:");
                foreach (FieldInformation fieldItem in fields)
                {
                    string fieldInformation = string.Format(
                                @"FieldName:[{0}] InternalName:[{1}] Type:[{2}] Value:[{3}]",
                                fieldItem.DisplayName,
                                string.IsNullOrEmpty(fieldItem.InternalName) ? "Null/Empty" : fieldItem.InternalName,
                                fieldItem.Type,
                                string.IsNullOrEmpty(fieldItem.Value) ? "Null/Empty" : fieldItem.Value);

                    logBuilder.AppendLine(fieldInformation);
                }

                logBuilder.AppendLine("==================");
                logBuilder.AppendLine(string.Format("Total fields:[{0}]", fields.Length));
                this.Site.Log.Add(LogEntryKind.Debug, logBuilder.ToString());
                #endregion log the fields information
            }

            return selectedField;
        }
        /// <summary>
        /// A method used to select a field by specified field attribute value. The "DisplayName" is not a unique identifier for a field, so the method return the first match item when using "DisplayName" attribute value. If there are no any fields are found, this method will raise an InvalidOperationException.
        /// </summary>
        /// <param name="fields">A parameter represents the fields array.</param>
        /// <param name="expectedAttributeValue">A parameter represents the expected attribute value which is used to match field item.</param>
        /// <param name="usedAttribute">A parameter represents the attribute type which is used to compare with the expected attribute value.</param>
        /// <returns>A return value represents the selected field.</returns>
        protected FieldInformation SelectFieldBySpecifiedAtrribute(FieldInformation[] fields, string expectedAttributeValue, FieldAttributeType usedAttribute)
        {
            FieldInformation selectedField = this.FindOutTheField(fields, expectedAttributeValue, usedAttribute);
            if (null == selectedField)
            {
               string errorMsg = string.Format(
                        "Could not find the expected field by specified value:[{0}] of [{1}] attribute.",
                        expectedAttributeValue,
                        usedAttribute);

               throw new InvalidOperationException(errorMsg);
            }

            return selectedField;
        }
        /// <summary>
        /// A method used to verify field information related requirements.
        /// </summary>
        /// <param name="fieldInformationItem">A parameter represents the field information.</param>
        private void VerifyFieldInformation(FieldInformation fieldInformationItem)
        {
            if (null == fieldInformationItem)
            {
                throw new ArgumentNullException("fieldInformationItem");
            }
            
            if (!string.IsNullOrEmpty(fieldInformationItem.Value))
            {
                // If the value attribute presents, then capture R70
                this.Site.CaptureRequirement(
                                            70,
                                            "[In FieldInformation] Value: The value of the field.");
            }

            // If the display name is non-empty and fewer than 256 characters. then capture R66.
            // The unicode encoding format can present all possible chars, all string are unicode string.
            this.Site.Log.Add(
                        LogEntryKind.Debug,
                        @"The DisplayName[{0}] length is [{1}]",
                        string.IsNullOrEmpty(fieldInformationItem.DisplayName) ? "Null/Empty" : fieldInformationItem.DisplayName,
                        string.IsNullOrEmpty(fieldInformationItem.DisplayName) ? "NUll/Zero" : fieldInformationItem.DisplayName.Length.ToString());
             
            this.Site.CaptureRequirementIfIsTrue(
                                                !string.IsNullOrEmpty(fieldInformationItem.DisplayName) && fieldInformationItem.DisplayName.Length < 256,
                                                66,
                                                "[In FieldInformation] [DisplayName] This value MUST be a non-empty Unicode string that is fewer than 256 characters.");

            // If the internal name is a ASCII string ,capture R68
            this.Site.CaptureRequirementIfIsTrue(
                                              this.VerifyInternalNameOfField(fieldInformationItem.InternalName),
                                              68,
                                              "[In FieldInformation] [InternalName] The value MUST be a non-empty ASCII string that does not contain spaces and is fewer than 256 characters.");
        }
        /// <summary>
        /// A method used to verify field information collection and all field items in this collection.
        /// </summary>
        /// <param name="fieldInfromationCollection">A parameter represents the  field information collection.</param>
        private void VerifyFieldInfromationCollection(FieldInformation[] fieldInfromationCollection)
        {
            if (null == fieldInfromationCollection || 0 == fieldInfromationCollection.Length)
            {
                return;
            }

            // If the schema validation is successful, the requirements: MS-COPYS_R76 and MS-COPYS_R77 can be directly captured.
            this.Site.CaptureRequirement(
                76,
                @"[In FieldInformationCollection] [The schema of complex type FieldInformationCollection is defined as:] <s:complexType name=""FieldInformationCollection"">
  <s:sequence>
    <s:element name=""FieldInformation"" type=""tns:FieldInformation"" minOccurs=""0"" maxOccurs=""unbounded""/>
  </s:sequence>
</s:complexType>");

            // Verified requirement: MS-COPYS_R77
            this.Site.CaptureRequirement(
                77,
                @"[In FieldInformationCollection] FieldInformation: A single metadata field for a file, as defined in section 2.2.4.4.");

            // If the schema validation is successful, all required properties in each fieldinformation item in the FieldInformationCollection are match the schema definition, the requirements: MS-COPYS_R62, MS-COPYS_R64, MS-COPYS_R65, MS-COPYS_R67 and MS-COPYS_R69 can be captured.
            this.Site.CaptureRequirement(
                62,
                @"[In FieldInformation] [The schema of complex type FieldInformation is defined as:] <s:complexType name=""FieldInformation"">
                  <s:attribute name=""Type"" type=""tns:FieldType"" use=""required""/>
                  <s:attribute name=""DisplayName"" type=""s:string"" use=""required""/>
                  <s:attribute name=""InternalName"" type=""s:string"" use=""required""/>
                  <s:attribute name=""Id"" type=""s1:guid"" use=""required""/>
                  <s:attribute name=""Value"" type=""s:string""/>
                </s:complexType>");

            string[] types = { "Invalid", "Integer", "Text", "Note", "DateTime", "Counter", "Choice", "Lookup", "Boolean", "Number", "Currency", "URL", "Computed", "Threading", "Guid", "MultiChoice", "GridChoice", "Calculated", "File", "Attachments", "User", "Recurrence", "CrossProjectLink", "ModStat", "AllDayEvent", "Error" };
            
            bool isVerifyR64 = false;
            foreach (string type in types)
            {
                if (fieldInfromationCollection[0].Type.ToString() == type)
                {
                    isVerifyR64 = true;
                    break;
                }
            }

            this.Site.CaptureRequirementIfIsTrue(
                isVerifyR64,
                64,
                @"[In FieldInformation] [Type] The value MUST contain one of the values [Invalid, Integer, Text, Note, DateTime, Counter, Choice, Lookup, Boolean, Number, Currency, URL, Computed, Threading, Guid, MultiChoice, GridChoice, Calculated, File, Attachments, User, Recurrence, CrossProjectLink, ModStat, AllDayEvent, Error] defined in section 2.2.5.2.");

            // The simple type FieldType
            this.Site.CaptureRequirementIfIsTrue(
                isVerifyR64,
                127,
                @"[In FieldType] Attributes that use FieldType MUST use one of the following values: Invalid, Integer, Text, Note, DateTime, Counter, Choice, Lookup, Boolean, Number, Currency, URL, Computed, Threading, Guid, MultiChoice, GridChoice, Calculated, File, Attachments, User, Recurrence, CrossProjectLink, ModStat, AllDayEvent, Error.");

            // Verified requirement: MS-COPYS_R65
            this.Site.CaptureRequirement(
                65,
                @"[In FieldInformation] DisplayName: The user-readable name of the field.");

            // Verified requirement: MS-COPYS_R67
            this.Site.CaptureRequirement(
                67,
                @"[In FieldInformation] InternalName: The internal name that identifies the metadata field for a file in the source location.");

            // Verified requirement: MS-COPYS_R69
            this.Site.CaptureRequirement(
                69,
                @"[In FieldInformation] Id: The GUID that identifies the metadata field for a file in the source location.");

            // If the schema validation is successful, all Fieldinformation item ins the FieldInformationCollection are match the schema definition, the requirements: MS-COPYS_R113, MS-COPYS_R127 and MS-COPYS_R129 can be directly captured.
            this.Site.CaptureRequirement(
                113,
                @"[In FieldType] [The schema of simple  type FieldType is defined as:] <s:simpleType name=""FieldType"">
  <s:restriction base=""s:string"">
    <s:enumeration value=""Invalid""/>
    <s:enumeration value=""Integer""/>
    <s:enumeration value=""Text""/>
    <s:enumeration value=""Note""/>
    <s:enumeration value=""DateTime""/>
    <s:enumeration value=""Counter""/>
    <s:enumeration value=""Choice""/>
    <s:enumeration value=""Lookup""/>
    <s:enumeration value=""Boolean""/>
    <s:enumeration value=""Number""/>
    <s:enumeration value=""Currency""/>
    <s:enumeration value=""URL""/>
    <s:enumeration value=""Computed""/>
    <s:enumeration value=""Threading""/>
    <s:enumeration value=""Guid""/>
    <s:enumeration value=""MultiChoice""/>
    <s:enumeration value=""GridChoice""/>
    <s:enumeration value=""Calculated""/>
    <s:enumeration value=""File""/>
    <s:enumeration value=""Attachments""/>
    <s:enumeration value=""User""/>
    <s:enumeration value=""Recurrence""/>
    <s:enumeration value=""CrossProjectLink""/>
    <s:enumeration value=""ModStat""/>
    <s:enumeration value=""AllDayEvent""/>
    <s:enumeration value=""Error""/>
  </s:restriction>
</s:simpleType>");

            // Verified requirement: MS-COPYS_R129
            this.Site.CaptureRequirement(
                129,
                @"[In guid] [The schema of simple  type guid is defined as:] <s:simpleType name=""guid"">
  <s:restriction base=""s:string"">
    <s:pattern value=""[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"" />
  </s:restriction>
</s:simpleType>");

            // Verify each field item.
            foreach (FieldInformation fieldItem in fieldInfromationCollection)
            {
                this.VerifyFieldInformation(fieldItem);
            }
        }
 /// <summary>
 /// Initializes a new instance of the GetItemResponse class.
 /// </summary>
 /// <param name="getItemResult">A parameter represents the result status of "CopyIntoItems" operation.</param>
 /// <param name="fields">A parameter represents the fields information of a file.</param>
 /// <param name="streamRawValue">A parameter represents the stream raw value.</param>
 public GetItemResponse(uint getItemResult, FieldInformation[] fields, byte[] streamRawValue)
 {
     this.getItemResultValue = getItemResult;
     this.fieldsCollection = fields;
     this.fileContentBinariesData = streamRawValue;
 }
        /// <summary>
        /// A method used to find out a field by specified field attribute value. The "DisplayName" is not a unique identifier for a field, so the method return the first match item when using "DisplayName" attribute value.
        /// </summary>
        /// <param name="fields">A parameter represents the fields array.</param>
        /// <param name="expectedAttributeValue">A parameter represents the expected attribute value which is used to match field item.</param>
        /// <param name="usedAttribute">A parameter represents the attribute type which is used to compare with the expected attribute value.</param>
        /// <returns>A return value represents the selected field.</returns>
        private FieldInformation FindOutTheField(FieldInformation[] fields, string expectedAttributeValue, FieldAttributeType usedAttribute)
        {
            #region validate parameters
            if (null == fields)
            {
                throw new ArgumentNullException("fields");
            }

            if (string.IsNullOrEmpty(expectedAttributeValue))
            {
                throw new ArgumentNullException("attributeValue");
            }

            if (0 == fields.Length)
            {
                throw new ArgumentException("The fields' array should contain at least one item.");
            }

            #endregion validate parameters

            FieldInformation selectedField = null;

            #region select the field by specified attribute value
            switch (usedAttribute)
            {
            case FieldAttributeType.InternalName:
            {
                var selectResult = from fieldItem in fields
                                   where expectedAttributeValue.Equals(fieldItem.InternalName, StringComparison.OrdinalIgnoreCase)
                                   select fieldItem;

                selectedField = 1 == selectResult.Count() ? selectResult.ElementAt <FieldInformation>(0) : null;
                break;
            }

            case FieldAttributeType.Id:
            {
                Guid expectedGuidValue;
                if (!Guid.TryParse(expectedAttributeValue, out expectedGuidValue))
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  @"The attributeValue parameter value should be a valid GUID value when select field by using [Id] attribute. Current attributeValue parameter:[{0}].",
                                  expectedAttributeValue));
                }

                var selectResult = from fieldItem in fields
                                   where expectedGuidValue.Equals(fieldItem.Id)
                                   select fieldItem;

                selectedField = 1 == selectResult.Count() ? selectResult.ElementAt <FieldInformation>(0) : null;
                break;
            }

            case FieldAttributeType.DisplayName:
            {
                var selectResult = from fieldItem in fields
                                   where expectedAttributeValue.Equals(fieldItem.InternalName, StringComparison.OrdinalIgnoreCase)
                                   select fieldItem;

                // The DisplayName attribute is not unique.
                selectedField = selectResult.Count() > 0 ? selectResult.ElementAt <FieldInformation>(0) : null;
                break;
            }
            }
            #endregion select the field by specified attribute value

            if (null == selectedField)
            {
                string errorMsg = string.Format(
                    "Could not find the expected field by specified vale:[{0}] of [{1}] attribute.",
                    expectedAttributeValue,
                    usedAttribute);

                #region log the fields information

                StringBuilder logBuilder = new StringBuilder();
                logBuilder.AppendLine(errorMsg);
                logBuilder.AppendLine("Fields in current field collection:");
                foreach (FieldInformation fieldItem in fields)
                {
                    string fieldInformation = string.Format(
                        @"FieldName:[{0}] InternalName:[{1}] Type:[{2}] Value:[{3}]",
                        fieldItem.DisplayName,
                        string.IsNullOrEmpty(fieldItem.InternalName) ? "Null/Empty" : fieldItem.InternalName,
                        fieldItem.Type,
                        string.IsNullOrEmpty(fieldItem.Value) ? "Null/Empty" : fieldItem.Value);

                    logBuilder.AppendLine(fieldInformation);
                }

                logBuilder.AppendLine("==================");
                logBuilder.AppendLine(string.Format("Total fields:[{0}]", fields.Length));
                this.Site.Log.Add(LogEntryKind.Debug, logBuilder.ToString());
                #endregion log the fields information
            }

            return(selectedField);
        }