public void GetUpdatesDoesNotInvokeServiceMethodIfLocalRepositoryDoesNotHaveAnyPackages()
        {
            // Arrange
            var localRepo         = new MockPackageRepository();
            var serviceRepository = new Mock <IServiceBasedRepository>(MockBehavior.Strict);
            var remoteRepo        = serviceRepository.As <IPackageRepository>().Object;

            // Act
            remoteRepo.GetUpdates(localRepo.GetPackages(), includePrerelease: false, includeAllVersions: false);

            // Assert
            serviceRepository.Verify(s => s.GetUpdates(It.IsAny <IEnumerable <IPackage> >(), false, false, It.IsAny <IEnumerable <FrameworkName> >(), It.IsAny <IEnumerable <IVersionSpec> >()), Times.Never());
        }
Esempio n. 2
0
        public void InstallCommandUsesRemoteIfCacheHasOldDependencyVersion()
        {
            // Arrange
            var newPackageDependency = PackageUtility.CreatePackage("Foo", "1.1");
            var newPackage           = PackageUtility.CreatePackage("Foo.UI", "1.1",
                                                                    dependencies: new[] { new PackageDependency("Foo", VersionUtility.ParseVersionSpec("[1.1]")) });
            var repository = new MockPackageRepository {
                newPackageDependency, newPackage
            };
            var repositoryFactory = new Mock <IPackageRepositoryFactory>();

            repositoryFactory.Setup(r => r.CreateRepository("Some source")).Returns(repository);

            var fileSystem = new MockFileSystem();
            var localCache = new Mock <IPackageRepository>(MockBehavior.Strict);

            localCache.Setup(c => c.GetPackages()).Returns(new[] { PackageUtility.CreatePackage("Foo", "1.0") }.AsQueryable()).Verifiable();

            var localRepository = new MockPackageRepository();
            var installCommand  = new TestInstallCommand(
                repositoryFactory.Object,
                GetSourceProvider(new[] { new PackageSource("Some source", "Some source name") }),
                fileSystem,
                machineCacheRepository: localCache.Object,
                localRepository: localRepository)
            {
                NoCache = false,
                Version = "1.1"
            };

            installCommand.Arguments.Add("Foo.UI");
            installCommand.Source.Add("Some Source name");

            // Act
            installCommand.ExecuteCommand();

            // Assert
            var installedPackages = localRepository.GetPackages().ToList();

            Assert.Equal(2, installedPackages.Count);
            Assert.Same(newPackageDependency, installedPackages[0]);
            Assert.Same(newPackage, installedPackages[1]);
            localCache.Verify();
        }
Esempio n. 3
0
        public void FindPackagesReturnsPackagesWithTermInPackageTagOrDescriptionOrId()
        {
            // Arrange
            var term = "TAG";
            var repo = new MockPackageRepository();

            repo.Add(CreateMockPackage("A", "1.0", "Description", " TAG "));
            repo.Add(CreateMockPackage("B", "2.0", "Description", "Tags"));
            repo.Add(CreateMockPackage("C", "1.0", "This description has tags in it"));
            repo.Add(CreateMockPackage("D", "1.0", "Description"));
            repo.Add(CreateMockPackage("TagCloud", "1.0", "Description"));

            // Act
            var packages = repo.GetPackages().Find(term.Split()).ToList();

            // Assert
            Assert.AreEqual(3, packages.Count);
            Assert.AreEqual("A", packages[0].Id);
            Assert.AreEqual("C", packages[1].Id);
            Assert.AreEqual("TagCloud", packages[2].Id);
        }
Esempio n. 4
0
        public void GetUpdatesDoesNotInvokeServiceMethodIfLocalRepositoryDoesNotHaveAnyPackages()
        {
            // Arrange 
            var localRepo = new MockPackageRepository();
            var serviceRepository = new Mock<IServiceBasedRepository>(MockBehavior.Strict);
            var remoteRepo = serviceRepository.As<IPackageRepository>().Object;

            // Act
            var packages = remoteRepo.GetUpdates(localRepo.GetPackages(), includePrerelease: false, includeAllVersions: false);

            // Assert
            serviceRepository.Verify(s => s.GetUpdates(It.IsAny<IEnumerable<IPackage>>(), false, false, It.IsAny<IEnumerable<FrameworkName>>()), Times.Never());
        }
