Esempio n. 1
0
        public void AddPackageReferenceAppliesPackageReferencesCorrectly()
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework, Version=4.5"));
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
            IPackage packageA = PackageUtility.CreatePackage(
                "A",
                "1.0",
                assemblyReferences: new[] { "lib\\a.dll", "lib\\b.dll" });
            sourceRepository.AddPackage(packageA);

            Mock<IPackage> mockPackageA = Mock.Get<IPackage>(packageA);
            mockPackageA.Setup(m => m.PackageAssemblyReferences).Returns(
                    new PackageReferenceSet[] { 
                        new PackageReferenceSet(VersionUtility.ParseFrameworkName("net40"), new [] { "a.dll" }),
                        new PackageReferenceSet(null, new [] { "b.dll" })
                    }
                );

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

            // Assert
            Assert.True(projectManager.LocalRepository.Exists("A"));
            Assert.True(projectSystem.ReferenceExists("a.dll"));
            Assert.False(projectSystem.ReferenceExists("b.dll"));
        }
Esempio n. 2
0
        public void InstallPackageIntoWindowsStoreProjectIgnoreAppConfigFile()
        {
            // Arrange
            var sourceRepository = new MockPackageRepository();

            var mockFileSystemProvider = new Mock <IFileSystemProvider>();

            mockFileSystemProvider.Setup(fs => fs.GetFileSystem(It.IsAny <string>())).Returns(new MockFileSystem());
            var project = TestUtils.GetProject("WindowsStore");

            var projectSystem = new TestableWindowsStoreProjectSystem(project, mockFileSystemProvider.Object);
            var pathResolver  = new DefaultPackagePathResolver(projectSystem);

            var package = NuGet.Test.PackageUtility.CreatePackage(
                "foo", "1.0.0", content: new[] { "readme.txt", "app.config" });

            sourceRepository.AddPackage(package);

            var projectManager = new ProjectManager(
                sourceRepository,
                pathResolver,
                projectSystem,
                new MockPackageRepository());

            // Act
            projectManager.AddPackageReference(package, ignoreDependencies: false, allowPrereleaseVersions: false);

            // Assert
            Assert.True(projectSystem.FileExists("readme.txt"));
            Assert.False(projectSystem.FileExists("app.config"));
        }
Esempio n. 3
0
        public void AddPackageReferenceLoadPackagesProjectNameConfigIfPresent()
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(
                new FrameworkName(".NETFramework, Version=4.5"));
            projectSystem.ProjectName = "CoolProject";
            projectSystem.AddFile("packages.CoolProject.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""luan"" version=""3.0"" />
</packages>");

            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
            IPackage packageA = PackageUtility.CreatePackage(
                "A",
                "1.0",
                assemblyReferences: new[] { "lib\\a.dll"});
            sourceRepository.AddPackage(packageA);

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

            // Assert
            Assert.True(projectManager.LocalRepository.Exists("A"));
            Assert.True(projectManager.Project.FileExists("packages.CoolProject.config"));
            Assert.False(projectManager.Project.FileExists("packages.config"));
        }
Esempio n. 4
0
        public void XdtTransformOnXmlNodeWithAttributes()
        {
            // Arrange
            var mockProjectSystem = new MockProjectSystem();
            var mockRepository    = new MockPackageRepository();

            mockProjectSystem.AddFile("test.xml",
                                      @"<a attrib=""b""/>".AsStream());
            var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(new MockProjectSystem()), mockProjectSystem, new MockPackageRepository());

            var package = new Mock <IPackage>();

            package.Setup(m => m.Id).Returns("A");
            package.Setup(m => m.Version).Returns(new SemanticVersion("1.0"));
            package.Setup(m => m.Listed).Returns(true);

            var file = new Mock <IPackageFile>();

            file.Setup(m => m.Path).Returns(@"content\test.xml.install.xdt");
            file.Setup(m => m.EffectivePath).Returns("test.xml.install.xdt");
            file.Setup(m => m.GetStream()).Returns(() =>
                                                   @"<a xmlns:xdt=""http://schemas.microsoft.com/XML-Document-Transform""><test xdt:Transform=""InsertIfMissing""/></a>".AsStream());

            package.Setup(m => m.GetFiles()).Returns(new[] { file.Object });
            mockRepository.AddPackage(package.Object);

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

            // Assert
            Assert.True(mockProjectSystem.FileExists("test.xml"));
            var actual = mockProjectSystem.OpenFile("test.xml").ReadToEnd();

            Assert.Equal("<a attrib=\"b\">\t<test/></a>", actual);
        }
