Пример #1
0
        public void InstallingPackageWithUnknownDependencyAndIgnoreDepencenciesInstallsPackageWithoutDependencies()
        {
            // Arrange
            var localRepository  = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var projectSystem    = new MockProjectSystem();
            var packageManager   = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);

            IPackage packageA = PackageUtility.CreatePackage("A", "1.0",
                                                             dependencies: new List <PackageDependency> {
                new PackageDependency("C")
            });

            IPackage packageC = PackageUtility.CreatePackage("C", "1.0");

            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageC);

            // Act
            packageManager.InstallPackage("A", version: null, ignoreDependencies: true);

            // Assert
            Assert.IsTrue(localRepository.Exists(packageA));
            Assert.IsFalse(localRepository.Exists(packageC));
        }
Пример #2
0
        public void InstallCommandUpdatesPackageIfAlreadyPresentAndNotUsingSideBySide()
        {
            // Arrange
            var fileSystem = new MockFileSystem();
            var repository = new MockPackageRepository();

            var packageManager = new PackageManager(GetFactory().CreateRepository("Some source"), new DefaultPackagePathResolver(fileSystem), fileSystem, repository);
            var installCommand = new TestInstallCommand(GetFactory(), GetSourceProvider(), fileSystem, packageManager)
            {
                Console        = new MockConsole(),
                ExcludeVersion = true,
                Version        = "0.4",
            };

            installCommand.Arguments.Add("Baz");

            // Act - 1
            installCommand.ExecuteCommand();

            // Assert - 1
            Assert.True(repository.Exists("Baz", new SemanticVersion("0.4")));

            // Act - 2
            installCommand.Version = null;
            installCommand.Execute();

            // Assert - 2
            Assert.False(repository.Exists("Baz", new SemanticVersion("0.4")));
            Assert.True(repository.Exists("Baz", new SemanticVersion("0.7")));
        }
Пример #3
0
        public void InstallPackageInstallsLowerReleaseVersionIfPrereleaseFlagIsNotSet()
        {
            // Arrange
            var localRepository  = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var projectSystem    = new MockProjectSystem();
            var packageManager   = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);

            IPackage packageA = PackageUtility.CreatePackage("A", "1.0.0",
                                                             dependencies: new[] {
                new PackageDependency("C")
            });

            IPackage packageC_RC = PackageUtility.CreatePackage("C", "1.0.0-RC-1");
            IPackage packageC    = PackageUtility.CreatePackage("C", "0.9");

            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageC);
            sourceRepository.AddPackage(packageC_RC);

            // Act
            packageManager.InstallPackage("A", version: null, ignoreDependencies: false, allowPrereleaseVersions: false);

            // Assert
            Assert.True(localRepository.Exists(packageA));
            Assert.True(localRepository.Exists(packageC));
        }
Пример #4
0
        public void InstallPackageDoesNotPerformWalkInfoCheckWhenPassingTheFlag()
        {
            // In this test, we simulate installing a solution-level package which depends on
            // a project-level package. Under normal condition, this is disallowed by NuGet.
            // However, if passing the 'ignoreWalkInfo' parameter with value of 'true',
            // NuGet will happily accept that. Hence the installation will succeed.
            // This is used by the package restore mode.

            var localRepository  = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var projectSystem    = new MockProjectSystem();
            var packageManager   = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);

            // A is solution-level package
            IPackage packageA = PackageUtility.CreatePackage("A", "1.0.0",
                                                             tools: new string[] { "init.ps1" },
                                                             dependencies: new[] {
                new PackageDependency("C")
            });

            IPackage packageC = PackageUtility.CreatePackage("C", "1.0.0-RC-1", content: new string[] { "a.txt" });

            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageC);

            // Act
            packageManager.InstallPackage(packageA, ignoreDependencies: false, allowPrereleaseVersions: true, ignoreWalkInfo: true);

            // Assert
            Assert.True(localRepository.Exists(packageA));
            Assert.True(localRepository.Exists(packageC));
        }
Пример #5
0
        public void InstallPackageConsidersAlreadyInstalledPrereleasePackagesWhenResolvingDependencies()
        {
            // Arrange
            var packageB_05  = PackageUtility.CreatePackage("B", "0.5.0");
            var packageB_10a = PackageUtility.CreatePackage("B", "1.0.0-a");
            var packageA     = PackageUtility.CreatePackage("A",
                                                            dependencies: new[] { new PackageDependency("B", VersionUtility.ParseVersionSpec("[0.5.0, 2.0.0)")) });

            var localRepository  = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var projectSystem    = new MockProjectSystem();
            var packageManager   = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);

            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageB_10a);
            sourceRepository.AddPackage(packageB_05);

            // Act
            // The allowPrereleaseVersions flag should be irrelevant since we specify a version.
            packageManager.InstallPackage("B", version: new SemanticVersion("1.0.0-a"), ignoreDependencies: false, allowPrereleaseVersions: false);
            // Verify we actually did install B.1.0.0a
            Assert.True(localRepository.Exists(packageB_10a));

            packageManager.InstallPackage("A");

            // Assert
            Assert.True(localRepository.Exists(packageA));
            Assert.True(localRepository.Exists(packageB_10a));
        }
Пример #6
0
        public void InstallPackageDisregardTargetFrameworkOfDependencies()
        {
            // Arrange
            var localRepository  = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var projectSystem    = new MockProjectSystem();
            var packageManager   = new PackageManager(
                sourceRepository,
                new DefaultPackagePathResolver(projectSystem),
                projectSystem,
                localRepository);

            IPackage packageA = PackageUtility.CreatePackage("A", "1.0.0",
                                                             dependencies: new[] {
                new PackageDependency("C", null)
            });

            IPackage packageC = PackageUtility.CreatePackage("C", "1.0.0");

            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageC);

            // Act
            packageManager.InstallPackage("A", version: null, ignoreDependencies: false, allowPrereleaseVersions: true);

            // Assert
            Assert.True(localRepository.Exists(packageA));
            Assert.True(localRepository.Exists(packageC));
        }
Пример #7
0
        public void InstallPackageInstallsSemVer200PrereleasePackageWithVersionGiven()
        {
            // Arrange
            var localRepository  = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var projectSystem    = new MockProjectSystem();
            var packageManager   = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);

            IPackage packageA = PackageUtility.CreatePackage("A", "1.0.0-beta.1.2+git.hash.21d2b3f0acb1c8ffe9909bf2f1cbed2273414e58",
                                                             dependencies: new[] {
                new PackageDependency("C", VersionUtility.ParseVersionSpec("2.0.0-beta.2.2+other.data"))
            });

            IPackage packageC = PackageUtility.CreatePackage("C", "2.0.0-beta.2.2+git.hash.a1d2b3f0acb1c8ffe9909bf2f1cbed2273414e58");

            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageC);

            // Act
            packageManager.InstallPackage("A", version: SemanticVersion.Parse("1.0.0-beta.1.2+other.data"), ignoreDependencies: false, allowPrereleaseVersions: true);

            // Assert
            Assert.True(localRepository.Exists(packageA));
            Assert.True(localRepository.Exists(packageC));
        }
Пример #8
0
        public void UninstallingPackageUninstallsPackageButNotDependencies()
        {
            // Arrange
            var localRepository  = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var projectSystem    = new MockProjectSystem();
            var packageManager   = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);

            IPackage packageA = PackageUtility.CreatePackage("A", "1.0",
                                                             dependencies: new List <PackageDependency> {
                new PackageDependency("B")
            });

            IPackage packageB = PackageUtility.CreatePackage("B", "1.0");

            localRepository.AddPackage(packageA);
            localRepository.AddPackage(packageB);

            // Act
            packageManager.UninstallPackage("A");

            // Assert
            Assert.False(localRepository.Exists(packageA));
            Assert.True(localRepository.Exists(packageB));
        }
Пример #9
0
        public void ReInstallingPackageAfterUninstallingDependencyShouldReinstallAllDependencies()
        {
            // Arrange
            var            localRepository  = new MockPackageRepository();
            var            sourceRepository = new MockPackageRepository();
            var            projectSystem    = new MockProjectSystem();
            PackageManager packageManager   = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);

            IPackage packageA = PackageUtility.CreatePackage("A", "1.0",
                                                             dependencies: new List <PackageDependency> {
                new PackageDependency("B")
            });

            IPackage packageB = PackageUtility.CreatePackage("B", "1.0",
                                                             dependencies: new List <PackageDependency> {
                new PackageDependency("C")
            });

            var packageC = PackageUtility.CreatePackage("C", "1.0");

            localRepository.AddPackage(packageA);
            localRepository.AddPackage(packageB);

            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageB);
            sourceRepository.AddPackage(packageC);

            // Act
            packageManager.InstallPackage("A");

            // Assert
            Assert.IsTrue(localRepository.Exists(packageA));
            Assert.IsTrue(localRepository.Exists(packageB));
            Assert.IsTrue(localRepository.Exists(packageC));
        }
Пример #10
0
        public void UpdatePackageWillAskForEachFileWhenThereAreFileConflict()
        {
            // Arrange
            var localRepository    = new MockPackageRepository();
            var sourceRepository   = new MockPackageRepository();
            var constraintProvider = NullConstraintProvider.Instance;
            var fileSystem         = new MockFileSystem();
            var pathResolver       = new DefaultPackagePathResolver(fileSystem);
            var projectSystem      = new MockProjectSystem();

            projectSystem.AddFile("one.txt", "this is one");
            projectSystem.AddFile("two.txt", "this is two");

            var packages    = new List <IPackage>();
            var package_A10 = PackageUtility.CreatePackage("A", "1.0", content: new[] { "1.txt" });
            var package_A12 = PackageUtility.CreatePackage("A", "1.2", content: new[] { "one.txt", "two.txt" });

            localRepository.Add(package_A10);
            sourceRepository.Add(package_A12);

            var sharedRepository = new Mock <ISharedPackageRepository>(MockBehavior.Strict);

            sharedRepository.Setup(s => s.AddPackage(package_A12)).Callback <IPackage>(p => packages.Add(p));
            sharedRepository.Setup(s => s.GetPackages()).Returns(packages.AsQueryable());

            var repositoryFactory = new Mock <IPackageRepositoryFactory>();

            repositoryFactory.Setup(s => s.CreateRepository(It.IsAny <string>())).Returns(sourceRepository);

            var packageSourceProvider = new Mock <IPackageSourceProvider>();

            packageSourceProvider.Setup(s => s.LoadPackageSources()).Returns(new[] { new PackageSource("foo-source") });

            var answers = new[] {
                FileConflictResolution.Overwrite,
                FileConflictResolution.Ignore,
            };

            int cursor  = 0;
            var console = new Mock <IConsole>();

            console.Setup(c => c.ResolveFileConflict(It.IsAny <string>())).Returns(() => answers[cursor++]);

            var updateCommand = new UpdateCommand()
            {
                RepositoryFactory = repositoryFactory.Object,
                SourceProvider    = packageSourceProvider.Object,
                Console           = console.Object,
            };

            // Act
            updateCommand.UpdatePackages(localRepository, fileSystem, sharedRepository.Object, sourceRepository, constraintProvider, pathResolver, projectSystem);

            // Assert
            Assert.True(localRepository.Exists("A", new SemanticVersion("1.2")));
            Assert.Equal("content\\one.txt", projectSystem.ReadAllText("one.txt"));
            Assert.Equal("this is two", projectSystem.ReadAllText("two.txt"));

            Assert.Equal(2, cursor);
        }
Пример #11
0
        public void CanExecuteReturnsCorrectResult()
        {
            // Local repository contains Package A and Package B
            // We test the CanExecute() method on Package A and Package C

            // Arrange
            var repository = new MockPackageRepository();

            var packageA = PackageUtility.CreatePackage("A", "1.0");
            repository.AddPackage(packageA);

            var packageB = PackageUtility.CreatePackage("B", "2.0");
            repository.AddPackage(packageB);

            var packageC = PackageUtility.CreatePackage("C", "2.0");

            var projectManager = new Mock<IProjectManager>();
            projectManager.Setup(p => p.IsInstalled(It.IsAny<IPackage>())).Returns<IPackage>(p => repository.Exists(p));

            var provider = CreateInstalledProvider(null, projectManager.Object);

            var extensionA = new PackageItem(provider, packageA, null);
            var extensionC = new PackageItem(provider, packageC, null);

            // Act
            bool canExecuteA = provider.CanExecute(extensionA);
            bool canExecuteC = provider.CanExecute(extensionC);

            // Assert
            Assert.IsTrue(canExecuteA);
            Assert.IsFalse(canExecuteC);
        }
Пример #12
0
        public void EnsurePackageDownloadsThePackageIfItIsNotCachedInMemoryOnInMachineCache()
        {
            // Arrange
            var zipPackage        = PackageUtility.CreatePackage("A", "1.2");
            var uri               = new Uri("http://nuget.org");
            var packageDownloader = new Mock <PackageDownloader>();

            packageDownloader.Setup(d => d.DownloadPackage(uri, It.IsAny <IPackageMetadata>()))
            .Returns(zipPackage)
            .Verifiable();
            var hashProvider   = new Mock <IHashProvider>(MockBehavior.Strict);
            var mockRepository = new MockPackageRepository();
            var context        = new Mock <IDataServiceContext>();

            context.Setup(c => c.GetReadStreamUri(It.IsAny <object>())).Returns(uri).Verifiable();

            var servicePackage = new DataServicePackage
            {
                Id           = "A",
                Version      = "1.2",
                PackageHash  = "NEWHASH",
                Downloader   = packageDownloader.Object,
                HashProvider = hashProvider.Object,
                Context      = context.Object
            };

            // Act
            servicePackage.EnsurePackage(mockRepository);

            // Assert
            context.Verify();
            packageDownloader.Verify();
            Assert.True(mockRepository.Exists(zipPackage));
        }
