示例#1
0
 /// <summary>
 /// Sends an email notification for a posted CMO message.
 /// </summary>
 /// <param name="message">The message to send posted notifications for.</param>
 /// <param name="loadCandidate">A delegate for handling requests for candidate information.</param>
 /// <param name="recipients">A collection of users who will receive the notifications.</param>
 /// <returns>true if and only if all recipients were successfully notified; otherwise, false.</returns>
 public static bool SendFor(CmoMessage message, LoadCandidateEventHandler loadCandidate = null, IEnumerable <CPUser> recipients = null)
 {
     if (loadCandidate == null)
     {
         loadCandidate = CPProviders.DataProvider.GetCandidate;
     }
     if (recipients == null)
     {
         recipients = CPSecurity.Provider.GetCampaignUsers(message.CandidateID, message.ElectionCycle, false);
     }
     using (CmoPostedMessageNotice notice = new CmoPostedMessageNotice(message))
     {
         notice.LoadCandidate += loadCandidate;
         notice.Recipients     = recipients;
         return(notice.Send());
     }
 }
示例#2
0
        public void SendForAsyncTest()
        {
            string     cid        = "811";
            int        usersCount = 5;
            string     email      = "*****@*****.**";
            CmoMessage message    = new CmoMessage(cid, 1)
            {
                Title    = "Unit Test Title",
                Body     = "Body for unit test",
                PostDate = DateTime.Now,
                Category = new CmoCategory(1)
                {
                    Name = "Test Category"
                }
            };
            LoadCandidateEventHandler loadCandidate = (string id) =>
            {
                return(new Candidate(id)
                {
                    FirstName = "CFB", LastName = "Installation"
                });
            };
            var recipients = from i in Enumerable.Range(1, usersCount)
                             select new CPUser("testuser" + i)
            {
                Cid         = cid,
                DisplayName = "Test User " + i,
                Email       = email,
                Enabled     = true,
                SourceType  = EntityType.Generic
            };

            CPProviders.SettingsProvider = new MockSettingsProvider();
            bool expected = true;
            bool actual;
            Func <CmoMessage, LoadCandidateEventHandler, IEnumerable <CPUser>, bool> caller = CmoPostedMessageNotice.SendFor;
            IAsyncResult result = caller.BeginInvoke(message, loadCandidate, recipients, null, null);

            actual = caller.EndInvoke(result);
            Assert.AreEqual(expected, actual);
        }
示例#3
0
        public void SendForTest()
        {
            string     cid           = "811";
            int        usersCount    = 5;
            string     googleAccount = "simoncwu";
            CmoMessage message       = new CmoMessage(cid, 1)
            {
                Title    = "Unit Test Title",
                Body     = "Body for unit test",
                PostDate = DateTime.Now,
                Category = new CmoCategory(1)
                {
                    Name = "Test Category"
                }
            };
            LoadCandidateEventHandler loadCandidate = (string id) =>
            {
                System.Threading.Thread.Sleep(10000);
                return(new Candidate(id)
                {
                    FirstName = "CFB", LastName = "Installation"
                });
            };
            var recipients = from i in Enumerable.Range(1, usersCount)
                             select new CPUser("testuser" + i)
            {
                Cid         = cid,
                DisplayName = "Test User " + i,
                Email       = googleAccount + "+caccess" + i + "@gmail.com",
                Enabled     = true,
                SourceType  = EntityType.Generic
            };

            CPProviders.SettingsProvider = new MockSettingsProvider();
            bool expected = true;
            bool actual;

            actual = CmoPostedMessageNotice.SendFor(message, loadCandidate, recipients);
            Assert.AreEqual(expected, actual);
        }