Skip to content

Update #92

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 1 commit into from
Dec 16, 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
@@ -0,0 +1,103 @@
// ----------------------------------------------------------------------------------
//
// 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.Azure.Commands.Compute;
using Microsoft.Azure.Commands.ScenarioTest;
using Microsoft.Azure.Commands.Compute.ScenarioTest;
using Microsoft.Azure.Management.Authorization;
using Microsoft.Azure.Management.Compute;
using Microsoft.Azure.Management.Compute.Models;
using Microsoft.Rest.Azure;
using Moq;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
using Microsoft.Azure.Commands.Common.Test.Mocks;
using Microsoft.Azure.Commands.Common.Authentication.Models;
using Microsoft.Azure.Commands.Utilities.Common;

namespace Microsoft.Azure.Commands.Compute.Test
{
public class GetAzureVMSizeCommandTests
{
private MemoryDataStore _dataStore;
private MockCommandRuntime _commandRuntimeMock;

private Mock<IVirtualMachineSizesOperations> vmSizesMock;

public GetAzureVMSizeCommandTests()
{
_dataStore = new MemoryDataStore();
_commandRuntimeMock = new MockCommandRuntime();
}
private IPage<T> GetPagableType<T>(List<T> collection)
{
var pagableResult = new Page<T>();
pagableResult.SetItemValue<T>(collection);
return pagableResult;
}

private void SetupListForVirtualMachineSizeAsync(string name, List<VirtualMachineSize> result)
{
vmSizesMock.Setup(f => f.ListWithHttpMessagesAsync(name, null, new CancellationToken()))
.Returns(Task.Factory.StartNew(() =>
new AzureOperationResponse<IPage<VirtualMachineSize>>
{
Body = GetPagableType(result)
}));
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void GetVirtualMachineSizesFromLocation()
{
var computeManagementClientMock = new Mock<IComputeManagementClient>();
vmSizesMock = new Mock<IVirtualMachineSizesOperations>();
computeManagementClientMock.Setup(f => f.VirtualMachineSizes).Returns(vmSizesMock.Object);
SetupListForVirtualMachineSizeAsync("westus", new List<VirtualMachineSize>());

var progressLoggerMock = new Mock<Action<string>>();
var errorLoggerMock = new Mock<Action<string>>();
var computeClient = new ComputeClient(computeManagementClientMock.Object)
{
VerboseLogger = progressLoggerMock.Object,
ErrorLogger = errorLoggerMock.Object
};

var profile = new AzureRMProfile(_dataStore);
profile.Environments.Add("foo", AzureEnvironment.PublicEnvironments.Values.FirstOrDefault());
profile.Context = new AzureContext(new AzureSubscription(), new AzureAccount(), profile.Environments["foo"]);
GetAzureVMSizeCommand cmdlt = new GetAzureVMSizeCommand
{
ComputeClient = computeClient,
Location = "westus"
};
cmdlt.DataStore = _dataStore;
cmdlt.SetCommandRuntimeMock(_commandRuntimeMock);
cmdlt.DefaultProfile = profile;

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

return;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
28 changes: 28 additions & 0 deletions src/CLU/Microsoft.Azure.Commands.Compute.Test/PageExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// ----------------------------------------------------------------------------------
//
// 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.Azure.Management.Compute.Models;
using System.Collections.Generic;
using System.Reflection;

namespace Microsoft.Azure.Commands.Compute.ScenarioTest
{
public static class PageExtensions
{
public static void SetItemValue<T> (this Page<T> pagableObj, List<T> collection) {
var property = typeof(Page<T>).GetProperty("Items", BindingFlags.Instance | BindingFlags.NonPublic);
property.SetValue(pagableObj, collection);
}
}
}
18 changes: 11 additions & 7 deletions src/CLU/Microsoft.Azure.Commands.Compute.Test/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
}
},
"dependencies": {
"AutoMapper": "4.1.1",
"Commands.Common": "",
"Commands.Common.Authentication": "",
"Commands.Common.Storage": "",
"Commands.ResourceManager.Common": "",
"Commands.ResourceManager.Cmdlets": "",
"Commands.ScenarioTests.ResourceManager.Common": "",
"Microsoft.Azure.Commands.Profile": "",
"Microsoft.Azure.Commands.Resources": "",
"Microsoft.Azure.Graph.RBAC": "2.0.0-preview",
"Microsoft.Azure.Management.Authorization": "2.0.1-preview",
"Microsoft.Azure.Management.Resources": "3.1.1-preview",
"Microsoft.Azure.Management.Compute": "11.0.0-prerelease",
"Microsoft.Azure.Management.Network": "3.0.3-preview",
"Microsoft.Azure.Management.Storage": "4.0.0-preview",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.210231457-alpha",
"Microsoft.Rest.ClientRuntime": "1.4.1",
"Microsoft.Rest.ClientRuntime.Azure": "2.1.0",
"Microsoft.Rest.ClientRuntime.Azure.Authentication": "1.0.0-preview",
"Microsoft.Rest.ClientRuntime": "1.5.0",
"Newtonsoft.Json": "7.0.1",
"System.Collections": "4.0.11-beta-23516",
"System.Collections.Concurrent": "4.0.11-beta-23516",
Expand All @@ -37,6 +37,7 @@
"System.Diagnostics.Tracing": "4.0.21-beta-23516",
"System.IO": "4.0.11-beta-23516",
"System.IO.FileSystem": "4.0.1-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Net.Http": "4.0.1-beta-23516",
"System.Net.WebHeaderCollection": "4.0.1-beta-23516",
"System.Reflection": "4.1.0-beta-23516",
Expand All @@ -55,13 +56,16 @@
"System.Threading": "4.0.11-beta-23516",
"System.Threading.Tasks": "4.0.11-beta-23516",
"System.Threading.Thread": "4.0.0-beta-23516",
"System.Xml.XmlDocument": "4.0.1-beta-23516",
"System.Xml.ReaderWriter": "4.0.11-beta-23516",
"xunit": "2.1.0",
"xunit.assert": "2.1.0",
"xunit.runner.dnx": "2.1.0-rc1-build204",
"moq.netcore": "4.4.0-beta8",
"Microsoft.CLU": "1.0.0",
"System.Linq": "4.0.1-beta-23409"
"System.Xml.XPath.XmlDocument": "4.0.1-beta-23516",
"WindowsAzure.Storage": "6.1.1-preview",
"Microsoft.Azure.Commands.Compute": "1.0.0-*"
},
"commands": {
"test": "xunit.runner.dnx"
Expand Down