PageRenderTime 37ms CodeModel.GetById 9ms app.highlight 19ms RepoModel.GetById 2ms app.codeStats 0ms

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

https://github.com/ajadex/SharpDevelop
C# | 240 lines | 173 code | 50 blank | 17 comment | 0 complexity | 5cf6e331b21da1820dac3e068d3dc5ee 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 System.Linq;
 22using ICSharpCode.PackageManagement;
 23using ICSharpCode.PackageManagement.Design;
 24using ICSharpCode.PackageManagement.Scripting;
 25using NuGet;
 26using NUnit.Framework;
 27using PackageManagement.Tests.Helpers;
 28
 29namespace PackageManagement.Tests
 30{
 31	[TestFixture]
 32	public class UpdateAllPackagesInProjectTests
 33	{
 34		UpdateAllPackagesInProject updateAllPackagesInProject;
 35		FakePackageManagementProject fakeProject;
 36		List<UpdatePackageAction> updateActions;
 37		
 38		void CreateUpdateAllPackagesInProject()
 39		{
 40			fakeProject = new FakePackageManagementProject();
 41			updateAllPackagesInProject = new UpdateAllPackagesInProject(fakeProject);
 42		}
 43		
 44		void AddPackageToProject(string packageId)
 45		{
 46			var package = new FakePackage(packageId, "1.0");
 47			fakeProject.FakePackagesInReverseDependencyOrder.Add(package);
 48		}
 49		
 50		void CallCreateActions()
 51		{
 52			IEnumerable<UpdatePackageAction> actions = updateAllPackagesInProject.CreateActions();
 53			updateActions = actions.ToList();
 54		}
 55		
 56		UpdatePackageAction FirstUpdateAction {
 57			get { return updateActions[0]; }
 58		}
 59		
 60		[Test]
 61		public void CreateActions_OnePackageInProject_ReturnsOneAction()
 62		{
 63			CreateUpdateAllPackagesInProject();
 64			AddPackageToProject("Test");
 65			CallCreateActions();
 66			
 67			Assert.AreEqual(1, updateActions.Count);
 68		}
 69		
 70		[Test]
 71		public void CreateActions_OnePackageInProject_ActionCreatedFromProject()
 72		{
 73			CreateUpdateAllPackagesInProject();
 74			AddPackageToProject("Test");
 75			CallCreateActions();
 76			
 77			UpdatePackageAction action = updateActions[0];
 78			UpdatePackageAction expectedAction = fakeProject.FirstFakeUpdatePackageActionCreated;
 79			
 80			Assert.AreEqual(expectedAction, action);
 81		}
 82		
 83		[Test]
 84		public void CreateActions_OnePackageInProject_PackageIdSpecifiedInAction()
 85		{
 86			CreateUpdateAllPackagesInProject();
 87			AddPackageToProject("Test");
 88			CallCreateActions();
 89			
 90			string id = FirstUpdateAction.PackageId;
 91			
 92			Assert.AreEqual("Test", id);
 93		}
 94		
 95		[Test]
 96		public void CreateActions_OnePackageInProject_PackageVersionSpecifiedInActionIsNull()
 97		{
 98			CreateUpdateAllPackagesInProject();
 99			AddPackageToProject("Test");
100			CallCreateActions();
101			
102			SemanticVersion version = FirstUpdateAction.PackageVersion;
103			
104			Assert.IsNull(version);
105		}
106		
107		[Test]
108		public void CreateActions_NoPackagesInProject_ReturnsNoActions()
109		{
110			CreateUpdateAllPackagesInProject();
111			CallCreateActions();
112						
113			Assert.AreEqual(0, updateActions.Count);
114		}
115		
116		[Test]
117		public void CreateActions_TwoPackagesInProject_TwoUpdateActionsCreated()
118		{
119			CreateUpdateAllPackagesInProject();
120			AddPackageToProject("Test1");
121			AddPackageToProject("Test2");
122			CallCreateActions();
123						
124			Assert.AreEqual(2, updateActions.Count);
125		}
126		
127		[Test]
128		public void CreateActions_TwoPackagesInProject_TwoPackageIdsSpecifiedInActions()
129		{
130			CreateUpdateAllPackagesInProject();
131			AddPackageToProject("Test1");
132			AddPackageToProject("Test2");
133			CallCreateActions();
134						
135			Assert.AreEqual("Test1", updateActions[0].PackageId);
136			Assert.AreEqual("Test2", updateActions[1].PackageId);
137		}
138		
139		[Test]
140		public void CreateActions_OnePackageInProject_UpdateIfPackageDoesNotExistInProjectIsFalse()
141		{
142			CreateUpdateAllPackagesInProject();
143			AddPackageToProject("Test");
144			CallCreateActions();
145			
146			bool update = FirstUpdateAction.UpdateIfPackageDoesNotExistInProject;
147			
148			Assert.IsFalse(update);
149		}
150		
151		[Test]
152		public void CreateActions_OnePackageInProjectAndUpdateDependenciesSetToFalse_ActionUpdateDependenciesIsFalse()
153		{
154			CreateUpdateAllPackagesInProject();
155			AddPackageToProject("Test");
156			updateAllPackagesInProject.UpdateDependencies = false;
157			
158			CallCreateActions();
159			
160			bool update = FirstUpdateAction.UpdateDependencies;
161			
162			Assert.IsFalse(update);
163		}
164		
165		[Test]
166		public void UpdateDependencies_NewInstance_ReturnsTrue()
167		{
168			CreateUpdateAllPackagesInProject();
169			bool update = updateAllPackagesInProject.UpdateDependencies;
170			
171			Assert.IsTrue(update);
172		}
173		
174		[Test]
175		public void CreateActions_OnePackageInProjectAndAllowPrereleaseVersionsSetToFalse_ActionPrereleaseVersionsIsFalse()
176		{
177			CreateUpdateAllPackagesInProject();
178			AddPackageToProject("Test");
179			updateAllPackagesInProject.AllowPrereleaseVersions = false;
180			
181			CallCreateActions();
182			
183			bool allow = FirstUpdateAction.AllowPrereleaseVersions;
184			
185			Assert.IsFalse(allow);
186		}
187		
188		[Test]
189		public void CreateActions_OnePackageInProjectAndAllowPrereleaseVersionsSetToTrue_ActionPrereleaseVersionsIsTrue()
190		{
191			CreateUpdateAllPackagesInProject();
192			AddPackageToProject("Test");
193			updateAllPackagesInProject.AllowPrereleaseVersions = true;
194			
195			CallCreateActions();
196			
197			bool allow = FirstUpdateAction.AllowPrereleaseVersions;
198			
199			Assert.IsTrue(allow);
200		}
201		
202		[Test]
203		public void AllowPrereleaseVersions_NewInstance_ReturnsFalse()
204		{
205			CreateUpdateAllPackagesInProject();
206			bool allow = updateAllPackagesInProject.AllowPrereleaseVersions;
207			
208			Assert.IsFalse(allow);
209		}
210		
211		[Test]
212		public void CreateActions_OnePackageInProjectAndUpdateDependenciesSetToTrue_ActionUpdateDependenciesIsTrue()
213		{
214			CreateUpdateAllPackagesInProject();
215			AddPackageToProject("Test");
216			updateAllPackagesInProject.UpdateDependencies = true;
217			
218			CallCreateActions();
219			
220			bool update = FirstUpdateAction.UpdateDependencies;
221			
222			Assert.IsTrue(update);
223		}
224		
225		[Test]
226		public void CreateActions_OnePackageInProjectAndPackageScriptRunnerSet_ActionPackageScriptRunnerIsSet()
227		{
228			CreateUpdateAllPackagesInProject();
229			AddPackageToProject("Test");
230			var expectedRunner = new FakePackageScriptRunner();
231			updateAllPackagesInProject.PackageScriptRunner = expectedRunner;
232			
233			CallCreateActions();
234			
235			IPackageScriptRunner runner = FirstUpdateAction.PackageScriptRunner;
236			
237			Assert.AreEqual(expectedRunner, runner);
238		}
239	}
240}