Esempio n. 5
0
        public void AddPackageWithXdtTransformFile()
        {
            // Arrange
            var mockProjectSystem = new MockProjectSystem();
            var mockRepository = new MockPackageRepository();
            mockProjectSystem.AddFile("web.config",
@"<configuration>
    <system.web>
        <compilation debug=""true"" />
    </system.web>
</configuration>
".AsStream());
            var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(new MockProjectSystem()), mockProjectSystem, new MockPackageRepository());

            var package = new Mock<IPackage>();
            package.Setup(m => m.Id).Returns("A");
            package.Setup(m => m.Version).Returns(new SemanticVersion("1.0"));
            package.Setup(m => m.Listed).Returns(true);
            
            var file = new Mock<IPackageFile>();
            file.Setup(m => m.Path).Returns(@"content\web.config.install.xdt");
            file.Setup(m => m.EffectivePath).Returns("web.config.install.xdt");
            file.Setup(m => m.GetStream()).Returns(() =>
@"<configuration xmlns:xdt=""http://schemas.microsoft.com/XML-Document-Transform"">
    <system.web>
        <compilation xdt:Locator=""Condition('@debug=true')"" debug=""false"" xdt:Transform=""Replace"" />
    </system.web>
</configuration>".AsStream());

            var file2 = new Mock<IPackageFile>();
            file2.Setup(m => m.Path).Returns(@"content\web.config.uninstall.xdt");
            file2.Setup(m => m.EffectivePath).Returns("web.config.uninstall.xdt");
            file2.Setup(m => m.GetStream()).Returns(() =>
@"<configuration xmlns:xdt=""http://schemas.microsoft.com/XML-Document-Transform"">
    <system.web>
        <compilation xdt:Locator=""Match(debug)"" debug=""false"" xdt:Transform=""Remove"" />
    </system.web>
</configuration>".AsStream());

            package.Setup(m => m.GetFiles()).Returns(new[] { file.Object, file2.Object });
            mockRepository.AddPackage(package.Object);

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

            // Assert
            Assert.False(mockProjectSystem.FileExists("web.config.install.xdt"));
            Assert.False(mockProjectSystem.FileExists("web.config.uninstall.xdt"));
            Assert.True(mockProjectSystem.FileExists("web.config"));
            Assert.Equal(
@"<configuration>
    <system.web>
        <compilation debug=""false""/>
    </system.web>
</configuration>
", mockProjectSystem.OpenFile("web.config").ReadToEnd());
        }
 public static void AddPackage(this DotNetProject project, IPackage package, IPackageRepository repository)
 {
     var packageManager = new PackageManager(repository, project.BaseDirectory);
     packageManager.InstallPackage(package, false);
     var projectSystem = new ProjectSystemWrapper(project);
     var projectManager = new ProjectManager(repository, packageManager.PathResolver, projectSystem, packageManager.LocalRepository);
     projectManager.AddPackageReference(package.Id);
     project.NeedsReload = true;
 }
Esempio n. 7
0
        public void RemovePackageWithXdtTransformFile()
        {
            // Arrange
            var mockProjectSystem = new MockProjectSystem();
            var mockRepository    = new MockPackageRepository();

            mockProjectSystem.AddFile("web.config",
                                      @"<configuration>
    <system.web><compilation debug=""false"" /></system.web>
</configuration>
".AsStream());
            var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(new MockProjectSystem()), mockProjectSystem, new MockPackageRepository());

            var package = new Mock <IPackage>();

            package.Setup(m => m.Id).Returns("A");
            package.Setup(m => m.Version).Returns(new SemanticVersion("1.0"));
            package.Setup(m => m.Listed).Returns(true);

            var file = new Mock <IPackageFile>();

            file.Setup(m => m.Path).Returns(@"content\web.config.uninstall.xdt");
            file.Setup(m => m.EffectivePath).Returns("web.config.uninstall.xdt");
            file.Setup(m => m.GetStream()).Returns(() =>
                                                   @"<configuration xmlns:xdt=""http://schemas.microsoft.com/XML-Document-Transform"">
    <system.web>
        <compilation xdt:Locator=""Match(debug)"" debug=""false"" xdt:Transform=""Remove"" />
    </system.web>
</configuration>".AsStream());

            package.Setup(m => m.GetFiles()).Returns(new[] { file.Object });
            mockRepository.AddPackage(package.Object);

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

            // Assert 1
            Assert.False(mockProjectSystem.FileExists("web.config.uninstall.xdt"));
            Assert.Equal(
                @"<configuration>
    <system.web><compilation debug=""false"" /></system.web>
</configuration>
", mockProjectSystem.OpenFile("web.config").ReadToEnd());

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

            // Assert 2
            Assert.False(mockProjectSystem.FileExists("web.config.uninstall.xdt"));
            Assert.True(mockProjectSystem.FileExists("web.config"));
            Assert.Equal(
                @"<configuration>
    <system.web></system.web>
</configuration>
", mockProjectSystem.OpenFile("web.config").ReadToEnd());
        }
Esempio n. 8
0
        public static void AddPackage(this DotNetProject project, IPackage package, IPackageRepository repository)
        {
            var packageManager = new PackageManager(repository, project.BaseDirectory);

            packageManager.InstallPackage(package, false);
            var projectSystem  = new ProjectSystemWrapper(project);
            var projectManager = new ProjectManager(repository, packageManager.PathResolver, projectSystem, packageManager.LocalRepository);

            projectManager.AddPackageReference(package.Id);
            project.NeedsReload = true;
        }
Esempio n. 9
0
        public void UpdatePackageWithMultipleSharedDependencies()
        {
            // Arrange
            var localRepository = new Mock <MockPackageRepository>()
            {
                CallBase = true
            }.As <ISharedPackageRepository>();
            var projectRepository = new MockProjectPackageRepository(localRepository.Object);
            var sourceRepository  = new MockPackageRepository();
            var fileSystem        = new MockFileSystem();
            var projectSystem     = new MockProjectSystem();
            var pathResolver      = new DefaultPackagePathResolver(fileSystem);
            // A1 -> B1, C1
            // A2 -> B1
            var A10 = PackageUtility.CreatePackage("A", "1.0", assemblyReferences: new[] { "A1.dll" }, dependencies: new[] {
                new PackageDependency("B", VersionUtility.ParseVersionSpec("1.0")),
                new PackageDependency("C", VersionUtility.ParseVersionSpec("1.0")),
            });
            var A20 = PackageUtility.CreatePackage("A", "2.0", assemblyReferences: new[] { "A2.dll" }, dependencies: new[] {
                new PackageDependency("B", VersionUtility.ParseVersionSpec("1.0"))
            });
            var B10 = PackageUtility.CreatePackage("B", "1.0", assemblyReferences: new[] { "B1.dll" });
            var C10 = PackageUtility.CreatePackage("C", "1.0", assemblyReferences: new[] { "C1.dll" });

            sourceRepository.AddPackage(A10);
            sourceRepository.AddPackage(A20);
            sourceRepository.AddPackage(B10);
            sourceRepository.AddPackage(C10);
            localRepository.Object.AddPackage(A10);
            localRepository.Object.AddPackage(A20);
            localRepository.Object.AddPackage(B10);
            localRepository.Object.AddPackage(C10);
            var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, fileSystem, localRepository.Object, new Mock <IRecentPackageRepository>().Object);
            var projectManager = new ProjectManager(localRepository.Object, pathResolver, projectSystem, projectRepository);

            projectManager.AddPackageReference("A", new Version("1.0"));

            // Act
            packageManager.UpdatePackage(projectManager, "A", version: null, updateDependencies: true, logger: NullLogger.Instance);

            // Assert
            Assert.IsFalse(packageManager.LocalRepository.Exists(A10));
            Assert.IsFalse(projectSystem.ReferenceExists("A1.dll"));
            Assert.IsFalse(packageManager.LocalRepository.Exists(C10));
            Assert.IsFalse(projectSystem.ReferenceExists("C1.dll"));
            Assert.IsTrue(packageManager.LocalRepository.Exists(B10));
            Assert.IsTrue(projectSystem.ReferenceExists("B1.dll"));
            Assert.IsTrue(packageManager.LocalRepository.Exists(A20));
            Assert.IsTrue(projectSystem.ReferenceExists("A2.dll"));
        }
Esempio n. 10
0
        public void AddingPackageReferenceAddsPreprocessedFileToTargetPathWithRemovedExtension()
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem();
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
            IPackage packageA = PackageUtility.CreatePackage("A", "1.0", new[] { @"foo\bar\file.pp" });
            sourceRepository.AddPackage(packageA);

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

            // Assert
            Assert.False(projectSystem.FileExists(@"foo\bar\file.pp"));
            Assert.True(projectSystem.FileExists(@"foo\bar\file"));
        }
Esempio n. 11
0
        public void AddingPackageReferenceThrowsExceptionPackageReferenceIsAdded()
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new Mock<MockProjectSystem>() { CallBase = true };
            projectSystem.Setup(m => m.AddFile("file", It.IsAny<Stream>())).Throws<UnauthorizedAccessException>();
            projectSystem.Setup(m => m.Root).Returns("FakeRoot");
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem.Object), projectSystem.Object, new MockPackageRepository());
            IPackage packageA = PackageUtility.CreatePackage("A", "1.0", new[] { "file" });
            sourceRepository.AddPackage(packageA);

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

            // Assert
            Assert.True(projectManager.LocalRepository.Exists(packageA));
        }
Esempio n. 12
0
        //download the specified version of the package and update project reference to it. The newly downloaded package
        //will be located in /packages folder. The updated project reference can be checked in corresponding .csproj file.
        public bool Execute(string packageid, string projectFile, SemanticVersion version, string packages)
        {
            try
            {
                System.Console.WriteLine("-------------------------------------");
                System.Console.WriteLine("Project File " + projectFile);
                System.Console.WriteLine("Package " + packageid);
                System.Console.WriteLine("Version " + version);

                IPackageRepository repo      = PackageRepositoryFactory.Default.CreateRepository("https://packages.nuget.org/api/v2");
                var packagePathResolver      = new DefaultPackagePathResolver(packages);
                var packagesFolderFileSystem = new PhysicalFileSystem(packages);
                var projectSystem            = new MSBuildProjectSystem(projectFile);
                var localRepository          = new LocalPackageRepository(packagePathResolver, packagesFolderFileSystem);
                var projectManager           = new ProjectManager(repo, packagePathResolver, projectSystem, localRepository);

                projectManager.RemovePackageReference(packageid, true, false);
                projectManager.AddPackageReference(packageid, version, true, false);
                projectSystem.Save();

                string   filename = packageid + "." + version;
                string[] s        = Directory.GetFiles(packages + @"\" + filename);
                if (s.IsEmpty())
                {
                    System.Console.WriteLine("empty");
                }
                else
                {
                    var        nupkgFile = new PhysicalFileSystem(s[0]);
                    ZipPackage z         = new ZipPackage(s[0]);
                    z.ExtractContents(nupkgFile, packages + @"\" + filename);
                }
                System.Console.WriteLine("Successfully updated");
                return(true);
            }
            catch (Exception e)
            {
                System.Console.Write("failure");
                System.Console.Write(e.StackTrace);
                return(false);
            }
        }
        /// <summary>
        /// Executes a package installation.
        /// </summary>
        /// <param name="package">The package to install.</param>
        /// <param name="packageRepository">The repository for the package.</param>
        /// <param name="sourceLocation">The source location.</param>
        /// <param name="targetPath">The path where to install the package.</param>
        /// <returns>The package information.</returns>
        protected PackageInfo ExecuteInstall(IPackage package, IPackageRepository packageRepository, string sourceLocation, string targetPath)
        {
            var logger = new NugetLogger(_logger);

            var project = new FileBasedProjectSystem(targetPath)
            {
                Logger = logger
            };

            IPackageRepository referenceRepository;

            if (package.IsTheme())
            {
                referenceRepository = new ThemeReferenceRepository(project, packageRepository, _themeRegistry);
            }
            else
            {
                referenceRepository = new PluginReferenceRepository(project, packageRepository, _pluginFinder);
            }

            var projectManager = new ProjectManager(
                packageRepository,
                new DefaultPackagePathResolver(targetPath),
                project,
                referenceRepository
                )
            {
                Logger = logger
            };

            // add the package to the project
            projectManager.AddPackageReference(package, true, false);

            return(new PackageInfo
            {
                Id = package.Id,
                Name = package.Title ?? package.Id,
                Version = package.Version.ToString(),
                Type = package.IsTheme() ? "Theme" : "Plugin",
                Path = targetPath
            });
        }
Esempio n. 14
0
        public void InstallPackage(string packageId, string projectPath, string targetFolder)
        {
            var packagePathResolver      = new DefaultPackagePathResolver(targetFolder);
            var packagesFolderFileSystem = new PhysicalFileSystem(targetFolder);
            var projectSystem            = new BetterThanMSBuildProjectSystem(projectPath)
            {
                Logger = _console
            };
            var localRepository = new BetterThanLocalPackageRepository(packagePathResolver, packagesFolderFileSystem, projectSystem);
            var projectManager  = new ProjectManager(_packageRepository, packagePathResolver, projectSystem,
                                                     localRepository)
            {
                Logger = _console
            };

            projectManager.PackageReferenceAdded += (sender, args) => args.Package.GetLibFiles()
                                                    .Each(file => SaveAssemblyFile(args.InstallPath, file));
            projectManager.AddPackageReference(packageId);
            projectSystem.Save();
        }
Esempio n. 15
0
        private PackageInfo ExecuteUpdate(IPackage package)
        {
            var appPath = CommonHelper.MapPath("~/");

            var logger = new NugetLogger(_logger);

            var project = new FileBasedProjectSystem(appPath)
            {
                Logger = logger
            };

            var nullRepository = new NullSourceRepository();

            var projectManager = new ProjectManager(
                nullRepository,
                new DefaultPackagePathResolver(appPath),
                project,
                nullRepository
                )
            {
                Logger = logger
            };

            // Perform the update
            projectManager.AddPackageReference(package, true, false);

            var info = new PackageInfo
            {
                Id      = package.Id,
                Name    = package.Title ?? package.Id,
                Version = package.Version.ToString(),
                Type    = "App",
                Path    = appPath
            };

            _logger.Information("Update '{0}' successfully executed.".FormatInvariant(info.Name));

            return(info);
        }
Esempio n. 16
0
        //download the specified version of the package and update project reference to it. The newly downloaded package
        //will be located in /packages folder. The updated project reference can be checked in corresponding .csproj file.
        public bool Execute(string packageid, string projectFile, SemanticVersion version, string packages)
        {
            try
            {
                System.Console.WriteLine("-------------------------------------");
                System.Console.WriteLine("Project File " + projectFile);
                System.Console.WriteLine("Package "+packageid);
                System.Console.WriteLine("Version "+version);

                IPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository("https://packages.nuget.org/api/v2");
                var packagePathResolver = new DefaultPackagePathResolver(packages);
                var packagesFolderFileSystem = new PhysicalFileSystem(packages);
                var projectSystem = new MSBuildProjectSystem(projectFile);
                var localRepository = new LocalPackageRepository(packagePathResolver, packagesFolderFileSystem);
                var projectManager = new ProjectManager(repo, packagePathResolver, projectSystem, localRepository);

                projectManager.RemovePackageReference(packageid,true,false);
                projectManager.AddPackageReference(packageid, version, true, false);
                projectSystem.Save();

                string filename = packageid + "." + version;
                string[] s = Directory.GetFiles(packages+ @"\"+filename);
                if (s.IsEmpty()) { System.Console.WriteLine("empty"); }
                else
                {
                    var nupkgFile = new PhysicalFileSystem(s[0]);
                    ZipPackage z = new ZipPackage(s[0]);
                    z.ExtractContents(nupkgFile, packages + @"\" + filename);
                }
                System.Console.WriteLine("Successfully updated");
                return true;
            }
            catch (Exception e)
            {
                System.Console.Write("failure");
                System.Console.Write(e.StackTrace);
                return false;
            }
        }
Esempio n. 17
0
        public void AddPackageReferenceThrowsIfTheMinClientVersionOfADependencyIsNotSatisfied()
        {
            // Arrange            
            Version nugetVersion = typeof(IPackage).Assembly.GetName().Version;
            Version requiredVersion = new Version(nugetVersion.Major, nugetVersion.Minor, nugetVersion.Build, nugetVersion.Revision + 1);

            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(VersionUtility.ParseFrameworkName("net40"));
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
            IPackage packageA = PackageUtility.CreatePackage(
                "A", 
                "1.0", 
                assemblyReferences: new[] { "lib\\me.dll" },
                dependencies: new PackageDependency[] { new PackageDependency("B") });
            IPackage packageB = PackageUtility.CreatePackage("B", "2.0", assemblyReferences: new[] { "lib\\you.dll" }, minClientVersion: requiredVersion.ToString());
            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageB);

            string expectedErrorMessage =
                String.Format("The '{0}' package requires NuGet client version '{1}' or above, but the current NuGet version is '{2}'.", "B 2.0", requiredVersion.ToString(), nugetVersion.ToString());

            // Act && Assert
            ExceptionAssert.Throws<NuGetVersionNotSatisfiedException>(() => projectManager.AddPackageReference("A"), expectedErrorMessage);
        }
Esempio n. 18
0
        public void AddPackageReferenceDoesNotThrowIfTheMinClientVersionIsLessThanNuGetVersion()
        {
            // Arrange            
            Version nugetVersion = typeof(IPackage).Assembly.GetName().Version;
            Version requiredVersion;
            if (nugetVersion.Minor > 0)
            {
                requiredVersion = new Version(nugetVersion.Major, nugetVersion.Minor - 1, nugetVersion.Build, nugetVersion.Revision);
            }
            else
            {
                requiredVersion = new Version(nugetVersion.Major - 1, nugetVersion.Minor, nugetVersion.Build, nugetVersion.Revision);
            }

            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(VersionUtility.ParseFrameworkName("net40"));
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
            IPackage packageA = PackageUtility.CreatePackage("A", "1.0", assemblyReferences: new[] { "lib\\me.dll" }, minClientVersion: requiredVersion.ToString());
            sourceRepository.AddPackage(packageA);

            // Act && Assert
            projectManager.AddPackageReference("A");
        }
Esempio n. 19
0
        public void AddPackageReferencePickPortableDependencySetOverFallbackDependencySet()
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(VersionUtility.ParseFrameworkName("portable-net45+wp8+windows8"));
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());

            var dependencySets = new PackageDependencySet[] 
            {
                new PackageDependencySet(targetFramework: null, dependencies: new [] { PackageDependency.CreateDependency("B", "1.0.0")}),
                new PackageDependencySet(targetFramework: VersionUtility.ParseFrameworkName("net45"), dependencies: new PackageDependency[0] { }),
                new PackageDependencySet(targetFramework: VersionUtility.ParseFrameworkName("win8"), dependencies: new PackageDependency[0] { }),
                new PackageDependencySet(targetFramework: VersionUtility.ParseFrameworkName("wp8"), dependencies: new PackageDependency[0] { }),
                new PackageDependencySet(targetFramework: VersionUtility.ParseFrameworkName("portable-net45+win8+wp8"), dependencies: new PackageDependency[0] { }),
            };

            IPackage packageA = PackageUtility.CreatePackageWithDependencySets("A", "1.0", new[] { "me.txt" }, dependencySets: dependencySets);
            IPackage packageB = PackageUtility.CreatePackage("B", "1.0", new[] { "you.txt" });

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

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

            // Assert
            Assert.True(projectManager.LocalRepository.Exists("A"));
            Assert.False(projectManager.LocalRepository.Exists("B"));

            Assert.True(projectSystem.FileExists("me.txt"));
            Assert.False(projectSystem.FileExists("you.txt"));
        }
Esempio n. 20
0
        public void AddPackageReferencePicksPortableLibraryAssemblyOverFallbackAssembly()
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(VersionUtility.ParseFrameworkName("portable-sl4+net45"));
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
            IPackage packageA = PackageUtility.CreatePackage("A", "1.0", assemblyReferences: new[] { "netcf\\you.dll", "lib\\portable-sl4+net45+wp8+windows8\\portable.dll", "lib\\me.dll" });
            sourceRepository.AddPackage(packageA);

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

            // Assert
            Assert.False(projectSystem.ReferenceExists("me.dll"));
            Assert.False(projectSystem.ReferenceExists("you.dll"));
            Assert.True(projectSystem.ReferenceExists("portable.dll"));
        }
Esempio n. 21
0
        public void AddPackageReferenceThrowsWhenNoTargetFrameworkIsCompatibleWithNonPortableProject()
        {
            // Arrange
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework, Version=4.5"));
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
            IPackage packageA = PackageUtility.CreatePackage("A", "1.0", new[] { "silverlight4\\a.txt" });
            sourceRepository.AddPackage(packageA);

            // Act
            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=v4.5', 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.");
        }
Esempio n. 22
0
        public void AddPackageReferencePicksPortableLibraryFilesOverFallbackFiles()
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(VersionUtility.ParseFrameworkName("portable-sl4+net4+wp8+windows8"));
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
            IPackage packageA = PackageUtility.CreatePackage("A", "1.0", new[] { "portable-windows8+sl4+wp8+net4\\portable.txt", "me.txt" });
            sourceRepository.AddPackage(packageA);

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

            // Assert
            Assert.False(projectSystem.FileExists("me.txt"));
            Assert.True(projectSystem.FileExists("portable.txt"));
        }
