Skip to content

Commit e0d279c

Browse files
committed
Merge pull request #174 from Azure/dev
.
2 parents 62ce2eb + dd85df9 commit e0d279c

File tree

77 files changed

+3690
-952
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+3690
-952
lines changed

src/Common/Commands.Common/Commands.Common.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
<Compile Include="TestMockSupport.cs" />
174174
<Compile Include="PSAzureAccount.cs" />
175175
<Compile Include="Properties\AssemblyInfo.cs" />
176+
<Compile Include="ValidateGuidNotEmpty.cs" />
176177
</ItemGroup>
177178
<ItemGroup>
178179
<EmbeddedResource Include="Properties\Resources.resx">
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Management.Automation;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Microsoft.WindowsAzure.Commands.Common
9+
{
10+
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
11+
public class ValidateGuidNotEmptyAttribute : ValidateArgumentsAttribute
12+
{
13+
protected override void Validate(object arguments, EngineIntrinsics engineIntrinsics)
14+
{
15+
if (arguments == null)
16+
{
17+
throw new ValidationMetadataException("Specify a parameter of type 'System.Guid' and try again.");
18+
}
19+
20+
Guid param = (Guid)arguments;
21+
if (param == Guid.Empty)
22+
{
23+
throw new ValidationMetadataException("Specify a non empty value of type 'System.Guid' and try again.");
24+
}
25+
}
26+
}
27+
}

src/ResourceManager/Insights/AzureRM.Insights.psd1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ ScriptsToProcess = @()
5757
TypesToProcess = @()
5858

5959
# Format files (.ps1xml) to be loaded when importing this module
60-
FormatsToProcess = @()
60+
FormatsToProcess = @(
61+
'.\Microsoft.Azure.Commands.Insights.format.ps1xml'
62+
)
6163