Esempio n. 5
0
        public void FindPackagesReturnsPackagesWithTermInPackageTagOrDescriptionOrId()
        {
            // Arrange
            var term = "TAG";
            var repo = new MockPackageRepository();
            repo.Add(CreateMockPackage("A", "1.0", "Description", " TAG "));
            repo.Add(CreateMockPackage("B", "2.0", "Description", "Tags"));
            repo.Add(CreateMockPackage("C", "1.0", "This description has tags in it"));
            repo.Add(CreateMockPackage("D", "1.0", "Description"));
            repo.Add(CreateMockPackage("TagCloud", "1.0", "Description"));

            // Act
            var packages = repo.GetPackages().Find(term).ToList();

            // Assert
            Assert.Equal(3, packages.Count);
            Assert.Equal("A", packages[0].Id);
            Assert.Equal("C", packages[1].Id);
            Assert.Equal("TagCloud", packages[2].Id);
        }
        public void CallingEnableCurrentSolutionWillAddPackagesToMachineCache()
        {
            // Arrange
            string tempSolutionPath = CreateTempFolder();

            // setup SolutionManager
            var solutionManager = new Mock<ISolutionManager>();
            solutionManager.Setup(p => p.IsSolutionOpen).Returns(true);
            solutionManager.Setup(p => p.SolutionDirectory).Returns(tempSolutionPath);

            // setup file system
            var fileSystem = new PhysicalFileSystem(tempSolutionPath);
            var fileSystemProvider = new Mock<IFileSystemProvider>();
            fileSystemProvider.Setup(p => p.GetFileSystem(tempSolutionPath)).Returns(fileSystem);

            var nugetFolderFileSystem = new PhysicalFileSystem(tempSolutionPath + "\\.nuget");
            fileSystemProvider.Setup(p => p.GetFileSystem(tempSolutionPath + "\\.nuget")).Returns(nugetFolderFileSystem);

            // setup DTE
            var dte = new Mock<DTE>();

            var projectItems = new Mock<ProjectItems>();
            var solutionFolder = new Mock<Project>();
            solutionFolder.Setup(s => s.Name).Returns(".nuget");
            solutionFolder.SetupGet(s => s.ProjectItems).Returns(projectItems.Object);

            var solution = new Mock<Solution>();
            solution.As<Solution2>().Setup(p => p.AddSolutionFolder(".nuget")).Returns(solutionFolder.Object);

            var projects = new MockProjects(new Project[0]);
            solution.As<Solution2>().Setup(s => s.Projects).Returns(projects);
            dte.SetupGet(p => p.Solution).Returns(solution.Object);

            // setup package repository
            var packageRepository = new MockPackageRepository();
            packageRepository.Add(PackageUtility.CreatePackage(
                "NuGet.Build",
                version: "1.0",
                tools: new string[] { "NuGet.targets" },
                dependencies: new PackageDependency[] { new PackageDependency("NuGet.CommandLine") }));
            packageRepository.Add(PackageUtility.CreatePackage(
                "NuGet.CommandLine",
                version: "2.0",
                tools: new string[] { "NuGet.exe" }));
            var packageRepositoryFactory = new Mock<IPackageRepositoryFactory>();
            packageRepositoryFactory.Setup(p => p.CreateRepository("x:\\nugetsource")).Returns(packageRepository);

            var packageSourceProvider = new Mock<IPackageSourceProvider>();
            packageSourceProvider.Setup(p => p.LoadPackageSources()).Returns(new[]
                                                                             {
                                                                                 new PackageSource("x:\\nugetsource")
                                                                             });
 
            var localCache = new MockPackageRepository();

            var packageRestore = CreateInstance(
                dte.Object,
                solutionManager.Object,
                fileSystemProvider.Object,
                packageRepositoryFactory.Object,
                localCache: localCache,
                packageSourceProvider: packageSourceProvider.Object);

            // Act 
            packageRestore.EnableCurrentSolutionForRestore(fromActivation: false);

            // Assert
            var cachePackages = localCache.GetPackages().ToList();
            Assert.Equal(2, cachePackages.Count);
            Assert.Equal("NuGet.Build", cachePackages[0].Id);
            Assert.Equal(new SemanticVersion("1.0"), cachePackages[0].Version);
            Assert.Equal("NuGet.CommandLine", cachePackages[1].Id);
            Assert.Equal(new SemanticVersion("2.0"), cachePackages[1].Version);
        }
