Esempio n. 1
0
        public void TestNotificationOnPOP3Deletion()
        {
            _settings.IMAPIdleEnabled = true;

             Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");
             SMTPClientSimulator.StaticSend(account.Address, account.Address, "Message 1", "Body 1");
             SMTPClientSimulator.StaticSend(account.Address, account.Address, "Message 1", "Body 1");
             POP3ClientSimulator.AssertMessageCount(account.Address, "test", 2);

             var imapSimulator = new IMAPClientSimulator();
             string sWelcomeMessage = imapSimulator.Connect();
             CustomAssert.IsTrue(imapSimulator.Logon("*****@*****.**", "test"));
             CustomAssert.IsTrue(imapSimulator.SelectFolder("INBOX"));
             CustomAssert.IsTrue(imapSimulator.StartIdle());

             var sim = new POP3ClientSimulator();
             CustomAssert.IsTrue(sim.ConnectAndLogon(account.Address, "test"));
             CustomAssert.IsTrue(sim.DELE(1));
             sim.QUIT();

             // After a delete, the following should be sent tot he IMAP client:
             //  - EXPUNGE
             //  - EXISTS
             //  - RECENT
             CustomAssert.IsTrue(imapSimulator.AssertPendingDataExists(), "No pending data exist");

             var deadline = DateTime.Now.AddSeconds(10);
             var message = new StringBuilder();

             while (DateTime.Now < deadline)
             {
            if (imapSimulator.GetPendingDataExists())
               message.Append(imapSimulator.Receive());

            var str = message.ToString();

            if (str.Contains("* 1 EXPUNGE") &&
                str.Contains("EXISTS") &&
                str.Contains("RECENT"))
            {
               return;
            }
             }

             var receivedText = message.ToString();
             CustomAssert.IsTrue(receivedText.Contains("* 1 EXPUNGE"), receivedText);
             CustomAssert.IsTrue(receivedText.Contains("EXISTS"), receivedText);
             CustomAssert.IsTrue(receivedText.Contains("RECENT"), receivedText);
        }