Esempio n. 1
0
        public void CanCreateUpdateDeleteSchedule()
        {
            using (var context = MockContext.Start(GetType().FullName))
            {
                using (var testFixture = new AutomationTestBase(context))
                {
                    var scheduleName = TestUtilities.GenerateName("hourlySche");
                    var startTime    = DateTimeOffset.Now.AddDays(1);
                    var expiryTime   = startTime.AddDays(5);

                    var schedule = testFixture.CreateHourlySchedule(scheduleName, startTime, expiryTime);
                    Assert.NotNull(schedule);

                    schedule = testFixture.GetSchedule(schedule.Name);
                    Assert.NotNull(schedule);

                    Assert.Equal(1, (int)(long)schedule.Interval);
                    Assert.Equal(ScheduleFrequency.Hour, schedule.Frequency);

                    schedule.IsEnabled   = false;
                    schedule.Description = "hourly schedule";
                    testFixture.UpdateSchedule(schedule);
                    var updatedSchedule = testFixture.GetSchedule(schedule.Name);
                    Assert.False(updatedSchedule.IsEnabled);
                    Assert.Equal(schedule.Description, updatedSchedule.Description);

                    testFixture.DeleteSchedule(schedule.Name);

                    Assert.Throws <ErrorResponseException>(() =>
                    {
                        schedule = testFixture.GetSchedule(schedule.Name);
                    });
                }
            }
        }
Esempio n. 2
0
        public void CanCreateUpdateDeleteSourceControl()
        {
            using (var context = MockContext.Start(GetType().FullName))
            {
                using (var testFixture = new AutomationTestBase(context))
                {
                    var sourceControlName = SourceControlDefinition.TestSimpleSourceControlDefinition.SourceControlName;
                    var repoUrl           = SourceControlDefinition.TestSimpleSourceControlDefinition.RepoUrl;
                    var branch            = SourceControlDefinition.TestSimpleSourceControlDefinition.Branch;
                    var folderPath        = SourceControlDefinition.TestSimpleSourceControlDefinition.FolderPath;
                    var autoSync          = SourceControlDefinition.TestSimpleSourceControlDefinition.AutoSync;
                    var publishRunbook    = SourceControlDefinition.TestSimpleSourceControlDefinition.PublishRunbook;
                    var sourceType        = SourceControlDefinition.TestSimpleSourceControlDefinition.SourceType;
                    var accessToken       = SourceControlDefinition.TestSimpleSourceControlDefinition.AccessToken;
                    var description       = SourceControlDefinition.TestSimpleSourceControlDefinition.Description;
                    var updateBranchName  = SourceControlDefinition.TestSimpleSourceControlDefinition.UpdateBranchName;
                    var updateAutoPublish = SourceControlDefinition.TestSimpleSourceControlDefinition.UpdateAutoPublish;

                    var sourceControl =
                        testFixture.CreateSourceControl(sourceControlName, repoUrl, branch, folderPath, autoSync, publishRunbook,
                                                        sourceType, accessToken, description);

                    var retrievedSourceControl = testFixture.GetSourceControl(sourceControlName);

                    Assert.NotNull(retrievedSourceControl);
                    Assert.Equal(retrievedSourceControl.RepoUrl, sourceControl.RepoUrl);
                    Assert.Equal(retrievedSourceControl.Branch, sourceControl.Branch);
                    Assert.Equal(retrievedSourceControl.FolderPath, sourceControl.FolderPath);
                    Assert.Equal(retrievedSourceControl.AutoSync, sourceControl.AutoSync);
                    Assert.Equal(retrievedSourceControl.PublishRunbook, sourceControl.PublishRunbook);
                    Assert.Equal(retrievedSourceControl.SourceType, sourceControl.SourceType);
                    Assert.Equal(retrievedSourceControl.Description, sourceControl.Description);

                    var updatedSourceControl =
                        testFixture.UpdateSourceControl(sourceControlName, updateBranchName, updateAutoPublish);

                    Assert.NotNull(updatedSourceControl);
                    Assert.Equal(updatedSourceControl.Branch, updateBranchName);
                    Assert.Equal(updatedSourceControl.AutoSync, updateAutoPublish);

                    var sourceControlList = testFixture.GetSourceControls();

                    Assert.NotNull(sourceControlList);
                    Assert.Single(sourceControlList.ToList());
                    sourceControl = sourceControlList.ToList()[0];
                    Assert.Equal(sourceControlName, sourceControl.Name);

                    testFixture.DeleteSourceControl(sourceControlName);

                    Assert.Throws <ErrorResponseException>(() =>
                    {
                        sourceControl = testFixture.GetSourceControl(sourceControlName);
                    });
                }
            }
        }
