示例#1
0
        public void ShowAllEmails()
        {
            SBEmailHeaders emailHeaders = new SBEmailHeaders();

            m_connector.GetHeaders(m_iEmailLookbackPeriod, "ASC", ref emailHeaders);

            for (int i = 0; i < emailHeaders.NumberOfEntries; ++i)
            {
                emailHeaders[i].m_sBodyText = m_connector.GetBodyTextById(emailHeaders[i].m_sId);
            }

            Console.WriteLine("Number of e-mails: " + emailHeaders.NumberOfEntries);
            Console.WriteLine("New e-mails      : " + emailHeaders.NumberOfUnreadEntries);

            for (int i = 0; i < emailHeaders.NumberOfEntries; ++i)
            {
                Console.WriteLine("=================================");
                Console.WriteLine("Email     : " + (i + 1));
                Console.WriteLine("From      : " + emailHeaders[i].m_sFromName);
                Console.WriteLine("Date      : " + emailHeaders[i].m_sDate);
                Console.WriteLine("Subject   : " + emailHeaders[i].m_sSubject);
                Console.WriteLine("Importance: " + emailHeaders[i].m_sImportance);
                Console.WriteLine("IsRead    : " + emailHeaders[i].m_bRead);
                Console.WriteLine("Body      : " + emailHeaders[i].m_sBodyText);
                Console.WriteLine("Type      : " + emailHeaders[i].m_Type);
                Console.WriteLine("=================================");
            }
        }
示例#2
0
        public void TestThatSentEmailIsPutIntoSentItemsFolder()
        {
            int            iEmailLookbackPeriod = 1;
            SBEmailHeaders emailHeaders         = new SBEmailHeaders();

            m_connector.SetFolder("Sent Items");
            m_connector.GetHeaders(iEmailLookbackPeriod, "ASC", ref emailHeaders);

            int numberOfEmailsPriorToSend = emailHeaders.NumberOfEntries;

            eResults result = m_connector.SendEmail(m_sUsername, "WebDAV Unit Test Send", 0, DateTime.Now.ToString(), eEmailBodyType.Text);

            Assert.That(result, Is.EqualTo(eResults.OK), "Call to SendEmail() failed.\n{0}", EmailServerInfo());


            // Unfortunately we need to wait a little while before the sent e-mail shows up in the Sent Items folder.

            Thread.Sleep(5000);

            m_connector.GetHeaders(iEmailLookbackPeriod, "ASC", ref emailHeaders);

            int numberOfEmailsAfterSend = emailHeaders.NumberOfEntries;

            Assert.That(numberOfEmailsAfterSend, Is.GreaterThan(numberOfEmailsPriorToSend));
        }
