Skip to content

Commit f8048be

Browse files
Merge pull request #5 from shipram/dev
Webhook changes
2 parents 053621e + c999ef2 commit f8048be

15 files changed

+958
-1
lines changed

src/ResourceManager/Automation/Commands.Automation.Test/Commands.ResourceManagement.Automation.Test.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,13 @@
111111
</ItemGroup>
112112
<ItemGroup>
113113
<Compile Include="Properties\AssemblyInfo.cs" />
114+
<Compile Include="UnitTests\GetAzureAutomationWebhookTest.cs" />
114115
<Compile Include="UnitTests\NewAzureAutomationAccountTest.cs" />
115116
<Compile Include="UnitTests\GetAzureAutomationAccountTest.cs" />
117+
<Compile Include="UnitTests\NewAzureAutomationWebhookTest.cs" />
116118
<Compile Include="UnitTests\RemoveAzureAutomationAccountTest.cs" />
119+
<Compile Include="UnitTests\RemoveAzureAutomationWebhookTest.cs" />
120+
<Compile Include="UnitTests\SetAzureAutomationWebhookTest.cs" />
117121
</ItemGroup>
118122
<ItemGroup>
119123
<ProjectReference Include="..\..\..\Common\Commands.Common.Test\Commands.Common.Test.csproj">
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 Microsoft.Azure.Commands.Automation.Cmdlet;
16+
using Microsoft.Azure.Commands.Automation.Common;
17+
using Microsoft.VisualStudio.TestTools.UnitTesting;
18+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
19+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
20+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
21+
using Moq;
22+
23+
namespace Microsoft.Azure.Commands.Automation.Test.UnitTests
24+
{
25+
[TestClass]
26+
public class GetAzureAutomationWebhookTest : TestBase
27+
{
28+
private Mock<IAutomationClient> mockAutomationClient;
29+
30+
private MockCommandRuntime mockCommandRuntime;
31+
32+
private GetAzureAutomationWebhook cmdlet;
33+
34+
[TestInitialize]
35+
public void SetupTest()
36+
{
37+
this.mockAutomationClient = new Mock<IAutomationClient>();
38+
this.mockCommandRuntime = new MockCommandRuntime();
39+
this.cmdlet = new GetAzureAutomationWebhook
40+
{
41+
AutomationClient = this.mockAutomationClient.Object,
42+
CommandRuntime = this.mockCommandRuntime
43+
};
44+
}
45+
46+
[TestMethod]
47+
public void GetAzureAutomationWebhookByNameSuccessful()
48+
{
49+
// Setup
50+
string resourceGroupName = "resourceGroup";
51+
string accountName = "account";
52+
string webhookName = "webhookName";
53+
this.cmdlet.SetParameterSet("ByName");
54+
55+
this.mockAutomationClient.Setup(f => f.GetWebhook(resourceGroupName, accountName, webhookName));
56+
57+
// Test
58+
this.cmdlet.ResourceGroupName = resourceGroupName;
59+
this.cmdlet.AutomationAccountName = accountName;
60+
this.cmdlet.Name = webhookName;
61+
this.cmdlet.ExecuteCmdlet();
62+
63+
// Assert
64+
this.mockAutomationClient.Verify(f => f.GetWebhook(resourceGroupName, accountName, webhookName), Times.Once());
65+
}
66+
}
67+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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 Microsoft.Azure.Commands.Automation.Cmdlet;
16+
using Microsoft.Azure.Commands.Automation.Common;
17+
using Microsoft.VisualStudio.TestTools.UnitTesting;
18+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
19+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
20+
using Moq;
21+
using System;
22+
23+
namespace Microsoft.Azure.Commands.Automation.Test.UnitTests
24+
{
25+
[TestClass]
26+
public class NewAzureAutomationWebhookTest : TestBase
27+
{
28+
private Mock<IAutomationClient> mockAutomationClient;
29+
30+
private MockCommandRuntime mockCommandRuntime;
31+
32+
private NewAzureAutomationWebhook cmdlet;
33+
34+
[TestInitialize]
35+
public void SetupTest()
36+
{
37+
this.mockAutomationClient = new Mock<IAutomationClient>();
38+
this.mockCommandRuntime = new MockCommandRuntime();
39+
this.cmdlet = new NewAzureAutomationWebhook
40+
{
41+
AutomationClient = this.mockAutomationClient.Object,
42+
CommandRuntime = this.mockCommandRuntime
43+
};
44+
}
45+
46+
[TestMethod]
47+
public void NewAzureAutomationWebhookByNameSuccessful()
48+
{
49+
// Setup
50+
string resourceGroupName = "resourceGroup";
51+
string accountName = "account";
52+
string name = "webhookName";
53+
string runbookName = "runbookName";
54+
DateTimeOffset expiryTime = DateTimeOffset.Now.AddDays(1);
55+
56+
this.mockAutomationClient.Setup(
57+
f => f.CreateWebhook(resourceGroupName, accountName, name, runbookName, true, expiryTime, null));
58+
59+
// Test
60+
this.cmdlet.ResourceGroupName = resourceGroupName;
61+
this.cmdlet.AutomationAccountName = accountName;
62+
this.cmdlet.Name = name;
63+
this.cmdlet.RunbookName = runbookName;
64+
this.cmdlet.ExpiryTime = expiryTime;
65+
this.cmdlet.IsEnabled = true;
66+
this.cmdlet.Parameters = null;
67+
this.cmdlet.ExecuteCmdlet();
68+
69+
// Assert
70+
this.mockAutomationClient.Verify(
71+
f => f.CreateWebhook(resourceGroupName, accountName, name, runbookName, true, expiryTime, null),
72+
Times.Once());
73+
}
74+
}
75+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 Microsoft.Azure.Commands.Automation.Cmdlet;
16+
using Microsoft.Azure.Commands.Automation.Common;
17+
using Microsoft.VisualStudio.TestTools.UnitTesting;
18+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
19+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
20+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
21+
using Moq;
22+
23+
namespace Microsoft.Azure.Commands.Automation.Test.UnitTests
24+
{
25+
[TestClass]
26+
public class RemoveAzureAutomationWebhookTest : TestBase
27+
{
28+
private Mock<IAutomationClient> mockAutomationClient;
29+
30+
private MockCommandRuntime mockCommandRuntime;
31+
32+
private RemoveAzureAutomationWebhook cmdlet;
33+
34+
[TestInitialize]
35+
public void SetupTest()
36+
{
37+
this.mockAutomationClient = new Mock<IAutomationClient>();
38+
this.mockCommandRuntime = new MockCommandRuntime();
39+
this.cmdlet = new RemoveAzureAutomationWebhook
40+
{
41+
AutomationClient = this.mockAutomationClient.Object,
42+
CommandRuntime = this.mockCommandRuntime
43+
};
44+
}
45+
46+
[TestMethod]
47+
public void RemoveAzureAutomationWebhookByNameSuccessful()
48+
{
49+
// Setup
50+
string resourceGroupName = "resourceGroup";
51+
string accountName = "account";
52+
string webhookName = "webhookName";
53+
this.cmdlet.SetParameterSet("ByName");
54+
55+
this.mockAutomationClient.Setup(f => f.DeleteWebhook(resourceGroupName, accountName, webhookName));
56+
57+
// Test
58+
this.cmdlet.ResourceGroupName = resourceGroupName;
59+
this.cmdlet.AutomationAccountName = accountName;
60+
this.cmdlet.Name = webhookName;
61+
this.cmdlet.ExecuteCmdlet();
62+
63+
// Assert
64+
this.mockAutomationClient.Verify(f => f.DeleteWebhook(resourceGroupName, accountName, webhookName), Times.Once());
65+
}
66+
}
67+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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 Microsoft.Azure.Commands.Automation.Cmdlet;
16+
using Microsoft.Azure.Commands.Automation.Common;
17+
using Microsoft.VisualStudio.TestTools.UnitTesting;
18+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
19+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
20+
using Moq;
21+
22+
namespace Microsoft.Azure.Commands.Automation.Test.UnitTests
23+
{
24+
[TestClass]
25+
public class SetAzureAutomationWebhookTest : TestBase
26+
{
27+
private Mock<IAutomationClient> mockAutomationClient;
28+
29+
private MockCommandRuntime mockCommandRuntime;
30+
31+
private SetAzureAutomationWebhook cmdlet;
32+
33+
[TestInitialize]
34+
public void SetupTest()
35+
{
36+
this.mockAutomationClient = new Mock<IAutomationClient>();
37+
this.mockCommandRuntime = new MockCommandRuntime();
38+
this.cmdlet = new SetAzureAutomationWebhook
39+
{
40+
AutomationClient = this.mockAutomationClient.Object,
41+
CommandRuntime = this.mockCommandRuntime
42+
};
43+
}
44+
45+
[TestMethod]
46+
public void SetAzureAutomationWebhookToDisabledSuccessful()
47+
{
48+
// Setup
49+
string resourceGroupName = "resourceGroup";
50+
string accountName = "account";
51+
string name = "webhookName";
52+
53+
this.mockAutomationClient.Setup(
54+
f => f.UpdateWebhook(resourceGroupName, accountName, name, null, false));
55+
56+
// Test
57+
this.cmdlet.ResourceGroupName = resourceGroupName;
58+
this.cmdlet.AutomationAccountName = accountName;
59+
this.cmdlet.Name = name;
60+
this.cmdlet.IsEnabled = false;
61+
this.cmdlet.Parameters = null;
62+
this.cmdlet.ExecuteCmdlet();
63+
64+
// Assert
65+
this.mockAutomationClient.Verify(
66+
f => f.UpdateWebhook(resourceGroupName, accountName, name, null, false),
67+
Times.Once());
68+
}
69+
}
70+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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 Microsoft.Azure.Commands.Automation.Common;
16+
using Microsoft.Azure.Commands.Automation.Model;
17+
using System.Collections.Generic;
18+
using System.Management.Automation;
19+
using System.Security.Permissions;
20+
21+
namespace Microsoft.Azure.Commands.Automation.Cmdlet
22+
{
23+
/// <summary>
24+
/// Get Webhook for automation.
25+
/// </summary>
26+
[Cmdlet(VerbsCommon.Get, "AzureAutomationWebhook", DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)]
27+
[OutputType(typeof(Webhook))]
28+
public class GetAzureAutomationWebhook : AzureAutomationBaseCmdlet
29+
{
30+
/// <summary>
31+
/// Gets or sets the Webhook name.
32+
/// </summary>
33+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Mandatory = true, ValueFromPipelineByPropertyName = true,
34+
HelpMessage = "The Webhook name.")]
35+
[Alias("WebhookName")]
36+
public string Name { get; set; }
37+
38+
/// <summary>
39+
/// Gets or sets the Webhook name.
40+
/// </summary>
41+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByRunbookName, Mandatory = true, ValueFromPipelineByPropertyName = true,
42+
HelpMessage = "The Runbook name.")]
43+
public string RunbookName { 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<Model.Webhook> webhooks = null;
52+
if (this.ParameterSetName == AutomationCmdletParameterSets.ByAll)
53+
{
54+
var nextLink = string.Empty;
55+
do
56+
{
57+
webhooks = this.AutomationClient.ListWebhooks(this.ResourceGroupName, this.AutomationAccountName, null, ref nextLink);
58+
this.GenerateCmdletOutput(webhooks);
59+
}
60+
while (!string.IsNullOrEmpty(nextLink));
61+
62+
}
63+
else if (this.ParameterSetName == AutomationCmdletParameterSets.ByName)
64+
{
65+
webhooks = new List<Webhook>
66+
{
67+
this.AutomationClient.GetWebhook(
68+
this.ResourceGroupName,
69+
this.AutomationAccountName,
70+
this.Name)
71+
};
72+
this.GenerateCmdletOutput(webhooks);
73+
}
74+
else if (this.ParameterSetName == AutomationCmdletParameterSets.ByRunbookName)
75+
{
76+
var nextLink = string.Empty;
77+
do
78+
{
79+
webhooks = this.AutomationClient.ListWebhooks(this.ResourceGroupName, this.AutomationAccountName, this.RunbookName, ref nextLink);
80+
this.GenerateCmdletOutput(webhooks);
81+
}
82+
while (!string.IsNullOrEmpty(nextLink));
83+
}
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)