Пример #13
0
        public void InstallPackageNotifiesBatchProcessorWhenExpandingPackageFiles()
        {
            // Arrange
            var package = PackageUtility.CreatePackage("B", "0.5.0", content: new[] { "content.txt" }, assemblyReferences: new[] { "Ref.dll" });

            var localRepository  = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var fileSystem       = new Mock <MockFileSystem> {
                CallBase = true
            };
            var batchProcessor = fileSystem.As <IBatchProcessor <string> >();

            batchProcessor.Setup(s => s.BeginProcessing(It.IsAny <IEnumerable <string> >(), PackageAction.Install))
            .Callback((IEnumerable <string> files, PackageAction _) => Assert.Equal(new[] { @"content\content.txt", "Ref.dll" }, files))
            .Verifiable();
            batchProcessor.Setup(s => s.EndProcessing()).Verifiable();

            var packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(fileSystem.Object), fileSystem.Object, localRepository);

            sourceRepository.AddPackage(package);

            // Act
            packageManager.InstallPackage("B");

            // Assert
            Assert.True(localRepository.Exists(package));
            batchProcessor.Verify();
        }
Пример #14
0
        public void UpdatePackageUninstallsPackageAndInstallsNewPackage()
        {
            // Arrange
            var            localRepository  = new MockPackageRepository();
            var            sourceRepository = new MockPackageRepository();
            var            projectSystem    = new MockProjectSystem();
            PackageManager packageManager   = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);

            IPackage A10 = PackageUtility.CreatePackage("A", "1.0");
            IPackage A20 = PackageUtility.CreatePackage("A", "2.0");

            localRepository.Add(A10);
            sourceRepository.Add(A20);

            // Act
            packageManager.UpdatePackage("A", updateDependencies: true);

            // Assert
            Assert.IsFalse(localRepository.Exists("A", new Version("1.0")));
            Assert.IsTrue(localRepository.Exists("A", new Version("2.0")));
        }
Пример #15
0
        public void InstallingPackageWithUnknownDependencyAndIgnoreDepencenciesInstallsPackageWithoutDependencies()
        {
            // Arrange
            var localRepository = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem();
            var packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);

            IPackage packageA = PackageUtility.CreatePackage("A", "1.0",
                                                            dependencies: new List<PackageDependency> {
                                                                 new PackageDependency("C")
                                                             });

            IPackage packageC = PackageUtility.CreatePackage("C", "1.0");
            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageC);

            // Act
            packageManager.InstallPackage("A", version: null, ignoreDependencies: true, allowPrereleaseVersions: true);

            // Assert
            Assert.True(localRepository.Exists(packageA));
            Assert.False(localRepository.Exists(packageC));
        }
Пример #16
0
        public void UpdatePackageDoesNothingIfNoUpdatesAvailable()
        {
            // Arrange
            var            localRepository  = new MockPackageRepository();
            var            sourceRepository = new MockPackageRepository();
            var            projectSystem    = new MockProjectSystem();
            PackageManager packageManager   = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);

            IPackage A10 = PackageUtility.CreatePackage("A", "1.0");

            localRepository.Add(A10);

            // Act
            packageManager.UpdatePackage("A", updateDependencies: true);

            // Assert
            Assert.IsTrue(localRepository.Exists("A", new Version("1.0")));
        }
Пример #17
0
        public void CanExecuteReturnsCorrectResult()
        {
            // Arrange

            var packageA = PackageUtility.CreatePackage("A", "1.0");
            var packageB = PackageUtility.CreatePackage("B", "2.0");
            var packageC = PackageUtility.CreatePackage("C", "3.0");

            var sourceRepository = new MockPackageRepository();
            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageC);
            sourceRepository.AddPackage(packageB);

            var localRepository = new MockPackageRepository();
            localRepository.AddPackage(packageA);

            var projectManager = new Mock<IProjectManager>();
            projectManager.Setup(p => p.IsInstalled(It.IsAny<IPackage>())).Returns<IPackage>(p => localRepository.Exists(p));

            var packageManager = new Mock<IVsPackageManager>();
            packageManager.Setup(p => p.SourceRepository).Returns(sourceRepository);

            var provider = CreateOnlineProvider(packageManager.Object, projectManager.Object);

            var extensionA = new PackageItem(provider, packageA, null);
            var extensionB = new PackageItem(provider, packageB, null);
            var extensionC = new PackageItem(provider, packageC, null);

            // Act
            bool canExecuteA = provider.CanExecute(extensionA);
            bool canExecuteB = provider.CanExecute(extensionB);
            bool canExecuteC = provider.CanExecute(extensionC);

            // Assert
            Assert.IsTrue(canExecuteC);
            Assert.IsTrue(canExecuteB);
            Assert.IsFalse(canExecuteA);
        }
Пример #18
0
        public void AddPackageReferenceAddingPackageWithDuplicateReferenceOverwritesReference()
        {
            // Arrange
            var projectSystem = new MockProjectSystem();
            var localRepository = new MockPackageRepository();
            var mockRepository = new MockPackageRepository();
            var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
            var packageA = PackageUtility.CreatePackage("A", "1.0",
                                                        assemblyReferences: new[] { "reference.dll" });
            var packageB = PackageUtility.CreatePackage("B", "1.0",
                                                        assemblyReferences: new[] { "reference.dll" });

            mockRepository.AddPackage(packageA);
            mockRepository.AddPackage(packageB);

            // Act
            projectManager.AddPackageReference("A");
            projectManager.AddPackageReference("B");

            // Assert
            Assert.Equal(0, projectSystem.Paths.Count);
            Assert.Equal(1, projectSystem.References.Count);
            Assert.True(projectSystem.References.ContainsKey(@"reference.dll"));
            Assert.True(projectSystem.References.ContainsValue(@"MockFileSystem\B.1.0\reference.dll"));
            Assert.True(localRepository.Exists("A"));
            Assert.True(localRepository.Exists("B"));
        }
Пример #19
0
        public void AddPackageReferenceAddsContentAndReferencesProjectSystem()
        {
            // Arrange
            var projectSystem = new MockProjectSystem();
            var localRepository = new MockPackageRepository();
            var mockRepository = new MockPackageRepository();
            var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
            var packageA = PackageUtility.CreatePackage("A", "1.0",
                                                        new[] { "contentFile" },
                                                        new[] { "reference.dll" },
                                                        new[] { "tool" });

            mockRepository.AddPackage(packageA);

            // Act
            projectManager.AddPackageReference("A");

            // Assert
            Assert.Equal(1, projectSystem.Paths.Count);
            Assert.Equal(1, projectSystem.References.Count);
            Assert.True(projectSystem.References.ContainsKey(@"reference.dll"));
            Assert.True(projectSystem.FileExists(@"contentFile"));
            Assert.True(localRepository.Exists("A"));
        }
