示例#1
0
        public void CanCreateUpdateDeleteWebhook()
        {
            using (var context = MockContext.Start(GetType().FullName))
            {
                using (var testFixture = new AutomationTestBase(context))
                {
                    var webhookName    = TestUtilities.GenerateName("webhook");
                    var runbookName    = RunbookDefinition.TestFasterWorkflow.RunbookName;
                    var runbookContent = RunbookDefinition.TestFasterWorkflow.PsScript;

                    testFixture.CreateRunbook(runbookName, runbookContent);
                    testFixture.PublishRunbook(runbookName);
                    var runbook = testFixture.GetRunbook(runbookName);
                    Assert.Equal("Published", runbook.State);

                    var uri = testFixture.GenerateUriForWebhook();

                    var webhook = testFixture.CreateWebhook(webhookName, runbookName, uri);
                    Assert.NotNull(webhook);

                    webhook = testFixture.GetWebhook(webhook.Name);
                    Assert.NotNull(webhook);
                    Assert.Equal(runbookName, webhook.Runbook.Name);

                    webhook.IsEnabled = false;

                    testFixture.UpdateWebhook(webhook);
                    var webhooks = testFixture.GetWebhooks();

                    Assert.Single(webhooks.ToList());
                    var updatedWebhook = webhooks.ToList()[0];
                    Assert.False(updatedWebhook.IsEnabled);

                    webhooks = testFixture.GetWebhooks(runbookName);

                    Assert.Single(webhooks.ToList());
                    updatedWebhook = webhooks.ToList()[0];
                    Assert.False(updatedWebhook.IsEnabled);

                    testFixture.DeleteWebhook(webhook.Name);
                    testFixture.DeleteRunbook(runbookName);

                    Assert.Throws <ErrorResponseException>(() =>
                    {
                        webhook = testFixture.GetWebhook(webhook.Name);
                    });
                }
            }
        }