Last active
January 1, 2016 09:19
-
-
Save dschenkelman/8124109 to your computer and use it in GitHub Desktop.
IntegrationTests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NugetPackageInstallationTests : IDisposable | |
{ | |
private readonly string _originalWorkingDirectory; | |
private readonly string _filesDirectory; | |
private string _localDirectory; | |
public NugetPackageInstallationTests() | |
{ | |
_originalWorkingDirectory = Environment.CurrentDirectory; | |
_filesDirectory = Path.Combine(AcceptanceTestHelpers.GetExecutingAssemblyDirectory(), "Files"); | |
} | |
[Fact] | |
[Trait("AcceptanceTest", "NugetPackageInstallationTests")] | |
[Trait("Requires", "Internet Connection")] | |
public void ShouldBeAbleToInstallPackages() | |
{ | |
// arrange | |
var methodName = AcceptanceTestHelpers.GetCurrentMethodName(); | |
_localDirectory = Path.Combine(AcceptanceTestHelpers.GetExecutingAssemblyDirectory(), methodName); | |
var packageConfigName = string.Format("{0}.packages.config", methodName); | |
Directory.CreateDirectory(_localDirectory); | |
File.Copy(Path.Combine(_filesDirectory, packageConfigName), Path.Combine(_localDirectory, "packages.config")); | |
Environment.CurrentDirectory = _localDirectory; | |
// act | |
const string Args = "-install"; | |
var result = Program.Main(Args.Split(' ')); | |
var packagesPath = Path.Combine(_localDirectory, "packages"); | |
var packagesDir = new DirectoryInfo(packagesPath); | |
var packagesDirectoriesNames = packagesDir.EnumerateDirectories().Select(pd => pd.Name).ToArray(); | |
// assert | |
result.ShouldEqual(0); | |
Directory.Exists(packagesPath).ShouldBeTrue(); | |
packagesDirectoriesNames.Length.ShouldEqual(4); | |
packagesDirectoriesNames.Count(n => Regex.IsMatch(n, @"Common\.Logging\.[0-9]+\.[0-9]+\.[0-9]+")).ShouldEqual(1); | |
packagesDirectoriesNames.Count(n => Regex.IsMatch(n, @"ScriptCs\.Contracts\.[0-9]+\.[0-9]+\.[0-9]+")).ShouldEqual(1); | |
packagesDirectoriesNames.Count(n => Regex.IsMatch(n, @"ScriptCs\.Core\.[0-9]+\.[0-9]+\.[0-9]+")).ShouldEqual(1); | |
packagesDirectoriesNames.Count(n => Regex.IsMatch(n, @"ServiceStack\.Text\.[0-9]+\.[0-9]+\.[0-9]+")).ShouldEqual(1); | |
} | |
public void Dispose() | |
{ | |
// this is here so it gets executed even if asserts fail | |
Environment.CurrentDirectory = _originalWorkingDirectory; | |
Directory.Delete(_localDirectory, true); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NugetPackageInstallationTests | |
{ | |
[Scenario] | |
[Trait("AcceptanceTest", "NugetPackageInstallationTests")] | |
[Trait("Requires", "Internet Connection")] | |
public void InstallPackagesFromPackagesConfigFile(string localDirectory, int result, string packagesPath, string originalWorkingDirectory) | |
{ | |
var methodName = AcceptanceTestHelpers.GetCurrentMethodName(); | |
"Given a current working directory"._(() => | |
{ | |
originalWorkingDirectory = Environment.CurrentDirectory; | |
localDirectory = Path.Combine(AcceptanceTestHelpers.GetExecutingAssemblyDirectory(), methodName); | |
Directory.CreateDirectory(localDirectory); | |
Environment.CurrentDirectory = localDirectory; | |
}).Teardown(() => | |
{ | |
Environment.CurrentDirectory = originalWorkingDirectory; | |
Directory.Delete(localDirectory, true); | |
}); | |
"And a packages.config file located in the current directory"._(() => | |
{ | |
var filesDirectory = Path.Combine(AcceptanceTestHelpers.GetExecutingAssemblyDirectory(), "Files"); | |
var packageConfigName = string.Format("{0}.packages.config", methodName); | |
Directory.CreateDirectory(localDirectory); | |
File.Copy(Path.Combine(filesDirectory, packageConfigName), Path.Combine(localDirectory, "packages.config")); | |
}); | |
"When the packages are installed"._(() => | |
{ | |
const string Args = "-install"; | |
result = Program.Main(Args.Split(' ')); | |
}); | |
"Then the program executes successfully"._(() => result.ShouldEqual(0)); | |
"And a packages directory is created inside the working directory"._(() => | |
{ | |
packagesPath = Path.Combine(localDirectory, "packages"); | |
Directory.Exists(packagesPath).ShouldBeTrue(); | |
}); | |
"And a directory for the package and each of its dependencies is created"._(() => | |
{ | |
var packagesDir = new DirectoryInfo(packagesPath); | |
var packagesDirectoriesNames = packagesDir.EnumerateDirectories().Select(pd => pd.Name).ToArray(); | |
packagesDirectoriesNames.Length.ShouldEqual(4); | |
packagesDirectoriesNames.Count(n => Regex.IsMatch(n, @"Common\.Logging\.[0-9]+\.[0-9]+\.[0-9]+")).ShouldEqual(1); | |
packagesDirectoriesNames.Count(n => Regex.IsMatch(n, @"ScriptCs\.Contracts\.[0-9]+\.[0-9]+\.[0-9]+")).ShouldEqual(1); | |
packagesDirectoriesNames.Count(n => Regex.IsMatch(n, @"ScriptCs\.Core\.[0-9]+\.[0-9]+\.[0-9]+")).ShouldEqual(1); | |
packagesDirectoriesNames.Count(n => Regex.IsMatch(n, @"ServiceStack\.Text\.[0-9]+\.[0-9]+\.[0-9]+")).ShouldEqual(1); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment