Browse Source

Support solution specific NuGet.Config files.

If a solution has its own NuGet.Config file this will be read and
any package sources defined in this file will be available in the
list of package sources in the Manage Packages dialog.
pull/480/head
Matt Ward 11 years ago
parent
commit
70fd9337bd
  1. 4
      src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj
  2. 1
      src/AddIns/Misc/PackageManagement/Project/Src/Design/FakePackageManagementProjectService.cs
  3. 28
      src/AddIns/Misc/PackageManagement/Project/Src/ISettingsFactory.cs
  4. 14
      src/AddIns/Misc/PackageManagement/Project/Src/ISettingsProvider.cs
  5. 10
      src/AddIns/Misc/PackageManagement/Project/Src/PackageManagementOptions.cs
  6. 36
      src/AddIns/Misc/PackageManagement/Project/Src/RegisteredPackageSourceSettings.cs
  7. 32
      src/AddIns/Misc/PackageManagement/Project/Src/SettingsFactory.cs
  8. 62
      src/AddIns/Misc/PackageManagement/Project/Src/SettingsProvider.cs
  9. 2
      src/AddIns/Misc/PackageManagement/Test/PackageManagement.Tests.csproj
  10. 37
      src/AddIns/Misc/PackageManagement/Test/Src/Helpers/FakeSettingsFactory.cs
  11. 22
      src/AddIns/Misc/PackageManagement/Test/Src/Helpers/TestablePackageManagementOptions.cs
  12. 115
      src/AddIns/Misc/PackageManagement/Test/Src/PackageManagementOptionsTests.cs
  13. 4
      src/AddIns/Misc/PackageManagement/Test/Src/PackageManagementOptionsViewModelTests.cs
  14. 80
      src/AddIns/Misc/PackageManagement/Test/Src/SettingsProviderTests.cs

4
src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj

@ -154,6 +154,7 @@ @@ -154,6 +154,7 @@
<Compile Include="Src\InstalledPackagesViewModel.cs" />
<Compile Include="Src\IPackageRepositoryFactoryEvents.cs" />
<Compile Include="Src\IPackageViewModelParent.cs" />
<Compile Include="Src\ISettingsProvider.cs" />
<Compile Include="Src\IUpdatePackagesAction.cs" />
<Compile Include="Src\IPackageExtensions.cs" />
<Compile Include="Src\IPackageAction.cs" />
@ -219,7 +220,6 @@ @@ -219,7 +220,6 @@
<Compile Include="Src\IPackageReferenceInstaller.cs" />
<Compile Include="Src\IPackageReferencesForProject.cs" />
<Compile Include="Src\IPropertyService.cs" />
<Compile Include="Src\ISettingsFactory.cs" />
<Compile Include="Src\IThreadSafePackageManagementEvents.cs" />
<Compile Include="Src\ManagePackagesUserPrompts.cs" />
<Compile Include="Src\ManagePackagesViewTitle.cs" />
@ -252,6 +252,7 @@ @@ -252,6 +252,7 @@
<Compile Include="Src\Scripting\NullGlobalMSBuildProjectCollection.cs" />
<Compile Include="Src\Scripting\RunAllProjectPackageScriptsAction.cs" />
<Compile Include="Src\ServiceWithWorkbenchOwner.cs" />
<Compile Include="Src\SettingsProvider.cs" />
<Compile Include="Src\SharpDevelopCredentialProvider.cs" />
<Compile Include="Src\SharpDevelopHttpUserAgent.cs" />
<Compile Include="Src\ThreadSafeCodeGenerator.cs" />
@ -400,7 +401,6 @@ @@ -400,7 +401,6 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\SelectProjectsViewModel.cs" />
<Compile Include="Src\SettingsFactory.cs" />
<Compile Include="Src\SolutionPackageRepositoryFactory.cs" />
<Compile Include="Src\SolutionPackageRepositoryPath.cs" />
<Compile Include="Src\PackageSourceConverter.cs" />

