예제 #1
0
            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);
            }
예제 #2
0
            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();
            }
예제 #3
0
            public void PackageAvailableFromLocal_InstallSucceeds()
            {
                // arrange
                var package = new MockPackage();
                var mockLocalRepository = new MockPackageRepository();
                var mockRemoteRepository = new MockPackageRepository();
                mockLocalRepository.AddPackage(package);

                var mockPackageManager = new Mock<IPackageManager>();
                var mockProjectManager = MockGenerator.CreateMockProjectManager(mockRemoteRepository, mockLocalRepository);
                mockProjectManager.Setup(pm => pm.AddPackageReference(package, It.IsAny<bool>(), It.IsAny<bool>())).Verifiable();

                Dependencies.NuGetPackageManagerFactory = MockGenerator.CreatePackageManagerFactory(mockPackageManager.Object);
                Dependencies.NuGetProjectManagerFactory = MockGenerator.CreateProjectManagerFactory(mockProjectManager.Object);
                Dependencies.NuGetProjectSystemFactory = MockGenerator.CreateProjectSystemFactory();

                // act
                NuGetCore core = new NuGetCore();
                var warnings = core.InstallPackage(@"C:\DummyPath", MockPackage.DefaultId, "http://dummyFeed", MockPackage.DefaultVersion.ToString());

                // assert
                mockProjectManager.Verify();
            }
예제 #4
0
            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);
            }
예제 #5
0
            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);
            }
예제 #6
0
            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);

            }
예제 #7
0
            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);
            }
예제 #8
0
            public void PackageAvailableFromRemote_UpdateSucceeds()
            {
                // arrange
                var updatedPackage = new MockPackage { Version = new SemanticVersion("2.0") };
                var mockLocalRepository = new MockPackageRepository();
                var mockRemoteRepository = new MockPackageRepository();
                mockLocalRepository.AddPackage(new MockPackage());
                mockRemoteRepository.AddPackage(updatedPackage);

                var mockPackageManager = MockGenerator.CreateMockPackageManager(mockRemoteRepository, mockLocalRepository);
                var mockProjectManager = MockGenerator.CreateMockProjectManager(mockRemoteRepository, mockLocalRepository);
                mockProjectManager.Setup(pm => pm.UpdatePackageReference(updatedPackage.Id, updatedPackage.Version, It.IsAny<bool>(), It.IsAny<bool>())).Verifiable();

                Dependencies.NuGetPackageManagerFactory = MockGenerator.CreatePackageManagerFactory(mockPackageManager.Object);
                Dependencies.NuGetProjectManagerFactory = MockGenerator.CreateProjectManagerFactory(mockProjectManager.Object);
                Dependencies.NuGetProjectSystemFactory = MockGenerator.CreateProjectSystemFactory();

                // act
                NuGetCore core = new NuGetCore();
                var warnings = core.UpdatePackage(@"C:\DummyPath", MockPackage.DefaultId, "http://dummyFeed", "2.0");

                // assert
                mockProjectManager.Verify();
            }
예제 #9
0
            public void DontSpecifyVersion_UpdatesToLatestPackage()
            {
                var latestPackage = new MockPackage { Version = new SemanticVersion("3.0") };
                var mockLocalRepository = new MockPackageRepository();
                var mockRemoteRepository = new MockPackageRepository();
                mockLocalRepository.AddPackage(new MockPackage());
                mockRemoteRepository.AddPackage(new MockPackage { Version = new SemanticVersion("2.0") });
                mockRemoteRepository.AddPackage(latestPackage);

                var mockPackageManager = MockGenerator.CreateMockPackageManager(mockRemoteRepository, mockLocalRepository);
                var mockProjectManager = MockGenerator.CreateMockProjectManager(mockRemoteRepository, mockLocalRepository);
                mockProjectManager.Setup(pm => pm.UpdatePackageReference(latestPackage.Id, latestPackage.Version, It.IsAny<bool>(), It.IsAny<bool>())).Verifiable();

                Dependencies.NuGetPackageManagerFactory = MockGenerator.CreatePackageManagerFactory(mockPackageManager.Object);
                Dependencies.NuGetProjectManagerFactory = MockGenerator.CreateProjectManagerFactory(mockProjectManager.Object);
                Dependencies.NuGetProjectSystemFactory = MockGenerator.CreateProjectSystemFactory();

                // act
                NuGetCore core = new NuGetCore();
                var warnings = core.UpdatePackage(@"C:\DummyPath", MockPackage.DefaultId, "http://dummyFeed", null);

                // assert
                mockProjectManager.Verify();
            }