Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding tests for chew/Resolve-Chew

  • Loading branch information...
commit b157fa04f59033217e6feda15e05297bf182ab10 1 parent 91d10ed
@idavis idavis authored
Showing with 148 additions and 14 deletions.
  1. +3 −7 src/functions/Resolve-Chew.ps1
  2. +145 −7 src/tests/Resolve-Chew.Tests.ps1
View
10 src/functions/Resolve-Chew.ps1
@@ -4,11 +4,9 @@ function Resolve-Chew {
param(
[Parameter(Position=0,Mandatory=$true)][string]$name = $null,
[Parameter(Position=1,Mandatory=$false)][alias("v")][string]$version = $null,
- [Parameter(Position=2,Mandatory=$false)][switch]$prerelease,
- [Parameter(Position=3,Mandatory=$false)][alias("group")][string[]]$groups = $null,
- [Parameter(Position=4,Mandatory=$false)][alias("s")][string]$source = $null,
- [Parameter(Position=5,Mandatory=$false)][switch]$continueOnError = $false,
- [Parameter(Position=6,Mandatory=$false)][string]$description = $null
+ [Parameter(Position=2,Mandatory=$false)][alias("group")][string[]]$groups = $null,
+ [Parameter(Position=3,Mandatory=$false)][alias("s")][string]$source = $null,
+ [Parameter(Position=4,Mandatory=$false)][alias("p")][switch]$prerelease = $false
)
if($groups -eq $null) {
$groups = @($chewie.default_group_name)
@@ -23,8 +21,6 @@ function Resolve-Chew {
Version = $version
Prerelease = $prerelease
Groups = $groups
- ContinueOnError = $continueOnError
- Description = $description
Duration = [System.TimeSpan]::Zero
Source = $source
}
View
152 src/tests/Resolve-Chew.Tests.ps1
@@ -1,13 +1,151 @@
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -ireplace ".tests.", "."
-#. "$here\_Common.ps1"
. "$here\..\functions\$sut"
. "$here\..\functions\Assert-Condition.ps1"
+. "$here\..\functions\New-Group.ps1"
+Describe "Ensure-PackagesDefaultsAreResolvedCorrectly" {
+ . "$here\_Common.ps1"
+ chew "ninject"
+ It "should use the package name for the package key" {
+ $chewie.Packages.ContainsKey("ninject").should.be($true)
+ }
+ It "should use the package name for the package name" {
+ $chewie.Packages["ninject"].Name.should.be("ninject")
+ }
+ It "should use a null version if none is specified" {
+ [string]::IsNullOrEmpty($chewie.Packages["ninject"].Version).should.be($true)
+ }
+ It "should use a false prerelease if none is specified" {
+ $chewie.Packages["ninject"].Prerelease.should.be($false)
+ }
+ It "should assign a group if none is specified" {
+ $chewie.Packages["ninject"].Groups.Count.should.be(1)
+ }
+ It "should use a default group if none is specified" {
+ $chewie.Packages["ninject"].Groups[0].should.be("default")
+ }
+ It "should use a 0 timespan" {
+ $chewie.Packages["ninject"].Duration.should.be([TimeSpan]::Zero)
+ }
+ It "should use the default source if none is specified" {
+ [string]::IsNullOrEmpty($chewie.Packages["ninject"].Source).should.be($true)
+ }
+}
-#Describe "Ensure-" {
-# . "$here\_Common.ps1"
-# It "should " {
-# $pwd.should.be("default")
-# }
-#}
+Describe "Ensure-PackagesAreVersionedWhenPassedTheParameter" {
+ It "should use the version when specified normally" {
+ . "$here\_Common.ps1"
+ chew "ninject" "3.2.1"
+ $chewie.Packages["ninject"].Version.should.be("3.2.1")
+ }
+ It "should use the version when passed as a named parameter" {
+ . "$here\_Common.ps1"
+ chew "ninject" -version "3.2.1"
+ $chewie.Packages["ninject"].Version.should.be("3.2.1")
+ }
+ It "should use the version when passed as a named parameter alias" {
+ . "$here\_Common.ps1"
+ chew "ninject" -v "3.2.1"
+ $chewie.Packages["ninject"].Version.should.be("3.2.1")
+ }
+}
+
+Describe "Ensure-PackagesAreSourcedWhenPassedTheParameter" {
+ $value = "http://my.nuget.server.org"
+ It "should use the source when specified normally" {
+ . "$here\_Common.ps1"
+ chew "ninject" "3.2.1" "default" $value
+ $chewie.Packages["ninject"].Source.should.be($value)
+ }
+ It "should use the source when passed as a named parameter" {
+ . "$here\_Common.ps1"
+ chew "ninject" -source $value
+ $chewie.Packages["ninject"].Source.should.be($value)
+ }
+ It "should use the source when passed as a named parameter alias" {
+ . "$here\_Common.ps1"
+ chew "ninject" -s $value
+ $chewie.Packages["ninject"].Source.should.be($value)
+ }
+}
+
+Describe "Ensure-PackagesAreSourcedWhenPassedTheParameter" {
+ $value = "all"
+ It "should use the group when specified normally" {
+ . "$here\_Common.ps1"
+ chew "ninject" "3.2.1" $value
+ $chewie.Packages["ninject"].Groups[0].should.be($value)
+ }
+ It "should use the group when passed normally with a collection of groups" {
+ . "$here\_Common.ps1"
+ chew "ninject" -groups $value,"another"
+ $chewie.Packages["ninject"].Groups[0].should.be($value)
+ }
+ It "should use the second group when specified normally" {
+ . "$here\_Common.ps1"
+ chew "ninject" "3.2.1" $value,"another"
+ $chewie.Packages["ninject"].Groups[1].should.be("another")
+ }
+ It "should use the group when passed as a named parameter" {
+ . "$here\_Common.ps1"
+ chew "ninject" -group $value
+ $chewie.Packages["ninject"].Groups[0].should.be($value)
+ }
+ It "should use the group when passed as a named parameter" {
+ . "$here\_Common.ps1"
+ chew "ninject" -groups $value
+ $chewie.Packages["ninject"].Groups[0].should.be($value)
+ }
+ It "should use the group when passed as a named parameter alias groups" {
+ . "$here\_Common.ps1"
+ chew "ninject" -groups $value,"another"
+ $chewie.Packages["ninject"].Groups[0].should.be($value)
+ }
+ It "should use the second group when passed as a named parameter" {
+ . "$here\_Common.ps1"
+ chew "ninject" -groups $value,"another"
+ $chewie.Packages["ninject"].Groups[1].should.be("another")
+ }
+ It "should use the source when passed as a named parameter alias g" {
+ . "$here\_Common.ps1"
+ chew "ninject" -g $value
+ $chewie.Packages["ninject"].Groups[0].should.be($value)
+ }
+}
+
+
+Describe "Ensure-PackagesAreMarkedToSupportPrereleasesWhenPassedTheParameter" {
+ It "should use the Prerelease when specified normally" {
+ . "$here\_Common.ps1"
+ chew "ninject" "3.2.1" "default" "someUrl" $true
+ $chewie.Packages["ninject"].Prerelease.should.be($true)
+ }
+ It "should use the Prerelease when passed as a named parameter" {
+ . "$here\_Common.ps1"
+ chew "ninject" -prerelease
+ $chewie.Packages["ninject"].Prerelease.should.be($true)
+ }
+ It "should use the Prerelease when passed as a named parameter alias" {
+ . "$here\_Common.ps1"
+ chew "ninject" -p
+ $chewie.Packages["ninject"].Prerelease.should.be($true)
+ }
+}
+
+Describe "Ensure-PackagesCanOnlyBeSpecifiedOnce" {
+ It "should throw when chewed twice" {
+ . "$here\_Common.ps1"
+ chew "ninject"
+ $error = $null
+ try{chew "ninject"}catch{$error = $_}
+ ($error -eq $null).should.be($false)
+ }
+ It "should throw when chewed and grouped" {
+ . "$here\_Common.ps1"
+ New-Group "foo" { chew "ninject" }
+ $error = $null
+ try{chew "ninject"}catch{$error = $_}
+ ($error -eq $null).should.be($false)
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.