/// <summary>
 /// Factory method for creating an Im address dictionary field uri
 /// </summary>
 /// <param name="fieldIndex">Im address field index</param>
 /// <returns>Indexed field uri</returns>
 /// 
 public static PathToIndexedFieldType CreateImAddress(ImAddressKeyType fieldIndex)
 {
     return new PathToIndexedFieldType(DictionaryURIType.contactsImAddress, fieldIndex.ToString());
 }
        public void MSOXWSCONT_S01_TC05_VerifyContactItemWithImAddressKeyTypeEnums()
        {
            // The value count of enumeration "ImAddressKeyType" is 3.
            int enumCount = 3;
            ImAddressKeyType[] addressKeyTypes = new ImAddressKeyType[enumCount];

            addressKeyTypes[0] = ImAddressKeyType.ImAddress1;
            addressKeyTypes[1] = ImAddressKeyType.ImAddress2;
            addressKeyTypes[2] = ImAddressKeyType.ImAddress3;

            // Define a contact array to store the contact items got from GetItem operation response.
            // Each contact should contain an ImAddressKeyType value as its element's value.
            ContactItemType[] contacts = new ContactItemType[enumCount];
            for (int i = 0; i < enumCount; i++)
            {
                ImAddressKeyType addressKeyType = addressKeyTypes[i];

                #region Step 1:Create the contact item with ImAddressKeyType
                // Create a contact item with ImAddressKeyType.
                ContactItemType item = this.BuildContactItemWithImAddress(addressKeyType);
                CreateItemResponseType createItemResponse = this.CallCreateItemOperation(item);

                // Check the response.
                Common.CheckOperationSuccess(createItemResponse, 1, this.Site);
                #endregion

                #region Step 2:Get the contact item.
                // The contact item to get.
                ItemIdType[] itemIds = Common.GetItemIdsFromInfoResponse(createItemResponse);

                GetItemResponseType getItemResponse = this.CallGetItemOperation(itemIds);

                // Check the response.
                Common.CheckOperationSuccess(getItemResponse, 1, this.Site);

                ContactItemType[] getItems = Common.GetItemsFromInfoResponse<ContactItemType>(getItemResponse);

                Site.Assert.AreEqual<int>(
                    1,
                    getItems.GetLength(0),
                    "One contact item should be returned!");

                contacts[i] = getItems[0];

                Site.Assert.IsNotNull(
                    contacts[i],
                    "The returned contact item should not be null.");

                Site.Assert.IsNotNull(
                    contacts[i].ImAddresses,
                    "The ImAddresses element in returned contact item should not be null.");

                Site.Assert.AreEqual<int>(
                    1,
                    contacts[i].ImAddresses.GetLength(0),
                    "One entry of ImAddresses element should be returned!");
                #endregion
            }

            #region Capture Code

            this.Site.Assert.IsTrue(
                this.IsSchemaValidated,
                "The schema should be validated! Expected result: {0}, Actual result: {1}",
                true.ToString(),
                this.IsSchemaValidated.ToString());

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

            // Verify MS-OXWSCONT requirement: MS-OXWSCONT_R151
            Site.CaptureRequirementIfAreEqual<ImAddressKeyType>(
                ImAddressKeyType.ImAddress1,
                contacts[0].ImAddresses[0].Key,
                151,
                @"[In t:ImAddressKeyType Simple Type] ImAddress1: Identifies the first instant messaging address for the user.");

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

            // Verify MS-OXWSCONT requirement: MS-OXWSCONT_R152
            Site.CaptureRequirementIfAreEqual<ImAddressKeyType>(
                ImAddressKeyType.ImAddress2,
                contacts[1].ImAddresses[0].Key,
                152,
                @"[In t:ImAddressKeyType Simple Type] ImAddress2: Identifies the second instant messaging address for the user.");

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

            // Verify MS-OXWSCONT requirement: MS-OXWSCONT_R153
            Site.CaptureRequirementIfAreEqual<ImAddressKeyType>(
                ImAddressKeyType.ImAddress3,
                contacts[2].ImAddresses[0].Key,
                153,
                @"[In t:ImAddressKeyType Simple Type] ImAddress3: Identifies the third instant messaging address for the user.");

            #endregion
        }
        /// <summary>
        /// Build a contact item with enumeration value of ImAddressKeyType.
        /// </summary>
        /// <param name="instantMessagingAddress">The enumeration value of ImAddressKeyType.</param>
        /// <returns>The contact item object.</returns>
        protected ContactItemType BuildContactItemWithImAddress(ImAddressKeyType instantMessagingAddress)
        {
            // Create a contact item type.
            ContactItemType item = new ContactItemType()
            {
                // Set a single IM address for the contact.
                ImAddresses = new ImAddressDictionaryEntryType[]
                {
                    new ImAddressDictionaryEntryType()
                    {
                        Value = Common.GenerateResourceName(this.Site, "EmailAddress") + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site),
                        Key = instantMessagingAddress,
                    }
                }
            };

            return item;
        }