Beispiel #1
0
        public void GetRestoreSettingsTask_VerifyEmptyPerFrameworkSettings()
        {
            using (var testDir = TestDirectory.CreateInTemp())
            {
                // Arrange
                var buildEngine = new TestBuildEngine();
                var testLogger  = buildEngine.TestLogger;

                var task = new GetRestoreSettingsTask()
                {
                    BuildEngine                 = buildEngine,
                    ProjectUniqueName           = Path.Combine(testDir, "a.csproj"),
                    RestoreSources              = new[] { Path.Combine(testDir, "base") },
                    RestoreFallbackFolders      = new[] { Path.Combine(testDir, "base") },
                    RestoreSettingsPerFramework = new ITaskItem[0]
                };

                // Act
                var result = task.Execute();

                // Assert
                result.Should().BeTrue();
                task.OutputSources.Should().BeEquivalentTo(new[] { Path.Combine(testDir, "base") });
                task.OutputFallbackFolders.Should().BeEquivalentTo(new[] { Path.Combine(testDir, "base") });
            }
        }
Beispiel #2
0
        public void GetRestoreSettingsTask_VerifyRestoreAdditionalProjectFallbackFoldersWithExcludeAreNotAdded()
        {
            using (var testDir = TestDirectory.CreateInTemp())
            {
                // Arrange
                var buildEngine = new TestBuildEngine();
                var testLogger  = buildEngine.TestLogger;

                var settingsPerFramework = new List <ITaskItem>();
                var settings1            = new Mock <ITaskItem>();
                settings1.SetupGet(e => e.ItemSpec).Returns("a");
                settings1.Setup(e => e.GetMetadata("RestoreAdditionalProjectFallbackFolders")).Returns(Path.Combine(testDir, "sourceC"));
                settingsPerFramework.Add(settings1.Object);

                var settings2 = new Mock <ITaskItem>();
                settings2.SetupGet(e => e.ItemSpec).Returns("b");
                settings2.Setup(e => e.GetMetadata("RestoreAdditionalProjectFallbackFoldersExcludes")).Returns(Path.Combine(testDir, "sourceC"));
                settingsPerFramework.Add(settings2.Object);

                var task = new GetRestoreSettingsTask()
                {
                    BuildEngine                 = buildEngine,
                    ProjectUniqueName           = Path.Combine(testDir, "a.csproj"),
                    RestoreFallbackFolders      = new[] { Path.Combine(testDir, "sourceA"), Path.Combine(testDir, "sourceB") },
                    RestoreSettingsPerFramework = settingsPerFramework.ToArray()
                };

                // Act
                var result = task.Execute();

                // Assert
                result.Should().BeTrue();
                task.OutputFallbackFolders.Should().BeEquivalentTo(new[] { Path.Combine(testDir, "sourceA"), Path.Combine(testDir, "sourceB") });
            }
        }
        public void ConfigDefaultsAreProperlyReadFromConfigDefaultsFile()
        {
            //Arrange
            var name1 = "Contoso Package Source";
            var name2 = "My Test Package Source";
            var feed1 = "http://contoso.com/packages/";
            var feed2 = "http://wwww.somerandomURL.com/";

            using (var nugetConfigFileFolder = TestDirectory.CreateInTemp())
            {
                var nugetConfigFile     = "NuGetDefaults.config";
                var nugetConfigFilePath = Path.Combine(nugetConfigFileFolder, nugetConfigFile);

                var enabledReplacement = @"<add key='" + name1 + "' value='" + feed1 + "' />";

                enabledReplacement = enabledReplacement + @"<add key='" + name2 + "' value='" + feed2 + "' />";
                var disabledReplacement = string.Empty;
                var defaultPushSource   = "<add key='DefaultPushSource' value='" + feed2 + "' />";
                File.WriteAllText(nugetConfigFilePath, CreateNuGetConfigContent(enabledReplacement, disabledReplacement, defaultPushSource));

                //Act
                ConfigurationDefaults       configDefaults = new ConfigurationDefaults(nugetConfigFileFolder, nugetConfigFile);
                IEnumerable <PackageSource> defaultSourcesFromConfigFile = configDefaults.DefaultPackageSources;
                string packageRestore    = configDefaults.DefaultPackageRestoreConsent;
                string packagePushSource = configDefaults.DefaultPushSource;

                //Assert
                VerifyPackageSource(defaultSourcesFromConfigFile, 2, new string[] { name1, name2 }, new string[] { feed1, feed2 });
                Assert.Equal(feed2, packagePushSource);
                Assert.Equal("true", packageRestore.ToLowerInvariant());
            }
        }
