PageRenderTime 22ms CodeModel.GetById 16ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/ajadex/SharpDevelop
C# | 116 lines | 79 code | 20 blank | 17 comment | 0 complexity | 26922ed104ef005803756a7bd59a90eb 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 SelectedProjectsForInstalledPackagesTests
 33	{
 34		SelectedProjectsForInstalledPackages selectedProjects;
 35		FakePackageManagementSolution fakeSolution;
 36
 37		void CreateFakeSolution()
 38		{
 39			fakeSolution = new FakePackageManagementSolution();
 40		}
 41		
 42		void CreateSelectedProjects()
 43		{
 44			selectedProjects = new SelectedProjectsForInstalledPackages(fakeSolution);
 45		}
 46		
 47		List<IProject> AddSolutionWithTwoProjectsToProjectService()
 48		{
 49			ISolution solution = ProjectHelper.CreateSolution();
 50			TestableProject project1 = ProjectHelper.CreateTestProject(solution, "Test1");
 51			TestableProject project2 = ProjectHelper.CreateTestProject(solution, "Test2");
 52			
 53			fakeSolution.FakeMSBuildProjects.Add(project1);
 54			fakeSolution.FakeMSBuildProjects.Add(project2);
 55			
 56			return fakeSolution.FakeMSBuildProjects;
 57		}
 58		
 59		[Test]
 60		public void GetProjects_SolutionHasTwoProjectsAndOneProjectSelectedInProjectsBrowserAndPackageIsInstalledInProject_ReturnsProjectAndIsSelectedIsTrue()
 61		{
 62			CreateFakeSolution();
 63			List<IProject> projectsAddedToSolution = AddSolutionWithTwoProjectsToProjectService();
 64			projectsAddedToSolution[0].Name = "Aaa";
 65			IProject msbuildProject = projectsAddedToSolution[1];
 66			msbuildProject.Name = "MyProject";
 67			fakeSolution.FakeActiveMSBuildProject = msbuildProject;
 68			
 69			var fakePackage = new FakePackage();
 70			var fakeProject = fakeSolution.AddFakeProjectToReturnFromGetProject("MyProject");
 71			fakeProject.FakePackages.Add(fakePackage);
 72			fakeSolution.AddFakeProjectToReturnFromGetProject("Aaa");
 73
 74			CreateSelectedProjects();
 75			
 76			List<IPackageManagementSelectedProject> projects =
 77				selectedProjects.GetProjects(fakePackage).ToList();
 78			
 79			var expectedProject = new FakeSelectedProject("MyProject", selected: true);
 80			var expectedProjects = new List<IPackageManagementSelectedProject>();
 81			expectedProjects.Add(expectedProject);
 82			
 83			SelectedProjectCollectionAssert.AreEqual(expectedProjects, projects);
 84			Assert.AreEqual(fakePackage.FakePackageRepository, fakeSolution.RepositoryPassedToGetProject);
 85			Assert.AreEqual(msbuildProject, fakeSolution.ProjectPassedToGetProject);
 86		}
 87		
 88		[Test]
 89		public void GetProjects_SolutionHasTwoProjectsAndNoProjectSelectedInProjectsBrowserAndPackageIsInstalledInFirstProject_ReturnsAllProjectsInSolutionWithIsSelectedIsTrue()
 90		{
 91			CreateFakeSolution();
 92			List<IProject> projectsAddedToSolution = AddSolutionWithTwoProjectsToProjectService();
 93			projectsAddedToSolution[0].Name = "Project A";
 94			projectsAddedToSolution[1].Name = "Project B";
 95			fakeSolution.FakeActiveProject = null;
 96			
 97			var fakePackage = new FakePackage("Test");
 98			var fakeProject = fakeSolution.AddFakeProjectToReturnFromGetProject("Project A");
 99			fakeProject.FakePackages.Add(fakePackage);
100			fakeSolution.AddFakeProjectToReturnFromGetProject("Project B");
101			
102			CreateSelectedProjects();
103			
104			List<IPackageManagementSelectedProject> projects =
105				selectedProjects.GetProjects(fakePackage).ToList();
106						
107			var expectedProjects = new List<IPackageManagementSelectedProject>();
108			expectedProjects.Add(new FakeSelectedProject("Project A", selected: true));
109			expectedProjects.Add(new FakeSelectedProject("Project B", selected: false));
110			
111			SelectedProjectCollectionAssert.AreEqual(expectedProjects, projects);
112			Assert.AreEqual(fakePackage.FakePackageRepository, fakeSolution.RepositoryPassedToGetProject);
113			Assert.AreEqual(projectsAddedToSolution, fakeSolution.ProjectsPassedToGetProject);
114		}
115	}
116}