示例#3
0
        public void TestThatSortOrderWorks()
        {
            SBEmailHeaders emailHeadersAscending  = new SBEmailHeaders();
            SBEmailHeaders emailHeadersDescending = new SBEmailHeaders();

            m_connector.GetHeaders(m_iEmailLookbackPeriod, "ASC", ref emailHeadersAscending);
            m_connector.GetHeaders(m_iEmailLookbackPeriod, "DESC", ref emailHeadersDescending);

            Assert.That(emailHeadersAscending.NumberOfEntries, Is.GreaterThan(1), "For this test to work at least two e-mails are required in the '{0}' folder.\n{1}", m_sFolder, EmailServerInfo());
            Assert.That(emailHeadersAscending.NumberOfEntries, Is.EqualTo(emailHeadersDescending.NumberOfEntries), "For this test to work the content of the '{0}' folder is not allowed to change.\n{1}", m_sFolder, EmailServerInfo());

            bool bMismatchFound = false;

            for (int i = 0; i < emailHeadersAscending.NumberOfEntries; ++i)
            {
                int iDescendingIndex = (emailHeadersDescending.NumberOfEntries - 1) - i;
                if (emailHeadersAscending[i].m_sId != emailHeadersDescending[iDescendingIndex].m_sId)
                {
                    bMismatchFound = true;
                    break;
                }
            }

            Assert.That(bMismatchFound, Is.False);
        }
        public void TestThatSentEmailIsPutIntoSentItemsFolder()
        {
            int            iEmailLookbackPeriod = 1;
            SBEmailHeaders emailHeaders         = new SBEmailHeaders();

            m_connector.SetFolder("Sent Items");
            m_connector.GetHeaders(iEmailLookbackPeriod, "ASC", ref emailHeaders);

            int numberOfEmailsPriorToSend = emailHeaders.NumberOfEntries;

            eResults result = m_connector.SendEmail(m_sUsername, "EWS Unit Test Send", 0, DateTime.Now.ToString(), eEmailBodyType.Text);

            Assert.That(result, Is.EqualTo(eResults.OK), "Call to SendEmail() failed.\n{0}", EmailServerInfo());


            // At times the sent e-mail doesn't show up right away in the Sent Items folder.
            // To ensure that this doesn't cause the test to fail we'll just have to add a little wait here.

            Thread.Sleep(5000);

            m_connector.GetHeaders(iEmailLookbackPeriod, "ASC", ref emailHeaders);

            int numberOfEmailsAfterSend = emailHeaders.NumberOfEntries;

            Assert.That(numberOfEmailsAfterSend, Is.GreaterThan(numberOfEmailsPriorToSend));
        }
示例#5
0
        public void TestThatNumberOfEmailsIsReturned()
        {
            SBEmailHeaders emailHeaders = new SBEmailHeaders();

            eResults result = m_connector.GetHeaders(m_iEmailLookbackPeriod, "ASC", ref emailHeaders);

            Assert.That(result, Is.EqualTo(eResults.OK), "Call to GetHeaders() failed.");
            Assert.That(emailHeaders.NumberOfEntries, Is.GreaterThan(0), "For this test to work there must be at least one e-mail in the '{0}' folder within the last {1} days.\n{2}", m_sFolder, m_iEmailLookbackPeriod, EmailServerInfo());
        }
示例#6
0
        public void TestThatEmptyInboxReturnsZeroEmails()
        {
            SBEmailHeaders emailHeaders = new SBEmailHeaders();

            int iEmailLookkbackPeriod = -1;                                     // This means we are looking for e-mails received tomorrow, which clearly there are none.

            eResults result = m_connector.GetHeaders(iEmailLookkbackPeriod, "ASC", ref emailHeaders);

            Assert.That(result, Is.EqualTo(eResults.OK), "Call to GetHeaders() failed.");
            Assert.That(emailHeaders.NumberOfEntries, Is.EqualTo(0), "Hmm, how is it possible that we found an e-mail in the '{0}' folder that we won't receive until tomorrow?\n{1}", m_sFolder, EmailServerInfo());
        }
        public void TestThatSBEmailHeadersCollectionReturnsCorrectNumberOfEntries()
        {
            int            iNumberOfEntries = 2;
            SBEmailHeaders sbEmailHeaders   = new SBEmailHeaders();

            for (int i = 0; i < iNumberOfEntries; ++i)
            {
                sbEmailHeaders.Add(new SBEmailHeaders.SBEmailHeader());
            }

            Assert.That(sbEmailHeaders.NumberOfEntries, Is.EqualTo(iNumberOfEntries));
        }
示例#8
0
        public void TestThatUsingIncorrectPasswordReturnsFail()
        {
            SBEmailHeaders emailHeaders = new SBEmailHeaders();

            IConnector connector = new WebDavConnectorImplementation(eEmailServerType.Exchange2007WebDAV);

            connector.Init(m_Logger, m_sExchangeServerAddress, m_sFolder, m_sDomain, m_sUsername, m_bDebugAll);
            connector.Connect("Wrong Password");
            eResults result = connector.GetHeaders(m_iEmailLookbackPeriod, "ASC", ref emailHeaders);

            Assert.That(result, Is.EqualTo(eResults.Fail));
        }