Esempio n. 3
0
        public void CanCreateUpdateDeleteDscNodeConfiguration()
        {
            using (var context = MockContext.Start(GetType().FullName))
            {
                using (var testFixture = new AutomationTestBase(context))
                {
                    var configName                     = DscNodeConfigurationDefinition.TestSimpleConfigurationDefinition.ConfigurationName;
                    var nodeConfigName                 = DscNodeConfigurationDefinition.TestSimpleConfigurationDefinition.NodeConfigurationName;
                    var nodeConfigurationContent       = DscNodeConfigurationDefinition.TestSimpleConfigurationDefinition.NodeConfigurationContent;
                    var nodeConfigContentHashValue     = DscNodeConfigurationDefinition.TestSimpleConfigurationDefinition.ContentHashValue;
                    var nodeConfigContentHashAlgorithm = DscNodeConfigurationDefinition.TestSimpleConfigurationDefinition.ContentHashAlgorithm;
                    var nodeConfigContentType          = DscNodeConfigurationDefinition.TestSimpleConfigurationDefinition.ContentType;
                    var nodeConfigContentVersion       =
                        DscNodeConfigurationDefinition.TestSimpleConfigurationDefinition.ContentVersion;
                    const string updatedConfigurationVersion = "2.0";

                    var configContent        = DscConfigurationDefinition.TestSimpleConfigurationDefinition.PsScript;
                    var description          = DscConfigurationDefinition.TestSimpleConfigurationDefinition.Description;
                    var contentHashValue     = DscConfigurationDefinition.TestSimpleConfigurationDefinition.ContentHashValue;
                    var contentHashAlgorithm = DscConfigurationDefinition.TestSimpleConfigurationDefinition.ContentHashAlgorithm;
                    var contentType          = DscConfigurationDefinition.TestSimpleConfigurationDefinition.ContentType;

                    testFixture.CreateDscConfiguration(configName, configContent,
                                                       description, contentHashValue, contentHashAlgorithm, contentType);

                    var nodeConfiguration = testFixture.CreateDscNodeConfiguration(nodeConfigName, configName,
                                                                                   nodeConfigurationContent, nodeConfigContentHashValue, nodeConfigContentHashAlgorithm,
                                                                                   nodeConfigContentType, nodeConfigContentVersion);

                    var nodeConfig = testFixture.GetDscNodeConfiguration(nodeConfigName);
                    Assert.NotNull(nodeConfig);
                    Assert.Equal(nodeConfig.Name, nodeConfiguration.Name);

                    testFixture.UpdateDscNodeConfiguration(nodeConfig, nodeConfigurationContent,
                                                           nodeConfigContentHashValue, nodeConfigContentHashAlgorithm, nodeConfigContentType,
                                                           updatedConfigurationVersion);

                    var dscConfigurations = testFixture.GetDscNodeConfigurations();
                    Assert.NotNull(dscConfigurations);
                    Assert.Single(dscConfigurations.ToList());
                    nodeConfiguration = dscConfigurations.ToList()[0];
                    Assert.Equal(nodeConfigName, nodeConfiguration.Name);

                    testFixture.DeleteDscNodeConfiguration(nodeConfigName);

                    Assert.Throws <ErrorResponseException>(() =>
                    {
                        nodeConfig = testFixture.GetDscNodeConfiguration(nodeConfigName);
                    });
                }
            }
        }
Esempio n. 4
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);
                    });
                }
            }
        }
