Exemplo n.º 1
0
        public void InstallPackageAddsAllFilesToFileSystem()
        {
            // Arrange
            var projectSystem    = new MockProjectSystem();
            var sourceRepository = new MockPackageRepository();
            var packageManager   = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem);

            IPackage packageA = PackageUtility.CreatePackage("A", "1.0",
                                                             new[] { "contentFile", @"sub\contentFile" },
                                                             new[] { @"lib\reference.dll" },
                                                             new[] { @"readme.txt" });

            sourceRepository.AddPackage(packageA);

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

            // Assert
            Assert.AreEqual(0, projectSystem.References.Count);
            Assert.AreEqual(5, projectSystem.Paths.Count);
            Assert.IsTrue(projectSystem.FileExists(@"A.1.0\content\contentFile"));
            Assert.IsTrue(projectSystem.FileExists(@"A.1.0\content\sub\contentFile"));
            Assert.IsTrue(projectSystem.FileExists(@"A.1.0\lib\reference.dll"));
            Assert.IsTrue(projectSystem.FileExists(@"A.1.0\tools\readme.txt"));
            Assert.IsTrue(projectSystem.FileExists(@"A.1.0\A.1.0.nupkg"));
        }
Exemplo n.º 2
0
        public void InstallSatellitePackageCopiesFilesToExistingRuntimePackageFolder()
        {
            // Arrange
            // Create a runtime package and a satellite package that has a dependency on the runtime package, and uses the
            // local suffix convention.
            var runtimePackage = PackageUtility.CreatePackage("foo", "1.0.0", assemblyReferences: new[] { @"lib\foo.dll" });

            var satellitePackage = PackageUtility.CreatePackage("foo.ja-jp", "1.0.0", language: "ja-jp",
                                                                satelliteAssemblies: new[] { @"lib\ja-jp\foo.resources.dll", @"lib\ja-jp\foo.xml" },
                                                                dependencies: new[] { new PackageDependency("foo", VersionUtility.ParseVersionSpec("[1.0.0]")) });

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

            sourceRepository.AddPackage(runtimePackage);
            sourceRepository.AddPackage(satellitePackage);

            // Act
            Install("foo", new NullProjectManager(packageManager));
            Install("foo.ja-jp", new NullProjectManager(packageManager));

            // Assert
            Assert.True(projectSystem.FileExists(@"foo.1.0.0\lib\foo.dll"));
            Assert.True(projectSystem.FileExists(@"foo.1.0.0\lib\ja-jp\foo.resources.dll"));
            Assert.True(projectSystem.FileExists(@"foo.1.0.0\lib\ja-jp\foo.xml"));
            Assert.True(projectSystem.FileExists(@"foo.ja-jp.1.0.0\lib\ja-jp\foo.resources.dll"));
            Assert.True(projectSystem.FileExists(@"foo.ja-jp.1.0.0\lib\ja-jp\foo.xml"));
        }
Exemplo n.º 3
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());
        }
Exemplo n.º 4
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"));
        }
Exemplo n.º 5
0
        public void UninstallingSatellitePackageRemovesCollidingRuntimeFiles()
        {
            // Arrange
            // Create a runtime package and a satellite package that has a dependency on the runtime package, and uses the
            // local suffix convention.
            var runtimePackage = PackageUtility.CreatePackage("foo", "1.0.0",
                                                              assemblyReferences: new[] { @"lib\ja-jp\collision.txt" });

            var satellitePackage = PackageUtility.CreatePackage("foo.ja-jp", "1.0.0", language: "ja-jp",
                                                                satelliteAssemblies: new[] { @"lib\ja-jp\collision.txt" },
                                                                dependencies: new[] { new PackageDependency("foo", VersionUtility.ParseVersionSpec("[1.0.0]")) });

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

            sourceRepository.AddPackage(runtimePackage);
            sourceRepository.AddPackage(satellitePackage);

            // Act
            packageManager.InstallPackage("foo");
            packageManager.InstallPackage("foo.ja-jp");

            packageManager.UninstallPackage("foo.ja-jp");

            // Assert
            Assert.Equal(0, projectSystem.Paths.Count);
            Assert.False(projectSystem.FileExists(@"foo.1.0.0\lib\ja-jp\collision.txt"));
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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.True(mockFileSystem.FileExists(@"A.1.0\A.1.0.nupkg"));
        }
