Example #1
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);
                    });
                }
            }
        }