public void InstallNewPackageToPackageManagerBeforeProjectManager()
            {
                var package = new MockPackage();
                var mockRepository = new MockPackageRepository();
                mockRepository.AddPackage(package);
                bool calledPackageManager = false;
                bool calledProjectManagerAfterPackageManager = false;

                var mockPackageMan = MockGenerator.CreateMockPackageManager(mockRepository, mockRepository);
                mockPackageMan.Setup(packMan => packMan.InstallPackage(package, It.IsAny<bool>(), It.IsAny<bool>()))
                    .Callback(() => calledPackageManager = true);

                var mockProjectMan = MockGenerator.CreateMockProjectManager(mockRepository, mockRepository);
                mockProjectMan.Setup(projMan => projMan.UpdatePackageReference(package.Id, package.Version, It.IsAny<bool>(), It.IsAny<bool>()))
                    .Callback(() => calledProjectManagerAfterPackageManager = calledPackageManager);

                Dependencies.NuGetPackageManagerFactory = MockGenerator.CreatePackageManagerFactory(mockPackageMan.Object);
                Dependencies.NuGetProjectManagerFactory = MockGenerator.CreateProjectManagerFactory(mockProjectMan.Object);

                // act
                WebNuGetProject project = new WebNuGetProject(new string[] {}, @"C:\DummyPath", null, MockGenerator.CreateWebProjectSystemFactory());
                var warnings = project.UpdatePackage(package);

                // assert
                Assert.True(calledProjectManagerAfterPackageManager);
            }
Beispiel #2
0
        private WebNuGetProject TryToLocatePackage(string sitePhysicalPath, string packageName, string source,
                                                   string version, Version targetFramework, out IPackage package)
        {
            var semanticVersion = (string.IsNullOrEmpty(version)) ? null : new SemanticVersion(version);
            var sources         = source.Split(';');

            var nugetProject = new WebNuGetProject(sources, sitePhysicalPath, targetFramework);

            package = nugetProject.SourceRepository.FindPackage(packageName, semanticVersion, true, false) ??
                      nugetProject.LocalRepository.FindPackage(packageName, semanticVersion, true, false);

            return(package == null ? null : nugetProject);
        }
