コード例 #1
0
        public void TestProcessingThread()
        {
            var seed = _rand.Next();

            Logger.InfoFormat("Using seed {0}", seed);

            var mailManager = new MailManagerMock();
            var message1    = mailManager.AddMessage(false);
            var message2    = mailManager.AddReply(message1, RandomDataHelper.GetBody(seed));
            var message3    = mailManager.AddReply(message2, RandomDataHelper.GetBody(seed));

            var instanceConfig = GetConfig().Instances.First();

            var workItemManagerMock = new WorkItemManagerMock(instanceConfig.WorkItemSettings.ConversationIndexFieldName);

            ProcessMailbox(mailManager, instanceConfig, workItemManagerMock);

            Assert.AreEqual(1, workItemManagerMock.Bugs.Count, "Only one bug should exist");
            var bug       = workItemManagerMock.Bugs.First();
            var bugFields = bug.Value;

            var expectedValues = new Dictionary <string, string>();

            instanceConfig.WorkItemSettings.DefaultFieldValues.ForEach(x => expectedValues[x.Field] = x.Value);

            expectedValues["Changed By"] = message3.SenderName;
            expectedValues[WorkItemManagerMock.HistoryField] = TextUtils.FixLineBreaks(message2.GetLastMessageText() + message3.GetLastMessageText());

            ValidateBugValues(expectedValues, bugFields);
        }
コード例 #2
0
        public static IncomingEmailMessageMock CreateWithRandomData(int numAttachments)
        {
            var mock = new IncomingEmailMessageMock
            {
                Subject           = RandomDataHelper.GetSubject(_seed++),
                RawBody           = RandomDataHelper.GetBody(_seed++),
                PlainTextBody     = RandomDataHelper.GetBody(_seed++),
                ConversationIndex = RandomDataHelper.GetConversationId(_seed++),
                ConversationTopic = RandomDataHelper.GetSubject(_seed++),
                SenderName        = RandomDataHelper.GetName(_seed++),
                SenderAlias       = RandomDataHelper.GetAlias(_seed++)
            };

            mock.SenderAddress = mock.SenderAlias + "@blah.com";
            mock.ToAddresses   = GetRandomAliasList(Rand.Next(1, 30));
            mock.CcAddresses   = GetRandomAliasList(Rand.Next(0, 30));
            mock.ToNames       = GetRandomNamesList(mock.ToAddresses.Count());
            mock.CcNames       = GetRandomNamesList(mock.CcAddresses.Count());
            mock.SentOn        = new DateTime(Rand.Next(2012, 2525), Rand.Next(1, 12), Rand.Next(1, 28));
            mock.ReceivedOn    = new DateTime(Rand.Next(2012, 2525), Rand.Next(1, 12), Rand.Next(1, 28));
            mock.IsHtmlBody    = Rand.Next(0, 1) == 0;

            var attachments = new List <IIncomingEmailAttachment>(numAttachments);

            for (var i = 0; i < numAttachments; i++)
            {
                attachments.Add(new IncomingAttachmentMock(Rand.Next(1, 100000)));
            }

            mock.Attachments = attachments;

            return(mock);
        }
コード例 #3
0
        public void TestApplyingOverridesInUpdateMessage()
        {
            var seed = _rand.Next();

            Logger.InfoFormat("Using seed {0}", seed);

            var mailManager = new MailManagerMock();
            var message1    = mailManager.AddMessage(false);

            var mnemonicDef = new Config.MnemonicDefinition {
                Mnemonic = "myMnemonic", Field = "Mnemonic Field", Value = "Mnemonic Value"
            };
            var mnemonicLine = string.Format("\n@@@{0}\n", mnemonicDef.Mnemonic);

            var explicitOverride1 = new KeyValuePair <string, string>("IsThisExplicit?", "Indeed");
            var explicitLine1     = string.Format("\n###{0}:{1}\n", explicitOverride1.Key, explicitOverride1.Value);

            var explicitOverride2 = new KeyValuePair <string, string>("WillThisOneBeProcessed?", "No");
            var explicitLine2     = string.Format("\n###{0}:{1}\n", explicitOverride2.Key, explicitOverride2.Value);

            var message2 = mailManager.AddReply(message1, mnemonicLine + RandomDataHelper.GetBody(seed));
            var message3 = mailManager.AddReply(message2, RandomDataHelper.GetBody(seed) + explicitLine1);

            // This last override will not be considered, because it's not part of the last message (it's at the
            // end of the message text, so considered as part of the first message)
            var message4 = mailManager.AddReply(message3, RandomDataHelper.GetBody(seed));

            message4.PlainTextBody += explicitLine2;

            var instanceConfig = GetConfig().Instances.First();

            instanceConfig.WorkItemSettings.ApplyOverridesDuringUpdate = true;
            instanceConfig.WorkItemSettings.Mnemonics.Add(mnemonicDef);

            var workItemManagerMock = new WorkItemManagerMock(instanceConfig.WorkItemSettings.ConversationIndexFieldName);

            ProcessMailbox(mailManager, instanceConfig, workItemManagerMock);

            Assert.AreEqual(1, workItemManagerMock.Bugs.Count, "Only one bug should exist");
            var bug       = workItemManagerMock.Bugs.First();
            var bugFields = bug.Value;

            var expectedValues = new Dictionary <string, string>();

            instanceConfig.WorkItemSettings.DefaultFieldValues.ForEach(x => expectedValues[x.Field] = x.Value);

            expectedValues["Changed By"] = message4.SenderName;
            expectedValues[WorkItemManagerMock.HistoryField] =
                TextUtils.FixLineBreaks(message2.GetLastMessageText() + message3.GetLastMessageText() + message4.GetLastMessageText());
            expectedValues[mnemonicDef.Field]     = mnemonicDef.Value;
            expectedValues[explicitOverride1.Key] = explicitOverride1.Value;

            ValidateBugValues(expectedValues, bugFields);
            Assert.IsFalse(bugFields.ContainsKey(explicitOverride2.Key));
        }
コード例 #4
0
        public void TestGetLastMessageTextBasic()
        {
            var message = new IncomingEmailMessageMock();

            var lastMessageText = RandomDataHelper.GetBody(_rand.Next());
            var numOfReplies    = _rand.Next(0, 100);
            var bodyBuilder     = new StringBuilder(lastMessageText);

            for (var i = 0; i < numOfReplies; i++)
            {
                bodyBuilder.AppendLine(RandomDataHelper.GetRandomMessageSeparator(_rand.Next()));
                bodyBuilder.Append(RandomDataHelper.GetBody(_rand.Next()));
            }
            message.PlainTextBody = bodyBuilder.ToString();

            Assert.AreEqual(lastMessageText, EmailBodyProcessingUtils.GetLastMessageText(message), "Verifying extracted last message text correctness");
        }