AddFile() public méthode

public AddFile ( string path ) : void
path string
Résultat void
        public void FindPackageFindTheRightPackage()
        {
            // Arrange
            var fileSystem = new MockFileSystem("c:\\");
            AddPackage(fileSystem, "A", "1.0");
            AddPackage(fileSystem, "B", "1.0-alpha");
            AddPackage(fileSystem, "C", "2.0.1-RC");
            AddPackage(fileSystem, "D", "3.0");

            // these are invalid packages (missing corresponding directory)
            fileSystem.AddFile("AA.2.0.nupkg");
            fileSystem.AddFile("BB.4.0.nupkg");
            fileSystem.CreateDirectory("BB.3.0");

            var pathResolver = new DefaultPackagePathResolver("c:\\");
            var repository = new UnzippedPackageRepository(pathResolver, fileSystem);

            // Act
            var packageA = repository.FindPackage("A", new SemanticVersion("1.0"));
            var packageB = repository.FindPackage("B", new SemanticVersion("1.0-alpha"));

            // Assert
            AssertPackage(packageA, "A", new SemanticVersion("1.0"));
            AssertPackage(packageB, "B", new SemanticVersion("1.0.0-alpha"));
        }
        public void GetPackagesReturnsAllValidPackages()
        {
            // Arrange
            var fileSystem = new MockFileSystem("c:\\");
            AddPackage(fileSystem, "A", "1.0");
            AddPackage(fileSystem, "B", "1.0-alpha");
            AddPackage(fileSystem, "C", "2.0.1-RC");
            AddPackage(fileSystem, "D", "3.0");

            // these are invalid packages (missing corresponding directory)
            fileSystem.AddFile("AA.2.0.nupkg");
            fileSystem.AddFile("BB.4.0.nupkg");
            fileSystem.CreateDirectory("BB.3.0");

            var pathResolver = new DefaultPackagePathResolver("c:\\");
            var repository = new UnzippedPackageRepository(pathResolver, fileSystem);

            // Act
            var packages = repository.GetPackages().ToList();

            // Assert
            Assert.Equal(4, packages.Count);
            AssertPackage(packages[0], "A", new SemanticVersion("1.0"));
            AssertPackage(packages[1], "B", new SemanticVersion("1.0.0-alpha"));
            AssertPackage(packages[2], "C", new SemanticVersion("2.0.1-RC"));
            AssertPackage(packages[3], "D", new SemanticVersion("3.0"));
        }
        public void ConfigFoundInDirectoryHierarchyIsCached()
        {
            // Arrange
            var solutionManager = new Mock<ISolutionManager>();
            solutionManager.Setup(m => m.SolutionDirectory).Returns(@"bar\baz");
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile(@"bar\nuget.config", @"
            <settings>
            <repositoryPath>lib</repositoryPath>
            </settings>");
            var fileSystemProvider = new Mock<IFileSystemProvider>();
            fileSystemProvider.Setup(m => m.GetFileSystem(@"bar\baz")).Returns(fileSystem);
            var repositorySettings = new RepositorySettings(solutionManager.Object, fileSystemProvider.Object);

            // Act
            string p1 = repositorySettings.RepositoryPath;

            fileSystem.AddFile(@"bar\baz\nuget.config", @"
            <settings>
            <repositoryPath>foo</repositoryPath>
            </settings>");

            string p2 = repositorySettings.RepositoryPath;

            // Assert
            Assert.AreEqual(@"bar\lib", p1);
            Assert.AreEqual(@"bar\lib", p2);
        }
        public void LoadPortableProfileWithMonoAsSupportedFramework()
        {
            // Arrange
            string content1 = @"
<Framework
    Identifier="".NETFramework""
    Profile=""*""
    MinimumVersion=""4.5""
    DisplayName="".NET Framework"" />";

            string content2 = @"
<Framework
    Identifier=""MonoTouch""
    MinimumVersion=""1.0""
    DisplayName=""Mono Touch"" />";

            var mockFileSystem = new MockFileSystem();
            mockFileSystem.AddFile("frameworkFile1.xml", content1);
            mockFileSystem.AddFile("frameworkFile2.xml", content2);

            var frameworkFiles = new string[] { "frameworkFile1.xml", "frameworkFile2.xml" };

            // Act
            var netPortableProfile = NetPortableProfileTable.LoadPortableProfile("4.5.0.0", "Profile1", mockFileSystem, frameworkFiles);

            // Assert
            Assert.True(netPortableProfile.SupportedFrameworks.Count == 1);
            Assert.True(netPortableProfile.SupportedFrameworks.Contains(new FrameworkName(".NETFramework, Version=4.5")));

            Assert.True(netPortableProfile.OptionalFrameworks.Count == 1);
            Assert.True(netPortableProfile.OptionalFrameworks.Contains(new FrameworkName("MonoTouch, Version=1.0")));
        }
        public void ResolvedRefreshPathsIgnoresFilesThatDoNotExist()
        {
            // Arrange
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile(@"bin\Foo.refresh", "x:\foo.dll");
            fileSystem.AddFile(@"bin\bar.refresh", "bar.dll");
            fileSystem.AddFile(@"C:\MockFileSystem\bar.dll");

            // Act
            var resolvedPaths = fileSystem.ResolveRefreshPaths();

            // Assert
            Assert.Equal(new[] { @"C:\MockFileSystem\bar.dll" }, resolvedPaths);
        }
        public void AddingBindingRedirectToEmptyConfig()
        {
            // Arrange            
            var mockFileSystem = new MockFileSystem();
            mockFileSystem.AddFile("config", @"<configuration></configuration>");

            var bindingRedirectManager = new BindingRedirectManager(mockFileSystem, "config");
            AssemblyBinding assemblyBinding = GetAssemblyBinding("AssemblyName", "token", "3.0.0.0");

            // Act
            bindingRedirectManager.AddBindingRedirects(new[] { assemblyBinding });

            // Assert
            string outputContent = mockFileSystem.OpenFile("config").ReadToEnd();
            Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
  <runtime>
    <assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1"">
      <dependentAssembly>
        <assemblyIdentity name=""AssemblyName"" publicKeyToken=""token"" culture=""neutral"" />
        <bindingRedirect oldVersion=""0.0.0.0-3.0.0.0"" newVersion=""3.0.0.0"" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>", outputContent);
        }
        public void MirrorCommandForPackageReferenceFileWarnsIfThereIsNoPackageToMirror()
        {
            // Arrange
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile(@"x:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
</packages>".AsStream());

            MessageLevel? level = null;
            string message = null;
            var console = new Mock<IConsole>();
            console.Setup(c => c.Log(It.IsAny<MessageLevel>(), It.IsAny<string>(), It.IsAny<object[]>())).Callback((MessageLevel a, string b, object[] c) =>
            {
                if (a == MessageLevel.Warning)
                {
                    level = a;
                    message = b;
                }
            });

            var mirrorCommand = new TestMirrorCommand(@"x:\test\packages.config", fileSystem: fileSystem) { Console = console.Object };

            // Act
            mirrorCommand.ExecuteCommand();

            // Assert
            Assert.Equal(level, MessageLevel.Warning);
            Assert.Equal(message, "No packages found to check for mirroring.");
        }
        public void DeleteFileAndEmptyParentDirectoriesDoNotDeleteParentDirectoryIfNotEmpty()
        {
            // Arrange
            var fileSystem = new MockFileSystem("x:\\");
            fileSystem.AddFile("foo\\bar\\hell\\x.txt");
            fileSystem.AddFile("foo\\bar\\y.txt");

            // Act
            fileSystem.DeleteFileAndParentDirectoriesIfEmpty("foo\\bar\\hell\\x.txt");

            // Assert
            Assert.False(fileSystem.FileExists("foo\\bar\\hell\\x.txt"));
            Assert.True(fileSystem.DirectoryExists("foo"));
            Assert.True(fileSystem.DirectoryExists("foo\\bar"));
            Assert.False(fileSystem.DirectoryExists("foo\\bar\\hell"));
        }
 private ConfigurationDefaults GetConfigurationDefaults(string configurationDefaultsContent)
 {
     var mockFileSystem = new MockFileSystem();
     var configurationDefaultsPath = "NuGetDefaults.config";
     mockFileSystem.AddFile(configurationDefaultsPath, configurationDefaultsContent);
     return new ConfigurationDefaults(mockFileSystem, configurationDefaultsPath);
 }
Exemple #10
0
        public void RestoreCommandMultipleSolutionFiles()
        {
            // Arrange
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("a.sln");
            fileSystem.AddFile("b.sln");

            var restoreCommand = new RestoreCommand()
            {
                FileSystem = fileSystem
            };

            // Assert
            ExceptionAssert.Throws<InvalidOperationException>(
                () => restoreCommand.DetermineRestoreMode(),
                "This folder contains more than one solution file.");
        }
Exemple #11
0
        public void RestoreCommandPreferSolutionFile()
        {
            // Arrange
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("a.sln");
            fileSystem.AddFile("packages.config");

            var restoreCommand = new RestoreCommand()
            {
                FileSystem = fileSystem
            };

            // Act
            restoreCommand.DetermineRestoreMode();

            // Assert
            Assert.True(restoreCommand.RestoringForSolution);
            Assert.Equal(fileSystem.GetFullPath("a.sln"), restoreCommand.SolutionFileFullPath);
        }
        public void AddRefreshFilesForAssembliesReferencesIncludeFilesUnderLibRoot()
        {
            // Arrange
            var projectSystem = new MockProjectSystem();
            var projectSystemFactory = new Mock<IProjectSystemFactory>();
            projectSystemFactory.Setup(p => p.CreateProjectSystem(It.IsAny<Project>(), It.IsAny<IFileSystemProvider>()))
                                .Returns(projectSystem);

            var websiteHandler = new VsWebsiteHandler(null, projectSystemFactory.Object);

            var packagesFileSystem = new MockFileSystem("x:\\some\\path");
            packagesFileSystem.CreateDirectory("A.1.0");
            packagesFileSystem.CreateDirectory("A.1.0\\lib");
            packagesFileSystem.AddFile("A.1.0\\lib\\one.dll");
            packagesFileSystem.AddFile("A.1.0\\lib\\two.winmd");

            packagesFileSystem.CreateDirectory("B.3.0.0-beta");
            packagesFileSystem.CreateDirectory("B.3.0.0-beta\\lib");
            packagesFileSystem.AddFile("B.3.0.0-beta\\lib\\three.dll");
            packagesFileSystem.AddFile("B.3.0.0-beta\\lib\\four.exe");

            var properties = new MockDteProperties();
            properties.AddProperty("FullPath", "x:\\project");
            properties.AddProperty("TargetFrameworkMoniker", ".NETFramework,Version=v4.0");

            var website = new Mock<Project>();
            website.Setup(p => p.Kind).Returns(VsConstants.WebSiteProjectTypeGuid);
            website.Setup(p => p.Properties).Returns(properties);

            // Act
            websiteHandler.AddRefreshFilesForReferences(
                website.Object, packagesFileSystem, new[] { new PackageName("A", new SemanticVersion("1.0")), 
                                                            new PackageName("B", new SemanticVersion("3.0.0-beta"))});

            // Assert
            Assert.True(projectSystem.DirectoryExists("bin"));
            var refreshFiles = projectSystem.GetFiles("bin", "*.refresh").OrderBy(s => s).ToList();
            Assert.Equal(4, refreshFiles.Count);
            Assert.Equal("bin\\four.exe.refresh", refreshFiles[0]);
            Assert.Equal("bin\\one.dll.refresh", refreshFiles[1]);
            Assert.Equal("bin\\three.dll.refresh", refreshFiles[2]);
            Assert.Equal("bin\\two.winmd.refresh", refreshFiles[3]);
        }
        public void MissingManifestFileThrows()
        {
            // Arrange
            var fileSystem = new MockFileSystem();
            fileSystem.CreateDirectory("jQuery.2.0.0");
            fileSystem.AddFile("jQuery.2.0.0.nupkg");

            // Act & Assert
            Assert.Throws(typeof(InvalidOperationException), () => new UnzippedPackage(fileSystem, "jQuery.2.0.0"));
        }
        public void GetPackageReferencesNormalizeProjectName()
        {
            // Arrange
            var config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""luan"" version=""1.0"" />
</packages>";

            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", config);
            fileSystem.AddFile("packages.project_with_space.config", config);
            var packageReferenceFile = new PackageReferenceFile(fileSystem, "packages.config", "project with space");

            // Act
            var values = packageReferenceFile.GetPackageReferences().ToArray();

            // Assert
            Assert.Equal(1, values.Length);
            Assert.Equal("luan", values[0].Id);
        }
Exemple #15
0
        public void CallingCtorWithMalformedConfigThrowsException()
        {
            var mockFileSystem = new MockFileSystem();
            var nugetConfigPath = "NuGet.Config";
            string config = @"<configuration><sectionName></configuration>";
            mockFileSystem.AddFile(nugetConfigPath, config);

            // Act & Assert
            ExceptionAssert.Throws<System.Xml.XmlException>(() => new Settings(mockFileSystem));

        }
        public void EnsureManifestIsParsedCorrectly()
        {
            // Arrange
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("Jumpo.1.0.0.nupkg");
            fileSystem.CreateDirectory("Jumpo.1.0.0");
            fileSystem.AddFile("Jumpo.1.0.0\\Jumpo.1.0.0.nuspec", GetCompleteManifestContent());

            // Act
            var package = new UnzippedPackage(fileSystem, "Jumpo.1.0.0");

            // Assert
            Assert.Equal("Jumpo", package.Id);
            Assert.Equal(new SemanticVersion("1.0.0"), package.Version);
            Assert.Equal(1, package.Authors.Count());
            Assert.Equal("dotnetjunky", package.Authors.ElementAt(0));
            Assert.Equal(1, package.Owners.Count());
            Assert.Equal("Outercurve", package.Owners.ElementAt(0));
            Assert.Equal("http://www.nuget.com/license", package.LicenseUrl.ToString());
            Assert.Equal("http://www.nuget.com/", package.ProjectUrl.ToString());
            Assert.Equal("http://www.outercurve.com/", package.IconUrl.ToString());
            Assert.Equal(1, package.DependencySets.Count());
            Assert.Equal("bing", package.DependencySets.ElementAt(0).Dependencies.ElementAt(0).Id);
            Assert.Equal(new SemanticVersion("1.0-RC"), package.DependencySets.ElementAt(0).Dependencies.ElementAt(0).VersionSpec.MinVersion);
            Assert.True(package.DependencySets.ElementAt(0).Dependencies.ElementAt(0).VersionSpec.IsMinInclusive);
            Assert.Equal(null, package.DependencySets.ElementAt(0).Dependencies.ElementAt(0).VersionSpec.MaxVersion);
            Assert.False(package.DependencySets.ElementAt(0).Dependencies.ElementAt(0).VersionSpec.IsMaxInclusive);
            Assert.Equal("Jumpo Jet", package.Title);
            Assert.True(package.RequireLicenseAcceptance);
            Assert.Equal("My package description.", package.Description);
            Assert.Equal("This is jumpo package.", package.Summary);
            Assert.Equal("New jumpo.", package.ReleaseNotes);
            Assert.Equal("ar-EG", package.Language);
            Assert.Equal(" haha void ", package.Tags);
            Assert.Equal(1, package.FrameworkAssemblies.Count());
            Assert.Equal("System", package.FrameworkAssemblies.ElementAt(0).AssemblyName);
            Assert.Equal(1, package.FrameworkAssemblies.ElementAt(0).SupportedFrameworks.Count());
            Assert.Equal(
                new FrameworkName(".NETFramework", new Version("4.5")), 
                package.FrameworkAssemblies.ElementAt(0).SupportedFrameworks.ElementAt(0));
        }
        public void PackageDirectoriesAreMarkedForDeletionIsTrueWhenDeletemeFileInRootOfPackageRepository()
        {
            // Arrange
            var fileSystem = new MockFileSystem();
            fileSystem.CreateDirectory("A.1.0.0");
            fileSystem.AddFile("A.1.0.0.deleteme");

            var deleteOnRestartManager = new DeleteOnRestartManager(() => fileSystem);

            // Assert
            Assert.True(deleteOnRestartManager.PackageDirectoriesAreMarkedForDeletion);
        }
        public void AddingBindingRedirectWithMultipleAssemblyBindingSectionsAddsToFirstOne()
        {
            // Arrange            
            var mockFileSystem = new MockFileSystem();
            mockFileSystem.AddFile("config", @"
<configuration>
    <runtime>
        <assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1"">
            <dependentAssembly>
                <assemblyIdentity name=""System.Web.Mvc"" publicKeyToken=""31bf3856ad364e35"" />
                <bindingRedirect oldVersion=""1.0.0.0"" newVersion=""2.0.0.0"" />
            </dependentAssembly>
        </assemblyBinding>
        <assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1"">
            <dependentAssembly>
                <assemblyIdentity name=""A.Library"" publicKeyToken=""a34a755ec277222f"" />
                <bindingRedirect oldVersion=""1.0.0.0-2.0.0.0"" newVersion=""2.0.0.0"" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>");

            var bindingRedirectManager = new BindingRedirectManager(mockFileSystem, "config");
            AssemblyBinding assemblyBinding = GetAssemblyBinding("AssemblyName", "token", "3.0.0.0");

            // Act
            bindingRedirectManager.AddBindingRedirects(new[] { assemblyBinding });

            // Assert
            string outputContent = mockFileSystem.OpenFile("config").ReadToEnd();
            Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
    <runtime>
        <assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1"">
            <dependentAssembly>
                <assemblyIdentity name=""System.Web.Mvc"" publicKeyToken=""31bf3856ad364e35"" />
                <bindingRedirect oldVersion=""1.0.0.0"" newVersion=""2.0.0.0"" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name=""AssemblyName"" publicKeyToken=""token"" culture=""neutral"" />
                <bindingRedirect oldVersion=""0.0.0.0-3.0.0.0"" newVersion=""3.0.0.0"" />
            </dependentAssembly>
        </assemblyBinding>
        <assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1"">
            <dependentAssembly>
                <assemblyIdentity name=""A.Library"" publicKeyToken=""a34a755ec277222f"" />
                <bindingRedirect oldVersion=""1.0.0.0-2.0.0.0"" newVersion=""2.0.0.0"" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>", outputContent);
        }
        public void ConstructorNormalizeProjectName()
        {
            // Arrange
            var fileSystem = new MockFileSystem("x:\\");
            fileSystem.AddFile("packages.project_with_space.config", "");

            // Act
            var packageReferenceFile = new PackageReferenceFile(
                fileSystem, "packages.config", "project with space");

            // Assert
            Assert.Equal("x:\\packages.project_with_space.config", packageReferenceFile.FullPath);
        }
Exemple #20
0
        public void RemoveOldFileDeletesNuGetFileWithExtensionOldIfExist()
        {
            // Arrange
            var oldFilePath = GetOldExePath();
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile(oldFilePath);

            // Act
            Program.RemoveOldFile(fileSystem);

            // Assert
            Assert.Equal(oldFilePath, fileSystem.Deleted.SingleOrDefault(), StringComparer.OrdinalIgnoreCase);
        }
        public void MarkPackageDirectoryForDeletionAddsDeletemeFileWhenDirectoryRemovalUnsuccessful()
        {
            // Arrange
            IPackage package = NuGet.Test.PackageUtility.CreatePackage(id: "foo", version: "1.0.0", content: new string[] { }, assemblyReferences: new string[] { }, tools: new[] { "lockedFile.txt" });
            var fileSystem = new MockFileSystem();
            var pathResolver = new DefaultPackagePathResolver(fileSystem);
            string packageDirectoryPath = pathResolver.GetPackageDirectory(package);
            string lockedFilePath = Path.Combine("tools", "lockedFile.txt");

            fileSystem.AddFile(Path.Combine(packageDirectoryPath, pathResolver.GetPackageFileName(package)), Stream.Null);
            fileSystem.AddFile(Path.Combine(packageDirectoryPath, packageDirectoryPath + Constants.ManifestExtension), Stream.Null);
            fileSystem.AddFile(Path.Combine(packageDirectoryPath, lockedFilePath), lockedFilePath.AsStream());

            var deleteOnRestartManager = new DeleteOnRestartManager(() => fileSystem, () => pathResolver);

            // Act
            deleteOnRestartManager.MarkPackageDirectoryForDeletion(package);

            // Assert
            Assert.True(fileSystem.DirectoryExists(packageDirectoryPath));
            Assert.True(fileSystem.FileExists(packageDirectoryPath + _deletionMarkerSuffix));
        }
Exemple #22
0
        public void RemoveOldFileDoesNotDeletesOldNuGetFileIfItDoesNotExistUnderWorkingDirectory()
        {
            // Arrange
            var oldFilePath = GetOldExePathUnderSubdirectory();
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile(oldFilePath);

            // Act
            Program.RemoveOldFile(fileSystem);

            // Assert
            Assert.False(fileSystem.Deleted.Any());
        }
        public void MarkPackageDirectoryForDeletionDoesNotAddDeletemeFileWhenFileModified()
        {
            // Arrange
            IPackage package = NuGet.Test.PackageUtility.CreatePackage(id: "foo", version: "1.0.0", content: new string[] {}, assemblyReferences: new string[] {}, tools: new[] { "modifiedFile.txt" });
            var fileSystem = new MockFileSystem();
            var pathResolver = new DefaultPackagePathResolver(fileSystem);
            string packageDirectoryPath = pathResolver.GetPackageDirectory(package);
            string modifiedFilePath = Path.Combine("tools", "modifiedFile.txt");

            fileSystem.AddFile(Path.Combine(packageDirectoryPath, pathResolver.GetPackageFileName(package)), Stream.Null);
            fileSystem.AddFile(Path.Combine(packageDirectoryPath, modifiedFilePath), "Modified Content".AsStream());

            var deleteOnRestartManager = new DeleteOnRestartManager(() => fileSystem, () => pathResolver);

            // Act
            deleteOnRestartManager.MarkPackageDirectoryForDeletion(package, _ => package);

            // Assert
            Assert.True(fileSystem.DirectoryExists(packageDirectoryPath));
            Assert.True(fileSystem.FileExists(Path.Combine(packageDirectoryPath, modifiedFilePath)));
            Assert.False(fileSystem.FileExists(packageDirectoryPath + _deletionMarkerSuffix));
        }
        public void PackageDirectoriesAreMarkedForDeletionIsFalsesWhenNoDeletemeFileInRootOfPackageRepository()
        {
            // Arrange
            var fileSystem = new MockFileSystem();
            fileSystem.CreateDirectory("A.1.0.0");
            fileSystem.AddFile("A.1.0.0");

            var deleteOnRestartManager = new DeleteOnRestartManager(() => fileSystem);

            // Act
            // Assert
            Assert.False(deleteOnRestartManager.GetPackageDirectoriesMarkedForDeletion().Any());
        }
        public void CallRemovePackageWillRemoveNuspecFile(string id, string version, string unexpectedPath)
        {
            // Arrange
            var fileSystem = new MockFileSystem("x:\\root");
            fileSystem.AddFile(unexpectedPath);
            var configFileSystem = new MockFileSystem();
            var repository = new SharedPackageRepository(new DefaultPackagePathResolver(fileSystem), fileSystem, configFileSystem);

            // Act
            repository.RemovePackage(PackageUtility.CreatePackage(id, version));

            // Assert
            Assert.False(fileSystem.FileExists(unexpectedPath));
        }
        public void InstallCommandForPackageReferenceFileDoesNotThrowIfThereIsNoPackageToInstall()
        {
            // Arrange
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile(@"x:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
</packages>".AsStream());

            var installCommand = new TestInstallCommand(GetFactory(), GetSourceProvider(), fileSystem, allowPackageRestore: false);
            installCommand.Arguments.Add(@"x:\test\packages.config");

            // Act & Assert
            installCommand.ExecuteCommand();
        }
Exemple #27
0
        public void GetCommandLineSettingsReturnsSettingsFromLocalFileIfExists()
        {
            // Arrange
            var fileContent = @"<?xml version=""1.0""?><configuration><fooSection><add key=""barValue"" value=""qux"" /></fooSection></configuration>";
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("NuGet.config", fileContent.AsStream());

            // Act
            var settings = Program.GetCommandLineSettings(fileSystem);
            var value = settings.GetValue("fooSection", "barValue");

            // Assert
            Assert.Equal("qux", value);
        }
        public void GetPackageReferencesReadFromProjectConfigFileIfPresent()
        {
            // Arrange
            var config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""luan"" version=""1.0"" />
</packages>";

            var projectConfig = @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""an"" version=""1.0"" />
</packages>";
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", config);
            fileSystem.AddFile("packages.project.config", projectConfig);
            var packageReferenceFile = new PackageReferenceFile(fileSystem, "packages.config", "project");

            // Act
            var values = packageReferenceFile.GetPackageReferences().ToArray();

            // Assert
            Assert.Equal(1, values.Length);
            Assert.Equal("an", values[0].Id);
        }
        public void GetPackageReferencesThrowsIfVersionIsNotPresent()
        {
            // Arrange
            var config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""A"" version="""" />
</packages>";
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", config);
            var packageReferenceFile = new PackageReferenceFile(fileSystem, "packages.config");

            // Act
            var values = packageReferenceFile.GetPackageReferences();

            // Assert
            Assert.Empty(values);
        }
        public void CallingCtorDoesNotExpandFiles()
        {
            // Arrange
            var ms = GetPackageStream();

            var fileSystem = new MockFileSystem("x:\\");
            fileSystem.AddFile("pam.nupkg", ms);

            var expandedFileSystem = new MockFileSystem();

            // Act
            var ozp = new TestableOptimizedZipPackage(fileSystem, "pam.nupkg", expandedFileSystem);

            // Assert
            Assert.False(ozp.HasCalledExpandedFolderPath);
            Assert.Equal(0, expandedFileSystem.Paths.Count);
        }