Inheritance: SearchExpressionType
        /// <summary>
        /// The operation construct a request for FindItem operation.
        /// </summary>
        /// <param name="folderName">A string that specifies the folder to search.</param>
        /// <param name="value">A string that specifies the value for a search restriction.</param>
        /// <param name="field">A string that specifies the type of referenced field URI.</param>
        /// <returns>The request of FindItem operation which constructed with special folder name, search restriction and referenced field URI</returns>
        protected FindItemType ConstructFindItemRequest(string folderName, string value, string field)
        {
            FindItemType findRequest = new FindItemType();
            findRequest.ItemShape = new ItemResponseShapeType();
            findRequest.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties;

            DistinguishedFolderIdType folderId = new DistinguishedFolderIdType();
            DistinguishedFolderIdNameType folderIdName;
            if (Enum.TryParse<DistinguishedFolderIdNameType>(folderName, out folderIdName))
            {
                folderId.Id = folderIdName;
            }
            else
            {
                Site.Assert.Fail("The value of the first argument (foldIdNameType) of FindItem operation is invalid.");
            }

            findRequest.ParentFolderIds = new BaseFolderIdType[1];
            findRequest.ParentFolderIds[0] = folderId;

            PathToUnindexedFieldType itemClass = new PathToUnindexedFieldType();
            UnindexedFieldURIType fieldURI;
            if (Enum.TryParse<UnindexedFieldURIType>(field, out fieldURI))
            {
                // set search field.
                itemClass.FieldURI = fieldURI;
            }
            else
            {
                Site.Assert.Fail("The value of the second argument (fieldURIType) of FindItem operation is invalid.");
            }

            ContainsExpressionType expressionType = new ContainsExpressionType();
            expressionType.Item = itemClass;
            expressionType.ContainmentMode = ContainmentModeType.Substring;
            expressionType.ContainmentModeSpecified = true;
            expressionType.ContainmentComparison = ContainmentComparisonType.IgnoreCaseAndNonSpacingCharacters;
            expressionType.ContainmentComparisonSpecified = true;
            expressionType.Constant = new ConstantValueType();
            expressionType.Constant.Value = value;

            RestrictionType restriction = new RestrictionType();
            restriction.Item = expressionType;

            if (!string.IsNullOrEmpty(value))
            {
                findRequest.Restriction = restriction;
            }

            return findRequest;
        }
        /// <summary>
        /// The method searches the mailbox and returns the items that meet a specified search restriction.
        /// </summary>
        /// <param name="folder">A string that specifies the folder to search.</param>
        /// <param name="value">A string that specifies the value for a search restriction.</param>
        /// <returns>If the method succeeds, return an array of item; otherwise, return null.</returns>
        private ItemIdType[] GetItemIds(string folder, string value)
        {
            #region Construct FindItem request
            FindItemType findRequest = new FindItemType();

            if (string.IsNullOrEmpty(folder) || string.IsNullOrEmpty(value))
            {
                Site.Assert.Fail("Invalid argument: one or more invalid arguments passed to GetItemIds method.");
            }

            findRequest.ItemShape = new ItemResponseShapeType();
            findRequest.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties;

            DistinguishedFolderIdType folderId = new DistinguishedFolderIdType();
            DistinguishedFolderIdNameType folderIdName;
            if (Enum.TryParse<DistinguishedFolderIdNameType>(folder, out folderIdName))
            {
                folderId.Id = folderIdName;
            }
            else
            {
                Site.Assert.Fail("The value of the first argument (foldIdNameType) of FindItem operation is invalid.");
            }

            findRequest.ParentFolderIds = new BaseFolderIdType[1];
            findRequest.ParentFolderIds[0] = folderId;

            PathToUnindexedFieldType itemClass = new PathToUnindexedFieldType();
            itemClass.FieldURI = UnindexedFieldURIType.itemSubject;
            ContainsExpressionType expressionType = new ContainsExpressionType();
            expressionType.Item = itemClass;
            expressionType.ContainmentMode = ContainmentModeType.Substring;
            expressionType.ContainmentModeSpecified = true;
            expressionType.ContainmentComparison = ContainmentComparisonType.IgnoreCaseAndNonSpacingCharacters;
            expressionType.ContainmentComparisonSpecified = true;
            expressionType.Constant = new ConstantValueType();
            expressionType.Constant.Value = value;

            RestrictionType restriction = new RestrictionType();
            restriction.Item = expressionType;

            findRequest.Restriction = restriction;
            #endregion

            #region Get the ids of all ItemId instances
            int counter = 0;
            int upperBound = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site));
            int waitTime = int.Parse(Common.GetConfigurationPropertyValue("WaitTime", this.Site));
            FindItemResponseType findResponse = new FindItemResponseType();

            while (counter < upperBound)
            {
                Thread.Sleep(waitTime);

                findResponse = this.exchangeServiceBinding.FindItem(findRequest);
                if (findResponse != null
                    && findResponse.ResponseMessages != null
                    && findResponse.ResponseMessages.Items != null
                    && findResponse.ResponseMessages.Items.Length > 0)
                {
                    ArrayOfRealItemsType items = ((FindItemResponseMessageType)findResponse.ResponseMessages.Items[0]).RootFolder.Item as ArrayOfRealItemsType;

                    if (items.Items != null && items.Items.Length > 0)
                    {
                        List<ItemIdType> itemIds = new List<ItemIdType>();
                        foreach (ItemType item in items.Items)
                        {
                            if (item.ItemId != null)
                            {
                                itemIds.Add(item.ItemId);
                            }
                        }

                        if (itemIds.Count > 0)
                        {
                            return itemIds.ToArray();
                        }
                    }
                }

                counter++;
            }

            Site.Log.Add(LogEntryKind.Debug, "When there is not any message found by FindItem operation, the retry count is {0}", counter);
            return null;
            #endregion
        }
        public void MSOXWSCORE_S01_TC24_CreateItemAssociatedWithFolder()
        {
            Site.Assume.IsTrue(Common.IsRequirementEnabled(2285, this.Site), "Exchange 2007 does not support the IsAssociated element.");

            #region Create an user configuration object.
            // User configuration objects are items that are associated with folders in a mailbox.
            string userConfiguratioName = Common.GenerateResourceName(this.Site, "UserConfigurationSampleName").Replace("_", string.Empty);
            bool isSuccess = this.USRCFGSUTControlAdapter.CreateUserConfiguration(
                Common.GetConfigurationPropertyValue("User1Name", this.Site),
                Common.GetConfigurationPropertyValue("User1Password", this.Site),
                Common.GetConfigurationPropertyValue("Domain", this.Site),
                userConfiguratioName);
            Site.Assert.IsTrue(isSuccess, "The user configuration object should be created successfully.");
            #endregion

            #region Find the created user configuration object
            FindItemType findRequest = new FindItemType();
            findRequest.ItemShape = new ItemResponseShapeType();
            findRequest.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties;
            findRequest.ParentFolderIds = new BaseFolderIdType[1]
            {
                new DistinguishedFolderIdType() { Id = DistinguishedFolderIdNameType.inbox }
            };
            PathToUnindexedFieldType itemSubject = new PathToUnindexedFieldType();
            itemSubject.FieldURI = UnindexedFieldURIType.itemItemClass;
            ContainsExpressionType expressionType = new ContainsExpressionType();
            expressionType.Item = itemSubject;
            expressionType.ContainmentMode = ContainmentModeType.Substring;
            expressionType.ContainmentModeSpecified = true;
            expressionType.ContainmentComparison = ContainmentComparisonType.IgnoreCaseAndNonSpacingCharacters;
            expressionType.ContainmentComparisonSpecified = true;
            expressionType.Constant = new ConstantValueType();
            expressionType.Constant.Value = "IPM.Configuration";

            RestrictionType restriction = new RestrictionType();
            restriction.Item = expressionType;
            findRequest.Restriction = restriction;
            findRequest.Traversal = ItemQueryTraversalType.Associated;

            FindItemResponseType findResponse = this.SRCHAdapter.FindItem(findRequest);
            ItemType[] foundItems = (((FindItemResponseMessageType)findResponse.ResponseMessages.Items[0]).RootFolder.Item as ArrayOfRealItemsType).Items;
            ItemType item = null;
            foreach (ItemType foundItem in foundItems)
            {
                if (foundItem.ItemClass.Contains(userConfiguratioName))
                {
                    item = foundItem;
                    break;
                }
            }

            Site.Assert.IsNotNull(item, "The created user configuration object should be found!");

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

            // Verify MS-OXWSCORE requirement: MS-OXWSCORE_R1618
            this.Site.CaptureRequirementIfIsTrue(
                item.IsAssociatedSpecified && item.IsAssociated,
                1618,
                @"[In t:ItemType Complex Type] [IsAssociated is] True, indicates the item is associated with a folder.");
            #endregion
        }