コード例 #1
0
        public void Can_use_Dsl_to_send_templated_email()
        {
            using (ShimsContext.Create())
            {
                // arrange
                var wi = new ShimWorkItem()
                {
                    TitleGet = () => "The wi title", IdGet = () => 99
                };
                var emailProvider = new Moq.Mock <IEmailProvider>();
                var tfsProvider   = new Moq.Mock <ITfsProvider>();
                tfsProvider.Setup(t => t.GetWorkItem(99)).Returns(wi);
                var engine = new TFSEventsProcessor.Dsl.DslProcessor();

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

                // act
                engine.RunScript(
                    @".\dsl",
                    @"dsl\tfs",
                    "sendtemplatedemail.py",
                    args,
                    tfsProvider.Object,
                    emailProvider.Object,
                    Helpers.TestData.DummyWorkItemChangedAlertXml());

                // assert
                emailProvider.Verify(
                    e =>
                    e.SendEmailAlert(Moq.It.IsAny <IFieldLookupProvider>(), @"dsl\tfs\EmailTemplate.htm", true, true));
            }
        }
コード例 #2
0
        public void Can_use_Dsl_to_update_a_work_item()
        {
            using (ShimsContext.Create())
            {
                // arrange
                // redirect the console
                var consoleOut = Helpers.Logging.RedirectConsoleOut();

                var wi = new ShimWorkItem()
                {
                    TitleGet = () => "Title", IdGet = () => 99
                };
                var emailProvider = new Moq.Mock <IEmailProvider>();
                var tfsProvider   = new Moq.Mock <ITfsProvider>();
                tfsProvider.Setup(t => t.CreateWorkItem(
                                      "tp",
                                      "Bug",
                                      new Dictionary <string, object>()
                {
                    { "Title", "The Title" },
                    { "Estimate", 2 }
                })).Returns(wi);
                var engine = new TFSEventsProcessor.Dsl.DslProcessor();

                // act
                engine.RunScript(@"dsl\tfs\updatewi.py", tfsProvider.Object, emailProvider.Object);

                // assert
                tfsProvider.Verify(t => t.UpdateWorkItem(It.IsAny <WorkItem>()));
            }
        }
コード例 #3
0
        public void Can_use_Dsl_to_retrieve_a_work_item()
        {
            using (ShimsContext.Create())
            {
                // arrange
                // redirect the console
                var consoleOut = Helpers.Logging.RedirectConsoleOut();

                var wi = new ShimWorkItem()
                {
                    TitleGet = () => "The wi title", IdGet = () => 99
                };
                var emailProvider = new Moq.Mock <IEmailProvider>();
                var tfsProvider   = new Moq.Mock <ITfsProvider>();
                tfsProvider.Setup(t => t.GetWorkItem(99)).Returns(wi);
                var engine = new TFSEventsProcessor.Dsl.DslProcessor();

                // act
                engine.RunScript(@"dsl\tfs\loadwi.py", tfsProvider.Object, emailProvider.Object);

                // assert
                Assert.AreEqual(
                    "Work item '99' has the title 'The wi title'" + Environment.NewLine,
                    consoleOut.ToString());
            }
        }
コード例 #4
0
        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 tfsProvider   = new Moq.Mock <ITfsProvider>();

            var testUri = new Uri("vstfs:///Build/Build/123");
            var build   = new Moq.Mock <IBuildDetail>();

            build.Setup(b => b.Uri).Returns(testUri);
            build.Setup(b => b.Quality).Returns("Test Failed");
            build.Setup(b => b.BuildNumber).Returns("CTAppBox.Main.CI_1.5.15.6731");

            tfsProvider.Setup(t => t.GetBuildDetails(It.IsAny <Uri>())).Returns(build.Object);

            var engine = new TFSEventsProcessor.Dsl.DslProcessor();
            var args   = new Dictionary <string, object>
            {
                { "Arguments", new[] { "BuildEvent", "vstfs:///Build/Build/123" } },
            };

            // act
            engine.RunScript(@"dsl\tfs\setbuildretensionbyquality.py", args, tfsProvider.Object, emailProvider.Object);

            // assert
            tfsProvider.Verify(t => t.SetBuildRetension(testUri, false));
            emailProvider.Verify(e => e.SendEmailAlert("richard@typhoontfs", "CTAppBox.Main.CI_1.5.15.6731 quality changed", "'CTAppBox.Main.CI_1.5.15.6731' retension set to 'False' as quality was changed to 'Test Failed'"));

            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.AreEqual("INFO | TFSEventsProcessor.Dsl.DslLibrary | 'CTAppBox.Main.CI_1.5.15.6731' retension set to 'False' as quality was changed to 'Test Failed'", memLogger.Logs[2]);
        }
