public void Can_use_Dsl_to_find_if_no_parent_work_item()
        {
            // 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(297)).Returns(RestTestData.GetSingleWorkItemByID());
            // don't need to assign a value for the parent call as will return null by default
            var engine = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();

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

            // assert
            Assert.AreEqual(
                "Work item '309' has no parent" + Environment.NewLine,
                consoleOut.ToString());
        }
        public void Can_use_Dsl_to_retrieve_a_work_item()
        {
            // 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(297)).Returns(RestTestData.GetSingleWorkItemByID());
            var engine = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();

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

            // assert
            Assert.AreEqual(
                "Work item '309' has the title 'Customer can sign in using their Microsoft Account'" + Environment.NewLine,
                consoleOut.ToString());
        }
Beispiel #3
0
        public void Can_use_Dsl_to_send_templated_email()
        {
            // arrange
            var emailProvider       = new Moq.Mock <IEmailProvider>();
            var azureDevOpsProvider = new Moq.Mock <IAzureDevOpsProvider>();

            azureDevOpsProvider.Setup(t => t.GetWorkItem(99)).Returns(RestTestData.GetSingleWorkItemByID());

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

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

            // act
            engine.RunScript(
                @".\dsl",
                @"TestDataFiles\Scripts\AzureDevOps\alerts",
                "sendtemplatedemail.py",
                args,
                azureDevOpsProvider.Object,
                emailProvider.Object,
                new Providers.JsonDataProvider(ServiceHookTestData.GetEventJson("workitem.updated")));

            // assert
            emailProvider.Verify(
                e =>
                e.SendEmailAlert(
                    Moq.It.IsAny <IFieldLookupProvider>(),
                    System.IO.Path.Combine(engine.BasePath, @"TestDataFiles\Scripts\AzureDevOps\alerts\EmailTemplate.htm"),
                    true,
                    true));
        }
Beispiel #4
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"));
        }
Beispiel #5
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());
        }