public void LoadPackageSourcesReturnsEmptySequenceIfDefaultPackageSourceIsEmpty()
        {
            // Arrange
            var settings = new MockUserSettingsManager();
            var provider = new PackageSourceProvider(settings, defaultSources: new PackageSource[] { });

            // Act
            var values = provider.LoadPackageSources();

            // Assert
            Assert.False(values.Any());
        }
        public void LoadPackageSourcesReturnsDefaultSourcesIfSpecified()
        {
            // Arrange
            var settings = new MockUserSettingsManager();
            var provider = new PackageSourceProvider(settings, defaultSources: new[] { new PackageSource("A"), new PackageSource("B") });

            // Act
            var values = provider.LoadPackageSources().ToList();

            // Assert
            Assert.Equal(2, values.Count);
            Assert.Equal("A", values.First().Source);
            Assert.Equal("B", values.Last().Source);
        }
        public void LoadPackageSourcesPerformMigrationIfSpecified()
        {
            // Arrange
            var settings = new MockUserSettingsManager();
            settings.SetValues(
                PackageSourceProvider.PackageSourcesSectionName,
                new KeyValuePair<string, string>[] { 
                    new KeyValuePair<string, string>("one", "onesource"),
                    new KeyValuePair<string, string>("two", "twosource"),
                    new KeyValuePair<string, string>("three", "threesource"),
                }
            );

            // disable package "three"
            settings.SetValue(
                PackageSourceProvider.DisabledPackageSourcesSectionName,
                "three",
                "threesource");

            var provider = new PackageSourceProvider(
                settings,
                null,
                new Dictionary<PackageSource, PackageSource> {
                    { new PackageSource("onesource", "one"), new PackageSource("goodsource", "good") },
                    { new PackageSource("foo", "bar"), new PackageSource("foo", "bar") },
                    { new PackageSource("threesource", "three"), new PackageSource("awesomesource", "awesome") }
                }
            );

            // Act
            var values = provider.LoadPackageSources().ToList();

            // Assert
            Assert.Equal(3, values.Count);
            AssertPackageSource(values[0], "good", "goodsource", true);
            AssertPackageSource(values[1], "two", "twosource", true);
            AssertPackageSource(values[2], "awesome", "awesomesource", false);

            var savedSettingValues = settings.GetValues(PackageSourceProvider.PackageSourcesSectionName);
            Assert.Equal(3, savedSettingValues.Count);
            Assert.Equal("good", savedSettingValues[0].Key);
            Assert.Equal("goodsource", savedSettingValues[0].Value);
            Assert.Equal("two", savedSettingValues[1].Key);
            Assert.Equal("twosource", savedSettingValues[1].Value);
            Assert.Equal("awesome", savedSettingValues[2].Key);
            Assert.Equal("awesomesource", savedSettingValues[2].Value);
        }
        public void SavePackageSourcesSaveCorrectDataToSettingsWhenSomePackgeSourceIsDisabled()
        {
            // Arrange
            var settings = new MockUserSettingsManager();
            var provider = CreatePackageSourceProvider(settings);

            var sources = new[] { new PackageSource("one"), new PackageSource("two"), new PackageSource("three", "three", isEnabled: false) };

            // Act
            provider.SavePackageSources(sources);

            // Assert
            var values = settings.GetValues(PackageSourceProvider.PackageSourcesSectionName);
            Assert.Equal(3, values.Count);
            Assert.Equal("one", values[0].Key);
            Assert.Equal("two", values[1].Key);
            Assert.Equal("three", values[2].Key);

            var disabledValues = settings.GetValues(PackageSourceProvider.DisabledPackageSourcesSectionName);
            Assert.NotNull(disabledValues);
            Assert.Equal(1, disabledValues.Count);
            Assert.Equal("three", disabledValues[0].Key);
        }
        public void SavePackageSourcesSaveCorrectDataToSettings()
        {
            // Arrange
            var settings = new MockUserSettingsManager();
            var provider = CreatePackageSourceProvider(settings);

            var sources = new[] { new PackageSource("one"), new PackageSource("two"), new PackageSource("three") };

            // Act
            provider.SavePackageSources(sources);

            // Assert
            var values = settings.GetValues(PackageSourceProvider.PackageSourcesSectionName);
            Assert.Equal(3, values.Count);
            Assert.Equal("one", values[0].Key);
            Assert.Equal("two", values[1].Key);
            Assert.Equal("three", values[2].Key);
        }
        public void LoadPackageSourcesReturnCorrectDataFromSettingsWhenSomePackageSourceIsDisabled()
        {
            // Arrange
            var settings = new MockUserSettingsManager();
            settings.SetValues(PackageSourceProvider.PackageSourcesSectionName,
                new[] {
                    new KeyValuePair<string, string>("one", "onesource"),
                    new KeyValuePair<string, string>("two", "twosource"),
                    new KeyValuePair<string, string>("three", "threesource")
                });
            settings.SetValues(PackageSourceProvider.DisabledPackageSourcesSectionName,
                new[] {
                    new KeyValuePair<string, string>("two", "true")
                });

            var provider = CreatePackageSourceProvider(settings);

            // Act
            var values = provider.LoadPackageSources().ToList();

            // Assert
            Assert.Equal(3, values.Count);
            AssertPackageSource(values[0], "one", "onesource", true);
            AssertPackageSource(values[1], "two", "twosource", false);
            AssertPackageSource(values[2], "three", "threesource", true);
        }