Пример #20
0
        public void CanExecuteReturnsCorrectResult()
        {
            // Local repository contains Package A and Package B
            // We test the CanExecute() method on Package A and Package C

            // Arrange
            var repository = new MockPackageRepository();

            var packageA = PackageUtility.CreatePackage("A", "1.0");

            repository.AddPackage(packageA);

            var packageB = PackageUtility.CreatePackage("B", "2.0");

            repository.AddPackage(packageB);

            var packageC = PackageUtility.CreatePackage("C", "2.0");

            var projectManager = new Mock <IProjectManager>();

            projectManager.Setup(p => p.IsInstalled(It.IsAny <IPackage>())).Returns <IPackage>(p => repository.Exists(p));

            var provider = CreateInstalledProvider(null, projectManager.Object);

            var extensionA = new PackageItem(provider, packageA, null);
            var extensionC = new PackageItem(provider, packageC, null);

            // Act
            bool canExecuteA = provider.CanExecute(extensionA);
            bool canExecuteC = provider.CanExecute(extensionC);

            // Assert
            Assert.IsTrue(canExecuteA);
            Assert.IsFalse(canExecuteC);
        }
Пример #21
0
        public void AddPackageReferenceAddsContentAccordingToTargetFramework3()
        {
            // Arrange
            var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework", new Version("2.0")));
            var localRepository = new MockPackageRepository();
            var mockRepository = new MockPackageRepository();
            var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
            var packageA = PackageUtility.CreatePackage("A", "1.0",
                                                        new[] { "sl3\\contentFile", "winrt45\\jQuery.js" },
                                                        new[] { "lib\\reference.dll" });

            mockRepository.AddPackage(packageA);

            // Act
            projectManager.AddPackageReference("A");

            // Assert
            Assert.Equal(0, projectSystem.Paths.Count);
            Assert.True(localRepository.Exists("A"));
        }
Пример #22
0
        public void AddPackageReferenceAllowsAddingMetadataPackage()
        {
            // Arrange
            var projectSystem = new MockProjectSystem();
            var localRepository = new MockPackageRepository();
            var mockRepository = new MockPackageRepository();
            var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
            
            var packageA = PackageUtility.CreatePackage("A", "1.0", new [] { "hello.txt" });
            var packageB = PackageUtility.CreatePackage("B", "2.0", dependencies: new[] { new PackageDependency("A") });

            var mockPackageB = Mock.Get(packageB);
            var files = PackageUtility.CreateFiles(new[] { "readme.txt", "foo.bar" });
            mockPackageB.Setup(p => p.GetFiles()).Returns(files);
            
            mockRepository.AddPackage(packageA);
            mockRepository.AddPackage(packageB);

            // Act
            projectManager.AddPackageReference("B");

            // Assert
            Assert.True(localRepository.Exists("A"));
            Assert.True(localRepository.Exists("B"));
        }
Пример #23
0
        public void AddPackageReferenceWithAnyNonCompatibleReferenceThrowsAndPackageIsNotReferenced()
        {
            // Arrange
            var mockProjectSystem = new Mock<MockProjectSystem>() { CallBase = true };
            var localRepository = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(mockProjectSystem.Object), mockProjectSystem.Object, localRepository);
            mockProjectSystem.Setup(m => m.TargetFramework).Returns(new FrameworkName(".NETFramework", new Version("2.0")));
            var mockPackage = new Mock<IPackage>();
            mockPackage.Setup(m => m.Id).Returns("A");
            mockPackage.Setup(m => m.Version).Returns(new SemanticVersion("1.0"));
            mockPackage.Setup(m => m.Listed).Returns(true);
            var assemblyReference = PackageUtility.CreateAssemblyReference("foo.dll", new FrameworkName(".NETFramework", new Version("5.0")));
            mockPackage.Setup(m => m.AssemblyReferences).Returns(new[] { assemblyReference });
            sourceRepository.AddPackage(mockPackage.Object);

            // Act & Assert            
            ExceptionAssert.Throws<InvalidOperationException>(
                () => projectManager.AddPackageReference("A"), 
                "Could not install package 'A 1.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v2.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.");
            Assert.False(localRepository.Exists(mockPackage.Object));
        }
Пример #24
0
        public void AddPackageAskToResolveConflictForEveryFileWithDependency()
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var localRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem();
            projectSystem.AddFile("one.txt", "this is one");
            projectSystem.AddFile("two.txt", "this is two");

            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
            IPackage packageA = PackageUtility.CreatePackage(
                "A", "1.0", content: new[] { "one.txt" }, dependencies: new PackageDependency[] { new PackageDependency("B") });
            sourceRepository.AddPackage(packageA);

            IPackage packageB = PackageUtility.CreatePackage("B", "1.0", content: new[] { "two.txt" });
            sourceRepository.AddPackage(packageB);

            var logger = new Mock<ILogger>();
            logger.Setup(l => l.ResolveFileConflict(It.IsAny<string>())).Returns(FileConflictResolution.OverwriteAll);
            projectManager.Logger = projectSystem.Logger = logger.Object;

            // Act
            projectManager.AddPackageReference("A");

            // Assert
            Assert.True(localRepository.Exists("A"));
            Assert.Equal("content\\one.txt", projectSystem.ReadAllText("one.txt"));
            Assert.Equal("content\\two.txt", projectSystem.ReadAllText("two.txt"));

            logger.Verify(l => l.ResolveFileConflict(It.IsAny<string>()), Times.Exactly(2));
        }
Пример #25
0
        public void AddPackageReferenceAcceptsMetaPackage()
        {
            // Arrange
            var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework", new Version("4.0")));
            var localRepository = new MockPackageRepository();
            var mockRepository = new MockPackageRepository();
            var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
            var packageA = PackageUtility.CreatePackage("A", "1.0", dependencies: new [] { new PackageDependency("B") });
            var packageB = PackageUtility.CreatePackage("B", "1.0-alpha", new [] { "net\\hello.txt" });
            mockRepository.AddPackage(packageA);
            mockRepository.AddPackage(packageB);

            // Act
            projectManager.AddPackageReference("A", version: null, ignoreDependencies: false, allowPrereleaseVersions: true);

            // Assert
            Assert.True(localRepository.Exists("A"));
            Assert.True(localRepository.Exists("B"));
        }
Пример #26
0
        public void AddPackageReferenceRecognizeEmptyFrameworkFolder2()
        {
            // Arrange
            var projectSystem = new MockProjectSystem(new FrameworkName("Silverlight", new Version("4.0")));
            var localRepository = new MockPackageRepository();
            var mockRepository = new MockPackageRepository();
            var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
            var packageA = PackageUtility.CreatePackage("A", "1.0",
                                                        new[] { "sl20\\contentFile", "sl20\\sub\\no.txt", "sl3\\_._", "foo.css" },
                                                        new[] { "reference.dll" });

            mockRepository.AddPackage(packageA);

            // Act
            projectManager.AddPackageReference("A");

            // Assert
            Assert.Equal(0, projectSystem.Paths.Count);
            Assert.False(projectSystem.FileExists(@"_._"));
            Assert.True(localRepository.Exists("A"));
        }