Exemplo n.º 8
0
        public void AddFilesAskingForResolutionForEveryConflict()
        {
            var resolutions = new FileConflictResolution[]
            {
                FileConflictResolution.Ignore,
                FileConflictResolution.Overwrite,
                FileConflictResolution.Ignore,
                FileConflictResolution.IgnoreAll,
                FileConflictResolution.OverwriteAll,
                FileConflictResolution.Overwrite,
            };

            var index  = 0;
            var logger = new Mock <ILogger>();

            logger.Setup(l => l.ResolveFileConflict(It.IsAny <string>()))
            .Returns(() => resolutions[index++]);

            // Arrange
            var project = new MockProjectSystem();

            project.AddFile("a.txt", "this is a");
            project.AddFile("b.txt", "this is b");
            project.AddFile("c.txt", "this is c");
            project.AddFile("d.txt", "this is d");
            project.AddFile("e.txt", "this is e");
            project.AddFile("f.txt", "this is f");
            project.Logger = logger.Object;

            var files = PackageUtility.CreateFiles(new [] { "a.txt", "b.txt", "c.txt", "d.txt", "e.txt", "f.txt" }, "content");

            // Act
            project.AddFiles(files, new Dictionary <FileTransformExtensions, IPackageFileTransformer>());

            // Assert
            Assert.True(project.FileExists("a.txt"));
            Assert.True(project.FileExists("b.txt"));
            Assert.True(project.FileExists("c.txt"));
            Assert.True(project.FileExists("d.txt"));
            Assert.True(project.FileExists("e.txt"));
            Assert.True(project.FileExists("f.txt"));

            logger.Verify(l => l.ResolveFileConflict(It.IsAny <string>()), Times.Exactly(6));

            Assert.Equal("this is a", project.ReadAllText("a.txt"));
            Assert.Equal("content\\b.txt", project.ReadAllText("b.txt"));
            Assert.Equal("this is c", project.ReadAllText("c.txt"));
            Assert.Equal("this is d", project.ReadAllText("d.txt"));
            Assert.Equal("content\\e.txt", project.ReadAllText("e.txt"));
            Assert.Equal("content\\f.txt", project.ReadAllText("f.txt"));
        }
Exemplo n.º 9
0
        public void AddFilesDoNotCallResolveFileConflictIfTheConflictFileDoesNotBelongToProject()
        {
            var logger = new Mock <ILogger>();

            // Arrange
            var project = new MockProjectSystem();

            project.AddFile("a.txt", "this is a");
            project.AddFile("b.txt", "this is b");
            project.ExcludeFileFromProject("b.txt");
            project.Logger = logger.Object;

            var files = PackageUtility.CreateFiles(new[] { "b.txt", "d.txt" }, "content");

            // Act
            project.AddFiles(files, new Dictionary <FileTransformExtensions, IPackageFileTransformer>());

            // Assert
            Assert.True(project.FileExists("d.txt"));
            Assert.False(project.FileExistsInProject("b.txt"));
            logger.Verify(l => l.ResolveFileConflict(It.IsAny <string>()), Times.Never());
        }
Exemplo n.º 10
0
        public void UninstallingSatellitePackageRemovesFilesFromRuntimePackageFolder()
        {
            // Arrange
            // Create a runtime package and a satellite package that has a dependency on the runtime package, and uses the
            // local suffix convention.
            var runtimePackage = PackageUtility.CreatePackage("foo", "1.0.0",
                                                              assemblyReferences: new[] {
                @"lib\foo.dll"
            },
                                                              content: new[] {
                @"english.txt"
            });

            var satellitePackage = PackageUtility.CreatePackage("foo.ja-jp", "1.0.0", language: "ja-jp",
                                                                satelliteAssemblies: new[] {
                @"lib\ja-jp\foo.resources.dll",
                @"lib\ja-jp\foo.xml",
                @"lib\japanese.xml"
            },
                                                                content: new[] {
                @"english.txt",
                @"japanese.txt"
            },
                                                                dependencies: new[] { new PackageDependency("foo") });

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

            sourceRepository.AddPackage(runtimePackage);
            sourceRepository.AddPackage(satellitePackage);

            // Act
            packageManager.InstallPackage("foo");
            packageManager.InstallPackage("foo.ja-jp");

            packageManager.UninstallPackage("foo.ja-jp");

            // Assert
            Assert.Equal(2, projectSystem.Paths.Count);
            Assert.True(projectSystem.FileExists(@"foo.1.0.0\content\english.txt"));
            Assert.True(projectSystem.FileExists(@"foo.1.0.0\lib\foo.dll"));
            Assert.False(projectSystem.FileExists(@"foo.1.0.0\lib\ja-jp\foo.resources.dll"));
            Assert.False(projectSystem.FileExists(@"foo.1.0.0\lib\ja-jp\foo.xml"));

            Assert.False(projectSystem.FileExists(@"foo.ja-jp.1.0.0\content\english.txt"));
            Assert.False(projectSystem.FileExists(@"foo.ja-jp.1.0.0\content\japanese.txt"));
            Assert.False(projectSystem.FileExists(@"foo.ja-jp.1.0.0\lib\japanese.xml"));
            Assert.False(projectSystem.FileExists(@"foo.ja-jp.1.0.0\lib\ja-jp\foo.resources.dll"));
            Assert.False(projectSystem.FileExists(@"foo.ja-jp.1.0.0\lib\ja-jp\foo.xml"));

            Assert.False(projectSystem.FileExists(@"foo.1.0.0\lib\japanese.xml"));
            Assert.False(projectSystem.FileExists(@"foo.1.0.0\content\japanese.txt"));
        }
Exemplo n.º 11
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());
        }