public void GetSubNotificationEmailTest() { string rootPath = TestConfig.GetConfig().GetRipleyServerPath(); BBC.Dna.AppContext.OnDnaStartup(rootPath); Console.WriteLine("Before SubNotificationEmailTests - GetSubNotificationEmailTest"); //Create the mocked inputcontext Mockery mock = new Mockery(); IInputContext context = DnaMockery.CreateDatabaseInputContext(); // Create a mocked site for the context ISite mockedSite = DnaMockery.CreateMockedSite(context, 1, "h2g2", "h2g2", true, "comment"); Stub.On(context).GetProperty("CurrentSite").Will(Return.Value(mockedSite)); Stub.On(mockedSite).GetProperty("ModClassID").Will(Return.Value(1)); BBC.Dna.User user = new BBC.Dna.User(context); Stub.On(context).GetProperty("ViewingUser").Will(Return.Value(user)); Stub.On(context).GetProperty("CurrentSite").Will(Return.Value(mockedSite)); CreateAndRecommendAndAllocateArticle(context); SubNotificationEmail subNotificationEmail = new SubNotificationEmail(context); bool toSend = false; string emailAddress = String.Empty; string emailSubject = String.Empty; string emailText = String.Empty; subNotificationEmail.CreateNotificationEmail(6, ref toSend, ref emailAddress, ref emailSubject, ref emailText); XmlElement xml = subNotificationEmail.RootElement; Assert.IsTrue(xml.SelectSingleNode("EMAIL") != null, "The xml is not generated correctly!!!"); DnaXmlValidator validator = new DnaXmlValidator(xml.InnerXml, _schemaUri); validator.Validate(); Console.WriteLine("After SubNotificationEmailTests - GetSubNotificationEmailTest"); }
/// <summary> /// Sends out an email containing a summary of the new allocations made /// to each sub editor. /// </summary> /// <param name="totalSent">total number of emails sent returned</param> /// <returns>True if emails sent okay, false if not</returns> private bool SendNotificationEmails(ref int totalSent) { UserList userList = new UserList(InputContext); userList.CreateSubEditorsList(); int[] userIDs = null; if (!userList.GetUserIDs(ref userIDs)) return false; for (int counter = 0; counter < userIDs.Length; counter++) { string emailAddress = String.Empty, emailSubject = String.Empty, emailText = String.Empty; bool toSend =true; // create their notification email object SubNotificationEmail subnotificationEmail = new SubNotificationEmail(InputContext); subnotificationEmail.CreateNotificationEmail(userIDs[counter], ref toSend, ref emailAddress, ref emailSubject, ref emailText); if(toSend) {// if we have an email to send then send it InputContext.SendMailOrSystemMessage(emailAddress, emailSubject, emailText, InputContext.CurrentSite.EditorsEmail, InputContext.CurrentSite.ShortName, false, userIDs[counter], InputContext.CurrentSite.SiteID); totalSent++; } } if (totalSent == 0) { XmlNode subAllocateForm = RootElement.SelectSingleNode("SUB-ALLOCATION-FORM"); XmlNode notifSent = AddElement(subAllocateForm, "NOTIFICATIONS-SENT","");//, dataReader.GetInt32NullAsZero("Total")); AddAttribute(notifSent, "TOTAL", totalSent); } else { XmlNode subAllocateForm = RootElement.SelectSingleNode("SUB-ALLOCATION-FORM"); XmlNode notifSent = AddElement(subAllocateForm, "NOTIFICATIONS-SENT", "An error occurred whilst trying to send emails");//, dataReader.GetInt32NullAsZero("Total")); AddAttribute(notifSent, "TYPE", "EMAIL-FAILURE"); } return true; }