1
src/AddIns/Misc/PackageManagement/Project/Src/Design/FakePackageManagementProjectService.cs

@ -43,6 +43,7 @@ namespace ICSharpCode.PackageManagement.Design @@ -43,6 +43,7 @@ namespace ICSharpCode.PackageManagement.Design
public void FireSolutionClosedEvent(ISolution solution)
{
OpenSolution = null;
if (SolutionClosed != null) {
SolutionClosed(this, new SolutionEventArgs(solution));
}

28
src/AddIns/Misc/PackageManagement/Project/Src/ISettingsFactory.cs

@ -1,28 +0,0 @@ @@ -1,28 +0,0 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using NuGet;
namespace ICSharpCode.PackageManagement
{
public interface ISettingsFactory
{
ISettings CreateSettings(string directory);
}
}

14
src/AddIns/Misc/PackageManagement/Project/Src/ISettingsProvider.cs

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using NuGet;
namespace ICSharpCode.PackageManagement
{
public interface ISettingsProvider
{
event EventHandler SettingsChanged;
ISettings LoadSettings();
}
}

10
src/AddIns/Misc/PackageManagement/Project/Src/PackageManagementOptions.cs

@ -35,15 +35,17 @@ namespace ICSharpCode.PackageManagement @@ -35,15 +35,17 @@ namespace ICSharpCode.PackageManagement
ObservableCollection<RecentPackageInfo> recentPackages;
PackageRestoreConsent packageRestoreConsent;
public PackageManagementOptions(Properties properties, ISettings settings)
public PackageManagementOptions(
Properties properties,
ISettingsProvider settingsProvider)
{
this.properties = properties;
registeredPackageSourceSettings = new RegisteredPackageSourceSettings(settings);
packageRestoreConsent = new PackageRestoreConsent(settings);
registeredPackageSourceSettings = new RegisteredPackageSourceSettings(settingsProvider);
packageRestoreConsent = new PackageRestoreConsent(settingsProvider.LoadSettings());
}
public PackageManagementOptions(Properties properties)
: this(properties, Settings.LoadDefaultSettings(null, null, null))
: this(properties, new SettingsProvider())
{
}

36
src/AddIns/Misc/PackageManagement/Project/Src/RegisteredPackageSourceSettings.cs

@ -21,6 +21,7 @@ using System.Collections.Generic; @@ -21,6 +21,7 @@ using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using ICSharpCode.SharpDevelop.Project;
using NuGet;
namespace ICSharpCode.PackageManagement
@ -35,20 +36,32 @@ namespace ICSharpCode.PackageManagement @@ -35,20 +36,32 @@ namespace ICSharpCode.PackageManagement
new PackageSource("(Aggregate source)", "All");
ISettings settings;
ISettingsProvider settingsProvider;
PackageSource defaultPackageSource;
RegisteredPackageSources packageSources;
PackageSource activePackageSource;
public RegisteredPackageSourceSettings(ISettings settings)
: this(settings, RegisteredPackageSources.DefaultPackageSource)
public RegisteredPackageSourceSettings(ISettingsProvider settingsProvider)
: this(settingsProvider, RegisteredPackageSources.DefaultPackageSource)
{
}
public RegisteredPackageSourceSettings(ISettings settings, PackageSource defaultPackageSource)
public RegisteredPackageSourceSettings(
ISettingsProvider settingsProvider,
PackageSource defaultPackageSource)
{
this.settings = settings;
this.settingsProvider = settingsProvider;
this.defaultPackageSource = defaultPackageSource;
settings = settingsProvider.LoadSettings();
ReadActivePackageSource();
RegisterSolutionEvents();
}
void RegisterSolutionEvents()
{
settingsProvider.SettingsChanged += SettingsChanged;
}
void ReadActivePackageSource()
@ -176,5 +189,20 @@ namespace ICSharpCode.PackageManagement @@ -176,5 +189,20 @@ namespace ICSharpCode.PackageManagement
{
settings.SetValue(ActivePackageSourceSectionName, activePackageSource.Key, activePackageSource.Value);
}
void SettingsChanged(object sender, EventArgs e)
{
settings = settingsProvider.LoadSettings();
ReadActivePackageSource();
ResetPackageSources();
}
void ResetPackageSources()
{
if (packageSources != null) {
packageSources.CollectionChanged -= PackageSourcesChanged;
packageSources = null;
}
}
}
}

