Skip to content

Commit 1485fa1

Browse files
committed
Fix for Issue #404
1 parent 2253251 commit 1485fa1

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed

src/Common/Commands.Common/Properties/Resources.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Common/Commands.Common/Properties/Resources.resx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,10 +1361,9 @@ use and privacy statement at <url> and (c) agree to sharing my contact inf
13611361
<data name="SwitchAzureModeDeprecated" xml:space="preserve">
13621362
<value>The Switch-AzureMode cmdlet is deprecated and will be removed in a future release.</value>
13631363
</data>
1364-
<data name="ComputeCloudExceptionOperationIdMessage" xml:space="preserve">
1365-
<value>OperationID : '{0}'</value>
1366-
</data>
1367-
<!-- DSC -->
1364+
<data name="ComputeCloudExceptionOperationIdMessage" xml:space="preserve">
1365+
<value>OperationID : '{0}'</value>
1366+
</data>
13681367
<data name="PublishVMDscExtensionGetDscResourceFailed" xml:space="preserve">
13691368
<value>Cannot get module for DscResource '{0}'. Possible solutions:
13701369
1) Specify -ModuleName for Import-DscResource in your configuration.
@@ -1466,4 +1465,7 @@ The file needs to be a PowerShell script (.ps1 or .psm1).</value>
14661465
<data name="AzureVMDscInvalidConfigurationDataFile" xml:space="preserve">
14671466
<value>The configuration data must be a .psd1 file</value>
14681467
</data>
1468+
<data name="CannotChangeBuiltinEnvironment" xml:space="preserve">
1469+
<value>Cannot change built-in environment {0}.</value>
1470+
</data>
14691471
</root>

src/Common/Commands.Profile/Environment/SetAzureEnvironment.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using System;
16+
using System.Globalization;
1517
using System.Management.Automation;
1618
using System.Security.Permissions;
1719
using Microsoft.Azure.Common.Authentication.Models;
20+
using Microsoft.WindowsAzure.Commands.Common.Properties;
1821
using Microsoft.WindowsAzure.Commands.Profile.Models;
1922
using Microsoft.WindowsAzure.Commands.Utilities.Profile;
2023

@@ -95,6 +98,12 @@ public SetAzureEnvironmentCommand() : base(true) { }
9598
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
9699
public override void ExecuteCmdlet()
97100
{
101+
if ((Name == "AzureCloud") || (Name == "AzureChinaCloud"))
102+
{
103+
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
104+
Resources.CannotChangeBuiltinEnvironment, Name));
105+
}
106+
98107
var newEnvironment = new AzureEnvironment { Name = Name, OnPremise = EnableAdfsAuthentication };
99108
if (ProfileClient.Profile.Environments.ContainsKey(Name))
100109
{

src/ServiceManagement/Services/Commands.Test/Environment/GetAzureEnvironmentTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Microsoft.Azure.Common.Authentication.Models;
1919
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
2020
using Microsoft.WindowsAzure.Commands.Profile;
21+
using Microsoft.WindowsAzure.Commands.Profile.Models;
2122
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
2223
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2324
using Moq;
@@ -41,10 +42,10 @@ public GetAzureEnvironmentTests()
4142
[Trait(Category.AcceptanceType, Category.CheckIn)]
4243
public void GetsAzureEnvironments()
4344
{
44-
List<PSObject> environments = null;
45+
List<PSAzureEnvironment> environments = null;
4546
Mock<ICommandRuntime> commandRuntimeMock = new Mock<ICommandRuntime>();
4647
commandRuntimeMock.Setup(c => c.WriteObject(It.IsAny<object>(), It.IsAny<bool>()))
47-
.Callback<object, bool>((e, _) => environments = (List<PSObject>)e);
48+
.Callback<object, bool>((e, _) => environments = (List<PSAzureEnvironment>)e);
4849

4950
GetAzureEnvironmentCommand cmdlet = new GetAzureEnvironmentCommand()
5051
{
@@ -63,10 +64,10 @@ public void GetsAzureEnvironments()
6364
[Trait(Category.AcceptanceType, Category.CheckIn)]
6465
public void GetsAzureEnvironment()
6566
{
66-
List<PSObject> environments = null;
67+
List<PSAzureEnvironment> environments = null;
6768
Mock<ICommandRuntime> commandRuntimeMock = new Mock<ICommandRuntime>();
6869
commandRuntimeMock.Setup(c => c.WriteObject(It.IsAny<object>(), It.IsAny<bool>()))
69-
.Callback<object, bool>((e, _) => environments = (List<PSObject>)e);
70+
.Callback<object, bool>((e, _) => environments = (List<PSAzureEnvironment>)e);
7071

7172
GetAzureEnvironmentCommand cmdlet = new GetAzureEnvironmentCommand()
7273
{

src/ServiceManagement/Services/Commands.Test/Environment/SetAzureEnvironmentTests.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System;
1616
using System.Collections.Generic;
1717
using System.Management.Automation;
18+
using Microsoft.WindowsAzure.Commands.Profile.Models;
1819
using Microsoft.WindowsAzure.Commands.Utilities.Common;
1920
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2021
using Xunit;
@@ -70,7 +71,7 @@ public void SetsAzureEnvironment()
7071
cmdlet.ExecuteCmdlet();
7172
cmdlet.InvokeEndProcessing();
7273

73-
commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny<AzureEnvironment>()), Times.Once());
74+
commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny<PSAzureEnvironment>()), Times.Once());
7475
client = new ProfileClient(new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));
7576
AzureEnvironment env = client.Profile.Environments["KaTaL"];
7677
Assert.Equal(env.Name.ToLower(), cmdlet.Name.ToLower());
@@ -94,9 +95,12 @@ public void ThrowsWhenSettingPublicEnvironment()
9495
Name = name,
9596
PublishSettingsFileUrl = "http://microsoft.com"
9697
};
97-
98-
cmdlet.InvokeBeginProcessing();
99-
Assert.Throws<ArgumentException>(() => cmdlet.ExecuteCmdlet());
98+
var savedValue = AzureEnvironment.PublicEnvironments[name].GetEndpoint(AzureEnvironment.Endpoint.PublishSettingsFileUrl);
99+
cmdlet.InvokeBeginProcessing();
100+
Assert.Throws<InvalidOperationException>(() => cmdlet.ExecuteCmdlet());
101+
var newValue = cmdlet.ProfileClient.Profile.Environments[name].GetEndpoint(AzureEnvironment.Endpoint.PublishSettingsFileUrl);
102+
Assert.Equal(savedValue, newValue);
103+
Assert.NotEqual(cmdlet.PublishSettingsFileUrl, newValue);
100104
}
101105
}
102106

0 commit comments

Comments
 (0)