Esempio n. 23
0
        public void AddPackageReferencePersistTargetFarmeworkToPackagesConfigFile()
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework", new Version("4.0")));

            var localRepository = new Mock<IPackageReferenceRepository>();
            localRepository.Setup(p => p.AddPackage("A", 
                                                    new SemanticVersion("1.0"),
                                                    false,
                                                    new FrameworkName(".NETFramework, Version=4.0"))).Verifiable();

            localRepository.Setup(p => p.AddPackage("B",
                                                    new SemanticVersion("2.0"),
                                                    false,
                                                    new FrameworkName(".NETFramework, Version=4.0"))).Verifiable();

            var projectManager = new ProjectManager(
                sourceRepository, 
                new DefaultPackagePathResolver(projectSystem), 
                projectSystem, 
                localRepository.Object);

            var dependency = new PackageDependency("B", null);
            var dependecySets = CreateDependencySet(".NETFramework, Version=3.0", dependency);

            IPackage packageA = PackageUtility.CreatePackageWithDependencySets("A", "1.0",
                                                                dependencySets: new[] { dependecySets },
                                                                content: new[] { "a.txt" });

            IPackage packageB = PackageUtility.CreatePackage("B", "2.0", content: new[] { "b.txt" });

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

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

            // Assert
            localRepository.VerifyAll();
        }