Esempio n. 5
0
        public void CanCreateSourceControlSyncJob()
        {
            using (var context = MockContext.Start(GetType().FullName))
            {
                using (var testFixture = new AutomationTestBase(context))
                {
                    var sourceControlName      = SourceControlDefinition.TestSimpleSourceControlDefinition.SourceControlName;
                    var repoUrl                = SourceControlDefinition.TestSimpleSourceControlDefinition.RepoUrl;
                    var branch                 = SourceControlDefinition.TestSimpleSourceControlDefinition.Branch;
                    var folderPath             = SourceControlDefinition.TestSimpleSourceControlDefinition.FolderPath;
                    var autoSync               = SourceControlDefinition.TestSimpleSourceControlDefinition.AutoSync;
                    var publishRunbook         = SourceControlDefinition.TestSimpleSourceControlDefinition.PublishRunbook;
                    var sourceControlType      = SourceControlDefinition.TestSimpleSourceControlDefinition.SourceType;
                    var securityToken          = SourceControlDefinition.TestSimpleSourceControlDefinition.AccessToken;
                    var description            = SourceControlDefinition.TestSimpleSourceControlDefinition.Description;
                    var updateBranchName       = SourceControlDefinition.TestSimpleSourceControlDefinition.UpdateBranchName;
                    var SourceControlSyncJobId = TestUtilities.GenerateGuid("jobId");

                    var sourceControl = testFixture.CreateSourceControl(sourceControlName, repoUrl, branch, folderPath, autoSync, publishRunbook,
                                                                        sourceControlType, securityToken, description);

                    var retrievedSourceControl = testFixture.GetSourceControl(sourceControlName);
                    Assert.NotNull(retrievedSourceControl);

                    var syncJob = testFixture.CreateSourceControlSyncJob(sourceControlName, SourceControlSyncJobId);

                    var retrievedSyncJob = testFixture.GetSourceControlSyncJob(sourceControlName, SourceControlSyncJobId);

                    Assert.NotNull(retrievedSyncJob);
                    Assert.Equal(retrievedSyncJob.SourceControlSyncJobId, SourceControlSyncJobId.ToString());
                    Assert.Equal(retrievedSyncJob.CreationTime, syncJob.CreationTime);
                    Assert.Equal(retrievedSyncJob.ProvisioningState, syncJob.ProvisioningState);
                    Assert.Equal(retrievedSyncJob.StartTime, syncJob.StartTime);
                    Assert.Equal(retrievedSyncJob.EndTime, syncJob.EndTime);
                    //Assert.Equal(retrievedSyncJob.SyncType, syncJob.SyncType);

                    var syncJobList = testFixture.GetSourceControlSyncJobs(sourceControlName);

                    Assert.NotNull(syncJobList);
                    Assert.Single(syncJobList.ToList());
                    syncJob = syncJobList.ToList()[0];
                    Assert.Equal(syncJob.SourceControlSyncJobId, syncJob.SourceControlSyncJobId);
                }
            }
        }
Esempio n. 6
0
        public void CanCreateUpdateDeletePython2Packages()
        {
            using (var context = MockContext.Start(GetType().FullName))
            {
                using (var testFixture = new AutomationTestBase(context))
                {
                    var python2PackageName = "numpy";
                    // Content links don't have to be valid for playback. However, these are the actual module download locations used for recording.
                    var contentLink1 = "https://bhbrahmaprodtestingseau.blob.core.windows.net/module1/numpy-1.14.5-cp27-none-win_amd64.whl";
                    var contentLink2 = "https://bhbrahmaprodtestingseau.blob.core.windows.net/module2/numpy-1.15.2-cp27-none-win_amd64.whl";

                    testFixture.DeletePython2Package(python2PackageName, true);

                    var python2Package = testFixture.CreateAutomationPython2Package(python2PackageName, contentLink1);

                    Assert.NotNull(python2Package);
                    Assert.Equal(ModuleProvisioningState.Creating, python2Package.ProvisioningState);
                    python2Package = EnsurePython2PackageReachesSuccessProvisioningState(python2PackageName, testFixture);
                    Assert.Equal(python2PackageName, python2Package.Name);
                    Assert.Equal("1.14.5", python2Package.Version);

                    // Update the module
                    python2Package = testFixture.CreateAutomationPython2Package(python2PackageName, contentLink2);
                    Assert.NotNull(python2Package);
                    Assert.Equal(ModuleProvisioningState.Creating, python2Package.ProvisioningState);
                    python2Package = EnsurePython2PackageReachesSuccessProvisioningState(python2PackageName, testFixture);
                    Assert.Equal(python2PackageName, python2Package.Name);
                    Assert.Equal("1.15.2", python2Package.Version);

                    // Delete the module
                    bool deleteCompleted = false;
                    testFixture.DeletePython2Package(python2PackageName);
                    try
                    {
                        testFixture.GetAutomationPython2Package(python2PackageName);
                    }
                    catch (ErrorResponseException)
                    {
                        // Exception expected
                        deleteCompleted = true;
                    }
                    Assert.True(deleteCompleted);
                }
            }
        }
