Skip to content

Added RM profile project #888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected override AzureContext DefaultContext
{
if (DefaultProfile == null || DefaultProfile.DefaultContext == null)
{
throw new PSInvalidOperationException("Run Login-AzureRMAccount to logic with profile.");
throw new PSInvalidOperationException("Run Login-AzureRMAccount to login.");
}

return DefaultProfile.DefaultContext;
Expand Down

Large diffs are not rendered by default.

Binary file not shown.
158 changes: 158 additions & 0 deletions src/Common/Commands.ResourceManager.Profile.Test/ProfileCmdletTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Microsoft.Azure.Commands.Profile;
using Microsoft.Azure.Commands.ResourceManager.Common;
using Microsoft.Azure.Common.Authentication;
using Microsoft.Azure.Common.Authentication.Models;
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using System.Linq;
using Xunit;
using System;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;

namespace Microsoft.Azure.Commands.ResourceManager.Profile.Test
{
public class ProfileCmdletTests : RMTestBase
{
private MemoryDataStore dataStore;
private MockCommandRuntime commandRuntimeMock;

public ProfileCmdletTests()
{
dataStore = new MemoryDataStore();
AzureSession.DataStore = dataStore;
commandRuntimeMock = new MockCommandRuntime();
AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory();
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void SelectAzureProfileInMemory()
{
var profile = new AzureRMProfile();
profile.Environments.Add("foo", AzureEnvironment.PublicEnvironments.Values.FirstOrDefault());
SelectAzureProfileCommand cmdlt = new SelectAzureProfileCommand();
// Setup
cmdlt.Profile = profile;
cmdlt.CommandRuntime = commandRuntimeMock;

// Act
cmdlt.InvokeBeginProcessing();
cmdlt.ExecuteCmdlet();
cmdlt.InvokeEndProcessing();

// Verify
Assert.True(AzureRMCmdlet.DefaultProfile.Environments.ContainsKey("foo"));
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void SelectAzureProfileNull()
{
SelectAzureProfileCommand cmdlt = new SelectAzureProfileCommand();
// Setup
cmdlt.CommandRuntime = commandRuntimeMock;

// Act
cmdlt.InvokeBeginProcessing();
Assert.Throws<ArgumentException>(() => cmdlt.ExecuteCmdlet());
cmdlt.InvokeEndProcessing();
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void SelectAzureProfileFromDisk()
{
var profile = new AzureRMProfile();
profile.Environments.Add("foo", AzureEnvironment.PublicEnvironments.Values.FirstOrDefault());
profile.Save("X:\\foo.json");
SelectAzureProfileCommand cmdlt = new SelectAzureProfileCommand();
// Setup
cmdlt.Path = "X:\\foo.json";
cmdlt.CommandRuntime = commandRuntimeMock;

// Act
cmdlt.InvokeBeginProcessing();
cmdlt.ExecuteCmdlet();
cmdlt.InvokeEndProcessing();

// Verify
Assert.True(AzureRMCmdlet.DefaultProfile.Environments.ContainsKey("foo"));
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void SaveAzureProfileInMemory()
{
var profile = new AzureRMProfile();
profile.Environments.Add("foo", AzureEnvironment.PublicEnvironments.Values.FirstOrDefault());
SaveAzureProfileCommand cmdlt = new SaveAzureProfileCommand();
// Setup
cmdlt.Profile = profile;
cmdlt.Path = "X:\\foo.json";
cmdlt.CommandRuntime = commandRuntimeMock;

// Act
cmdlt.InvokeBeginProcessing();
cmdlt.ExecuteCmdlet();
cmdlt.InvokeEndProcessing();

// Verify
Assert.True(AzureSession.DataStore.FileExists("X:\\foo.json"));
var profile2 = new AzureRMProfile("X:\\foo.json");
Assert.True(profile2.Environments.ContainsKey("foo"));
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void SaveAzureProfileNull()
{
SaveAzureProfileCommand cmdlt = new SaveAzureProfileCommand();
// Setup
AzureRMCmdlet.DefaultProfile = null;
cmdlt.Path = "X:\\foo.json";
cmdlt.CommandRuntime = commandRuntimeMock;

// Act
Assert.Throws<ArgumentException>(() => cmdlt.ExecuteCmdlet());
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void SaveAzureProfileFromDefault()
{
var profile = new AzureRMProfile();
profile.Environments.Add("foo", AzureEnvironment.PublicEnvironments.Values.FirstOrDefault());
profile.DefaultContext = new AzureContext(new AzureSubscription(), new AzureAccount(), profile.Environments["foo"]);
AzureRMCmdlet.DefaultProfile = profile;
SaveAzureProfileCommand cmdlt = new SaveAzureProfileCommand();
// Setup
cmdlt.Path = "X:\\foo.json";
cmdlt.CommandRuntime = commandRuntimeMock;

// Act
cmdlt.InvokeBeginProcessing();
cmdlt.ExecuteCmdlet();
cmdlt.InvokeEndProcessing();

// Verify
Assert.True(AzureSession.DataStore.FileExists("X:\\foo.json"));
var profile2 = new AzureRMProfile("X:\\foo.json");
Assert.True(profile2.Environments.ContainsKey("foo"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Xunit;

[assembly: AssemblyTitle("Microsoft Azure Powershell - Common ResourceManager Profile Test")]
[assembly: AssemblyCompany(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyCompany)]
[assembly: AssemblyProduct(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyProduct)]
[assembly: AssemblyCopyright(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyCopyright)]

[assembly: ComVisible(false)]
[assembly: CLSCompliant(false)]
[assembly: AssemblyVersion(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyVersion)]
[assembly: AssemblyFileVersion(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyFileVersion)]
34 changes: 34 additions & 0 deletions src/Common/Commands.ResourceManager.Profile.Test/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Hyak.Common" version="1.0.2" targetFramework="net45" />
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Azure.Common.Authentication" version="1.1.4-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Resources" version="2.18.7-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.0.5715.36130-prerelease" targetFramework="net45" />
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
<package id="Microsoft.Data.Edm" version="5.6.4" targetFramework="net45" />
<package id="Microsoft.Data.OData" version="5.6.4" targetFramework="net45" />
<package id="Microsoft.Data.Services.Client" version="5.6.4" targetFramework="net45" />
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.18.206251556" targetFramework="net45" />
<package id="Microsoft.Net.Http" version="2.2.28" targetFramework="net45" />
<package id="Microsoft.Rest.ClientRuntime" version="1.2.0" targetFramework="net45" />
<package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="0.9.3" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.3" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Management" version="4.1.1" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Management.Compute" version="12.3.1" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Management.Storage" version="5.1.1" targetFramework="net45" />
<package id="Moq" version="4.2.1402.2112" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
<package id="System.Spatial" version="5.6.4" targetFramework="net45" />
<package id="WindowsAzure.Storage" version="5.0.0" targetFramework="net45" />
<package id="xunit" version="2.0.0" targetFramework="net45" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net45" />
<package id="xunit.assert" version="2.0.0" targetFramework="net45" />
<package id="xunit.core" version="2.0.0" targetFramework="net45" />
<package id="xunit.extensibility.core" version="2.0.0" targetFramework="net45" />
<package id="xunit.runner.visualstudio" version="2.0.1" targetFramework="net45" />
</packages>
Loading