コード例 #5
0
        public void Can_use_Dsl_to_find_if_no_parent_work_item()
        {
            using (ShimsContext.Create())
            {
                // arrange
                // redirect the console
                var consoleOut = Helpers.Logging.RedirectConsoleOut();

                var wi = new ShimWorkItem()
                {
                    TitleGet = () => "The wi title", IdGet = () => 99
                };
                var emailProvider = new Moq.Mock <IEmailProvider>();
                var tfsProvider   = new Moq.Mock <ITfsProvider>();
                tfsProvider.Setup(t => t.GetWorkItem(99)).Returns(wi);
                // don't need to assign a value for the parent call as will return null by default
                var engine = new TFSEventsProcessor.Dsl.DslProcessor();

                // act
                engine.RunScript(@"dsl\tfs\loadparentwi.py", tfsProvider.Object, emailProvider.Object);

                // assert
                Assert.AreEqual(
                    "Work item '99' has no parent" + Environment.NewLine,
                    consoleOut.ToString());
            }
        }
コード例 #6
0
        public void Can_use_Dsl_to_retrieve_a_changeset()
        {
            using (ShimsContext.Create())
            {
                // arrange
                // redirect the console
                var consoleOut = Helpers.Logging.RedirectConsoleOut();

                var cs = new ShimChangeset()
                {
                    CommentGet = () => "A comment", ChangesetIdGet = () => 99
                };
                var emailProvider = new Moq.Mock <IEmailProvider>();
                var tfsProvider   = new Moq.Mock <ITfsProvider>();
                tfsProvider.Setup(t => t.GetChangeSet(99)).Returns(cs);
                var engine = new TFSEventsProcessor.Dsl.DslProcessor();

                // act
                engine.RunScript(@"dsl\tfs\loadchangeset.py", tfsProvider.Object, emailProvider.Object);

                // assert
                Assert.AreEqual(
                    "Changeset '99' has the comment 'A comment'" + Environment.NewLine,
                    consoleOut.ToString());
            }
        }
コード例 #7
0
        public void Cannot_use_Dsl_to_update_parent_work_item_if_children_not_complete()
        {
            using (ShimsContext.Create())
            {
                // arrange
                var memLogger = Helpers.Logging.CreateMemoryTargetLogger(LogLevel.Debug);

                var emailProvider = new Moq.Mock <IEmailProvider>(MockBehavior.Strict);
                var wi100         = new ShimWorkItem()
                {
                    TitleGet = () => "The child title",
                    IdGet    = () => 100,
                    StateGet = () => "Done"
                };
                var wi101 = new ShimWorkItem()
                {
                    TitleGet = () => "The child title",
                    IdGet    = () => 101,
                    StateGet = () => "Committed"
                };
                var parent99 = new ShimWorkItem()
                {
                    TitleGet = () => "The parent title",
                    IdGet    = () => 99,
                    StateGet = () => "Committed"
                };


                var tfsProvider = new Moq.Mock <ITfsProvider>(MockBehavior.Strict);
                tfsProvider.Setup(t => t.GetWorkItem(It.IsAny <int>())).Returns(wi100);
                tfsProvider.Setup(t => t.GetParentWorkItem(It.IsAny <WorkItem>())).Returns(parent99);
                tfsProvider.Setup(t => t.GetChildWorkItems(It.IsAny <WorkItem>()))
                .Returns(new WorkItem[] { wi100, wi101 });

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

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

                // act
                engine.RunScript(
                    @"dsl\tfs\changeparentworkitemstate.py",
                    args,
                    tfsProvider.Object,
                    emailProvider.Object);

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

                // we rely on the MockBehavior.Strict to throw an error if any methods are called we have not expected
                // i.e. a call to the emailer or update of the work item
            }
        }
コード例 #8
0
        public void A_null_dsl_script_throws_exception()
        {
            // arrange
            var engine = new TFSEventsProcessor.Dsl.DslProcessor();

            // act
            engine.RunScript(null, null, null);

            // assert
            // checked in attribute
        }
