Skip to content

Commit

Permalink
Added Show-VSTeamPackage (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
DarqueWarrior authored Sep 27, 2020
1 parent cdc2074 commit 8c9094c
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 6 deletions.
63 changes: 63 additions & 0 deletions .docs/Show-VSTeamPackage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!-- #include "./common/header.md" -->

# Show-VSTeamPackage

## SYNOPSIS

<!-- #include "./synopsis/Show-VSTeamPackage.md" -->

## SYNTAX

## DESCRIPTION

<!-- #include "./synopsis/Show-VSTeamPackage.md" -->

## EXAMPLES

### Example 1: From pipeline

```powershell
Get-VSTeamPackage -feedName vsteam -Top 1 -Skip 2 | Show-VSTeamPackage
```

This command will open a web browser with this package showing.

### Example 2: By parameter

```powershell
$p = Get-VSTeamPackage -feedName vsteam -Top 1 -Skip 2
Show-VSTeamPackage $p
```

This command will open a web browser with this package showing.

## PARAMETERS

### Package

Package to show

```yaml
Type: vsteam_lib.Package
Required: True
Position: 0
Accept pipeline input: true (ByPropertyName)
```
## INPUTS
### vsteam_lib.Package
## OUTPUTS
### vsteam_lib.Package
## NOTES
<!-- #include "./common/prerequisites.md" -->
## RELATED LINKS
<!-- #include "./common/related.md" -->
[Add-VSTeamPackage](Add-VSTeamPackage.md)
1 change: 1 addition & 0 deletions .docs/synopsis/Show-VSTeamPackage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Opens the package in the default browser.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Next

Added Get-VSTeamPackage to return packages of a feed.
Added Show-VSTeamPackage to open package in default browser.

## 7.0.1

Expand Down
10 changes: 7 additions & 3 deletions Source/Classes/Provider/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ public class Package : Directory
public object Versions { get; set; }
public Link Links { get; }

public string FeedId { get; }

/// <summary>
/// Used for testing
/// </summary>
public Package(PSObject obj, IPowerShell powerShell) :
public Package(PSObject obj, string feedId, IPowerShell powerShell) :
base(obj, obj.GetValue("name"), "Version", powerShell, null)
{
this.FeedId = feedId;

if (obj.HasValue("_links"))
{
this.Links = new Link(obj);
Expand All @@ -31,8 +35,8 @@ public Package(PSObject obj, IPowerShell powerShell) :
/// Used by PowerShell
/// </summary>
[ExcludeFromCodeCoverage]
public Package(PSObject obj) :
this(obj, new PowerShellWrapper(RunspaceMode.CurrentRunspace))
public Package(PSObject obj, string feedId) :
this(obj, feedId, new PowerShellWrapper(RunspaceMode.CurrentRunspace))
{
}
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Public/Get-VSTeamPackage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ function Get-VSTeamPackage {
-Version $(_getApiVersion packaging)

if ($null -ne $packageId) {
return [vsteam_lib.Package]::new($resp)
return [vsteam_lib.Package]::new($resp, $feedId)
}

$objs = @()

foreach ($item in $resp.value) {
$objs += [vsteam_lib.Package]::new($item, $ProjectName)
$objs += [vsteam_lib.Package]::new($item, $feedId)
}

Write-Output $objs
Expand Down
13 changes: 13 additions & 0 deletions Source/Public/Show-VSTeamPackage.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function Show-VSTeamPackage {
[CmdletBinding(HelpUri='https://methodsandpractices.github.io/vsteam-docs/docs/modules/vsteam/commands/Show-VSTeamPackage')]
param(
[Parameter(Position = 0, Mandatory, ValueFromPipeline)]
[vsteam_lib.Package] $package
)

process {
_hasAccount

Show-Browser "$(_getInstance)/_packaging?_a=package&feedName=$($package.FeedId)&package=$($package.Name)&protocolType=$($package.ProtocolType)&version=$($p.Versions[0].version)"
}
}
1 change: 1 addition & 0 deletions Tests/function/tests/Get-VSTeamPackage.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Describe 'VSTeamPackage' {

## Assert
$actual.count | Should -Be 4
$actual[0].FeedId | Should -Be '00000000-0000-0000-0000-000000000001'

Should -Invoke _callApi -Exactly -Times 1 -Scope It -ParameterFilter {
$Subdomain -eq 'feeds' -and
Expand Down
25 changes: 25 additions & 0 deletions Tests/function/tests/Show-VSTeamPackage.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Set-StrictMode -Version Latest

Describe 'VSTeamPackage' {
BeforeAll {
. "$PSScriptRoot\_testInitialize.ps1" $PSCommandPath

## Arrange
Mock Show-Browser
Mock _getInstance { return 'https://dev.azure.com/test' }
}

Context 'Show-VSTeamPackage' {
It 'by name should call show-browser' {
## Arrange
$p = [vsteam_lib.Package]::new($(Open-SampleFile 'Get-VSTeamPackage.json' -Index 0),
'00000000-0000-0000-0000-000000000001')

## Act
Show-VSTeamPackage $p

## Assert
Should -Invoke Show-Browser
}
}
}
3 changes: 2 additions & 1 deletion Tests/library/Provider/PackageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ public void Package_Constructor()
var obj = BaseTests.LoadJson("Get-VSTeamPackage.json");

// Act
var actual = new Package(obj[2], ps);
var actual = new Package(obj[2], "MyFeed", ps);

// Assert
Assert.AreEqual("VSTeam", actual.Name, "Name");
Assert.AreEqual("MyFeed", actual.FeedId, "FeedId");
Assert.AreEqual("NuGet", actual.ProtocolType, "ProtocolType");
Assert.AreEqual("vsteam", actual.NormalizedName, "NormalizedName");
Assert.AreEqual(Guid.Parse("6c163345-4ec5-0000-84a9-2693e6f066d0"), actual.Id, "Id");
Expand Down

0 comments on commit 8c9094c

Please sign in to comment.