Ejemplo n.º 1
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());
        }
Ejemplo n.º 2
0
        public void AddFilesAddFilesToProjectSystem()
        {
            // Arrange
            var fileSystem = new MockProjectSystem();
            var files = PackageUtility.CreateFiles(new[] { "A", "B", "C" });

            // Act
            fileSystem.AddFiles(files, String.Empty);

            // Assert
            Assert.True(fileSystem.FileExists("A"));
            Assert.True(fileSystem.FileExists("B"));
            Assert.True(fileSystem.FileExists("C"));
        }
Ejemplo n.º 3
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"));
        }
Ejemplo n.º 4
0
        public void AddPackageAddsFileToFileSystem()
        {
            // Arrange
            var mockFileSystem = new MockProjectSystem();
            var repository = new LocalPackageRepository(new DefaultPackagePathResolver(mockFileSystem),
                                                        mockFileSystem);
            IPackage package = PackageUtility.CreatePackage("A", "1.0");

            // Act
            repository.AddPackage(package);

            // Assert
            Assert.IsTrue(mockFileSystem.FileExists(@"A.1.0\A.1.0.nupkg"));
        }
Ejemplo n.º 5
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"));
        }
Ejemplo n.º 6
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"));
        }
Ejemplo n.º 7
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("_._"));
        }
Ejemplo n.º 8
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"));
        }
Ejemplo n.º 9
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"));
        }
Ejemplo n.º 10
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"));
        }
Ejemplo n.º 11
0
        public void RemovePackageReferenceExcludesFileIfAnotherPackageUsesThem()
        {
            // Arrange
            var mockProjectSystem = new MockProjectSystem();
            var mockRepository = new MockPackageRepository();
            var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(new MockProjectSystem()), mockProjectSystem, new MockPackageRepository());
            IPackage packageA = PackageUtility.CreatePackage("A", "1.0",
                                                             new[] { "fileA", "commonFile" });

            IPackage packageB = PackageUtility.CreatePackage("B", "1.0",
                                                            new[] { "fileB", "commonFile" });

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

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

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

            // Assert
            Assert.True(mockProjectSystem.Deleted.Contains(@"fileA"));
            Assert.True(mockProjectSystem.FileExists(@"commonFile"));
        }
