コード例 #1
0
        /// <summary>
        /// Basic CRUD operations test.
        /// </summary>
        /// <param name="exchangeService"></param>
        public static void CreateReadUpdateDeleteMailFolder(ExchangeService exchangeService)
        {
            exchangeService.MailboxId = new MailboxId(AppConfig.MailboxA);

            foreach (MailFolder folder in exchangeService.FindFolders(WellKnownFolderName.Inbox, new FolderView(10)))
            {
                folder.Delete();
            }

            MailFolder folder1 = new MailFolder(exchangeService)
            {
                DisplayName = "MyTestFolder1"
            };

            Assert.IsNull(folder1.Id);
            folder1.Save(WellKnownFolderName.Inbox);
            Assert.IsNotNull(folder1.Id);

            MailFolder folder2 = new MailFolder(exchangeService);

            folder2.DisplayName = "MyTestFolder2";

            Assert.IsNull(folder2.Id);
            folder2.Save(WellKnownFolderName.Inbox);
            Assert.IsNotNull(folder2.Id);

            Thread.Sleep(5000);

            folder2 = folder2.Move(folder1.Id);

            folder1.DisplayName = "NewDisplayName";
            folder1.Update();

            Assert.AreEqual(
                "NewDisplayName",
                folder1.DisplayName);

            Assert.AreEqual(
                folder1.Id,
                folder2.ParentFolderId);

            folder2.Delete();
            Assert.IsNull(folder2.DisplayName);
            Assert.IsNull(folder2.Id);

            folder1.Delete();
            Assert.IsNull(folder1.DisplayName);
            Assert.IsNull(folder1.Id);
        }
コード例 #2
0
        /// <summary>
        /// Test mail folder sync.
        /// </summary>
        /// <param name="exchangeService"></param>
        public static void SyncMailFolders(ExchangeService exchangeService)
        {
            string folder1Name = "TempSyncFolder1";
            string folder2Name = "TempSyncFolder2";

            exchangeService.MailboxId = new MailboxId(AppConfig.MailboxA);

            FindFoldersResults findFolders = exchangeService.FindFolders(
                WellKnownFolderName.MsgFolderRoot,
                new FolderView(30));

            foreach (MailFolder mailFolder in findFolders)
            {
                if (mailFolder.DisplayName == folder1Name ||
                    mailFolder.DisplayName == folder2Name)
                {
                    mailFolder.Delete();
                }
            }

            string syncState = null;
            int    counter   = 0;
            SyncMailFolderHierarchyResponse sync;

            do
            {
                sync      = exchangeService.SyncFolderHierarchy(syncState);
                syncState = sync.SyncState;

                counter++;
            } while (sync.MoreAvailable || counter == 4);

            Assert.IsFalse(sync.MoreAvailable);

            MailFolder folder1 = new MailFolder(exchangeService);

            folder1.DisplayName = folder1Name;
            folder1.Save(WellKnownFolderName.MsgFolderRoot);

            MailFolder folder2 = new MailFolder(exchangeService);

            folder2.DisplayName = folder2Name;
            folder2.Save(WellKnownFolderName.MsgFolderRoot);

            sync      = exchangeService.SyncFolderHierarchy(syncState);
            syncState = sync.SyncState;

            Assert.AreEqual(
                2,
                sync.TotalCount);

            foreach (ItemChange <MailFolder> change in sync)
            {
                Assert.IsTrue(change.ChangeType == SyncChangeType.Created);
            }

            folder1.Delete();
            folder2.Delete();

            sync = exchangeService.SyncFolderHierarchy(syncState);

            Assert.IsTrue(sync.TotalCount == 2);
            foreach (ItemChange <MailFolder> change in sync)
            {
                Assert.IsTrue(change.ChangeType == SyncChangeType.Deleted);
            }
        }
コード例 #3
0
        /// <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();
        }