Beispiel #4
0
        public void GetRestoreSettingsTask_FindConfigInProjectFolder()
        {
            // Verifies that we include any config file found in the project folder
            using (var machineWide = TestDirectory.CreateInTemp())
                using (var workingDir = TestDirectory.CreateInTemp())
                {
                    // Arrange
                    SettingsTestUtils.CreateConfigurationFile(Settings.DefaultSettingsFileName, machineWide, MachineWideSettingsConfig);
                    var machineWideSettings = new Lazy <IMachineWideSettings>(() => new TestMachineWideSettings(new Settings(machineWide, Settings.DefaultSettingsFileName, isMachineWide: true)));

                    var innerConfigFile = Path.Combine(workingDir, "sub", Settings.DefaultSettingsFileName);
                    var outerConfigFile = Path.Combine(workingDir, Settings.DefaultSettingsFileName);

                    var projectDirectory = Path.GetDirectoryName(innerConfigFile);
                    Directory.CreateDirectory(projectDirectory);

                    File.WriteAllText(innerConfigFile, InnerConfig);
                    File.WriteAllText(outerConfigFile, OuterConfig);

                    var settings = RestoreSettingsUtils.ReadSettings(null, projectDirectory, null, machineWideSettings);

                    var innerValue = SettingsUtility.GetValueForAddItem(settings, "SectionName", "inner-key");
                    var outerValue = SettingsUtility.GetValueForAddItem(settings, "SectionName", "outer-key");

                    // Assert
                    Assert.Equal("inner-value", innerValue);
                    Assert.Equal("outer-value", outerValue);
                    Assert.True(settings.GetConfigFilePaths().Contains(innerConfigFile));
                    Assert.True(settings.GetConfigFilePaths().Contains(outerConfigFile));
                }
        }
        public void CreateConfigurationDefaultsThrowsWhenXmlIsInvalid()
        {
            //Arrange
            var name1 = "Contoso Package Source";
            var name2 = "My Test Package Source";
            var feed1 = "http://contoso.com/packages/";
            var feed2 = "http://wwww.somerandomURL.com/";

            using (var nugetConfigFileFolder = TestDirectory.CreateInTemp())
            {
                var nugetConfigFile     = "NuGetDefaults.config";
                var nugetConfigFilePath = Path.Combine(nugetConfigFileFolder, nugetConfigFile);

                var enabledReplacement = @"<add key='" + name1 + "' value='" + feed1;

                enabledReplacement = enabledReplacement + @"<add key='" + name2 + "' value='" + feed2;
                var disabledReplacement = string.Empty;
                var defaultPushSource   = "<add key='DefaultPushSource' value='" + feed2 + "' />";
                File.WriteAllText(nugetConfigFilePath, CreateNuGetConfigContent(enabledReplacement, disabledReplacement, defaultPushSource));

                Assert.Throws <NuGetConfigurationException>(() =>
                {
                    ConfigurationDefaults configDefaults = new ConfigurationDefaults(nugetConfigFileFolder, nugetConfigFile);
                });
            }
        }
        public void GetDefaultPackageSourcesReturnsValidPackageSources()
        {
            // Arrange
            using (var mockBaseDirectory = TestDirectory.CreateInTemp())
            {
                var configurationDefaultsContent = @"
<configuration>
    <packageSources>
        <add key='Contoso Package Source' value='http://contoso.com/packages/' />
        <add key='NuGet Official Feed' value='http://www.nuget.org/api/v2/' />
    </packageSources>
    <disabledPackageSources>
        <add key='NuGet Official Feed' value='true' />
    </disabledPackageSources>
</configuration>";
                // Act & Assert
                ConfigurationDefaults ConfigurationDefaults = GetConfigurationDefaults(configurationDefaultsContent, mockBaseDirectory);

                Assert.NotNull(ConfigurationDefaults.DefaultPackageSources);

                List <PackageSource> defaultPackageSources = ConfigurationDefaults.DefaultPackageSources.ToList();

                Assert.Equal(defaultPackageSources.Count, 2);

                Assert.Equal(defaultPackageSources[0].Name, "Contoso Package Source");
                Assert.True(defaultPackageSources[0].IsEnabled);
                Assert.True(defaultPackageSources[0].IsOfficial);

                Assert.Equal(defaultPackageSources[1].Name, "NuGet Official Feed");
                Assert.False(defaultPackageSources[1].IsEnabled);
                Assert.True(defaultPackageSources[1].IsOfficial);
            }
        }