示例#9
0
        public void TestThatSetFolderWorks()
        {
            string         sFolder      = "Sent Items";
            SBEmailHeaders emailHeaders = new SBEmailHeaders();

            m_connector.SetFolder(sFolder);
            m_connector.GetHeaders(m_iEmailLookbackPeriod, "ASC", ref emailHeaders);

            Assert.That(emailHeaders.NumberOfEntries, Is.GreaterThan(0), "For this test to work there must be at least one e-mail in the '{0}' folder within the last {1} days.\n{2}", sFolder, m_iEmailLookbackPeriod, EmailServerInfo());

            for (int i = 0; i < emailHeaders.NumberOfEntries; ++i)
            {
                Assert.That(emailHeaders[i].m_sFromName, Is.EqualTo(m_sUserDisplayName));
            }
        }
        public void TestThatSBEmailHeadersCollectionReturnsCorrectNumberOfUnreadEntries()
        {
            int iNumberOfUnreadEntries = 2;

            SBEmailHeaders sbEmailHeaders = new SBEmailHeaders();

            for (int i = 0; i < iNumberOfUnreadEntries; ++i)
            {
                SBEmailHeaders.SBEmailHeader sbEmailHeaderUnread = new SBEmailHeaders.SBEmailHeader();
                sbEmailHeaderUnread.m_bRead = false;
                sbEmailHeaders.Add(sbEmailHeaderUnread);
            }

            SBEmailHeaders.SBEmailHeader sbEmailHeaderRead = new SBEmailHeaders.SBEmailHeader();
            sbEmailHeaderRead.m_bRead = true;
            sbEmailHeaders.Add(sbEmailHeaderRead);

            Assert.That(sbEmailHeaders.NumberOfUnreadEntries, Is.EqualTo(iNumberOfUnreadEntries));
        }
示例#11
0
        public void TestThatEwsAndWebDavReturnSameEmails()
        {
            SBEmailHeaders webDavEmailHeaders = new SBEmailHeaders();
            SBEmailHeaders ewsEmailHeaders    = new SBEmailHeaders();

            m_EwsConnector.GetHeaders(m_iEmailLookbackPeriod, "ASC", ref ewsEmailHeaders);
            m_WebDavConnector.GetHeaders(m_iEmailLookbackPeriod, "ASC", ref webDavEmailHeaders);

            Assert.That(ewsEmailHeaders.NumberOfEntries, Is.EqualTo(webDavEmailHeaders.NumberOfEntries), "Total number of e-mails differs.");
            Assert.That(ewsEmailHeaders.NumberOfUnreadEntries, Is.EqualTo(webDavEmailHeaders.NumberOfUnreadEntries), "Number of new e-mails differs.");

            for (int i = 0; i < webDavEmailHeaders.NumberOfEntries; ++i)
            {
                Assert.That(ewsEmailHeaders[i].m_sFromName, Is.EqualTo(webDavEmailHeaders[i].m_sFromName), "From name differs.");
                Assert.That(ewsEmailHeaders[i].m_sSubject, Is.EqualTo(webDavEmailHeaders[i].m_sSubject), "Subject differs.");
                Assert.That(ewsEmailHeaders[i].m_sDate, Is.EqualTo(webDavEmailHeaders[i].m_sDate), "Date differs.");
                Assert.That(ewsEmailHeaders[i].m_sImportance, Is.EqualTo(webDavEmailHeaders[i].m_sImportance), "Importance differs.");
                Assert.That(ewsEmailHeaders[i].m_bRead, Is.EqualTo(webDavEmailHeaders[i].m_bRead), "Read status differs.");
                Assert.That(ewsEmailHeaders[i].m_Type, Is.EqualTo(webDavEmailHeaders[i].m_Type), "Type differs.");
            }
        }
        public void TestThatEmptySBEmailHeadersCollectionHasATotalOfZeroUnreadEntries()
        {
            SBEmailHeaders sbEmailHeaders = new SBEmailHeaders();

            Assert.That(sbEmailHeaders.NumberOfUnreadEntries, Is.EqualTo(0));
        }