Ejemplo n.º 12
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"));
        }
        public void ReinstallPackagesRestoresPackageInAllProjectsWithNewContentIfSourcePackageChanges()
        {
            // Arrange
            var localRepositoryMock = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
            var localRepository = localRepositoryMock.Object;

            var sourceRepository = new MockPackageRepository();
            var projectSystem1 = new MockProjectSystem();
            var pathResolver1 = new DefaultPackagePathResolver(projectSystem1);
            var packageReferenceRepository1 = new PackageReferenceRepository(projectSystem1, localRepository);
            var projectManager1 = new ProjectManager(localRepository, pathResolver1, projectSystem1, packageReferenceRepository1);

            var projectSystem2 = new MockProjectSystem();
            var pathResolver2 = new DefaultPackagePathResolver(projectSystem2);
            var packageReferenceRepository2 = new PackageReferenceRepository(projectSystem2, localRepository);
            var projectManager2 = new ProjectManager(localRepository, pathResolver2, projectSystem2, packageReferenceRepository2);

            var project1 = TestUtils.GetProject("Project1");
            var project2 = TestUtils.GetProject("Project2");

            var packageManager = new MockVsPackageManager(
                TestUtils.GetSolutionManager(projects: new[] { project1, project2 }),
                sourceRepository,
                new Mock<IFileSystemProvider>().Object,
                projectSystem2,
                localRepository,
                new Mock<IDeleteOnRestartManager>().Object,
                new Mock<VsPackageInstallerEvents>().Object);

            packageManager.RegisterProjectManager(project1, projectManager1);
            packageManager.RegisterProjectManager(project2, projectManager2);

            var packageA = PackageUtility.CreatePackage(
                "A",
                "1.2-alpha",
                new[] { "content.txt" },
                new[] { "lib\\ref.dll" });

            var packageA2 = PackageUtility.CreatePackage(
                "A",
                "1.2-alpha",
                new[] { "foo.txt" },
                new[] { "lib\\bar.dll" });

            var packageB = PackageUtility.CreatePackage(
                "B",
                "2.0",
                new[] { "hello.txt" },
                new[] { "lib\\comma.dll" });

            var packageB2 = PackageUtility.CreatePackage(
                "B",
                "2.0",
                new[] { "world.txt" },
                new[] { "lib\\dude.dll" });

            sourceRepository.Add(packageA);
            sourceRepository.Add(packageB);

            // install package A -> project 1
            // and package B -> project 2
            packageManager.InstallPackage(projectManager1, "A", new SemanticVersion("1.2-alpha"), ignoreDependencies: false, allowPrereleaseVersions: true, logger: null);
            packageManager.InstallPackage(projectManager2, "B", new SemanticVersion("2.0"), ignoreDependencies: false, allowPrereleaseVersions: true, logger: null);

            Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
            Assert.True(projectManager1.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
            Assert.True(projectSystem1.FileExists("content.txt"));
            Assert.True(projectSystem1.ReferenceExists("ref.dll"));

            Assert.True(packageManager.LocalRepository.Exists("B", new SemanticVersion("2.0")));
            Assert.True(projectManager2.LocalRepository.Exists("B", new SemanticVersion("2.0")));
            Assert.True(projectSystem2.FileExists("hello.txt"));
            Assert.True(projectSystem2.ReferenceExists("comma.dll"));

            // now change the package A and B to different packages
            sourceRepository.RemovePackage(packageA);
            sourceRepository.RemovePackage(packageB);
            sourceRepository.AddPackage(packageA2);
            sourceRepository.AddPackage(packageB2);

            localRepositoryMock.Setup(p => p.IsReferenced("A", new SemanticVersion("1.2-alpha"))).Returns((string id, SemanticVersion version) => projectManager1.LocalRepository.Exists(id, version));
            localRepositoryMock.Setup(p => p.IsReferenced("B", new SemanticVersion("2.0"))).Returns((string id, SemanticVersion version) => projectManager2.LocalRepository.Exists(id, version));

            // Act
            packageManager.ReinstallPackages(updateDependencies: true, allowPrereleaseVersions: false, logger: NullLogger.Instance, eventListener: NullPackageOperationEventListener.Instance);

            // Assert
            Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
            Assert.True(projectManager1.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));

            Assert.False(projectSystem1.FileExists("content.txt"));
            Assert.True(projectSystem1.FileExists("foo.txt"));
            Assert.False(projectSystem1.ReferenceExists("ref.dll"));
            Assert.True(projectSystem1.ReferenceExists("bar.dll"));

            Assert.True(packageManager.LocalRepository.Exists("B", new SemanticVersion("2.0")));
            Assert.True(projectManager2.LocalRepository.Exists("B", new SemanticVersion("2.0")));

            Assert.False(projectSystem2.FileExists("hello.txt"));
            Assert.True(projectSystem2.FileExists("world.txt"));
            Assert.False(projectSystem2.ReferenceExists("comma.dll"));
            Assert.True(projectSystem2.ReferenceExists("dude.dll"));
        }
        public void ReinstallPackagesSkipRestallingForOneProjectButProceedWithTheOther()
        {
            // Arrange
            var localRepositoryMock = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
            var localRepository = localRepositoryMock.Object;
            var sourceRepository = new MockPackageRepository();

            var projectSystem1 = new MockProjectSystem(new FrameworkName(".NETFramework, Version=v3.0"));
            var pathResolver1 = new DefaultPackagePathResolver(projectSystem1);
            var packageReferenceRepository1 = new PackageReferenceRepository(projectSystem1, localRepository);
            var projectManager1 = new ProjectManager(localRepository, pathResolver1, projectSystem1, packageReferenceRepository1);

            var projectSystem2 = new MockProjectSystem(new FrameworkName(".NETCore, Version=v4.5"));
            var pathResolver2 = new DefaultPackagePathResolver(projectSystem2);
            var packageReferenceRepository2 = new PackageReferenceRepository(projectSystem2, localRepository);
            var projectManager2 = new ProjectManager(localRepository, pathResolver2, projectSystem2, packageReferenceRepository2);

            var project1 = TestUtils.GetProject("Project1");
            var project2 = TestUtils.GetProject("Project2");

            var packageManager = new MockVsPackageManager(
                TestUtils.GetSolutionManager(projects: new[] { project1, project2 }),
                sourceRepository,
                new Mock<IFileSystemProvider>().Object,
                projectSystem2,
                localRepository,
                new Mock<IDeleteOnRestartManager>().Object,
                new Mock<VsPackageInstallerEvents>().Object);

            packageManager.RegisterProjectManager(project1, projectManager1);
            packageManager.RegisterProjectManager(project2, projectManager2);

            var packageA = PackageUtility.CreatePackage(
                "A",
                "1.2-alpha",
                new[] { "net30\\content.txt", "silverlight40\\content4.txt" },
                new[] { "lib\\net30\\ref.dll", "lib\\silverlight40\\refsl.dll" });

            var packageB = PackageUtility.CreatePackage(
                "B",
                "2.0",
                new[] { "winrt45\\hello.txt", "sl4-wp71\\world.txt" },
                new[] { "lib\\winrt45\\comma.dll", "lib\\sl4-wp71\\dude.dll" });

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

            // install package A -> project 1
            // and package B -> project 2
            packageManager.InstallPackage(projectManager1, "A", new SemanticVersion("1.2-alpha"), ignoreDependencies: false, allowPrereleaseVersions: true, logger: null);
            packageManager.InstallPackage(projectManager2, "B", new SemanticVersion("2.0"), ignoreDependencies: false, allowPrereleaseVersions: true, logger: null);

            // now change project's target framework to silverlight
            projectSystem1.ChangeTargetFramework(new FrameworkName("Silverlight, Version=v4.0"));
            projectSystem2.ChangeTargetFramework(new FrameworkName("Silverlight, Version=v4.0, Profile=WindowsPhone71"));

            localRepositoryMock.Setup(p => p.IsReferenced("A", new SemanticVersion("1.2-alpha"))).Returns((string id, SemanticVersion version) => projectManager1.LocalRepository.Exists(id, version));
            localRepositoryMock.Setup(p => p.IsReferenced("B", new SemanticVersion("2.0"))).Returns((string id, SemanticVersion version) => projectManager2.LocalRepository.Exists(id, version));

            var logger = new Mock<ILogger>();
            logger.Setup(s => s.Log(
                MessageLevel.Warning,
                "Skipped reinstalling package '{0}' in project '{1}' because the package does not exist in the package source.",
                "B 2.0",
                "Project2")
            ).Verifiable();

            // Act
            packageManager.ReinstallPackages(updateDependencies: true, allowPrereleaseVersions: false, logger: logger.Object, eventListener: NullPackageOperationEventListener.Instance);

            // Assert
            logger.Verify();

            Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
            Assert.True(projectManager1.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));

            Assert.False(projectSystem1.FileExists("content.txt"));
            Assert.True(projectSystem1.FileExists("content4.txt"));
            Assert.False(projectSystem1.ReferenceExists("ref.dll"));
            Assert.True(projectSystem1.ReferenceExists("refsl.dll"));

            Assert.True(packageManager.LocalRepository.Exists("B", new SemanticVersion("2.0")));
            Assert.True(projectManager2.LocalRepository.Exists("B", new SemanticVersion("2.0")));

            Assert.True(projectSystem2.FileExists("hello.txt"));
            Assert.False(projectSystem2.FileExists("world.txt"));
            Assert.True(projectSystem2.ReferenceExists("comma.dll"));
            Assert.False(projectSystem2.ReferenceExists("dude.dll"));
        }
        public void ReinstallPackagesRestoresAllPackagesInAProjectWithNewContentIfProjectFrameworkChanges()
        {
            // Arrange
            var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object;
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework, Version=v3.0"));
            var pathResolver = new DefaultPackagePathResolver(projectSystem);

            var packageReferenceRepository = new PackageReferenceRepository(projectSystem, localRepository);
            var projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, packageReferenceRepository);

            var packageManager = new VsPackageManager(
                TestUtils.GetSolutionManager(),
                sourceRepository,
                new Mock<IFileSystemProvider>().Object,
                projectSystem,
                localRepository,
                new Mock<IDeleteOnRestartManager>().Object,
                new Mock<VsPackageInstallerEvents>().Object);

            var packageA = PackageUtility.CreatePackage(
                "A",
                "1.2-alpha",
                new[] { "net30\\content.txt", "silverlight40\\content4.txt" },
                new[] { "lib\\net30\\ref.dll", "lib\\silverlight40\\refsl.dll" });

            var packageB = PackageUtility.CreatePackage(
                "B",
                "2.0",
                new[] { "net30\\contentB.txt", "silverlight40\\content4B.txt" },
                new[] { "lib\\net30\\refB.dll", "lib\\silverlight40\\refslB.dll" });

            sourceRepository.Add(packageA);
            sourceRepository.Add(packageB);

            packageManager.InstallPackage(projectManager, "A", new SemanticVersion("1.2-alpha"), ignoreDependencies: false, allowPrereleaseVersions: true, logger: null);
            packageManager.InstallPackage(projectManager, "B", new SemanticVersion("2.0"), ignoreDependencies: false, allowPrereleaseVersions: true, logger: null);

            Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
            Assert.True(projectManager.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
            Assert.True(projectSystem.FileExists("content.txt"));
            Assert.False(projectSystem.FileExists("content4.txt"));
            Assert.True(projectSystem.ReferenceExists("ref.dll"));
            Assert.False(projectSystem.ReferenceExists("refsl.dll"));

            Assert.True(packageManager.LocalRepository.Exists("B"));
            Assert.True(projectManager.LocalRepository.Exists("B"));
            Assert.True(projectSystem.FileExists("contentB.txt"));
            Assert.False(projectSystem.FileExists("content4B.txt"));
            Assert.True(projectSystem.ReferenceExists("refB.dll"));
            Assert.False(projectSystem.ReferenceExists("refslB.dll"));

            // now change project's target framework to silverlight
            projectSystem.ChangeTargetFramework(new FrameworkName("Silverlight, Version=v4.0"));

            // Act
            packageManager.ReinstallPackages(projectManager, updateDependencies: true, allowPrereleaseVersions: false, logger: null);

            // Assert
            Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
            Assert.True(projectManager.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
            Assert.False(projectSystem.FileExists("content.txt"));
            Assert.True(projectSystem.FileExists("content4.txt"));
            Assert.False(projectSystem.ReferenceExists("ref.dll"));
            Assert.True(projectSystem.ReferenceExists("refsl.dll"));

            Assert.True(packageManager.LocalRepository.Exists("B"));
            Assert.True(projectManager.LocalRepository.Exists("B"));
            Assert.False(projectSystem.FileExists("contentB.txt"));
            Assert.True(projectSystem.FileExists("content4B.txt"));
            Assert.False(projectSystem.ReferenceExists("refB.dll"));
            Assert.True(projectSystem.ReferenceExists("refslB.dll"));
        }
Ejemplo n.º 16
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"));
        }