Пример #27
0
        public void AddPackageReferenceThrowsIfThereIsNoCompatibleFrameworkFolderUnderContentAndLib()
        {
            // Arrange
            var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework", new Version("4.0")));
            var localRepository = new MockPackageRepository();
            var mockRepository = new MockPackageRepository();
            var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
            var packageA = PackageUtility.CreatePackage("A", "1.0",
                                                        content: new[] { "silverlight\\reference.txt" },
                                                        assemblyReferences: new string[] { "lib\\windows8\\one.dll" });

            mockRepository.AddPackage(packageA);

            // Act
            ExceptionAssert.Throws<InvalidOperationException>(() => projectManager.AddPackageReference("A"));

            // Assert
            Assert.False(localRepository.Exists("A"));
        }
        public void ExecuteMethodCallsUninstallPackageMethodOnPackageManager()
        {
            // Arrange
            var packageA = PackageUtility.CreatePackage("A", "1.0");
            var packageB = PackageUtility.CreatePackage("B", "2.0");
            var packageC = PackageUtility.CreatePackage("C", "3.0");

            var sourceRepository = new MockPackageRepository();

            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageC);
            sourceRepository.AddPackage(packageB);

            var localRepository = new MockPackageRepository();

            localRepository.AddPackage(packageB);

            var projectManager1 = new Mock <IProjectManager>();

            projectManager1.Setup(p => p.LocalRepository).Returns(localRepository);
            projectManager1.Setup(p => p.IsInstalled(It.IsAny <IPackage>())).Returns <IPackage>(p => localRepository.Exists(p));

            var projectManager2 = new Mock <IProjectManager>();

            projectManager2.Setup(p => p.LocalRepository).Returns(localRepository);
            projectManager2.Setup(p => p.IsInstalled(It.IsAny <IPackage>())).Returns <IPackage>(p => localRepository.Exists(p));

            var project1 = MockProjectUtility.CreateMockProject("Project1");
            var project2 = MockProjectUtility.CreateMockProject("Project2");

            var packageManager = new Mock <IVsPackageManager>();

            packageManager.Setup(p => p.SourceRepository).Returns(sourceRepository);
            packageManager.Setup(p => p.GetProjectManager(It.Is <Project>(s => s == project1))).Returns(projectManager1.Object);
            packageManager.Setup(p => p.GetProjectManager(It.Is <Project>(s => s == project2))).Returns(projectManager2.Object);
            packageManager.Setup(p => p.IsProjectLevel(It.IsAny <IPackage>())).Returns(true);

            var solutionManager = new Mock <ISolutionManager>();

            solutionManager.Setup(p => p.GetProject(It.Is <string>(s => s == "Project1"))).Returns(project1);
            solutionManager.Setup(p => p.GetProject(It.Is <string>(s => s == "Project2"))).Returns(project2);
            solutionManager.Setup(p => p.GetProjects()).Returns(new Project[] { project1, project2 });

            var mockWindowService = new Mock <IUserNotifierServices>();

            mockWindowService.Setup(p => p.ShowProjectSelectorWindow(
                                        It.IsAny <string>(),
                                        It.IsAny <IPackage>(),
                                        It.IsAny <Predicate <Project> >(),
                                        It.IsAny <Predicate <Project> >())).Returns(Enumerable.Empty <Project>());

            var provider      = CreateSolutionInstalledProvider(packageManager.Object, localRepository, solutionManager: solutionManager.Object, userNotifierServices: mockWindowService.Object);
            var extensionTree = provider.ExtensionsTree;

            var firstTreeNode = (SimpleTreeNode)extensionTree.Nodes[0];

            provider.SelectedNode = firstTreeNode;

            var manualEvent = new ManualResetEventSlim(false);

            provider.ExecuteCompletedCallback = delegate
            {
                // Assert
                packageManager.Verify(p => p.UninstallPackage(
                                          projectManager1.Object,
                                          packageB.Id,
                                          null,
                                          false,
                                          false,
                                          provider),
                                      Times.Once());

                packageManager.Verify(p => p.UninstallPackage(
                                          projectManager2.Object,
                                          packageB.Id,
                                          null,
                                          false,
                                          false,
                                          provider),
                                      Times.Once());

                manualEvent.Set();
            };

            var extensionB = new PackageItem(provider, packageB);

            // Act
            provider.Execute(extensionB);

            // do not allow the method to return
            manualEvent.Wait();
        }
Пример #29
0
        public void ExecuteMethodCallsUninstallPackageMethodOnPackageManager()
        {
            // Arrange
            var packageA = PackageUtility.CreatePackage("A", "1.0");
            var packageB = PackageUtility.CreatePackage("B", "2.0");
            var packageC = PackageUtility.CreatePackage("C", "3.0");

            var sourceRepository = new MockPackageRepository();
            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageC);
            sourceRepository.AddPackage(packageB);

            var localRepository = new MockPackageRepository();
            localRepository.AddPackage(packageB);

            var projectManager1 = new Mock<IProjectManager>();
            projectManager1.Setup(p => p.LocalRepository).Returns(localRepository);
            projectManager1.Setup(p => p.IsInstalled(It.IsAny<IPackage>())).Returns<IPackage>(p => localRepository.Exists(p));

            var projectManager2 = new Mock<IProjectManager>();
            projectManager2.Setup(p => p.LocalRepository).Returns(localRepository);
            projectManager2.Setup(p => p.IsInstalled(It.IsAny<IPackage>())).Returns<IPackage>(p => localRepository.Exists(p));

            var project1 = MockProjectUtility.CreateMockProject("Project1");
            var project2 = MockProjectUtility.CreateMockProject("Project2");

            var packageManager = new Mock<IVsPackageManager>();
            packageManager.Setup(p => p.SourceRepository).Returns(sourceRepository);
            packageManager.Setup(p => p.GetProjectManager(It.Is<Project>(s => s == project1))).Returns(projectManager1.Object);
            packageManager.Setup(p => p.GetProjectManager(It.Is<Project>(s => s == project2))).Returns(projectManager2.Object);
            packageManager.Setup(p => p.IsProjectLevel(It.IsAny<IPackage>())).Returns(true);

            var solutionManager = new Mock<ISolutionManager>();
            solutionManager.Setup(p => p.GetProject(It.Is<string>(s => s == "Project1"))).Returns(project1);
            solutionManager.Setup(p => p.GetProject(It.Is<string>(s => s == "Project2"))).Returns(project2);
            solutionManager.Setup(p => p.GetProjects()).Returns(new Project[] { project1, project2 });

            var mockWindowService = new Mock<IUserNotifierServices>();
            mockWindowService.Setup(p => p.ShowProjectSelectorWindow(
                It.IsAny<string>(),
                It.IsAny<IPackage>(),
                It.IsAny<Predicate<Project>>(),
                It.IsAny<Predicate<Project>>())).Returns(Enumerable.Empty<Project>());

            var provider = CreateSolutionInstalledProvider(packageManager.Object, localRepository, solutionManager: solutionManager.Object, userNotifierServices: mockWindowService.Object);
            var extensionTree = provider.ExtensionsTree;

            var firstTreeNode = (SimpleTreeNode)extensionTree.Nodes[0];
            provider.SelectedNode = firstTreeNode;

            var manualEvent = new ManualResetEventSlim(false);

            provider.ExecuteCompletedCallback = delegate
            {
                // Assert
                packageManager.Verify(p => p.UninstallPackage(
                    projectManager1.Object,
                    packageB.Id,
                    null,
                    false,
                    false,
                    provider),
                    Times.Once());

                packageManager.Verify(p => p.UninstallPackage(
                    projectManager2.Object,
                    packageB.Id,
                    null,
                    false,
                    false,
                    provider),
                    Times.Once());

                manualEvent.Set();
            };

            var extensionB = new PackageItem(provider, packageB);

            // Act
            provider.Execute(extensionB);

            // do not allow the method to return
            manualEvent.Wait();
        }