示例#13
0
        public void TestThatAcceptingAMeetingRequestAddsTheMeetingIntoTheCalendar()
        {
            eResults result = eResults.OK;

            int iEmailLookbackPeriod = 1;
            int iMeetingTimePeriod   = 3;

            string sTestRequirement = String.Format("For this test to work the following have to be true:\n" +
                                                    "     A meeting request with the subject \"WebDAV Meeting Request Test\" has to be received within the last {0} days.\n" +
                                                    "     The requested meeting has to occur within the next {1} days.\n{2}", iEmailLookbackPeriod, iMeetingTimePeriod, EmailServerInfo());

            SBEmailHeaders emailHeaders = new SBEmailHeaders();

            m_connector.GetHeaders(iEmailLookbackPeriod, "ASC", ref emailHeaders);

            // Look for the meeting request e-mail required by this test.

            bool   bMeetingRequestFound = false;
            string sMeetingRequestId    = null;

            for (int i = 0; (i < emailHeaders.NumberOfEntries && !bMeetingRequestFound); ++i)
            {
                if (emailHeaders[i].m_Type == eItemType.MeetingRequest)
                {
                    if (emailHeaders[i].m_sSubject.ToLower() == "webdav meeting request test")
                    {
                        bMeetingRequestFound = true;
                        sMeetingRequestId    = emailHeaders[i].m_sId;
                    }
                }
            }

            Assert.That(bMeetingRequestFound, Is.True, sTestRequirement);

            SBCalendarEntries calendarEntriesInitially = new SBCalendarEntries();

            m_connector.GetCalendarEntries(DateTime.Now, iMeetingTimePeriod, ref calendarEntriesInitially);

            int iNumberOfTentativeMeetingsInitially = 0;
            int iNumberOfAcceptedMeetingsInitially  = 0;

            for (int i = 0; i < calendarEntriesInitially.Count; ++i)
            {
                switch (calendarEntriesInitially[i].m_sBusystatus)
                {
                case "TENTATIVE":
                    ++iNumberOfTentativeMeetingsInitially;
                    break;

                case "BUSY":
                    ++iNumberOfAcceptedMeetingsInitially;
                    break;
                }
            }

            result = m_connector.SendMeetingRequestResp(sMeetingRequestId, "WebDAV Meeting Request Reponse Test", eMeetingRequestResp.Accept, true);

            Assert.That(result, Is.EqualTo(eResults.OK), "Call to SendMeetingRequestResp() failed.\n{0}", EmailServerInfo());

            SBCalendarEntries calendarEntriesFinally = new SBCalendarEntries();

            m_connector.GetCalendarEntries(DateTime.Now, iMeetingTimePeriod, ref calendarEntriesFinally);

            int iNumberOfTentativeMeetings = 0;
            int iNumberOfAcceptedMeetings  = 0;

            for (int i = 0; i < calendarEntriesFinally.Count; ++i)
            {
                switch (calendarEntriesFinally[i].m_sBusystatus)
                {
                case "TENTATIVE":
                    ++iNumberOfTentativeMeetings;
                    break;

                case "BUSY":
                    ++iNumberOfAcceptedMeetings;
                    break;
                }
            }

            Assert.That((iNumberOfAcceptedMeetings - iNumberOfAcceptedMeetingsInitially), Is.EqualTo(1), "Number of accepted meetings hasn't changed as expected");
            Assert.That((iNumberOfTentativeMeetings - iNumberOfTentativeMeetingsInitially), Is.EqualTo(-1), "Number of tentative meetings hasn't changed as expected");
        }