示例#1
0
        public void MessagesArrive()
        {
            var scheduler = new TestScheduler();

            Core.Dependencies.TimeScheduler = scheduler;

            int folderMsgCount    = -1;
            int folderUnreadCount = -1;

            int msgCount = -1;

            // Wait for the inbox to appear
            var findInbox = server_.AllFolders.Select((folders) =>
            {
                return(folders.Where(folder => folder.FullName == "INBOX").FirstOrDefault());
            })
                            .Where(folder => folder != null)
                            .Take(1);

            // Now subscribe to interesting parts of the inbox
            findInbox.Subscribe(folder =>
            {
                server_.SelectFolder(folder);

                folder.Exists.Subscribe(val => folderMsgCount    = val);
                folder.Unseen.Subscribe(val => folderUnreadCount = val);

                folder.Messages.Subscribe(msgs =>
                {
                    msgCount = msgs.Count();
                });
            });

            // Now start feeding the server with fake data.

            // Get the Inbox to appear
            var inbox = new Folder(server_, "INBOX", "INBOX", ".", false, true);

            testServer_.AddFolder(inbox);

            // Add a message to it.
            var msg1 = new MessageHeader(1, inbox);

            inbox.AddMessage(msg1);

            scheduler.AdvanceBy(TimeSpan.FromSeconds(1).Ticks);
            Assert.AreEqual(1, folderMsgCount);
            Assert.AreEqual(1, folderUnreadCount);
            Assert.AreEqual(1, msgCount);

            // Add another message to it.
            var msg2 = new MessageHeader(2, inbox);

            inbox.AddMessage(msg2);

            scheduler.AdvanceBy(TimeSpan.FromSeconds(1).Ticks);
            Assert.AreEqual(2, folderMsgCount);
            Assert.AreEqual(2, folderUnreadCount);
            Assert.AreEqual(2, msgCount);

            // Mark the first message as read
            server_.SetFlag(msg1, MessageFlags.Seen, true);

            scheduler.AdvanceBy(TimeSpan.FromSeconds(1).Ticks);
            Assert.AreEqual(2, folderMsgCount);
            Assert.AreEqual(1, folderUnreadCount);
            Assert.AreEqual(2, msgCount);

            // Delete the 2nd message
            server_.SetFlag(msg2, MessageFlags.Deleted, true);

            scheduler.AdvanceBy(TimeSpan.FromSeconds(1).Ticks);
            Assert.AreEqual(2, folderMsgCount);
            Assert.AreEqual(1, folderUnreadCount);
            Assert.AreEqual(2, msgCount);

            // Expunge the folder
            server_.ExpungeFolder();

            scheduler.AdvanceBy(TimeSpan.FromSeconds(1).Ticks);
            Assert.AreEqual(1, folderMsgCount);
            Assert.AreEqual(0, folderUnreadCount);
            Assert.AreEqual(1, msgCount);

            // Mark the first as unread again
            server_.SetFlag(msg1, MessageFlags.Seen, false);

            scheduler.AdvanceBy(TimeSpan.FromSeconds(1).Ticks);
            Assert.AreEqual(1, folderMsgCount);
            Assert.AreEqual(1, folderUnreadCount);
            Assert.AreEqual(1, msgCount);
        }
示例#2
0
        public void MessagesFiltered()
        {
            var scheduler = new TestScheduler();

            Core.Dependencies.TimeScheduler = scheduler;

            int visibleMessages = -1;

            // Wait for the inbox to appear
            var findInbox = server_.AllFolders.Select((folders) =>
            {
                return(folders.Where(folder => folder.FullName == "INBOX").FirstOrDefault());
            })
                            .Where(folder => folder != null)
                            .Take(1)
                            .Subscribe(folder =>
            {
                // Now subscribe to interesting parts of the inbox

                server_.SelectFolder(folder);

                folder.ViewMessages.Select(msgs =>
                {
                    return(msgs.Count());
                }).Subscribe(msgCount => {
                    visibleMessages = msgCount;
                });
            });

            // Now start feeding the server with fake data.

            // Get the Inbox to appear
            var inbox = new Folder(server_, "INBOX", "INBOX", ".", false, true);

            testServer_.AddFolder(inbox);

            // Add a message to it.
            var msg1 = new MessageHeader(1, inbox);

            msg1.SetValue("subject", "Subject A");

            inbox.AddMessage(msg1);

            // Add another message to it.
            var msg2 = new MessageHeader(2, inbox);

            msg2.SetValue("subject", "Subject B");

            inbox.AddMessage(msg2);

            scheduler.AdvanceBy(TimeSpan.FromSeconds(1).Ticks);
            Assert.AreEqual(2, visibleMessages);


            // Now filter the messages
            inbox.SetFilterMsgIds(new int[] { 2 });

            scheduler.AdvanceBy(TimeSpan.FromSeconds(1).Ticks);
            Assert.AreEqual(1, visibleMessages);


            inbox.SetFilterMsgIds(new int[] { 1 });

            scheduler.AdvanceBy(TimeSpan.FromSeconds(1).Ticks);
            Assert.AreEqual(1, visibleMessages);

            inbox.SetFilterMsgIds(new int[] { 1, 2 });

            scheduler.AdvanceBy(TimeSpan.FromSeconds(1).Ticks);
            Assert.AreEqual(2, visibleMessages);

            inbox.SetFilterMsgIds(new int[] { });

            scheduler.AdvanceBy(TimeSpan.FromSeconds(1).Ticks);
            Assert.AreEqual(0, visibleMessages);

            inbox.SetFilterMsgIds(null);

            scheduler.AdvanceBy(TimeSpan.FromSeconds(1).Ticks);
            Assert.AreEqual(2, visibleMessages);
        }