Beispiel #7
0
        public void GetRestoreSettingsTask_RestoreTaskBased_PackageReference_ProjectLevelConfig()
        {
            using (var testDir = TestDirectory.CreateInTemp())
            {
                // Arrange
                var buildEngine = new TestBuildEngine();
                var testLogger  = buildEngine.TestLogger;

                var settingsPerFramework = new List <ITaskItem>();
                var settings1            = new Mock <ITaskItem>();
                settings1.SetupGet(e => e.ItemSpec).Returns("a");
                settingsPerFramework.Add(settings1.Object);

                var task = new GetRestoreSettingsTask()
                {
                    BuildEngine                 = buildEngine,
                    ProjectUniqueName           = Path.Combine(testDir, "a.csproj"),
                    RestoreSettingsPerFramework = settingsPerFramework.ToArray()
                };

                var configFile = Path.Combine(testDir, Settings.DefaultSettingsFileName);
                File.WriteAllText(configFile, RootConfig);

                // Act
                var result = task.Execute();

                // Assert
                result.Should().BeTrue();
                task.OutputSources.Should().BeEquivalentTo(new[] { "https://api.nuget.org/v3/index.json" });
                task.OutputFallbackFolders.Should().BeEmpty();
                task.OutputConfigFilePaths.Should().Contain(configFile);
            }
        }
Beispiel #8
0
        public void GetRestoreSettingsTask_VerifyDisabledSourcesAreExcluded()
        {
            using (var testDir = TestDirectory.CreateInTemp())
            {
                // Arrange
                var buildEngine = new TestBuildEngine();
                var testLogger  = buildEngine.TestLogger;


                var configFile = Path.Combine(testDir, Settings.DefaultSettingsFileName);

                var projectDirectory = Path.GetDirectoryName(configFile);
                Directory.CreateDirectory(projectDirectory);

                File.WriteAllText(configFile, DisableSourceConfig);

                var task = new GetRestoreSettingsTask()
                {
                    BuildEngine                 = buildEngine,
                    ProjectUniqueName           = Path.Combine(testDir, "a.csproj"),
                    RestoreFallbackFolders      = new[] { Path.Combine(testDir, "base") },
                    RestoreSettingsPerFramework = new ITaskItem[0]
                };

                // Act
                var result = task.Execute();

                // Assert
                result.Should().BeTrue();
                task.OutputSources.Should().BeEquivalentTo(new[] { @"https://nuget.org/v2/api" });
            }
        }