Beispiel #3
0
        private WebNuGetProject TryToLocatePackage(string sitePhysicalPath, string packageName, string source,
                                                     string version, Version targetFramework, out IPackage package)
        {
            var semanticVersion = (string.IsNullOrEmpty(version)) ? null : new SemanticVersion(version);
            var sources = source.Split(';');

            var nugetProject = new WebNuGetProject(sources, sitePhysicalPath, targetFramework);

            package = nugetProject.SourceRepository.FindPackage(packageName, semanticVersion, true, false) ??
                      nugetProject.LocalRepository.FindPackage(packageName, semanticVersion, true, false);

            return package == null ? null : nugetProject;
        }
            public void UninstallOldPackageFails_HandleGracefully()
            {
                var oldPackage = new MockPackage();
                var package = new MockPackage { Version = new SemanticVersion("2.0") };

                var mockRepository = new MockPackageRepository();
                mockRepository.AddPackage(oldPackage);

                var mockPackageMan = MockGenerator.CreateMockPackageManager(mockRepository, mockRepository);
                mockPackageMan.Setup(packMan => packMan.UninstallPackage(oldPackage, It.IsAny<bool>(), It.IsAny<bool>()))
                    .Throws(new InvalidOperationException("Dummy message"));
                mockPackageMan.SetupProperty(packMan => packMan.Logger, new TestEasy.NuGet.WebNuGetProject.ErrorLogger());
                var mockProjectMan = MockGenerator.CreateMockProjectManager(mockRepository, mockRepository);

                Dependencies.NuGetPackageManagerFactory = MockGenerator.CreatePackageManagerFactory(mockPackageMan.Object);
                Dependencies.NuGetProjectManagerFactory = MockGenerator.CreateProjectManagerFactory(mockProjectMan.Object);

                // act
                WebNuGetProject project = new WebNuGetProject(new string[] { }, @"C:\DummyPath", null, MockGenerator.CreateWebProjectSystemFactory());
                var warnings = project.UpdatePackage(package);

                // assert
                Assert.Contains("Package MockPackage.1.0 could not be uninstalled: Dummy message", warnings);
            }
            public void OldVersionOfPackageUninstalled()
            {
                var oldPackage = new MockPackage();
                var package = new MockPackage { Version = new SemanticVersion("2.0") };

                var mockRepository = new MockPackageRepository();
                mockRepository.AddPackage(oldPackage);

                var mockPackageMan = MockGenerator.CreateMockPackageManager(mockRepository, mockRepository);
                mockPackageMan.Setup(packMan => packMan.UninstallPackage(oldPackage, It.IsAny<bool>(), It.IsAny<bool>()))
                    .Verifiable();
                var mockProjectMan = MockGenerator.CreateMockProjectManager(mockRepository, mockRepository);

                Dependencies.NuGetPackageManagerFactory = MockGenerator.CreatePackageManagerFactory(mockPackageMan.Object);
                Dependencies.NuGetProjectManagerFactory = MockGenerator.CreateProjectManagerFactory(mockProjectMan.Object);

                // act
                WebNuGetProject project = new WebNuGetProject(new string[] { }, @"C:\DummyPath", null, MockGenerator.CreateWebProjectSystemFactory());
                var warnings = project.UpdatePackage(package);

                // assert
                mockPackageMan.Verify();
            }
            public void DoesNotReturnPackagesFromLocal()
            {
                var packageA = new MockPackage { Id = "A" };
                var packageB = new MockPackage { Id = "B" };
                var packageAB = new MockPackage { Id = "AB" };
                
                var mockRemoteRepo = new MockPackageRepository();
                mockRemoteRepo.AddPackage(packageA);
                mockRemoteRepo.AddPackage(packageB);
                var mockLocalRepo = new MockPackageRepository();
                mockLocalRepo.AddPackage(packageAB);

                Dependencies.NuGetProjectManagerFactory = MockGenerator.CreateProjectManagerFactory(MockGenerator.CreateMockProjectManager(mockRemoteRepo, mockLocalRepo).Object);

                // act
                var project = new WebNuGetProject(new string[] { "http://dummyFeed" }, @"C:\DummyPath", null, MockGenerator.CreateWebProjectSystemFactory());
                var results = project.GetRemotePackages("A");

                Assert.Equal(new IPackage[] { packageA }, results);
            }
            public void OrderedByDownloadCountFirst()
            {
                var packageA = new MockPackage { Id = "A", DownloadCount = 1 };
                var packageB = new MockPackage { Id = "B", DownloadCount = 2 };

                var mockRepo = new MockPackageRepository();
                mockRepo.AddPackage(packageA);
                mockRepo.AddPackage(packageB);

                Dependencies.NuGetProjectManagerFactory = MockGenerator.CreateProjectManagerFactory(MockGenerator.CreateMockProjectManager(mockRepo, new MockPackageRepository()).Object);

                // act
                var project = new WebNuGetProject(new string[] { "http://dummyFeed" }, @"C:\DummyPath", null, MockGenerator.CreateWebProjectSystemFactory());
                var results = project.GetRemotePackages("");

                Assert.Equal(new IPackage[] { packageB, packageA }, results);

                packageA.DownloadCount = 2;

                results = project.GetRemotePackages("");
                Assert.Equal(new IPackage[] { packageA, packageB}, results);

            }
            public void EmptySearchTerms_ReturnsAllLocalPackages()
            {
                var packageA = new MockPackage { Id = "A" };
                var packageB = new MockPackage { Id = "B" };

                var mockRepo = new MockPackageRepository();
                mockRepo.AddPackage(packageA);
                mockRepo.AddPackage(packageB);

                Dependencies.NuGetProjectManagerFactory = MockGenerator.CreateProjectManagerFactory(MockGenerator.CreateMockProjectManager(new MockPackageRepository(), mockRepo).Object);

                // act
                var project = new WebNuGetProject(new string[] {"http://dummyFeed"}, @"C:\DummyPath", null, MockGenerator.CreateWebProjectSystemFactory());
                var results = project.GetInstalledPackages("");

                Assert.Equal(new IPackage[] { packageA, packageB}, results);
            }
            public void RemoveFromPackageManagerAfterRemovingFromProjectManager()
            {
                var package = new MockPackage();
                bool calledProjectManager = false;
                bool calledPackageManagerAfterProjectManager = false;

                var mockPackageMan = new Mock<IPackageManager>() { DefaultValue = DefaultValue.Mock };
                mockPackageMan.Setup(packMan => packMan.UninstallPackage(package, It.IsAny<bool>(), It.IsAny<bool>()))
                    .Callback(() => calledPackageManagerAfterProjectManager = calledProjectManager);

                var mockProjectMan = new Mock<IProjectManager>() { DefaultValue = DefaultValue.Mock };
                mockProjectMan.Setup(projMan => projMan.RemovePackageReference(It.IsAny<IPackage>(), false, true))
                    .Callback(() => calledProjectManager = true);

                Dependencies.NuGetPackageManagerFactory = MockGenerator.CreatePackageManagerFactory(mockPackageMan.Object);
                Dependencies.NuGetProjectManagerFactory = MockGenerator.CreateProjectManagerFactory(mockProjectMan.Object);

                // act
                WebNuGetProject project = new WebNuGetProject(new string[] { }, @"C:\DummyPath", null, MockGenerator.CreateWebProjectSystemFactory());
                var warnings = project.UninstallPackage(package, true);

                // assert
                Assert.True(calledPackageManagerAfterProjectManager);
            }