Microsoft.Protocols.TestSuites.MS_OXWSCORE.S04_ManageEmailItems.MSOXWSCORE_S04_TC22_VerifyItemWithEntityExtractionResult C# (CSharp) Method

MSOXWSCORE_S04_TC22_VerifyItemWithEntityExtractionResult() private method

        public void MSOXWSCORE_S04_TC22_VerifyItemWithEntityExtractionResult()
        {
            Site.Assume.IsTrue(Common.IsRequirementEnabled(1708, this.Site), "Exchange 2007 and Exchange 2010 do not support the EntityExtractionResultType complex type.");

            #region Step 1: Create message with specific body.

            // Define the specific elements' values.
            string meetingSuggestions = "Let's meet for business discussion, from 2:00pm to 2:30pm, December 15th, 2012.";
            string address = "1234 Main Street, Redmond, WA 07722";
            string taskSuggestions = "Please update the spreadsheet by today.";
            string phoneNumbers = "(235) 555-0110";
            string phoneNumberType = "Home";
            string businessName = "Department of Revenue Services";
            string contactDisplayName = TestSuiteHelper.ContactString;
            string emailAddress = Common.GetConfigurationPropertyValue("User2Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);
            string url = Common.GetConfigurationPropertyValue("ServiceUrl", this.Site);
            string userEmailAddress = Common.GetConfigurationPropertyValue("User1Name", this.Site) + "@" + Common.GetConfigurationPropertyValue("Domain", this.Site);

            // Define the MessageType item which will be created.
            MessageType[] messages = new MessageType[] { new MessageType() };
            messages[0].Subject = Common.GenerateResourceName(
                this.Site,
                TestSuiteHelper.SubjectForCreateItem);
            EmailAddressType email = new EmailAddressType();
            email.EmailAddress = userEmailAddress;
            messages[0].ToRecipients = new EmailAddressType[1];
            messages[0].ToRecipients[0] = email;
            messages[0].Body = new BodyType();
            messages[0].Body.Value = string.Format(
                "{0} {1} Any problems, contact with {2} from {3}, his {4} phone number is {5}, his email is {6}, his blog is {7} and his address is {8}",
                meetingSuggestions,
                taskSuggestions,
                contactDisplayName,
                businessName,
                phoneNumberType,
                phoneNumbers,
                emailAddress,
                url,
                address);

            // Define the request of CreateItem operation.
            CreateItemType requestItem = new CreateItemType();
            requestItem.MessageDispositionSpecified = true;
            requestItem.MessageDisposition = MessageDispositionType.SendOnly;
            requestItem.Items = new NonEmptyArrayOfAllItemsType();
            requestItem.Items.Items = messages;

            // Call the CreateItem operation.
            CreateItemResponseType createItemResponse = this.COREAdapter.CreateItem(requestItem);

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

            #region Step 2: Find the message in the inbox folder of User1.
            // Find the received item in the Inbox folder.
            ItemIdType[] foundItems = this.FindItemsInFolder(DistinguishedFolderIdNameType.inbox, messages[0].Subject, "User1");

            // The result of FindItemsInFolder should not be null.
            Site.Assert.IsNotNull(
                foundItems,
                "The result of FindItemsInFolder should not be null.");

            // One item should be returned.
            Site.Assert.AreEqual<int>(
                 1,
                 foundItems.GetLength(0),
                 "One item should be returned! Expected Item Count: {0}, Actual Item Count: {1}",
                 1,
                 foundItems.GetLength(0));
            #endregion

            #region Step 3: Get the message.
            // Get information from the found items.
            GetItemResponseType getItemResponse = this.CallGetItemOperation(foundItems);

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

            ItemIdType[] getItemIds = Common.GetItemIdsFromInfoResponse(getItemResponse);

            // One item should be returned.
            Site.Assert.AreEqual<int>(
                 1,
                 getItemIds.GetLength(0),
                 "One item should be returned! Expected Item Count: {0}, Actual Item Count: {1}",
                 1,
                 getItemIds.GetLength(0));

            // Check whether the child elements of EntityExtractionResultType have been returned successfully.
            ItemInfoResponseMessageType getItems = getItemResponse.ResponseMessages.Items[0] as ItemInfoResponseMessageType;

            Site.Assert.IsTrue(this.IsSchemaValidated, "The schema should be validated.");

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

            // Verify MS-OXWSCORE requirement: MS-OXWSCORE_R1325
            // The schema is validated and InternetMessageHeaders is not null, so this requirement can be captured.
            this.Site.CaptureRequirementIfIsNotNull(
                getItems.Items.Items[0].InternetMessageHeaders,
                1325,
                @"[In t:ItemType Complex Type] The type of InternetMessageHeaders is t:NonEmptyArrayOfInternetHeadersType (section 2.2.4.12).");

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

            // Verify MS-OXWSCORE requirement: MS-OXWSCORE_R122
            // The schema is validated and InternetMessageHeaders is not null, so this requirement can be captured.
            this.Site.CaptureRequirement(
                122,
                @"[In t:NonEmptyArrayOfInternetHeadersType Complex Type] The type [NonEmptyArrayOfInternetHeadersType] is defined as follow:
<xs:complexType name=""NonEmptyArrayOfInternetHeadersType"">
  <xs:sequence>
    <xs:element name=""InternetMessageHeader""
      type=""t:InternetHeaderType""
      maxOccurs=""unbounded""
     />
  </xs:sequence>
</xs:complexType>");

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

            // Verify MS-OXWSCORE requirement: MS-OXWSCORE_R20301
            // MS-OXWSCORE_R1325 is captured, this requirement can be captured directly.
            this.Site.CaptureRequirement(
                20301,
                @"[In t:ItemType Complex Type] It [InternetMessageHeaders] can be retrieved by GetItem (section 3.1.4.4) operation.");

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

            // Verify MS-OXWSCORE requirement: MS-OXWSCORE_R1367
            // The schema is validated and InternetMessageHeaders is not null, so this requirement can be captured.
            this.Site.CaptureRequirement(
                1367,
                @"[In t:NonEmptyArrayOfInternetHeadersType Complex Type] The type of InternetMessageHeader is t:InternetHeaderType([MS-OXWSCDATA] section 2.2.4.35).");

            foreach (InternetHeaderType internetMessageHeader in getItems.Items.Items[0].InternetMessageHeaders)
            {
                // Add the debug information
                this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXWSCDATA_R1674");

                // Verify MS-OXWSCDATA requirement: MS-OXWSCDATA_R1674
                // The schema is validated and the internetMessageHeader is not null, so this requirement can be captured.
                this.Site.CaptureRequirementIfIsNotNull(
                    internetMessageHeader,
                    "MS-OXWSCDATA",
                    1674,
                    @"[In t:InternetHeaderType Complex Type] The attribute ""HeaderName"" is ""xs:string"" type.");

                // Add the debug information
                this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXWSCORE_R88");
                this.Site.Log.Add(LogEntryKind.Debug, "The HeaderName should not be null, actual {0}.", internetMessageHeader.HeaderName);
                this.Site.Log.Add(LogEntryKind.Debug, "The Value should not be null, actual {0}.", internetMessageHeader.Value);

                // Verify MS-OXWSCORE requirement: MS-OXWSCORE_R88
                // The schema is validated and the child elements in internetMessageHeader are not null, so this requirement can be captured.
                bool isVerifiedR88 = internetMessageHeader.HeaderName != null && internetMessageHeader.Value != null;

                this.Site.CaptureRequirementIfIsTrue(
                    isVerifiedR88,
                    88,
                    @"[In t:ItemType Complex Type] [The element ""InternetMessageHeaders""] Specifies an array of the type InternetHeaderType that represents the collection of all Internet message headers that are contained in an item in a mailbox.");

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

                // Verify MS-OXWSCORE requirement: MS-OXWSCORE_R124
                this.Site.CaptureRequirement(
                    124,
                    @"[In t:NonEmptyArrayOfInternetHeadersType Complex Type] [The element ""InternetMessageHeader""] Specifies a single Internet message header.");
            }

            EntityExtractionResultType entityExtractionResult = getItems.Items.Items[0].EntityExtractionResult;

            // Verify EntityExtractionResultType structure.
            this.VerifyEntityExtractionResultType(entityExtractionResult);

            // Verify ArrayOfAddressEntitiesType structure.
            this.VerifyArrayOfAddressEntitiesType(entityExtractionResult.Addresses, address);

            // Verify ArrayOfMeetingSuggestionsType structure.
            // "2:00pm, December 15th, 2012" is supposed to be "2012/12/15 14:00:00" in dataTime type.
            // "2:30pm, December 15th, 2012" is supposed to be "2012/12/15 14:30:00" in dataTime type.
            this.VerifyArrayOfMeetingSuggestionsType(entityExtractionResult.MeetingSuggestions, meetingSuggestions, DateTime.Parse("2012/12/15 14:00:00"), DateTime.Parse("2012/12/15 14:30:00"), Common.GetConfigurationPropertyValue("User1Name", this.Site), userEmailAddress);

            // Verify ArrayOfTaskSuggestionsType structure.
            this.VerifyArrayOfTaskSuggestionsType(entityExtractionResult.TaskSuggestions, taskSuggestions, Common.GetConfigurationPropertyValue("User1Name", this.Site), userEmailAddress);

            // Verify ArrayOfEmailAddressEntitiesType structure.
            this.VerifyArrayOfEmailAddressEntitiesType(entityExtractionResult.EmailAddresses, emailAddress);

            // Verify ArrayOfContactsType structure.
            Uri uri = new Uri(url);
            this.VerifyArrayOfContactsType(entityExtractionResult.Contacts, contactDisplayName, businessName, uri, phoneNumbers, phoneNumberType, emailAddress, address);

            // Verify ArrayOfUrlEntitiesType structure.
            this.VerifyArrayOfUrlEntitiesType(entityExtractionResult.Urls, uri);

            // Verify ArrayOfPhoneEntitiesType structure.
            this.VerifyArrayOfPhoneEntitiesType(entityExtractionResult.PhoneNumbers, phoneNumbers, phoneNumberType);
            #endregion
        }