Exemple #1
0
        public void Can_use_Dsl_to_update_parent_work_item_when_all_children_done()
        {
            // arrange
            var memLogger = Helpers.Logging.CreateMemoryTargetLogger(LogLevel.Debug);

            var emailProvider       = new Moq.Mock <IEmailProvider>();
            var azureDevOpsProvider = new Moq.Mock <IAzureDevOpsProvider>();

            azureDevOpsProvider.Setup(t => t.GetWorkItem(It.IsAny <int>())).Returns(RestTestData.GetSingleWorkItemByID());
            azureDevOpsProvider.Setup(t => t.GetParentWorkItem(It.IsAny <JObject>())).Returns(RestTestData.GetSingleWorkItemByID());
            azureDevOpsProvider.Setup(t => t.GetChildWorkItems(It.IsAny <JObject>())).Returns(RestTestData.GetSetOfWorkItemsByID(true));

            var eventDataProvider = new Moq.Mock <IEventDataProvider>();

            var engine = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();

            var args = new Dictionary <string, object> {
                { "Arguments", new[] { "workitem.updated", "100" } }
            };

            // act
            engine.RunScript(
                @"TestDataFiles\Scripts\AzureDevOps\alerts\changeparentworkitemstate.py",
                args,
                azureDevOpsProvider.Object,
                emailProvider.Object,
                eventDataProvider.Object);

            // assert
            foreach (var line in memLogger.Logs)
            {
                Console.WriteLine(line);
            }

            azureDevOpsProvider.Verify(t => t.UpdateWorkItem(It.IsAny <JObject>()));
            emailProvider.Verify(
                e => e.SendEmailAlert(
                    "*****@*****.**",
                    "Work item '309' has been updated",
                    "Work item '309' has been set as 'Done' as all its child work items are done"));
        }
        public void Can_use_Dsl_to_retrieve_a_child_work_items()
        {
            // arrange
            // redirect the console
            var consoleOut = Helpers.Logging.RedirectConsoleOut();

            var emailProvider       = new Moq.Mock <IEmailProvider>();
            var azureDevOpsProvider = new Moq.Mock <IAzureDevOpsProvider>();
            var eventDataProvider   = new Moq.Mock <IEventDataProvider>();

            azureDevOpsProvider.Setup(t => t.GetWorkItem(It.IsAny <int>())).Returns(RestTestData.GetSingleWorkItemWithReleationshipsByID());
            azureDevOpsProvider.Setup(t => t.GetChildWorkItems(It.IsAny <JObject>())).Returns(RestTestData.GetSetOfWorkItemsByID(false));
            var engine = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();

            // act
            engine.RunScript(@"TestDataFiles\Scripts\AzureDevOps\api\loadchildwi.py", azureDevOpsProvider.Object, emailProvider.Object, eventDataProvider.Object);

            // assert
            Assert.AreEqual(
                "Work item '23' has a child '297' with the title 'Customer can sign in using their Microsoft Account'" + Environment.NewLine +
                "Work item '23' has a child '299' with the title 'JavaScript implementation for Microsoft Account'" + Environment.NewLine +
                "Work item '23' has a child '300' with the title 'Unit Testing for MSA login'" + Environment.NewLine,
                consoleOut.ToString());
        }
Exemple #3
0
        public void Cannot_use_Dsl_to_update_parent_work_item_if_children_not_complete()
        {
            // arrange
            var memLogger = Helpers.Logging.CreateMemoryTargetLogger(LogLevel.Debug);

            var emailProvider       = new Moq.Mock <IEmailProvider>();
            var azureDevOpsProvider = new Moq.Mock <IAzureDevOpsProvider>();

            azureDevOpsProvider.Setup(t => t.GetWorkItem(It.IsAny <int>())).Returns(RestTestData.GetSingleWorkItemByID());
            azureDevOpsProvider.Setup(t => t.GetParentWorkItem(It.IsAny <JObject>())).Returns(RestTestData.GetSingleWorkItemByID());
            azureDevOpsProvider.Setup(t => t.GetChildWorkItems(It.IsAny <JObject>())).Returns(RestTestData.GetSetOfWorkItemsByID(false));

            var eventDataProvider = new Moq.Mock <IEventDataProvider>();

            var engine = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();

            var args = new Dictionary <string, object> {
                { "Arguments", new[] { "WorkItemEvent", "100" } }
            };

            // act
            engine.RunScript(
                @"TestDataFiles\Scripts\AzureDevOps\alerts\changeparentworkitemstate.py",
                args,
                azureDevOpsProvider.Object,
                emailProvider.Object,
                eventDataProvider.Object);

            // assert
            foreach (var line in memLogger.Logs)
            {
                Console.WriteLine(line);
            }

            azureDevOpsProvider.Verify(t => t.UpdateWorkItem(It.IsAny <JObject>()), Times.Never());
        }