Beispiel #9
0
        public void GetRestoreSettingsTask_WithFallbackFoldersOverride_ResolvesAgainstWorkingDirectory()
        {
            using (var testDir = TestDirectory.CreateInTemp())
            {
                // Arrange
                var buildEngine = new TestBuildEngine();
                var testLogger  = buildEngine.TestLogger;

                var settingsPerFramework = new List <ITaskItem>();
                var settings1            = new Mock <ITaskItem>();
                settings1.SetupGet(e => e.ItemSpec).Returns("a");
                settingsPerFramework.Add(settings1.Object);
                var startupDirectory = Path.Combine(testDir, "innerPath");
                var relativePath     = "relativeSource";

                var task = new GetRestoreSettingsTask()
                {
                    BuildEngine                    = buildEngine,
                    MSBuildStartupDirectory        = startupDirectory,
                    ProjectUniqueName              = Path.Combine(testDir, "a.csproj"),
                    RestoreFallbackFolders         = new[] { Path.Combine(testDir, "sourceA"), Path.Combine(testDir, "sourceB") },
                    RestoreFallbackFoldersOverride = new[] { relativePath },
                    RestoreSettingsPerFramework    = settingsPerFramework.ToArray()
                };

                // Act
                var result = task.Execute();

                // Assert
                result.Should().BeTrue();
                task.OutputFallbackFolders.Should().BeEquivalentTo(new[] { Path.Combine(startupDirectory, relativePath) });
            }
        }
Beispiel #10
0
        public void TestConfigFileProbingDirectory()
        {
            // Arrange
            var parentConfig = @"<?xml version=""1.0"" encoding=""utf-8""?>
            <configuration>
                <fallbackPackageFolders>
                    <add key=""a"" value=""C:\Temp\a"" />
                </fallbackPackageFolders>
            </configuration>";

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

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

            var configName = "NuGet.Config";

            using (var machineWide = TestDirectory.CreateInTemp())
                using (var mockParentDirectory = TestDirectory.CreateInTemp())
                {
                    // Parent
                    //       Base
                    //            Probe Path
                    //       Unreachable
                    var basePath        = Path.Combine(mockParentDirectory, "base");
                    var unreachablePath = Path.Combine(mockParentDirectory, "unreachable");
                    var probePath       = Path.Combine(basePath, "probe");
                    Directory.CreateDirectory(basePath);
                    Directory.CreateDirectory(unreachablePath);
                    Directory.CreateDirectory(probePath);

                    SettingsTestUtils.CreateConfigurationFile(configName, mockParentDirectory, parentConfig);
                    SettingsTestUtils.CreateConfigurationFile(configName, basePath, baseConfig);
                    SettingsTestUtils.CreateConfigurationFile(configName, unreachablePath, unreachableConfig);

                    SettingsTestUtils.CreateConfigurationFile(configName, machineWide, MachineWideSettingsConfig);

                    var machineWideSettings = new Lazy <IMachineWideSettings>(() => new TestMachineWideSettings(new Settings(machineWide, configName, isMachineWide: true)));

                    // Test

                    var settings  = RestoreSettingsUtils.ReadSettings(null, probePath, null, machineWideSettings);
                    var filePaths = settings.GetConfigFilePaths();

                    Assert.Equal(4, filePaths.Count()); // base, parent, app data + machine wide
                    Assert.Contains(Path.Combine(basePath, configName), filePaths);
                    Assert.Contains(Path.Combine(mockParentDirectory, configName), filePaths);
                    Assert.DoesNotContain(Path.Combine(unreachablePath, configName), filePaths);
                }
        }
        public void CreateConfigurationDefaultsReturnsNonNullConfigurationDefaults()
        {
            // Arrange
            using (var mockBaseDirectory = TestDirectory.CreateInTemp())
            {
                ConfigurationDefaults ConfigurationDefaults = GetConfigurationDefaults(@"<configuration></configuration>", mockBaseDirectory);

                // Act & Assert
                Assert.NotNull(ConfigurationDefaults);
            }
        }
