Ejemplo n.º 1
0
        public void GetFallbackPackageFolders_MultipleFoldersFromMultipleNuGetConfigs()
        {
            // Arrange
            var configA = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
    <fallbackPackageFolders>
        <add key=""a"" value=""C:\Temp\a"" />
        <add key=""b"" value=""C:\Temp\b"" />
    </fallbackPackageFolders>
</configuration>";

            var configB = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
    <fallbackPackageFolders>
        <add key=""c"" value=""C:\Temp\c"" />
        <add key=""d"" value=""C:\Temp\d"" />
    </fallbackPackageFolders>
</configuration>";

            var configC = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
    <fallbackPackageFolders>
        <add key=""x"" value=""C:\Temp\x"" />
        <add key=""y"" value=""C:\Temp\y"" />
    </fallbackPackageFolders>
</configuration>";

            var nugetConfigPath = "NuGet.Config";

            using (var machineWide = TestDirectory.Create())
                using (var mockBaseDirectory = TestDirectory.Create())
                {
                    var subFolder = Path.Combine(mockBaseDirectory, "sub");

                    ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, subFolder, configA);
                    ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, configB);
                    ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, machineWide, configC);

                    var machineWiderFolderSettings = new Settings(machineWide);
                    var machineWideSettings        = new TestMachineWideSettings(machineWiderFolderSettings);

                    var settings = Settings.LoadDefaultSettings(
                        subFolder,
                        configFileName: null,
                        machineWideSettings: machineWideSettings);

                    // Act
                    var paths = SettingsUtility.GetFallbackPackageFolders(settings).ToArray();

                    // Assert
                    Assert.Equal(6, paths.Length);
                    Assert.Equal("a", GetFileName(paths[0]));
                    Assert.Equal("b", GetFileName(paths[1]));
                    Assert.Equal("c", GetFileName(paths[2]));
                    Assert.Equal("d", GetFileName(paths[3]));
                    Assert.Equal("x", GetFileName(paths[4]));
                    Assert.Equal("y", GetFileName(paths[5]));
                }
        }
Ejemplo n.º 2
0
        public void GetFallbackPackageFolders_MultipleFoldersFromMultipleNuGetConfigs()
        {
            // Arrange
            var configA = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
    <fallbackPackageFolders>
        <add key=""a"" value=""C:\Temp\a"" />
        <add key=""b"" value=""C:\Temp\b"" />
    </fallbackPackageFolders>
</configuration>";

            var configB = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
    <fallbackPackageFolders>
        <add key=""c"" value=""C:\Temp\c"" />
        <add key=""d"" value=""C:\Temp\d"" />
    </fallbackPackageFolders>
</configuration>";

            var configC = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
    <fallbackPackageFolders>
        <add key=""x"" value=""C:\Temp\x"" />
        <add key=""y"" value=""C:\Temp\y"" />
    </fallbackPackageFolders>
</configuration>";

            var nugetConfigPath = "NuGet.Config";

            using (var machineWide = TestDirectory.Create())
                using (var mockBaseDirectory = TestDirectory.Create())
                {
                    var subFolder = Path.Combine(mockBaseDirectory, "sub");

                    ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, subFolder, configA);
                    ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, configB);
                    ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, machineWide, configC);

                    var machineWiderFolderSettings = new Settings(machineWide);
                    var machineWideSettings        = new TestMachineWideSettings(machineWiderFolderSettings);

                    var settings = Settings.LoadDefaultSettings(
                        subFolder,
                        configFileName: null,
                        machineWideSettings: machineWideSettings);

                    // Act
                    var actual = SettingsUtility
                                 .GetFallbackPackageFolders(settings)
                                 .Select(GetFileName);

                    var expected = new[] { "a", "b", "c", "d", "x", "y" };

                    // Ignore any extra folders on the machine
                    var actualFiltered = Enumerable.Intersect(actual, expected);
                    Assert.Equal(expected, actualFiltered);
                }
        }