예제 #1
0
        public void Can_log_debug_message_to_nlog()
        {
            // arrange
            var emailProvider       = new Moq.Mock <IEmailProvider>();
            var azureDevOpsProvider = new Moq.Mock <IAzureDevOpsProvider>();
            var eventDataProvider   = new Moq.Mock <IEventDataProvider>();

            // create a memory logger
            var memLogger = Helpers.Logging.CreateMemoryTargetLogger(LogLevel.Debug);
            var engine    = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();

            // act
            engine.RunScript(
                @"TestDataFiles\Scripts\logging\logmessage.py",
                azureDevOpsProvider.Object,
                emailProvider.Object,
                eventDataProvider.Object);

            // assert
            Assert.AreEqual(7, memLogger.Logs.Count);
            // memLogger.Logs[0] is the log message from the runscript method
            // memLogger.Logs[1] is the log message from the runscript method
            // memLogger.Logs[2] is the log message from the runscript method
            Assert.AreEqual("DEBUG | AzureDevOpsEventsProcessor.Dsl.DslLibrary | This is a debug line", memLogger.Logs[3]);
            Assert.AreEqual("INFO | AzureDevOpsEventsProcessor.Dsl.DslLibrary | This is a info line", memLogger.Logs[4]);
            Assert.AreEqual("ERROR | AzureDevOpsEventsProcessor.Dsl.DslLibrary | This is an error line", memLogger.Logs[5]);
            Assert.AreEqual("DEBUG | AzureDevOpsEventsProcessor.Dsl.DslLibrary | List: [List item 1] [List item 2] ", memLogger.Logs[6]);
        }
        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());
        }
예제 #3
0
        public void Can_use_methods_in_two_dsl_libraries_script()
        {
            // arrange
            var emailProvider       = new Moq.Mock <IEmailProvider>();
            var azureDevOpsProvider = new Moq.Mock <IAzureDevOpsProvider>();
            var eventDataProvider   = new Moq.Mock <IEventDataProvider>();


            // create a memory logger
            var memLogger = Helpers.Logging.CreateMemoryTargetLogger(LogLevel.Info);
            var engine    = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();

            // act
            engine.RunScript(
                @"testDataFiles\scripts\scripting\twolibraries.py",
                azureDevOpsProvider.Object,
                emailProvider.Object,
                eventDataProvider.Object);

            // assert
            Assert.AreEqual(4, memLogger.Logs.Count);
            // memLogger.Logs[0] is the log message from the runscript method
            // memLogger.Logs[1] is the log message from the runscript method
            // memLogger.Logs[2] is the log message from the runscript method
            Assert.AreEqual("INFO | AzureDevOpsEventsProcessor.Dsl.DslLibrary | When you add 1 and 2 you get 3", memLogger.Logs[3]);

            emailProvider.Verify(e => e.SendEmailAlert("*****@*****.**", "The subject", "When you add 1 and 2 you get 3"));
        }
        public void Can_use_Dsl_to_retrieve_a_push()
        {
            // 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.GetPushDetails("3c4e22ee-6148-45a3-913b-454009dac91d", 73)).Returns(RestTestData.GetPushDetails());
            azureDevOpsProvider.Setup(t => t.GetCommitDetails(It.IsAny <Uri>())).Returns(RestTestData.GetCommitDetails());
            var engine = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();

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

            // assert
            Assert.AreEqual(
                "Push '73' contains 2 commits\r\nCommit be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4\r\nCommit be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4\r\n",
                consoleOut.ToString());
        }
예제 #5
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));
        }
        public void Get_error_log_if_pass_invalid_eventype_provided()
        {
            // arrange
            var memLogger = Helpers.Logging.CreateMemoryTargetLogger(LogLevel.Error);

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


            var engine = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();
            var args   = new Dictionary <string, object>
            {
                { "Arguments", new[] { "Invalidstring", "ignored" } },
            };

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

            // assert
            Assert.AreEqual(2, memLogger.Logs.Count);
            Assert.AreEqual("ERROR | AzureDevOpsEventsProcessor.Dsl.DslLibrary | Was not expecting to get here", memLogger.Logs[0]);
            Assert.AreEqual("ERROR | AzureDevOpsEventsProcessor.Dsl.DslLibrary | List: [Invalidstring] [ignored] ", memLogger.Logs[1]);
        }
        public void Can_use_Dsl_to_retrieve_a_changeset()
        {
            // 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.GetChangesetDetails(7)).Returns(RestTestData.GetChangeSetDetails());
            var engine = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();

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

            // assert
            Assert.AreEqual(
                "Changeset '7' has the comment 'Added 2 files to SampleProject' and contains 2 files" + Environment.NewLine,
                consoleOut.ToString());
        }