コード例 #9
0
        public void A_missing_TFS_provider_throws_exception()
        {
            // arrange
            var engine = new TFSEventsProcessor.Dsl.DslProcessor();

            // act
            engine.RunScript(@"dsl\scripting\badscript1.py", null, null);

            // assert
            // checked in attribute
        }
コード例 #10
0
        public void A_missing_Email_provider_throws_exception()
        {
            // arrange
            var tfsProvider = new Moq.Mock <ITfsProvider>();
            var engine      = new TFSEventsProcessor.Dsl.DslProcessor();

            // act
            engine.RunScript(@"dsl\scripting\badscript1.py", tfsProvider.Object, null);

            // assert
            // checked in attribute
        }
コード例 #11
0
        public void A_script_with_an_invalid_DSL_call_throws_exception()
        {
            // arrange
            var emailProvider = new Moq.Mock <IEmailProvider>();
            var tfsProvider   = new Moq.Mock <ITfsProvider>();
            var engine        = new TFSEventsProcessor.Dsl.DslProcessor();

            // act
            engine.RunScript(@"dsl\scripting\badscript2.py", tfsProvider.Object, emailProvider.Object);

            // assert
            // checked in attribute
        }
コード例 #12
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 tfsProvider   = new Moq.Mock <ITfsProvider>();
            var engine        = new TFSEventsProcessor.Dsl.DslProcessor();

            // act
            engine.RunScript(@"dsl\email\sendemail.py", tfsProvider.Object, emailProvider.Object);

            // assert
            emailProvider.Verify(e => e.SendEmailAlert("*****@*****.**", "The subject", "The body of the email"));
        }
コード例 #13
0
        public void Can_log_error_messages_only_to_nlog()
        {
            // arrange
            var emailProvider = new Moq.Mock <IEmailProvider>();
            var tfsProvider   = new Moq.Mock <ITfsProvider>();

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

            // act
            engine.RunScript(@"dsl\logging\logmessage.py", tfsProvider.Object, emailProvider.Object);

            // assert
            Assert.AreEqual(1, memLogger.Logs.Count);
            Assert.AreEqual("ERROR | TFSEventsProcessor.Dsl.DslLibrary | This is an error line", memLogger.Logs[0]);
        }
コード例 #14
0
        public void Can_use_Dsl_to_increment_build_argument()
        {
            // arrange
            var buildUri    = new Uri("vstfs:///Build/Build/123");
            var buildDefUri = new Uri("vstfs:///Build/Build/XYZ");

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

            build.Setup(b => b.Uri).Returns(buildUri);
            build.Setup(b => b.Quality).Returns("Released");
            build.Setup(b => b.BuildDefinitionUri).Returns(buildDefUri);
            build.Setup(b => b.BuildDefinition.Name).Returns("Build Def");

            var tfsProvider = new Moq.Mock <ITfsProvider>();

            tfsProvider.Setup(t => t.GetBuildDetails(It.IsAny <Uri>())).Returns(build.Object);
            tfsProvider.Setup(t => t.GetBuildArgument(It.IsAny <Uri>(), "MajorVersion")).Returns(1);
            tfsProvider.Setup(t => t.GetBuildArgument(It.IsAny <Uri>(), "MinorVersion")).Returns(6);
            tfsProvider.Setup(t => t.GetBuildArgument(It.IsAny <Uri>(), "MinorVersion")).Returns(7);
            // used for the second call
            tfsProvider.Setup(t => t.GetBuildArgument(It.IsAny <Uri>(), "VersionStartDate")).Returns("1 Jan 2012");

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

            var args = new Dictionary <string, object>
            {
                {
                    "Arguments",
                    new[] { "BuildEvent", "vstfs:///Build/Build/123" }
                },
            };

            // act
            engine.RunScript(@"dsl\tfs\incrementbuildargument.py", args, tfsProvider.Object, emailProvider.Object);

            // assert

            emailProvider.Verify(
                e =>
                e.SendEmailAlert(
                    "richard@typhoontfs",
                    "Build Def version incremented",
                    "'Build Def' version incremented to 1.7.[days since 1 Jan 2012].[build count] as last build quality set to 'Released'"));
        }
