Skip to content

Major refactoring: name changes, adding more cmdlets and fixins some bugs #1969

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 21 commits into from
Mar 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d6f5dc4
FW: [Pre-Build] Renaming cmdlets, removing one, and splitting one int…
gucalder Mar 14, 2016
6e9698f
[LogProfiles] Introducing log profiles to powershell
vcanaa Mar 14, 2016
7ecc817
FW: Update the reference to the Insights SDK
gucalder Mar 16, 2016
ef6ba50
[Insights][Shoebox] Add retention commands
vcanaa Mar 17, 2016
c029a9f
FW: Fixing the Add-AzureRmWebtestAlertRule Cmdlet
gucalder Mar 17, 2016
c69ded8
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
gucalder Mar 17, 2016
6640b07
FW: Update help file
gucalder Mar 18, 2016
555ae64
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
gucalder Mar 18, 2016
ae73e19
FW: Fixing incorrect reference to the Insights SDK
gucalder Mar 18, 2016
a5fb2d7
Merge branch 'dev' into retention
vcanaa Mar 18, 2016
999bc61
FW: Updating reference to the Insights SDK in RedisCache for the buil…
gucalder Mar 18, 2016
daa0689
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
gucalder Mar 18, 2016
579f1a4
[Insights] Remove empty logs and metrics from output
vcanaa Mar 18, 2016
f5bb824
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
gucalder Mar 21, 2016
cbeb2ba
FW: Fix Sql scenario test that called Get-Metrics, which is now calle…
gucalder Mar 21, 2016
ea02f47
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
gucalder Mar 21, 2016
7de5e4c
[Insights] CR fixes for logprofiles
vcanaa Mar 22, 2016
714adf0
Merge branch 'dev' of https://github.com/AuxMon/azure-powershell into…
gucalder Mar 22, 2016
a37c220
FW: Completing the help file (missing the help for LogProfile CmdLets)
gucalder Mar 22, 2016
f4b7685
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
gucalder Mar 22, 2016
153f602
Merge branch 'dev' of https://github.com/AuxMon/azure-powershell into…
gucalder Mar 22, 2016
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
1 change: 1 addition & 0 deletions src/Common/Commands.Common/Commands.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="StringExtensions.cs" />
<Compile Include="AzureDataCmdlet.cs" />
<Compile Include="AzurePSCmdlet.cs" />
<Compile Include="AzurePSDataCollectionProfile.cs" />
Expand Down
34 changes: 34 additions & 0 deletions src/Common/Commands.Common/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// ----------------------------------------------------------------------------------
//
// 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 System.Globalization;

