/// <summary> /// Sync messages /// </summary> public static async Task SyncMessages(ExchangeService exchangeService) { string folderName = "TempSyncFolder"; await FunctionalTestHelpers.DeleteFolderIfExist( folderName, exchangeService, WellKnownFolderName.MsgFolderRoot); MailFolder folder = await FunctionalTestHelpers.CreateFolder( folderName, exchangeService, WellKnownFolderName.MsgFolderRoot); for (int i = 0; i < 10; i++) { await FunctionalTestHelpers.CreateMessage( i, folder, exchangeService); } string syncState = null; MessagePropertySet propertySet = new MessagePropertySet(); propertySet.Add(MessageObjectSchema.ToRecipients); ChangeCollection <MessageChange> syncCollection; int counter = 0; int numberOfMessages = 0; do { syncCollection = await exchangeService.SyncFolderItems( folder.Id, propertySet, syncState); syncState = syncCollection.SyncState; numberOfMessages += syncCollection.TotalCount; counter++; foreach (MessageChange itemChange in syncCollection.Items) { Assert.IsTrue( itemChange.ChangeType == ChangeType.Created); } } while (syncCollection.MoreAvailable || counter == 4); Assert.IsFalse(syncCollection.MoreAvailable); Assert.AreEqual(10, numberOfMessages); FindItemResults <Message> items = await exchangeService.FindItems(folder.Id, new MessageView(4)); for (int i = 0; i < items.TotalCount; i++) { Message msg = items.Items[i]; if (i < 2) { msg.IsRead = false; await msg.UpdateAsync(); } else { await msg.DeleteAsync(); } } syncCollection = await exchangeService.SyncFolderItems( folder.Id, propertySet, syncState); Assert.IsFalse(syncCollection.MoreAvailable); Assert.IsTrue( syncCollection.TotalCount == 4); int changes = syncCollection.Items.Count(i => i.ChangeType == ChangeType.Deleted); Assert.AreEqual( 2, changes); changes = syncCollection.Items.Count(i => i.ChangeType == ChangeType.Updated); Assert.IsTrue(changes == 2); await folder.DeleteAsync(); }
public void MessagePropertySetProperties() { MessagePropertySet messagePropertySet = new MessagePropertySet(); Assert.IsNull(messagePropertySet.Properties); Assert.IsTrue( messagePropertySet.FirstClassProperties.Contains(nameof(Entity.Id))); Assert.IsTrue( messagePropertySet.FirstClassProperties.Contains(nameof(Message.IsRead))); Assert.IsTrue( messagePropertySet.FirstClassProperties.Contains(nameof(Message.Subject))); Assert.IsTrue( messagePropertySet.FirstClassProperties.Contains(nameof(Message.ParentFolderId))); messagePropertySet.AddProperty(nameof(Message.Body)); // First class properties + one added Assert.IsTrue(messagePropertySet.Properties.Properties.Length == 5); Assert.ThrowsException <ArgumentException>(() => { messagePropertySet.AddProperty("NonExistingProp"); }); messagePropertySet.AddProperties(new [] { nameof(Message.BodyPreview), nameof(Message.CcRecipients) }); Assert.IsTrue(messagePropertySet.Properties.Properties.Length == 7); messagePropertySet.Add(new ExtendedPropertyDefinition( MapiPropertyType.String, 3421)); Assert.AreEqual( "$expand=SingleValueExtendedProperties($filter=PropertyId eq 'String 0x0D5D')", messagePropertySet.ExpandQuery.Query); messagePropertySet = new MessagePropertySet(); Assert.IsNull(messagePropertySet.Properties); Assert.IsNull(messagePropertySet.ExpandQuery); messagePropertySet.Add(new ExtendedPropertyDefinition(MapiPropertyType.StringArray, 3421)); Assert.AreEqual( "$expand=MultiValueExtendedProperties($filter=PropertyId eq 'StringArray 0x0D5D')", messagePropertySet.ExpandQuery.Query); messagePropertySet.Add(new ExtendedPropertyDefinition( MapiPropertyType.String, 3421)); Assert.AreEqual( "$expand=SingleValueExtendedProperties($filter=PropertyId eq 'String 0x0D5D'),MultiValueExtendedProperties($filter=PropertyId eq 'StringArray 0x0D5D')", messagePropertySet.ExpandQuery.Query); messagePropertySet.Add(new ExtendedPropertyDefinition( MapiPropertyType.Boolean, 0x0E1F)); Assert.AreEqual( "$expand=SingleValueExtendedProperties($filter=PropertyId eq 'String 0x0D5D' or PropertyId eq 'Boolean 0x0E1F'),MultiValueExtendedProperties($filter=PropertyId eq 'StringArray 0x0D5D')", messagePropertySet.ExpandQuery.Query); }
/// <summary> /// Sync messages /// </summary> public static void SyncMessages(ExchangeService exchangeService) { string folderName = "TempSyncFolder"; TestHelpers.DeleteFolderIfExist( folderName, exchangeService, WellKnownFolderName.MsgFolderRoot); MailFolder folder = TestHelpers.CreateFolder( folderName, exchangeService, WellKnownFolderName.MsgFolderRoot); for (int i = 0; i < 10; i++) { TestHelpers.CreateMessage( i, folder.FolderId, exchangeService); } string syncState = null; MessagePropertySet propertySet = new MessagePropertySet(); propertySet.AddProperty("ToRecipients"); SyncFolderItemsCollection <Item> syncCollection; int counter = 0; int numberOfMessages = 0; do { syncCollection = exchangeService.SyncFolderItems( folder.FolderId, propertySet, 4, syncState); syncState = syncCollection.SyncState; numberOfMessages += syncCollection.TotalCount; counter++; foreach (ItemChange <Item> itemChange in syncCollection) { Assert.IsTrue( itemChange.ChangeType == SyncChangeType.Created); } } while (syncCollection.MoreAvailable || counter == 4); Assert.IsFalse(syncCollection.MoreAvailable); Assert.AreEqual(10, numberOfMessages); FindItemsResults <Item> items = exchangeService.FindItems(folder.FolderId, new MessageView(4)); for (int i = 0; i < items.TotalCount; i++) { Message msg = (Message)items.Items[i]; if (i < 2) { msg.IsRead = false; msg.Update(); } else { msg.Delete(); } } syncCollection = exchangeService.SyncFolderItems( folder.FolderId, propertySet, 10, syncState); Assert.IsFalse(syncCollection.MoreAvailable); Assert.IsTrue( syncCollection.TotalCount == 4); int changes = syncCollection.Items.Count(i => i.ChangeType == SyncChangeType.Deleted); Assert.AreEqual( 2, changes); changes = syncCollection.Items.Count(i => i.ChangeType == SyncChangeType.ReadFlagChanged); Assert.IsTrue(changes == 2); folder.Delete(); }