Skip to content

Added Get-AzureRMAutomationHybridRunbookWorkerGroup cmdlet #2325

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 11 commits into from
Jun 28, 2016
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 @@ -102,7 +102,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robplank We no longer accept MSTest tests - please convert this to xunit, and you will be good. Mainly this is just re-attributing the methods, as the model for tests is largely the same

<Private>False</Private>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.4.1.1\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
Expand Down Expand Up @@ -130,8 +132,10 @@
<HintPath>..\..\..\packages\Microsoft.Net.Http.2.2.28\lib\net45\System.Net.Http.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Xml" /> <Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath> <Private>True</Private>
<Reference Include="System.Xml" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.assert, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\xunit.assert.2.1.0\lib\portable-net45+win8+wp8+wpa81\xunit.assert.dll</HintPath>
Expand Down Expand Up @@ -187,6 +191,7 @@
<Compile Include="UnitTests\StartAzureAutomationRunbookTest.cs" />
<Compile Include="UnitTests\StopAzureAutomationJobTest.cs" />
<Compile Include="UnitTests\SuspendAzureAutomationJobTest.cs" />
<Compile Include="UnitTests\GetAzureAutomationHybridWorkerGroupTest.cs" />
<Compile Include="UnitTests\UnregisterAzureAutomationScheduledRunbookTest.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using Microsoft.Azure.Commands.Automation.Cmdlet;
using Microsoft.Azure.Commands.Automation.Common;
using Microsoft.Azure.Commands.Automation.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Moq;
using System.Collections.Generic;
using Xunit;

