PageRenderTime 29ms CodeModel.GetById 9ms app.highlight 13ms RepoModel.GetById 2ms app.codeStats 0ms

/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
 19using System;
 20using ICSharpCode.Core;
 21using ICSharpCode.PackageManagement;
 22using ICSharpCode.PackageManagement.Design;
 23using ICSharpCode.SharpDevelop.Project;
 24using NUnit.Framework;
 25using Rhino.Mocks;
 26using PackageManagement.Tests.Helpers;
 27
 28namespace PackageManagement.Tests
 29{
 30	[TestFixture]
 31	public class SolutionPackageRepositoryPathTests
 32	{
 33		SolutionPackageRepositoryPath repositoryPath;
 34		IProject testProject;
 35		TestablePackageManagementOptions options;
 36		ISolution solution;
 37		FakeSettings settings;
 38		
 39		void CreateSolutionPackageRepositoryPath()
 40		{
 41			repositoryPath = new SolutionPackageRepositoryPath(testProject, options);
 42		}
 43		
 44		void CreateSolutionPackageRepositoryPath(ISolution solution)
 45		{
 46			repositoryPath = new SolutionPackageRepositoryPath(solution, options);
 47		}
 48		
 49		void CreateTestProject()
 50		{
 51			testProject = ProjectHelper.CreateTestProject();
 52		}
 53		
 54		void CreateSolution(string fileName)
 55		{
 56			solution = MockRepository.GenerateStrictMock<ISolution>();
 57			var file = FileName.Create(fileName);
 58			solution.Stub(s => s.FileName).Return(file);
 59			solution.Stub(s => s.Directory).Return(file.GetParentDirectory());
 60		}
 61		
 62		void CreateOptions()
 63		{
 64			options = new TestablePackageManagementOptions();
 65			settings = options.FakeSettings;
 66		}
 67
 68		void SolutionNuGetConfigFileHasCustomPackagesPath(string fullPath)
 69		{
 70			settings.SetRepositoryPathSetting(fullPath);
 71		}
 72		
 73		[Test]
 74		public void PackageRepositoryPath_ProjectAndSolutionHaveDifferentFolders_IsConfiguredPackagesFolderInsideSolutionFolder()
 75		{
 76			CreateOptions();
 77			CreateTestProject();
 78			testProject.ParentSolution.Stub(s => s.Directory).Return(DirectoryName.Create(@"d:\projects\MyProject\"));
 79			options.PackagesDirectory = "MyPackages";
 80			CreateSolutionPackageRepositoryPath();
 81			
 82			string path = repositoryPath.PackageRepositoryPath;
 83			string expectedPath = @"d:\projects\MyProject\MyPackages";
 84			
 85			Assert.AreEqual(expectedPath, path);
 86		}
 87		
 88		[Test]
 89		public void PackageRepositoryPath_PassSolutionToConstructor_IsConfiguredPackagesFolderInsideSolutionFolder()
 90		{
 91			CreateOptions();
 92			CreateSolution(@"d:\projects\MySolution\MySolution.sln");
 93			options.PackagesDirectory = "Packages";
 94			CreateSolutionPackageRepositoryPath(solution);
 95			
 96			string path = repositoryPath.PackageRepositoryPath;
 97			string expectedPath = @"d:\projects\MySolution\Packages";
 98			
 99			Assert.AreEqual(expectedPath, path);
100		}
101		
102		[Test]
103		public void GetInstallPath_GetInstallPathForPackage_ReturnsPackagePathInsideSolutionPackagesRepository()
104		{
105			CreateOptions();
106			CreateSolution(@"d:\projects\Test\MySolution\MyProject.sln");
107			options.PackagesDirectory = "MyPackages";
108			CreateSolutionPackageRepositoryPath(solution);
109			
110			var package = FakePackage.CreatePackageWithVersion("MyPackage", "1.2.1.40");
111			
112			string installPath = repositoryPath.GetInstallPath(package);
113			
114			string expectedInstallPath = 
115				@"d:\projects\Test\MySolution\MyPackages\MyPackage.1.2.1.40";
116			
117			Assert.AreEqual(expectedInstallPath, installPath);
118		}
119		
120		[Test]
121		public void PackageRepositoryPath_SolutionHasNuGetFileThatOverridesDefaultPackagesRepositoryPath_OverriddenPathReturned()
122		{
123			CreateOptions();
124			CreateSolution(@"d:\projects\MySolution\MySolution.sln");
125			options.PackagesDirectory = "Packages";
126			SolutionNuGetConfigFileHasCustomPackagesPath(@"d:\Team\MyPackages");
127			CreateSolutionPackageRepositoryPath(solution);
128			string expectedPath = @"d:\Team\MyPackages";
129
130			string path = repositoryPath.PackageRepositoryPath;
131
132			Assert.AreEqual(expectedPath, path);
133		}
134	}
135}