PageRenderTime 36ms CodeModel.GetById 16ms app.highlight 14ms RepoModel.GetById 2ms app.codeStats 0ms

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

https://github.com/ajadex/SharpDevelop
C# | 201 lines | 142 code | 42 blank | 17 comment | 0 complexity | c5f260ec93e35369ed432fd0ca45de9e 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.PackageManagement;
 21using ICSharpCode.PackageManagement.Design;
 22using ICSharpCode.PackageManagement.Scripting;
 23using NuGet;
 24using NUnit.Framework;
 25using PackageManagement.Tests.Helpers;
 26using Rhino.Mocks;
 27
 28namespace PackageManagement.Tests
 29{
 30	[TestFixture]
 31	public class UpdatePackagesActionTests
 32	{
 33		TestableUpdatePackagesAction action;
 34		IPackageManagementProject project;
 35		IPackageManagementEvents packageEvents;
 36		
 37		void CreateAction()
 38		{
 39			CreateSolution();
 40			packageEvents = MockRepository.GenerateStub<IPackageManagementEvents>();
 41			action = new TestableUpdatePackagesAction(project, packageEvents);
 42		}
 43		
 44		void CreateActionWithOperations(params PackageOperation[] operations)
 45		{
 46			CreateAction();
 47			action.AddOperations(operations);
 48		}
 49		
 50		void CreateSolution()
 51		{
 52			project = MockRepository.GenerateStub<IPackageManagementProject>();
 53		}
 54		
 55		IPackage CreatePackage()
 56		{
 57			return MockRepository.GenerateStub<IPackage>();
 58		}
 59		
 60		PackageOperation CreateInstallOperationWithFile(string fileName)
 61		{
 62			return PackageOperationHelper.CreateInstallOperationWithFile(fileName);
 63		}
 64		
 65		IPackageScriptRunner CreatePackageScriptRunner()
 66		{
 67			return MockRepository.GenerateStub<IPackageScriptRunner>();
 68		}
 69		
 70		FakePackage AddPackageToAction(string id, string version)
 71		{
 72			var package = new FakePackage(id, version);
 73			action.AddPackages(new FakePackage[] { package });
 74			return package;
 75		}
 76		
 77		[Test]
 78		public void UpdateDependencies_DefaultValue_IsTrue()
 79		{
 80			CreateActionWithOperations();
 81			
 82			bool result = action.UpdateDependencies;
 83			
 84			Assert.IsTrue(result);
 85		}
 86		
 87		[Test]
 88		public void HasPackageScriptsToRun_PackageHasInitPowerShellScript_ReturnsTrue()
 89		{
 90			PackageOperation operation = CreateInstallOperationWithFile(@"tools\install.ps1");
 91			CreateActionWithOperations(operation);
 92			
 93			bool result = action.HasPackageScriptsToRun();
 94			
 95			Assert.IsTrue(result);
 96		}
 97		
 98		[Test]
 99		public void HasPackageScriptsToRun_PackageHasOneTextFile_ReturnsFalse()
100		{
101			PackageOperation operation = CreateInstallOperationWithFile(@"tools\readme.txt");
102			CreateActionWithOperations(operation);
103			
104			bool result = action.HasPackageScriptsToRun();
105			
106			Assert.IsFalse(result);
107		}
108		
109		[Test]
110		public void Execute_UpdatePackagesAction_PackagesUpdatedUsingProject()
111		{
112			CreateAction();
113			
114			action.Execute();
115			
116			project.AssertWasCalled(p => p.UpdatePackages(action));
117		}
118		
119		[Test]
120		public void Execute_UpdatePackagesActionWithOnePackageOperation_PackagesUpdatedUsingProject()
121		{
122			PackageOperation operation = CreateInstallOperationWithFile(@"tools\readme.txt");
123			CreateActionWithOperations(operation);
124			
125			action.Execute();
126			
127			project.AssertWasCalled(p => p.UpdatePackages(action));
128		}
129		
130		[Test]
131		public void Execute_PackageScriptRunnerSet_RunPackageScriptsActionCreatedUsingPackageScriptRunner()
132		{
133			CreateAction();
134			IPackageScriptRunner expectedRunner = CreatePackageScriptRunner();
135			action.PackageScriptRunner = expectedRunner;
136			
137			action.Execute();
138			
139			IPackageScriptRunner actualRunner = action.ScriptRunnerPassedToCreateRunPackageScriptsAction;
140			Assert.AreEqual(expectedRunner, actualRunner);
141		}
142		
143		[Test]
144		public void Execute_PackageScriptRunnerSet_RunPackageScriptsActionCreatedUsingProject()
145		{
146			CreateAction();
147			action.PackageScriptRunner = CreatePackageScriptRunner();
148			
149			action.Execute();
150			
151			IPackageManagementProject actualProject = action.ProjectPassedToCreateRunPackageScriptsAction;
152			Assert.AreEqual(project, actualProject);
153		}
154		
155		[Test]
156		public void Execute_PackageScriptRunnerSet_RunPackageScriptsActionIsDisposed()
157		{
158			CreateAction();
159			action.PackageScriptRunner = CreatePackageScriptRunner();
160			
161			action.Execute();
162			
163			Assert.IsTrue(action.IsRunPackageScriptsActionDisposed);
164		}
165		
166		[Test]
167		public void Execute_NullPackageScriptRunner_RunPackageScriptsActionIsNotCreated()
168		{
169			CreateAction();
170			action.PackageScriptRunner = null;
171			
172			action.Execute();
173			
174			Assert.IsFalse(action.IsRunPackageScriptsActionCreated);
175		}
176		
177		[Test]
178		public void Execute_PackageScriptRunnerSet_PackagesAreUpdated()
179		{
180			CreateAction();
181			PackageOperation operation = CreateInstallOperationWithFile(@"tools\readme.txt");
182			CreateActionWithOperations(operation);
183			action.PackageScriptRunner = CreatePackageScriptRunner();
184			
185			action.Execute();
186			
187			project.AssertWasCalled(p => p.UpdatePackages(action));
188		}
189		
190		[Test]
191		public void Execute_ActionHasOnePackage_ParentPackagesUpdatedEventIsFired()
192		{
193			CreateAction();
194			AddPackageToAction("Test", "1.0");
195			
196			action.Execute();
197			
198			packageEvents.AssertWasCalled(events => events.OnParentPackagesUpdated(action.Packages));
199		}
200	}
201}