Esempio n. 1
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));
        }
        private static void ProcessMailbox(
            MailManagerMock mailManager,
            Config.InstanceConfig instanceConfig,
            WorkItemManagerMock workItemManagerMock)
        {
            var sbs = new SimpleBugStrategy(instanceConfig, workItemManagerMock);

            foreach (var incomingEmailMessage in mailManager.ReadMessages())
            {
                sbs.ProcessInboxMessage(incomingEmailMessage);
            }
        }
Esempio n. 3
0
        public void TestSimpleExplicitOverride()
        {
            var config = GetConfig();

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

            message.PlainTextBody += string.Format("###{0}:{1}", BasicField, BasicValue);

            var extractor  = new OverridesExtractor(message, config);
            var dictionary = extractor.GetOverrides();

            Assert.IsTrue(dictionary.ContainsKey(BasicField), string.Format("Validate override for field {0} exists", BasicField));
            Assert.AreEqual(BasicValue, dictionary[BasicField], "Validate the right value was assigned as part of explicit overrides resolution");
        }
Esempio n. 4
0
        public void TestDefaultDateNominalOverride()
        {
            var config = GetConfig();

            config.WorkItemSettings.DateBasedOverrides.Add(new Config.DateBasedFieldOverrides());
            config.WorkItemSettings.DateBasedOverrides[0].FieldName    = BasicField;
            config.WorkItemSettings.DateBasedOverrides[0].DefaultValue = BasicValue;
            config.WorkItemSettings.DateBasedOverrides[0].Entries      = new List <Config.DateBasedOverrideEntry>
            {
                new Config.DateBasedOverrideEntry
                {
                    StartDate = DateTime.Now + TimeSpan.FromDays(-50),
                    Value     = BasicValue
                },
                new Config.DateBasedOverrideEntry
                {
                    StartDate = DateTime.Now + TimeSpan.FromDays(-30),
                    Value     = BasicValue2
                },
                new Config.DateBasedOverrideEntry {
                    StartDate = DateTime.Now + TimeSpan.FromDays(10), Value = BasicValue
                },
                new Config.DateBasedOverrideEntry {
                    StartDate = DateTime.Now + TimeSpan.FromDays(20), Value = BasicValue
                },
                new Config.DateBasedOverrideEntry {
                    StartDate = DateTime.Now + TimeSpan.FromDays(30), Value = BasicValue
                },
                new Config.DateBasedOverrideEntry {
                    StartDate = DateTime.Now + TimeSpan.FromDays(40), Value = BasicValue
                }
            };

            // Should pick this one

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

            var extractor  = new OverridesExtractor(message, config);
            var dictionary = extractor.GetOverrides();

            Assert.IsTrue(dictionary.ContainsKey(BasicField), string.Format("Validate override for field {0} exists", BasicField));
            Assert.AreEqual(BasicValue2, dictionary[BasicField], "Validate the right value was assigned as part of mnemonic resolution");
        }
