-
Notifications
You must be signed in to change notification settings - Fork 4k
Tool to generate format.ps1xml #5666
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
Changes from all commits
b7ccd51
b0d52bd
5354e8d
f3714b6
e6ad6cc
3ad32db
3041cca
5723f76
c040da8
72dce06
4c03d97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// 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; | ||
|
||
namespace Microsoft.WindowsAzure.Commands.Common.Attributes | ||
{ | ||
[Flags] | ||
public enum ViewControl | ||
{ | ||
None = 0, | ||
Table, | ||
List, | ||
All = Table | List, | ||
} | ||
|
||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] | ||
public sealed class Ps1XmlAttribute : Attribute | ||
{ | ||
public string Label { get; set; } | ||
|
||
public ViewControl Target { get; set; } = ViewControl.Table; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<config> | ||
<add key="repositorypath" value="..\..\src\packages" /> | ||
</config> | ||
</configuration> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
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("RepoTasks.Attributes")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("HP Inc.")] | ||
[assembly: AssemblyProduct("RepoTasks.Attributes")] | ||
[assembly: AssemblyCopyright("Copyright © HP Inc. 2018")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("8fa4a3ff-cb2c-48d9-9b44-a6e01c75fc2a")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// 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. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
namespace RepoTasks.Cmdlets.Tests | ||
{ | ||
using CmdletsForTest; | ||
using System; | ||
using System.Collections.Generic; | ||
using RemoteWorker; | ||
using Xunit; | ||
using System.IO; | ||
|
||
public class AppDomainWorkerShould : IDisposable | ||
{ | ||
private readonly AppDomain _domain; | ||
private readonly IReflectionWorker _reflectionWorker; | ||
private const string ExpectedAssemblyName = "RepoTasks.CmdletsForTest"; | ||
|
||
// Setup | ||
public AppDomainWorkerShould() | ||
{ | ||
var setup = new AppDomainSetup | ||
{ | ||
ApplicationBase = AppDomain.CurrentDomain.BaseDirectory, | ||
}; | ||
|
||
_domain = AppDomain.CreateDomain("AppDomainIsolation: " + Guid.NewGuid(), null, setup); | ||
var type = typeof(AppDomainWorker); | ||
Assert.NotNull(type.FullName); | ||
|
||
_reflectionWorker = (IReflectionWorker)_domain.CreateInstanceFromAndUnwrap(type.Assembly.Location, type.FullName); | ||
} | ||
|
||
// TearDown | ||
public void Dispose() | ||
{ | ||
if (_domain != null) AppDomain.Unload(_domain); | ||
} | ||
|
||
[Fact] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @markcowl |
||
[Trait(Category.AcceptanceType, Category.CheckIn)] | ||
public void ReturnCmdletTypesAndAssemblyNameWithCmdlets() | ||
{ | ||
var cmdlets = new[] {"Test-Dummy"}; | ||
ReturnCmdletTypesAndAssemblyName(cmdlets); | ||
} | ||
|
||
[Fact] | ||
[Trait(Category.AcceptanceType, Category.CheckIn)] | ||
public void ReturnCmdletTypesAndAssemblyNameWithoutCmdlets() | ||
{ | ||
ReturnCmdletTypesAndAssemblyName(null); | ||
} | ||
|
||
[Fact] | ||
[Trait(Category.AcceptanceType, Category.CheckIn)] | ||
public void ReturnCmdletTypesAndAssemblyNameWithEmptyCmdlets() | ||
{ | ||
var cmdlets = new string[] {}; | ||
ReturnCmdletTypesAndAssemblyName(cmdlets); | ||
} | ||
|
||
[Fact] | ||
[Trait(Category.AcceptanceType, Category.CheckIn)] | ||
public void BuildConfiguration() | ||
{ | ||
var cmdlets = new[] { "Test-Dummy" }; | ||
var types = ReturnCmdletTypesAndAssemblyName(cmdlets); | ||
var conf = new AppDomainWorker().BuildXmlConfiguration(types); | ||
Assert.Equal(4, conf.ViewDefinitions.Views.Length); | ||
|
||
var view0 = conf.ViewDefinitions.Views[0]; | ||
Assert.Equal($"{ExpectedAssemblyName}.Models.PsDummyOutput1", view0?.ViewSelectedBy?.TypeName); | ||
|
||
var expecterProps1 = new[] { "RequestId", "StatusCode", "Id", "Name", "Type" }; | ||
var columnItems = view0?.TableControl?.TableRowEntries[0]?.TableColumnItems; | ||
Assert.NotNull(columnItems); | ||
Assert.Equal(expecterProps1.Length, columnItems.Length); | ||
foreach (var expectedProp in expecterProps1) | ||
{ | ||
Assert.Contains(columnItems, ci => ci.PropertyName == expectedProp); | ||
} | ||
} | ||
|
||
[Fact] | ||
[Trait(Category.AcceptanceType, Category.CheckIn)] | ||
public void DoWorkRemotelyAndReturnFilname() | ||
{ | ||
var assemblyFileName = Path.GetFileName(typeof(TestDummyCommand).Assembly.Location); | ||
var assemblyPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, assemblyFileName); | ||
var cmdlets = new[] { "Test-Dummy" }; | ||
var filename =_reflectionWorker.BuildFormatPs1Xml(assemblyPath, cmdlets, false); | ||
Assert.NotNull(filename); | ||
Assert.Equal($"{ExpectedAssemblyName}.generated.format.ps1xml", filename); | ||
} | ||
|
||
private static IList<Type> ReturnCmdletTypesAndAssemblyName(string[] cmdlets) | ||
{ | ||
var assemblyPath = typeof(TestDummyCommand).Assembly.Location; | ||
string assembyName; | ||
var types = AppDomainWorker.GetCmdletTypes(assemblyPath, cmdlets, out assembyName); | ||
Assert.Equal($"{ExpectedAssemblyName}", assembyName); | ||
Assert.True(types.Count >= 1); | ||
Assert.Contains(types, t => t.FullName == $"{ExpectedAssemblyName}.TestDummyCommand"); | ||
if (cmdlets != null && cmdlets?.Length == 1) | ||
{ | ||
Assert.DoesNotContain(types, t => t.FullName == $"{ExpectedAssemblyName}.TestDummyTwoCommand"); | ||
} | ||
|
||
return types; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace RepoTasks.Cmdlets.Tests | ||
{ | ||
class Category | ||
{ | ||
public const string AcceptanceType = "AcceptanceType"; | ||
public const string CheckIn = "CheckIn"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
@{ | ||
|
||
# Script module or binary module file associated with this manifest. | ||
RootModule = '' | ||
|
||
# Version number of this module. | ||
ModuleVersion = '3.4.0' | ||
|
||
# ID used to uniquely identify this module | ||
GUID = '0a83c907-1ffb-4d87-a492-c65ac7d7ed37' | ||
|
||
# Author of this module | ||
Author = 'Microsoft Corporation' | ||
|
||
# Company or vendor of this module | ||
CompanyName = 'Microsoft Corporation' | ||
|
||
# Copyright statement for this module | ||
Copyright = 'Microsoft Corporation. All rights reserved.' | ||
|
||
# Description of the functionality provided by this module | ||
Description = 'Test' | ||
|
||
# Minimum version of the Windows PowerShell engine required by this module | ||
PowerShellVersion = '3.0' | ||
|
||
# Name of the Windows PowerShell host required by this module | ||
# PowerShellHostName = '' | ||
|
||
# Minimum version of the Windows PowerShell host required by this module | ||
# PowerShellHostVersion = '' | ||
|
||
# Minimum version of Microsoft .NET Framework required by this module | ||
DotNetFrameworkVersion = '4.5.2' | ||
|
||
# Minimum version of the common language runtime (CLR) required by this module | ||
CLRVersion = '4.0' | ||
|
||
# Processor architecture (None, X86, Amd64) required by this module | ||
# ProcessorArchitecture = '' | ||
|
||
# Modules that must be imported into the global environment prior to importing this module | ||
RequiredModules = @() | ||
|
||
# Assemblies that must be loaded prior to importing this module | ||
# RequiredAssemblies = @() | ||
|
||
# Script files (.ps1) that are run in the caller's environment prior to importing this module. | ||
# ScriptsToProcess = @() | ||
|
||
# Type files (.ps1xml) to be loaded when importing this module | ||
#TypesToProcess = 'Dummy.Types.ps1xml' | ||
|
||
# Format files (.ps1xml) to be loaded when importing this module | ||
#FormatsToProcess = '' | ||
|
||
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess | ||
NestedModules = @('.\RepoTasks.CmdletsForTest.dll') | ||
|
||
# Functions to export from this module | ||
# FunctionsToExport = @() | ||
|
||
# Cmdlets to export from this module | ||
CmdletsToExport = '*' | ||
|
||
# Variables to export from this module | ||
# VariablesToExport = @() | ||
|
||
# Aliases to export from this module | ||
AliasesToExport = '' | ||
|
||
# DSC resources to export from this module | ||
# DscResourcesToExport = @() | ||
|
||
# List of all modules packaged with this module | ||
# ModuleList = @() | ||
|
||
# List of all files packaged with this module | ||
# FileList = @() | ||
|
||
# HelpInfo URI of this module | ||
# HelpInfoURI = '' | ||
|
||
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. | ||
# DefaultCommandPrefix = '' | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we only want this one to go in the table view