Esempio n. 7
0
        public void CanCreateUpdateDeleteAutomationModules()
        {
            using (var context = MockContext.Start(GetType().FullName))
            {
                using (var testFixture = new AutomationTestBase(context))
                {
                    var moduleName = "HelloAndSum";
                    // Content links don't have to be valid for playback. However, these are the actual module download locations used for recording.
                    var contentLink1 = "https://bhbrahmaprodtestingseau.blob.core.windows.net/module1/HelloAndSum.zip";
                    var contentLink2 = "https://bhbrahmaprodtestingseau.blob.core.windows.net/module2/HelloAndSum.zip";

                    testFixture.DeleteModule(moduleName, true);

                    var module = testFixture.CreateAutomationModule(moduleName, contentLink1);

                    Assert.NotNull(module);
                    Assert.Equal(ModuleProvisioningState.Creating, module.ProvisioningState);
                    module = EnsureModuleReachesSuccessProvisioningState(moduleName, testFixture);
                    Assert.Equal(moduleName, module.Name);
                    Assert.Equal("1.0", module.Version);

                    // Update the module
                    module = testFixture.CreateAutomationModule(moduleName, contentLink2);
                    Assert.NotNull(module);
                    Assert.Equal(ModuleProvisioningState.Creating, module.ProvisioningState);
                    module = EnsureModuleReachesSuccessProvisioningState(moduleName, testFixture);
                    Assert.Equal(moduleName, module.Name);
                    Assert.Equal("2.0", module.Version);

                    // Delete the module
                    bool deleteCompleted = false;
                    testFixture.DeleteModule(moduleName);
                    try
                    {
                        testFixture.GetAutomationModule(moduleName);
                    }
                    catch (ErrorResponseException)
                    {
                        // Exception expected
                        deleteCompleted = true;
                    }
                    Assert.True(deleteCompleted);
                }
            }
        }
Esempio n. 8
0
        public void CanCreateUpdateDeleteRunbook()
        {
            using (var context = MockContext.Start(GetType().FullName))
            {
                using (var testFixture = new AutomationTestBase(context))
                {
                    var runbookName    = RunbookDefinition.TestPSScript.RunbookName;
                    var runbookContent = RunbookDefinition.TestPSScript.PsScript;

                    testFixture.CreatePSScriptRunbook(runbookName, runbookContent);
                    var runbook = testFixture.GetRunbook(runbookName);
                    Assert.NotNull(runbook);

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

                    const string description = "description of runbook";
                    runbook.LogProgress = true;
                    runbook.Description = description;

                    testFixture.UpdateRunbook(runbook);
                    var updatedRunbook = testFixture.GetRunbook(runbookName);
                    Assert.True(runbook.LogProgress);
                    Assert.False(runbook.LogVerbose);
                    Assert.Equal(runbook.Description, updatedRunbook.Description);

                    var runbookContentV2 = RunbookDefinition.TestPSScriptV2.PsScript;
                    testFixture.UpdateRunbookContent(runbookName, runbookContentV2);
                    var updatedContent = testFixture.GetRunbookContent(runbookName);
                    var reader         = new StreamReader(updatedContent);
                    Assert.Equal(runbookContentV2, reader.ReadToEnd());

                    testFixture.DeleteRunbook(runbookName);

                    Assert.Throws <ErrorResponseException>(() =>
                    {
                        runbook = testFixture.GetRunbook(runbookName);
                    });
                }
            }
        }
        public void CanCreateUpdateDeleteDscConfiguration()
        {
            using (var context = MockContext.Start(this.GetType()))
            {
                using (var testFixture = new AutomationTestBase(context, "CanCreateUpdateDeleteDscConfiguration"))
                {
                    var configName           = DscConfigurationDefinition.TestSimpleConfigurationDefinition.ConfigurationName;
                    var configContent        = DscConfigurationDefinition.TestSimpleConfigurationDefinition.PsScript;
                    var description          = DscConfigurationDefinition.TestSimpleConfigurationDefinition.Description;
                    var contentHashValue     = DscConfigurationDefinition.TestSimpleConfigurationDefinition.ContentHashValue;
                    var contentHashAlgorithm = DscConfigurationDefinition.TestSimpleConfigurationDefinition.ContentHashAlgorithm;
                    var contentType          = DscConfigurationDefinition.TestSimpleConfigurationDefinition.ContentType;

                    const string updatedDescription = "new sample configuration test";

                    var configuration = testFixture.CreateDscConfiguration(configName, configContent,
                                                                           description, contentHashValue, contentHashAlgorithm, contentType);

                    var config = testFixture.GetDscConfiguration(configName);
                    Assert.NotNull(config);
                    Assert.Equal(config.Name, configuration.Name);
                    Assert.Equal(config.Description, configuration.Description);

                    config.Description = updatedDescription;
                    testFixture.UpdateDscConfiguration(config, configContent,
                                                       description, contentHashValue, contentHashAlgorithm, contentType);

                    var dscConfigurations = testFixture.GetDscConfigurations();
                    Assert.NotNull(dscConfigurations);
                    Assert.Single(dscConfigurations.ToList());
                    configuration = dscConfigurations.ToList()[0];
                    Assert.Equal(configName, configuration.Name);

                    testFixture.DeleteDscConfiguration(configName);

                    Assert.Throws <ErrorResponseException>(() =>
                    {
                        config = testFixture.GetDscConfiguration(configName);
                    });
                }
            }
        }