Пример #30
0
        public void AddPackageWithUnsupportedTransformFileSkipsUnsupportedFile()
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var localRepository = new MockPackageRepository();
            var projectSystem = new Mock<MockProjectSystem>() { CallBase = true };
            projectSystem.Setup(m => m.IsSupportedFile("unsupported")).Returns(false);
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem.Object), projectSystem.Object, localRepository);
            IPackage packageA = PackageUtility.CreatePackage("A", "1.0", new[] { "a", "b", "unsupported.pp" });
            sourceRepository.AddPackage(packageA);

            // Act
            projectManager.AddPackageReference("A");

            // Assert
            Assert.Equal(2, projectSystem.Object.Paths.Count);
            Assert.True(projectSystem.Object.FileExists("a"));
            Assert.True(projectSystem.Object.FileExists("b"));
            Assert.True(localRepository.Exists("A"));
            Assert.False(projectSystem.Object.FileExists("unsupported"));
        }
Пример #31
0
        public void InstallPackageDisregardTargetFrameworkOfDependencies()
        {
            // Arrange
            var localRepository = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem();
            var packageManager = new PackageManager(
                sourceRepository, 
                new DefaultPackagePathResolver(projectSystem), 
                projectSystem, 
                localRepository);

            IPackage packageA = PackageUtility.CreatePackage("A", "1.0.0",
                                                             dependencies: new[] {
                                                                 new PackageDependency("C", null)
                                                             });

            IPackage packageC = PackageUtility.CreatePackage("C", "1.0.0");
            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageC);

            // Act
            packageManager.InstallPackage("A", version: null, ignoreDependencies: false, allowPrereleaseVersions: true);

            // Assert
            Assert.True(localRepository.Exists(packageA));
            Assert.True(localRepository.Exists(packageC));
        }
Пример #32
0
        public void AddPackageDoNotTransformPackagesConfigFileInNestedFolder()
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var localRepository = new MockPackageRepository();
            var projectSystem = new Mock<MockProjectSystem>() { CallBase = true };
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem.Object), projectSystem.Object, localRepository);
            IPackage packageA = PackageUtility.CreatePackage("A", "1.0", new[] { "a", "b", "sub\\packages.config.pp", "local\\PACKAGES.config.transform", "fod\\packages.config.Install.XDT", "car\\Packages.Config.uninstall.Xdt" });
            sourceRepository.AddPackage(packageA);

            // Act
            projectManager.AddPackageReference("A");

            // Assert
            Assert.Equal(6, projectSystem.Object.Paths.Count);
            Assert.True(projectSystem.Object.FileExists("a"));
            Assert.True(projectSystem.Object.FileExists("b"));
            Assert.True(projectSystem.Object.FileExists("sub\\packages.config.pp"));
            Assert.True(projectSystem.Object.FileExists("local\\packages.config.transform"));
            Assert.True(projectSystem.Object.FileExists("fod\\packages.config.install.xdt"));
            Assert.True(projectSystem.Object.FileExists("car\\packages.config.uninstall.xdt"));
            Assert.True(localRepository.Exists("A"));
            Assert.False(projectSystem.Object.FileExists("sub\\packages.config"));
            Assert.False(projectSystem.Object.FileExists("local\\packages.config"));
        }
Пример #33
0
        public void InstallPackageInstallsLowerReleaseVersionIfPrereleaseFlagIsNotSet()
        {
            // Arrange
            var localRepository = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem();
            var packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);

            IPackage packageA = PackageUtility.CreatePackage("A", "1.0.0",
                                                             dependencies: new[] {
                                                                 new PackageDependency("C")
                                                             });

            IPackage packageC_RC = PackageUtility.CreatePackage("C", "1.0.0-RC-1");
            IPackage packageC = PackageUtility.CreatePackage("C", "0.9");
            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageC);
            sourceRepository.AddPackage(packageC_RC);

            // Act 
            packageManager.InstallPackage("A", version: null, ignoreDependencies: false, allowPrereleaseVersions: false);

            // Assert
            Assert.True(localRepository.Exists(packageA));
            Assert.True(localRepository.Exists(packageC));
        }
Пример #34
0
        public void RemovePackageWithTransformFileThatThrowsContinuesRemovingPackage()
        {
            // Arrange
            var mockProjectSystem = new MockProjectSystem();
            var mockRepository = new MockPackageRepository();
            var localRepository = new MockPackageRepository();
            mockProjectSystem.AddFile("web.config", () => { throw new UnauthorizedAccessException(); });
            mockProjectSystem.AddFile("foo.txt");
            var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(new MockProjectSystem()), mockProjectSystem, localRepository);
            var package = new Mock<IPackage>();
            package.Setup(m => m.Id).Returns("A");
            package.Setup(m => m.Version).Returns(new SemanticVersion("1.0"));
            var file = new Mock<IPackageFile>();
            var contentFile = new Mock<IPackageFile>();
            contentFile.Setup(m => m.Path).Returns(@"content\foo.txt");
            contentFile.Setup(m => m.GetStream()).Returns(new MemoryStream());
            contentFile.Setup(m => m.EffectivePath).Returns("foo.txt");
            file.Setup(m => m.Path).Returns(@"content\web.config.transform");
            file.Setup(m => m.EffectivePath).Returns("web.config.transform");
            file.Setup(m => m.GetStream()).Returns(() =>
@"<configuration>
    <system.web>
        <compilation debug=""true"" targetFramework=""4.0"" />
    </system.web>
</configuration>
".AsStream());
            package.Setup(m => m.GetFiles()).Returns(new[] { file.Object, contentFile.Object });
            mockRepository.AddPackage(package.Object);
            projectManager.LocalRepository.AddPackage(package.Object);

            // Act
            projectManager.RemovePackageReference("A");

            // Assert
            Assert.False(mockProjectSystem.FileExists("foo.txt"));
            Assert.False(localRepository.Exists(package.Object));
        }
Пример #35
0
        public void InstallPackageConsidersAlreadyInstalledPrereleasePackagesWhenResolvingDependencies()
        {
            // Arrange
            var packageB_05 = PackageUtility.CreatePackage("B", "0.5.0");
            var packageB_10a = PackageUtility.CreatePackage("B", "1.0.0-a");
            var packageA = PackageUtility.CreatePackage("A",
                                dependencies: new[] { new PackageDependency("B", VersionUtility.ParseVersionSpec("[0.5.0, 2.0.0)")) });

            var localRepository = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem();
            var packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageB_10a);
            sourceRepository.AddPackage(packageB_05);

            // Act 
            // The allowPrereleaseVersions flag should be irrelevant since we specify a version.
            packageManager.InstallPackage("B", version: new SemanticVersion("1.0.0-a"), ignoreDependencies: false, allowPrereleaseVersions: false);
            // Verify we actually did install B.1.0.0a
            Assert.True(localRepository.Exists(packageB_10a));

            packageManager.InstallPackage("A");

            // Assert
            Assert.True(localRepository.Exists(packageA));
            Assert.True(localRepository.Exists(packageB_10a));

        }