コード例 #15
0
        public void Can_use_Dsl_to_set_build_retension()
        {
            // arrange
            var consoleOut    = Helpers.Logging.RedirectConsoleOut();
            var emailProvider = new Moq.Mock <IEmailProvider>();
            var tfsProvider   = new Moq.Mock <ITfsProvider>();
            var testUri       = new Uri("vstfs:///Build/Build/123");
            var engine        = new TFSEventsProcessor.Dsl.DslProcessor();

            // act
            engine.RunScript(@"dsl\tfs\keepbuild.py", tfsProvider.Object, emailProvider.Object);

            // assert
            tfsProvider.Verify(t => t.SetBuildRetension(testUri, true));
            Assert.AreEqual(
                "Set build retension for 'vstfs:///Build/Build/123'" + Environment.NewLine,
                consoleOut.ToString());
        }
コード例 #16
0
        public void Error_logged_if_no_Dsl_library_folder_found()
        {
            // arrange
            var emailProvider = new Moq.Mock <IEmailProvider>();
            var tfsProvider   = new Moq.Mock <ITfsProvider>();

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

            // act
            engine.RunScript(@"c:\dummy", @"dsl\scripting\args.py", string.Empty, null, tfsProvider.Object, emailProvider.Object, string.Empty);

            // assert
            Assert.AreEqual(2, memLogger.Logs.Count);
            // memLogger.Logs[0] is the log message from the runscript method
            Assert.AreEqual(@"ERROR | TFSEventsProcessor.Dsl.DslProcessor | TFSEventsProcessor: DslProcessor cannot find DSL folder c:\dummy", memLogger.Logs[1]);
        }
