Skip to content

Commit e6098cf

Browse files
authored
Merge branch 'preview' into 6436
2 parents ccae361 + 86677b4 commit e6098cf

File tree

109 files changed

+10128
-13948
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+10128
-13948
lines changed

Azure.PowerShell.Netcore.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tools.Common.Netcore", "too
123123
EndProject
124124
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StaticAnalysis.Netcore", "tools\StaticAnalysis\StaticAnalysis.Netcore.csproj", "{493FA948-DA9C-47CD-8385-3C0261377D86}"
125125
EndProject
126+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Commands.RedisCache.Netcore", "src\ResourceManager\RedisCache\Commands.RedisCache\Commands.RedisCache.Netcore.csproj", "{06B4370D-D375-482C-AD23-CFDAC0176147}"
127+
EndProject
126128
Global
127129
GlobalSection(SolutionConfigurationPlatforms) = preSolution
128130
Debug|Any CPU = Debug|Any CPU
@@ -853,6 +855,18 @@ Global
853855
{493FA948-DA9C-47CD-8385-3C0261377D86}.Release|x64.Build.0 = Release|Any CPU
854856
{493FA948-DA9C-47CD-8385-3C0261377D86}.Release|x86.ActiveCfg = Release|Any CPU
855857
{493FA948-DA9C-47CD-8385-3C0261377D86}.Release|x86.Build.0 = Release|Any CPU
858+
{06B4370D-D375-482C-AD23-CFDAC0176147}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
859+
{06B4370D-D375-482C-AD23-CFDAC0176147}.Debug|Any CPU.Build.0 = Debug|Any CPU
860+
{06B4370D-D375-482C-AD23-CFDAC0176147}.Debug|x64.ActiveCfg = Debug|Any CPU
861+
{06B4370D-D375-482C-AD23-CFDAC0176147}.Debug|x64.Build.0 = Debug|Any CPU
862+
{06B4370D-D375-482C-AD23-CFDAC0176147}.Debug|x86.ActiveCfg = Debug|Any CPU
863+
{06B4370D-D375-482C-AD23-CFDAC0176147}.Debug|x86.Build.0 = Debug|Any CPU
864+
{06B4370D-D375-482C-AD23-CFDAC0176147}.Release|Any CPU.ActiveCfg = Release|Any CPU
865+
{06B4370D-D375-482C-AD23-CFDAC0176147}.Release|Any CPU.Build.0 = Release|Any CPU
866+
{06B4370D-D375-482C-AD23-CFDAC0176147}.Release|x64.ActiveCfg = Release|Any CPU
867+
{06B4370D-D375-482C-AD23-CFDAC0176147}.Release|x64.Build.0 = Release|Any CPU
868+
{06B4370D-D375-482C-AD23-CFDAC0176147}.Release|x86.ActiveCfg = Release|Any CPU
869+
{06B4370D-D375-482C-AD23-CFDAC0176147}.Release|x86.Build.0 = Release|Any CPU
856870
EndGlobalSection
857871
GlobalSection(SolutionProperties) = preSolution
858872
HideSolutionNode = FALSE

build.proj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@
134134
<Target Name="Clean">
135135
<Message Importance="high" Text="Cleaning Cmdlets..." ContinueOnError="false" />
136136

137+
<!-- Clean out the NuGet cache -->
138+
<Exec ContinueOnError="false"
139+
Command="&quot;$(PowerShellCommand)&quot; -NonInteractive -NoLogo -NoProfile -Command &quot; $Path = Join-Path $env:USERPROFILE .nuget; if (Test-Path $Path) { Remove-Item $Path -Recurse } &quot;"/>
140+
137141
<!-- Clean each project -->
138142
<MSBuild Projects="@(CmdletSolutionsToBuild)"
139143
Targets="Clean"