Пример #36
0
        public void AddPackageReferenceWithAnyNonCompatibleFrameworkReferenceDoesThrow()
        {
            // Arrange
            var mockProjectSystem = new Mock<MockProjectSystem>() { CallBase = true };
            var localRepository = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(mockProjectSystem.Object), mockProjectSystem.Object, localRepository);
            mockProjectSystem.Setup(m => m.TargetFramework).Returns(VersionUtility.ParseFrameworkName("net20"));
            var mockPackage = new Mock<IPackage>();
            mockPackage.Setup(m => m.Id).Returns("A");
            mockPackage.Setup(m => m.Version).Returns(new SemanticVersion("1.0"));
            mockPackage.Setup(m => m.Listed).Returns(true);
            var frameworkReference = new FrameworkAssemblyReference("System.Web", new[] { VersionUtility.ParseFrameworkName("net50") });
            mockPackage.Setup(m => m.FrameworkAssemblies).Returns(new[] { frameworkReference });
            sourceRepository.AddPackage(mockPackage.Object);

            // Act & Assert
            ExceptionAssert.Throws<InvalidOperationException>(
                () => projectManager.AddPackageReference("A"));

            Assert.False(localRepository.Exists(mockPackage.Object));
        }
Пример #37
0
        public void InstallPackageNotifiesBatchProcessorWhenExpandingPackageFiles()
        {
            // Arrange
            var package = PackageUtility.CreatePackage("B", "0.5.0", content: new[] { "content.txt" }, assemblyReferences: new[] { "Ref.dll" });

            var localRepository = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var fileSystem = new Mock<MockFileSystem> { CallBase = true };
            var batchProcessor = fileSystem.As<IBatchProcessor<string>>();
            batchProcessor.Setup(s => s.BeginProcessing(It.IsAny<IEnumerable<string>>(), PackageAction.Install))
                          .Callback((IEnumerable<string> files, PackageAction _) => Assert.Equal(new[] { PathFixUtility.FixPath(@"content\content.txt"), "Ref.dll" }, files))
                          .Verifiable();
            batchProcessor.Setup(s => s.EndProcessing()).Verifiable();

            var packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(fileSystem.Object), fileSystem.Object, localRepository);
            sourceRepository.AddPackage(package);

            // Act 
            packageManager.InstallPackage("B");
            
            // Assert
            Assert.True(localRepository.Exists(package));
            batchProcessor.Verify();
        }
Пример #38
0
        public void AddPackageReferenceDoesNotImportsTargetOrPropFileThatAreNotAtContentRoot()
        {
            // Arrange
            var projectSystem = new MockProjectSystem(new FrameworkName("Native", new Version("2.0")), "x:\\root");
            var localRepository = new MockPackageRepository();
            var mockRepository = new MockPackageRepository();
            var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
            var packageA = PackageUtility.CreatePackage("A", "1.0");

            var mockPackageA = Mock.Get(packageA);
            var files = PackageUtility.CreateFiles(new[] { "build\\native\\foo\\A.targets", "build\\native\\bar\\B.props", "content\\native\\foo.css" });
            mockPackageA.Setup(p => p.GetFiles()).Returns(files);

            mockRepository.AddPackage(mockPackageA.Object);

            // Act
            projectManager.AddPackageReference("A");

            // Assert
            Assert.True(localRepository.Exists("A"));

            Assert.False(projectSystem.ImportExists("x:\\root\\A.1.0\\build\\native\\foo\\A.targets"));
            Assert.False(projectSystem.ImportExists("x:\\root\\A.1.0\\build\\native\\bar\\A.props"));
        }
Пример #39
0
        public void UpdatePackageOverwriteAllFilesWhenFileConflictActionSetToOverwrite()
        {
            // Arrange
            var localRepository = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var constraintProvider = NullConstraintProvider.Instance;
            var fileSystem = new MockFileSystem();
            var pathResolver = new DefaultPackagePathResolver(fileSystem);
            var projectSystem = new MockProjectSystem();
            projectSystem.AddFile("one.txt", "this is one");
            projectSystem.AddFile("two.txt", "this is two");

            var packages = new List<IPackage>();
            var package_A10 = PackageUtility.CreatePackage("A", "1.0", content: new[] { "1.txt" });
            var package_A12 = PackageUtility.CreatePackage("A", "1.2", content: new[] { "one.txt", "two.txt" });
            localRepository.Add(package_A10);
            sourceRepository.Add(package_A12);

            var sharedRepository = new Mock<ISharedPackageRepository>(MockBehavior.Strict);
            sharedRepository.Setup(s => s.AddPackage(package_A12)).Callback<IPackage>(p => packages.Add(p));
            sharedRepository.Setup(s => s.GetPackages()).Returns(packages.AsQueryable());

            var repositoryFactory = new Mock<IPackageRepositoryFactory>();
            repositoryFactory.Setup(s => s.CreateRepository(It.IsAny<string>())).Returns(sourceRepository);

            var packageSourceProvider = new Mock<IPackageSourceProvider>();
            packageSourceProvider.Setup(s => s.LoadPackageSources()).Returns(new[] { new PackageSource("foo-source") });

            var console = new Mock<IConsole>();
            console.Setup(c => c.ResolveFileConflict(It.IsAny<string>())).Returns(FileConflictResolution.Ignore);

            var updateCommand = new UpdateCommand()
            {
                RepositoryFactory = repositoryFactory.Object,
                SourceProvider = packageSourceProvider.Object,
                Console = console.Object,
                FileConflictAction = FileConflictAction.Overwrite
            };

            // Act
            updateCommand.UpdatePackages(localRepository, fileSystem, sharedRepository.Object, sourceRepository, constraintProvider, pathResolver, projectSystem);

            // Assert
            Assert.True(localRepository.Exists("A", new SemanticVersion("1.2")));
            Assert.Equal("content\\one.txt", projectSystem.ReadAllText("one.txt"));
            Assert.Equal("content\\two.txt", projectSystem.ReadAllText("two.txt"));
        }
Пример #40
0
        public void RemovePackageReferenceRemoveContentAccordingToTargetFramework()
        {
            // Arrange
            var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework", new Version("2.0")));
            projectSystem.AddFile("jQuery.js", "content\\[net35]\\jQuery.js");
            projectSystem.AddFile("foo.css", "content\\foo.css");

            var localRepository = new MockPackageRepository();
            var mockRepository = new MockPackageRepository();
            var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
            var packageA = PackageUtility.CreatePackage("A", "1.0",
                                                        new[] { "net20\\contentFile", "net35\\jQuery.js", "foo.css" },
                                                        new[] { "lib\\eference.dll" });
            mockRepository.AddPackage(packageA);
            projectManager.AddPackageReference("A");
            Assert.True(projectSystem.FileExists(@"contentFile"));

            // Act
            projectManager.RemovePackageReference("A");

            // Assert
            Assert.Equal(2, projectSystem.Paths.Count);
            Assert.True(projectSystem.FileExists(@"jQuery.js"));
            Assert.True(projectSystem.FileExists(@"foo.css"));
            Assert.False(localRepository.Exists("A"));
        }
