public void TestHeaderErrors()
 {
     try
     {
         SignificantIncidentReport sir = new SignificantIncidentReport(_sir.Sender, _sir.Subject, _sir.Header, _sir.Text);
         Assert.ThrowsException <ArgumentException>(() => sir = new SignificantIncidentReport("_sir.Sender", _sir.Subject, _sir.Header, _sir.Text));
     }
     catch (ArgumentException e)
     {
         Assert.Fail("The ArgumentException was not thrown.\n\n" + e.Message);
     }
 }
        public void TestTextErrors()
        {
            string msg = "a";

            for (int i = 0; i < 729; i++)
            {
                msg += "aaaaaaaa";
            }

            SignificantIncidentReport sir = new SignificantIncidentReport(_sir.Sender, _sir.Subject, _sir.Header, _sir.Text);

            Assert.ThrowsException <ArgumentException>(() => sir = new SignificantIncidentReport(_sir.Sender, _sir.Subject, _sir.Header, msg));
        }
Esempio n. 3
0
        /// <summary>
        /// This is what happens when you click the "Process" button.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event arguments</param>
        public void btnProcess_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtHeader.Text.StartsWith("S")) // Check its an SMS
                {
                    SMS sms = _sf.ProcessSMS(txtSender.Text, txtHeader.Text, txtBody.Text);
                    txtBody.Text = sms.Text;             // Add content to text box
                }
                else if (txtHeader.Text.StartsWith("E")) // Check it's an email
                {
                    string        msg = txtBody.Text;    // Initialise msg text.
                    List <string> urls;

                    if (txtSubject.Text.StartsWith("SIR")) // Check if it is a SIR
                    {
                        SignificantIncidentReport sir = _sf.ProcessSIR(txtSender.Text, txtHeader.Text, txtSubject.Text, txtBody.Text);
                        txtBody.Text = sir.Text;

                        urls = sir.QuarantinedURLs(msg);

                        lstSIR.Items.Add("Code: " + sir.Code);
                        lstSIR.Items.Add("Nature: " + sir.Nature);

                        foreach (string s in urls)
                        {
                            lstURLs.Items.Add(s); // Add quarantined URLs to list box
                        }
                        return;
                    }

                    // Do the same thing, but for a regular email.

                    Email email = _sf.ProcessEmail(txtSender.Text, txtHeader.Text, txtSubject.Text, txtBody.Text);
                    txtBody.Text = email.Text;

                    urls = email.QuarantinedURLs(msg);

                    foreach (string s in urls)
                    {
                        lstURLs.Items.Add(s);
                    }
                }
                else if (txtHeader.Text.StartsWith("T")) // Check it's a tweet
                {
                    string msg   = txtBody.Text;
                    Tweet  tweet = _sf.ProcessTweet(txtSender.Text, txtHeader.Text, txtBody.Text);
                    txtBody.Text = tweet.Text;

                    List <string> mentions = tweet.ExtractMentions(msg);
                    List <string> hash     = tweet.ExtractHashtags(msg);

                    foreach (string s in mentions)
                    {
                        lstMentions.Items.Add(s); // Put mentions in mention box
                    }

                    foreach (string s in hash)
                    {
                        lstHash.Items.Add(s); // Put hashtags in hash box
                    }
                }
                else
                {
                    MessageBox.Show(
                        "The header field starts with an invalid character. Please make this S, E or T followed by 9 characters.",
                        "Whoops!", MessageBoxButton.OK, MessageBoxImage.Exclamation); // Otherwise return error box
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public void TestSubjectErrors()
        {
            SignificantIncidentReport sir = new SignificantIncidentReport(_sir.Sender, _sir.Subject, _sir.Header, _sir.Text);

            Assert.ThrowsException <ArgumentException>(() => sir = new SignificantIncidentReport(_sir.Sender, _sir.Subject, "_sir.Header", _sir.Text));
        }
 public void TestNatureException()
 {
     Assert.ThrowsException <ArgumentException>(() =>
                                                _sir = new SignificantIncidentReport("*****@*****.**", "SIR - 26/11/2008", "E321467852",
                                                                                     "Sort Code: 99-13-34 Nature of Incident: blah blah blah https://www.google.com/jeff_bezos"));
 }