PageRenderTime 27ms CodeModel.GetById 11ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

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

https://github.com/ajadex/SharpDevelop
C# | 211 lines | 145 code | 49 blank | 17 comment | 0 complexity | eac8db81bea631dc3bbdc2f436bfee89 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;
 22
 23using ICSharpCode.PackageManagement;
 24using ICSharpCode.PackageManagement.Design;
 25using ICSharpCode.SharpDevelop.Project;
 26using NUnit.Framework;
 27using PackageManagement.Tests.Helpers;
 28
 29namespace PackageManagement.Tests
 30{
 31	[TestFixture]
 32	public class SelectedProjectsForUpdatedPackagesTests
 33	{
 34		TestableSelectedProjectsForUpdatedPackages selectedProjects;
 35		FakePackageManagementSolution fakeSolution;
 36		
 37		void CreateFakeSolution()
 38		{
 39			fakeSolution = new FakePackageManagementSolution();
 40		}
 41		
 42		void CreateSelectedProjects()
 43		{
 44			selectedProjects = new TestableSelectedProjectsForUpdatedPackages(fakeSolution);
 45		}
 46		
 47		List<IProject> AddSolutionWithTwoProjectsToProjectService(string projectName1, string projectName2)
 48		{
 49			ISolution solution = ProjectHelper.CreateSolution();
 50			TestableProject project1 = ProjectHelper.CreateTestProject(solution, projectName1);
 51			TestableProject project2 = ProjectHelper.CreateTestProject(solution, projectName2);
 52			
 53			fakeSolution.FakeMSBuildProjects.Add(project1);
 54			fakeSolution.FakeMSBuildProjects.Add(project2);
 55			
 56			fakeSolution.AddFakeProjectToReturnFromGetProject(projectName1);
 57			fakeSolution.AddFakeProjectToReturnFromGetProject(projectName2);
 58			
 59			return fakeSolution.FakeMSBuildProjects;
 60		}
 61		
 62		FakePackageManagementProject GetProject(string name)
 63		{
 64			return fakeSolution.FakeProjectsToReturnFromGetProject[name];
 65		}
 66		
 67		[Test]
 68		public void GetProjects_TwoProjectsAndPackageNotInstalledInAnyProject_IsEnabledIsFalseForAllSelectedProjects()
 69		{
 70			CreateFakeSolution();
 71			AddSolutionWithTwoProjectsToProjectService("Project A", "Project B");
 72			fakeSolution.NoProjectsSelected();
 73			CreateSelectedProjects();
 74			
 75			var fakePackage = new FakePackage("Test");
 76			List<IPackageManagementSelectedProject> projects =
 77				selectedProjects.GetProjects(fakePackage).ToList();
 78			
 79			var expectedProjects = new List<IPackageManagementSelectedProject>();
 80			expectedProjects.Add(new FakeSelectedProject("Project A", selected: false, enabled: false));
 81			expectedProjects.Add(new FakeSelectedProject("Project B", selected: false, enabled: false));
 82			
 83			SelectedProjectCollectionAssert.AreEqual(expectedProjects, projects);
 84		}
 85		
 86		[Test]
 87		public void GetProjects_TwoProjectsAndOlderPackageInstalledInFirstProject_IsEnabledIsTrueForFirstSelectedProjectButFalseForSecond()
 88		{
 89			CreateFakeSolution();
 90			AddSolutionWithTwoProjectsToProjectService("Project A", "Project B");
 91			fakeSolution.NoProjectsSelected();
 92			CreateSelectedProjects();
 93			
 94			var olderFakePackage = new FakePackage("Test", "1.0");
 95			FakePackageManagementProject projectA = GetProject("Project A");
 96			projectA.FakePackages.Add(olderFakePackage);
 97				
 98			var fakePackage = new FakePackage("Test", "1.2");
 99			List<IPackageManagementSelectedProject> projects =
100				selectedProjects.GetProjects(fakePackage).ToList();
101			
102			var expectedProjects = new List<IPackageManagementSelectedProject>();
103			expectedProjects.Add(new FakeSelectedProject("Project A", selected: true, enabled: true));
104			expectedProjects.Add(new FakeSelectedProject("Project B", selected: false, enabled: false));
105			
106			SelectedProjectCollectionAssert.AreEqual(expectedProjects, projects);
107		}
108		
109		[Test]
110		public void IsProjectEnabled_PackageOlderThanPackageIntalledInProject_ReturnsFalse()
111		{
112			CreateFakeSolution();
113			CreateSelectedProjects();
114			
115			var oldPackage = new FakePackage("Test", "1.0");
116			var newPackage = new FakePackage("Test", "1.3");
117			
118			var project = new FakePackageManagementProject();
119			project.FakePackages.Add(newPackage);
120			
121			bool enabled = selectedProjects.CallIsProjectEnabled(project, oldPackage);
122			
123			Assert.IsFalse(enabled);
124		}
125		
126		[Test]
127		public void IsProjectEnabled_PackageSameVersionAsPackageIntalledInProject_ReturnsFalse()
128		{
129			CreateFakeSolution();
130			CreateSelectedProjects();
131			
132			var oldPackage = new FakePackage("Test", "1.0");
133			var newPackage = new FakePackage("Test", "1.0");
134			
135			var project = new FakePackageManagementProject();
136			project.FakePackages.Add(newPackage);
137			
138			bool enabled = selectedProjects.CallIsProjectEnabled(project, oldPackage);
139			
140			Assert.IsFalse(enabled);
141		}
142		
143		[Test]
144		public void IsProjectSelected_PackageSameVersionAsPackageIntalledInProject_ReturnsFalse()
145		{
146			CreateFakeSolution();
147			CreateSelectedProjects();
148			
149			var oldPackage = new FakePackage("Test", "1.0");
150			var newPackage = new FakePackage("Test", "1.0");
151			
152			var project = new FakePackageManagementProject();
153			project.FakePackages.Add(newPackage);
154			
155			bool selected = selectedProjects.CallIsProjectSelected(project, oldPackage);
156			
157			Assert.IsFalse(selected);
158		}
159		
160		[Test]
161		public void IsProjectEnabled_PackageNewerThanPackageIntalledInProject_ReturnsTrue()
162		{
163			CreateFakeSolution();
164			CreateSelectedProjects();
165			
166			var oldPackage = new FakePackage("Test", "1.0");
167			var newPackage = new FakePackage("Test", "1.3");
168			
169			var project = new FakePackageManagementProject();
170			project.FakePackages.Add(oldPackage);
171			
172			bool enabled = selectedProjects.CallIsProjectEnabled(project, newPackage);
173			
174			Assert.IsTrue(enabled);
175		}
176		
177		[Test]
178		public void IsProjectEnabled_PackageIdNotInstalledInProject_ReturnsFalse()
179		{
180			CreateFakeSolution();
181			CreateSelectedProjects();
182			
183			var oldPackage = new FakePackage("Foo", "1.0");
184			var newPackage = new FakePackage("Bar", "1.3");
185			
186			var project = new FakePackageManagementProject();
187			project.FakePackages.Add(oldPackage);
188			
189			bool enabled = selectedProjects.CallIsProjectEnabled(project, newPackage);
190			
191			Assert.IsFalse(enabled);
192		}
193		
194		[Test]
195		public void IsProjectEnabled_PackageNewerThanPackageIntalledInProjectButPackageIdsDifferInCase_ReturnsTrue()
196		{
197			CreateFakeSolution();
198			CreateSelectedProjects();
199			
200			var oldPackage = new FakePackage("test", "1.0");
201			var newPackage = new FakePackage("TEST", "1.3");
202			
203			var project = new FakePackageManagementProject();
204			project.FakePackages.Add(oldPackage);
205			
206			bool enabled = selectedProjects.CallIsProjectEnabled(project, newPackage);
207			
208			Assert.IsTrue(enabled);
209		}
210	}
211}