Esempio n. 24
0
        public void SafeUpdatingADependencyDoesNotUninstallPackage()
        {
            // Arrange
            
            var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework", new Version("4.0")));

            var packageA = PackageUtility.CreatePackage("A", "1.0", dependencies: new [] { new PackageDependency("C"), new PackageDependency("B") });
            var packageB10 = PackageUtility.CreatePackage("B", "1.0", dependencies: new[] { new PackageDependency("C") });
            var packageB101 = PackageUtility.CreatePackage("B", "1.0.1", dependencies: new[] { new PackageDependency("C") });
            var packageC = PackageUtility.CreatePackage("C", "1.0", content: new[] { "1.txt" });
            
            var localRepository = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository { packageA, packageB10, packageB101, packageC };

            var projectManager = new ProjectManager(
                sourceRepository,
                new DefaultPackagePathResolver(projectSystem),
                projectSystem,
                localRepository);

            // Act 1 
            projectManager.AddPackageReference(packageB10, ignoreDependencies: false, allowPrereleaseVersions: false);

            // Assert 1
            Assert.Contains(packageB10, localRepository);
            Assert.Contains(packageC, localRepository);

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

            // Assert 2
            Assert.Contains(packageA, localRepository);
            Assert.Contains(packageB10, localRepository);
            Assert.Contains(packageC, localRepository);
        }
