/src/AddIns/Misc/PackageManagement/Test/Src/SolutionPackageRepositoryPathTests.cs

https://github.com/ajadex/SharpDevelop · C# · 135 lines · 96 code · 22 blank · 17 comment · 0 complexity · ae20f42a2f5df44e6e5a51ecded87ef4 MD5 · raw file

  1. // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System;
  19. using ICSharpCode.Core;
  20. using ICSharpCode.PackageManagement;
  21. using ICSharpCode.PackageManagement.Design;
  22. using ICSharpCode.SharpDevelop.Project;
  23. using NUnit.Framework;
  24. using Rhino.Mocks;
  25. using PackageManagement.Tests.Helpers;
  26. namespace PackageManagement.Tests
  27. {
  28. [TestFixture]
  29. public class SolutionPackageRepositoryPathTests
  30. {
  31. SolutionPackageRepositoryPath repositoryPath;
  32. IProject testProject;
  33. TestablePackageManagementOptions options;
  34. ISolution solution;
  35. FakeSettings settings;
  36. void CreateSolutionPackageRepositoryPath()
  37. {
  38. repositoryPath = new SolutionPackageRepositoryPath(testProject, options);
  39. }
  40. void CreateSolutionPackageRepositoryPath(ISolution solution)
  41. {
  42. repositoryPath = new SolutionPackageRepositoryPath(solution, options);
  43. }
  44. void CreateTestProject()
  45. {
  46. testProject = ProjectHelper.CreateTestProject();
  47. }
  48. void CreateSolution(string fileName)
  49. {
  50. solution = MockRepository.GenerateStrictMock<ISolution>();
  51. var file = FileName.Create(fileName);
  52. solution.Stub(s => s.FileName).Return(file);
  53. solution.Stub(s => s.Directory).Return(file.GetParentDirectory());
  54. }
  55. void CreateOptions()
  56. {
  57. options = new TestablePackageManagementOptions();
  58. settings = options.FakeSettings;
  59. }
  60. void SolutionNuGetConfigFileHasCustomPackagesPath(string fullPath)
  61. {
  62. settings.SetRepositoryPathSetting(fullPath);
  63. }
  64. [Test]
  65. public void PackageRepositoryPath_ProjectAndSolutionHaveDifferentFolders_IsConfiguredPackagesFolderInsideSolutionFolder()
  66. {
  67. CreateOptions();
  68. CreateTestProject();
  69. testProject.ParentSolution.Stub(s => s.Directory).Return(DirectoryName.Create(@"d:\projects\MyProject\"));
  70. options.PackagesDirectory = "MyPackages";
  71. CreateSolutionPackageRepositoryPath();
  72. string path = repositoryPath.PackageRepositoryPath;
  73. string expectedPath = @"d:\projects\MyProject\MyPackages";
  74. Assert.AreEqual(expectedPath, path);
  75. }
  76. [Test]
  77. public void PackageRepositoryPath_PassSolutionToConstructor_IsConfiguredPackagesFolderInsideSolutionFolder()
  78. {
  79. CreateOptions();
  80. CreateSolution(@"d:\projects\MySolution\MySolution.sln");
  81. options.PackagesDirectory = "Packages";
  82. CreateSolutionPackageRepositoryPath(solution);
  83. string path = repositoryPath.PackageRepositoryPath;
  84. string expectedPath = @"d:\projects\MySolution\Packages";
  85. Assert.AreEqual(expectedPath, path);
  86. }
  87. [Test]
  88. public void GetInstallPath_GetInstallPathForPackage_ReturnsPackagePathInsideSolutionPackagesRepository()
  89. {
  90. CreateOptions();
  91. CreateSolution(@"d:\projects\Test\MySolution\MyProject.sln");
  92. options.PackagesDirectory = "MyPackages";
  93. CreateSolutionPackageRepositoryPath(solution);
  94. var package = FakePackage.CreatePackageWithVersion("MyPackage", "1.2.1.40");
  95. string installPath = repositoryPath.GetInstallPath(package);
  96. string expectedInstallPath =
  97. @"d:\projects\Test\MySolution\MyPackages\MyPackage.1.2.1.40";
  98. Assert.AreEqual(expectedInstallPath, installPath);
  99. }
  100. [Test]
  101. public void PackageRepositoryPath_SolutionHasNuGetFileThatOverridesDefaultPackagesRepositoryPath_OverriddenPathReturned()
  102. {
  103. CreateOptions();
  104. CreateSolution(@"d:\projects\MySolution\MySolution.sln");
  105. options.PackagesDirectory = "Packages";
  106. SolutionNuGetConfigFileHasCustomPackagesPath(@"d:\Team\MyPackages");
  107. CreateSolutionPackageRepositoryPath(solution);
  108. string expectedPath = @"d:\Team\MyPackages";
  109. string path = repositoryPath.PackageRepositoryPath;
  110. Assert.AreEqual(expectedPath, path);
  111. }
  112. }
  113. }