32
src/AddIns/Misc/PackageManagement/Project/Src/SettingsFactory.cs

@ -1,32 +0,0 @@ @@ -1,32 +0,0 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using NuGet;
namespace ICSharpCode.PackageManagement
{
public class SettingsFactory : ISettingsFactory
{
public ISettings CreateSettings(string directory)
{
var fileSystem = new PhysicalFileSystem(directory);
return new Settings(fileSystem);
}
}
}

62
src/AddIns/Misc/PackageManagement/Project/Src/SettingsProvider.cs

@ -0,0 +1,62 @@ @@ -0,0 +1,62 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.IO;
using ICSharpCode.SharpDevelop.Project;
using NuGet;
namespace ICSharpCode.PackageManagement
{
public class SettingsProvider : ISettingsProvider
{
public static Func<IFileSystem, string, IMachineWideSettings, ISettings> LoadDefaultSettings
= Settings.LoadDefaultSettings;
IPackageManagementProjectService projectService;
public SettingsProvider()
: this(PackageManagementServices.ProjectService)
{
}
public SettingsProvider(IPackageManagementProjectService projectService)
{
this.projectService = projectService;
projectService.SolutionOpened += OnSettingsChanged;
projectService.SolutionClosed += OnSettingsChanged;
}
public event EventHandler SettingsChanged;
void OnSettingsChanged(object sender, SolutionEventArgs e)
{
if (SettingsChanged != null) {
SettingsChanged(this, new EventArgs());
}
}
public ISettings LoadSettings()
{
return LoadSettings(GetSolutionDirectory());
}
string GetSolutionDirectory()
{
ISolution solution = projectService.OpenSolution;
if (solution != null) {
return solution.Directory;
}
return null;
}
ISettings LoadSettings(string directory)
{
if (directory == null) {
return LoadDefaultSettings(null, null, null);
}
return LoadDefaultSettings(new PhysicalFileSystem(directory), null, null);
}
}
}

2
src/AddIns/Misc/PackageManagement/Test/PackageManagement.Tests.csproj

@ -176,7 +176,6 @@ @@ -176,7 +176,6 @@
<Compile Include="Src\Helpers\FakePowerShellDetection.cs" />
<Compile Include="Src\Helpers\FakePowerShellSession.cs" />
<Compile Include="Src\Helpers\FakePropertyService.cs" />
<Compile Include="Src\Helpers\FakeSettingsFactory.cs" />
<Compile Include="Src\Helpers\FakeSolutionPackageRepository.cs" />
<Compile Include="Src\Helpers\FakeTextEditorOptions.cs" />
<Compile Include="Src\Helpers\ProjectItemCollectionAssert.cs" />
@ -195,6 +194,7 @@ @@ -195,6 +194,7 @@
<Compile Include="Src\Scripting\ConsoleHostFileConflictResolverTests.cs" />
<Compile Include="Src\Scripting\MSBuildProjectImportsMergerTests.cs" />
<Compile Include="Src\Scripting\MSBuildProjectPropertiesMergerTests.cs" />
<Compile Include="Src\SettingsProviderTests.cs" />
<Compile Include="Src\UpdatedPackagesTests.cs" />
<Compile Include="Src\UpdatePackagesActionTests.cs" />
<Compile Include="Src\UpdateSolutionPackagesActionTests.cs" />

37
src/AddIns/Misc/PackageManagement/Test/Src/Helpers/FakeSettingsFactory.cs