Esempio n. 25
0
        public void ReThrowWithMeaningfulErrorMessageWhenXdtFileHasSyntaxError()
        {
            // Arrange
            var mockProjectSystem = new MockProjectSystem();
            var mockRepository    = new MockPackageRepository();

            mockProjectSystem.AddFile("web.config",
                                      @"<configuration>
    <system.web>
        <compilation debug=""true"" />
    </system.web>
</configuration>
".AsStream());
            var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(new MockProjectSystem()), mockProjectSystem, new MockPackageRepository());

            var package = new Mock <IPackage>();

            package.Setup(m => m.Id).Returns("A");
            package.Setup(m => m.Version).Returns(new SemanticVersion("1.0"));
            package.Setup(m => m.Listed).Returns(true);

            var file = new Mock <IPackageFile>();

            file.Setup(m => m.Path).Returns(@"content\web.config.install.xdt");
            file.Setup(m => m.EffectivePath).Returns("web.config.install.xdt");
            file.Setup(m => m.GetStream()).Returns(() =>
                                                   @"<configuration xmlns:xdt=""http://schemas.microsoft.com/XML-Document-Transform"">
    <system.web>
        <compilation xd:Locator=""Condition('@debug=true')"" debug=""false"" xdt:Transform=""Replace"" />
    </system.web>
</configuration>".AsStream());

            var file2 = new Mock <IPackageFile>();

            file2.Setup(m => m.Path).Returns(@"content\web.config.uninstall.xdt");
            file2.Setup(m => m.EffectivePath).Returns("web.config.uninstall.xdt");
            file2.Setup(m => m.GetStream()).Returns(() =>
                                                    @"<configuration xmlns:xdt=""http://schemas.microsoft.com/XML-Document-Transform"">
    <system.web>
        <compilation xdt:Locator=""Match(debug)"" debug=""false"" xdt:Transform=""Remove"" />
    </system.web>
</configuration>".AsStream());

            package.Setup(m => m.GetFiles()).Returns(new[] { file.Object, file2.Object });
            mockRepository.AddPackage(package.Object);

            // Act
            ExceptionAssert.Throws <InvalidDataException>(
                () => projectManager.AddPackageReference("A"),
                @"An error occurred while applying transformation to 'web.config' in project 'x:\MockFileSystem': 'xd' is an undeclared prefix. Line 3, position 22.");

            // Assert
            Assert.False(mockProjectSystem.FileExists("web.config.install.xdt"));
            Assert.False(mockProjectSystem.FileExists("web.config.uninstall.xdt"));
            Assert.True(mockProjectSystem.FileExists("web.config"));
            Assert.Equal(
                @"<configuration>
    <system.web>
        <compilation debug=""true"" />
    </system.web>
</configuration>
", mockProjectSystem.OpenFile("web.config").ReadToEnd());
        }
Esempio n. 26
0
        public void UpdatePackageReferenceIncludeDependencyPackageCorrectly2()
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework", new Version("4.0")));
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());

            var dependency = new PackageDependency("B", null);
            var dependencySet = CreateDependencySet(".NETFramework, Version=4.0", dependency);
            IPackage packageA = PackageUtility.CreatePackageWithDependencySets("A", "1.0",
                                                             dependencySets: new List<PackageDependencySet> { dependencySet },
                                                             content: new[] { "a.txt" });

            var dependency2 = new PackageDependency("B", null);
            var dependencySet2 = CreateDependencySet(".NETFramework, Version=4.5", dependency2);
            IPackage packageA2 = PackageUtility.CreatePackageWithDependencySets("A", "2.0",
                                                                dependencySets: new List<PackageDependencySet> { dependencySet2 },
                                                                content: new[] { "a2.txt" });

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

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

            projectManager.AddPackageReference("A", new SemanticVersion("1.0"));

            Assert.True(projectManager.LocalRepository.Exists("A"));
            Assert.True(projectManager.LocalRepository.Exists("B"));

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

            // Assert
            Assert.False(projectManager.LocalRepository.Exists("A", new SemanticVersion("1.0")));
            Assert.True(projectManager.LocalRepository.Exists("A", new SemanticVersion("2.0")));
            Assert.False(projectManager.LocalRepository.Exists("B"));
            Assert.True(projectSystem.FileExists("a2.txt"));
            Assert.False(projectSystem.FileExists("b.txt"));
        }
Esempio n. 27
0
        public void AddPackageReferencePicksSpecificLibraryOverPortableOne(string pickedContentFile, string projectFramework)
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(new FrameworkName(projectFramework));
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
            IPackage packageA = PackageUtility.CreatePackage("A", "1.0", new[] { "portable40-net40+wp7+silverlight4+windows\\two.txt", pickedContentFile});
            sourceRepository.AddPackage(packageA);

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

            // Assert
            Assert.False(projectSystem.FileExists("two.txt"));
            Assert.True(projectSystem.FileExists("one.txt"));
        }
