Skip to content

Commit 9c5b928

Browse files
committed
Merge branch 'dev' of https://github.com/elvg/azure-powershell into dev3
2 parents afc67b0 + 7c34a3b commit 9c5b928

18 files changed

+798
-9
lines changed

src/ServiceManagement/Automation/Commands.Automation.Test/Commands.Automation.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,19 @@
110110
</ItemGroup>
111111
<ItemGroup>
112112
<Compile Include="Properties\AssemblyInfo.cs" />
113+
<Compile Include="UnitTests\GetAzureAutomationConnectionTest.cs" />
113114
<Compile Include="UnitTests\GetAzureAutomationCertificateTest.cs" />
114115
<Compile Include="UnitTests\NewAzureAutomationAccountTest.cs" />
115116
<Compile Include="UnitTests\GetAzureAutomationAccountTest.cs" />
116117
<Compile Include="UnitTests\GetAzureAutomationRunbookDefinitionTest.cs" />
117118
<Compile Include="UnitTests\GetAzureAutomationRunbookTest.cs" />
118119
<Compile Include="UnitTests\GetAzureAutomationScheduledRunbookTest.cs" />
120+
<Compile Include="UnitTests\NewAzureAutomationConnectionTest.cs" />
119121
<Compile Include="UnitTests\NewAzureAutomationCertificateTest.cs" />
120122
<Compile Include="UnitTests\NewAzureAutomationRunbookTest.cs" />
121123
<Compile Include="UnitTests\PublishAzureAutomationRunbookTest.cs" />
122124
<Compile Include="UnitTests\RemoveAzureAutomationAccountTest.cs" />
125+
<Compile Include="UnitTests\RemoveAzureAutomationConnectionTest.cs" />
123126
<Compile Include="UnitTests\RemoveAzureAutomationCertificateTest.cs" />
124127
<Compile Include="UnitTests\RegisterAzureAutomationScheduledRunbookTest.cs" />
125128
<Compile Include="UnitTests\RemoveAzureAutomationRunbookTest.cs" />
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using Microsoft.Azure.Commands.Automation.Cmdlet;
18+
using Microsoft.Azure.Commands.Automation.Common;
19+
using Microsoft.Azure.Commands.Automation.Model;
20+
using Microsoft.VisualStudio.TestTools.UnitTesting;
21+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
22+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
23+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
24+
using Moq;
25+
26+
namespace Microsoft.Azure.Commands.Automation.Test.UnitTests
27+
{
28+
[TestClass]
29+
public class GetAzureAutomationConnectionTest : TestBase
30+
{
31+
private Mock<IAutomationClient> mockAutomationClient;
32+
33+
private MockCommandRuntime mockCommandRuntime;
34+
35+
private GetAzureAutomationConnection cmdlet;
36+
37+
[TestInitialize]
38+
public void SetupTest()
39+
{
40+
this.mockAutomationClient = new Mock<IAutomationClient>();
41+
this.mockCommandRuntime = new MockCommandRuntime();
42+
this.cmdlet = new GetAzureAutomationConnection
43+
{
44+
AutomationClient = this.mockAutomationClient.Object,
45+
CommandRuntime = this.mockCommandRuntime
46+
};
47+
}
48+
49+
[TestMethod]
50+
public void GetAzureAutomationConnectionByNameSuccessfull()
51+
{
52+
// Setup
53+
string accountName = "automation";
54+
string connectionName = "connection";
55+
56+
this.mockAutomationClient.Setup(f => f.GetConnection(accountName, connectionName));
57+
58+
// Test
59+
this.cmdlet.AutomationAccountName = accountName;
60+
this.cmdlet.Name = connectionName;
61+
this.cmdlet.SetParameterSet("ByConnectionName");
62+
this.cmdlet.ExecuteCmdlet();
63+
64+
// Assert
65+
this.mockAutomationClient.Verify(f => f.GetConnection(accountName, connectionName), Times.Once());
66+
}
67+
68+
[TestMethod]
69+
public void GetAzureAutomationConnectionByAllSuccessfull()
70+
{
71+
// Setup
72+
string accountName = "automation";
73+
74+
this.mockAutomationClient.Setup(f => f.ListConnections(accountName)).Returns((string a) => new List<Connection>());
75+
76+
// Test
77+
this.cmdlet.AutomationAccountName = accountName;
78+
this.cmdlet.ExecuteCmdlet();
79+
80+
// Assert
81+
this.mockAutomationClient.Verify(f => f.ListConnections(accountName), Times.Once());
82+
}
83+
84+
[TestMethod]
85+
public void GetAzureAutomationConnectionByTypeSuccessfull()
86+
{
87+
// Setup
88+
string accountName = "automation";
89+
string connectionTypeName = "connectionType";
90+
91+
this.mockAutomationClient.Setup(f => f.ListConnectionsByType(accountName, connectionTypeName)).Returns((string a, string b) => new List<Connection>());
92+
93+
// Test
94+
this.cmdlet.AutomationAccountName = accountName;
95+
this.cmdlet.ConnectionTypeName = connectionTypeName;
96+
this.cmdlet.SetParameterSet("ByConnectionTypeName");
97+
this.cmdlet.ExecuteCmdlet();
98+
99+
// Assert
100+
this.mockAutomationClient.Verify(f => f.ListConnectionsByType(accountName, connectionTypeName), Times.Once());
101+
}
102+
}
103+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Collections.Generic;
16+
using Microsoft.Azure.Commands.Automation.Cmdlet;
17+
using Microsoft.Azure.Commands.Automation.Common;
18+
using Microsoft.VisualStudio.TestTools.UnitTesting;
19+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
20+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
21+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
22+
using Moq;
23+
using System.Management.Automation;
24+
using System.Security;
25+
using System;
26+
27+
namespace Microsoft.Azure.Commands.Automation.Test.UnitTests
28+
{
29+
[TestClass]
30+
public class NewAzureAutomationConnectionTest : TestBase
31+
{
32+
private Mock<IAutomationClient> mockAutomationClient;
33+
34+
private MockCommandRuntime mockCommandRuntime;
35+
36+
private NewAzureAutomationConnection cmdlet;
37+
38+
[TestInitialize]
39+
public void SetupTest()
40+
{
41+
this.mockAutomationClient = new Mock<IAutomationClient>();
42+
this.mockCommandRuntime = new MockCommandRuntime();
43+
this.cmdlet = new NewAzureAutomationConnection
44+
{
45+
AutomationClient = this.mockAutomationClient.Object,
46+
CommandRuntime = this.mockCommandRuntime
47+
};
48+
}
49+
50+
[TestMethod]
51+
public void NewAzureAutomationConnectionByNameSuccessfull()
52+
{
53+
// Setup
54+
string accountName = "automation";
55+
string connectionName = "connection";
56+
string connectionTypeName = "connectiontype";
57+
string password = "password";
58+
string description = "desc";
59+
60+
this.mockAutomationClient.Setup(
61+
f => f.CreateConnection(accountName, connectionName, connectionTypeName, null, description));
62+
63+
this.cmdlet.AutomationAccountName = accountName;
64+
this.cmdlet.Name = connectionName;
65+
this.cmdlet.Description = description;
66+
this.cmdlet.ConnectionTypeName = connectionTypeName;
67+
this.cmdlet.ConnectionFieldValues = null;
68+
this.cmdlet.ExecuteCmdlet();
69+
70+
// Assert
71+
this.mockAutomationClient.Verify(f => f.CreateConnection(accountName, connectionName, connectionTypeName, null, description), Times.Once());
72+
}
73+
}
74+
}

src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/RemoveAzureAutomationCertificateTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@ public void RemoveAzureAutomationCertificateByNameSuccessfull()
4848
{
4949
// Setup
5050
string accountName = "automation";
51-
string certifiateName = "cert";
51+
string certificateName = "cert";
5252

53-
this.mockAutomationClient.Setup(f => f.DeleteCertificate(accountName, certifiateName));
53+
this.mockAutomationClient.Setup(f => f.DeleteCertificate(accountName, certificateName));
5454

5555
// Test
5656
this.cmdlet.AutomationAccountName = accountName;
57-
this.cmdlet.Name = certifiateName;
57+
this.cmdlet.Name = certificateName;
5858
this.cmdlet.Force = true;
5959
this.cmdlet.ExecuteCmdlet();
6060

6161
// Assert
62-
this.mockAutomationClient.Verify(f => f.DeleteCertificate(accountName, certifiateName), Times.Once());
62+
this.mockAutomationClient.Verify(f => f.DeleteCertificate(accountName, certificateName), Times.Once());
6363
}
6464
}
6565
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using Microsoft.Azure.Commands.Automation.Cmdlet;
17+
using Microsoft.Azure.Commands.Automation.Common;
18+
using Microsoft.VisualStudio.TestTools.UnitTesting;
19+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
20+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
21+
using Moq;
22+
23+
namespace Microsoft.Azure.Commands.Automation.Test.UnitTests
24+
{
25+
[TestClass]
26+
public class RemoveAzureAutomationConnectionTest : TestBase
27+
{
28+
private Mock<IAutomationClient> mockAutomationClient;
29+
30+
private MockCommandRuntime mockCommandRuntime;
31+
32+
private RemoveAzureAutomationConnection cmdlet;
33+
34+
[TestInitialize]
35+
public void SetupTest()
36+
{
37+
this.mockAutomationClient = new Mock<IAutomationClient>();
38+
this.mockCommandRuntime = new MockCommandRuntime();
39+
this.cmdlet = new RemoveAzureAutomationConnection
40+
{
41+
AutomationClient = this.mockAutomationClient.Object,
42+
CommandRuntime = this.mockCommandRuntime
43+
};
44+
}
45+
46+
[TestMethod]
47+
public void RemoveAzureAutomationConnectionByNameSuccessfull()
48+
{
49+
// Setup
50+
string accountName = "automation";
51+
string connectionName = "connection";
52+
53+
this.mockAutomationClient.Setup(f => f.DeleteConnection(accountName, connectionName));
54+
55+
// Test
56+
this.cmdlet.AutomationAccountName = accountName;
57+
this.cmdlet.Name = connectionName;
58+
this.cmdlet.Force = true;
59+
this.cmdlet.ExecuteCmdlet();
60+
61+
// Assert
62+
this.mockAutomationClient.Verify(f => f.DeleteConnection(accountName, connectionName), Times.Once());
63+
}
64+
}
65+
}

