public void FetchPackage_VersionSpecified_CorrectVersionSelected() { string sourceNuGetRoot = TestUtils.CreateTestDirectory(this.TestContext, ".nuget.source"); string targetNuGetRoot = TestUtils.CreateTestDirectory(this.TestContext, ".nuget.target"); IPackageManager mgr = CreatePackageManager(sourceNuGetRoot); AddPackage(mgr, "package.id.1", "0.8.0"); AddPackage(mgr, "package.id.1", "1.0.0-rc1"); AddPackage(mgr, "package.id.1", "2.0.0"); AddPackage(mgr, "dummy.package.1", "0.8.0"); AddPackage(mgr, "package.id.1", "0.9.0"); AddPackage(mgr, "package.id.1", "1.0.0"); NuGetPackageHandler handler = new NuGetPackageHandler(sourceNuGetRoot, new TestLogger()); // Check for specific versions IPackage actual = handler.FetchPackage("package.id.1", new SemanticVersion("0.8.0"), targetNuGetRoot); AssertExpectedPackage(actual, "package.id.1", "0.8.0"); actual = handler.FetchPackage("package.id.1", new SemanticVersion("1.0.0-rc1"), targetNuGetRoot); AssertExpectedPackage(actual, "package.id.1", "1.0.0-rc1"); actual = handler.FetchPackage("package.id.1", new SemanticVersion("2.0.0"), targetNuGetRoot); AssertExpectedPackage(actual, "package.id.1", "2.0.0"); }
public void FetchPackage_VersionSpecified_CorrectVersionSelected() { string targetNuGetRoot = TestUtils.CreateTestDirectory(this.TestContext, ".nuget.target"); RemoteRepoBuilder remoteRepoBuilder = new RemoteRepoBuilder(this.TestContext); BuildAndInstallPackage(remoteRepoBuilder, "package.id.1", "0.8.0"); BuildAndInstallPackage(remoteRepoBuilder, "package.id.1", "1.0.0-rc1"); BuildAndInstallPackage(remoteRepoBuilder, "package.id.1", "2.0.0"); BuildAndInstallPackage(remoteRepoBuilder, "dummy.package.1", "0.8.0"); BuildAndInstallPackage(remoteRepoBuilder, "package.id.1", "0.9.0"); BuildAndInstallPackage(remoteRepoBuilder, "package.id.1", "1.0.0"); NuGetPackageHandler handler = new NuGetPackageHandler(remoteRepoBuilder.FakeRemoteRepo, targetNuGetRoot, new TestLogger()); // Check for specific versions IPackage actual = handler.FetchPackage("package.id.1", new SemanticVersion("0.8.0")); AssertExpectedPackage(actual, "package.id.1", "0.8.0"); actual = handler.FetchPackage("package.id.1", new SemanticVersion("1.0.0-rc1")); AssertExpectedPackage(actual, "package.id.1", "1.0.0-rc1"); actual = handler.FetchPackage("package.id.1", new SemanticVersion("2.0.0")); AssertExpectedPackage(actual, "package.id.1", "2.0.0"); }
public void GetDependencies_DependenciesNotInstalledLocally_Warning() { // Arrange string targetNuGetRoot = TestUtils.CreateTestDirectory(TestContext, ".nuget.target"); RemoteRepoBuilder remoteRepoBuilder = new RemoteRepoBuilder(TestContext); string dummyContentFile = CreateDummyContentFile(); IEnumerable <IPackage> actualDependencies; // Build a dependency graph: "main" depends on "dependency" IPackage dependencyPackage = remoteRepoBuilder.CreatePackage("dependency.package.id", "1.2", dummyContentFile, RemoteRepoBuilder.License.Required /* no dependencies */); IPackage mainPackage = remoteRepoBuilder.CreatePackage("a", "2.0", dummyContentFile, RemoteRepoBuilder.License.NotRequired, dependencyPackage); // 1. Dependencies have not been installed locally -> warning but no error TestLogger logger = new TestLogger(); NuGetPackageHandler testSubject = new NuGetPackageHandler(remoteRepoBuilder.FakeRemoteRepo, targetNuGetRoot, logger); actualDependencies = testSubject.GetInstalledDependencies(mainPackage); AssertExpectedPackageIds(actualDependencies /* no dependencies resolved*/); logger.AssertErrorsLogged(0); logger.AssertWarningsLogged(1); logger.AssertSingleWarningExists("dependency.package.id"); // 2. Now install the package -> dependencies should resolve ok logger = new TestLogger(); testSubject = new NuGetPackageHandler(remoteRepoBuilder.FakeRemoteRepo, targetNuGetRoot, logger); testSubject.FetchPackage(mainPackage.Id, mainPackage.Version); actualDependencies = testSubject.GetInstalledDependencies(mainPackage); AssertExpectedPackageIds(actualDependencies, "dependency.package.id"); logger.AssertErrorsLogged(0); logger.AssertWarningsLogged(0); }
public void FetchPackage_PackageNotFound_NullReturned() { // Arrange string targetNuGetRoot = TestUtils.CreateTestDirectory(this.TestContext, ".nuget.target"); RemoteRepoBuilder remoteRepoBuilder = new RemoteRepoBuilder(this.TestContext); BuildAndInstallPackage(remoteRepoBuilder, "package.id.1", "0.8.0"); BuildAndInstallPackage(remoteRepoBuilder, "package.id.1", "0.9.0"); NuGetPackageHandler handler = new NuGetPackageHandler(remoteRepoBuilder.FakeRemoteRepo, targetNuGetRoot, new TestLogger()); // 1. Package id not found IPackage actual = handler.FetchPackage("unknown.package.id", new SemanticVersion("0.8.0")); Assert.IsNull(actual, "Not expecting a package to be found"); // 2. Package id not found actual = handler.FetchPackage("package.id.1", new SemanticVersion("0.7.0")); Assert.IsNull(actual, "Not expecting a package to be found"); }
public void FetchPackage_PackageNotFound_NullReturned() { // Arrange string sourceNuGetRoot = TestUtils.CreateTestDirectory(this.TestContext, ".nuget.source"); string targetNuGetRoot = TestUtils.CreateTestDirectory(this.TestContext, ".nuget.target"); IPackageManager mgr = CreatePackageManager(sourceNuGetRoot); AddPackage(mgr, "package.id.1", "0.8.0"); AddPackage(mgr, "package.id.1", "0.9.0"); NuGetPackageHandler handler = new NuGetPackageHandler(sourceNuGetRoot, new TestLogger()); // 1. Package id not found IPackage actual = handler.FetchPackage("unknown.package.id", new SemanticVersion("0.8.0"), targetNuGetRoot); Assert.IsNull(actual, "Not expecting a package to be found"); // 2. Package id not found actual = handler.FetchPackage("package.id.1", new SemanticVersion("0.7.0"), targetNuGetRoot); Assert.IsNull(actual, "Not expecting a package to be found"); }
public void NuGet_TestDependencyResolutionFailure() { // Arrange string testDir = TestUtils.CreateTestDirectory(this.TestContext); TestLogger logger = new TestLogger(); NuGetPackageHandler handler = new NuGetPackageHandler(testDir, logger); // Act // Fetch a package that should fail due to pre-release dependencies IPackage package = handler.FetchPackage("codeCracker", null, testDir); // Assert // No files should have been downloaded Assert.IsTrue(Directory.GetFiles(testDir, "*.*", SearchOption.AllDirectories).Length == 0); Assert.IsNull(package); }
public void NuGet_TestDependencyResolutionFailure() { // Arrange string testDir = TestUtils.CreateTestDirectory(this.TestContext); TestLogger logger = new TestLogger(); NuGetPackageHandler handler = new NuGetPackageHandler(logger); // Act // Fetch a package that should fail due to pre-release dependencies IPackage package = handler.FetchPackage(AnalyzerPluginGenerator.NuGetPackageSource, "codeCracker", null, testDir); // Assert // No files should have been downloaded Assert.IsTrue(Directory.GetFiles(testDir).Length == 0); Assert.IsNull(package); }
public void GetDependencies_DependenciesInstalledLocally_Succeeds() { // Arrange string targetNuGetRoot = TestUtils.CreateTestDirectory(this.TestContext, ".nuget.target"); RemoteRepoBuilder remoteRepoBuilder = new RemoteRepoBuilder(this.TestContext); string dummyContentFile = CreateDummyContentFile(); // Build a dependency graph // A depends on B // B depends on C, D, E // D also depends on E => duplicate dependency // E depends on F // -> expected [B, C, D, E, F] // Leaf nodes IPackage f = remoteRepoBuilder.CreatePackage("f", "1.0", dummyContentFile, RemoteRepoBuilder.License.NotRequired /* no dependencies */); IPackage c = remoteRepoBuilder.CreatePackage("c", "1.0", dummyContentFile, RemoteRepoBuilder.License.NotRequired /* no dependencies */); IPackage e = remoteRepoBuilder.CreatePackage("e", "1.0", dummyContentFile, RemoteRepoBuilder.License.Required, f); IPackage d = remoteRepoBuilder.CreatePackage("d", "1.1", dummyContentFile, RemoteRepoBuilder.License.Required, e); IPackage b = remoteRepoBuilder.CreatePackage("b", "1.2", dummyContentFile, RemoteRepoBuilder.License.Required, c, d, e); IPackage a = remoteRepoBuilder.CreatePackage("a", "2.0", dummyContentFile, RemoteRepoBuilder.License.NotRequired, b); NuGetPackageHandler testSubject = new NuGetPackageHandler(remoteRepoBuilder.FakeRemoteRepo, targetNuGetRoot, new TestLogger()); // We assume that all of the packages have been installed locally we attempt to resolve the dependencies testSubject.FetchPackage("a", new SemanticVersion("2.0")); // 1. Package with no dependencies -> empty list IEnumerable <IPackage> actualDependencies = testSubject.GetInstalledDependencies(f); AssertExpectedPackageIds(actualDependencies /* none */); // 2. Package with only direct dependencies -> non-empty list actualDependencies = testSubject.GetInstalledDependencies(e); AssertExpectedPackageIds(actualDependencies, "f"); // 3. Package with indirect dependencies -> non-empty list actualDependencies = testSubject.GetInstalledDependencies(a); AssertExpectedPackageIds(actualDependencies, "b", "c", "d", "e", "f"); }
public void FetchPackage_VersionNotSpecified_NoReleaseVersions_LastPreReleaseVersionSelected() { // Arrange string targetNuGetRoot = TestUtils.CreateTestDirectory(this.TestContext, ".nuget.target"); RemoteRepoBuilder remoteRepoBuilder = new RemoteRepoBuilder(this.TestContext); BuildAndInstallPackage(remoteRepoBuilder, "package.id.1", "0.9.0-rc1"); BuildAndInstallPackage(remoteRepoBuilder, "package.id.1", "1.0.0-rc1"); BuildAndInstallPackage(remoteRepoBuilder, "package.id.1", "1.1.0-rc1"); BuildAndInstallPackage(remoteRepoBuilder, "dummy.package.1", "2.0.0"); BuildAndInstallPackage(remoteRepoBuilder, "dummy.package.1", "2.0.0-rc2"); NuGetPackageHandler handler = new NuGetPackageHandler(remoteRepoBuilder.FakeRemoteRepo, targetNuGetRoot, new TestLogger()); // Act IPackage actual = handler.FetchPackage("package.id.1", null); // Assert AssertExpectedPackage(actual, "package.id.1", "1.1.0-rc1"); }
public void NuGet_TestPackageDownload_PreRelease_Release() { // Arrange string targetNuGetRoot = TestUtils.CreateTestDirectory(this.TestContext, ".nuget.target"); // Create test NuGet payload and packages IPackageRepository fakeRemoteRepo = CreateTestPackageWithSingleDependency(PreReleaseVersion, ReleaseVersion); TestLogger logger = new TestLogger(); NuGetPackageHandler handler = new NuGetPackageHandler(fakeRemoteRepo, targetNuGetRoot, logger); // Act // Attempt to download a package which is not released with a dependency that is released IPackage package = handler.FetchPackage(DependentPackageId, null); // Assert AssertExpectedPackage(package, DependentPackageId, PreReleaseVersion); // Packages should have been downloaded AssertPackageDownloaded(targetNuGetRoot, DependentPackageId, PreReleaseVersion); AssertPackageDownloaded(targetNuGetRoot, TestPackageId, ReleaseVersion); }
public void NuGet_TestPackageDownload_PreRelease_PreRelease() { // Arrange string targetNuGetRoot = TestUtils.CreateTestDirectory(this.TestContext, ".nuget.target"); // Create test NuGet payload and packages IPackageRepository fakeRemoteRepo = CreateTestPackageWithSingleDependency(PreReleaseVersion, PreReleaseVersion); TestLogger logger = new TestLogger(); NuGetPackageHandler handler = new NuGetPackageHandler(fakeRemoteRepo, targetNuGetRoot, logger); // Act // Attempt to download a package which is not released with a dependency that is not released IPackage package = handler.FetchPackage(DependentPackageId, null); // Assert AssertExpectedPackage(package, DependentPackageId, PreReleaseVersion); // Packages should have been downloaded AssertPackageDownloaded(targetNuGetRoot, DependentPackageId, PreReleaseVersion); AssertPackageDownloaded(targetNuGetRoot, TestPackageId, PreReleaseVersion); }
public void FetchPackage_VersionNotSpecified_NoReleaseVersions_LastPreReleaseVersionSelected() { // Arrange string sourceNuGetRoot = TestUtils.CreateTestDirectory(this.TestContext, ".nuget.source"); string targetNuGetRoot = TestUtils.CreateTestDirectory(this.TestContext, ".nuget.target"); IPackageManager mgr = CreatePackageManager(sourceNuGetRoot); AddPackage(mgr, "package.id.1", "0.9.0-rc1"); AddPackage(mgr, "package.id.1", "1.0.0-rc1"); AddPackage(mgr, "package.id.1", "1.1.0-rc1"); AddPackage(mgr, "dummy.package.1", "2.0.0"); AddPackage(mgr, "dummy.package.1", "2.0.0-rc2"); NuGetPackageHandler handler = new NuGetPackageHandler(sourceNuGetRoot, new TestLogger()); // Act IPackage actual = handler.FetchPackage("package.id.1", null, targetNuGetRoot); // Assert AssertExpectedPackage(actual, "package.id.1", "1.1.0-rc1"); }
public void NuGet_TestPackageDownload_PreRelease_PreRelease() { // Arrange string testDir = TestUtils.CreateTestDirectory(this.TestContext); string testDownloadDir = Path.Combine(testDir, "download"); // Create test NuGet payload and packages BuildTestPackages(false, false); TestLogger logger = new TestLogger(); NuGetPackageHandler handler = new NuGetPackageHandler(testDir, logger); // Act // Attempt to download a package which is not released with a dependency that is not released IPackage package = handler.FetchPackage(DependentPackageName, null, testDownloadDir); // Assert AssertExpectedPackage(package, DependentPackageName, PreReleaseVersion); // Packages should have been downloaded AssertPackageDownloaded(testDownloadDir, DependentPackageName, PreReleaseVersion); AssertPackageDownloaded(testDownloadDir, TestPackageName, PreReleaseVersion); }
public void NuGet_TestPackageDownload_PreRelease_Release() { // Arrange string testDir = TestUtils.CreateTestDirectory(this.TestContext); string testDownloadDir = Path.Combine(testDir, "download"); // Create test NuGet payload and packages BuildTestPackages(false, true); TestLogger logger = new TestLogger(); NuGetPackageHandler handler = new NuGetPackageHandler(testDir, logger); // Act // Attempt to download a package which is not released with a dependency that is released IPackage package = handler.FetchPackage(DependentPackageName, null, testDownloadDir); // Assert AssertExpectedPackage(package, DependentPackageName, PreReleaseVersion); // Packages should have been downloaded AssertPackageDownloaded(testDownloadDir, DependentPackageName, PreReleaseVersion); AssertPackageDownloaded(testDownloadDir, TestPackageName, ReleaseVersion); }
public void FetchPackage_VersionNotSpecified_ReleaseVersionExists_LastReleaseVersionSelected() { // Arrange string targetNuGetRoot = TestUtils.CreateTestDirectory(this.TestContext, ".nuget.target"); RemoteRepoBuilder remoteRepoBuilder = new RemoteRepoBuilder(this.TestContext); BuildAndInstallPackage(remoteRepoBuilder, "package.id.1", "0.8.0"); BuildAndInstallPackage(remoteRepoBuilder, "package.id.1", "0.9.0-rc1"); BuildAndInstallPackage(remoteRepoBuilder, "package.id.1", "1.0.0"); BuildAndInstallPackage(remoteRepoBuilder, "package.id.1", "1.1.0-rc1"); BuildAndInstallPackage(remoteRepoBuilder, "dummy.package.1", "2.0.0"); NuGetPackageHandler handler = new NuGetPackageHandler(remoteRepoBuilder.FakeRemoteRepo, targetNuGetRoot, new TestLogger()); // Act IPackage actual = handler.FetchPackage("package.id.1", null); // Assert AssertExpectedPackage(actual, "package.id.1", "1.0.0"); }
public void GetDependencies_DependenciesInstalledLocally_Succeeds() { // Arrange string targetNuGetRoot = TestUtils.CreateTestDirectory(this.TestContext, ".nuget.target"); RemoteRepoBuilder remoteRepoBuilder = new RemoteRepoBuilder(this.TestContext); string dummyContentFile = CreateDummyContentFile(); // Build a dependency graph // A depends on B // B depends on C, D, E // D also depends on E => duplicate dependency // E depends on F // -> expected [B, C, D, E, F] // Leaf nodes IPackage f = remoteRepoBuilder.CreatePackage("f", "1.0", dummyContentFile, RemoteRepoBuilder.License.NotRequired /* no dependencies */); IPackage c = remoteRepoBuilder.CreatePackage("c", "1.0", dummyContentFile, RemoteRepoBuilder.License.NotRequired /* no dependencies */); IPackage e = remoteRepoBuilder.CreatePackage("e", "1.0", dummyContentFile, RemoteRepoBuilder.License.Required, f); IPackage d = remoteRepoBuilder.CreatePackage("d", "1.1", dummyContentFile, RemoteRepoBuilder.License.Required, e); IPackage b = remoteRepoBuilder.CreatePackage("b", "1.2", dummyContentFile, RemoteRepoBuilder.License.Required, c, d, e); IPackage a = remoteRepoBuilder.CreatePackage("a", "2.0", dummyContentFile, RemoteRepoBuilder.License.NotRequired, b); NuGetPackageHandler testSubject = new NuGetPackageHandler(remoteRepoBuilder.FakeRemoteRepo, targetNuGetRoot, new TestLogger()); // We assume that all of the packages have been installed locally we attempt to resolve the dependencies testSubject.FetchPackage("a", new SemanticVersion("2.0")); // 1. Package with no dependencies -> empty list IEnumerable<IPackage> actualDependencies = testSubject.GetInstalledDependencies(f); AssertExpectedPackageIds(actualDependencies /* none */); // 2. Package with only direct dependencies -> non-empty list actualDependencies = testSubject.GetInstalledDependencies(e); AssertExpectedPackageIds(actualDependencies, "f"); // 3. Package with indirect dependencies -> non-empty list actualDependencies = testSubject.GetInstalledDependencies(a); AssertExpectedPackageIds(actualDependencies, "b", "c", "d", "e", "f"); }
public void GetDependencies_DependenciesNotInstalledLocally_Warning() { // Arrange string targetNuGetRoot = TestUtils.CreateTestDirectory(this.TestContext, ".nuget.target"); RemoteRepoBuilder remoteRepoBuilder = new RemoteRepoBuilder(this.TestContext); string dummyContentFile = CreateDummyContentFile(); IEnumerable<IPackage> actualDependencies; // Build a dependency graph: "main" depends on "dependency" IPackage dependencyPackage = remoteRepoBuilder.CreatePackage("dependency.package.id", "1.2", dummyContentFile, RemoteRepoBuilder.License.Required /* no dependencies */); IPackage mainPackage = remoteRepoBuilder.CreatePackage("a", "2.0", dummyContentFile, RemoteRepoBuilder.License.NotRequired, dependencyPackage); // 1. Dependencies have not been installed locally -> warning but no error TestLogger logger = new TestLogger(); NuGetPackageHandler testSubject = new NuGetPackageHandler(remoteRepoBuilder.FakeRemoteRepo, targetNuGetRoot, logger); actualDependencies = testSubject.GetInstalledDependencies(mainPackage); AssertExpectedPackageIds(actualDependencies /* no dependencies resolved*/); logger.AssertErrorsLogged(0); logger.AssertWarningsLogged(1); logger.AssertSingleWarningExists("dependency.package.id"); // 2. Now install the package -> dependencies should resolve ok logger = new TestLogger(); testSubject = new NuGetPackageHandler(remoteRepoBuilder.FakeRemoteRepo, targetNuGetRoot, logger); testSubject.FetchPackage(mainPackage.Id, mainPackage.Version); actualDependencies = testSubject.GetInstalledDependencies(mainPackage); AssertExpectedPackageIds(actualDependencies, "dependency.package.id"); logger.AssertErrorsLogged(0); logger.AssertWarningsLogged(0); }
public void FetchPackage_VersionSpecified_CorrectVersionSelected() { string sourceNuGetRoot = TestUtils.CreateTestDirectory(this.TestContext, ".nuget.source"); string targetNuGetRoot = TestUtils.CreateTestDirectory(this.TestContext, ".nuget.target"); IPackageManager mgr = CreatePackageManager(sourceNuGetRoot); BuildAndInstallPackage(mgr, "package.id.1", "0.8.0"); BuildAndInstallPackage(mgr, "package.id.1", "1.0.0-rc1"); BuildAndInstallPackage(mgr, "package.id.1", "2.0.0"); BuildAndInstallPackage(mgr, "dummy.package.1", "0.8.0"); BuildAndInstallPackage(mgr, "package.id.1", "0.9.0"); BuildAndInstallPackage(mgr, "package.id.1", "1.0.0"); NuGetPackageHandler handler = new NuGetPackageHandler(sourceNuGetRoot, new TestLogger()); // Check for specific versions IPackage actual = handler.FetchPackage("package.id.1", new SemanticVersion("0.8.0"), targetNuGetRoot); AssertExpectedPackage(actual, "package.id.1", "0.8.0"); actual = handler.FetchPackage("package.id.1", new SemanticVersion("1.0.0-rc1"), targetNuGetRoot); AssertExpectedPackage(actual, "package.id.1", "1.0.0-rc1"); actual = handler.FetchPackage("package.id.1", new SemanticVersion("2.0.0"), targetNuGetRoot); AssertExpectedPackage(actual, "package.id.1", "2.0.0"); }
public void FetchPackage_VersionNotSpecified_NoReleaseVersions_LastPreReleaseVersionSelected() { // Arrange string sourceNuGetRoot = TestUtils.CreateTestDirectory(this.TestContext, ".nuget.source"); string targetNuGetRoot = TestUtils.CreateTestDirectory(this.TestContext, ".nuget.target"); IPackageManager mgr = CreatePackageManager(sourceNuGetRoot); BuildAndInstallPackage(mgr, "package.id.1", "0.9.0-rc1"); BuildAndInstallPackage(mgr, "package.id.1", "1.0.0-rc1"); BuildAndInstallPackage(mgr, "package.id.1", "1.1.0-rc1"); BuildAndInstallPackage(mgr, "dummy.package.1", "2.0.0"); BuildAndInstallPackage(mgr, "dummy.package.1", "2.0.0-rc2"); NuGetPackageHandler handler = new NuGetPackageHandler(sourceNuGetRoot, new TestLogger()); // Act IPackage actual = handler.FetchPackage("package.id.1", null, targetNuGetRoot); // Assert AssertExpectedPackage(actual, "package.id.1", "1.1.0-rc1"); }
public void FetchPackage_PackageNotFound_NullReturned() { // Arrange string sourceNuGetRoot = TestUtils.CreateTestDirectory(this.TestContext, ".nuget.source"); string targetNuGetRoot = TestUtils.CreateTestDirectory(this.TestContext, ".nuget.target"); IPackageManager mgr = CreatePackageManager(sourceNuGetRoot); BuildAndInstallPackage(mgr, "package.id.1", "0.8.0"); BuildAndInstallPackage(mgr, "package.id.1", "0.9.0"); NuGetPackageHandler handler = new NuGetPackageHandler(sourceNuGetRoot, new TestLogger()); // 1. Package id not found IPackage actual = handler.FetchPackage("unknown.package.id", new SemanticVersion("0.8.0"), targetNuGetRoot); Assert.IsNull(actual, "Not expecting a package to be found"); // 2. Package id not found actual = handler.FetchPackage("package.id.1", new SemanticVersion("0.7.0"), targetNuGetRoot); Assert.IsNull(actual, "Not expecting a package to be found"); }