Пример #41
0
        public void InstallPackageDoesNotPerformWalkInfoCheckWhenPassingTheFlag()
        {
            // In this test, we simulate installing a solution-level package which depends on 
            // a project-level package. Under normal condition, this is disallowed by NuGet. 
            // However, if passing the 'ignoreWalkInfo' parameter with value of 'true', 
            // NuGet will happily accept that. Hence the installation will succeed.
            // This is used by the package restore mode.

            var localRepository = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem();
            var packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);

            // A is solution-level package
            IPackage packageA = PackageUtility.CreatePackage("A", "1.0.0",
                                                             tools: new string[] { "init.ps1"},
                                                             dependencies: new[] {
                                                                 new PackageDependency("C")
                                                             });

            IPackage packageC = PackageUtility.CreatePackage("C", "1.0.0-RC-1", content: new string[] { "a.txt" } );
            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageC);

            // Act
            packageManager.InstallPackage(packageA, ignoreDependencies: false, allowPrereleaseVersions: true, ignoreWalkInfo: true);

            // Assert
            Assert.True(localRepository.Exists(packageA));
            Assert.True(localRepository.Exists(packageC));
        }
Пример #42
0
        public void AddPackageReferenceDoesNotThrowIfThereIsCompatibleAssemblyInContentButNotInLib()
        {
            // Arrange
            var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework", new Version("4.0")));
            var localRepository = new MockPackageRepository();
            var mockRepository = new MockPackageRepository();
            var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
            var packageA = PackageUtility.CreatePackage("A", "1.0",
                                                        content: new[] { "net20\\reference.txt" },
                                                        assemblyReferences: new string[] { "lib\\WindowsPhone7\\one.dll" });

            mockRepository.AddPackage(packageA);

            // Act
            projectManager.AddPackageReference("A");

            // Assert
            Assert.True(localRepository.Exists("A"));
            Assert.False(projectSystem.ReferenceExists("one.dll"));
            Assert.True(projectSystem.FileExists("reference.txt"));
        }
Пример #43
0
        public void ReInstallingPackageAfterUninstallingDependencyShouldReinstallAllDependencies()
        {
            // Arrange
            var localRepository = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem();
            PackageManager packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);

            IPackage packageA = PackageUtility.CreatePackage("A", "1.0",
                dependencies: new List<PackageDependency> {
                    new PackageDependency("B")
                });

            IPackage packageB = PackageUtility.CreatePackage("B", "1.0",
                                                            dependencies: new List<PackageDependency> {
                                                                new PackageDependency("C")
                                                            });

            var packageC = PackageUtility.CreatePackage("C", "1.0");

            localRepository.AddPackage(packageA);
            localRepository.AddPackage(packageB);

            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageB);
            sourceRepository.AddPackage(packageC);

            // Act
            packageManager.InstallPackage("A");

            // Assert            
            Assert.True(localRepository.Exists(packageA));
            Assert.True(localRepository.Exists(packageB));
            Assert.True(localRepository.Exists(packageC));
        }
Пример #44
0
        public void AddPackageReferenceAddsAssemblyReferencesUsingNewFolderConvention()
        {
            // Arrange
            var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework", new Version("4.0")));
            var localRepository = new MockPackageRepository();
            var mockRepository = new MockPackageRepository();
            var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
            var packageA = PackageUtility.CreatePackage("A", "1.0",
                                                        new[] { "contentFiles" },
                                                        new[] { "lib\\net35\\reference.dll", "lib\\net45\\bar.dll" });

            mockRepository.AddPackage(packageA);

            // Act
            projectManager.AddPackageReference("A");

            // Assert
            Assert.Equal(1, projectSystem.References.Count);
            Assert.True(projectSystem.References.ContainsKey(@"reference.dll"));
            Assert.False(projectSystem.References.ContainsKey(@"bar.dll"));
            Assert.True(localRepository.Exists("A"));
        }
Пример #45
0
        public void UpdatePackageDoesNothingIfNoUpdatesAvailable()
        {
            // Arrange
            var localRepository = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem();
            PackageManager packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);

            IPackage A10 = PackageUtility.CreatePackage("A", "1.0");
            localRepository.Add(A10);

            // Act
            packageManager.UpdatePackage("A", updateDependencies: true, allowPrereleaseVersions: false);

            // Assert
            Assert.True(localRepository.Exists("A", new SemanticVersion("1.0")));
        }
Пример #46
0
        public void AddPackageReferenceRecognizeEmptyFrameworkFolder5()
        {
            // Arrange
            var projectSystem = new MockProjectSystem(new FrameworkName(".NETCore", new Version("4.5")));
            var localRepository = new MockPackageRepository();
            var mockRepository = new MockPackageRepository();
            var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
            var packageA = PackageUtility.CreatePackage("A", "1.0",
                                                        assemblyReferences: new string[] { 
                                                            "lib\\sl3\\reference.dll", 
                                                            "lib\\winrt\\_._",
                                                            "lib\\winrt45\\one.dll"
                                                        });
            mockRepository.AddPackage(packageA);

            // Act
            projectManager.AddPackageReference("A");

            // Assert
            Assert.False(projectSystem.ReferenceExists("reference.dll"));
            Assert.False(projectSystem.ReferenceExists("_._"));
            Assert.True(projectSystem.ReferenceExists("one.dll"));
            Assert.True(localRepository.Exists("A"));
        }
Пример #47
0
        public void CanExecuteReturnsCorrectResult()
        {
            // Arrange

            var packageA = PackageUtility.CreatePackage("A", "1.0");
            var packageB = PackageUtility.CreatePackage("B", "2.0");
            var packageC = PackageUtility.CreatePackage("C", "3.0");

            var sourceRepository = new MockPackageRepository();

            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageC);
            sourceRepository.AddPackage(packageB);

            var localRepository = new MockPackageRepository();

            localRepository.AddPackage(packageA);

            var projectManager = new Mock <IProjectManager>();

            projectManager.Setup(p => p.IsInstalled(It.IsAny <IPackage>())).Returns <IPackage>(p => localRepository.Exists(p));

            var packageManager = new Mock <IVsPackageManager>();

            packageManager.Setup(p => p.SourceRepository).Returns(sourceRepository);

            var provider = CreateOnlineProvider(packageManager.Object, projectManager.Object);

            var extensionA = new PackageItem(provider, packageA, null);
            var extensionB = new PackageItem(provider, packageB, null);
            var extensionC = new PackageItem(provider, packageC, null);

            // Act
            bool canExecuteA = provider.CanExecute(extensionA);
            bool canExecuteB = provider.CanExecute(extensionB);
            bool canExecuteC = provider.CanExecute(extensionC);

            // Assert
            Assert.IsTrue(canExecuteC);
            Assert.IsTrue(canExecuteB);
            Assert.IsFalse(canExecuteA);
        }