Esempio n. 10
0
        public void CanCreateUpdateDeleteCredential()
        {
            using (var context = MockContext.Start(GetType().FullName))
            {
                using (var testFixture = new AutomationTestBase(context))
                {
                    var credentialName = TestUtilities.GenerateName("credential");
                    var userName       = "******";
                    var password       = "******";

                    var credential = testFixture.CreateCredential(credentialName, userName, password);
                    Assert.NotNull(credential);

                    credential = testFixture.GetCredential(credential.Name);
                    Assert.NotNull(credential);
                    Assert.Equal(userName, credential.UserName);

                    userName = "******";
                    password = "******";

                    credential.Description = "description of credential";
                    testFixture.UpdateCredential(credential, password, userName);
                    var credentials = testFixture.GetCredentials();

                    Assert.Single(credentials.ToList());
                    var updatedCredential = credentials.ToList()[0];
                    Assert.Equal(credential.UserName, updatedCredential.UserName);
                    Assert.Equal(credential.Description, updatedCredential.Description);

                    testFixture.DeleteCredential(credential.Name);

                    Assert.Throws <ErrorResponseException>(() =>
                    {
                        credential = testFixture.GetCredential(credential.Name);
                    });
                }
            }
        }
Esempio n. 11
0
        public void CanCreateUpdateDeleteVariable()
        {
            using (var context = MockContext.Start(GetType().FullName))
            {
                using (var testFixture = new AutomationTestBase(context))
                {
                    var variableName = TestUtilities.GenerateName("variable");
                    var value        = 10;

                    var variable = testFixture.CreateVariable(variableName, value);
                    Assert.NotNull(variable);

                    variable = testFixture.GetVariable(variable.Name);
                    Assert.NotNull(variable);
                    Assert.Equal(value, Convert.ToInt32(JsonConvert.DeserializeObject <object>(variable.Value)));

                    value                = 20;
                    variable.Value       = JsonConvert.SerializeObject(value);
                    variable.Description = "int typed variable";

                    testFixture.UpdateVariable(variable);
                    var variables = testFixture.GetVariables();
                    Assert.Single(variables.ToList());
                    var updatedVariable = variables.ToList()[0];
                    Assert.Equal(value, Convert.ToInt32(JsonConvert.DeserializeObject <object>(updatedVariable.Value)));
                    Assert.Equal(variable.Description, updatedVariable.Description);

                    testFixture.DeleteVariable(variable.Name);

                    Assert.Throws <ErrorResponseException>(() =>
                    {
                        variable = testFixture.GetVariable(variable.Name);
                    });
                }
            }
        }
Esempio n. 12
0
        private Module EnsurePython2PackageReachesSuccessProvisioningState(string moduleName, AutomationTestBase testFixture)
        {
            GetModuleAction getPython2PackageAction = () => testFixture.GetAutomationPython2Package(moduleName);

            return(TestProvisioningStateSucceeded(getPython2PackageAction));
        }
Esempio n. 13
0
        private Module EnsureModuleReachesSuccessProvisioningState(string moduleName, AutomationTestBase testFixture)
        {
            // Wait for the module Provisioing state to reach Succeeded
            GetModuleAction getmoduleAction = () => testFixture.GetAutomationModule(moduleName);

            return(TestProvisioningStateSucceeded(getmoduleAction));
        }