Skip to content

Commit

Permalink
Merge pull request #5 from shipram/dev
Browse files Browse the repository at this point in the history
Webhook changes
  • Loading branch information
safeermohammed committed May 22, 2015
2 parents 053621e + c999ef2 commit f8048be
Show file tree
Hide file tree
Showing 15 changed files with 958 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,13 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UnitTests\GetAzureAutomationWebhookTest.cs" />
<Compile Include="UnitTests\NewAzureAutomationAccountTest.cs" />
<Compile Include="UnitTests\GetAzureAutomationAccountTest.cs" />
<Compile Include="UnitTests\NewAzureAutomationWebhookTest.cs" />
<Compile Include="UnitTests\RemoveAzureAutomationAccountTest.cs" />
<Compile Include="UnitTests\RemoveAzureAutomationWebhookTest.cs" />
<Compile Include="UnitTests\SetAzureAutomationWebhookTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Common\Commands.Common.Test\Commands.Common.Test.csproj">
Expand Down
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());
}
}
}
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());
}
}
}
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());
}
}
}
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());
}
}
}
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));
}
}
}
}
Loading

0 comments on commit f8048be

Please sign in to comment.