Beispiel #12
0
        public void GetRestoreSettingsTask_VerifyAggregationAcrossFrameworks()
        {
            using (var testDir = TestDirectory.CreateInTemp())
            {
                // Arrange
                var buildEngine = new TestBuildEngine();
                var testLogger  = buildEngine.TestLogger;

                var settingsPerFramework = new List <ITaskItem>();
                var settings1            = new Mock <ITaskItem>();
                settings1.SetupGet(e => e.ItemSpec).Returns("a");
                settings1.Setup(e => e.GetMetadata("RestoreAdditionalProjectSources")).Returns($"{Path.Combine(testDir, "a")};{Path.Combine(testDir, "b")}");
                settings1.Setup(e => e.GetMetadata("RestoreAdditionalProjectFallbackFolders")).Returns($"{Path.Combine(testDir, "m")};{Path.Combine(testDir, "n")}");
                settingsPerFramework.Add(settings1.Object);

                var settings2 = new Mock <ITaskItem>();
                settings2.SetupGet(e => e.ItemSpec).Returns("b");
                settings2.Setup(e => e.GetMetadata("RestoreAdditionalProjectSources")).Returns(Path.Combine(testDir, "c"));
                settings2.Setup(e => e.GetMetadata("RestoreAdditionalProjectFallbackFolders")).Returns(Path.Combine(testDir, "s"));
                settingsPerFramework.Add(settings2.Object);

                var settings3 = new Mock <ITaskItem>();
                settings3.SetupGet(e => e.ItemSpec).Returns("c");
                settings3.Setup(e => e.GetMetadata("RestoreAdditionalProjectSources")).Returns(Path.Combine(testDir, "d"));
                settingsPerFramework.Add(settings3.Object);

                var settings4 = new Mock <ITaskItem>();
                settings4.SetupGet(e => e.ItemSpec).Returns("d");
                settings4.Setup(e => e.GetMetadata("RestoreAdditionalProjectFallbackFolders")).Returns(Path.Combine(testDir, "t"));
                settingsPerFramework.Add(settings4.Object);

                var settings5 = new Mock <ITaskItem>();
                settings5.SetupGet(e => e.ItemSpec).Returns("e");
                settingsPerFramework.Add(settings5.Object);

                var task = new GetRestoreSettingsTask()
                {
                    BuildEngine                 = buildEngine,
                    ProjectUniqueName           = Path.Combine(testDir, "a.csproj"),
                    RestoreSources              = new[] { Path.Combine(testDir, "base") },
                    RestoreFallbackFolders      = new[] { Path.Combine(testDir, "base") },
                    RestoreSettingsPerFramework = settingsPerFramework.ToArray()
                };

                // Act
                var result = task.Execute();

                // Assert
                result.Should().BeTrue();
                task.OutputSources.Should().BeEquivalentTo(new[] { Path.Combine(testDir, "base"), Path.Combine(testDir, "a"), Path.Combine(testDir, "b"), Path.Combine(testDir, "c"), Path.Combine(testDir, "d") });
                task.OutputFallbackFolders.Should().BeEquivalentTo(new[] { Path.Combine(testDir, "base"), Path.Combine(testDir, "m"), Path.Combine(testDir, "n"), Path.Combine(testDir, "s"), Path.Combine(testDir, "t") });
            }
        }
