/// <summary> /// Loop to find the item with the specified subject. /// </summary> /// <param name="folderName">Name of the specified folder.</param> /// <param name="itemSubject">Subject of the specified item.</param> /// <param name="itemType">Type of the specified item.</param> /// <returns>Item with the specified subject.</returns> private ItemType LoopToFindItem(DistinguishedFolderIdNameType folderName, string itemSubject, Item itemType) { ItemType[] items = null; ItemType firstFoundItem = null; int sleepTimes = 0; // Get the query sleep delay and times from ptfconfig file. int queryDelay = int.Parse(Common.GetConfigurationPropertyValue("WaitTime", this.Site)); int queryTimes = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site)); // Loop to find the item, in case that the sent item has still not been received. do { Thread.Sleep(queryDelay); items = this.FindAllItems(folderName); sleepTimes++; }while (items == null && sleepTimes < queryTimes); ItemType type = null; switch (itemType) { case Item.MeetingRequest: type = new MeetingRequestMessageType(); break; case Item.MeetingResponse: type = new MeetingResponseMessageType(); break; case Item.MeetingCancellation: type = new MeetingCancellationMessageType(); break; case Item.CalendarItem: type = new CalendarItemType(); break; } if (items != null) { // Find the item with the specified subject and store its ID. for (int i = 0; i < items.Length; i++) { if (items[i].Subject.Contains(itemSubject) && items[i].GetType().ToString() == type.ToString()) { firstFoundItem = items[i]; break; } } } return(firstFoundItem); }
/// <summary> /// Log on to a mailbox with a specified user account and find the specified meeting message in the Inbox folder, then accept it. /// </summary> /// <param name="userName">Name of the user.</param> /// <param name="userPassword">Password of the user.</param> /// <param name="userDomain">Domain of the user.</param> /// <param name="itemSubject">Subject of the meeting message which should be accepted.</param> /// <param name="itemType">Type of the item which should be accepted.</param> /// <returns>If the specified meeting message is accepted successfully, return true; otherwise, return false.</returns> public bool FindAndAcceptMeetingMessage(string userName, string userPassword, string userDomain, string itemSubject, string itemType) { // Define the Inbox folder as parent folder. DistinguishedFolderIdNameType parentFolderIdName = DistinguishedFolderIdNameType.inbox; // Switch to specified user mailbox. bool isSwitched = AdapterHelper.SwitchUser(userName, userPassword, userDomain, this.exchangeServiceBinding, this.Site); Site.Assert.IsTrue( isSwitched, string.Format("Log on mailbox with the UserName: {0}, Password: {1}, Domain: {2} should be successful.", userName, userPassword, userDomain)); Item item = (Item)Enum.Parse(typeof(Item), itemType, true); // Loop to find the specified item in the specified folder. ItemType type = this.LoopToFindItem(parentFolderIdName, itemSubject, item); bool isAccepted = false; if (type != null) { MeetingRequestMessageType message = type as MeetingRequestMessageType; // Create a request for the CreateItem operation. CreateItemType createItemRequest = new CreateItemType(); // Add the CalendarItemType item to the items to be created. createItemRequest.Items = new NonEmptyArrayOfAllItemsType(); // Create an AcceptItemType item to reply to a meeting request. AcceptItemType acceptItem = new AcceptItemType(); // Set the related meeting request. acceptItem.ReferenceItemId = message.ItemId; createItemRequest.Items.Items = new ItemType[] { acceptItem }; // Set the MessageDisposition property to SendOnly. createItemRequest.MessageDisposition = MessageDispositionType.SendOnly; createItemRequest.MessageDispositionSpecified = true; // Invoke the CreateItem operation. CreateItemResponseType createItemResponse = this.exchangeServiceBinding.CreateItem(createItemRequest); if (createItemResponse != null && createItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success) { isAccepted = true; } } return(isAccepted); }
public void MSOXWSMTGS_S04_TC02_MoveMeeting() { #region Define the target folder to move // Define the Inbox folder as the target folder for moving meeting item. DistinguishedFolderIdType inboxFolder = new DistinguishedFolderIdType(); inboxFolder.Id = DistinguishedFolderIdNameType.inbox; TargetFolderIdType meetingTargetFolder = new TargetFolderIdType(); meetingTargetFolder.Item = inboxFolder; // Define the Calendar folder as the target folder for moving meeting request message, meeting response message and meeting cancellation message. DistinguishedFolderIdType calendarFolder = new DistinguishedFolderIdType(); calendarFolder.Id = DistinguishedFolderIdNameType.calendar; TargetFolderIdType msgTargetFolder = new TargetFolderIdType(); msgTargetFolder.Item = calendarFolder; #endregion #region Organizer creates a meeting with CalendarItemCreateOrDeleteOperationType value set to SendOnlyToAll #region Define a meeting to be moved CalendarItemType meetingItem = new CalendarItemType(); meetingItem.Subject = this.Subject; meetingItem.UID = Guid.NewGuid().ToString(); meetingItem.RequiredAttendees = new AttendeeType[] { GetAttendeeOrResource(this.AttendeeEmailAddress) }; meetingItem.OptionalAttendees = new AttendeeType[] { GetAttendeeOrResource(this.OrganizerEmailAddress) }; meetingItem.Resources = new AttendeeType[] { GetAttendeeOrResource(this.RoomEmailAddress) }; #endregion ItemInfoResponseMessageType item = this.CreateSingleCalendarItem(Role.Organizer, meetingItem, CalendarItemCreateOrDeleteOperationType.SendOnlyToAll); ItemIdType meetingId = item.Items.Items[0].ItemId; #endregion #region Organizer moves the meeting item to Inbox folder ItemInfoResponseMessageType movedItem = this.MoveSingleCalendarItem(Role.Organizer, meetingId, meetingTargetFolder); Site.Assert.AreEqual <ResponseClassType>( ResponseClassType.Success, movedItem.ResponseClass, "Server should return success for moving the meeting item."); ItemIdType movedMeetingItemId = movedItem.Items.Items[0].ItemId; #endregion #region Organizer calls FindItem to verify the meeting item is moved to Inbox folder CalendarItemType calendar = this.SearchSingleItem(Role.Organizer, DistinguishedFolderIdNameType.inbox, "IPM.Appointment", meetingItem.UID) as CalendarItemType; Site.Assert.IsNotNull(calendar, "The meeting item should be moved into organizer's Inbox folder."); #endregion #region Attendee finds the meeting request message in his Inbox folder MeetingRequestMessageType request = this.SearchSingleItem(Role.Attendee, DistinguishedFolderIdNameType.inbox, "IPM.Schedule.Meeting.Request", meetingItem.UID) as MeetingRequestMessageType; Site.Assert.IsNotNull(request, "The meeting request message should exist in attendee's inbox folder."); #endregion #region Attendee moves the meeting request message to the Calendar folder movedItem = this.MoveSingleCalendarItem(Role.Attendee, request.ItemId, msgTargetFolder); Site.Assert.AreEqual <ResponseClassType>( ResponseClassType.Success, movedItem.ResponseClass, @"Server should return success for moving meeting request message."); #endregion #region Attendee calls FindItem to verify the meeting request message is moved to Calendar folder request = this.SearchSingleItem(Role.Attendee, DistinguishedFolderIdNameType.calendar, "IPM.Schedule.Meeting.Request", meetingItem.UID) as MeetingRequestMessageType; Site.Assert.IsNotNull(request, "The meeting request message should exist in attendee's calendar folder."); #endregion #region Attendee calls CreateItem to accept the meeting request with CalendarItemCreateOrDeleteOperationType value set to SendOnlyToAll AcceptItemType acceptItem = new AcceptItemType(); acceptItem.ReferenceItemId = request.ItemId; item = this.CreateSingleCalendarItem(Role.Attendee, acceptItem, CalendarItemCreateOrDeleteOperationType.SendOnlyToAll); #endregion #region Organizer finds the meeting response message in its Inbox folder MeetingResponseMessageType response = this.SearchSingleItem(Role.Organizer, DistinguishedFolderIdNameType.inbox, "IPM.Schedule.Meeting.Resp", meetingItem.UID) as MeetingResponseMessageType; Site.Assert.IsNotNull(response, "The meeting response message should exist in organizer's inbox folder."); #endregion #region Organizer moves the meeting response message to his Calendar folder movedItem = this.MoveSingleCalendarItem(Role.Organizer, response.ItemId, msgTargetFolder); Site.Assert.AreEqual <ResponseClassType>( ResponseClassType.Success, movedItem.ResponseClass, "EWS should return success for moving the meeting response message."); #endregion #region Organizer calls FindItem to verify the meeting response message is moved to Calendar folder response = this.SearchSingleItem(Role.Organizer, DistinguishedFolderIdNameType.calendar, "IPM.Schedule.Meeting.Resp", meetingItem.UID) as MeetingResponseMessageType; Site.Assert.IsNotNull(response, "The meeting response message should be in organizer's calendar folder."); #endregion #region Organizer calls DeleteItem to delete the meeting with CalendarItemCreateOrDeleteOperationType value set to SendOnlyToAll ResponseMessageType deletedItem = this.DeleteSingleCalendarItem(Role.Organizer, movedMeetingItemId, CalendarItemCreateOrDeleteOperationType.SendOnlyToAll); Site.Assert.IsNotNull(deletedItem, "Delete the meeting should be successful."); #endregion #region Attendee finds the meeting cancellation message in his Inbox folder MeetingCancellationMessageType canceledMeeting = this.SearchSingleItem(Role.Attendee, DistinguishedFolderIdNameType.inbox, "IPM.Schedule.Meeting.Canceled", meetingItem.UID) as MeetingCancellationMessageType; Site.Assert.IsNotNull(canceledMeeting, "The meeting cancellation message should be in attendee's inbox folder."); #endregion #region Attendee moves the meeting cancellation message to his Calendar folder movedItem = this.MoveSingleCalendarItem(Role.Attendee, canceledMeeting.ItemId, msgTargetFolder); Site.Assert.AreEqual <ResponseClassType>( ResponseClassType.Success, movedItem.ResponseClass, "EWS should return success for moving the meeting cancellation message."); #endregion #region Attendee calls FindItem to verify the meeting cancellation message is moved to Calendar folder canceledMeeting = this.SearchSingleItem(Role.Attendee, DistinguishedFolderIdNameType.calendar, "IPM.Schedule.Meeting.Canceled", meetingItem.UID) as MeetingCancellationMessageType; Site.Assert.IsNotNull(canceledMeeting, "The meeting cancellation message should be in attendee's calendar folder."); #endregion #region Attendee removes the meeting item RemoveItemType removeItem = new RemoveItemType(); removeItem.ReferenceItemId = canceledMeeting.ItemId; item = this.CreateSingleCalendarItem(Role.Attendee, removeItem, CalendarItemCreateOrDeleteOperationType.SendToNone); Site.Assert.IsNotNull(item, "The meeting item should be removed."); #endregion #region Clean up organizer's calendar and deleteditems folders, and attendee's sentitems and deleteditems folders this.CleanupFoldersByRole(Role.Organizer, new List <DistinguishedFolderIdNameType>() { DistinguishedFolderIdNameType.calendar, DistinguishedFolderIdNameType.deleteditems }); this.CleanupFoldersByRole(Role.Attendee, new List <DistinguishedFolderIdNameType>() { DistinguishedFolderIdNameType.sentitems, DistinguishedFolderIdNameType.deleteditems }); #endregion }
public void MSOXWSMTGS_S03_TC02_CopySingleMeetingItem() { #region Organizer creates a single meeting getItem with CalendarItemCreateOrDeleteOperationType value set to SendOnlyToAll CalendarItemType meetingItem = new CalendarItemType(); meetingItem.Subject = this.Subject; meetingItem.UID = Guid.NewGuid().ToString(); meetingItem.RequiredAttendees = new AttendeeType[] { GetAttendeeOrResource(this.AttendeeEmailAddress) }; meetingItem.OptionalAttendees = new AttendeeType[] { GetAttendeeOrResource(this.OrganizerEmailAddress) }; meetingItem.Resources = new AttendeeType[] { GetAttendeeOrResource(this.RoomEmailAddress) }; ItemInfoResponseMessageType item = this.CreateSingleCalendarItem(Role.Organizer, meetingItem, CalendarItemCreateOrDeleteOperationType.SendOnlyToAll); Site.Assert.IsNotNull(item, "Create single meeting item should be successful."); #endregion #region Organizer copies the created single meeting item to Drafts folder CalendarItemType calendar = this.SearchSingleItem(Role.Organizer, DistinguishedFolderIdNameType.calendar, "IPM.Appointment", meetingItem.UID) as CalendarItemType; Site.Assert.IsNotNull(calendar, "The created calendar should exist in organizer's calendar folder."); ItemIdType itemId = calendar.ItemId; DistinguishedFolderIdType folderId = new DistinguishedFolderIdType(); folderId.Id = DistinguishedFolderIdNameType.drafts; TargetFolderIdType targetFolderId = new TargetFolderIdType(); targetFolderId.Item = folderId; ItemInfoResponseMessageType copiedItem = this.CopySingleCalendarItem(Role.Organizer, itemId, targetFolderId); Site.Assert.IsNotNull(copiedItem, @"Copy the single meeting item should be successful."); #endregion #region Organizer calls GetItem operation to verify whether the meeting item is really copied calendar = this.SearchSingleItem(Role.Organizer, DistinguishedFolderIdNameType.drafts, "IPM.Appointment", meetingItem.UID) as CalendarItemType; Site.Assert.IsNotNull(calendar, "The copied calendar should exist in organizer's Drafts folder."); #endregion #region Attendee gets the meeting request message in the Inbox folder MeetingRequestMessageType request = this.SearchSingleItem(Role.Attendee, DistinguishedFolderIdNameType.inbox, meetingItem.Subject, meetingItem.UID, UnindexedFieldURIType.itemSubject) as MeetingRequestMessageType; Site.Assert.IsNotNull(request, "The meeting request message should exist in attendee's inbox folder."); #endregion #region Attendee copies the meeting request message to the Drafts folder copiedItem = this.CopySingleCalendarItem(Role.Attendee, request.ItemId, targetFolderId); Site.Assert.IsNotNull(copiedItem, @"Copy the single meeting request message should be successful."); #endregion #region Attendee calls CreateItem to accept the meeting request with CalendarItemCreateOrDeleteOperationType value set to SendOnlyToAll AcceptItemType acceptItem = new AcceptItemType(); acceptItem.ReferenceItemId = request.ItemId; Site.Assert.IsNotNull( this.CreateSingleCalendarItem(Role.Attendee, acceptItem, CalendarItemCreateOrDeleteOperationType.SendOnlyToAll), "Attendee creates items for meeting request should succeed."); #endregion #region Organizer finds the meeting response message in his Inbox folder and copies it to the Drafts folder MeetingResponseMessageType response = this.SearchSingleItem(Role.Organizer, DistinguishedFolderIdNameType.inbox, "IPM.Schedule.Meeting.Resp", meetingItem.UID) as MeetingResponseMessageType; Site.Assert.IsNotNull(response, "The response message from Attendee should be in organizer's Inbox folder."); copiedItem = this.CopySingleCalendarItem(Role.Organizer, response.ItemId, targetFolderId); Site.Assert.IsNotNull(copiedItem, @"Copy the single meeting response message should be successful."); #endregion #region Organizer deletes the meeting item with CalendarItemCreateOrDeleteOperationType value set to SendOnlyToAll ResponseMessageType deletedItem = this.DeleteSingleCalendarItem(Role.Organizer, itemId, CalendarItemCreateOrDeleteOperationType.SendOnlyToAll); Site.Assert.IsNotNull(deletedItem, @"Delete the single meeting item should be successful."); #endregion #region Attendee finds the meeting cancellation message in the Inbox folder and copies it to the Drafts folder int upperBound = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site)); int waitTime = int.Parse(Common.GetConfigurationPropertyValue("WaitTime", this.Site)); int count = 1; MeetingCancellationMessageType canceledItem = null; while (canceledItem == null && count++ <= upperBound) { canceledItem = this.SearchSingleItem(Role.Attendee, DistinguishedFolderIdNameType.inbox, "IPM.Schedule.Meeting.Canceled", meetingItem.UID) as MeetingCancellationMessageType; System.Threading.Thread.Sleep(waitTime); } Site.Assert.IsNotNull(canceledItem, "The cancellation meeting message should be in attendee's Inbox folder."); ItemIdType canceledItemId = canceledItem.ItemId; copiedItem = this.CopySingleCalendarItem(Role.Attendee, canceledItemId, targetFolderId); Site.Assert.IsNotNull(copiedItem, "Attendee should copy the meeting cancellation message to the Drafts folder."); #endregion #region Clean up inbox, drafts and deleteditems folders of both organizer and attendee. Attendee's sentitems and calendar should also be cleaned up. this.CleanupFoldersByRole(Role.Organizer, new List <DistinguishedFolderIdNameType>() { DistinguishedFolderIdNameType.inbox, DistinguishedFolderIdNameType.drafts, DistinguishedFolderIdNameType.deleteditems }); this.CleanupFoldersByRole(Role.Attendee, new List <DistinguishedFolderIdNameType>() { DistinguishedFolderIdNameType.inbox, DistinguishedFolderIdNameType.calendar, DistinguishedFolderIdNameType.sentitems, DistinguishedFolderIdNameType.drafts, DistinguishedFolderIdNameType.deleteditems }); #endregion }
/// <summary> /// Log on a mailbox with a specified user account and check whether the specified item exists. /// </summary> /// <param name="userName">Name of the user.</param> /// <param name="userPassword">Password of the user.</param> /// <param name="userDomain">Domain of the user.</param> /// <param name="folderName">Name of the folder which should be searched for the specified item.</param> /// <param name="itemSubject">Subject of the item which should exist.</param> /// <param name="itemType">Type of the item which should exist.</param> /// <returns>If the item exists, return true; otherwise, return false.</returns> public bool IsItemExisting(string userName, string userPassword, string userDomain, string folderName, string itemSubject, string itemType) { bool isExisting = false; // Parse the parent folder name to DistinguishedFolderIdNameType. DistinguishedFolderIdNameType parentFolderIdName = (DistinguishedFolderIdNameType)Enum.Parse(typeof(DistinguishedFolderIdNameType), folderName, true); // Switch to specified user mailbox. bool isSwitched = AdapterHelper.SwitchUser(userName, userPassword, userDomain, this.exchangeServiceBinding, this.Site); Site.Assert.IsTrue( isSwitched, string.Format("Log on mailbox with the UserName: {0}, Password: {1}, Domain: {2} should be successful.", userName, userPassword, userDomain)); Item item = (Item)Enum.Parse(typeof(Item), itemType, true); // Loop to find the specified item ItemType type = this.LoopToFindItem(parentFolderIdName, itemSubject, item); if (type != null) { switch (item) { case Item.MeetingRequest: MeetingRequestMessageType requestMessage = type as MeetingRequestMessageType; if (requestMessage != null) { isExisting = true; } break; case Item.MeetingResponse: MeetingResponseMessageType responseMessage = type as MeetingResponseMessageType; if (responseMessage != null) { isExisting = true; } break; case Item.MeetingCancellation: MeetingCancellationMessageType cancellationMessage = type as MeetingCancellationMessageType; if (cancellationMessage != null) { isExisting = true; } break; case Item.CalendarItem: CalendarItemType calendarItem = type as CalendarItemType; if (calendarItem != null) { isExisting = true; } break; } } return(isExisting); }