Beispiel #1
0
        /// <summary>
        /// Find message call.
        /// </summary>
        public static async Task FindMessage(ExchangeService exchangeService)
        {
            string folderName = "TestFindItemFolder";
            await FunctionalTestHelpers.DeleteFolderIfExist(
                folderName,
                exchangeService,
                WellKnownFolderName.MsgFolderRoot);

            MailFolder folder = await FunctionalTestHelpers.CreateFolder(
                folderName,
                exchangeService,
                WellKnownFolderName.MsgFolderRoot);

            for (int i = 0; i < 9; i++)
            {
                await FunctionalTestHelpers.CreateMessage(
                    1,
                    folder,
                    exchangeService);
            }

            for (int i = 0; i < 10; i++)
            {
                await FunctionalTestHelpers.CreateMessage(
                    i,
                    folder,
                    exchangeService);
            }

            // there are 10 "Test msg 1" and 9 others. Expecting to see
            // sync 5 times.
            SearchFilter subjectFilter = new SearchFilter.IsEqualTo(
                MessageObjectSchema.Subject,
                "Test msg 1");

            MessageView mv = new MessageView(2);
            FindItemResults <Message> items = null;
            int counter = 0;

            do
            {
                items = await exchangeService.FindItems(
                    folder.Id,
                    mv,
                    subjectFilter);

                mv.Offset += mv.PageSize;
                counter++;
            } while (items.MoreAvailable);

            Assert.AreEqual(
                6,
                counter);
        }
Beispiel #2
0
        /// <summary>
        /// Create, read, update, delete message.
        /// </summary>
        /// <param name="exchangeService">Exchange service.</param>
        /// <returns></returns>
        public static async Task CreateReadUpdateDeleteMessage(ExchangeService exchangeService)
        {
            string folderName = "TestCrudItems";
            await FunctionalTestHelpers.DeleteFolderIfExist(
                folderName,
                exchangeService,
                WellKnownFolderName.MsgFolderRoot);

            MailFolder mailFolder = await FunctionalTestHelpers.CreateFolder(
                folderName,
                exchangeService,
                WellKnownFolderName.MsgFolderRoot);

            for (int i = 0; i < 10; i++)
            {
                Message msg = new Message(exchangeService);
                msg.Subject = Guid.NewGuid().ToString();
                msg.Body    = new ItemBody()
                {
                    ContentType = BodyType.Html,
                    Content     = $"body {Guid.NewGuid().ToString()}"
                };

                await msg.SaveAsync(mailFolder);
            }

            FindItemResults <Message> items = await exchangeService.FindItems(mailFolder.Id, new MessageView(12));

            Assert.AreEqual(
                10,
                items.TotalCount);

            foreach (Message item in items)
            {
                item.Subject = $"Changed subject - {item.Subject}";
                await item.UpdateAsync();
            }

            items = await exchangeService.FindItems(mailFolder.Id, new MessageView(12));

            foreach (Message item in items)
            {
                Assert.IsTrue(
                    item.Subject.StartsWith("Changed subject -"));

                await item.DeleteAsync();
            }
        }
Beispiel #3
0
        /// <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();
        }