src/ServiceManagement/Automation/Commands.Automation/Cmdlet/AzureAutomationBaseCmdlet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public override void ExecuteCmdlet()
8585
}
8686
}
8787

88-
if (cloudException.Response.StatusCode == HttpStatusCode.NoContent)
88+
if (cloudException.Response.StatusCode == HttpStatusCode.NoContent || cloudException.Response.StatusCode == HttpStatusCode.NotFound)
8989
{
9090
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.ResourceNotFound), cloudException);
9191
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using System.Management.Automation;
18+
using System.Security.Permissions;
19+
using Microsoft.Azure.Commands.Automation.Model;
20+
using Microsoft.Azure.Commands.Automation.Common;
21+
22+
namespace Microsoft.Azure.Commands.Automation.Cmdlet
23+
{
24+
/// <summary>
25+
/// Gets a connection for automation.
26+
/// </summary>
27+
[Cmdlet(VerbsCommon.Get, "AzureAutomationConnection", DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)]
28+
[OutputType(typeof(Connection))]
29+
public class GetAzureAutomationConnection : AzureAutomationBaseCmdlet
30+
{
31+
/// <summary>
32+
/// Gets or sets the connection name.
33+
/// </summary>
34+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConnectionName, Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The connection name.")]
35+
[ValidateNotNullOrEmpty]
36+
public string Name { get; set; }
37+
38+
/// <summary>
39+
/// Gets or sets the connection name.
40+
/// </summary>
41+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConnectionTypeName, Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The connection name.")]
42+
[ValidateNotNullOrEmpty]
43+
public string ConnectionTypeName { get; set; }
44+
45+
/// <summary>
46+
/// Execute this cmdlet.
47+
/// </summary>
48+
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
49+
protected override void AutomationExecuteCmdlet()
50+
{
51+
IEnumerable<Connection> ret = null;
52+
if (this.ParameterSetName == AutomationCmdletParameterSets.ByConnectionName)
53+
{
54+
ret = new List<Connection>
55+
{
56+
this.AutomationClient.GetConnection(this.AutomationAccountName, this.Name)
57+
};
58+
}
59+
else if (this.ParameterSetName == AutomationCmdletParameterSets.ByConnectionTypeName)
60+
{
61+
ret = this.AutomationClient.ListConnectionsByType(this.AutomationAccountName, this.ConnectionTypeName);
62+
}
63+
else
64+
{
65+
ret = this.AutomationClient.ListConnections(this.AutomationAccountName);
66+
}
67+
68+
this.GenerateCmdletOutput(ret);
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)