Skip to content

Commit

Permalink
Add functional tests for project K
Browse files Browse the repository at this point in the history
  • Loading branch information
danliu authored and Dan Liu committed Oct 19, 2015
1 parent cb7dcc2 commit 8dde352
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 5 deletions.
1 change: 1 addition & 0 deletions NuGet.Clients.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{83AEE32C
test\EndToEnd\tests\OpenPackagePageTest.ps1 = test\EndToEnd\tests\OpenPackagePageTest.ps1
test\EndToEnd\tests\PackageRestoreTest.ps1 = test\EndToEnd\tests\PackageRestoreTest.ps1
test\EndToEnd\tests\PackTest.ps1 = test\EndToEnd\tests\PackTest.ps1
test\EndToEnd\tests\ProjectKTest.ps1 = test\EndToEnd\tests\ProjectKTest.ps1
test\EndToEnd\tests\ProjectRetargeting.ps1 = test\EndToEnd\tests\ProjectRetargeting.ps1
test\EndToEnd\tests\ServicesTest.ps1 = test\EndToEnd\tests\ServicesTest.ps1
test\EndToEnd\tests\Settings.ps1 = test\EndToEnd\tests\Settings.ps1
Expand Down
41 changes: 41 additions & 0 deletions test/EndToEnd/nuget.assert.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,47 @@ function Assert-ProjectJsonDependency {
Assert-True $found "Package $Id $Range is not referenced in $($Project.Name)"
}

function Assert-ProjectJsonDependencyWithinTargetFramework {
param(
[parameter(Mandatory = $true)]
$Project,
[parameter(Mandatory = $true)]
[string]$Id,
[string]$Range
)

$projectJson = Get-ProjectJsonPackageSpec $Project

Assert-NotNull $projectJson

$found = $false

foreach ($targetFrameworkInfo in $projectJson.TargetFrameworks) {

foreach ($dependency in $targetFrameworkInfo.Dependencies) {

$library = $dependency.LibraryRange

if ($library.Name.ToUpperInvariant().Equals($Id.ToUpperInvariant()))
{
if ($Range)
{
if ($library.VersionRange.OriginalString.ToUpperInvariant().Equals($Range.ToUpperInvariant()))
{
$found = $true
}
}
else
{
$found = $true
}
}
}
}

Assert-True $found "Package $Id $Range is not referenced in $($Project.Name)"
}

function Assert-ProjectJsonDependencyNotFound {
param(
[parameter(Mandatory = $true)]
Expand Down
164 changes: 164 additions & 0 deletions test/EndToEnd/tests/ProjectKTest.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Basic install into project K project
function Test-ProjectKInstallPackage {
# Arrange
$project = New-DNXClassLibrary

# Act
Install-Package jQuery -ProjectName $project.Name -version 2.1.4

# Assert
Assert-ProjectJsonDependency $project jQuery 2.1.4
}

# Basic uninstall
function Test-ProjectKUninstallPackage {
# Arrange
$project = New-DNXConsoleApp
Install-Package EntityFramework -ProjectName $project.Name -version 6.1.3

# Act
Uninstall-Package EntityFramework

# Assert
Assert-ProjectJsonDependencyNotFound $project EntityFramework
}

# Basic update
function Test-ProjectKUpdatePackage {
# Arrange
$project = New-DNXConsoleApp
Install-Package log4net -ProjectName $project.Name -version 2.0.1

# Act
Update-Package log4net

# Assert
Assert-ProjectJsonDependencyWithinTargetFramework $project log4net 2.0.3
}

# Install multiple packages
function Test-ProjectKInstallMultiplePackages {
# Arrange
$project = New-DNXClassLibrary

# Act
Install-Package newtonsoft.json -ProjectName $project.Name -version 7.0.1
Install-Package jQuery.Validation -version 1.14.0 -DependencyVersion HighestMinor

# Assert
Assert-ProjectJsonDependency $project newtonsoft.json 7.0.1
Assert-ProjectJsonDependency $project jQuery.Validation 1.14.0
Assert-ProjectJsonDependencyNotFound $project jQuery
}

# Uninstall multiple packages
function Test-ProjectKUninstallMultiplePackages {
# Arrange
$project = New-DNXClassLibrary

# Act
Install-Package Microsoft.Dnx.TestHost -ProjectName $project.Name -pre
Install-Package Knockoutjs -ProjectName $project.Name
Install-Package TestPackage.OnlyDNXCore -ProjectName $project.Name
Uninstall-Package Microsoft.Dnx.TestHost -RemoveDependencies
UnInstall-Package TestPackage.OnlyDNXCore

# Assert
Assert-ProjectJsonDependencyNotFound $project Microsoft.Dnx.TestHost
Assert-ProjectJsonDependencyNotFound $project TestPackage.OnlyDNXCore
Assert-ProjectJsonDependency $project Knockoutjs
}

# Update to prerelease MVC packages that contains DNXCore50 dependencies
function Test-ProjectKUpdateMVCPackagePrerelease {
# Arrange
$project = New-DNXConsoleApp
Install-Package Microsoft.AspNet.Mvc -ProjectName $project.Name -version 5.2.2

# Act
Update-Package Microsoft.AspNet.Mvc -version 6.0.0-beta7

# Assert
Assert-ProjectJsonDependency $project Microsoft.AspNet.Mvc 6.0.0-beta7
}

# Update all packages
function Test-ProjectKUpdateAllPackages {
# Arrange
$project = New-DNXConsoleApp
Install-Package TestPackage.danliutestpackage -ProjectName $project.Name -version 6.0.0

# Act
Update-Package

# Assert
Assert-ProjectJsonDependency $project TestPackage.danliutestpackage 7.0.0
}

# No package update available. Latest version already installed.
function Test-ProjectKUpdatePackageNoUpdateAvailable {
# Arrange
$project = New-DNXConsoleApp

# Act
Install-Package TestPackage.JustContent -version 1.0.0
Update-Package TestPackage.JustContent

#Assert
Assert-ProjectJsonDependencyWithinTargetFramework $project TestPackage.JustContent 1.0.0
}

# Update-Package -reinstall
function Test-ProjectKUpdatePackageReinstall {
# Arrange
$project = New-DNXClassLibrary
Install-Package Microsoft.AspNet.Mvc -ProjectName $project.Name -version 5.2.3

# Act
Update-Package Microsoft.AspNet.Mvc -reinstall

# Assert
Assert-ProjectJsonDependency $project Microsoft.AspNet.Mvc 5.2.3
}

# Test whatIf for package actions
function Test-ProjectKPackageActionsWhatIf {
# Arrange
$project = New-DNXConsoleApp

# Act
Install-Package jQuery -version 2.0.1 -WhatIf
Install-Package jQuery -version 2.0.3
Uninstall-Package jQuery -WhatIf
Update-Package jQuery -WhatIf

# Assert
Assert-ProjectJsonDependency $project jQuery 2.0.3
}

function Test-ProjectKInstallNonExistentPackage {
# Arrange
$project = New-DNXClassLibrary

# Act and Assert
Assert-Throws { Install-Package NonExisting } "Unable to find package 'NonExisting'"
}

function Test-ProjectKUpdateNonExistentPackage {
# Arrange
$project = New-DNXConsoleApp

# Act and Assert
Assert-Throws { Update-Package WebGrease -ProjectName $project.Name -version 1.0.5 } "'WebGrease' was not installed in any project. Update failed."
}

function Test-ProjectKUninstallNonExistentPackage {
# Arrange
$project = New-DNXClassLibrary

# Act and Assert
$expectedMessage = "Package 'Antlr' to be uninstalled could not be found in project '" + $project.Name + "'"
Assert-Throws { Uninstall-Package Antlr -ProjectName $project.Name } $expectedMessage
}


40 changes: 35 additions & 5 deletions test/EndToEnd/vs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,23 @@ function New-Project {
# Make sure there is a solution
Ensure-Solution

# Get the zip file where the project template is located
$projectTemplatePath = Join-Path $TemplatePath "$TemplateName.zip"
if ($TemplateName -eq 'DNXClassLibrary' -or $TemplateName -eq 'DNXConsoleApp')
{
# Get the zip file where the project template is located
$projectTemplatePath = $TemplateName + '.vstemplate|FrameworkVersion=4.5'
$lang = 'CSharp/Web'

# Find the vs template file
$projectTemplateFilePath = $dte.Solution.GetProjectTemplate($projectTemplatePath, $lang)
}
else
{
# Get the zip file where the project template is located
$projectTemplatePath = Join-Path $TemplatePath "$TemplateName.zip"

# Find the vs template file
$projectTemplateFilePath = @(Get-ChildItem $projectTemplatePath -Filter *.vstemplate)[0].FullName
# Find the vs template file
$projectTemplateFilePath = @(Get-ChildItem $projectTemplatePath -Filter *.vstemplate)[0].FullName
}

# Get the output path of the project
if($SolutionFolder) {
Expand Down Expand Up @@ -518,7 +530,25 @@ function New-DNXClassLibrary

try
{
$SolutionFolder | New-Project DNXClassLibrary $ProjectName
$SolutionFolder | New-Project DNXClassLibrary $ProjectName
}
catch {
# If we're unable to create the project that means we probably don't have some SDK installed
# Signal to the runner that we want to skip this test
throw "SKIP: $($_)"
}
}

function New-DNXConsoleApp
{
param(
[string]$ProjectName,
[parameter(ValueFromPipeline = $true)]$SolutionFolder
)

try
{
$SolutionFolder | New-Project DNXConsoleApp $ProjectName
}
catch {
# If we're unable to create the project that means we probably don't have some SDK installed
Expand Down

0 comments on commit 8dde352

Please sign in to comment.