public void Can_run_a_script_using_work_item_deleted_data()
        {
            // arrange
            var alertMessage = ServiceHookTestData.GetEventJson("workitem.deleted");

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

            var sut = new Controllers.WebHookController(
                emailProvider.Object,
                azureDevOpsProvider.Object,
                @"TestDataFiles\Scripts\AzureDevOps\alerts\fullscript.py", @".\dsl");

            // redirect the console
            var consoleOut = Helpers.Logging.RedirectConsoleOut();

            // act
            var actual = sut.Post(alertMessage);

            // assert
            Assert.AreEqual(HttpStatusCode.OK, actual.StatusCode);
            Assert.AreEqual("Got a known workitem.deleted event type with id 5" + Environment.NewLine, consoleOut.ToString());
        }
        public void Can_run_a_script_using_push_data()
        {
            // arrange
            var alertMessage = ServiceHookTestData.GetEventJson("git.push");

            var emailProvider       = new Moq.Mock <IEmailProvider>();
            var azureDevOpsProvider = new Moq.Mock <IAzureDevOpsProvider>();
            var sut = new Controllers.WebHookController(
                emailProvider.Object,
                azureDevOpsProvider.Object,
                @"TestDataFiles\Scripts\AzureDevOps\alerts\fullscript.py",
                @".\dsl");

            // redirect the console
            var consoleOut = Helpers.Logging.RedirectConsoleOut();

            // act
            var actual = sut.Post(alertMessage);

            // assert
            Assert.AreEqual(HttpStatusCode.OK, actual.StatusCode);
            Assert.AreEqual("Got a known git.push event type on repo 3c4e22ee-6148-45a3-913b-454009dac91d with id 73" + Environment.NewLine, consoleOut.ToString());
        }
        public void Can_run_a_script_using_pull_request_merged_data()
        {
            // arrange
            var alertMessage = ServiceHookTestData.GetEventJson("git.pullrequest.merged");


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

            var sut = new Controllers.WebHookController(
                emailProvider.Object,
                azureDevOpsProvider.Object,
                @"TestDataFiles\Scripts\AzureDevOps\alerts\fullscript.py", @".\dsl");

            // redirect the console
            var consoleOut = Helpers.Logging.RedirectConsoleOut();

            // act
            var actual = sut.Post(alertMessage);

            // assert
            Assert.AreEqual(HttpStatusCode.OK, actual.StatusCode);
            Assert.AreEqual("Got a known git.pullrequest.merged event type on repo 4bc14d40-c903-45e2-872e-0462c7748079 with id 1" + Environment.NewLine, consoleOut.ToString());
        }
        public void Cannot_run_a_script_using_an_unknown_event_type()
        {
            // arrange
            var alertMessage = ServiceHookTestData.GetEventJson("dummy");

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

            var sut = new Controllers.WebHookController(
                emailProvider.Object,
                azureDevOpsProvider.Object,
                @"TestDataFiles\Scripts\AzureDevOps\alerts\fullscript.py",
                @".\dsl");

            // redirect the console
            var consoleOut = Helpers.Logging.RedirectConsoleOut();

            // act
            var actual = sut.Post(alertMessage);

            // assert
            Assert.AreEqual(HttpStatusCode.BadRequest, actual.StatusCode);
            Assert.AreEqual("", consoleOut.ToString());
        }