コード例 #17
0
        public void Can_log_info_and_error_messages_only_to_nlog()
        {
            // arrange
            var emailProvider = new Moq.Mock <IEmailProvider>();
            var tfsProvider   = new Moq.Mock <ITfsProvider>();

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

            // act
            engine.RunScript(@"dsl\logging\logmessage.py", tfsProvider.Object, emailProvider.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
            Assert.AreEqual("INFO | TFSEventsProcessor.Dsl.DslLibrary | This is a info line", memLogger.Logs[2]);
            Assert.AreEqual("ERROR | TFSEventsProcessor.Dsl.DslLibrary | This is an error line", memLogger.Logs[3]);
        }
コード例 #18
0
        public void Can_use_Dsl_to_create_a_work_item()
        {
            using (ShimsContext.Create())
            {
                // arrange
                // redirect the console
                var consoleOut = Helpers.Logging.RedirectConsoleOut();

                var wi = new ShimWorkItem()
                {
                    TitleGet = () => "Title", IdGet = () => 99
                };
                var emailProvider = new Moq.Mock <IEmailProvider>();
                var tfsProvider   = new Moq.Mock <ITfsProvider>();
                tfsProvider.Setup(t => t.CreateWorkItem(
                                      "tp",
                                      "Bug",
                                      new Dictionary <string, object>()
                {
                    { "Title", "The Title" },
                    { "Estimate", 2 }
                })).Returns(wi);
                var engine = new TFSEventsProcessor.Dsl.DslProcessor();

                // act
                engine.RunScript(@"dsl\tfs\createwi.py", tfsProvider.Object, emailProvider.Object);

                // assert
                tfsProvider.Verify(t => t.CreateWorkItem("tp",
                                                         "Bug",
                                                         new Dictionary <string, object>()
                {
                    { "Title", "The Title" },
                    { "Estimate", 2 }
                }));

                Assert.AreEqual(
                    "Work item '99' has been created with the title 'Title'" + Environment.NewLine,
                    consoleOut.ToString());
            }
        }
コード例 #19
0
        public void Can_use_methods_in_two_dsl_libraries_script()
        {
            // arrange
            var emailProvider = new Moq.Mock <IEmailProvider>();
            var tfsProvider   = new Moq.Mock <ITfsProvider>();

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

            // act
            engine.RunScript(@"dsl\scripting\twolibraries.py", tfsProvider.Object, emailProvider.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.AreEqual("INFO | TFSEventsProcessor.Dsl.DslLibrary | When you add 1 and 2 you get 3", memLogger.Logs[2]);

            emailProvider.Verify(e => e.SendEmailAlert("*****@*****.**", "The subject", "When you add 1 and 2 you get 3"));
        }
コード例 #20
0
        public void Can_use_Dsl_to_get_build_details()
        {
            // arrange
            var consoleOut = Helpers.Logging.RedirectConsoleOut();
            var testUri    = new Uri("vstfs:///Build/Build/123");

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

            build.Setup(b => b.Uri).Returns(testUri);
            build.Setup(b => b.Quality).Returns("Test Quality");

            var tfsProvider = new Moq.Mock <ITfsProvider>();

            tfsProvider.Setup(t => t.GetBuildDetails(It.IsAny <Uri>())).Returns(build.Object);
            var engine = new TFSEventsProcessor.Dsl.DslProcessor();

            // act
            engine.RunScript(@"dsl\tfs\loadbuild.py", tfsProvider.Object, emailProvider.Object);
            // assert
            Assert.AreEqual("Build 'vstfs:///Build/Build/123' has the quality 'Test Quality'" + Environment.NewLine, consoleOut.ToString());
        }
コード例 #21
0
        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 tfsProvider   = new Moq.Mock <ITfsProvider>();

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

            // act
            engine.RunScript(@"dsl\tfs\setbuildretensionbyquality.py", args, tfsProvider.Object, emailProvider.Object);

            // assert
            Assert.AreEqual(2, memLogger.Logs.Count);
            Assert.AreEqual("ERROR | TFSEventsProcessor.Dsl.DslLibrary | Was not expecting to get here", memLogger.Logs[0]);
            Assert.AreEqual("ERROR | TFSEventsProcessor.Dsl.DslLibrary | List: [Invalidstring] [ignored] ", memLogger.Logs[1]);
        }
コード例 #22
0
        public void Can_use_Dsl_to_unset_build_retension_and_send_email()
        {
            // arrange
            var testUri = new Uri("vstfs:///Build/Build/123");

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

            build.Setup(b => b.Uri).Returns(testUri);
            build.Setup(b => b.Quality).Returns("Test Failed");
            build.Setup(b => b.BuildNumber).Returns("123");

            var tfsProvider = new Moq.Mock <ITfsProvider>();

            tfsProvider.Setup(t => t.GetBuildDetails(It.IsAny <Uri>())).Returns(build.Object);

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

            var args = new Dictionary <string, object>
            {
                {
                    "Arguments",
                    new[] { "BuildEvent", "vstfs:///Build/Build/123" }
                },
            };

            // act
            engine.RunScript(@"dsl\tfs\setbuildretensionbyquality.py", args, tfsProvider.Object, emailProvider.Object);

            // assert
            tfsProvider.Verify(t => t.SetBuildRetension(testUri, false));
            emailProvider.Verify(
                e =>
                e.SendEmailAlert(
                    "richard@typhoontfs",
                    "123 quality changed",
                    "'123' retension set to 'False' as quality was changed to 'Test Failed'"));
        }
コード例 #23
0
        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 tfsProvider   = new Moq.Mock <ITfsProvider>();

            var args = new Dictionary <string, object>
            {
                { "Arguments", new[] { "BuildEvent", "vstfs:///Build/Build/123" } },
            };
            var engine = new TFSEventsProcessor.Dsl.DslProcessor();

            // act
            engine.RunScript(@"dsl\tfs\fullscript.py", args, tfsProvider.Object, emailProvider.Object);

            // assert

            Assert.AreEqual("A build event vstfs:///Build/Build/123" + Environment.NewLine, consoleOut.ToString());
        }
コード例 #24
0
        public void Can_pass_argument_to_script_when_scripts_found_by_folder()
        {
            // arrange
            // redirect the console
            var consoleOut = new StringWriter();

            Console.SetOut(consoleOut);

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

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

            // act
            engine.RunScript(@".\dsl", @"dsl\scripting", "args.py", args, tfsProvider.Object, emailProvider.Object, string.Empty);

            // assert

            Assert.AreEqual("['foo', 'bar', 'biz baz']" + Environment.NewLine, consoleOut.ToString());
        }
