Skip to content

Commit 23dc83f

Browse files
committed
BUG: 3314805 Create Tests for the Powershell Commandlets
1 parent 1a3afd1 commit 23dc83f

14 files changed

+964
-12
lines changed

src/AzurePowershell.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.StreamAnalytics.Te
161161
EndProject
162162
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.Insights", "ResourceManager\Insights\Commands.Insights\Commands.Insights.csproj", "{DEA446A1-84E2-46CC-B780-EB4AFDE2460E}"
163163
EndProject
164+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.Insights.Test", "ResourceManager\Insights\Commands.Insights.Test\Commands.Insights.Test.csproj", "{469F20E0-9D40-41AD-94C3-B47AD15A4C00}"
165+
EndProject
164166
Global
165167
GlobalSection(SolutionConfigurationPlatforms) = preSolution
166168
Debug|Any CPU = Debug|Any CPU
@@ -391,6 +393,10 @@ Global
391393
{DEA446A1-84E2-46CC-B780-EB4AFDE2460E}.Debug|Any CPU.Build.0 = Debug|Any CPU
392394
{DEA446A1-84E2-46CC-B780-EB4AFDE2460E}.Release|Any CPU.ActiveCfg = Release|Any CPU
393395
{DEA446A1-84E2-46CC-B780-EB4AFDE2460E}.Release|Any CPU.Build.0 = Release|Any CPU
396+
{469F20E0-9D40-41AD-94C3-B47AD15A4C00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
397+
{469F20E0-9D40-41AD-94C3-B47AD15A4C00}.Debug|Any CPU.Build.0 = Debug|Any CPU
398+
{469F20E0-9D40-41AD-94C3-B47AD15A4C00}.Release|Any CPU.ActiveCfg = Release|Any CPU
399+
{469F20E0-9D40-41AD-94C3-B47AD15A4C00}.Release|Any CPU.Build.0 = Release|Any CPU
394400
EndGlobalSection
395401
GlobalSection(SolutionProperties) = preSolution
396402
HideSolutionNode = FALSE
@@ -423,5 +429,6 @@ Global
423429
{A415F75B-EB6A-49A6-934E-5BA71B83D6EB} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
424430
{0FA676D5-1349-4086-B33F-65EC2CB7DA41} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
425431
{7E6683BE-ECFF-4709-89EB-1325E9E70512} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
432+
{469F20E0-9D40-41AD-94C3-B47AD15A4C00} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
426433
EndGlobalSection
427434
EndGlobal
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\..\..\packages\xunit.runner.visualstudio.0.99.9-build1021\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\..\packages\xunit.runner.visualstudio.0.99.9-build1021\build\net20\xunit.runner.visualstudio.props')" />
4+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
5+
<PropertyGroup>
6+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8+
<ProjectGuid>{469F20E0-9D40-41AD-94C3-B47AD15A4C00}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>Microsoft.Azure.Commands.Insights.Test</RootNamespace>
12+
<AssemblyName>Microsoft.Azure.Commands.Insights.Test</AssemblyName>
13+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
<TargetFrameworkProfile />
16+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\</SolutionDir>
17+
<RestorePackages>true</RestorePackages>
18+
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
19+
<NuGetPackageImportStamp>944f727b</NuGetPackageImportStamp>
20+
</PropertyGroup>
21+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
22+
<SignAssembly>true</SignAssembly>
23+
<AssemblyOriginatorKeyFile>MSSharedLibKey.snk</AssemblyOriginatorKeyFile>
24+
<DelaySign>true</DelaySign>
25+
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
26+
<Prefer32Bit>false</Prefer32Bit>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
29+
<DebugSymbols>true</DebugSymbols>
30+
<DebugType>full</DebugType>
31+
<Optimize>false</Optimize>
32+
<OutputPath>bin\Debug\</OutputPath>
33+
<DefineConstants>DEBUG;TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
38+
<OutputPath>bin\Release\</OutputPath>
39+
<DefineConstants>TRACE;SIGN</DefineConstants>
40+
<Optimize>true</Optimize>
41+
<DebugType>pdbonly</DebugType>
42+
<PlatformTarget>AnyCPU</PlatformTarget>
43+
<ErrorReport>prompt</ErrorReport>
44+
<RunCodeAnalysis>false</RunCodeAnalysis>
45+
</PropertyGroup>
46+
<ItemGroup>
47+
<Reference Include="Hyak.Common">
48+
<HintPath>..\..\..\packages\Hyak.Common.1.0.1\lib\portable-net403+win+wpa81\Hyak.Common.dll</HintPath>
49+
</Reference>
50+
<Reference Include="Microsoft.Azure.Common">
51+
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.0.1\lib\net45\Microsoft.Azure.Common.dll</HintPath>
52+
</Reference>
53+
<Reference Include="Microsoft.Azure.Common.Extensions, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
54+
<SpecificVersion>False</SpecificVersion>
55+
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Extensions.0.14.0-preview\lib\net45\Microsoft.Azure.Common.Extensions.dll</HintPath>
56+
</Reference>
57+
<Reference Include="Microsoft.Azure.Common.NetFramework">
58+
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.0.1\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
59+
</Reference>
60+
<Reference Include="Microsoft.Azure.Insights">
61+
<HintPath>..\..\..\packages\Microsoft.Azure.Insights.0.7.0-preview\lib\net45\Microsoft.Azure.Insights.dll</HintPath>
62+
</Reference>
63+
<Reference Include="Microsoft.Azure.ResourceManager">
64+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.12.0-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
65+
</Reference>
66+
<Reference Include="Microsoft.Azure.Test.Framework">
67+
<HintPath>..\..\..\packages\Microsoft.Azure.Test.Framework.1.0.5486.28526-prerelease\lib\net45\Microsoft.Azure.Test.Framework.dll</HintPath>
68+
</Reference>
69+
<Reference Include="Microsoft.Azure.Test.HttpRecorder">
70+
<HintPath>..\..\..\packages\Microsoft.Azure.Test.HttpRecorder.1.0.5486.28526-prerelease\lib\net45\Microsoft.Azure.Test.HttpRecorder.dll</HintPath>
71+
</Reference>
72+
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
73+
<SpecificVersion>False</SpecificVersion>
74+
<HintPath>..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.11.10918.1222\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
75+
</Reference>
76+
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms, Version=2.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
77+
<SpecificVersion>False</SpecificVersion>
78+
<HintPath>..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.11.10918.1222\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll</HintPath>
79+
</Reference>
80+
<Reference Include="Microsoft.Threading.Tasks">
81+
<SpecificVersion>False</SpecificVersion>
82+
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
83+
</Reference>
84+
<Reference Include="Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
85+
<SpecificVersion>False</SpecificVersion>
86+
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
87+
</Reference>
88+
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop, Version=1.0.168.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
89+
<SpecificVersion>False</SpecificVersion>
90+
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
91+
</Reference>
92+
<Reference Include="Microsoft.WindowsAzure.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
93+
<SpecificVersion>False</SpecificVersion>
94+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.4.0.1\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
95+
</Reference>
96+
<Reference Include="Microsoft.WindowsAzure.Management.Storage">
97+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Storage.5.0.0\lib\net40\Microsoft.WindowsAzure.Management.Storage.dll</HintPath>
98+
</Reference>
99+
<Reference Include="Microsoft.WindowsAzure.Storage">
100+
<HintPath>..\..\..\packages\WindowsAzure.Storage.4.0.0\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
101+
</Reference>
102+
<Reference Include="Moq, Version=4.2.1402.2112, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
103+
<SpecificVersion>False</SpecificVersion>
104+
<HintPath>..\..\..\packages\Moq.4.2.1402.2112\lib\net40\Moq.dll</HintPath>
105+
</Reference>
106+
<Reference Include="Newtonsoft.Json">
107+
<SpecificVersion>False</SpecificVersion>
108+
<HintPath>..\..\..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
109+
</Reference>
110+
<Reference Include="System" />
111+
<Reference Include="System.Core" />
112+
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
113+
<SpecificVersion>False</SpecificVersion>
114+
<HintPath>C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dll</HintPath>
115+
</Reference>
116+
<Reference Include="System.Net" />
117+
<Reference Include="System.Net.Http" />
118+
<Reference Include="System.Net.Http.Extensions, Version=2.2.28.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
119+
<SpecificVersion>False</SpecificVersion>
120+
<HintPath>..\..\..\packages\Microsoft.Net.Http.2.2.28\lib\net45\System.Net.Http.Extensions.dll</HintPath>
121+
</Reference>
122+
<Reference Include="System.Net.Http.Primitives, Version=4.2.28.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
123+
<SpecificVersion>False</SpecificVersion>
124+
<HintPath>..\..\..\packages\Microsoft.Net.Http.2.2.28\lib\net45\System.Net.Http.Primitives.dll</HintPath>
125+
</Reference>
126+
<Reference Include="System.Net.Http.WebRequest" />
127+
<Reference Include="System.Data.DataSetExtensions" />
128+
<Reference Include="Microsoft.CSharp" />
129+
<Reference Include="System.Data" />
130+
<Reference Include="xunit, Version=1.9.2.1705, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
131+
<SpecificVersion>False</SpecificVersion>
132+
<HintPath>..\..\..\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath>
133+
</Reference>
134+
<Reference Include="xunit.extensions, Version=1.9.2.1705, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
135+
<SpecificVersion>False</SpecificVersion>
136+
<HintPath>..\..\..\packages\xunit.extensions.1.9.2\lib\net20\xunit.extensions.dll</HintPath>
137+
</Reference>
138+
</ItemGroup>
139+
<ItemGroup>
140+
<Compile Include="Events\GetAzureCorrelationIdLogCommandTests.cs" />
141+
<Compile Include="Events\GetAzureResourceLogCommandTests.cs" />
142+
<Compile Include="Events\GetAzureResourceProviderLogCommandTests.cs" />
143+
<Compile Include="Events\GetAzureSubscriptionIdLogCommandTests.cs" />
144+
<Compile Include="Events\Utilities.cs" />
145+
<Compile Include="Events\GetAzureResourceGroupLogCommandTests.cs" />
146+
<Compile Include="Properties\AssemblyInfo.cs" />
147+
</ItemGroup>
148+
<ItemGroup>
149+
<ProjectReference Include="..\..\..\Common\Commands.ScenarioTests.Common\Commands.ScenarioTests.Common.csproj">
150+
<Project>{c1bda476-a5cc-4394-914d-48b0ec31a710}</Project>
151+
<Name>Commands.ScenarioTests.Common</Name>
152+
</ProjectReference>
153+
<ProjectReference Include="..\..\..\Common\Commands.Common.Test\Commands.Common.Test.csproj">
154+
<Project>{3b48a77b-5956-4a62-9081-92ba04b02b27}</Project>
155+
<Name>Commands.Common.Test</Name>
156+
</ProjectReference>
157+
<ProjectReference Include="..\..\..\Common\Commands.Common\Commands.Common.csproj">
158+
<Project>{5ee72c53-1720-4309-b54b-5fb79703195f}</Project>
159+
<Name>Commands.Common</Name>
160+
</ProjectReference>
161+
<ProjectReference Include="..\Commands.Insights\Commands.Insights.csproj">
162+
<Project>{DEA446A1-84E2-46CC-B780-EB4AFDE2460E}</Project>
163+
<Name>Commands.Insights</Name>
164+
</ProjectReference>
165+
</ItemGroup>
166+
<ItemGroup>
167+
<None Include="MSSharedLibKey.snk" />
168+
<None Include="packages.config" />
169+
</ItemGroup>
170+
<ItemGroup>
171+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
172+
</ItemGroup>
173+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
174+
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
175+
<Import Project="..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
176+
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
177+
<Error Condition="!Exists('..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
178+
<Error Condition="Exists('..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
179+
</Target>
180+
<PropertyGroup>
181+
<PostBuildEvent>xcopy "$(SolutionDir)Package\$(ConfigurationName)\*.*" $(TargetDir) /Y /E</PostBuildEvent>
182+
</PropertyGroup>
183+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
184+
<PropertyGroup>
185+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
186+
</PropertyGroup>
187+
<Error Condition="!Exists('..\..\..\packages\xunit.runner.visualstudio.0.99.9-build1021\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\xunit.runner.visualstudio.0.99.9-build1021\build\net20\xunit.runner.visualstudio.props'))" />
188+
</Target>
189+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
190+
Other similar extension points exist, see Microsoft.Common.targets.
191+
<Target Name="BeforeBuild">
192+
</Target>
193+
<Target Name="AfterBuild">
194+
</Target>
195+
-->
196+
</Project>
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 System;
16+
using System.Management.Automation;
17+
using System.Threading;
18+
using System.Threading.Tasks;
19+
using Microsoft.Azure.Insights;
20+
using Microsoft.Azure.Insights.Models;
21+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
22+
using Moq;
23+
using Xunit;
24+
25+
namespace Microsoft.Azure.Commands.Insights.Test.Events
26+
{
27+
public class GetAzureCorrelationIdLogCommandTests
28+
{
29+
private readonly GetAzureCorrelationIdLogCommand cmdlet;
30+
31+
private readonly Mock<InsightsClient> insightsClientMock;
32+
33+
private readonly Mock<IEventOperations> insightsEventOperationsMock;
34+
35+
private Mock<ICommandRuntime> commandRuntimeMock;
36+
37+
private EventDataListResponse response;
38+
39+
private string filter;
40+
private string selected;
41+
42+
public GetAzureCorrelationIdLogCommandTests()
43+
{
44+
insightsEventOperationsMock = new Mock<IEventOperations>();
45+
insightsClientMock = new Mock<InsightsClient>();
46+
commandRuntimeMock = new Mock<ICommandRuntime>();
47+
cmdlet = new GetAzureCorrelationIdLogCommand()
48+
{
49+
CommandRuntime = commandRuntimeMock.Object,
50+
InsightsClient = insightsClientMock.Object
51+
};
52+
53+
response = Utilities.InitializeResponse();
54+
55+
insightsEventOperationsMock.Setup(f => f.ListEventsAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
56+
.Returns(Task.FromResult<EventDataListResponse>(response))
57+
.Callback((string f, string s, CancellationToken t) =>
58+
{
59+
filter = f;
60+
selected = s;
61+
});
62+
63+
insightsClientMock.SetupGet(f => f.EventOperations).Returns(this.insightsEventOperationsMock.Object);
64+
}
65+
66+
[Fact]
67+
[Trait(Category.AcceptanceType, Category.CheckIn)]
68+
public void GetAzureCorrelationIdLogCommandParametersProcessing()
69+
{
70+
var startDate = DateTime.Now.AddSeconds(-1);
71+
72+
// Setting required parameter
73+
cmdlet.CorrelationId = Utilities.Correlation;
74+
75+
Utilities.ExecuteVerifications(
76+
cmdlet: cmdlet,
77+
insinsightsEventOperationsMockightsClientMock: this.insightsEventOperationsMock,
78+
requiredFieldName: "correlationId",
79+
requiredFieldValue: Utilities.Correlation,
80+
filter: ref this.filter,
81+
selected: ref this.selected,
82+
startDate: startDate,
83+
response: response);
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)