Esempio n. 5
0
        public void TestSimpleMnemonicOverride()
        {
            var config = GetConfig();

            config.WorkItemSettings.Mnemonics.Add(
                new Config.MnemonicDefinition {
                Mnemonic = BasicMnemonic.ToUpper(), Field = BasicField, Value = BasicValue
            });

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

            message.PlainTextBody += string.Format("@@@{0}", BasicMnemonic.ToLower());

            var extractor  = new OverridesExtractor(message, config);
            var dictionary = extractor.GetOverrides();

            Assert.IsTrue(dictionary.ContainsKey(BasicField), string.Format("Validate override for field {0} exists", BasicField));
            Assert.AreEqual(BasicValue, dictionary[BasicField], "Validate the right value was assigned as part of mnemonic resolution");
        }
        public void TestAppendOnlyMessageSubject()
        {
            var seed = _rand.Next();

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

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

            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 newBugId = workItemManagerMock.Bugs.First().Key + 1;

            workItemManagerMock.Bugs.Add(newBugId, new Dictionary <string, string>());

            mailManager.Clear();

            const string comment           = "Comment";
            var          appendOnlySubject = string.Format("RE: Bug #{0}: coverage drop and fluctuation in CO3 [was: RE: CX LATAM coverage drop observed on 12/29-12/30 UTC (TFS# 719845)]", newBugId);
            var          appendOnlyMessage = mailManager.AddMessage(appendOnlySubject, comment);

            // Message has a conversation index that suggests it's related to a thread with some work item ID x, but it has
            // a subject that connects it to work item ID x+1
            // Should end up applying to the latter work-item (x+1)
            appendOnlyMessage.ConversationIndex = message1.ConversationIndex + "AAAA";

            ProcessMailbox(mailManager, instanceConfig, workItemManagerMock);

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

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

            Assert.AreEqual(2, workItemManagerMock.Bugs.Count, "Only one bug should exist");
            ValidateBugValues(expectedValues, workItemManagerMock.Bugs[newBugId]);
        }
        public void TestAppendOnlyMessageBody()
        {
            var seed = _rand.Next();

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

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

            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 newBugId = workItemManagerMock.Bugs.First().Key + 1;

            workItemManagerMock.Bugs.Add(newBugId, new Dictionary <string, string>());

            mailManager.Clear();

            var appendOnlyMessage = mailManager.AddMessage(false);

            appendOnlyMessage.PlainTextBody = string.Format("Blah !!!bug #{0}freqmnclkwerqcnew", newBugId);

            // Message has a conversation index that suggests it's related to a thread with some work item ID x, but it has
            // a subject that connects it to work item ID x+1
            // Should end up applying to the latter work-item (x+1)
            appendOnlyMessage.ConversationIndex = message1.ConversationIndex + "AAAA";

            ProcessMailbox(mailManager, instanceConfig, workItemManagerMock);

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

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

            Assert.AreEqual(2, workItemManagerMock.Bugs.Count, "Only one bug should exist");
            ValidateBugValues(expectedValues, workItemManagerMock.Bugs[newBugId]);
        }
        public void TestMenmonics()
        {
            var seed = _rand.Next();

            var mnemonicDef = new Config.MnemonicDefinition
            {
                Mnemonic = "UPPERCASElowercase", Field = "Mnemonic Field", Value = "Mnemonic Value"
            };

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

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

            message.PlainTextBody += string.Format("\n@@@{0}\n", mnemonicDef.Mnemonic.ToLower());

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

            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();

            foreach (var defaultValue in instanceConfig.WorkItemSettings.DefaultFieldValues)
            {
                var fieldValues = bug.Value;
                var fieldName   = defaultValue.Field;
                Assert.IsTrue(fieldValues.ContainsKey(fieldName), string.Format("Default value {0} isn't set in the bug", fieldName));
                Assert.AreEqual(defaultValue.Value, fieldValues[fieldName], string.Format("Value of field {0} is different than expected", fieldName));
            }

            Assert.IsTrue(bug.Value.ContainsKey(mnemonicDef.Field), "Check mnemonic field is set");
            Assert.AreEqual(mnemonicDef.Value, bug.Value[mnemonicDef.Field],
                            "Check mnemonic field contains the right value");
        }
        public void TestAttachOriginalMessage()
        {
            var rand = new Random();
            var seed = rand.Next();

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

            var mailManager = new MailManagerMock();

            mailManager.AddMessage(false);

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

            instanceConfig.WorkItemSettings.AttachOriginalMessage = true;
            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();

            Assert.IsTrue(workItemManagerMock.Attachments.ContainsKey(bug.Key));
            Assert.AreEqual(workItemManagerMock.Attachments[bug.Key].Count, 1);
        }
Esempio n. 10
0
        private static IncomingEmailMessageMock GetMessageWithOverrides(string alias, string mnemonic, string explicitField, string explicitValue)
        {
            var mailManager = new MailManagerMock();
            var message     = mailManager.AddMessage(false);

            if (!string.IsNullOrEmpty(mnemonic))
            {
                message.PlainTextBody += string.Format("@@@{0}\n", mnemonic);
            }

            if (!string.IsNullOrEmpty(explicitField))
            {
                message.PlainTextBody += string.Format("###{0}:{1}\n", explicitField, explicitValue);
            }

            if (!string.IsNullOrEmpty(alias))
            {
                var newTo = message.To.ToList();
                newTo.Add(BasicAlias);
                message.To = newTo;
            }

            return(message);
        }
Esempio n. 11
0
        public void TestSimpleRecipientOverride()
        {
            var config = GetConfig();

            config.WorkItemSettings.RecipientOverrides.Add(
                new Config.RecipientOverrideDefinition {
                Alias = BasicAlias.ToUpper(), Field = BasicField, Value = BasicValue
            });

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

            // Add the alias that will be resolved
            var newTo = message.To.ToList();

            newTo.Add(BasicAlias.ToLower());
            message.To = newTo;

            var extractor  = new OverridesExtractor(message, config);
            var dictionary = extractor.GetOverrides();

            Assert.IsTrue(dictionary.ContainsKey(BasicField), string.Format("Validate override for field {0} exists", BasicField));
            Assert.AreEqual(BasicValue, dictionary[BasicField], "Validate the right value was assigned as part of recipient overrides resolution");
        }
Esempio n. 12
0
        public void TestAttachingUpdateMessages()
        {
            var seed = _rand.Next();

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

            var mailManager = new MailManagerMock();
            var message1    = mailManager.AddMessage(false);
            var message2    = mailManager.AddReply(message1, "message 1");
            var message3    = mailManager.AddReply(message2, "message 2");

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

            instanceConfig.WorkItemSettings.AttachUpdateMessages = true;

            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);

            Assert.IsTrue(workItemManagerMock.Attachments.ContainsKey(bug.Key));
            Assert.AreEqual(workItemManagerMock.Attachments[bug.Key].Count, 3);
        }