コード例 #25
0
        public void Can_use_Dsl_to_update_parent_work_item_when_all_children_done()
        {
            using (ShimsContext.Create())
            {
                // arrange
                var memLogger = Helpers.Logging.CreateMemoryTargetLogger(LogLevel.Debug);

                var emailProvider = new Moq.Mock <IEmailProvider>();
                var wi100         = new ShimWorkItem()
                {
                    TitleGet = () => "The child title",
                    IdGet    = () => 100,
                    StateGet = () => "Done"
                };
                var wi101 = new ShimWorkItem()
                {
                    TitleGet = () => "The child title",
                    IdGet    = () => 101,
                    StateGet = () => "Done"
                };
                var parent99 = new ShimWorkItem()
                {
                    TitleGet = () => "The parent title",
                    IdGet    = () => 99,
                    StateGet = () => "Committed"
                };

                var tfsProvider = new Moq.Mock <ITfsProvider>();
                tfsProvider.Setup(t => t.GetWorkItem(It.IsAny <int>())).Returns(wi100);
                tfsProvider.Setup(t => t.GetParentWorkItem(It.IsAny <WorkItem>())).Returns(parent99);
                tfsProvider.Setup(t => t.GetChildWorkItems(It.IsAny <WorkItem>()))
                .Returns(new WorkItem[] { wi100, wi101 });

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

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

                // act
                engine.RunScript(
                    @"dsl\tfs\changeparentworkitemstate.py",
                    args,
                    tfsProvider.Object,
                    emailProvider.Object);

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

                tfsProvider.Verify(t => t.UpdateWorkItem(parent99));
                emailProvider.Verify(
                    e =>
                    e.SendEmailAlert(
                        "richard@typhoontfs",
                        "Work item '99' has been updated",
                        "Work item '99' has been set as 'Done' as all its child work items are done"));
            }
        }
コード例 #26
0
        public void Notify(string eventXml, string tfsIdentityXml)
        {
            try
            {
                if (ConfigHelper.ParseOrDefault(System.Configuration.ConfigurationManager.AppSettings["LogEventsToFile"]) == true)
                {
                    var logPath = ConfigHelper.GetLoggingPath();
                    logger.Info(string.Format("TFSEventsProcessor: DslScriptService Event being logged to [{0}]", logPath));
                    LoggingHelper.DumpEventToDisk(eventXml, logPath);
                }

                // Create a new Tfs helper
                this.iTfsProvider.UnpackIdentity(tfsIdentityXml);

                // work out the event type
                string[] argItems = null;
                try
                {
                    var buildDetails = EventXmlHelper.GetBuildStatusChangedAlertFields(eventXml);
                    argItems = new[] { EventTypes.BuildEvent.ToString(), buildDetails.BuildUri.ToString() };
                    logger.Info(string.Format(
                                    "TFSEventsProcessor: DslScriptService Event being processed for Build:{0}",
                                    buildDetails.BuildUri));
                }
                catch (NullReferenceException)
                {
                    // if it not build must be work item
                    // Extract the required information out of the eventXml
                    var workItemId = EventXmlHelper.GetWorkItemValue <int>(
                        eventXml,
                        EventXmlHelper.FieldSection.CoreFields,
                        EventXmlHelper.FieldType.IntegerField,
                        EventXmlHelper.ValueType.NewValue,
                        "System.Id");
                    if (workItemId > 0)
                    {
                        argItems = new[] { EventTypes.WorkItemEvent.ToString(), workItemId.ToString() };
                        logger.Info(
                            string.Format("TFSEventsProcessor: DslScriptService Event being processed for WI:{0}", workItemId));
                    }
                    else
                    {
                        try
                        {
                            var checkInDetails = EventXmlHelper.GetCheckInDetails(eventXml);
                            argItems = new[] { EventTypes.CheckInEvent.ToString(), checkInDetails.Changeset.ToString() };
                            logger.Info(
                                string.Format(
                                    "TFSEventsProcessor: DslScriptService Event being processed for Checkin:{0}",
                                    checkInDetails.Changeset));
                        }
                        catch (NullReferenceException)
                        {
                            // other event type
                        }
                    }
                }
                var args = new Dictionary <string, object>
                {
                    { "Arguments", argItems },
                };

                var engine = new TFSEventsProcessor.Dsl.DslProcessor();
                engine.RunScript(
                    this.dslFolder,
                    this.scriptFolder,
                    GetScriptName(argItems[0], this.scriptFile),
                    args,
                    this.iTfsProvider,
                    this.iEmailProvider,
                    eventXml);
            }
            catch (Exception ex)
            {
                // using a global exception catch to make sure we don't block any threads
                this.DumpException(ex);
            }
        }