Esempio n. 7
0
        public void CallingEnableCurrentSolutionWillAddPackagesToMachineCache()
        {
            // Arrange
            string tempSolutionPath = CreateTempFolder();

            // setup SolutionManager
            var solutionManager = new Mock <ISolutionManager>();

            solutionManager.Setup(p => p.IsSolutionOpen).Returns(true);
            solutionManager.Setup(p => p.SolutionDirectory).Returns(tempSolutionPath);

            // setup file system
            var fileSystem         = new PhysicalFileSystem(tempSolutionPath);
            var fileSystemProvider = new Mock <IFileSystemProvider>();

            fileSystemProvider.Setup(p => p.GetFileSystem(tempSolutionPath)).Returns(fileSystem);

            var nugetFolderFileSystem = new PhysicalFileSystem(tempSolutionPath + "\\.nuget");

            fileSystemProvider.Setup(p => p.GetFileSystem(tempSolutionPath + "\\.nuget")).Returns(nugetFolderFileSystem);

            // setup DTE
            var dte = new Mock <DTE>();

            var projectItems   = new Mock <ProjectItems>();
            var solutionFolder = new Mock <Project>();

            solutionFolder.Setup(s => s.Name).Returns(".nuget");
            solutionFolder.SetupGet(s => s.ProjectItems).Returns(projectItems.Object);

            var solution = new Mock <Solution>();

            solution.As <Solution2>().Setup(p => p.AddSolutionFolder(".nuget")).Returns(solutionFolder.Object);

            var projects = new MockProjects(new Project[0]);

            solution.As <Solution2>().Setup(s => s.Projects).Returns(projects);
            dte.SetupGet(p => p.Solution).Returns(solution.Object);

            // setup package repository
            var packageRepository = new MockPackageRepository();

            packageRepository.Add(PackageUtility.CreatePackage(
                                      "NuGet.Build",
                                      version: "1.0",
                                      tools: new string[] { "NuGet.targets" },
                                      dependencies: new PackageDependency[] { new PackageDependency("NuGet.CommandLine") }));
            packageRepository.Add(PackageUtility.CreatePackage(
                                      "NuGet.CommandLine",
                                      version: "2.0",
                                      tools: new string[] { "NuGet.exe" }));
            var packageRepositoryFactory = new Mock <IPackageRepositoryFactory>();

            packageRepositoryFactory.Setup(p => p.CreateRepository("x:\\nugetsource")).Returns(packageRepository);

            var packageSourceProvider = new Mock <IVsPackageSourceProvider>();

            packageSourceProvider.Setup(p => p.LoadPackageSources()).Returns(new[]
            {
                new PackageSource("x:\\nugetsource")
            });

            var localCache = new MockPackageRepository();

            var packageRestore = CreateInstance(
                dte.Object,
                solutionManager.Object,
                fileSystemProvider.Object,
                packageRepositoryFactory.Object,
                localCache: localCache,
                packageSourceProvider: packageSourceProvider.Object);

            // Act
            packageRestore.EnableCurrentSolutionForRestore(fromActivation: false);

            // Assert
            var cachePackages = localCache.GetPackages().ToList();

            Assert.Equal(2, cachePackages.Count);
            Assert.Equal("NuGet.Build", cachePackages[0].Id);
            Assert.Equal(new SemanticVersion("1.0"), cachePackages[0].Version);
            Assert.Equal("NuGet.CommandLine", cachePackages[1].Id);
            Assert.Equal(new SemanticVersion("2.0"), cachePackages[1].Version);
        }