/// <summary> /// Define general CreateItem request message /// </summary> /// <param name="messageDisposition">A value specifies how a message item is handled after it is created or updated</param> /// <param name="savedTargetFolderName">The folder in which new items are saved</param> /// <returns>A request to create an item</returns> protected CreateItemType GetCreateItemType(MessageDispositionType messageDisposition, DistinguishedFolderIdNameType savedTargetFolderName) { CreateItemType createItemRequest = new CreateItemType { MessageDisposition = messageDisposition, MessageDispositionSpecified = true, SavedItemFolderId = new TargetFolderIdType { Item = new DistinguishedFolderIdType { Id = savedTargetFolderName } }, Items = new NonEmptyArrayOfAllItemsType { Items = new MessageType[] { new MessageType { Sender = new SingleRecipientType { Item = new EmailAddressType { EmailAddress = this.sender } }, ToRecipients = new EmailAddressType[] { new EmailAddressType { EmailAddress = this.recipient1 } }, Subject = this.subject, } } }, }; return(createItemRequest); }
/// <summary> /// Create an item in the specified folder. /// </summary> /// <param name="parentFolderType">Type of the parent folder.</param> /// <param name="parentFolderId">ID of the parent folder.</param> /// <param name="itemSubject">Subject of the item which should be created.</param> /// <returns>ID of the created item.</returns> protected ItemIdType CreateItem(DistinguishedFolderIdNameType parentFolderType, string parentFolderId, string itemSubject) { // Create a request for the CreateItem operation and initialize the ItemType instance. CreateItemType createItemRequest = new CreateItemType(); ItemType item = null; // Get different values for item based on different parent folder type. switch (parentFolderType) { case DistinguishedFolderIdNameType.contacts: ContactItemType contact = new ContactItemType(); contact.Subject = itemSubject; contact.FileAs = itemSubject; item = contact; break; case DistinguishedFolderIdNameType.calendar: // Set the sendMeetingInvitations property. CalendarItemCreateOrDeleteOperationType sendMeetingInvitations = CalendarItemCreateOrDeleteOperationType.SendToNone; createItemRequest.SendMeetingInvitations = (CalendarItemCreateOrDeleteOperationType)sendMeetingInvitations; createItemRequest.SendMeetingInvitationsSpecified = true; CalendarItemType calendar = new CalendarItemType(); calendar.Subject = itemSubject; item = calendar; break; case DistinguishedFolderIdNameType.inbox: MessageType message = new MessageType(); message.Subject = itemSubject; item = message; break; case DistinguishedFolderIdNameType.tasks: TaskType taskItem = new TaskType(); taskItem.Subject = itemSubject; item = taskItem; break; default: Site.Assert.Fail("The parent folder type '{0}' is invalid and the valid folder types are: contacts, calendar, inbox and tasks.", parentFolderType.ToString()); break; } // Set the MessageDisposition property. MessageDispositionType messageDisposition = MessageDispositionType.SaveOnly; createItemRequest.MessageDisposition = (MessageDispositionType)messageDisposition; createItemRequest.MessageDispositionSpecified = true; // Specify the folder in which new items are saved. createItemRequest.SavedItemFolderId = new TargetFolderIdType(); FolderIdType folderId = new FolderIdType(); folderId.Id = parentFolderId; createItemRequest.SavedItemFolderId.Item = folderId; // Specify the collection of items to be created. createItemRequest.Items = new NonEmptyArrayOfAllItemsType(); createItemRequest.Items.Items = new ItemType[] { item }; // Initialize the ID of the created item. ItemIdType createdItemId = null; // Invoke the create item operation and get the response. CreateItemResponseType createItemResponse = this.COREAdapter.CreateItem(createItemRequest); if (createItemResponse != null && createItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success) { ItemInfoResponseMessageType info = createItemResponse.ResponseMessages.Items[0] as ItemInfoResponseMessageType; Site.Assert.IsNotNull(info, "The items in CreateItem response should not be null."); // Get the ID of the created item. createdItemId = info.Items.Items[0].ItemId; } return(createdItemId); }
/// <summary> /// Verify the validation of a response of CreateItem operation returned by server. /// </summary> /// <param name="createItemResponse">A response of CreateItem operation returned by server.</param> /// <param name="messageDisposition">A value specifies how a message item is handled after it is created or updated.</param> /// <returns>The validation result.</returns> protected bool VerifyCreateItemResponse(CreateItemResponseType createItemResponse, MessageDispositionType messageDisposition) { bool isValidCreateResponse = false; if (this.VerifyResponse(createItemResponse)) { this.infoItems = TestSuiteHelper.GetInfoItemsInResponse(createItemResponse); Site.Assert.IsNotNull(this.infoItems, @"The CreateItem response should contain one or more items of ItemInfoResponseMessageType."); switch (messageDisposition) { case MessageDispositionType.SaveOnly: this.firstItemOfFirstInfoItem = TestSuiteHelper.GetItemTypeItemFromInfoItemsByIndex(this.infoItems, 0, 0); Site.Assert.IsNotNull(this.firstItemOfFirstInfoItem, @"The first item of the array of ItemType type returned from server response should not be null."); Site.Assert.IsNotNull(this.firstItemOfFirstInfoItem.ItemId, @"The ItemId property of the first item should not be null."); isValidCreateResponse = true; break; case MessageDispositionType.SendAndSaveCopy: case MessageDispositionType.SendOnly: Site.Assert.IsTrue(this.infoItems.Length > 0, "infoItems instance should contain at least one item."); Site.Assert.IsNotNull(this.infoItems[0], "The first item of infoItems instance should not be null."); Site.Assert.IsNotNull(this.infoItems[0].Items, "The Items property of the first item of infoItems instance should not be null."); break; } isValidCreateResponse = true; } return(isValidCreateResponse); }
/// <summary> /// Verify the validation of a response of CreateItem operation returned by server. /// </summary> /// <param name="createItemResponse">A response of CreateItem operation returned by server.</param> /// <param name="messageDisposition">A value specifies how a message item is handled after it is created or updated.</param> /// <returns>The validation result.</returns> protected bool VerifyCreateItemResponse(CreateItemResponseType createItemResponse, MessageDispositionType messageDisposition) { bool isValidCreateResponse = false; if (this.VerifyResponse(createItemResponse)) { this.infoItems = TestSuiteHelper.GetInfoItemsInResponse(createItemResponse); Site.Assert.IsNotNull(this.infoItems, @"The CreateItem response should contain one or more items of ItemInfoResponseMessageType."); switch (messageDisposition) { case MessageDispositionType.SaveOnly: this.firstItemOfFirstInfoItem = TestSuiteHelper.GetItemTypeItemFromInfoItemsByIndex(this.infoItems, 0, 0); Site.Assert.IsNotNull(this.firstItemOfFirstInfoItem, @"The first item of the array of ItemType type returned from server response should not be null."); Site.Assert.IsNotNull(this.firstItemOfFirstInfoItem.ItemId, @"The ItemId property of the first item should not be null."); isValidCreateResponse = true; break; case MessageDispositionType.SendAndSaveCopy: case MessageDispositionType.SendOnly: Site.Assert.IsTrue(this.infoItems.Length > 0, "infoItems instance should contain at least one item."); Site.Assert.IsNotNull(this.infoItems[0], "The first item of infoItems instance should not be null."); Site.Assert.IsNotNull(this.infoItems[0].Items, "The Items property of the first item of infoItems instance should not be null."); break; } isValidCreateResponse = true; } return isValidCreateResponse; }
/// <summary> /// Define general CreateItem request message /// </summary> /// <param name="messageDisposition">A value specifies how a message item is handled after it is created or updated</param> /// <param name="savedTargetFolderName">The folder in which new items are saved</param> /// <returns>A request to create an item</returns> protected CreateItemType GetCreateItemType(MessageDispositionType messageDisposition, DistinguishedFolderIdNameType savedTargetFolderName) { CreateItemType createItemRequest = new CreateItemType { MessageDisposition = messageDisposition, MessageDispositionSpecified = true, SavedItemFolderId = new TargetFolderIdType { Item = new DistinguishedFolderIdType { Id = savedTargetFolderName } }, Items = new NonEmptyArrayOfAllItemsType { Items = new MessageType[] { new MessageType { Sender = new SingleRecipientType { Item = new EmailAddressType { EmailAddress = this.sender } }, ToRecipients = new EmailAddressType[] { new EmailAddressType { EmailAddress = this.recipient1 } }, Subject = this.subject, } } }, }; return createItemRequest; }