Skip to content

Clu test project and updates to clu-getstart.md #1680

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 14 commits into from
Jan 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 9 additions & 9 deletions clu-getstart.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Work on CLU cmdlets
# Work on CLU cmdlets

## Prerequsites

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

* \<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:
* %PackageId% - replace with the module name (Microsoft.Azure.Commands.\<rp-name\>)
Expand Down Expand Up @@ -63,16 +63,16 @@ To test on osx/linux boxes, do #1, open `<repo-root>\drop\clurun`, copy the flav
(All of those are subject to change, contact yugangw or adxsdkdev for any questions)

## Quick introductions on cmdlets
* Run commands using the ‘az’ prefix, cmdlet nouns, and cmdlet verbs, for example, `az env get` maps to the cmdlet `Get-AzureRmEnvironment`
* 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"`
* Run commands using the ‘az’ prefix, cmdlet nouns, and cmdlet verbs, for example, `az env ls` maps to the cmdlet `Get-AzureRmEnvironment`
* 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"`
* To log in, 3 options
* login interactively using device flow, this is the only option for msa account or any org-id with 2fa enforced, example: `az account add`
* login with user and password, this works on org-id w/o 2fa enforced, example: `az account add --Username [email protected] --Password password1`
* login as service principal. Example: `az account add --ServicePrincipal --TenantId <tenant> --ApplicationId <id> --Secret <secret>`
* login interactively using device flow, this is the only option for msa account or any org-id with 2fa enforced, example: `az login`
* login with user and password, this works on org-id w/o 2fa enforced, example: `az login --Username [email protected] --Password password1`
* login as service principal. Example: `az login --ServicePrincipal --TenantId <tenant> --ApplicationId <id> --Secret <secret>`
* Piping between cmdlets should work the same way that Powerhell piping works
```az subscription get --SubscriptionName | az context set```
```az subscription ls --SubscriptionName | az context set```
* You can capture piped output using redirection to a file - the result will be the json serialization of the output object.
```az subscription get > subscriptions.json```
```az subscription ls > subscriptions.json```
* You can use file input to a parameter using '@' notation:
```az command --param1 @file1.json```
Reads input from file1.json and attempts to deserialize the .net object that is the Parameter type for ```param1```
Expand Down
6 changes: 6 additions & 0 deletions src/CLU/CLUCoreCLR.sln
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Sync", "Sync\Sync.xproj", "
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Azure.Commands.Network", "Microsoft.Azure.Commands.Network\Microsoft.Azure.Commands.Network.xproj", "{C4DCF4EA-62E7-431E-ADB5-16FD6CFEA5D6}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU.Test", "Microsoft.CLU.Test\Microsoft.CLU.Test.xproj", "{13C34370-51A4-4726-81B8-BE0996FC9CF0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -166,6 +168,10 @@ Global
{C4DCF4EA-62E7-431E-ADB5-16FD6CFEA5D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C4DCF4EA-62E7-431E-ADB5-16FD6CFEA5D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C4DCF4EA-62E7-431E-ADB5-16FD6CFEA5D6}.Release|Any CPU.Build.0 = Release|Any CPU
{13C34370-51A4-4726-81B8-BE0996FC9CF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{13C34370-51A4-4726-81B8-BE0996FC9CF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13C34370-51A4-4726-81B8-BE0996FC9CF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13C34370-51A4-4726-81B8-BE0996FC9CF0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 2 additions & 1 deletion src/CLU/Microsoft.CLU.Common/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@
[assembly: InternalsVisibleTo("clurun")]
[assembly: InternalsVisibleTo("Microsoft.CLU")]
[assembly: InternalsVisibleTo("Microsoft.CLU.Run")]
[assembly: InternalsVisibleTo("Microsoft.CLU.Tests")]
[assembly: InternalsVisibleTo("Microsoft.CLU.Test")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
4 changes: 4 additions & 0 deletions src/CLU/Microsoft.CLU.Run/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

// The friend assemblies of Microsoft.CLU.Run
[assembly: InternalsVisibleTo("Microsoft.CLU.Test")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
2 changes: 1 addition & 1 deletion src/CLU/Microsoft.CLU.Run/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"System.Runtime.Loader": "4.0.0-beta-23516",
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0-beta-23516",
"System.IO.Compression": "4.1.0-beta-23516",
"NuGet.Commands": "3.3.0-local-*",
"NuGet.Commands": "3.3.0",
"NuGet.Versioning": "3.3.0-local-*",
"Newtonsoft.Json": "7.0.1",

Expand Down
68 changes: 68 additions & 0 deletions src/CLU/Microsoft.CLU.Test/HelpTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Microsoft.Azure.Commands.ScenarioTest;
using Microsoft.CLU.Help;
using Moq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace Microsoft.CLU.Test
{
public class HelpTests
{
private readonly Mock<IHelpPackageFinder> helpPackageFinderMock = new Mock<IHelpPackageFinder>();

public HelpTests()
{
this.helpPackageFinderMock
.Setup(m => m.FindPackages())
.Returns(() =>
{
return new List<CommandDispatchHelper.PkgInfo>()
{
new MockPkgInfo("abc", "1.0.0", "abc.ext"),
new MockPkgInfo("abc def", "1.0.0", "abc.def.ext"),
new MockPkgInfo("abc def ghi", "1.0.0", "abc.def.ghi.ext"),
new MockPkgInfo("ddd eee aaa", "1.0.0", "ddd.eee.aaa.ext"),
};
});
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestHelpStartsWith()
{
var commandInfos = CommandDispatchHelper.CompleteCommands(this.helpPackageFinderMock.Object, new string[] { "a" });
Assert.Equal(3, commandInfos.Count());
Assert.Equal(commandInfos.Count(), commandInfos.Where(c => c.Discriminators.StartsWith("a")).Count());

commandInfos = CommandDispatchHelper.CompleteCommands(this.helpPackageFinderMock.Object, new string[] { "abc" });
Assert.Equal(3, commandInfos.Count());
Assert.Equal(commandInfos.ElementAt(0).Discriminators, "abc");
Assert.Equal(commandInfos.ElementAt(1).Discriminators, "abc def");
Assert.Equal(commandInfos.ElementAt(2).Discriminators, "abc def ghi");

commandInfos = CommandDispatchHelper.CompleteCommands(this.helpPackageFinderMock.Object, new string[] { "dd" });
Assert.Equal(1, commandInfos.Count());
Assert.Equal(commandInfos.Count(), commandInfos.Where(c => c.Discriminators.StartsWith("dd")).Count());
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestHelpFileSearch()
{
var helpInfo = CommandDispatchHelper.FindBestHelp(this.helpPackageFinderMock.Object, new string[] { "abc" });
Assert.NotNull(helpInfo);
Assert.Equal(helpInfo.Discriminators, "abc");

helpInfo = CommandDispatchHelper.FindBestHelp(this.helpPackageFinderMock.Object, new string[] { "abc", "def" });
Assert.NotNull(helpInfo);
Assert.Equal(helpInfo.Discriminators, "abc;def");

helpInfo = CommandDispatchHelper.FindBestHelp(this.helpPackageFinderMock.Object, new string[] { "abc", "def", "ghi" });
Assert.NotNull(helpInfo);
Assert.Equal(helpInfo.Discriminators, "abc;def;ghi");
}
}
}
21 changes: 21 additions & 0 deletions src/CLU/Microsoft.CLU.Test/Microsoft.CLU.Test.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.24711" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.24711</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>13c34370-51a4-4726-81b8-be0996fc9cf0</ProjectGuid>
<RootNamespace>Microsoft.CLU.Test</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
30 changes: 30 additions & 0 deletions src/CLU/Microsoft.CLU.Test/MockPkgInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CLU.Help;

namespace Microsoft.CLU.Test
{
internal class MockPkgInfo : Help.CommandDispatchHelper.PkgInfo
{
public MockPkgInfo(string name, string version, string fullPath) : base(name, version, fullPath)
{

}

public override IEnumerable<CommandDispatchHelper.CommandInfo> GetCommands()
{
yield return new CommandDispatchHelper.CommandInfo()
{
Discriminators = Name,
Package = this
};
}

public override IEnumerable<CommandDispatchHelper.HelpInfo> GetHelp()
{
yield return new CommandDispatchHelper.HelpInfo(Path);
}
}
}
35 changes: 35 additions & 0 deletions src/CLU/Microsoft.CLU.Test/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// ----------------------------------------------------------------------------------
//
// 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.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Microsoft.CLU.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Microsoft.CLU.Test")]
[assembly: AssemblyCopyright("Copyright © Microsoft")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: ComVisible(false)]

[assembly: Guid("28fe3fc0-6fdf-4f01-8a82-d7b4a834ddd3")]

[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("1.0.0")]
35 changes: 0 additions & 35 deletions src/CLU/Microsoft.CLU.Test/StringGenerator.cs

This file was deleted.

69 changes: 69 additions & 0 deletions src/CLU/Microsoft.CLU.Test/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"version": "1.0.0-*",
"description": "Tests for CLU",
"authors": [ "burtbiel" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"frameworks": {
"dnxcore50": {
"dependencies": {
"Microsoft.NETCore": "5.0.1-beta-23516",
"Microsoft.NETCore.Platforms": "1.0.1-beta-23516",
"Microsoft.CSharp": "4.0.1-beta-23516"
}
}
},
"dependencies": {
"Commands.Common": "",
"Commands.Common.Authentication": "",
"Commands.ResourceManager.Common": "",
"Commands.ResourceManager.Cmdlets": "",
"Commands.ScenarioTests.ResourceManager.Common": "",
"Microsoft.Azure.Commands.Profile": "",
"Microsoft.Azure.Commands.Resources": "",
"Microsoft.Azure.Graph.RBAC": "2.1.1-preview",
"Microsoft.Azure.Management.Authorization": "2.3.0-preview",
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
"Microsoft.Rest.ClientRuntime": "1.8.2",
"Microsoft.Rest.ClientRuntime.Azure": "2.5.4",
"Microsoft.Rest.ClientRuntime.Azure.Authentication": "1.2.1-preview",
"Newtonsoft.Json": "7.0.1",
"System.Collections": "4.0.11-beta-23516",
"System.Collections.Concurrent": "4.0.11-beta-23516",
"System.Diagnostics.Tools": "4.0.1-beta-23516",
"System.Diagnostics.TraceSource": "4.0.0-beta-23516",
"System.Diagnostics.Tracing": "4.0.21-beta-23516",
"System.IO": "4.0.11-beta-23516",
"System.IO.FileSystem": "4.0.1-beta-23516",
"System.Net.Http": "4.0.1-beta-23516",
"System.Net.WebHeaderCollection": "4.0.1-beta-23516",
"System.Reflection": "4.1.0-beta-23516",
"System.Reflection.Extensions": "4.0.1-beta-23516",
"System.Reflection.Primitives": "4.0.1-beta-23516",
"System.Reflection.TypeExtensions": "4.1.0-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Runtime.Extensions": "4.0.11-beta-23516",
"System.Runtime.Serialization.Json": "4.0.1-beta-23516",
"System.Runtime.Serialization.Primitives": "4.1.0-beta-23516",
"System.Runtime.Serialization.Xml": "4.1.0-beta-23516",
"System.Security.Cryptography.Algorithms": "4.0.0-beta-23516",
"System.Security.Cryptography.X509Certificates": "4.0.0-beta-23516",
"System.Text.Encoding": "4.0.11-beta-23516",
"System.Text.Encoding.Extensions": "4.0.11-beta-23516",
"System.Threading": "4.0.11-beta-23516",
"System.Threading.Tasks": "4.0.11-beta-23516",
"System.Threading.Thread": "4.0.0-beta-23516",
"System.Xml.ReaderWriter": "4.0.11-beta-23516",
"xunit": "2.1.0",
"xunit.assert": "2.1.0",
"xunit.runner.dnx": "2.1.0-rc1-build204",
"moq.netcore": "4.4.0-beta8",
"Microsoft.CLU": "1.0.0",
"System.Linq": "4.0.1-beta-23409"
},
"commands": {
"test": "xunit.runner.dnx"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ public IEnumerable<string> ListCommands(string[] args)
#if PSCMDLET_HELP
return CmdletHelp.Generate(parser.FormatParameterName, _discriminatorBinder.Modules, args, prefix);
#else
var commands = Microsoft.CLU.Help.CommandDispatchHelper.CompleteCommands(CLUEnvironment.GetPackagesRootPath(), args).ToArray();
var commands = CommandDispatchHelper
.CompleteCommands(new HelpPackageFinder(CLUEnvironment.GetPackagesRootPath()), args).ToArray();
if (commands.Length > 0)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factored out the package path into HelpPackageFinder so we can create our own packages in the unit tests

{
foreach (var command in commands)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.Collections.Generic;
using Microsoft.CLU.Common.Properties;
using Microsoft.CLU.Help;

namespace Microsoft.CLU.CommandLineParser
{
Expand Down Expand Up @@ -185,8 +186,8 @@ public string FormatParameterName(string name, string type, bool isMandatory, bo

private void PresentCommandCompletion(string[] arguments)
{
foreach (var cmd in Help.CommandDispatchHelper.CompleteCommands(CLUEnvironment.GetPackagesRootPath(),
arguments).OrderBy((cmd) => cmd.Commandline))
foreach (var cmd in CommandDispatchHelper.CompleteCommands(new HelpPackageFinder(CLUEnvironment.GetPackagesRootPath()), arguments)
.OrderBy((cmd) => cmd.Commandline))
{
Console.WriteLine(cmd.Commandline);
}
Expand All @@ -202,7 +203,7 @@ private void PresentCommandHelp(string[] arguments)
}
else
{
var helpFile = Help.CommandDispatchHelper.FindBestHelp(CLUEnvironment.GetPackagesRootPath(), arguments);
var helpFile = CommandDispatchHelper.FindBestHelp(new HelpPackageFinder(CLUEnvironment.GetPackagesRootPath()), arguments);
if (helpFile != null)
{
// Found appropriate help...
Expand Down
Loading