Skip to content

Commit 71b6b5f

Browse files
committed
Merge pull request Azure#1680 from BurtBiel/burtbiel/CluTests
Clu test project and updates to clu-getstart.md
2 parents 1b69480 + 077f8d2 commit 71b6b5f

File tree

17 files changed

+313
-77
lines changed

17 files changed

+313
-77
lines changed

clu-getstart.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Work on CLU cmdlets
1+
# Work on CLU cmdlets
22

33
## Prerequsites
44

@@ -25,7 +25,7 @@ CLUPackages require some additional files to direct generation of indexing, and
2525
| ------------- |:-------------:|
2626
| CommandAssemblies | File name of cmdlets assembly(ies) |
2727
| NounPrefix | ‘AzureRm’ The part of the cmdlet noun to remove in clu commands|
28-
| NounFirst | if true, the verb comes at the end of the command (e.g. az resource get)|
28+
| NounFirst | if true, the verb comes at the end of the command (e.g. az resource ls)|
2929

3030
* \<modulename\>.nuspec.template, which contains nuspec format metadata about the package – the base temaplate is in tools\clu\Microsoft.Azure.Commands.nuspec.template. Here are the special fields defined in this template:
3131
* %PackageId% - replace with the module name (Microsoft.Azure.Commands.\<rp-name\>)
@@ -63,16 +63,16 @@ To test on osx/linux boxes, do #1, open `<repo-root>\drop\clurun`, copy the flav
6363
(All of those are subject to change, contact yugangw or adxsdkdev for any questions)
6464

6565
## Quick introductions on cmdlets
66-
* Run commands using the ‘az’ prefix, cmdlet nouns, and cmdlet verbs, for example, `az env get` maps to the cmdlet `Get-AzureRmEnvironment`
67-
* Cmdlet parameters use the double dash (--) so for example, getting a subscription with a particular name would be: `az subscription get –-SubscriptionName “name of subscription"`
66+
* Run commands using the ‘az’ prefix, cmdlet nouns, and cmdlet verbs, for example, `az env ls` maps to the cmdlet `Get-AzureRmEnvironment`
67+
* Cmdlet parameters use the double dash (--) so for example, getting a subscription with a particular name would be: `az subscription ls –-SubscriptionName “name of subscription"`
6868
* To log in, 3 options
69-
* login interactively using device flow, this is the only option for msa account or any org-id with 2fa enforced, example: `az account add`
70-
* login with user and password, this works on org-id w/o 2fa enforced, example: `az account add --Username [email protected] --Password password1`
71-
* login as service principal. Example: `az account add --ServicePrincipal --TenantId <tenant> --ApplicationId <id> --Secret <secret>`
69+
* login interactively using device flow, this is the only option for msa account or any org-id with 2fa enforced, example: `az login`
70+
* login with user and password, this works on org-id w/o 2fa enforced, example: `az login --Username [email protected] --Password password1`
71+
* login as service principal. Example: `az login --ServicePrincipal --TenantId <tenant> --ApplicationId <id> --Secret <secret>`
7272
* Piping between cmdlets should work the same way that Powerhell piping works
73-
```az subscription get --SubscriptionName | az context set```
73+
```az subscription ls --SubscriptionName | az context set```
7474
* You can capture piped output using redirection to a file - the result will be the json serialization of the output object.
75-
```az subscription get > subscriptions.json```
75+
```az subscription ls > subscriptions.json```
7676
* You can use file input to a parameter using '@' notation:
7777
```az command --param1 @file1.json```
7878
Reads input from file1.json and attempts to deserialize the .net object that is the Parameter type for ```param1```

src/CLU/CLUCoreCLR.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Sync", "Sync\Sync.xproj", "
6666
EndProject
6767
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Azure.Commands.Network", "Microsoft.Azure.Commands.Network\Microsoft.Azure.Commands.Network.xproj", "{C4DCF4EA-62E7-431E-ADB5-16FD6CFEA5D6}"
6868
EndProject
69+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU.Test", "Microsoft.CLU.Test\Microsoft.CLU.Test.xproj", "{13C34370-51A4-4726-81B8-BE0996FC9CF0}"
70+
EndProject
6971
Global
7072
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7173
Debug|Any CPU = Debug|Any CPU
@@ -166,6 +168,10 @@ Global
166168
{C4DCF4EA-62E7-431E-ADB5-16FD6CFEA5D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
167169
{C4DCF4EA-62E7-431E-ADB5-16FD6CFEA5D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
168170
{C4DCF4EA-62E7-431E-ADB5-16FD6CFEA5D6}.Release|Any CPU.Build.0 = Release|Any CPU
171+
{13C34370-51A4-4726-81B8-BE0996FC9CF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
172+
{13C34370-51A4-4726-81B8-BE0996FC9CF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
173+
{13C34370-51A4-4726-81B8-BE0996FC9CF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
174+
{13C34370-51A4-4726-81B8-BE0996FC9CF0}.Release|Any CPU.Build.0 = Release|Any CPU
169175
EndGlobalSection
170176
GlobalSection(SolutionProperties) = preSolution
171177
HideSolutionNode = FALSE

src/CLU/Microsoft.CLU.Common/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@
3939
[assembly: InternalsVisibleTo("clurun")]
4040
[assembly: InternalsVisibleTo("Microsoft.CLU")]
4141
[assembly: InternalsVisibleTo("Microsoft.CLU.Run")]
42-
[assembly: InternalsVisibleTo("Microsoft.CLU.Tests")]
42+
[assembly: InternalsVisibleTo("Microsoft.CLU.Test")]
43+
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]

src/CLU/Microsoft.CLU.Run/Properties/AssemblyInfo.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@
3434
// [assembly: AssemblyVersion("1.0.*")]
3535
[assembly: AssemblyVersion("1.0.0.0")]
3636
[assembly: AssemblyFileVersion("1.0.0.0")]
37+
38+
// The friend assemblies of Microsoft.CLU.Run
39+
[assembly: InternalsVisibleTo("Microsoft.CLU.Test")]
40+
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]

src/CLU/Microsoft.CLU.Run/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"System.Runtime.Loader": "4.0.0-beta-23516",
1616
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0-beta-23516",
1717
"System.IO.Compression": "4.1.0-beta-23516",
18-
"NuGet.Commands": "3.3.0-local-*",
18+
"NuGet.Commands": "3.3.0",
1919
"NuGet.Versioning": "3.3.0-local-*",
2020
"Newtonsoft.Json": "7.0.1",
2121

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using Microsoft.Azure.Commands.ScenarioTest;
2+
using Microsoft.CLU.Help;
3+
using Moq;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Threading.Tasks;
8+
using Xunit;
9+
10+
namespace Microsoft.CLU.Test
11+
{
12+
public class HelpTests
13+
{
14+
private readonly Mock<IHelpPackageFinder> helpPackageFinderMock = new Mock<IHelpPackageFinder>();
15+
16+
public HelpTests()
17+
{
18+
this.helpPackageFinderMock
19+
.Setup(m => m.FindPackages())
20+
.Returns(() =>
21+
{
22+
return new List<CommandDispatchHelper.PkgInfo>()
23+
{
24+
new MockPkgInfo("abc", "1.0.0", "abc.ext"),
25+
new MockPkgInfo("abc def", "1.0.0", "abc.def.ext"),
26+
new MockPkgInfo("abc def ghi", "1.0.0", "abc.def.ghi.ext"),
27+
new MockPkgInfo("ddd eee aaa", "1.0.0", "ddd.eee.aaa.ext"),
28+
};
29+
});
30+
}
31+
32+
[Fact]
33+
[Trait(Category.AcceptanceType, Category.CheckIn)]
34+
public void TestHelpStartsWith()
35+
{
36+
var commandInfos = CommandDispatchHelper.CompleteCommands(this.helpPackageFinderMock.Object, new string[] { "a" });
37+
Assert.Equal(3, commandInfos.Count());
38+
Assert.Equal(commandInfos.Count(), commandInfos.Where(c => c.Discriminators.StartsWith("a")).Count());
39+
40+
commandInfos = CommandDispatchHelper.CompleteCommands(this.helpPackageFinderMock.Object, new string[] { "abc" });
41+
Assert.Equal(3, commandInfos.Count());
42+
Assert.Equal(commandInfos.ElementAt(0).Discriminators, "abc");
43+
Assert.Equal(commandInfos.ElementAt(1).Discriminators, "abc def");
44+
Assert.Equal(commandInfos.ElementAt(2).Discriminators, "abc def ghi");
45+
46+
commandInfos = CommandDispatchHelper.CompleteCommands(this.helpPackageFinderMock.Object, new string[] { "dd" });
47+
Assert.Equal(1, commandInfos.Count());
48+
Assert.Equal(commandInfos.Count(), commandInfos.Where(c => c.Discriminators.StartsWith("dd")).Count());
49+
}
50+
51+
[Fact]
52+
[Trait(Category.AcceptanceType, Category.CheckIn)]
53+
public void TestHelpFileSearch()
54+
{
55+
var helpInfo = CommandDispatchHelper.FindBestHelp(this.helpPackageFinderMock.Object, new string[] { "abc" });
56+
Assert.NotNull(helpInfo);
57+
Assert.Equal(helpInfo.Discriminators, "abc");
58+
59+
helpInfo = CommandDispatchHelper.FindBestHelp(this.helpPackageFinderMock.Object, new string[] { "abc", "def" });
60+
Assert.NotNull(helpInfo);
61+
Assert.Equal(helpInfo.Discriminators, "abc;def");
62+
63+
helpInfo = CommandDispatchHelper.FindBestHelp(this.helpPackageFinderMock.Object, new string[] { "abc", "def", "ghi" });
64+
Assert.NotNull(helpInfo);
65+
Assert.Equal(helpInfo.Discriminators, "abc;def;ghi");
66+
}
67+
}
68+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0.24711" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.24711</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
8+
<PropertyGroup Label="Globals">
9+
<ProjectGuid>13c34370-51a4-4726-81b8-be0996fc9cf0</ProjectGuid>
10+
<RootNamespace>Microsoft.CLU.Test</RootNamespace>
11+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
12+
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
13+
</PropertyGroup>
14+
<PropertyGroup>
15+
<SchemaVersion>2.0</SchemaVersion>
16+
</PropertyGroup>
17+
<ItemGroup>
18+
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
19+
</ItemGroup>
20+
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
21+
</Project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.CLU.Help;
6+
7+
namespace Microsoft.CLU.Test
8+
{
9+
internal class MockPkgInfo : Help.CommandDispatchHelper.PkgInfo
10+
{
11+
public MockPkgInfo(string name, string version, string fullPath) : base(name, version, fullPath)
12+
{
13+
14+
}
15+
16+
public override IEnumerable<CommandDispatchHelper.CommandInfo> GetCommands()
17+
{
18+
yield return new CommandDispatchHelper.CommandInfo()
19+
{
20+
Discriminators = Name,
21+
Package = this
22+
};
23+
}
24+
25+
public override IEnumerable<CommandDispatchHelper.HelpInfo> GetHelp()
26+
{
27+
yield return new CommandDispatchHelper.HelpInfo(Path);
28+
}
29+
}
30+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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.Reflection;
16+
using System.Runtime.InteropServices;
17+
18+
// General Information about an assembly is controlled through the following
19+
// set of attributes. Change these attribute values to modify the information
20+
// associated with an assembly.
21+
[assembly: AssemblyTitle("Microsoft.CLU.Test")]
22+
[assembly: AssemblyDescription("")]
23+
[assembly: AssemblyConfiguration("")]
24+
[assembly: AssemblyCompany("")]
25+
[assembly: AssemblyProduct("Microsoft.CLU.Test")]
26+
[assembly: AssemblyCopyright("Copyright © Microsoft")]
27+
[assembly: AssemblyTrademark("")]
28+
[assembly: AssemblyCulture("")]
29+
30+
[assembly: ComVisible(false)]
31+
32+
[assembly: Guid("28fe3fc0-6fdf-4f01-8a82-d7b4a834ddd3")]
33+
34+
[assembly: AssemblyVersion("1.0.0")]
35+
[assembly: AssemblyFileVersion("1.0.0")]

src/CLU/Microsoft.CLU.Test/StringGenerator.cs

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"version": "1.0.0-*",
3+
"description": "Tests for CLU",
4+
"authors": [ "burtbiel" ],
5+
"tags": [ "" ],
6+
"projectUrl": "",
7+
"licenseUrl": "",
8+
"frameworks": {
9+
"dnxcore50": {
10+
"dependencies": {
11+
"Microsoft.NETCore": "5.0.1-beta-23516",
12+
"Microsoft.NETCore.Platforms": "1.0.1-beta-23516",
13+
"Microsoft.CSharp": "4.0.1-beta-23516"
14+
}
15+
}
16+
},
17+
"dependencies": {
18+
"Commands.Common": "",
19+
"Commands.Common.Authentication": "",
20+
"Commands.ResourceManager.Common": "",
21+
"Commands.ResourceManager.Cmdlets": "",
22+
"Commands.ScenarioTests.ResourceManager.Common": "",
23+
"Microsoft.Azure.Commands.Profile": "",
24+
"Microsoft.Azure.Commands.Resources": "",
25+
"Microsoft.Azure.Graph.RBAC": "2.1.1-preview",
26+
"Microsoft.Azure.Management.Authorization": "2.3.0-preview",
27+
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
28+
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
29+
"Microsoft.Rest.ClientRuntime": "1.8.2",
30+
"Microsoft.Rest.ClientRuntime.Azure": "2.5.4",
31+
"Microsoft.Rest.ClientRuntime.Azure.Authentication": "1.2.1-preview",
32+
"Newtonsoft.Json": "7.0.1",
33+
"System.Collections": "4.0.11-beta-23516",
34+
"System.Collections.Concurrent": "4.0.11-beta-23516",
35+
"System.Diagnostics.Tools": "4.0.1-beta-23516",
36+
"System.Diagnostics.TraceSource": "4.0.0-beta-23516",
37+
"System.Diagnostics.Tracing": "4.0.21-beta-23516",
38+
"System.IO": "4.0.11-beta-23516",
39+
"System.IO.FileSystem": "4.0.1-beta-23516",
40+
"System.Net.Http": "4.0.1-beta-23516",
41+
"System.Net.WebHeaderCollection": "4.0.1-beta-23516",
42+
"System.Reflection": "4.1.0-beta-23516",
43+
"System.Reflection.Extensions": "4.0.1-beta-23516",
44+
"System.Reflection.Primitives": "4.0.1-beta-23516",
45+
"System.Reflection.TypeExtensions": "4.1.0-beta-23516",
46+
"System.Runtime": "4.0.21-beta-23516",
47+
"System.Runtime.Extensions": "4.0.11-beta-23516",
48+
"System.Runtime.Serialization.Json": "4.0.1-beta-23516",
49+
"System.Runtime.Serialization.Primitives": "4.1.0-beta-23516",
50+
"System.Runtime.Serialization.Xml": "4.1.0-beta-23516",
51+
"System.Security.Cryptography.Algorithms": "4.0.0-beta-23516",
52+
"System.Security.Cryptography.X509Certificates": "4.0.0-beta-23516",
53+
"System.Text.Encoding": "4.0.11-beta-23516",
54+
"System.Text.Encoding.Extensions": "4.0.11-beta-23516",
55+
"System.Threading": "4.0.11-beta-23516",
56+
"System.Threading.Tasks": "4.0.11-beta-23516",
57+
"System.Threading.Thread": "4.0.0-beta-23516",
58+
"System.Xml.ReaderWriter": "4.0.11-beta-23516",
59+
"xunit": "2.1.0",
60+
"xunit.assert": "2.1.0",
61+
"xunit.runner.dnx": "2.1.0-rc1-build204",
62+
"moq.netcore": "4.4.0-beta8",
63+
"Microsoft.CLU": "1.0.0",
64+
"System.Linq": "4.0.1-beta-23409"
65+
},
66+
"commands": {
67+
"test": "xunit.runner.dnx"
68+
}
69+
}

src/CLU/Microsoft.CLU/CommandBinder/CmdletBinderAndCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ public IEnumerable<string> ListCommands(string[] args)
177177
#if PSCMDLET_HELP
178178
return CmdletHelp.Generate(parser.FormatParameterName, _discriminatorBinder.Modules, args, prefix);
179179
#else
180-
var commands = Microsoft.CLU.Help.CommandDispatchHelper.CompleteCommands(CLUEnvironment.GetPackagesRootPath(), args).ToArray();
180+
var commands = CommandDispatchHelper
181+
.CompleteCommands(new HelpPackageFinder(CLUEnvironment.GetPackagesRootPath()), args).ToArray();
181182
if (commands.Length > 0)
182183
{
183184
foreach (var command in commands)

src/CLU/Microsoft.CLU/CommandLineParser/UnixCommandLineParser.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Diagnostics;
44
using System.Collections.Generic;
55
using Microsoft.CLU.Common.Properties;
6+
using Microsoft.CLU.Help;
67

78
namespace Microsoft.CLU.CommandLineParser
89
{
@@ -185,8 +186,8 @@ public string FormatParameterName(string name, string type, bool isMandatory, bo
185186

186187
private void PresentCommandCompletion(string[] arguments)
187188
{
188-
foreach (var cmd in Help.CommandDispatchHelper.CompleteCommands(CLUEnvironment.GetPackagesRootPath(),
189-
arguments).OrderBy((cmd) => cmd.Commandline))
189+
foreach (var cmd in CommandDispatchHelper.CompleteCommands(new HelpPackageFinder(CLUEnvironment.GetPackagesRootPath()), arguments)
190+
.OrderBy((cmd) => cmd.Commandline))
190191
{
191192
Console.WriteLine(cmd.Commandline);
192193
}
@@ -202,7 +203,7 @@ private void PresentCommandHelp(string[] arguments)
202203
}
203204
else
204205
{
205-
var helpFile = Help.CommandDispatchHelper.FindBestHelp(CLUEnvironment.GetPackagesRootPath(), arguments);
206+
var helpFile = CommandDispatchHelper.FindBestHelp(new HelpPackageFinder(CLUEnvironment.GetPackagesRootPath()), arguments);
206207
if (helpFile != null)
207208
{
208209
// Found appropriate help...

0 commit comments

Comments
 (0)