internal static PsAzurePowerShellScript ToPsAzurePowerShellScript(AzurePowerShellScript script) { return(new PsAzurePowerShellScript { Name = script.Name, Type = script.Type, Id = script.Id, Identity = script.Identity, Location = script.Location, Tags = script.Tags, CleanupPreference = script.CleanupPreference, ProvisioningState = script.ProvisioningState, Status = DeploymentScriptsAutoMapperProfile.Mapper.Map <PsScriptStatus>(script.Status), Outputs = script.Outputs, PrimaryScriptUri = script.PrimaryScriptUri, SupportingScriptUris = script.SupportingScriptUris, ScriptContent = script.ScriptContent, Arguments = script.Arguments, EnvironmentVariables = script.EnvironmentVariables, ForceUpdateTag = script.ForceUpdateTag, RetentionInterval = XmlConvert.ToString(script.RetentionInterval), Timeout = script.Timeout.HasValue ? XmlConvert.ToString(script.Timeout.Value) : null, AzPowerShellVersion = script.AzPowerShellVersion, ScriptKind = "AzurePowerShell" }); }
public void CanReturnErrorOnScriptExecutionFailure() { using (var context = MockContext.Start(this.GetType())) { var client = context.GetServiceClient <DeploymentScriptsClient>(); // create user assigned managed identity during test run since we'll be using dynamic properties, such as subscriptionId from the test var userAssignedIdentities = new Dictionary <string, UserAssignedIdentity> { { $"/subscriptions/{client.SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/filiz-user-assigned-msi", new UserAssignedIdentity() } }; var managedIdentity = new ManagedServiceIdentity(ManagedServiceIdentityType.UserAssigned, userAssignedIdentities); // Create deployment script object with minimal properties var deploymentScriptName = TestUtilities.GetCurrentMethodName() + "--" + TestUtilities.GenerateName(); var deploymentScript = new AzurePowerShellScript(managedIdentity, LocationWestUs, RetentionInterval, AzurePowerShellVersion, scriptContent: MalformedScriptContent); var createDeploymentScriptResult = client.DeploymentScripts.BeginCreate(ResourceGroupName, deploymentScriptName, deploymentScript) as AzurePowerShellScript; Assert.NotNull(createDeploymentScriptResult); Assert.Equal(ScriptProvisioningState.Creating, createDeploymentScriptResult.ProvisioningState); AzurePowerShellScript getDeploymentScript; // wait until the deployment script fails var MaxPoll = 20; var pollCount = 0; do { Assert.True(pollCount < MaxPoll); getDeploymentScript = client.DeploymentScripts.Get(ResourceGroupName, deploymentScriptName) as AzurePowerShellScript; TestUtilities.Wait(10000); pollCount++; } while (getDeploymentScript.ProvisioningState != ScriptProvisioningState.Failed); // Validate result Assert.NotNull(getDeploymentScript); Assert.NotNull(getDeploymentScript.Status.Error); Assert.Equal(typeof(ErrorResponse), getDeploymentScript.Status.Error.GetType()); // Delete deployment script client.DeploymentScripts.Delete(ResourceGroupName, deploymentScriptName); var list = client.DeploymentScripts.ListByResourceGroup(ResourceGroupName); Assert.Empty(list.Where(p => p.Name.Equals(deploymentScriptName))); } }
private static void AssertValidDeploymentScript(AzurePowerShellScript model, AzurePowerShellScript getResult) { Assert.AreEqual(model.Id, getResult.Id); Assert.AreEqual(model.Name, getResult.Name); Assert.AreEqual(model.ResourceType, getResult.ResourceType); if (model.ContainerSettings != null || getResult.ContainerSettings != null) { Assert.NotNull(model.ContainerSettings); Assert.NotNull(getResult.ContainerSettings); Assert.AreEqual(model.ContainerSettings.ContainerGroupName, getResult.ContainerSettings.ContainerGroupName); } if (model.StorageAccountSettings != null || getResult.StorageAccountSettings != null) { Assert.NotNull(model.StorageAccountSettings); Assert.NotNull(getResult.StorageAccountSettings); Assert.AreEqual(model.StorageAccountSettings.StorageAccountName, getResult.StorageAccountSettings.StorageAccountName); Assert.AreEqual(model.StorageAccountSettings.StorageAccountKey, getResult.StorageAccountSettings.StorageAccountKey); } Assert.AreEqual(model.CleanupPreference, getResult.CleanupPreference); Assert.AreEqual(model.ProvisioningState, getResult.ProvisioningState); if (model.Status != null || getResult.Status != null) { Assert.NotNull(model.Status); Assert.NotNull(getResult.Status); Assert.AreEqual(model.Status.ContainerInstanceId, getResult.Status.ContainerInstanceId); Assert.AreEqual(model.Status.StorageAccountId, getResult.Status.StorageAccountId); Assert.AreEqual(model.Status.StartOn, getResult.Status.StartOn); Assert.AreEqual(model.Status.EndOn, getResult.Status.EndOn); Assert.AreEqual(model.Status.ExpirationOn, getResult.Status.ExpirationOn); //Assert.AreEqual(model.Status.Error, getResult.Status.Error); } Assert.AreEqual(model.Outputs.Count, getResult.Outputs.Count); foreach (var kv in model.Outputs) { Assert.IsTrue(getResult.Outputs.ContainsKey(kv.Key)); Assert.AreEqual(kv.Value.ToArray(), getResult.Outputs[kv.Key].ToArray()); } Assert.AreEqual(model.PrimaryScriptUri, getResult.PrimaryScriptUri); Assert.AreEqual(model.SupportingScriptUris, getResult.SupportingScriptUris); Assert.AreEqual(model.ScriptContent, getResult.ScriptContent); Assert.AreEqual(model.Arguments, getResult.Arguments); if (model.EnvironmentVariables != null || getResult.EnvironmentVariables != null) { Assert.NotNull(model.EnvironmentVariables); Assert.NotNull(getResult.EnvironmentVariables); Assert.AreEqual(model.EnvironmentVariables.Count, getResult.EnvironmentVariables.Count); for (int i = 0; i < model.EnvironmentVariables.Count; ++i) { Assert.AreEqual(model.EnvironmentVariables[i].Name, getResult.EnvironmentVariables[i].Name); Assert.AreEqual(model.EnvironmentVariables[i].Value, getResult.EnvironmentVariables[i].Value); Assert.AreEqual(model.EnvironmentVariables[i].SecureValue, getResult.EnvironmentVariables[i].SecureValue); } } Assert.AreEqual(model.ForceUpdateTag, getResult.ForceUpdateTag); Assert.AreEqual(model.RetentionInterval, getResult.RetentionInterval); Assert.AreEqual(model.Timeout, getResult.Timeout); Assert.AreEqual(model.AzPowerShellVersion, getResult.AzPowerShellVersion); }
public async Task CanGetDeploymentScriptExecutionLogs() { // create user assigned managed identity during test run since we'll be using dynamic properties, such as subscriptionId from the test var userAssignedIdentities = new Dictionary <string, UserAssignedIdentity> { { $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/filiz-user-assigned-msi", new UserAssignedIdentity() } }; var managedIdentity = new ManagedServiceIdentity() { Type = "UserAssigned", UserAssignedIdentities = userAssignedIdentities }; // Create deployment script object with minimal properties var deploymentScriptName = GetCallingMethodName() + "--" + Recording.GenerateAssetName("csmd"); var deploymentScript = new AzurePowerShellScript(managedIdentity, LocationWestUs, RetentionInterval, AzurePowerShellVersion) { ScriptContent = ScriptContent, Arguments = ScriptArguments }; var rawcreateDeploymentScriptResult = await DeploymentScriptsOperations.StartCreateAsync(ResourceGroupName, deploymentScriptName, deploymentScript); var createDeploymentScriptResult = (await WaitForCompletionAsync(rawcreateDeploymentScriptResult)).Value as AzurePowerShellScript; Assert.NotNull(createDeploymentScriptResult); Assert.AreEqual(ScriptProvisioningState.Succeeded, createDeploymentScriptResult.ProvisioningState); AzurePowerShellScript getDeploymentScript = (await DeploymentScriptsOperations.GetAsync(ResourceGroupName, deploymentScriptName)).Value as AzurePowerShellScript; Assert.NotNull(getDeploymentScript); // Validate getlogs result var getLogsResult = DeploymentScriptsOperations.GetLogsDefaultAsync(ResourceGroupName, deploymentScriptName); Assert.NotNull(getLogsResult); // Delete deployments script await DeploymentScriptsOperations.DeleteAsync(ResourceGroupName, deploymentScriptName); var list = await DeploymentScriptsOperations.ListByResourceGroupAsync(ResourceGroupName).ToEnumerableAsync(); Assert.IsEmpty(list.Where(p => p.Name.Equals(deploymentScriptName))); }
public async Task Get() { string rgName = Recording.GenerateAssetName("testRg-4-"); ResourceGroupData rgData = new ResourceGroupData(Location.WestUS2); var lro = await Client.DefaultSubscription.GetResourceGroups().CreateOrUpdateAsync(rgName, rgData); ResourceGroup rg = lro.Value; string deployScriptName = Recording.GenerateAssetName("deployScript-G-"); DeploymentScriptData deploymentScriptData = await GetDeploymentScriptDataAsync(); DeploymentScript tempDeploymentScript = (await rg.GetDeploymentScripts().CreateOrUpdateAsync(deployScriptName, deploymentScriptData)).Value; AzurePowerShellScript deploymentScript = tempDeploymentScript.Data as AzurePowerShellScript; DeploymentScript tempGetDeploymentScript = await rg.GetDeploymentScripts().GetAsync(deployScriptName); AzurePowerShellScript getdeploymentScript = tempGetDeploymentScript.Data as AzurePowerShellScript; AssertValidDeploymentScript(deploymentScript, getdeploymentScript); }
public void CanGetDeploymentScriptExecutionLogs() { using (var context = MockContext.Start(this.GetType())) { var client = context.GetServiceClient <DeploymentScriptsClient>(); // create user assigned managed identity during test run since we'll be using dynamic properties, such as subscriptionId from the test var userAssignedIdentities = new Dictionary <string, UserAssignedIdentity> { { $"/subscriptions/{client.SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/filiz-user-assigned-msi", new UserAssignedIdentity() } }; var managedIdentity = new ManagedServiceIdentity(ManagedServiceIdentityType.UserAssigned, userAssignedIdentities); // Create deployment script object with minimal properties var deploymentScriptName = TestUtilities.GetCurrentMethodName() + "--" + TestUtilities.GenerateName(); var deploymentScript = new AzurePowerShellScript(managedIdentity, LocationWestUs, RetentionInterval, AzurePowerShellVersion, scriptContent: ScriptContent, arguments: ScriptArguments); var createDeploymentScriptResult = client.DeploymentScripts.Create(ResourceGroupName, deploymentScriptName, deploymentScript) as AzurePowerShellScript; Assert.NotNull(createDeploymentScriptResult); Assert.Equal(ScriptProvisioningState.Succeeded, createDeploymentScriptResult.ProvisioningState); AzurePowerShellScript getDeploymentScript = client.DeploymentScripts.Get(ResourceGroupName, deploymentScriptName) as AzurePowerShellScript; Assert.NotNull(getDeploymentScript); // Validate getlogs result var getLogsResult = client.DeploymentScripts.GetLogsDefault(ResourceGroupName, deploymentScriptName); Assert.NotNull(getLogsResult); // Delete deployments script client.DeploymentScripts.Delete(ResourceGroupName, deploymentScriptName); var list = client.DeploymentScripts.ListByResourceGroup(ResourceGroupName); Assert.Empty(list.Where(p => p.Name.Equals(deploymentScriptName))); } }
internal static DeploymentScriptData DeserializeDeploymentScriptData(JsonElement element) { if (element.TryGetProperty("kind", out JsonElement discriminator)) { switch (discriminator.GetString()) { case "AzureCLI": return(AzureCliScript.DeserializeAzureCliScript(element)); case "AzurePowerShell": return(AzurePowerShellScript.DeserializeAzurePowerShellScript(element)); } } Optional <ManagedServiceIdentity> identity = default; string location = default; Optional <IDictionary <string, string> > tags = default; ScriptType kind = default; Optional <SystemData> systemData = default; ResourceIdentifier id = default; string name = default; ResourceType type = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("identity")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } identity = ManagedServiceIdentity.DeserializeManagedServiceIdentity(property.Value); continue; } if (property.NameEquals("location")) { location = property.Value.GetString(); continue; } if (property.NameEquals("tags")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } Dictionary <string, string> dictionary = new Dictionary <string, string>(); foreach (var property0 in property.Value.EnumerateObject()) { dictionary.Add(property0.Name, property0.Value.GetString()); } tags = dictionary; continue; } if (property.NameEquals("kind")) { kind = new ScriptType(property.Value.GetString()); continue; } if (property.NameEquals("systemData")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString()); continue; } if (property.NameEquals("id")) { id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("type")) { type = property.Value.GetString(); continue; } } return(new DeploymentScriptData(id, name, type, identity.Value, location, Optional.ToDictionary(tags), kind, systemData)); }
public void CanCrudSimpleDeploymentScript() { using (var context = MockContext.Start(this.GetType())) { var client = context.GetServiceClient <DeploymentScriptsClient>(); // create user assigned managed identity during test run since we'll be using dynamic properties, such as subscriptionId from the test var userAssignedIdentities = new Dictionary <string, UserAssignedIdentity> { { $"/subscriptions/{client.SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/filiz-user-assigned-msi", new UserAssignedIdentity() } }; var managedIdentity = new ManagedServiceIdentity(ManagedServiceIdentityType.UserAssigned, userAssignedIdentities); // Create deployment script object with minimal properties var deploymentScriptName = TestUtilities.GetCurrentMethodName() + "--" + TestUtilities.GenerateName(); var deploymentScript = new AzurePowerShellScript(managedIdentity, LocationWestUs, RetentionInterval, AzurePowerShellVersion, scriptContent: ScriptContent, arguments: ScriptArguments); var createDeploymentScriptResult = client.DeploymentScripts.Create(ResourceGroupName, deploymentScriptName, deploymentScript) as AzurePowerShellScript; Assert.NotNull(createDeploymentScriptResult); Assert.Equal(ScriptProvisioningState.Succeeded, createDeploymentScriptResult.ProvisioningState); AzurePowerShellScript getDeploymentScript = client.DeploymentScripts.Get(ResourceGroupName, deploymentScriptName) as AzurePowerShellScript; // Validate result Assert.NotNull(getDeploymentScript); Assert.Equal(deploymentScript.Location, getDeploymentScript.Location); Assert.Equal(deploymentScript.AzPowerShellVersion, getDeploymentScript.AzPowerShellVersion); Assert.Equal(deploymentScript.Identity.Type.ToLower(), getDeploymentScript.Identity.Type.ToLower()); Assert.NotNull(deploymentScript.Identity.UserAssignedIdentities.Values.FirstOrDefault()); Assert.Equal(deploymentScript.Identity.UserAssignedIdentities.Keys.FirstOrDefault(), getDeploymentScript.Identity.UserAssignedIdentities.Keys.FirstOrDefault()); Assert.NotNull(getDeploymentScript.ScriptContent); Assert.Equal(deploymentScript.ScriptContent, getDeploymentScript.ScriptContent); Assert.NotNull(getDeploymentScript.Arguments); Assert.Equal(deploymentScript.Arguments, getDeploymentScript.Arguments); Assert.NotNull(deploymentScript.RetentionInterval.ToString()); Assert.Equal(deploymentScript.RetentionInterval, getDeploymentScript.RetentionInterval); // Validate read-only properties Assert.NotNull(getDeploymentScript.Id); Assert.NotNull(getDeploymentScript.Name); Assert.Equal(deploymentScriptName, getDeploymentScript.Name); Assert.NotNull(getDeploymentScript.Identity.UserAssignedIdentities.Values.FirstOrDefault().ClientId); Assert.NotNull(getDeploymentScript.Identity.UserAssignedIdentities.Values.FirstOrDefault().PrincipalId); Assert.NotNull(getDeploymentScript.ProvisioningState); Assert.NotNull(getDeploymentScript.Timeout); Assert.NotNull(getDeploymentScript.CleanupPreference); Assert.NotNull(getDeploymentScript.Status); Assert.NotNull(getDeploymentScript.Status.StartTime); Assert.NotNull(getDeploymentScript.Status.EndTime); Assert.NotNull(getDeploymentScript.Status.ContainerInstanceId); Assert.NotNull(getDeploymentScript.Status.StorageAccountId); Assert.NotEmpty(getDeploymentScript.Outputs); // List at resource group level and validate var listAtResourceGroupResult = client.DeploymentScripts.ListByResourceGroup(ResourceGroupName); Assert.NotEmpty(listAtResourceGroupResult); Assert.NotNull(listAtResourceGroupResult.FirstOrDefault(p => p.Name.Equals(deploymentScriptName))); Assert.Equal(deploymentScript.AzPowerShellVersion, (listAtResourceGroupResult.First() as AzurePowerShellScript).AzPowerShellVersion); Assert.NotNull((listAtResourceGroupResult.First() as AzurePowerShellScript).ProvisioningState); // List at subscription level and validate var listAtSubscriptionResult = client.DeploymentScripts.ListBySubscription(); Assert.NotEmpty(listAtSubscriptionResult); Assert.NotNull(listAtSubscriptionResult.FirstOrDefault(p => p.Name.Equals(deploymentScriptName))); Assert.Equal(AzurePowerShellVersion, (listAtSubscriptionResult.First() as AzurePowerShellScript).AzPowerShellVersion); Assert.NotNull((listAtSubscriptionResult.First() as AzurePowerShellScript).ProvisioningState); // Delete deployments script and validate client.DeploymentScripts.Delete(ResourceGroupName, deploymentScriptName); var list = client.DeploymentScripts.ListByResourceGroup(ResourceGroupName); Assert.Empty(list.Where(p => p.Name.Equals(deploymentScriptName))); list = client.DeploymentScripts.ListBySubscription(); Assert.Empty(list.Where(p => p.Name.Equals(deploymentScriptName))); } }
public async Task CanCrudSimpleDeploymentScript() { // create user assigned managed identity during test run since we'll be using dynamic properties, such as subscriptionId from the test var userAssignedIdentities = new Dictionary <string, UserAssignedIdentity> { { $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/filiz-user-assigned-msi", new UserAssignedIdentity() } }; var managedIdentity = new ManagedServiceIdentity() { Type = "UserAssigned", UserAssignedIdentities = userAssignedIdentities }; // Create deployment script object with minimal properties var deploymentScriptName = GetCallingMethodName() + "--" + Recording.GenerateAssetName("csmd"); var deploymentScript = new AzurePowerShellScript(managedIdentity, LocationWestUs, RetentionInterval, AzurePowerShellVersion) { ScriptContent = ScriptContent, Arguments = ScriptArguments }; var rawCreateDeploymentScriptResult = await DeploymentScriptsOperations.StartCreateAsync(ResourceGroupName, deploymentScriptName, deploymentScript); var createDeploymentScriptResult = (await WaitForCompletionAsync(rawCreateDeploymentScriptResult)).Value as AzurePowerShellScript; Assert.NotNull(createDeploymentScriptResult); Assert.AreEqual(ScriptProvisioningState.Succeeded, createDeploymentScriptResult.ProvisioningState); AzurePowerShellScript getDeploymentScript = (await DeploymentScriptsOperations.GetAsync(ResourceGroupName, deploymentScriptName)).Value as AzurePowerShellScript; // Validate result Assert.NotNull(getDeploymentScript); Assert.AreEqual(deploymentScript.Location, getDeploymentScript.Location); Assert.AreEqual(deploymentScript.AzPowerShellVersion, getDeploymentScript.AzPowerShellVersion); Assert.AreEqual(deploymentScript.Identity.Type.ToLower(), getDeploymentScript.Identity.Type.ToLower()); Assert.NotNull(deploymentScript.Identity.UserAssignedIdentities.Values.FirstOrDefault()); Assert.AreEqual(deploymentScript.Identity.UserAssignedIdentities.Keys.FirstOrDefault(), getDeploymentScript.Identity.UserAssignedIdentities.Keys.FirstOrDefault()); Assert.NotNull(getDeploymentScript.ScriptContent); Assert.AreEqual(deploymentScript.ScriptContent, getDeploymentScript.ScriptContent); Assert.NotNull(getDeploymentScript.Arguments); Assert.AreEqual(deploymentScript.Arguments, getDeploymentScript.Arguments); Assert.NotNull(deploymentScript.RetentionInterval.ToString()); Assert.AreEqual(deploymentScript.RetentionInterval, getDeploymentScript.RetentionInterval); // Validate read-only properties Assert.NotNull(getDeploymentScript.Id); Assert.NotNull(getDeploymentScript.Name); Assert.AreEqual(deploymentScriptName, getDeploymentScript.Name); Assert.NotNull(getDeploymentScript.Identity.UserAssignedIdentities.Values.FirstOrDefault().ClientId); Assert.NotNull(getDeploymentScript.Identity.UserAssignedIdentities.Values.FirstOrDefault().PrincipalId); Assert.NotNull(getDeploymentScript.ProvisioningState); Assert.NotNull(getDeploymentScript.Timeout); Assert.NotNull(getDeploymentScript.CleanupPreference); Assert.NotNull(getDeploymentScript.Status); Assert.NotNull(getDeploymentScript.Status.StartTime); Assert.NotNull(getDeploymentScript.Status.EndTime); Assert.NotNull(getDeploymentScript.Status.ContainerInstanceId); Assert.NotNull(getDeploymentScript.Status.StorageAccountId); Assert.IsNotEmpty(getDeploymentScript.Outputs); // List at resource group level and validate var listAtResourceGroupResult = await DeploymentScriptsOperations.ListByResourceGroupAsync(ResourceGroupName).ToEnumerableAsync(); Assert.IsNotEmpty(listAtResourceGroupResult); Assert.NotNull(listAtResourceGroupResult.FirstOrDefault(p => p.Name.Equals(deploymentScriptName))); Assert.AreEqual(deploymentScript.AzPowerShellVersion, (listAtResourceGroupResult.First() as AzurePowerShellScript).AzPowerShellVersion); Assert.NotNull((listAtResourceGroupResult.First() as AzurePowerShellScript).ProvisioningState); // List at subscription level and validate var listAtSubscriptionResult = await DeploymentScriptsOperations.ListBySubscriptionAsync().ToEnumerableAsync(); Assert.IsNotEmpty(listAtSubscriptionResult); Assert.NotNull(listAtSubscriptionResult.FirstOrDefault(p => p.Name.Equals(deploymentScriptName))); Assert.AreEqual(AzurePowerShellVersion, (listAtSubscriptionResult.First() as AzurePowerShellScript).AzPowerShellVersion); Assert.NotNull((listAtSubscriptionResult.First() as AzurePowerShellScript).ProvisioningState); // Delete deployments script and validate await DeploymentScriptsOperations.DeleteAsync(ResourceGroupName, deploymentScriptName); var list = await DeploymentScriptsOperations.ListByResourceGroupAsync(ResourceGroupName).ToEnumerableAsync(); Assert.IsEmpty(list.Where(p => p.Name.Equals(deploymentScriptName))); list = await DeploymentScriptsOperations.ListBySubscriptionAsync().ToEnumerableAsync(); Assert.IsEmpty(list.Where(p => p.Name.Equals(deploymentScriptName))); }
public async Task CanReturnErrorOnScriptExecutionFailure() { // create user assigned managed identity during test run since we'll be using dynamic properties, such as subscriptionId from the test var userAssignedIdentities = new Dictionary <string, UserAssignedIdentity> { { $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/filiz-user-assigned-msi", new UserAssignedIdentity() } }; var managedIdentity = new ManagedServiceIdentity() { Type = "UserAssigned", UserAssignedIdentities = userAssignedIdentities }; // Create deployment script object with minimal properties var deploymentScriptName = GetCallingMethodName() + "--" + Recording.GenerateAssetName("csmd"); var deploymentScript = new AzurePowerShellScript(managedIdentity, LocationWestUs, RetentionInterval, AzurePowerShellVersion) { ScriptContent = MalformedScriptContent }; var rawcreateDeploymentScriptResult = await DeploymentScriptsOperations.StartCreateAsync(ResourceGroupName, deploymentScriptName, deploymentScript); var createDeploymentScriptResult = (await DeploymentScriptsOperations.GetAsync(ResourceGroupName, deploymentScriptName)).Value as AzurePowerShellScript; Assert.NotNull(createDeploymentScriptResult); if (this.IsAsync) { Assert.AreEqual(ScriptProvisioningState.Creating.ToString(), createDeploymentScriptResult.ProvisioningState.Value.ToString()); } else { Assert.AreEqual(ScriptProvisioningState.ProvisioningResources.ToString(), createDeploymentScriptResult.ProvisioningState.Value.ToString()); } AzurePowerShellScript getDeploymentScript; // wait until the deployment script fails var MaxPoll = 20; var pollCount = 0; do { Assert.True(pollCount < MaxPoll); getDeploymentScript = (await DeploymentScriptsOperations.GetAsync(ResourceGroupName, deploymentScriptName)).Value as AzurePowerShellScript; if (Mode == RecordedTestMode.Record) { Thread.Sleep(10 * 1000); } pollCount++; } while (getDeploymentScript.ProvisioningState != ScriptProvisioningState.Failed); // Validate result Assert.NotNull(getDeploymentScript); Assert.NotNull(getDeploymentScript.Status.Error); Assert.AreEqual(typeof(ErrorResponse), getDeploymentScript.Status.Error.GetType()); // Delete deployment script await DeploymentScriptsOperations.DeleteAsync(ResourceGroupName, deploymentScriptName); var list = await DeploymentScriptsOperations.ListByResourceGroupAsync(ResourceGroupName).ToEnumerableAsync(); Assert.IsEmpty(list.Where(p => p.Name.Equals(deploymentScriptName))); }