public void UpdatePackageToSpecificVersion() { // arrange NuGetManager nuget = new NuGetManager(); var nugetSources = AbsolutePath(@"LocalizedNugetPackage"); nuget.InstallPackages( _appInfo.PhysicalPath, new List<PackageName> { new PackageName("LocalizedNugetPackage", new SemanticVersion("1.0")) }, nugetSources); // act nuget.UpdatePackages( _appInfo.PhysicalPath, new List<PackageName> { new PackageName("LocalizedNugetPackage", new SemanticVersion("2.0.0")) }, nugetSources); // assert var expectedPackageInstallDir = Path.Combine(_appInfo.PhysicalPath, "packages", "LocalizedNugetPackage.2.0.0"); Assert.IsTrue(Directory.Exists(expectedPackageInstallDir)); var notExpectedPackageInstallDir = Path.Combine(_appInfo.PhysicalPath, "packages", "LocalizedNugetPackage.1.0.0"); Assert.IsFalse(Directory.Exists(notExpectedPackageInstallDir)); }
public void PackageNameIsEmpty_Throws() { var manager = new NuGetManager(); var ex = Assert.Throws<ArgumentNullException>(() => manager.InstallPackage("DummyPath", null)); Assert.Contains("packageName", ex.Message); ex = Assert.Throws<ArgumentNullException>(() => manager.InstallPackage("DummyPath", string.Empty)); Assert.Contains("packageName", ex.Message); }
public void PhysicalPathIsEmpty_Throws() { var manager = new NuGetManager(); var ex = Assert.Throws<ArgumentNullException>(() => manager.InstallPackage(null, "DummyPackage")); Assert.Contains("appPhysicalPath", ex.Message); ex = Assert.Throws<ArgumentNullException>(() => manager.InstallPackage(string.Empty, "DummyPackage")); Assert.Contains("appPhysicalPath", ex.Message); }
public void SourcesProvided_NugetDefaultFeedIncluded() { // arrange var mockNugetCore = new Mock<INuGetCore>(); mockNugetCore.Setup(n => n.InstallPackage("DummyPath", "DummyPackage", It.Is<string>(s => s.Contains(NuGetManager.NUGET_DEFAULT_SOURCE)), "", null)) .Returns(() => null) .Verifiable(); var mockFileSystem = new Mock<Core.Abstractions.IFileSystem>(); // act var manager = new NuGetManager(mockNugetCore.Object, mockFileSystem.Object); manager.InstallPackage("DummyPath", "DummyPackage", "http://DummyFeed"); // assert mockNugetCore.Verify(); }
public void InstallSatelliteAssemblyTest() { // arrange NuGetManager nuget = new NuGetManager(); var nugetSources = AbsolutePath(@"LocalizedNugetPackage"); // act nuget.InstallPackages( _appInfo.PhysicalPath, new List<PackageName> { new PackageName("LocalizedNugetPackage.zh-Hans", new SemanticVersion("1.0")) }, nugetSources); // assert var expectedLocAssembly = Path.Combine(_appInfo.PhysicalPath, @"bin\zh-Hans\LocalizedNugetPackage.resources.dll"); Assert.IsTrue(File.Exists(expectedLocAssembly)); }
public void InstallAllProvidedPackages() { // arrange var mockNugetCore = new Mock<INuGetCore>(); mockNugetCore.Setup(n => n.InstallPackage("DummyPath", "FooPackage", It.IsAny<string>(), "1.0", null)) .Returns(Enumerable.Empty<string>).Verifiable(); mockNugetCore.Setup(n => n.InstallPackage("DummyPath", "BarPackage", It.IsAny<string>(), "2.0", null)) .Returns(Enumerable.Empty<string>).Verifiable(); var mockFileSystem = new Mock<Core.Abstractions.IFileSystem>(); var packagesToInstall = new List<PackageName>() { new PackageName("FooPackage", SemanticVersion.Parse("1.0")), new PackageName("BarPackage", SemanticVersion.Parse("2.0")) }; // act var manager = new NuGetManager(mockNugetCore.Object, mockFileSystem.Object); manager.InstallPackages("DummyPath", packagesToInstall); // assert mockNugetCore.Verify(); }
public void PackagesIsNull_Throws() { var manager = new NuGetManager(); Assert.Throws<ArgumentNullException>(() => manager.InstallPackages("DummyPath", (IEnumerable<PackageName>)null)); }
public void BinariesOnlyTrue_WebConfigDoesntExist() { // arrange var mockNugetCore = new Mock<INuGetCore>(); var mockFileSystem = new Mock<Core.Abstractions.IFileSystem>(MockBehavior.Strict); mockFileSystem.Setup(fs => fs.DirectorySetAttribute("DummyPath", FileAttributes.Normal)); mockFileSystem.Setup(fs => fs.FileExists(@"DummyPath\web.config")).Returns(false).Verifiable(); mockFileSystem.Setup(fs => fs.FileExists(@"DummyPath\web.config.temp")).Returns(false).Verifiable(); // act var manager = new NuGetManager(mockNugetCore.Object, mockFileSystem.Object); manager.InstallPackage(@"DummyPath", "DummyPackage", binariesOnly: true); // assert mockFileSystem.Verify(); // assert we don't call any other FileSystem APIs handled by MockBehavior.Strict }
public void BinariesOnlyTrue_WebConfigIsPreserved() { // arrange var mockNugetCore = new Mock<INuGetCore>(); var mockFileSystem = new Mock<Core.Abstractions.IFileSystem>(); mockFileSystem.Setup(fs => fs.DirectorySetAttribute("DummyPath", FileAttributes.Normal)); mockFileSystem.Setup(fs => fs.FileExists(@"DummyPath\web.config")).Returns(true).Verifiable(); mockFileSystem.Setup(fs => fs.FileCopy(@"DummyPath\web.config", @"DummyPath\web.config.temp", true)).Verifiable(); mockFileSystem.Setup(fs => fs.FileExists(@"DummyPath\web.config.temp")).Returns(true).Verifiable(); mockFileSystem.Setup(fs => fs.FileCopy(@"DummyPath\web.config.temp", @"DummyPath\web.config", true)).Verifiable(); mockFileSystem.Setup(fs => fs.FileDelete(@"DummyPath\web.config.temp")).Verifiable(); // act var manager = new NuGetManager(mockNugetCore.Object, mockFileSystem.Object); manager.InstallPackage(@"DummyPath", "DummyPackage", binariesOnly: true); // assert mockFileSystem.Verify(); }
public void BinariesOnlyFalse_WebConfigNotPreserved() { var mockNugetCore = new Mock<INuGetCore>(); var mockFileSystem = new Mock<Core.Abstractions.IFileSystem>(MockBehavior.Strict); mockFileSystem.Setup(fs => fs.DirectorySetAttribute("DummyPath", FileAttributes.Normal)); // act // assert we don't call any other FileSystem APIs handled by MockBehavior.Strict var manager = new NuGetManager(mockNugetCore.Object, mockFileSystem.Object); manager.InstallPackage(@"DummyPath", "DummyPackage", binariesOnly: false); }
public void NullVersionConvertedToEmptyString() { // arrange var mockNugetCore = new Mock<INuGetCore>(); mockNugetCore.Setup(n => n.UpdatePackage("DummyPath", "FooPackage", It.IsAny<string>(), "", null)) .Returns(Enumerable.Empty<string>).Verifiable(); var mockFileSystem = new Mock<Core.Abstractions.IFileSystem>(); var packagesToUpdate = new List<PackageName>() { new PackageName("FooPackage", null), }; // act var manager = new NuGetManager(mockNugetCore.Object, mockFileSystem.Object); manager.UpdatePackages("DummyPath", packagesToUpdate); // assert mockNugetCore.Verify(); }
public void ReadFromPackagesConfig_UseCustomSources(string configContent, string[] packagesToExpect, string customSources) { // arrange var mockNugetCore = new Mock<INuGetCore>(); foreach (var package in packagesToExpect) { string packageId = package.Split('|')[0]; string packageVer = package.Split('|')[1]; mockNugetCore.Setup(n => n.InstallPackage("DummyPath", packageId, It.Is<string>(s => s.Contains(customSources)), It.IsAny<string>(), null)) .Returns(Enumerable.Empty<string>).Verifiable(); } var mockFileSystem = new Mock<Core.Abstractions.IFileSystem>(MockBehavior.Strict); mockFileSystem.Setup(fs => fs.DirectorySetAttribute("DummyPath", FileAttributes.Normal)); mockFileSystem.Setup(fs => fs.FileExists("DummyPackagesConfigPath")).Returns(true); mockFileSystem.Setup(fs => fs.FileReadAllText("DummyPackagesConfigPath")).Returns(configContent); // act var manager = new NuGetManager(mockNugetCore.Object, mockFileSystem.Object); manager.InstallPackages("DummyPath", "DummyPackagesConfigPath", binariesOnly: false); // assert mockNugetCore.Verify(); }
public void PackagesConfigPathDoesNotExist_Throws() { var mockNugetCore = new Mock<INuGetCore>(); var mockFileSystem = new Mock<Core.Abstractions.IFileSystem>(MockBehavior.Strict); // strict ensures we don't use any other FileSystem APIs mockFileSystem.Setup(fs => fs.FileExists("DummyPackagesConfigPath")).Returns(false).Verifiable(); var manager = new NuGetManager(mockNugetCore.Object, mockFileSystem.Object); Assert.Throws<FileNotFoundException>(() => manager.InstallPackages("DummyPath", "DummyPackagesConfigPath")); mockFileSystem.Verify(); }
public void PackagesConfigPathIsEmpty_Throws() { var manager = new NuGetManager(); Assert.Throws<ArgumentNullException>(() => manager.InstallPackages("DummyPath", (string)null)); Assert.Throws<ArgumentNullException>(() => manager.InstallPackages("DummyPath", "")); }
public void UpdatePackage_UpdatesReferencesInProjectFile() { // arrange NuGetManager nuget = new NuGetManager(); var nugetSources = AbsolutePath(@"LocalizedNugetPackage"); nuget.InstallPackages( _appInfo.PhysicalPath, new List<PackageName> { new PackageName("LocalizedNugetPackage", new SemanticVersion("1.0")) }, nugetSources); // act nuget.UpdatePackage( _appInfo.PhysicalPath, "LocalizedNugetPackage", nugetSources); var projectFileContents = File.ReadAllText(Path.Combine(_appInfo.PhysicalPath, "TestEasyWAP.csproj")); // assert var expectedPackageInstallDir = Path.Combine(_appInfo.PhysicalPath, "packages", "LocalizedNugetPackage.3.0.0-prerelease"); Assert.IsTrue(Directory.Exists(expectedPackageInstallDir)); Assert.IsTrue(projectFileContents.Contains("LocalizedNugetPackage.3.0.0-prerelease")); var notExpectedPackageInstallDir = Path.Combine(_appInfo.PhysicalPath, "packages", "LocalizedNugetPackage.1.0.0"); Assert.IsFalse(Directory.Exists(notExpectedPackageInstallDir)); Assert.IsFalse(projectFileContents.Contains("LocalizedNugetPackage.1.0.0")); }