-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from shipram/dev
Webhook changes
- Loading branch information
Showing
15 changed files
with
958 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...rceManager/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationWebhookTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// 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.Automation.Cmdlet; | ||
using Microsoft.Azure.Commands.Automation.Common; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks; | ||
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; | ||
using Microsoft.WindowsAzure.Commands.Utilities.Common; | ||
using Moq; | ||
|
||
namespace Microsoft.Azure.Commands.Automation.Test.UnitTests | ||
{ | ||
[TestClass] | ||
public class GetAzureAutomationWebhookTest : TestBase | ||
{ | ||
private Mock<IAutomationClient> mockAutomationClient; | ||
|
||
private MockCommandRuntime mockCommandRuntime; | ||
|
||
private GetAzureAutomationWebhook cmdlet; | ||
|
||
[TestInitialize] | ||
public void SetupTest() | ||
{ | ||
this.mockAutomationClient = new Mock<IAutomationClient>(); | ||
this.mockCommandRuntime = new MockCommandRuntime(); | ||
this.cmdlet = new GetAzureAutomationWebhook | ||
{ | ||
AutomationClient = this.mockAutomationClient.Object, | ||
CommandRuntime = this.mockCommandRuntime | ||
}; | ||
} | ||
|
||
[TestMethod] | ||
public void GetAzureAutomationWebhookByNameSuccessful() | ||
{ | ||
// Setup | ||
string resourceGroupName = "resourceGroup"; | ||
string accountName = "account"; | ||
string webhookName = "webhookName"; | ||
this.cmdlet.SetParameterSet("ByName"); | ||
|
||
this.mockAutomationClient.Setup(f => f.GetWebhook(resourceGroupName, accountName, webhookName)); | ||
|
||
// Test | ||
this.cmdlet.ResourceGroupName = resourceGroupName; | ||
this.cmdlet.AutomationAccountName = accountName; | ||
this.cmdlet.Name = webhookName; | ||
this.cmdlet.ExecuteCmdlet(); | ||
|
||
// Assert | ||
this.mockAutomationClient.Verify(f => f.GetWebhook(resourceGroupName, accountName, webhookName), Times.Once()); | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...rceManager/Automation/Commands.Automation.Test/UnitTests/NewAzureAutomationWebhookTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// 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.Automation.Cmdlet; | ||
using Microsoft.Azure.Commands.Automation.Common; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks; | ||
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; | ||
using Moq; | ||
using System; | ||
|
||
namespace Microsoft.Azure.Commands.Automation.Test.UnitTests | ||
{ | ||
[TestClass] | ||
public class NewAzureAutomationWebhookTest : TestBase | ||
{ | ||
private Mock<IAutomationClient> mockAutomationClient; | ||
|
||
private MockCommandRuntime mockCommandRuntime; | ||
|
||
private NewAzureAutomationWebhook cmdlet; | ||
|
||
[TestInitialize] | ||
public void SetupTest() | ||
{ | ||
this.mockAutomationClient = new Mock<IAutomationClient>(); | ||
this.mockCommandRuntime = new MockCommandRuntime(); | ||
this.cmdlet = new NewAzureAutomationWebhook | ||
{ | ||
AutomationClient = this.mockAutomationClient.Object, | ||
CommandRuntime = this.mockCommandRuntime | ||
}; | ||
} | ||
|
||
[TestMethod] | ||
public void NewAzureAutomationWebhookByNameSuccessful() | ||
{ | ||
// Setup | ||
string resourceGroupName = "resourceGroup"; | ||
string accountName = "account"; | ||
string name = "webhookName"; | ||
string runbookName = "runbookName"; | ||
DateTimeOffset expiryTime = DateTimeOffset.Now.AddDays(1); | ||
|
||
this.mockAutomationClient.Setup( | ||
f => f.CreateWebhook(resourceGroupName, accountName, name, runbookName, true, expiryTime, null)); | ||
|
||
// Test | ||
this.cmdlet.ResourceGroupName = resourceGroupName; | ||
this.cmdlet.AutomationAccountName = accountName; | ||
this.cmdlet.Name = name; | ||
this.cmdlet.RunbookName = runbookName; | ||
this.cmdlet.ExpiryTime = expiryTime; | ||
this.cmdlet.IsEnabled = true; | ||
this.cmdlet.Parameters = null; | ||
this.cmdlet.ExecuteCmdlet(); | ||
|
||
// Assert | ||
this.mockAutomationClient.Verify( | ||
f => f.CreateWebhook(resourceGroupName, accountName, name, runbookName, true, expiryTime, null), | ||
Times.Once()); | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...Manager/Automation/Commands.Automation.Test/UnitTests/RemoveAzureAutomationWebhookTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// 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.Automation.Cmdlet; | ||
using Microsoft.Azure.Commands.Automation.Common; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks; | ||
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; | ||
using Microsoft.WindowsAzure.Commands.Utilities.Common; | ||
using Moq; | ||
|
||
namespace Microsoft.Azure.Commands.Automation.Test.UnitTests | ||
{ | ||
[TestClass] | ||
public class RemoveAzureAutomationWebhookTest : TestBase | ||
{ | ||
private Mock<IAutomationClient> mockAutomationClient; | ||
|
||
private MockCommandRuntime mockCommandRuntime; | ||
|
||
private RemoveAzureAutomationWebhook cmdlet; | ||
|
||
[TestInitialize] | ||
public void SetupTest() | ||
{ | ||
this.mockAutomationClient = new Mock<IAutomationClient>(); | ||
this.mockCommandRuntime = new MockCommandRuntime(); | ||
this.cmdlet = new RemoveAzureAutomationWebhook | ||
{ | ||
AutomationClient = this.mockAutomationClient.Object, | ||
CommandRuntime = this.mockCommandRuntime | ||
}; | ||
} | ||
|
||
[TestMethod] | ||
public void RemoveAzureAutomationWebhookByNameSuccessful() | ||
{ | ||
// Setup | ||
string resourceGroupName = "resourceGroup"; | ||
string accountName = "account"; | ||
string webhookName = "webhookName"; | ||
this.cmdlet.SetParameterSet("ByName"); | ||
|
||
this.mockAutomationClient.Setup(f => f.DeleteWebhook(resourceGroupName, accountName, webhookName)); | ||
|
||
// Test | ||
this.cmdlet.ResourceGroupName = resourceGroupName; | ||
this.cmdlet.AutomationAccountName = accountName; | ||
this.cmdlet.Name = webhookName; | ||
this.cmdlet.ExecuteCmdlet(); | ||
|
||
// Assert | ||
this.mockAutomationClient.Verify(f => f.DeleteWebhook(resourceGroupName, accountName, webhookName), Times.Once()); | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...rceManager/Automation/Commands.Automation.Test/UnitTests/SetAzureAutomationWebhookTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// 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.Automation.Cmdlet; | ||
using Microsoft.Azure.Commands.Automation.Common; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks; | ||
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; | ||
using Moq; | ||
|
||
namespace Microsoft.Azure.Commands.Automation.Test.UnitTests | ||
{ | ||
[TestClass] | ||
public class SetAzureAutomationWebhookTest : TestBase | ||
{ | ||
private Mock<IAutomationClient> mockAutomationClient; | ||
|
||
private MockCommandRuntime mockCommandRuntime; | ||
|
||
private SetAzureAutomationWebhook cmdlet; | ||
|
||
[TestInitialize] | ||
public void SetupTest() | ||
{ | ||
this.mockAutomationClient = new Mock<IAutomationClient>(); | ||
this.mockCommandRuntime = new MockCommandRuntime(); | ||
this.cmdlet = new SetAzureAutomationWebhook | ||
{ | ||
AutomationClient = this.mockAutomationClient.Object, | ||
CommandRuntime = this.mockCommandRuntime | ||
}; | ||
} | ||
|
||
[TestMethod] | ||
public void SetAzureAutomationWebhookToDisabledSuccessful() | ||
{ | ||
// Setup | ||
string resourceGroupName = "resourceGroup"; | ||
string accountName = "account"; | ||
string name = "webhookName"; | ||
|
||
this.mockAutomationClient.Setup( | ||
f => f.UpdateWebhook(resourceGroupName, accountName, name, null, false)); | ||
|
||
// Test | ||
this.cmdlet.ResourceGroupName = resourceGroupName; | ||
this.cmdlet.AutomationAccountName = accountName; | ||
this.cmdlet.Name = name; | ||
this.cmdlet.IsEnabled = false; | ||
this.cmdlet.Parameters = null; | ||
this.cmdlet.ExecuteCmdlet(); | ||
|
||
// Assert | ||
this.mockAutomationClient.Verify( | ||
f => f.UpdateWebhook(resourceGroupName, accountName, name, null, false), | ||
Times.Once()); | ||
} | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationWebhook.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// 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.Automation.Common; | ||
using Microsoft.Azure.Commands.Automation.Model; | ||
using System.Collections.Generic; | ||
using System.Management.Automation; | ||
using System.Security.Permissions; | ||
|
||
namespace Microsoft.Azure.Commands.Automation.Cmdlet | ||
{ | ||
/// <summary> | ||
/// Get Webhook for automation. | ||
/// </summary> | ||
[Cmdlet(VerbsCommon.Get, "AzureAutomationWebhook", DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)] | ||
[OutputType(typeof(Webhook))] | ||
public class GetAzureAutomationWebhook : AzureAutomationBaseCmdlet | ||
{ | ||
/// <summary> | ||
/// Gets or sets the Webhook name. | ||
/// </summary> | ||
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Mandatory = true, ValueFromPipelineByPropertyName = true, | ||
HelpMessage = "The Webhook name.")] | ||
[Alias("WebhookName")] | ||
public string Name { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the Webhook name. | ||
/// </summary> | ||
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByRunbookName, Mandatory = true, ValueFromPipelineByPropertyName = true, | ||
HelpMessage = "The Runbook name.")] | ||
public string RunbookName { get; set; } | ||
|
||
/// <summary> | ||
/// Execute this cmdlet. | ||
/// </summary> | ||
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")] | ||
protected override void AutomationExecuteCmdlet() | ||
{ | ||
IEnumerable<Model.Webhook> webhooks = null; | ||
if (this.ParameterSetName == AutomationCmdletParameterSets.ByAll) | ||
{ | ||
var nextLink = string.Empty; | ||
do | ||
{ | ||
webhooks = this.AutomationClient.ListWebhooks(this.ResourceGroupName, this.AutomationAccountName, null, ref nextLink); | ||
this.GenerateCmdletOutput(webhooks); | ||
} | ||
while (!string.IsNullOrEmpty(nextLink)); | ||
|
||
} | ||
else if (this.ParameterSetName == AutomationCmdletParameterSets.ByName) | ||
{ | ||
webhooks = new List<Webhook> | ||
{ | ||
this.AutomationClient.GetWebhook( | ||
this.ResourceGroupName, | ||
this.AutomationAccountName, | ||
this.Name) | ||
}; | ||
this.GenerateCmdletOutput(webhooks); | ||
} | ||
else if (this.ParameterSetName == AutomationCmdletParameterSets.ByRunbookName) | ||
{ | ||
var nextLink = string.Empty; | ||
do | ||
{ | ||
webhooks = this.AutomationClient.ListWebhooks(this.ResourceGroupName, this.AutomationAccountName, this.RunbookName, ref nextLink); | ||
this.GenerateCmdletOutput(webhooks); | ||
} | ||
while (!string.IsNullOrEmpty(nextLink)); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.