public void CreateConfigurationDefaultsThrowsWhenXmlIsInvalid()
        {
            //Arrange
            string name1 = "Contoso Package Source";
            string name2 = "My Test Package Source";
            string feed1 = "http://contoso.com/packages/";
            string feed2 = "http://wwww.somerandomURL.com/";

            string nugetConfigFileFolder = NuGet.Configuration.Test.TestFilesystemUtility.CreateRandomTestFolder();
            string nugetConfigFile = "NuGetDefaults.config";
            string nugetConfigFilePath = Path.Combine(nugetConfigFileFolder, nugetConfigFile);
            File.Create(nugetConfigFilePath).Close();

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

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

            //Act & Assert
            try
            {
                ConfigurationDefaults configDefaults = new ConfigurationDefaults(nugetConfigFileFolder, nugetConfigFile);
            }
            catch (Exception e)
            {
                Assert.True("XmlException" == e.GetType().Name);
            }
        }
        public void ConfigDefaultsAreProperlyReadFromConfigDefaultsFile()
        {
            //Arrange
            string name1 = "Contoso Package Source";
            string name2 = "My Test Package Source";
            string feed1 = "http://contoso.com/packages/";
            string feed2 = "http://wwww.somerandomURL.com/";

            string nugetConfigFileFolder = NuGet.Configuration.Test.TestFilesystemUtility.CreateRandomTestFolder();
            string nugetConfigFile = "NuGetDefaults.config";
            string nugetConfigFilePath = Path.Combine(nugetConfigFileFolder, nugetConfigFile);
            File.Create(nugetConfigFilePath).Close();
            
            string enabledReplacement = @"<add key='" + name1 + "' value='" + feed1 + "' />";

            enabledReplacement = enabledReplacement + @"<add key='" + name2 + "' value='" + feed2 + "' />";
            string disabledReplacement = string.Empty;
            string 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());

            //Clean up
            NuGet.Configuration.Test.TestFilesystemUtility.DeleteRandomTestFolders(nugetConfigFileFolder);
        }
        public void GetDefaultSameSourcePackageSourcesFromSourceProvider()
        {
            // Arrange
            using (var mockBaseDirectory = TestDirectory.CreateInTemp())
            {
                var configurationDefaultsContent = @"
<configuration>
    <packageSources>
        <add key='Contoso Package Source' value='http://www.nuget.org/api/v2/' />
    </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);

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

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

                // Assert
                Assert.Equal(1, packageSources.Count());
                Assert.Equal("v2", packageSources[0].Name);
                Assert.Equal("http://www.nuget.org/api/v2/", packageSources[0].Source);
            }
        }
        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/";

            string nugetConfigFileFolder = TestFilesystemUtility.CreateRandomTestFolder();
            var    nugetConfigFile       = "NuGetDefaults.config";
            var    nugetConfigFilePath   = Path.Combine(nugetConfigFileFolder, nugetConfigFile);

            File.Create(nugetConfigFilePath).Close();

            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());

            //Clean up
            TestFilesystemUtility.DeleteRandomTestFolders(nugetConfigFileFolder);
        }
        public void GetDefaultPushSourceReturnsNull()
        {
            //Arrange
            string nugetConfigFileFolder = NuGet.Configuration.Test.TestFilesystemUtility.CreateRandomTestFolder();
            string nugetConfigFile = "NuGetDefaults.config";
            string nugetConfigFilePath = Path.Combine(nugetConfigFileFolder, nugetConfigFile);
            File.Create(nugetConfigFilePath).Close();

            string configurationDefaultsContent = @"<configuration></configuration>";
            File.WriteAllText(nugetConfigFilePath, configurationDefaultsContent);
                       
            ConfigurationDefaults configDefaults = new ConfigurationDefaults(nugetConfigFileFolder, nugetConfigFile);
            Assert.Null(configDefaults.DefaultPushSource);
        }
Exemplo n.º 6
0
        public void GetDefaultPackageSourcesReturnsEmptyList()
        {
            //Arrange
            string nugetConfigFileFolder = TestFilesystemUtility.CreateRandomTestFolder();
            var nugetConfigFile = "NuGetDefaults.config";
            var nugetConfigFilePath = Path.Combine(nugetConfigFileFolder, nugetConfigFile);
            File.Create(nugetConfigFilePath).Close();

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

            ConfigurationDefaults configDefaults = new ConfigurationDefaults(nugetConfigFileFolder, nugetConfigFile);
            Assert.True(configDefaults.DefaultPackageSources.ToList().Count == 0);
        }