예제 #8
0
        public void Error_logged_if_no_Dsl_library_in_dsl_folder()
        {
            // arrange
            var emailProvider       = new Moq.Mock <IEmailProvider>();
            var azureDevOpsProvider = new Moq.Mock <IAzureDevOpsProvider>();
            var eventDataProvider   = new Moq.Mock <IEventDataProvider>();

            // create a memory logger
            var memLogger = Helpers.Logging.CreateMemoryTargetLogger(LogLevel.Info);
            var engine    = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();

            // act
            engine.RunScript(
                @"testDataFiles\scripts\scripting",
                @"testDataFiles\scripts\scripting\args.py",
                string.Empty,
                null,
                azureDevOpsProvider.Object,
                emailProvider.Object,
                eventDataProvider.Object);

            // assert
            Assert.AreEqual(3, memLogger.Logs.Count);
            // memLogger.Logs[0] is the log message from the runscript method
            // memLogger.Logs[1] is the log message from the runscript method
            Assert.IsTrue(memLogger.Logs[2].StartsWith(@"ERROR | AzureDevOpsEventsProcessor.Dsl.DslProcessor | DslProcessor: DslProcessor cannot find DSL libraries in folder "));
        }
예제 #9
0
        public void Can_pass_argument_to_named_script()
        {
            // arrange
            // redirect the console
            var consoleOut = new StringWriter();

            Console.SetOut(consoleOut);

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


            var args = new Dictionary <string, object>
            {
                { "Arguments", new[] { "foo", "bar", "biz baz" } },
            };
            var engine = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();

            // act
            engine.RunScript(
                @".\testDataFiles\scripts\scripting\args.py",
                args,
                azureDevOpsProvider.Object,
                emailProvider.Object,
                eventDataProvider.Object);

            // assert

            Assert.AreEqual("['foo', 'bar', 'biz baz']" + Environment.NewLine, consoleOut.ToString());
        }
        public void Can_use_Dsl_to_get_build_details()
        {
            // arrange
            var consoleOut = Helpers.Logging.RedirectConsoleOut();

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

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

            azureDevOpsProvider.Setup(t => t.GetBuildDetails(It.IsAny <int>())).Returns(RestTestData.GetBuildDetails());
            var engine = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();

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


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

            // assert
            Assert.AreEqual("Build 'vstfs:///Build/Build/391' has the result 'succeeded'" + 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());
        }
        public void Can_pass_realistic_build_arguments_to_script()
        {
            // 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>();

            var args = new Dictionary <string, object>
            {
                { "Arguments", new[] { "build.complete", "123" } },
            };
            var engine = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();

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

            // assert

            Assert.AreEqual("Got a known build.complete event type with id 123" + Environment.NewLine, consoleOut.ToString());
        }
        public void Can_use_Dsl_to_update_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.CreateWorkItem(
                                          "tp",
                                          "Bug",
                                          new Dictionary <string, object>()
            {
                { "Title", "The Title" },
                { "Estimate", 2 }
            })).Returns(RestTestData.CreateWorkItem());
            var engine = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();

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

            // assert
            azureDevOpsProvider.Verify(t => t.UpdateWorkItem(It.IsAny <JObject>()));
        }
예제 #14
0
        public void Error_logged_if_no_Dsl_library_folder_found()
        {
            // arrange
            var emailProvider       = new Moq.Mock <IEmailProvider>();
            var azureDevOpsProvider = new Moq.Mock <IAzureDevOpsProvider>();
            var eventDataProvider   = new Moq.Mock <IEventDataProvider>();

            // create a memory logger
            var memLogger = Helpers.Logging.CreateMemoryTargetLogger(LogLevel.Info);
            var engine    = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();

            // act
            engine.RunScript(
                @"c:\dummy",
                @"testDataFiles\scripts\scripting\args.py",
                string.Empty,
                null,
                azureDevOpsProvider.Object,
                emailProvider.Object,
                eventDataProvider.Object);

            // assert
            Assert.AreEqual(1, memLogger.Logs.Count);
            Assert.AreEqual(@"ERROR | AzureDevOpsEventsProcessor.Dsl.DslProcessor | DslProcessor: DslProcessor cannot find DSL folder c:\dummy", memLogger.Logs[0]);
        }
예제 #15
0
        public void A_null_dsl_script_throws_exception()
        {
            // arrange
            var engine = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();

            // act // assert
            Assert.Throws <ArgumentNullException>(() => engine.RunScript(null, null, null, null));
        }