src/ResourceManager/Automation/Commands.Automation/Cmdlet/ExportAzureAutomationDscConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public override void ExecuteCmdlet()
7373
if (ShouldProcess(Name, VerbsData.Export))
7474
{
7575
var ret = this.AutomationClient.GetConfigurationContent(this.ResourceGroupName,
76-
this.AutomationAccountName, this.Name, isDraft, OutputFolder, this.Force);
76+
this.AutomationAccountName, this.Name, isDraft, ResolveUserPath(OutputFolder), this.Force);
7777

7878
this.WriteObject(ret, true);
7979
}

src/ResourceManager/Automation/Commands.Automation/Cmdlet/ExportAzureAutomationDscNodeReportContent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public override void ExecuteCmdlet()
7070
if (ShouldProcess(ReportId.ToString(), VerbsData.Export))
7171
{
7272
var ret = this.AutomationClient.GetDscNodeReportContent(this.ResourceGroupName,
73-
this.AutomationAccountName, this.NodeId, this.ReportId, OutputFolder, overwriteExistingFile);
73+
this.AutomationAccountName, this.NodeId, this.ReportId, ResolveUserPath(OutputFolder), overwriteExistingFile);
7474

7575
this.WriteObject(ret, true);
7676
}

src/ResourceManager/Automation/Commands.Automation/Cmdlet/ExportAzureAutomationRunbook.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected override void AutomationProcessRecord()
6666
if (ShouldProcess(Name, VerbsData.Export))
6767
{
6868
var outputFolder = this.AutomationClient.ExportRunbook(this.ResourceGroupName,
69-
this.AutomationAccountName, this.Name, isDraft, this.OutputFolder, this.Force.IsPresent);
69+
this.AutomationAccountName, this.Name, isDraft, ResolveUserPath(this.OutputFolder), this.Force.IsPresent);
7070

7171
this.WriteObject(outputFolder, true);
7272
}

