Skip to content

Commit

Permalink
Adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jainaashish authored and nkolev92 committed Feb 13, 2019
1 parent 3b8b9bf commit ae27a18
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/EndToEnd/tests/ServicesTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1002,3 +1002,21 @@ function Test-InstallPackageAsyncWithPackageReferenceFormat {
Assert-AreEqual $packageRefs[0].GetMetadataValue("Identity") 'owin'
Assert-AreEqual $packageRefs[0].GetMetadataValue("Version") '1.0.0'
}

function Test-BuildIntegratedProjectInstallPackage {

# Arrange
$project = New-Project BuildIntegratedClassLibrary Project1
$id = 'CustomBuildIntegratedProjectInstallPackage'
$version = '1.0.0'

$solutionFile = Get-SolutionFullName
$solutionDir = Split-Path $solutionFile -Parent
$source = Join-Path $solutionDir "CustomSource"

# Act
[API.Test.InternalAPITestHook]::InstallPackageApiFromSource($source, $id, $version)

# Assert
Assert-ProjectJsonLockFilePackage $project $id $version
}
68 changes: 68 additions & 0 deletions test/TestExtensions/API.Test/InternalAPITestHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Shell;
using NuGet.Common;
using NuGet.PackageManagement.VisualStudio;
using NuGet.Packaging;
using NuGet.Versioning;
using NuGet.VisualStudio;
using Task = System.Threading.Tasks.Task;

Expand Down Expand Up @@ -56,6 +60,49 @@ public static void InstallPackageApi(string source, string id, string version, b
});
}

public static void InstallPackageApiFromSource(string source, string id, string version)
{
CreatePackage(source, id, version);
InstallPackageApi(source, id, version, prerelease: false);
}

private static void CreatePackage(string path, string id, string version)
{
var builder = new NuGet.Packaging.PackageBuilder()
{
Id = id,
Version = NuGetVersion.Parse(version),
Description = "Description.",
DevelopmentDependency = false
};

builder.Authors.Add("testAuthor");
builder.Files.Add(CreatePackageFile("lib/net45/a.dll"));

Directory.CreateDirectory(path);

using (var stream = File.OpenWrite(Path.Combine(path, $"{id}.{version}.nupkg")))
{
builder.Save(stream);
}
}

private static IPackageFile CreatePackageFile(string name)
{
var file = new InMemoryFile
{
Path = name,
Stream = new MemoryStream()
};

string effectivePath;
var fx = FrameworkNameUtility.ParseFrameworkNameFromFilePath(name, out effectivePath);
file.EffectivePath = effectivePath;
file.TargetFramework = fx;

return file;
}

public static void UninstallPackageApi(string id, bool dependency)
{
ThreadHelper.JoinableTaskFactory.Run(
Expand Down Expand Up @@ -185,5 +232,26 @@ public static bool IsFileExistsInProject(string projectUniqueName, string filePa
return false;
});
}

private class InMemoryFile : IPackageFile
{
private DateTimeOffset _lastWriteTime;

public string EffectivePath { get; set; }

public string Path { get; set; }

public FrameworkName TargetFramework { get; set; }

public MemoryStream Stream { get; set; }

public Stream GetStream()
{
_lastWriteTime = DateTimeOffset.UtcNow;
return Stream;
}

public DateTimeOffset LastWriteTime => _lastWriteTime;
}
}
}

0 comments on commit ae27a18

Please sign in to comment.