Exemplo n.º 1
0
        public void addTest()
        {
            sirList list            = new sirList();
            string  testVar         = "Test string";
            string  mixedStringTest = "123456ABCDEF_%^";

            list.add(mixedStringTest);
            list.add(testVar);
            Assert.AreEqual(sirList.SIRlist.ElementAt(0), mixedStringTest);
            Assert.AreEqual(sirList.SIRlist.ElementAt(1), testVar);
        }
Exemplo n.º 2
0
        public void countTest()
        {
            sirList list = new sirList();

            sirList.SIRlist.Clear();
            string testVar         = "Test string";
            string mixedStringTest = "123456ABCDEF_%^";

            list.add(mixedStringTest);
            list.add(testVar);
            Assert.AreEqual(list.count(), 2);
        }
Exemplo n.º 3
0
        public void returnValueTest()
        {
            sirList list = new sirList();

            sirList.SIRlist.Clear();
            string testVar         = "Test string with many characters in it";
            string mixedStringTest = "123456ABCDEF_%^";

            list.add(mixedStringTest);
            list.add(testVar);
            Assert.AreEqual(list.returnValue(0), mixedStringTest);
            Assert.AreEqual(list.returnValue(1), testVar);
        }
Exemplo n.º 4
0
        public void assignEmailSubject(email asset, List <string> incidents, sirList SIRList)
        {
            if (asset.Body.Length >= 40)
            {
                string SIRstring = asset.Body.Substring(0, 12);
                if (Regex.IsMatch(SIRstring, "SIR [0-9][0-9]/[0-9][0-9]/[0-9][0-9]"))
                {
                    string   sortCode;
                    string[] splitString = asset.Body.Split(null);
                    if (splitString[2] == "Sort" && splitString[3] == "Code:" && splitString[5] == "Nature" && splitString[6] == "of" && splitString[7] == "Incident:")
                    {
                        asset.IsSIR = true;

                        if (Regex.IsMatch(splitString[4], "[0-9][0-9]-[0-9][0-9]-[0-9][0-9]"))
                        {
                            sortCode = splitString[4];
                        }
                        else
                        {
                            throw new Exception("Sort code invalid");
                        }

                        asset.Subject = SIRstring.Substring(0, 12);
                        string[] sirInfo = new string[2];
                        sirInfo[0] = sortCode;

                        string sirIncident = splitString[8];

                        bool found = false;
                        //check if incident given is a recognised incident in the list
                        for (int i = 0; i < incidents.Count(); i++)
                        {
                            if (incidents[i].Equals(sirIncident))
                            {
                                found      = true;
                                sirInfo[1] = sirIncident;
                                break;
                            }
                        }

                        /*if the incident is not found yet the message has been identified as an SIR
                         * then check if the incident consists of two words, such as "ATM Theft"
                         */
                        if (!found)
                        {
                            sirIncident = splitString[8] + " " + splitString[9];
                            for (int i = 0; i < incidents.Count(); i++)
                            {
                                if (incidents[i].Equals(sirIncident))
                                {
                                    found      = true;
                                    sirInfo[1] = sirIncident;
                                    break;
                                }
                            }
                        }
                        if (!found)
                        {
                            throw new Exception("The incident listed is not a registered incident");
                        }
                        string sirInfoJoined = string.Join(" ", sirInfo[0], sirInfo[1]);
                        SIRList.add(sirInfoJoined);
                        asset.Body = asset.Body.Substring(12);
                        return;
                    }
                }

                else if (SIRstring.Contains("SIR"))
                {
                    throw new Exception("This message has been detected as a Significant Incident Report, however the format of the of the subject is incorrect.");
                }
            }
            //if message is standard email
            if (!asset.IsSIR && asset.Body.Length >= 20)
            {
                asset.Subject = asset.Body.Substring(0, 20);
                string newBodyText = asset.Body.Remove(0, 20);
                asset.Body = newBodyText;
            }
            else
            {
                throw new Exception("The subject of the message is less than 20 characters");
            }
        }