namespace Microsoft.WindowsAzure.Commands.Common
{
/// <summary>
/// Extension methods for strings.
/// </summary>
public static class StringExtensions
{
/// <summary>
/// Formats the string with parameters and invariant culture.
/// </summary>
/// <param name="s">The string</param>
/// <param name="args">The arguments</param>
public static string FormatInvariant(this string s, params object[] args)
{
return string.Format(CultureInfo.InvariantCulture, s, args);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
// ----------------------------------------------------------------------------------
//
// 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 System;
using System.Collections.Generic;
using System.Management.Automation;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Commands.Insights.Alerts;
using Microsoft.Azure.Management.Insights;
using Microsoft.Azure.Management.Insights.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Moq;
using Xunit;

namespace Microsoft.Azure.Commands.Insights.Test.Alerts
{
public class AddAzureRmLogAlertRuleTests
{
private readonly AddAzureRmLogAlertRuleCommand cmdlet;
private readonly Mock<InsightsManagementClient> insightsManagementClientMock;
private readonly Mock<IAlertOperations> insightsAlertRuleOperationsMock;
private Mock<ICommandRuntime> commandRuntimeMock;
private AzureOperationResponse response;
private string resourceGroup;
private RuleCreateOrUpdateParameters createOrUpdatePrms;

public AddAzureRmLogAlertRuleTests()
{
insightsAlertRuleOperationsMock = new Mock<IAlertOperations>();
insightsManagementClientMock = new Mock<InsightsManagementClient>();
commandRuntimeMock = new Mock<ICommandRuntime>();
cmdlet = new AddAzureRmLogAlertRuleCommand()
{
CommandRuntime = commandRuntimeMock.Object,
InsightsManagementClient = insightsManagementClientMock.Object
};

response = new AzureOperationResponse()
{
RequestId = Guid.NewGuid().ToString(),
StatusCode = HttpStatusCode.OK,
};

insightsAlertRuleOperationsMock.Setup(f => f.CreateOrUpdateRuleAsync(It.IsAny<string>(), It.IsAny<RuleCreateOrUpdateParameters>(), It.IsAny<CancellationToken>()))
.Returns(Task.FromResult<AzureOperationResponse>(response))
.Callback((string resourceGrp, RuleCreateOrUpdateParameters createOrUpdateParams, CancellationToken t) =>
{
resourceGroup = resourceGrp;
createOrUpdatePrms = createOrUpdateParams;
});

insightsManagementClientMock.SetupGet(f => f.AlertOperations).Returns(this.insightsAlertRuleOperationsMock.Object);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void AddAlertRuleCommandParametersProcessing()
{
// Null actions
cmdlet.Name = Utilities.Name;
cmdlet.Location = "East US";
cmdlet.ResourceGroup = Utilities.ResourceGroup;
cmdlet.TargetResourceId = "/subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/misitiooeltuyo";
cmdlet.Actions = null;

cmdlet.ExecuteCmdlet();

this.AssertResult(
location: "East US",
tagsKey: "hidden-link:/subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/misitiooeltuyo",
isEnabled: true,
actionsNull: true,
actionsCount: 0);

// Null actions and disabled
cmdlet.DisableRule = true;

cmdlet.ExecuteCmdlet();

this.AssertResult(
location: "East US",
tagsKey: "hidden-link:/subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/misitiooeltuyo",
isEnabled: false,
actionsNull: true,
actionsCount: 0);

// Empty actions
cmdlet.DisableRule = false;
cmdlet.Actions = new List<RuleAction>();

cmdlet.ExecuteCmdlet();

this.AssertResult(
location: "East US",
tagsKey: "hidden-link:/subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/misitiooeltuyo",
isEnabled: true,
actionsNull: false,
actionsCount: 0);

// Non-empty actions (one action)
List<string> eMails = new List<string>();
eMails.Add("[email protected]");
RuleAction ruleAction = new RuleEmailAction
{
SendToServiceOwners = true,
CustomEmails = eMails
};

cmdlet.Actions.Add(ruleAction);

cmdlet.ExecuteCmdlet();

this.AssertResult(
location: "East US",
tagsKey: "hidden-link:/subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/misitiooeltuyo",
isEnabled: true,
actionsNull: false,
actionsCount: 1);

// Non-empty actions (two actions)
var properties = new Dictionary<string, string>();
properties.Add("hello", "goodbye");
ruleAction = new RuleWebhookAction
{
ServiceUri = "http://bueno.net",
Properties = properties
};

cmdlet.Actions.Add(ruleAction);

cmdlet.ExecuteCmdlet();

this.AssertResult(
location: "East US",
tagsKey: "hidden-link:/subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/misitiooeltuyo",
isEnabled: true,
actionsNull: false,
actionsCount: 2);
}

private void AssertResult(
string location,
string tagsKey,
bool isEnabled,
bool actionsNull,
int actionsCount
)
{
Assert.Equal(Utilities.ResourceGroup, this.resourceGroup);
Assert.Equal(location, this.createOrUpdatePrms.Location);
Assert.True(this.createOrUpdatePrms.Tags.ContainsKey(tagsKey));

Assert.NotNull(this.createOrUpdatePrms);

if (actionsNull)
{
Assert.Null(this.createOrUpdatePrms.Properties.Actions);
}
else
{
Assert.NotNull(this.createOrUpdatePrms.Properties.Actions);
Assert.Equal(actionsCount, this.createOrUpdatePrms.Properties.Actions.Count);
}

Assert.Equal(Utilities.Name, this.createOrUpdatePrms.Properties.Name);
Assert.Equal(isEnabled, this.createOrUpdatePrms.Properties.IsEnabled);
}
}
}
Loading