Esempio n. 28
0
        public void RemovingPackageWithModifiedContentFileWithinIgnoreMarkersSucceeds2()
        {
            // Arrange
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem();
            var projectManager = new ProjectManager(
                sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
            var packageA = PackageUtility.CreatePackage("A", "1.0", content: new[] { "a.file" });

            var contentFile = PackageUtility.CreateMockedPackageFile("content", "a.file", @"this is awesome.
*******NUGET: BEGIN LICENSE TEXT------------------
SDAFLKDSAJFL;KJDSAL;KFJL;DSAKJFL;KDSA
******NUGET: END LICENSE TEXT-------");

            var mockPackageA = Mock.Get<IPackage>(packageA);
            mockPackageA.Setup(p => p.GetFiles()).Returns(new[] { contentFile.Object });
            
            sourceRepository.AddPackage(packageA);

            projectManager.AddPackageReference("A");
            Assert.True(projectManager.LocalRepository.Exists(packageA));
            Assert.True(projectSystem.FileExists("a.file"));

            projectSystem.ReadAllText("a.file");

            // now modify 'a.file' to include ignore line markers
            projectSystem.AddFile("a.file", @"this is awesome.");

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

            // Assert
            Assert.False(projectManager.LocalRepository.Exists(packageA));
            Assert.False(projectSystem.FileExists("a.file"));
        }
Esempio n. 29
0
        public void AddPackageReferencePicksThePortableLibraryWithLeastPlatformsWhenInstalledIntoNonPortableProject()
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(VersionUtility.ParseFrameworkName("netcore45"));
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
            IPackage packageA = PackageUtility.CreatePackage(
                "A",
                "1.0",
                new[] { "portable-net45+sl4+win8+wp8\\zero.txt",
                        "portable-net45+win8+wp8\\one.txt",
                        "portable-net40+sl4+win8+wp71\\two.txt"});

            sourceRepository.AddPackage(packageA);

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

            // Assert
            Assert.False(projectSystem.FileExists("zero.txt"));
            Assert.True(projectSystem.FileExists("one.txt"));
            Assert.False(projectSystem.FileExists("two.txt"));
        }
Esempio n. 30
0
        public void AddPackageReferencePicksThePortableLibraryWithHigherVersionOfTheMatchingFrameworks(string contentFile, string otherContentFile)
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(new FrameworkName("Silverlight, Version=4.0"));
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
            IPackage packageA = PackageUtility.CreatePackage("A", "1.0", new[] { contentFile, otherContentFile });
            sourceRepository.AddPackage(packageA);

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

            // Assert
            Assert.True(projectSystem.FileExists("one.txt"));
            Assert.False(projectSystem.FileExists("two.txt"));
        }