Beispiel #13
0
        public void TestSolutionSettings()
        {
            // Arrange
            var subFolderConfig = @"<?xml version=""1.0"" encoding=""utf-8""?>
            <configuration>
                <fallbackPackageFolders>
                    <add key=""a"" value=""C:\Temp\a"" />
                </fallbackPackageFolders>
            </configuration>";

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



            var baseConfigPath = "NuGet.Config";

            using (var machineWide = TestDirectory.CreateInTemp())
                using (var mockBaseDirectory = TestDirectory.CreateInTemp())
                {
                    var subFolder = Path.Combine(mockBaseDirectory, "sub");
                    var solutionDirectoryConfig = Path.Combine(mockBaseDirectory, NuGetConstants.NuGetSolutionSettingsFolder);

                    SettingsTestUtils.CreateConfigurationFile(baseConfigPath, solutionDirectoryConfig, baseConfig);
                    SettingsTestUtils.CreateConfigurationFile(baseConfigPath, subFolder, subFolderConfig);
                    SettingsTestUtils.CreateConfigurationFile(baseConfigPath, machineWide, MachineWideSettingsConfig);
                    var machineWideSettings = new Lazy <IMachineWideSettings>(() => new TestMachineWideSettings(new Settings(machineWide, baseConfigPath, isMachineWide: true)));

                    // Test

                    var settings  = RestoreSettingsUtils.ReadSettings(mockBaseDirectory, mockBaseDirectory, null, machineWideSettings);
                    var filePaths = settings.GetConfigFilePaths();

                    Assert.Equal(3, filePaths.Count()); // Solution, app data + machine wide
                    Assert.True(filePaths.Contains(Path.Combine(solutionDirectoryConfig, baseConfigPath)));
                    Assert.True(filePaths.Contains(Path.Combine(machineWide, baseConfigPath)));

                    // Test
                    settings  = RestoreSettingsUtils.ReadSettings(mockBaseDirectory, mockBaseDirectory, Path.Combine(subFolder, baseConfigPath), machineWideSettings);
                    filePaths = settings.GetConfigFilePaths();

                    Assert.Equal(1, filePaths.Count());
                    Assert.True(filePaths.Contains(Path.Combine(subFolder, baseConfigPath)));
                }
        }
        public void GetDefaultPackageSourcesReturnsEmptyList()
        {
            //Arrange
            using (var nugetConfigFileFolder = TestDirectory.CreateInTemp())
            {
                var nugetConfigFile     = "NuGetDefaults.config";
                var nugetConfigFilePath = Path.Combine(nugetConfigFileFolder, nugetConfigFile);

                var configurationDefaultsContent = @"<configuration></configuration>";
                File.WriteAllText(nugetConfigFilePath, configurationDefaultsContent);

                ConfigurationDefaults configDefaults = new ConfigurationDefaults(nugetConfigFileFolder, nugetConfigFile);
                Assert.True(configDefaults.DefaultPackageSources.ToList().Count == 0);
            }
        }
        public void GetDefaultPushSourceReturnsNull()
        {
            //Arrange
            using (var nugetConfigFileFolder = TestDirectory.CreateInTemp())
            {
                var nugetConfigFile     = "NuGetDefaults.config";
                var nugetConfigFilePath = Path.Combine(nugetConfigFileFolder, nugetConfigFile);

                var configurationDefaultsContent = @"<configuration></configuration>";
                File.WriteAllText(nugetConfigFilePath, configurationDefaultsContent);

                ConfigurationDefaults configDefaults = new ConfigurationDefaults(nugetConfigFileFolder, nugetConfigFile);
                Assert.Null(configDefaults.DefaultPushSource);
            }
        }
        public void GetDefaultPushSourceReadsTheCorrectValue()
        {
            // Arrange
            using (var mockBaseDirectory = TestDirectory.CreateInTemp())
            {
                var configurationDefaultsContent = @"
<configuration>
     <config>
        <add key='DefaultPushSource' value='http://contoso.com/packages/' />
    </config>
</configuration>";

                // Act & Assert
                ConfigurationDefaults ConfigurationDefaults = GetConfigurationDefaults(configurationDefaultsContent, mockBaseDirectory);

                Assert.Equal("http://contoso.com/packages/", ConfigurationDefaults.DefaultPushSource);
            }
        }
        public void GetDefaultPackageSources_LocalizatedPackagesourceKeys_ConsideredDiffererent()
        {
            // Arrange
            using (var mockBaseDirectory = TestDirectory.CreateInTemp())
            {
                var configurationDefaultsContent = @"
<configuration>
    <packageSources>
        <add key='encyclopaedia' value='http://contoso.com/packages1/' />
        <add key='encyclopædia' value='http://contoso.com/packages2/' />
    </packageSources>
</configuration>";

                var config = @"
<configuration>
    <packageSources>
        <add key='v2' value='http://www.nuget.org/api/v2/' />
    </packageSources>
</configuration>";

                File.WriteAllText(Path.Combine(mockBaseDirectory, "NuGet.Config"), config);
                var settings = Settings.LoadSettings(mockBaseDirectory,
                                                     configFileName: null,
                                                     machineWideSettings: null,
                                                     loadUserWideSettings: false,
                                                     useTestingGlobalPath: false);
                ConfigurationDefaults ConfigurationDefaults = GetConfigurationDefaults(configurationDefaultsContent, mockBaseDirectory);

                List <PackageSource> defaultSources = ConfigurationDefaults.DefaultPackageSources.ToList();
                var packageSourceProvider           = new PackageSourceProvider(settings, ConfigurationDefaults.DefaultPackageSources);

                // Act
                List <PackageSource> packageSources = packageSourceProvider.LoadPackageSources().ToList();

                // Assert
                Assert.Equal(3, packageSources.Count());
                Assert.Equal(2, defaultSources.Count());
                Assert.Equal("v2", packageSources[0].Name);
                Assert.Equal("encyclopaedia", packageSources[1].Name);
                Assert.Equal("encyclopaedia", defaultSources[0].Name);
                Assert.Equal("encyclopædia", packageSources[2].Name);
                Assert.Equal("encyclopædia", defaultSources[1].Name);
            }
        }
        public void GetDefaultPackageSourcesFromSourceProvider()
        {
            // Arrange
            using (var mockBaseDirectory = TestDirectory.CreateInTemp())
            {
                var configurationDefaultsContent = @"
<configuration>
    <packageSources>
        <add key='Contoso Package Source' value='http://contoso.com/packages/' />
    </packageSources>
      <config>
        <add key='DefaultPushSource' value='http://contoso.com/packages/' />
    </config>
</configuration>";
                var config = @"
<configuration>
    <packageSources>
        <add key='v2' value='http://www.nuget.org/api/v2/' />
    </packageSources>
</configuration>";

                File.WriteAllText(Path.Combine(mockBaseDirectory, "NuGet.Config"), config);
                var settings = Settings.LoadSettings(mockBaseDirectory,
                                                     configFileName: null,
                                                     machineWideSettings: null,
                                                     loadUserWideSettings: false,
                                                     useTestingGlobalPath: false);
                ConfigurationDefaults ConfigurationDefaults = GetConfigurationDefaults(configurationDefaultsContent, mockBaseDirectory);

                var packageSourceProvider = new PackageSourceProvider(settings, ConfigurationDefaults.DefaultPackageSources);

                // Act
                List <PackageSource> packageSources = packageSourceProvider.LoadPackageSources().ToList();

                // Assert
                Assert.Equal("http://contoso.com/packages/", ConfigurationDefaults.DefaultPushSource);
                Assert.Equal(2, packageSources.Count());
                Assert.Equal("v2", packageSources[0].Name);
                Assert.Equal("Contoso Package Source", packageSources[1].Name);
            }
        }
        public void GetSources_WithRestoreSourcesGlobal_Property_ResolvesAgainstWorkingDirectory()
        {
            using (var testDir = TestDirectory.CreateInTemp())
            {
                // Arrange
                var startupDirectory = Path.Combine(testDir, "startup");
                var projectDirectory = Path.Combine(testDir, "project");
                var relativePath     = "relativeSource";

                // Act
                var effectiveSources = BuildTasksUtility.GetSources(
                    startupDirectory: startupDirectory,
                    projectDirectory: projectDirectory,
                    sources: new string[] { relativePath },
                    sourcesOverride: new string[] { relativePath },
                    additionalProjectSources: Array.Empty <string>(),
                    settings: NullSettings.Instance
                    );

                // Assert
                effectiveSources.ShouldBeEquivalentTo(new[] { Path.Combine(startupDirectory, relativePath) });
            }
        }