src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationDscOnboardingMetaconfig.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public SwitchParameter Force
6060
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
6161
public override void ExecuteCmdlet()
6262
{
63+
OutputFolder = ResolveUserPath(OutputFolder);
6364
this.ConfirmAction(
6465
this.Force.IsPresent,
6566
string.Format(CultureInfo.CurrentCulture, Resources.DscMetaMofHasKeysWarning),

src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public override void ExecuteCmdlet()
9494
var configuration = this.AutomationClient.CreateConfiguration(
9595
this.ResourceGroupName,
9696
this.AutomationAccountName,
97-
this.SourcePath,
97+
ResolveUserPath(this.SourcePath),
9898
this.Tags,
9999
this.Description,
100100
this.LogVerbose,

src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public override void ExecuteCmdlet()
7777
{
7878
if (ShouldProcess(Path, VerbsData.Import))
7979
{
80+
Path = ResolveUserPath(Path);
8081
var nodeName = System.IO.Path.GetFileNameWithoutExtension(Path);
8182
var nodeConfigurationName = ConfigurationName + "." + nodeName;
8283
NodeConfiguration nodeConfigurationModel = null;

src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationCertificate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class NewAzureAutomationCertificate : AzureAutomationBaseCmdlet
7070
protected override void AutomationProcessRecord()
7171
{
7272

73-
var createdCertificate = this.AutomationClient.CreateCertificate(this.ResourceGroupName, this.AutomationAccountName, this.Name, this.ResolvePath(this.Path), this.Password, this.Description, this.Exportable.IsPresent);
73+
var createdCertificate = this.AutomationClient.CreateCertificate(this.ResourceGroupName, this.AutomationAccountName, this.Name, this.ResolvePath(Path), this.Password, this.Description, this.Exportable.IsPresent);
7474

7575
this.WriteObject(createdCertificate);
7676
}

src/ResourceManager/Automation/Commands.Automation/Common/AutomationClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1895,7 +1895,7 @@ private DirectoryInfo WriteRunbookToFile(string outputFolder, string runbookName
18951895

18961896
var fileExtension = IsGraphRunbook(runbookType) ? Constants.SupportedFileExtensions.Graph : Constants.SupportedFileExtensions.PowerShellScript;
18971897

1898-
var outputFilePath = outputFolderFullPath + "\\" + runbookName + fileExtension;
1898+
var outputFilePath = Path.Combine(outputFolderFullPath, runbookName + fileExtension);
18991899

19001900
// file exists and overwrite Not specified
19011901
if (File.Exists(outputFilePath) && !overwriteExistingFile)

src/ResourceManager/AzureBatch/Commands.Batch/Files/GetBatchNodeFileContentCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public class GetBatchNodeFileContentCommand : BatchObjectModelCmdletBase
9696

9797
public override void ExecuteCmdlet()
9898
{
99+
DestinationPath = ResolveUserPath(DestinationPath);
99100
if (this.ByteRangeEnd != null && this.ByteRangeStart == null)
100101
{
101102
this.ByteRangeStart = 0;

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Action/SaveAzureVMImageCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public override void ExecuteCmdlet()
8888
result.EndTime = DateTime.Now;
8989
if (!string.IsNullOrWhiteSpace(this.Path))
9090
{
91-
File.WriteAllText(this.Path, op.Body.Resources[0].ToString());
91+
File.WriteAllText(ResolveUserPath(this.Path), op.Body.Resources[0].ToString());
9292
}
9393
WriteObject(result);
9494
});

src/ResourceManager/DataLakeStore/Commands.DataLakeStore/DataPlaneCommands/ExportAzureRmDataLakeStoreItem.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public class ExportAzureDataLakeStoreItem : DataLakeStoreFileSystemCmdletBase
109109
public override void ExecuteCmdlet()
110110
{
111111
// We will let this throw itself if the path they give us is invalid
112-
var powerShellReadyPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(Destination);
112+
var powerShellReadyPath = ResolveUserPath(Destination);
113113
ConfirmAction(
114114
VerbsData.Export,
115115
Path.TransformedPath,
@@ -119,8 +119,7 @@ public override void ExecuteCmdlet()
119119
{
120120
if (ParameterSetName.Equals(DiagnosticParameterSetName) && DiagnosticLogLevel != LogLevel.None)
121121
{
122-
var diagnosticPath =
123-
SessionState.Path.GetUnresolvedProviderPathFromPSPath(DiagnosticLogPath);
122+
var diagnosticPath = ResolveUserPath(DiagnosticLogPath);
124123
DataLakeStoreFileSystemClient.SetupFileLogging(DiagnosticLogLevel, diagnosticPath);
125124
}
126125

src/ResourceManager/DataLakeStore/Commands.DataLakeStore/DataPlaneCommands/ImportAzureRmDataLakeStoreItem.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public class ImportAzureDataLakeStoreItem : DataLakeStoreFileSystemCmdletBase
118118

119119
public override void ExecuteCmdlet()
120120
{
121-
var powerShellSourcePath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(Path);
121+
var powerShellSourcePath = ResolveUserPath(Path);
122122
ConfirmAction(
123123
Resources.UploadFileMessage,
124124
Destination.TransformedPath,
@@ -128,8 +128,7 @@ public override void ExecuteCmdlet()
128128
{
129129
if (ParameterSetName.Equals(DiagnosticParameterSetName) && DiagnosticLogLevel != LogLevel.None)
130130
{
131-
var diagnosticPath =
132-
SessionState.Path.GetUnresolvedProviderPathFromPSPath(DiagnosticLogPath);
131+
var diagnosticPath = ResolveUserPath(DiagnosticLogPath);
133132
DataLakeStoreFileSystemClient.SetupFileLogging(DiagnosticLogLevel, diagnosticPath);
134133
}
135134

src/ResourceManager/DeviceProvisioningServices/Commands.DeviceProvisioningServices/Cmdlet/IotDpsCertificates/AddAzureRmIotDeviceProvisioningServiceCertificate.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public class AddAzureRmIoTDeviceProvisioningServiceCertificate : IotDpsBaseCmdle
114114

115115
public override void ExecuteCmdlet()
116116
{
117+
Path = ResolveUserPath(Path);
117118
if (ShouldProcess(Name, DPSResources.AddCertificate))
118119
{
119120
switch (ParameterSetName)

src/ResourceManager/DeviceProvisioningServices/Commands.DeviceProvisioningServices/Cmdlet/IotDpsCertificates/SetAzureRmIotDeviceProvisioningServiceCertificate.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public class SetAzureRmIoTDeviceProvisioningServiceCertificate : IotDpsBaseCmdle
111111

112112
public override void ExecuteCmdlet()
113113
{
114+
Path = ResolveUserPath(Path);
114115
if (ShouldProcess(Name, DPSResources.SetCertificate))
115116
{
116117
switch (ParameterSetName)

src/ResourceManager/IotHub/Commands.IotHub/IotHub/AddAzureRmIotHubCertificate.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public class AddAzureRmIotHubCertificate : IotHubBaseCmdlet
104104

105105
public override void ExecuteCmdlet()
106106
{
107+
Path = ResolveUserPath(Path);
107108
if (ShouldProcess(CertificateName, Properties.Resources.AddIotHubCertificate))
108109
{
109110
string certificate = string.Empty;

src/ResourceManager/IotHub/Commands.IotHub/IotHub/SetAzureRmIotHubVerifiedCertificate.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public class SetAzureRmIotHubVerifiedCertificate : IotHubBaseCmdlet
112112

113113
public override void ExecuteCmdlet()
114114
{
115+
Path = ResolveUserPath(Path);
115116
if (ShouldProcess(CertificateName, Properties.Resources.VerifyIotHubCertificate))
116117
{
117118
string certificate = string.Empty;

src/ResourceManager/KeyVault/Commands.KeyVault/Commands/ImportAzureKeyVaultCertificate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public override void ExecuteCmdlet()
179179

180180
internal X509Certificate2Collection InitializeCertificateCollection()
181181
{
182-
FileInfo certFile = new FileInfo(this.GetUnresolvedProviderPathFromPSPath(this.FilePath));
182+
FileInfo certFile = new FileInfo(ResolveUserPath(this.FilePath));
183183
if (!certFile.Exists)
184184
{
185185
throw new FileNotFoundException(string.Format(KeyVaultProperties.Resources.CertificateFileNotFound, this.FilePath));

src/ResourceManager/KeyVault/Commands.KeyVault/Commands/ManagedStorageAccounts/RestoreAzureKeyVaultManagedStorageAccount.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public override void ExecuteCmdlet()
9595

9696
if (ShouldProcess(VaultName, Properties.Resources.RestoreManagedStorageAccount))
9797
{
98-
var resolvedFilePath = this.GetUnresolvedProviderPathFromPSPath(InputFile);
98+
var resolvedFilePath = this.ResolveUserPath(InputFile);
9999

100100
if (!AzureSession.Instance.DataStore.FileExists(resolvedFilePath))
101101
{

src/ResourceManager/KeyVault/Commands.KeyVault/Commands/RestoreAzureKeyVaultCertificate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public override void ExecuteCmdlet()
9595

9696
if (ShouldProcess(VaultName, Properties.Resources.RestoreCertificate))
9797
{
98-
var resolvedFilePath = this.GetUnresolvedProviderPathFromPSPath(InputFile);
98+
var resolvedFilePath = this.ResolveUserPath(InputFile);
9999

100100
if (!AzureSession.Instance.DataStore.FileExists(resolvedFilePath))
101101
{

src/ResourceManager/KeyVault/Commands.KeyVault/Commands/RestoreAzureKeyVaultKey.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,17 @@ public override void ExecuteCmdlet()
9494

9595
if (ShouldProcess(VaultName, Properties.Resources.RestoreKey))
9696
{
97-
var filePath = ResolvePath(InputFile);
97+
var filePath = ResolveKeyVaultPath(InputFile);
9898

9999
var restoredKeyBundle = this.DataServiceClient.RestoreKey(VaultName, filePath);
100100

101101
this.WriteObject(restoredKeyBundle);
102102
}
103103
}
104104

105-
private string ResolvePath(string filePath)
105+
private string ResolveKeyVaultPath(string filePath)
106106
{
107-
FileInfo keyFile = new FileInfo(this.GetUnresolvedProviderPathFromPSPath(filePath));
107+
FileInfo keyFile = new FileInfo(this.ResolveUserPath(filePath));
108108
if (!keyFile.Exists)
109109
{
110110
throw new FileNotFoundException(string.Format(Resources.BackupKeyFileNotFound, filePath));

src/ResourceManager/KeyVault/Commands.KeyVault/Commands/RestoreAzureKeyVaultSecret.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public override void ExecuteCmdlet( )
9595

9696
if (ShouldProcess(VaultName, Properties.Resources.RestoreSecret))
9797
{
98-
var resolvedFilePath = this.GetUnresolvedProviderPathFromPSPath(InputFile);
98+
var resolvedFilePath = this.ResolveUserPath(InputFile);
9999

100100
if (!AzureSession.Instance.DataStore.FileExists(resolvedFilePath))
101101
{

src/ResourceManager/KeyVault/Commands.KeyVault/help/Set-AzureRmKeyVaultAccessPolicy.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,10 @@ The acceptable values for this parameter:
450450
- Setissuers
451451
- Deleteissuers
452452
- Manageissuers
453+
- Recover
454+
- Backup
455+
- Restore
456+
- Purge
453457
454458
```yaml
455459
Type: System.String[]

src/ResourceManager/Profile/Commands.Profile.Test/EnvironmentCmdletTests.cs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Microsoft.Azure.Commands.Common.Authentication;
1616
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
1717
using Microsoft.Azure.Commands.Common.Authentication.Models;
18+
using Microsoft.Azure.Commands.Common.Authentication.ResourceManager;
1819
using Microsoft.Azure.Commands.Profile;
1920
using Microsoft.Azure.Commands.Profile.Models;
2021
using Microsoft.Azure.Commands.Profile.Utilities;
@@ -715,6 +716,104 @@ public void SetEnvironmentForStack()
715716
Assert.Equal(env3.GetEndpoint(AzureEnvironment.Endpoint.Gallery), cmdlet3.GalleryEndpoint);
716717
}
717718

719+
[Fact]
720+
[Trait(Category.AcceptanceType, Category.CheckIn)]
721+
public void SetEnvironmentForMultipleContexts()
722+
{
723+
// Add new environment
724+
Mock<ICommandRuntime> commandRuntimeMock = new Mock<ICommandRuntime>();
725+
SetupConfirmation(commandRuntimeMock);
726+
var cmdlet = new AddAzureRMEnvironmentCommand()
727+
{
728+
CommandRuntime = commandRuntimeMock.Object,
729+
Name = "Katal",
730+
ARMEndpoint = "https://management.azure.com/",
731+
AzureKeyVaultDnsSuffix = "vault.local.azurestack.external",
732+
AzureKeyVaultServiceEndpointResourceId = "https://vault.local.azurestack.external"
733+
734+
};
735+
var dict = new Dictionary<string, object>
736+
{
737+
{ "ARMEndpoint", "https://management.azure.com/" },
738+
{ "AzureKeyVaultDnsSuffix", "vault.local.azurestack.external" },
739+
{ "AzureKeyVaultServiceEndpointResourceId", "https://vault.local.azurestack.external" }
740+
};
741+
742+
cmdlet.SetBoundParameters(dict);
743+
cmdlet.SetParameterSet("ARMEndpoint");
744+
cmdlet.InvokeBeginProcessing();
745+
cmdlet.ExecuteCmdlet();
746+
cmdlet.InvokeEndProcessing();
747+
var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile<AzureRmProfile>());
748+
IAzureEnvironment env = AzureRmProfileProvider.Instance.Profile.Environments.First((e) => string.Equals(e.Name, "KaTaL", StringComparison.OrdinalIgnoreCase));
749+
Assert.Equal(env.Name, cmdlet.Name);
750+
Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix), dict["AzureKeyVaultDnsSuffix"]);
751+
Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId), dict["AzureKeyVaultServiceEndpointResourceId"]);
752+
753+
// Create contexts using the new environment
754+
var profile = new AzureRmProfile();
755+
string contextName1;
756+
var context1 = (new AzureContext { Environment = env })
757+
.WithAccount(new AzureAccount { Id = "[email protected]" })
758+
.WithTenant(new AzureTenant { Id = Guid.NewGuid().ToString(), Directory = "contoso.com" })
759+
.WithSubscription(new AzureSubscription { Id = Guid.NewGuid().ToString(), Name = "Contoso Subscription 1" });
760+
profile.TryAddContext(context1, out contextName1);
761+
string contextName2;
762+
var context2 = (new AzureContext { Environment = env })
763+
.WithAccount(new AzureAccount { Id = "[email protected]" })
764+
.WithTenant(new AzureTenant { Id = Guid.NewGuid().ToString(), Directory = "contoso.cn" })
765+
.WithSubscription(new AzureSubscription { Id = Guid.NewGuid().ToString(), Name = "Contoso Subscription 2" });
766+
profile.TryAddContext(context2, out contextName2);
767+
profile.TrySetDefaultContext(context1);
768+
AzureRmProfileProvider.Instance.Profile = profile;
769+
770+
// Update the environment with new endpoints
771+
commandRuntimeMock = new Mock<ICommandRuntime>();
772+
SetupConfirmation(commandRuntimeMock);
773+
var cmdlet2 = new AddAzureRMEnvironmentCommand()
774+
{
775+
CommandRuntime = commandRuntimeMock.Object,
776+
Name = "Katal",
777+
ARMEndpoint = "https://management.azure.com/",
778+
AzureKeyVaultDnsSuffix = "adminvault.local.azurestack.external",
779+
AzureKeyVaultServiceEndpointResourceId = "https://adminvault.local.azurestack.external"
780+
};
781+
782+
dict.Clear();
783+
dict = new Dictionary<string, object>
784+
{
785+
{ "ARMEndpoint", "https://management.azure.com/" },
786+
{ "AzureKeyVaultDnsSuffix", "adminvault.local.azurestack.external" },
787+
{ "AzureKeyVaultServiceEndpointResourceId", "https://adminvault.local.azurestack.external" }
788+
};
789+
790+
cmdlet2.SetBoundParameters(dict);
791+
cmdlet2.SetParameterSet("ARMEndpoint");
792+
cmdlet2.InvokeBeginProcessing();
793+
cmdlet2.ExecuteCmdlet();
794+
cmdlet2.InvokeEndProcessing();
795+
796+
profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile<AzureRmProfile>());
797+
env = AzureRmProfileProvider.Instance.Profile.Environments.First((e) => string.Equals(e.Name, "KaTaL", StringComparison.OrdinalIgnoreCase));
798+
Assert.Equal(env.Name, cmdlet.Name);
799+
Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix), dict["AzureKeyVaultDnsSuffix"]);
800+
Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId), dict["AzureKeyVaultServiceEndpointResourceId"]);
801+
802+
// Validate that the endpoints were updated in the contexts
803+
profile = (AzureRmProfile)AzureRmProfileProvider.Instance.Profile;
804+
Assert.NotNull(profile);
805+
Assert.NotNull(profile.Contexts);
806+
Assert.NotEmpty(profile.Contexts);
807+
foreach (var context in profile.Contexts.Values)
808+
{
809+
Assert.NotNull(context);
810+
Assert.NotNull(context.Environment);
811+
Assert.Equal(context.Environment.Name, env.Name);
812+
Assert.Equal(context.Environment.AzureKeyVaultDnsSuffix, env.AzureKeyVaultDnsSuffix);
813+
Assert.Equal(context.Environment.AzureKeyVaultServiceEndpointResourceId, env.AzureKeyVaultServiceEndpointResourceId);
814+
}
815+
}
816+
718817
[Fact]
719818
[Trait(Category.AcceptanceType, Category.CheckIn)]
720819
public void RemovesAzureEnvironment()

0 commit comments

Comments
 (0)