Esempio n. 31
0
        public void AddPackageReferencePrefersVersionClosenessOverClientProfileCompatibility()
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework, Version=4.5, Profile=Client"));
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
            IPackage packageA = PackageUtility.CreatePackage(
                "A",
                "1.0",
                content: new[] { "net35\\a.txt", "net4.0.0.1\\b.txt", "net40-client\\c.txt", "net4.5.0.1-client\\d.txt" });
            sourceRepository.AddPackage(packageA);

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

            // Assert
            Assert.False(projectSystem.FileExists("a.txt"));
            Assert.True(projectSystem.FileExists("b.txt"));
            Assert.False(projectSystem.FileExists("c.txt"));
            Assert.False(projectSystem.FileExists("d.txt"));
        }
Esempio n. 32
0
        public void AddPackageReferencePrefersFullProfileOverClientProfileWhenInstallIntoFullProfileProject()
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework, Version=4.5"));
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
            IPackage packageA = PackageUtility.CreatePackage(
                "A",
                "1.0",
                content: new[] { "net40-client\\b.txt", "net40\\a.txt" },
                assemblyReferences: new[] { "lib\\net40\\a.dll", "lib\\net40-client\\b.dll" });
            sourceRepository.AddPackage(packageA);

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

            // Assert
            Assert.False(projectSystem.ReferenceExists("b.dll"));
            Assert.False(projectSystem.FileExists("b.txt"));

            Assert.True(projectSystem.ReferenceExists("a.dll"));
            Assert.True(projectSystem.FileExists("a.txt"));
        }
Esempio n. 33
0
        /// <summary>
        /// Executes a package installation.
        /// </summary>
        /// <param name="package">The package to install.</param>
        /// <param name="packageRepository">The repository for the package.</param>
        /// <param name="sourceLocation">The source location.</param>
        /// <param name="targetPath">The path where to install the package.</param>
        /// <returns>The package information.</returns>
        protected PackageInfo ExecuteInstall(IPackage package, IPackageRepository packageRepository, string sourceLocation, string targetPath)
        {
            // this logger is used to render NuGet's log on the notifier
            var logger = new NugetLogger(_notifier);

            bool installed = false;

            // if we can access the parent directory, and the solution is inside, NuGet-install the package here
            string solutionPath;
            var    installedPackagesPath = String.Empty;

            if (TryGetSolutionPath(targetPath, out solutionPath))
            {
                installedPackagesPath = Path.Combine(solutionPath, PackagesPath);
                try {
                    var packageManager = new NuGetPackageManager(
                        packageRepository,
                        new DefaultPackagePathResolver(sourceLocation),
                        new PhysicalFileSystem(installedPackagesPath)
                    {
                        Logger = logger
                    }
                        )
                    {
                        Logger = logger
                    };

                    packageManager.InstallPackage(package, true);
                    installed = true;
                }
                catch {
                    // installing the package at the solution level failed
                }
            }

            // if the package got installed successfully, use it, otherwise use the previous repository
            var sourceRepository = installed
                ? new LocalPackageRepository(installedPackagesPath)
                : packageRepository;

            var project = new FileBasedProjectSystem(targetPath)
            {
                Logger = logger
            };
            var projectManager = new ProjectManager(
                sourceRepository, // source repository for the package to install
                new DefaultPackagePathResolver(targetPath),
                project,
                new ExtensionReferenceRepository(project, sourceRepository, _extensionManager)
                )
            {
                Logger = logger
            };

            // add the package to the project
            projectManager.AddPackageReference(package.Id, package.Version);

            return(new PackageInfo {
                ExtensionName = package.Title ?? package.Id,
                ExtensionVersion = package.Version.ToString(),
                ExtensionType = package.Id.StartsWith(PackagingSourceManager.GetExtensionPrefix(DefaultExtensionTypes.Theme)) ? DefaultExtensionTypes.Theme : DefaultExtensionTypes.Module,
                ExtensionPath = targetPath
            });
        }
Esempio n. 34
0
        public void AddPackageReferencePicksMatchingProfileEvenIfItIsEmpty()
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(VersionUtility.ParseFrameworkName("sl4"));
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
            IPackage packageA = PackageUtility.CreatePackage("A", "1.0", new[] { "sl3\\_._", "me.txt" });
            sourceRepository.AddPackage(packageA);

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

            // Assert
            Assert.False(projectSystem.FileExists("me.txt"));
            Assert.False(projectSystem.FileExists("_._"));
        }
Esempio n. 35
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"));
        }
Esempio n. 36
0
        public void AddPackageReferencePicksThePortableLibraryWithMoreMatchingVersionsWhenInstalledIntoPortableProject2()
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(VersionUtility.ParseFrameworkName("portable-net45+sl5+wp71"));
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
            IPackage packageA = PackageUtility.CreatePackage(
                "A",
                "1.0",
                new[] { "portable-net45+sl5+wp8\\one.txt",
                        "portable-net45+sl5+wp8\\two.txt",
                        "portable-net45+sl5+wp71+win8\\three.txt",
                        "portable-net45+sl4+wp71+win8\\four.txt",
                        "portable-net40+sl4+wp71+win8\\five.txt",
                        "portable-net40+sl4+wp7+win8\\six.txt",
                        "portable-wp8+win8\\seven.txt" });

            sourceRepository.AddPackage(packageA);

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

            // Assert
            Assert.False(projectSystem.FileExists("one.txt"));
            Assert.False(projectSystem.FileExists("two.txt"));
            Assert.True(projectSystem.FileExists("three.txt"));
            Assert.False(projectSystem.FileExists("four.txt"));
            Assert.False(projectSystem.FileExists("five.txt"));
            Assert.False(projectSystem.FileExists("six.txt"));
            Assert.False(projectSystem.FileExists("seven.txt"));
        }