Ejemplo n.º 17
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"));
        }
Ejemplo n.º 18
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));
        }
Ejemplo n.º 19
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"));
        }
Ejemplo n.º 20
0
        public void AddPackageReferenceImportsTargetOrPropFileAtContentRoot()
        {
            // 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\\A.targets", "build\\a.props", "content\\foo.css" });
            mockPackageA.Setup(p => p.GetFiles()).Returns(files);

            mockRepository.AddPackage(mockPackageA.Object);

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

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

            Assert.Equal(1, projectSystem.Paths.Count);
            Assert.True(projectSystem.FileExists(@"foo.css"));
            Assert.False(projectSystem.FileExists(@"a.targets"));
            Assert.False(projectSystem.FileExists(@"A.props"));

            Assert.True(projectSystem.ImportExists("x:\\root\\A.1.0\\build\\A.props", ProjectImportLocation.Top));
            Assert.True(projectSystem.ImportExists("x:\\root\\A.1.0\\build\\A.targets", ProjectImportLocation.Bottom));
        }
Ejemplo n.º 21
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"));
        }
Ejemplo n.º 22
0
        public void AddPackageReferenceAddsContentAccordingToTargetFramework2()
        {
            // 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", "sub\\foo.css" },
                                                        new[] { "lib\\reference.dll" });

            mockRepository.AddPackage(packageA);

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

            // Assert
            Assert.Equal(1, projectSystem.Paths.Count);
            Assert.True(projectSystem.FileExists(@"sub\foo.css"));
            Assert.True(localRepository.Exists("A"));
        }
Ejemplo n.º 23
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"));
        }
Ejemplo n.º 24
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"));
        }
Ejemplo n.º 25
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"));
        }
Ejemplo n.º 26
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"));
        }
Ejemplo n.º 27
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"));
        }
Ejemplo n.º 28
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"));
        }
Ejemplo n.º 29
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"));
        }
Ejemplo n.º 30
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"));
        }