6264
# Modules to import as nested modules of the module specified in ModuleToProcess
6365
NestedModules = @(

src/ResourceManager/Insights/Commands.Insights.Test/Commands.Insights.Test.csproj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
5959
</Reference>
6060
<Reference Include="Microsoft.Azure.Insights">
61-
<HintPath>..\..\..\packages\Microsoft.Azure.Insights.0.7.7-preview\lib\net45\Microsoft.Azure.Insights.dll</HintPath>
61+
<HintPath>..\..\..\packages\Microsoft.Azure.Insights.0.9.1-preview\lib\net45\Microsoft.Azure.Insights.dll</HintPath>
6262
</Reference>
6363
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6464
<SpecificVersion>False</SpecificVersion>
@@ -150,11 +150,14 @@
150150
<Compile Include="Autoscale\NewAutoscaleProfileCommandTests.cs" />
151151
<Compile Include="Autoscale\NewAutoscaleRuleCommandTests.cs" />
152152
<Compile Include="Autoscale\RemoveAutoscaleSettingCommandTests.cs" />
153+
<Compile Include="Diagnostics\SetDiagnosticSettingCommandTests.cs" />
154+
<Compile Include="Diagnostics\GetDiagnosticSettingCommandTests.cs" />
153155
<Compile Include="Events\GetAzureRmLogCommandTests.cs" />
154156
<Compile Include="Metrics\FormatMetricsAsTableCommandTests.cs" />
155157
<Compile Include="Metrics\GetMetricDefinitionsCommandTests.cs" />
156158
<Compile Include="Metrics\GetMetricsCommandTests.cs" />
157159
<Compile Include="Properties\AssemblyInfo.cs" />
160+
<Compile Include="ScenarioTests\AzureRmDiagnosticSettingTests.cs" />
158161
<Compile Include="ScenarioTests\AlertsTests.cs" />
159162
<Compile Include="ScenarioTests\AutoscaleTests.cs" />
160163
<Compile Include="ScenarioTests\EventsTests.cs" />
@@ -185,6 +188,9 @@
185188
<ItemGroup>
186189
<None Include="MSSharedLibKey.snk" />
187190
<None Include="packages.config" />
191+
<None Include="ScenarioTests\AzureRmDiagnosticSettingTests.ps1">
192+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
193+
</None>
188194
<None Include="ScenarioTests\AlertsTests.ps1">
189195
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
190196
</None>
@@ -203,6 +209,12 @@
203209
<None Include="ScenarioTests\UsageMetricsTests.ps1">
204210
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
205211
</None>
212+
<None Include="SessionRecords\Microsoft.Azure.Commands.Insights.Test.ScenarioTests.AzureRmDiagnosticSettingTests\TestSetAzureRmDiagnosticSetting.json">
213+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
214+
</None>
215+
<None Include="SessionRecords\Microsoft.Azure.Commands.Insights.Test.ScenarioTests.AzureRmDiagnosticSettingTests\TestGetAzureRmDiagnosticSetting.json">
216+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
217+
</None>
206218
<None Include="SessionRecords\Microsoft.Azure.Commands.Insights.Test.ScenarioTests.AlertsTests\TestAddAlertRule.json">
207219
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
208220
</None>
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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.Net;
19+
using System.Threading;
20+
using System.Threading.Tasks;
21+
using Microsoft.Azure.Commands.Insights.Alerts;
22+
using Microsoft.Azure.Commands.Insights.Diagnostics;
23+
using Microsoft.Azure.Management.Insights;
24+
using Microsoft.Azure.Management.Insights.Models;
25+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
26+
using Moq;
27+
using Xunit;
28+
29+
namespace Microsoft.Azure.Commands.Insights.Test.Diagnostics
30+
{
31+
public class GetDiagnosticSettingCommandTests
32+
{
33+
private readonly GetAzureRmDiagnosticSettingCommand cmdlet;
34+
private readonly Mock<InsightsManagementClient> insightsManagementClientMock;
35+
private readonly Mock<IServiceDiagnosticSettingsOperations> insightsDiagnosticsOperationsMock;
36+
private Mock<ICommandRuntime> commandRuntimeMock;
37+
private ServiceDiagnosticSettingsGetResponse response;
38+
private RuleCreateOrUpdateParameters createOrUpdatePrms;
39+
private const string resourceId = "/subscriptions/123/resourcegroups/rg/providers/rp/resource/myresource";
40+
private string calledResourceId;
41+
42+
public GetDiagnosticSettingCommandTests()
43+
{
44+
insightsDiagnosticsOperationsMock = new Mock<IServiceDiagnosticSettingsOperations>();
45+
insightsManagementClientMock = new Mock<InsightsManagementClient>();
46+
commandRuntimeMock = new Mock<ICommandRuntime>();
47+
cmdlet = new GetAzureRmDiagnosticSettingCommand()
48+
{
49+
CommandRuntime = commandRuntimeMock.Object,
50+
InsightsManagementClient = insightsManagementClientMock.Object
51+
};
52+
53+
response = new ServiceDiagnosticSettingsGetResponse
54+
{
55+
RequestId = Guid.NewGuid().ToString(),
56+
StatusCode = HttpStatusCode.OK,
57+
Properties = new ServiceDiagnosticSettings
58+
{
59+
StorageAccountId = "/subscriptions/123/resourcegroups/rg/providers/microsoft.storage/accounts/myaccount",
60+
Logs = new List<LogSettings>
61+
{
62+
new LogSettings
63+
{
64+
Category = "TestCategory1",
65+
Enabled = true
66+
},
67+
new LogSettings
68+
{
69+
Category = "TestCategory2",
70+
Enabled = false
71+
}
72+
},
73+
Metrics = new List<MetricSettings>
74+
{
75+
new MetricSettings
76+
{
77+
TimeGrain = TimeSpan.FromMinutes(1),
78+
Enabled = false
79+
},
80+
new MetricSettings
81+
{
82+
TimeGrain = TimeSpan.FromHours(1)
83+
}
84+
}
85+
}
86+
};
87+
88+
insightsDiagnosticsOperationsMock.Setup(f => f.GetAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()))
89+
.Returns(Task.FromResult<ServiceDiagnosticSettingsGetResponse>(response))
90+
.Callback((string resourceId, CancellationToken cancellationToken) =>
91+
{
92+
this.calledResourceId = resourceId;
93+
});
94+
95+
insightsManagementClientMock.SetupGet(f => f.ServiceDiagnosticSettingsOperations).Returns(this.insightsDiagnosticsOperationsMock.Object);
96+
}
97+
98+
[Fact]
99+
[Trait(Category.AcceptanceType, Category.CheckIn)]
100+
public void AddAlertRuleCommandParametersProcessing()
101+
{
102+
cmdlet.ResourceId = resourceId;
103+
cmdlet.ExecuteCmdlet();
104+
105+
Assert.Equal(resourceId, calledResourceId);
106+
}
107+
}
108+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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.Linq;
18+
using System.Management.Automation;
19+
using System.Net;
20+
using System.Threading;
21+
using System.Threading.Tasks;
22+
using Microsoft.Azure.Commands.Insights.Alerts;
23+
using Microsoft.Azure.Commands.Insights.Diagnostics;
24+
using Microsoft.Azure.Management.Insights;
25+
using Microsoft.Azure.Management.Insights.Models;
26+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
27+
using Moq;
28+
using Xunit;
29+
30+
namespace Microsoft.Azure.Commands.Insights.Test.Diagnostics
31+
{
32+
public class SetDiagnosticSettingCommandTests
33+
{
34+
private readonly SetAzureRmDiagnosticSettingCommand cmdlet;
35+
private readonly Mock<InsightsManagementClient> insightsManagementClientMock;
36+
private readonly Mock<IServiceDiagnosticSettingsOperations> insightsDiagnosticsOperationsMock;
37+
private Mock<ICommandRuntime> commandRuntimeMock;
38+
private ServiceDiagnosticSettingsGetResponse response;
39+
private RuleCreateOrUpdateParameters createOrUpdatePrms;
40+
private const string resourceId = "/subscriptions/123/resourcegroups/rg/providers/rp/resource/myresource";
41+
private const string storageAccountId = "/subscriptions/123/resourcegroups/rg/providers/microsoft.storage/accounts/myaccount";
42+
private string calledResourceId;
43+
ServiceDiagnosticSettingsPutParameters calledPutParameters;
44+
45+
public SetDiagnosticSettingCommandTests()
46+
{
47+
insightsDiagnosticsOperationsMock = new Mock<IServiceDiagnosticSettingsOperations>();
48+
insightsManagementClientMock = new Mock<InsightsManagementClient>();
49+
commandRuntimeMock = new Mock<ICommandRuntime>();
50+
cmdlet = new SetAzureRmDiagnosticSettingCommand()
51+
{
52+
CommandRuntime = commandRuntimeMock.Object,
53+
InsightsManagementClient = insightsManagementClientMock.Object
54+
};
55+
56+
response = new ServiceDiagnosticSettingsGetResponse
57+
{
58+
RequestId = Guid.NewGuid().ToString(),
59+
StatusCode = HttpStatusCode.OK,
60+
Properties = new ServiceDiagnosticSettings
61+
{
62+
StorageAccountId = storageAccountId,
63+
Logs = new List<LogSettings>
64+
{
65+
new LogSettings
66+
{
67+
Category = "TestCategory1",
68+
Enabled = true
69+
},
70+
new LogSettings
71+
{
72+
Category = "TestCategory2",
73+
Enabled = false
74+
}
75+
},
76+
Metrics = new List<MetricSettings>
77+
{
78+
new MetricSettings
79+
{
80+
TimeGrain = TimeSpan.FromMinutes(1),
81+
Enabled = false
82+
},
83+
new MetricSettings
84+
{
85+
TimeGrain = TimeSpan.FromHours(1),
86+
Enabled = true
87+
}
88+
}
89+
}
90+
};
91+
92+
insightsDiagnosticsOperationsMock.Setup(f => f.GetAsync(It.IsAny<string>()))
93+
.Returns(Task.FromResult<ServiceDiagnosticSettingsGetResponse>(response))
94+
.Callback((string resourceId) =>
95+
{
96+
this.calledResourceId = resourceId;
97+
});
98+
99+
insightsDiagnosticsOperationsMock.Setup(f => f.PutAsync(It.IsAny<string>(), It.IsAny<ServiceDiagnosticSettingsPutParameters>()))
100+
.Returns(Task.FromResult<EmptyResponse>(new EmptyResponse()))
101+
.Callback((string resourceId, ServiceDiagnosticSettingsPutParameters putParameters) =>
102+
{
103+
this.calledResourceId = resourceId;
104+
this.calledPutParameters = putParameters;
105+
});
106+
107+
insightsManagementClientMock.SetupGet(f => f.ServiceDiagnosticSettingsOperations).Returns(this.insightsDiagnosticsOperationsMock.Object);
108+
}
109+
}
110+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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.WindowsAzure.Commands.ScenarioTest;
16+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
17+
using Xunit;
18+
19+
namespace Microsoft.Azure.Commands.Insights.Test.ScenarioTests
20+
{
21+
public class AzureRmDiagnosticSettingTests : RMTestBase
22+
{
23+
[Fact]
24+
[Trait(Category.AcceptanceType, Category.CheckIn)]
25+
public void TestGetAzureRmDiagnosticSetting()
26+
{
27+
TestsController.NewInstance.RunPsTest("Test-GetAzureRmDiagnosticSetting");
28+
}
29+
30+
[Fact]
31+
[Trait(Category.AcceptanceType, Category.CheckIn)]
32+
public void TestSetAzureRmDiagnosticSetting()
33+
{
34+
TestsController.NewInstance.RunPsTest("Test-SetAzureRmDiagnosticSetting");
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)