예제 #16
0
        public void A_missing_AzureDevOps_provider_throws_exception()
        {
            // arrange
            var engine = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();

            // act // assert
            Assert.Throws <ArgumentNullException>(() => engine.RunScript(@"testDataFiles\scripts\scripting\badscript1.py", null, null, null));
        }
예제 #17
0
        public void A_missing_EventData_provider_throws_exception()
        {
            // arrange
            var azureDevOpsProvider = new Moq.Mock <IAzureDevOpsProvider>();
            var emailProvider       = new Moq.Mock <IEmailProvider>();
            var engine = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();

            // act // assert
            Assert.Throws <ArgumentNullException>(() => engine.RunScript(@"testDataFiles\scripts\scripting\badscript1.py", azureDevOpsProvider.Object, emailProvider.Object, null));
        }
예제 #18
0
        public void A_script_with_an_invalid_DSL_call_throws_exception()
        {
            // arrange
            var emailProvider       = new Moq.Mock <IEmailProvider>();
            var azureDevOpsProvider = new Moq.Mock <IAzureDevOpsProvider>();
            var eventDataProvider   = new Moq.Mock <IEventDataProvider>();
            var engine = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();

            // act // assert
            Assert.Throws <UnboundNameException>(() => engine.RunScript(@"testDataFiles\scripts\scripting\badscript2.py", azureDevOpsProvider.Object, emailProvider.Object, eventDataProvider.Object));
        }
예제 #19
0
        public void A_script_with_syntax_error_throws_exception()
        {
            // arrange
            var emailProvider       = new Moq.Mock <IEmailProvider>();
            var azureDevOpsProvider = new Moq.Mock <IAzureDevOpsProvider>();
            var eventDataProvider   = new Moq.Mock <IEventDataProvider>();

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

            // act // assert
            Assert.Throws <SyntaxErrorException>(() => engine.RunScript(@"testDataFiles\scripts\scripting\badscript1.py", azureDevOpsProvider.Object, emailProvider.Object, eventDataProvider.Object));
        }
예제 #20
0
        public void Can_use_Dsl_to_send_an_email()
        {
            // 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>();

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

            // act
            engine.RunScript(@"TestDataFiles\Scripts\email\sendemail.py", azureDevOpsProvider.Object, emailProvider.Object, eventDataProvider.Object);

            // assert
            emailProvider.Verify(e => e.SendEmailAlert("*****@*****.**", "The subject", "The body of the email"));
        }
        public void Can_use_Dsl_to_set_build_retension()
        {
            // arrange
            var consoleOut          = Helpers.Logging.RedirectConsoleOut();
            var emailProvider       = new Moq.Mock <IEmailProvider>();
            var azureDevOpsProvider = new Moq.Mock <IAzureDevOpsProvider>();
            var engine            = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();
            var eventDataProvider = new Moq.Mock <IEventDataProvider>();


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

            // assert
            azureDevOpsProvider.Verify(t => t.SetBuildRetension(It.IsAny <Uri>(), true));
            Assert.AreEqual(
                "Set build retension for 'http://dummy/_api/build'" + Environment.NewLine,
                consoleOut.ToString());
        }
예제 #22
0
        public void Can_log_error_messages_only_to_nlog()
        {
            // arrange
            var emailProvider       = new Moq.Mock <IEmailProvider>();
            var azureDevOpsProvider = new Moq.Mock <IAzureDevOpsProvider>();
            var eventDataProvider   = new Moq.Mock <IEventDataProvider>();


            // create a memory logger
            var memLogger = Helpers.Logging.CreateMemoryTargetLogger(LogLevel.Error);
            var engine    = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();

            // act
            engine.RunScript(@"TestDataFiles\Scripts\logging\logmessage.py", azureDevOpsProvider.Object, emailProvider.Object, eventDataProvider.Object);

            // assert
            Assert.AreEqual(1, memLogger.Logs.Count);
            Assert.AreEqual("ERROR | AzureDevOpsEventsProcessor.Dsl.DslLibrary | This is an error line", memLogger.Logs[0]);
        }
        public void Can_use_Dsl_to_update_a_build_tag()
        {
            // arrange
            var consoleOut          = Helpers.Logging.RedirectConsoleOut();
            var emailProvider       = new Moq.Mock <IEmailProvider>();
            var azureDevOpsProvider = new Moq.Mock <IAzureDevOpsProvider>();
            var engine            = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();
            var eventDataProvider = new Moq.Mock <IEventDataProvider>();

            azureDevOpsProvider.Setup(t => t.GetBuildDetails(It.IsAny <int>())).Returns(RestTestData.GetBuildDetails());

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

            // assert
            azureDevOpsProvider.Verify(t => t.AddBuildTag(It.IsAny <Uri>(), "The Tag"));
            Assert.AreEqual(
                "Set tag for build for '123'" + Environment.NewLine,
                consoleOut.ToString());
        }
