PageRenderTime 25ms CodeModel.GetById 16ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

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

https://github.com/ajadex/SharpDevelop
C# | 163 lines | 108 code | 38 blank | 17 comment | 0 complexity | 08c5b6a54d5c36bde7284cfd8a4adef1 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 System.Collections.Generic;
 21using ICSharpCode.PackageManagement;
 22using ICSharpCode.PackageManagement.Design;
 23using NuGet;
 24using NUnit.Framework;
 25
 26namespace PackageManagement.Tests
 27{
 28	[TestFixture]
 29	public class PackageFilesTests
 30	{
 31		PackageFiles packageFiles;
 32		
 33		void CreatePackageFiles(FakePackage package)
 34		{
 35			packageFiles = new PackageFiles(package);
 36		}
 37		
 38		void CreatePackageFilesWithOneFile(string fileName)
 39		{
 40			var package = new FakePackage();
 41			package.AddFile(fileName);
 42			CreatePackageFiles(package);
 43		}
 44		
 45		void CreatePackageFilesWithTwoFiles(string fileName1, string fileName2)
 46		{
 47			var package = new FakePackage();
 48			package.AddFile(fileName1);
 49			package.AddFile(fileName2);
 50			CreatePackageFiles(package);
 51		}
 52		
 53		[Test]
 54		public void HasAnyPackageScripts_HasOnePowerShellInitScript_ReturnsTrue()
 55		{
 56			CreatePackageFilesWithOneFile(@"tools\init.ps1");
 57			
 58			bool hasScripts = packageFiles.HasAnyPackageScripts();
 59			
 60			Assert.IsTrue(hasScripts);
 61		}
 62		
 63		[Test]
 64		public void HasAnyPackageScripts_HasOneCSharpFile_ReturnsFalse()
 65		{
 66			CreatePackageFilesWithOneFile(@"src\test.cs");
 67			
 68			bool hasScripts = packageFiles.HasAnyPackageScripts();
 69			
 70			Assert.IsFalse(hasScripts);
 71		}
 72		
 73		[Test]
 74		public void HasAnyPackageScripts_HasOnePowerShellInitScriptWithDifferentParentFolder_ReturnsTrue()
 75		{
 76			CreatePackageFilesWithOneFile(@"parentfolder\init.ps1");
 77			
 78			bool hasScripts = packageFiles.HasAnyPackageScripts();
 79			
 80			Assert.IsTrue(hasScripts);
 81		}
 82		
 83		[Test]
 84		public void HasAnyPackageScripts_HasOnePowerShellInitScriptInUpperCase_ReturnsTrue()
 85		{
 86			CreatePackageFilesWithOneFile(@"tools\INIT.PS1");
 87			
 88			bool hasScripts = packageFiles.HasAnyPackageScripts();
 89			
 90			Assert.IsTrue(hasScripts);
 91		}
 92		
 93		[Test]
 94		public void HasAnyPackageScripts_HasOnePowerShellInstallScript_ReturnsTrue()
 95		{
 96			CreatePackageFilesWithOneFile(@"tools\install.ps1");
 97			
 98			bool hasScripts = packageFiles.HasAnyPackageScripts();
 99			
100			Assert.IsTrue(hasScripts);
101		}
102		
103		[Test]
104		public void HasAnyPackageScripts_HasOnePowerShellInstallScriptInUpperCase_ReturnsTrue()
105		{
106			CreatePackageFilesWithOneFile(@"tools\INSTALL.PS1");
107			
108			bool hasScripts = packageFiles.HasAnyPackageScripts();
109			
110			Assert.IsTrue(hasScripts);
111		}
112		
113		[Test]
114		public void HasAnyPackageScripts_HasOnePowerShellUninstallScript_ReturnsTrue()
115		{
116			CreatePackageFilesWithOneFile(@"tools\uninstall.ps1");
117			
118			bool hasScripts = packageFiles.HasAnyPackageScripts();
119			
120			Assert.IsTrue(hasScripts);
121		}
122		
123		[Test]
124		public void HasAnyPackageScripts_HasOnePowerShellUninstallScriptInUpperCase_ReturnsTrue()
125		{
126			CreatePackageFilesWithOneFile(@"tools\UNINSTALL.PS1");
127			
128			bool hasScripts = packageFiles.HasAnyPackageScripts();
129			
130			Assert.IsTrue(hasScripts);
131		}
132		
133		[Test]
134		public void HasAnyPackageScripts_SecondFileIsPowerShellInitScript_ReturnsTrue()
135		{
136			CreatePackageFilesWithTwoFiles(@"src\test.cs", @"tools\init.ps1");
137			
138			bool hasScripts = packageFiles.HasAnyPackageScripts();
139			
140			Assert.IsTrue(hasScripts);
141		}
142		
143		[Test]
144		public void HasUninstallPackageScript_HasOnePowerShellUninstallScript_ReturnsTrue()
145		{
146			CreatePackageFilesWithOneFile(@"tools\uninstall.ps1");
147			
148			bool hasScript = packageFiles.HasUninstallPackageScript();
149			
150			Assert.IsTrue(hasScript);
151		}
152		
153		[Test]
154		public void HasUninstallPackageScript_HasOneCSharpFile_ReturnsFalse()
155		{
156			CreatePackageFilesWithOneFile(@"tools\test.cs");
157			
158			bool hasScript = packageFiles.HasUninstallPackageScript();
159			
160			Assert.IsFalse(hasScript);
161		}
162	}
163}