@ -1,37 +0,0 @@ @@ -1,37 +0,0 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using ICSharpCode.PackageManagement;
using ICSharpCode.PackageManagement.Design;
using NuGet;
namespace PackageManagement.Tests.Helpers
{
public class FakeSettingsFactory : ISettingsFactory
{
public FakeSettings FakeSettings = new FakeSettings();
public string DirectoryPassedToCreateSettings;
public ISettings CreateSettings(string directory)
{
DirectoryPassedToCreateSettings = directory;
return FakeSettings;
}
}
}

22
src/AddIns/Misc/PackageManagement/Test/Src/Helpers/TestablePackageManagementOptions.cs

@ -29,15 +29,31 @@ namespace PackageManagement.Tests.Helpers @@ -29,15 +29,31 @@ namespace PackageManagement.Tests.Helpers
public FakeSettings FakeSettings;
public TestablePackageManagementOptions()
: this(new Properties(), new FakeSettings())
: this(new Properties(), new FakeSettings(), new FakePackageManagementProjectService())
{
}
public TestablePackageManagementOptions(Properties properties, FakeSettings fakeSettings)
: base(properties, fakeSettings)
public TestablePackageManagementOptions(
Properties properties,
FakeSettings fakeSettings,
FakePackageManagementProjectService projectService)
: base(properties, CreateSettingsProvider(fakeSettings, projectService))
{
this.Properties = properties;
this.FakeSettings = fakeSettings;
}
public static void ChangeSettingsReturnedBySettingsProvider(FakeSettings settings)
{
SettingsProvider.LoadDefaultSettings = (fileSystem, configFile, machineSettings) => {
return settings;
};
}
public static SettingsProvider CreateSettingsProvider(FakeSettings fakeSettings, FakePackageManagementProjectService projectService)
{
ChangeSettingsReturnedBySettingsProvider(fakeSettings);
return new SettingsProvider(projectService);
}
}
}

115
src/AddIns/Misc/PackageManagement/Test/Src/PackageManagementOptionsTests.cs