Esempio n. 37
0
        public void AddPackageReferenceIncludeDependencyPackageCorrectly(string dependencyVersion)
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework", new Version("4.0")));
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());

            var dependency = new PackageDependency("B", null);
            var dependecySets = CreateDependencySet(".NETFramework, Version=" + dependencyVersion, dependency);

            IPackage packageA = PackageUtility.CreatePackageWithDependencySets("A", "1.0",
                                                                dependencySets: new [] { dependecySets }, 
                                                                content: new[] { "a.txt" });

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

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

            // Act
            projectManager.AddPackageReference("A");
            
            // Assert
            Assert.True(projectManager.LocalRepository.Exists("A"));
            Assert.True(projectManager.LocalRepository.Exists("B"));
            Assert.True(projectSystem.FileExists("a.txt"));
            Assert.True(projectSystem.FileExists("b.txt"));
        }
Esempio n. 38
0
        public void AddPackageReferenceWhenNewVersionOfPackageAlreadyReferencedDowngradesPackage()
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem();
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
            IPackage packageA10 = PackageUtility.CreatePackage("A", "1.0",
                                                                dependencies: new List<PackageDependency> { 
                                                                    new PackageDependency("B")
                                                                }, content: new[] { "foo" });
            IPackage packageA20 = PackageUtility.CreatePackage("A", "2.0",
                                                                dependencies: new List<PackageDependency> { 
                                                                    new PackageDependency("B")
                                                                }, content: new[] { "foo" });
            IPackage packageB10 = PackageUtility.CreatePackage("B", "1.0", content: new[] { "foo" });
            projectManager.LocalRepository.AddPackage(packageA20);
            projectManager.LocalRepository.AddPackage(packageB10);

            sourceRepository.AddPackage(packageA20);
            sourceRepository.AddPackage(packageB10);
            sourceRepository.AddPackage(packageA10);
            sourceRepository.AddPackage(packageA20);
            sourceRepository.AddPackage(packageB10);

            // Act & Assert
            projectManager.AddPackageReference("A", new SemanticVersion("1.0"));
            Assert.False(projectManager.LocalRepository.Exists(packageA20));
            Assert.True(projectManager.LocalRepository.Exists(packageA10));
        }
Esempio n. 39
0
        public void AddPackageReferenceDoNotIncludeDependencyPackageIfTargetFrameworkDoesNotMatch(string dependencyVersion)
        {
            // Arrange
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework", new Version("2.0")));
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());

            var dependency = new PackageDependency("B", null);
            var dependencySet = new PackageDependencySet(
                new FrameworkName(".NETFramework", new Version(dependencyVersion)), 
                new PackageDependency[] {dependency});

            IPackage packageA = PackageUtility.CreatePackage("A", "1.0", content: new[] { "a.txt" });
            Mock.Get(packageA).Setup(p => p.DependencySets).Returns(new [] {dependencySet});

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

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

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

            // Assert
            Assert.True(projectManager.LocalRepository.Exists("A"));
            Assert.False(projectManager.LocalRepository.Exists("B"));
            Assert.True(projectSystem.FileExists("a.txt"));
            Assert.False(projectSystem.FileExists("b.txt"));
        }
Esempio n. 40
0
        public void RemovingPackageWithModifiedContentFileWithinBeginMarkersRemoveFile()
        {
            // Arrange
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem();
            var projectManager = new ProjectManager(
                sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
            var packageA = PackageUtility.CreatePackage("A", "1.0", content: new[] { "a.file" });
            sourceRepository.AddPackage(packageA);

            projectManager.AddPackageReference("A");
            Assert.True(projectManager.LocalRepository.Exists(packageA));
            Assert.True(projectSystem.FileExists("a.file"));

            projectSystem.ReadAllText("a.file");

            // now modify 'a.file' to include ignore line markers
            projectSystem.AddFile("a.file", @"content\a.file
-----------------NUGET: BEGIN LICENSE TEXT
dsaflkdjsal;fkjdsal;kjf
sdafkljdsal;kjfl;dkasjfl;kdas
fdsalk;fj;lkdsajfl;kdsa");
            // Act 
            projectManager.RemovePackageReference("A");

            // Assert
            Assert.False(projectManager.LocalRepository.Exists(packageA));
            Assert.False(projectSystem.FileExists("a.file"));
        }
Esempio n. 41
0
        public void RemovePackageReferenceRemoveDependencyPackageCorrectly2()
        {
            // Arrange            
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework", new Version("2.0")));
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());

            var dependencyB = new PackageDependency("B", null);
            var dependencySetB = CreateDependencySet(".NETFramework, Version=2.1", dependencyB);

            var dependencyC = new PackageDependency("C", null);
            var dependencySetC = CreateDependencySet(".NETFramework, Version=2.0", dependencyC);

            IPackage packageA = PackageUtility.CreatePackageWithDependencySets("A", "1.0",
                                                                dependencySets: new List<PackageDependencySet> { dependencySetB, dependencySetC },
                                                                content: new[] { "a.txt" });

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

            IPackage packageC = PackageUtility.CreatePackage("C", "2.0", content: new[] { "c.txt" });

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

            projectManager.AddPackageReference("A");

            Assert.True(projectManager.LocalRepository.Exists("A"));
            Assert.False(projectManager.LocalRepository.Exists("B"));
            Assert.True(projectManager.LocalRepository.Exists("C"));

            Assert.True(projectSystem.FileExists("a.txt"));
            Assert.False(projectSystem.FileExists("b.txt"));
            Assert.True(projectSystem.FileExists("c.txt"));

            // Act
            projectManager.RemovePackageReference("A", forceRemove: false, removeDependencies: true);

            Assert.False(projectManager.LocalRepository.Exists("A"));
            Assert.False(projectManager.LocalRepository.Exists("B"));
            Assert.False(projectManager.LocalRepository.Exists("C"));

            Assert.False(projectSystem.FileExists("a.txt"));
            Assert.False(projectSystem.FileExists("b.txt"));
            Assert.False(projectSystem.FileExists("c.txt"));
        }