예제 #24
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"));
        }
예제 #25
0
        public void Can_use_Dsl_to_increment_build_argument()
        {
            // arrange
            var emailProvider = new Moq.Mock <IEmailProvider>();

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

            azureDevOpsProvider.Setup(t => t.GetBuildDetails(It.IsAny <int>())).Returns(RestTestData.GetBuildDetails());
            azureDevOpsProvider.Setup(t => t.GetBuildArgument(It.IsAny <Uri>(), "MajorVersion")).Returns("1");
            azureDevOpsProvider.Setup(t => t.GetBuildArgument(It.IsAny <Uri>(), "MinorVersion")).Returns("6");

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

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

            var args = new Dictionary <string, object>
            {
                {
                    "Arguments",
                    new[] { "build.complete", "391" }
                },
            };

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

            // assert

            emailProvider.Verify(
                e =>
                e.SendEmailAlert(
                    "*****@*****.**",
                    "VsoBuildApi version incremented",
                    "'VsoBuildApi' version incremented to 1.7.x.x"));
        }
        public void Can_use_Dsl_to_unset_build_retension_by_quality()
        {
            // arrange
            var memLogger = Helpers.Logging.CreateMemoryTargetLogger(LogLevel.Debug);

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

            var build = RestTestData.GetBuildDetails();

            build["result"] = "failed";

            azureDevOpsProvider.Setup(t => t.GetBuildDetails(It.IsAny <int>())).Returns(build);

            var engine = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();
            var args   = new Dictionary <string, object>
            {
                { "Arguments", new[] { "build.complete", "391" } },
            };

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

            // assert
            azureDevOpsProvider.Verify(t => t.SetBuildRetension(It.IsAny <Uri>(), false));
            emailProvider.Verify(e => e.SendEmailAlert("*****@*****.**", "20150716.2 retension set to False", "'20150716.2' retension set to 'False' as result was 'failed'"));

            Assert.AreEqual(4, memLogger.Logs.Count);
            // memLogger.Logs[0] is the log message from the runscript method
            // memLogger.Logs[1] is the log message from the runscript method
            // memLogger.Logs[2] is the log message from the runscript method
            Assert.AreEqual("INFO | AzureDevOpsEventsProcessor.Dsl.DslLibrary | '20150716.2' retension set to 'False' as result was 'failed'", memLogger.Logs[3]);
        }
        public void Can_use_Dsl_to_create_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.CreateWorkItem(
                                          It.IsAny <string>(),
                                          It.IsAny <string>(),
                                          It.IsAny <Dictionary <string, object> >())).Returns(RestTestData.CreateWorkItem());
            var engine = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();

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

            // assert
            azureDevOpsProvider.Verify(t => t.CreateWorkItem(
                                           "SampleProject",
                                           "Bug",
                                           new Dictionary <string, object>()
            {
                { "System.Title", "The Title" },
                { "Microsoft.VSTS.Scheduling.Effort", 2 }
            }));

            Assert.AreEqual(
                "Work item '299' has been created with the title 'JavaScript implementation for Microsoft Account'" + Environment.NewLine,
                consoleOut.ToString());
        }
예제 #28
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());
        }
        public void Can_run_a_script_against_live()
        {
            // arrange
            var memLogger = Helpers.Logging.CreateMemoryTargetLogger(LogLevel.Debug);
            var uri       = new Uri("https://dev.azure.com/instance");
            var pat       = "<YOUR PAT>";
            var wi        = 98578;
            var eventType = "workitem.updated";

            var emailProvider       = new Moq.Mock <IEmailProvider>();
            var azureDevOpsProvider = new AzureDevOpsProvider(uri, pat);
            var eventDataProvider   = new Moq.Mock <IEventDataProvider>();

            var engine = new AzureDevOpsEventsProcessor.Dsl.DslProcessor();
            var args   = new Dictionary <string, object>
            {
                { "Arguments", new[] { eventType, wi.ToString() } },
            };

            // act
            // add the name of the script you want to locally debug
            engine.RunScript(
                @"TestDataFiles\Scripts\AzureDevOps\alerts\markparentasblocked.py",
                args,
                azureDevOpsProvider,
                emailProvider.Object,
                eventDataProvider.Object
                );

            // assert

            // dump the log to look at
            Console.Write(string.Join(Environment.NewLine, memLogger.Logs));
            // Always fail as this is a manual test in relity
            Assert.IsFalse(true);
        }
        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());
        }