@ -36,6 +36,8 @@ namespace PackageManagement.Tests @@ -36,6 +36,8 @@ namespace PackageManagement.Tests
Properties properties;
PackageManagementOptions options;
FakeSettings fakeSettings;
SettingsProvider settingsProvider;
FakePackageManagementProjectService projectService;
void CreateOptions()
{
@ -63,12 +65,26 @@ namespace PackageManagement.Tests @@ -63,12 +65,26 @@ namespace PackageManagement.Tests
void CreateOptions(FakeSettings fakeSettings)
{
CreateProperties();
options = new PackageManagementOptions(properties, fakeSettings);
CreateSettingsProvider(fakeSettings);
options = new PackageManagementOptions(properties, settingsProvider);
}
void CreateSettingsProvider(FakeSettings fakeSettings)
{
projectService = new FakePackageManagementProjectService();
settingsProvider = TestablePackageManagementOptions.CreateSettingsProvider(fakeSettings, projectService);
}
void ChangeSettingsReturnedBySettingsProvider()
{
fakeSettings = new FakeSettings();
TestablePackageManagementOptions.ChangeSettingsReturnedBySettingsProvider(fakeSettings);
}
void CreateOptions(Properties properties, FakeSettings fakeSettings)
{
options = new PackageManagementOptions(properties, fakeSettings);
CreateSettingsProvider(fakeSettings);
options = new PackageManagementOptions(properties, settingsProvider);
}
void SaveOptions()
@ -88,6 +104,18 @@ namespace PackageManagement.Tests @@ -88,6 +104,18 @@ namespace PackageManagement.Tests
fakeSettings.SetPackageRestoreSetting(true);
}
void OpenSolution()
{
var helper = new SolutionHelper(@"d:\projects\MyProject\MySolution.sln");
projectService.FireSolutionOpenedEvent(helper.MSBuildSolution);
}
void CloseSolution()
{
var helper = new SolutionHelper(@"d:\projects\MyProject\MySolution.sln");
projectService.FireSolutionClosedEvent(helper.MSBuildSolution);
}
[Test]
public void PackageSources_OnePackageSourceInSettings_ContainsSinglePackageSourceFromSettings()
{
@ -465,5 +493,88 @@ namespace PackageManagement.Tests @@ -465,5 +493,88 @@ namespace PackageManagement.Tests
KeyValuePair<string, string> keyValuePair = fakeSettings.GetValuePassedToSetValueForPackageRestoreSection();
Assert.AreEqual("False", keyValuePair.Value);
}
[Test]
public void PackageSources_SolutionOpenedAfterInitialPackageSourcesLoaded_ContainsPackageSourceFromSolutionSpecificSettings()
{
CreateSettings();
var packageSource = new PackageSource("http://codeplex.com", "Test");
fakeSettings.AddFakePackageSource(packageSource);
CreateOptions(fakeSettings);
RegisteredPackageSources initialSources = options.PackageSources;
var expectedInitialSources = new List<PackageSource>();
expectedInitialSources.Add(packageSource);
ChangeSettingsReturnedBySettingsProvider();
packageSource = new PackageSource("http://codeplex.com", "Test");
fakeSettings.AddFakePackageSource(packageSource);
var expectedSources = new List<PackageSource>();
expectedSources.Add(packageSource);
packageSource = new PackageSource("http://nuget.org", "ProjectSource");
fakeSettings.AddFakePackageSource(packageSource);
expectedSources.Add(packageSource);
OpenSolution();
RegisteredPackageSources actualSources = options.PackageSources;
Assert.AreEqual(expectedInitialSources, initialSources);
Assert.AreEqual(expectedSources, actualSources);
}
[Test]
public void PackageSources_SolutionClosedAfterInitialPackageSourcesLoaded_PackageSourcesReloaded()
{
CreateSettings();
var packageSource = new PackageSource("http://codeplex.com", "Test");
fakeSettings.AddFakePackageSource(packageSource);
var expectedInitialSources = new List<PackageSource>();
expectedInitialSources.Add(packageSource);
packageSource = new PackageSource("http://nuget.org", "ProjectSource");
fakeSettings.AddFakePackageSource(packageSource);
expectedInitialSources.Add(packageSource);
OpenSolution();
CreateOptions(fakeSettings);
RegisteredPackageSources initialSources = options.PackageSources;
ChangeSettingsReturnedBySettingsProvider();
packageSource = new PackageSource("http://codeplex.com", "Test");
fakeSettings.AddFakePackageSource(packageSource);
var expectedSources = new List<PackageSource>();
expectedSources.Add(packageSource);
CloseSolution();
RegisteredPackageSources actualSources = options.PackageSources;
Assert.AreEqual(expectedInitialSources, initialSources);
Assert.AreEqual(expectedSources, actualSources);
}
[Test]
public void PackageSources_SolutionClosedAfterInitialPackageSourcesLoaded_ActivePackageSourceReloaded()
{
CreateSettings();
var packageSource = new PackageSource("http://codeplex.com", "Test");
fakeSettings.AddFakePackageSource(packageSource);
var expectedInitialSources = new List<PackageSource>();
expectedInitialSources.Add(packageSource);
var initialActivePackageSource = new PackageSource("http://nuget.org", "ProjectSource");
fakeSettings.AddFakePackageSource(initialActivePackageSource);
fakeSettings.SetFakeActivePackageSource(initialActivePackageSource);
expectedInitialSources.Add(initialActivePackageSource);
OpenSolution();
CreateOptions(fakeSettings);
RegisteredPackageSources actualInitialPackageSources = options.PackageSources;
PackageSource actualInitialActivePackageSource = options.ActivePackageSource;
ChangeSettingsReturnedBySettingsProvider();
var expectedActivePackageSource = new PackageSource("http://codeplex.com", "Test");
fakeSettings.SetFakeActivePackageSource(expectedActivePackageSource);
fakeSettings.AddFakePackageSource(expectedActivePackageSource);
CloseSolution();
PackageSource actualSource = options.ActivePackageSource;
Assert.AreEqual(initialActivePackageSource, actualInitialActivePackageSource);
Assert.AreEqual(expectedActivePackageSource, actualSource);
Assert.AreEqual(expectedInitialSources, actualInitialPackageSources);
Assert.AreEqual(new PackageSource[] { expectedActivePackageSource }, options.PackageSources);
}
}
}