namespace Microsoft.Azure.Commands.ResourceManager.Automation.Test.UnitTests
{
[TestClass]
public class GetAzureAutomationHybridWorkerGroupTest : RMTestBase
{
private Mock<IAutomationClient> mockAutomationClient;

private MockCommandRuntime mockCommandRuntime;

private GetAzureAutomationHybridWorkerGroup cmdlet;


public GetAzureAutomationHybridWorkerGroupTest()
{
this.mockAutomationClient = new Mock<IAutomationClient>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Xunit, this can just be in the class constructor, as long as it can run before each test. You can do suite-based intiailization using TestFixtures

this.mockCommandRuntime = new MockCommandRuntime();
this.cmdlet = new GetAzureAutomationHybridWorkerGroup
{
AutomationClient = this.mockAutomationClient.Object,
CommandRuntime = this.mockCommandRuntime
};
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void GetAzureAutomationHybridWorkerGroupByNameSuccessfull()
{
//Setup
string resourceGroupName = "resourceGroup";
string accountName = "automation";
string hybridRunbookWorkerGroupName = "hybridRunbookWorkerGroup";

this.mockAutomationClient.Setup(f => f.GetHybridRunbookWorkerGroup(resourceGroupName, accountName, hybridRunbookWorkerGroupName));

// Test
this.cmdlet.ResourceGroupName = resourceGroupName;
this.cmdlet.AutomationAccountName = accountName;
this.cmdlet.Name = hybridRunbookWorkerGroupName;
this.cmdlet.SetParameterSet("ByName");
this.cmdlet.ExecuteCmdlet();

// Assert
this.mockAutomationClient.Verify(f => f.GetHybridRunbookWorkerGroup(resourceGroupName, accountName, hybridRunbookWorkerGroupName), Times.Once());
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void GetAzureAutomationHybridWorkerGroupByAllSuccessfull()
{
// Setup
string resourceGroupName = "resourceGroup";
string accountName = "automation";
string nextLink = string.Empty;

this.mockAutomationClient.Setup(f => f.ListHybridRunbookWorkerGroups(resourceGroupName, accountName, ref nextLink)).Returns((string a, string b, string c) => new List<HybridRunbookWorkerGroup>()); ;

// Test
this.cmdlet.ResourceGroupName = resourceGroupName;
this.cmdlet.AutomationAccountName = accountName;
this.cmdlet.SetParameterSet("ByAll");
this.cmdlet.ExecuteCmdlet();

//Assert
this.mockAutomationClient.Verify(f => f.ListHybridRunbookWorkerGroups(resourceGroupName, accountName, ref nextLink), Times.Once());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Management.Automation;
using System.Security.Permissions;
using Microsoft.Azure.Commands.Automation.Model;
using Microsoft.Azure.Commands.Automation.Common;


namespace Microsoft.Azure.Commands.Automation.Cmdlet
{
[Cmdlet(VerbsCommon.Get, "AzureRMAutomationHybridWorkerGroup", DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)]
[OutputType(typeof(HybridRunbookWorkerGroup))]
public class GetAzureAutomationHybridWorkerGroup : AzureAutomationBaseCmdlet
{
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName,Position = 2, Mandatory = false, ValueFromPipeline = true, HelpMessage = "The Hybrid Runbook Worker Group name")]
[Alias("Group")]
public string Name { get; set; }

protected override void AutomationProcessRecord()
{
if (this.ParameterSetName == AutomationCmdletParameterSets.ByName)
{
IEnumerable<HybridRunbookWorkerGroup> ret = null;
ret = new List<HybridRunbookWorkerGroup> {

this.AutomationClient.GetHybridRunbookWorkerGroup(this.ResourceGroupName, this.AutomationAccountName, this.Name)
};
this.GenerateCmdletOutput(ret);
}
else if(this.ParameterSetName == AutomationCmdletParameterSets.ByAll)
{
var nextLink = string.Empty;
do
{
var results = this.AutomationClient.ListHybridRunbookWorkerGroups(this.ResourceGroupName, this.AutomationAccountName, ref nextLink);
this.GenerateCmdletOutput(results);
}while (!string.IsNullOrEmpty(nextLink));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Cmdlet\AzureAutomationBaseCmdlet.cs" />
<Compile Include="Cmdlet\GetAzureAutomationHybridWorkerGroup.cs" />
<Compile Include="Cmdlet\GetAzureAutomationJobOutputRecord.cs" />
<Compile Include="Cmdlet\ImportAzureAutomationDscNodeConfiguration.cs" />
<Compile Include="Cmdlet\ExportAzureAutomationDscConfiguration.cs" />
Expand Down Expand Up @@ -225,6 +226,8 @@
<Compile Include="Model\DscNode.cs" />
<Compile Include="Model\DscNodeReport.cs" />
<Compile Include="Model\DscOnboardingMetaconfig.cs" />
<Compile Include="Model\HybridRunbookWorker.cs" />
<Compile Include="Model\HybridRunbookWorkerGroup.cs" />
<Compile Include="Model\Job.cs" />
<Compile Include="Model\JobSchedule.cs" />
<Compile Include="Model\JobStreamRecord.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
using Runbook = Microsoft.Azure.Commands.Automation.Model.Runbook;
using Schedule = Microsoft.Azure.Commands.Automation.Model.Schedule;
using Variable = Microsoft.Azure.Commands.Automation.Model.Variable;
using HybridRunbookWorkerGroup = Microsoft.Azure.Commands.Automation.Model.HybridRunbookWorkerGroup;


namespace Microsoft.Azure.Commands.Automation.Common
{
Expand All @@ -54,6 +56,10 @@ public AutomationClient()
{
}

/// <summary>
///
/// </summary>
/// <param name="context"></param>
public AutomationClient(AzureContext context)
: this(context.Subscription,
AzureSession.ClientFactory.CreateClient<AutomationManagement.AutomationManagementClient>(context,
Expand Down Expand Up @@ -1360,6 +1366,41 @@ public void DeleteConnection(string resourceGroupName, string automationAccountN

#endregion

#region HybridRunbookworkers

public IEnumerable<HybridRunbookWorkerGroup> ListHybridRunbookWorkerGroups(string resourceGroupName, string automationAccountName, ref string nextLink)
{
HybridRunbookWorkerGroupsListResponse response;

if (string.IsNullOrEmpty(nextLink))
{
response = this.automationManagementClient.HybridRunbookWorkerGroups.List(resourceGroupName, automationAccountName);
}
else
{
response = this.automationManagementClient.HybridRunbookWorkerGroups.ListNext(nextLink);
}

nextLink = response.NextLink;

return response.HybridRunbookWorkerGroups.Select(c => new HybridRunbookWorkerGroup(resourceGroupName, automationAccountName, c));
}

public HybridRunbookWorkerGroup GetHybridRunbookWorkerGroup(string resourceGroupName, string automationAccountName, string name)
{
var hybridRunbookWorkerGroupModel = this.TryGetHybridRunbookWorkerModel(resourceGroupName, automationAccountName, name);
if (hybridRunbookWorkerGroupModel == null)
{
throw new ResourceCommonException(typeof(HybridRunbookWorkerGroup),
string.Format(CultureInfo.CurrentCulture, Resources.HybridRunbookWorkerGroupNotFound, name));
}

return new HybridRunbookWorkerGroup(resourceGroupName, automationAccountName, hybridRunbookWorkerGroupModel);

}

#endregion

#region JobSchedules

public JobSchedule GetJobSchedule(string resourceGroupName, string automationAccountName, Guid jobScheduleId)
Expand Down Expand Up @@ -1599,7 +1640,30 @@ private Azure.Management.Automation.Models.Runbook TryGetRunbookModel(string res
return runbook;
}

private Azure.Management.Automation.Models.Certificate TryGetCertificateModel(string resourceGroupName, string automationAccountName,



private Azure.Management.Automation.Models.HybridRunbookWorkerGroup TryGetHybridRunbookWorkerModel(string resourceGroupName, string automationAccountName, string HybridRunbookWorkerGroupName)
{
Azure.Management.Automation.Models.HybridRunbookWorkerGroup hybridRunbookWorkerGroup = null;
try
{
hybridRunbookWorkerGroup = this.automationManagementClient.HybridRunbookWorkerGroups.Get(resourceGroupName, automationAccountName, HybridRunbookWorkerGroupName).HybridRunbookWorkerGroup;
}
catch (CloudException e)
{
if (e.Response.StatusCode == HttpStatusCode.NotFound)
{
hybridRunbookWorkerGroup = null;
}
else
{
throw;
}
}
return hybridRunbookWorkerGroup;
}
private Azure.Management.Automation.Models.Certificate TryGetCertificateModel(string resourceGroupName, string automationAccountName,
string certificateName)
{
Azure.Management.Automation.Models.Certificate certificate = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ Model.Webhook CreateWebhook(

#endregion

#region HybridrunbookWorker
HybridRunbookWorkerGroup GetHybridRunbookWorkerGroup(string resourceGroupName, string automationAccountName, string hybridRunbookWorkerGroupName);

IEnumerable<HybridRunbookWorkerGroup> ListHybridRunbookWorkerGroups(string resourceGroupName, string automationAccountName, ref string nextLink);
#endregion

#region Credentials

CredentialInfo CreateCredential(string resourceGroupName, string automationAccountName, string name, string userName, string password, string description);
Expand Down
Loading