4
src/AddIns/Misc/PackageManagement/Test/Src/PackageManagementOptionsViewModelTests.cs

@ -50,8 +50,10 @@ namespace PackageManagement.Tests @@ -50,8 +50,10 @@ namespace PackageManagement.Tests
void CreateOptions()
{
var properties = new Properties();
var projectService = new FakePackageManagementProjectService();
fakeSettings = new FakeSettings();
options = new PackageManagementOptions(properties, fakeSettings);
SettingsProvider settingsProvider = TestablePackageManagementOptions.CreateSettingsProvider(fakeSettings, projectService);
options = new PackageManagementOptions(properties, settingsProvider);
}
void EnablePackageRestoreInOptions()

80
src/AddIns/Misc/PackageManagement/Test/Src/SettingsProviderTests.cs

@ -0,0 +1,80 @@ @@ -0,0 +1,80 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.PackageManagement;
using ICSharpCode.PackageManagement.Design;
using NuGet;
using NUnit.Framework;
using PackageManagement.Tests.Helpers;
namespace PackageManagement.Tests
{
[TestFixture]
public class SettingsProviderTests
{
SettingsProvider settingsProvider;
FakeSettings fakeSettings;
FakePackageManagementProjectService projectService;
IFileSystem fileSystemUsedToLoadSettings;
string configFileUsedToLoadSettings;
IMachineWideSettings machinesettingsUsedToLoadSettings;
[SetUp]
public void SetUp()
{
fakeSettings = new FakeSettings();
projectService = new FakePackageManagementProjectService();
SettingsProvider.LoadDefaultSettings = LoadDefaultSettings;
settingsProvider = new SettingsProvider(projectService);
}
ISettings LoadDefaultSettings(IFileSystem fileSystem, string configFile, IMachineWideSettings machineSettings)
{
fileSystemUsedToLoadSettings = fileSystem;
configFileUsedToLoadSettings = configFile;
machinesettingsUsedToLoadSettings = machineSettings;
return fakeSettings;
}
void OpenSolution(string fileName)
{
var helper = new SolutionHelper(fileName);
projectService.OpenSolution = helper.MSBuildSolution;
}
[TearDown]
public void TearDown()
{
// This resets SettingsProvider.LoadDefaultSettings.
TestablePackageManagementOptions.CreateSettingsProvider(fakeSettings, projectService);
}
[Test]
public void LoadSettings_NoSolutionOpen_NullFileSystemAndNullConfigFileAndNullMachineSettingsUsed()
{
fileSystemUsedToLoadSettings = new FakeFileSystem();
configFileUsedToLoadSettings = "configFile";
ISettings settings = settingsProvider.LoadSettings();
Assert.IsNull(fileSystemUsedToLoadSettings);
Assert.IsNull(configFileUsedToLoadSettings);
Assert.IsNull(machinesettingsUsedToLoadSettings);
Assert.AreEqual(fakeSettings, settings);
}
[Test]
public void LoadSettings_SolutionOpen_FileSystemWithRootSetToSolutionDirectoryUsedToLoadSettings()
{
string fileName = @"d:\projects\MyProject\MyProject.sln";
OpenSolution(fileName);
ISettings settings = settingsProvider.LoadSettings();
Assert.AreEqual(@"d:\projects\MyProject", fileSystemUsedToLoadSettings.Root);
Assert.AreEqual(fakeSettings, settings);
}
}
}
Loading…
Cancel
Save