PageRenderTime 58ms CodeModel.GetById 16ms app.highlight 34ms RepoModel.GetById 2ms app.codeStats 0ms

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

https://github.com/ajadex/SharpDevelop
C# | 1120 lines | 890 code | 213 blank | 17 comment | 0 complexity | 7e61a29378f6ecbbab3c7cf9c328c5e5 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.Linq;
  21using System.Collections.Generic;
  22using ICSharpCode.Core;
  23using ICSharpCode.PackageManagement;
  24using ICSharpCode.PackageManagement.Design;
  25using ICSharpCode.SharpDevelop.Project;
  26using NuGet;
  27using NUnit.Framework;
  28using Rhino.Mocks;
  29using PackageManagement.Tests.Helpers;
  30using Rhino.Mocks.Expectations;
  31
  32namespace PackageManagement.Tests
  33{
  34	[TestFixture]
  35	public class SharpDevelopPackageManagerTests
  36	{
  37		SharpDevelopPackageManager packageManager;
  38		FakePackageRepository fakeFeedSourceRepository;
  39		FakeSharedPackageRepository fakeSolutionSharedRepository;
  40		IProject testProject;
  41		PackageManagementOptions options;
  42		SolutionPackageRepositoryPath repositoryPaths;
  43		PackageReferenceRepositoryHelper packageRefRepositoryHelper;
  44		TestableProjectManager testableProjectManager;
  45		FakeFileSystem fakeFileSystem;
  46		FakePackageOperationResolverFactory fakePackageOperationResolverFactory;
  47		IPackageOperationResolver fakePackageOperationResolver;
  48		
  49		void CreatePackageManager(IProject project, PackageReferenceRepositoryHelper packageRefRepositoryHelper)
  50		{
  51			options = new TestablePackageManagementOptions();
  52			options.PackagesDirectory = "packages";
  53			
  54			repositoryPaths = new SolutionPackageRepositoryPath(project, options);
  55			var pathResolver = new DefaultPackagePathResolver(repositoryPaths.PackageRepositoryPath);
  56			
  57			fakeFileSystem = new FakeFileSystem();
  58			
  59			fakeFeedSourceRepository = new FakePackageRepository();
  60			fakeSolutionSharedRepository = packageRefRepositoryHelper.FakeSharedSourceRepository;
  61			
  62			fakePackageOperationResolverFactory = new FakePackageOperationResolverFactory();
  63			
  64			var fakeSolutionPackageRepository = new FakeSolutionPackageRepository();
  65			fakeSolutionPackageRepository.FileSystem = fakeFileSystem;
  66			fakeSolutionPackageRepository.PackagePathResolver = pathResolver;
  67			fakeSolutionPackageRepository.FakeSharedRepository = fakeSolutionSharedRepository;
  68			
  69			packageManager = new SharpDevelopPackageManager(fakeFeedSourceRepository,
  70				packageRefRepositoryHelper.FakeProjectSystem,
  71				fakeSolutionPackageRepository,
  72				fakePackageOperationResolverFactory);
  73		}
  74		
  75		void CreatePackageManager()
  76		{
  77			CreateTestProject();
  78			CreatePackageReferenceRepositoryHelper();
  79			CreatePackageManager(testProject, packageRefRepositoryHelper);
  80		}
  81		
  82		void CreatePackageReferenceRepositoryHelper()
  83		{
  84			packageRefRepositoryHelper = new PackageReferenceRepositoryHelper();
  85		}
  86		
  87		void CreateTestProject()
  88		{
  89			testProject = ProjectHelper.CreateTestProject();
  90			testProject.ParentSolution.Stub(s => s.Directory).Return(DirectoryName.Create(@"c:\projects\Test\MyProject"));
  91		}
  92		
  93		void CreateTestableProjectManager()
  94		{
  95			testableProjectManager = new TestableProjectManager();
  96			packageManager.ProjectManager = testableProjectManager;
  97		}
  98		
  99		FakePackage CreateFakePackage(string id = "Test", string version = "1.0.0.0")
 100		{
 101			return new FakePackage(id, version);
 102		}
 103		
 104		FakePackage InstallPackage()
 105		{
 106			FakePackage package = CreateFakePackage();
 107			packageManager.InstallPackage(package);
 108			return package;
 109		}
 110		
 111		FakePackage InstallPackageWithNoPackageOperations()
 112		{
 113			return InstallPackageWithNoPackageOperations(ignoreDependencies: false);
 114		}
 115		
 116		FakePackage InstallPackageWithNoPackageOperationsAndIgnoreDependencies()
 117		{
 118			return InstallPackageWithNoPackageOperations(ignoreDependencies: true);
 119		}
 120		
 121		FakePackage InstallPackageWithNoPackageOperationsAndAllowPrereleaseVersions()
 122		{
 123			return InstallPackageWithNoPackageOperations(ignoreDependencies: false, allowPrereleaseVersions: true);
 124		}
 125		
 126		FakePackage InstallPackageWithNoPackageOperations(bool ignoreDependencies)
 127		{
 128			return InstallPackageWithNoPackageOperations(ignoreDependencies, allowPrereleaseVersions: false);
 129		}
 130		
 131		FakePackage InstallPackageWithNoPackageOperations(bool ignoreDependencies, bool allowPrereleaseVersions)
 132		{
 133			FakePackage package = CreateFakePackage();
 134			var operations = new List<PackageOperation>();
 135			var installAction = new FakeInstallPackageAction();
 136			installAction.IgnoreDependencies = ignoreDependencies;
 137			installAction.AllowPrereleaseVersions = allowPrereleaseVersions;
 138			installAction.Operations = operations;
 139			packageManager.InstallPackage(package, installAction);
 140			return package;
 141		}
 142		
 143		FakePackage InstallPackageWithPackageOperations(PackageOperation operation)
 144		{
 145			var operations = new PackageOperation[] {
 146				operation
 147			};
 148			FakePackage package = CreateFakePackage();
 149			var installAction = new FakeInstallPackageAction();
 150			installAction.Operations = operations;
 151			packageManager.InstallPackage(package, installAction);
 152			return package;
 153		}
 154		
 155		FakePackage InstallPackageAndIgnoreDependencies()
 156		{
 157			return InstallPackageWithParameters(true, false);
 158		}
 159		
 160		FakePackage InstallPackageWithParameters(bool ignoreDependencies, bool allowPrereleaseVersions)
 161		{
 162			FakePackage package = CreateFakePackage();
 163			packageManager.InstallPackage(package, ignoreDependencies, allowPrereleaseVersions);
 164			return package;
 165		}
 166		
 167		FakePackage InstallPackageAndAllowPrereleaseVersions()
 168		{
 169			return InstallPackageWithParameters(false, true);
 170		}
 171		
 172		FakePackage InstallPackageAndDoNotAllowPrereleaseVersions()
 173		{
 174			return InstallPackageWithParameters(false, false);
 175		}
 176		
 177		FakePackage InstallPackageAndDoNotIgnoreDependencies()
 178		{
 179			return InstallPackageWithParameters(false, false);
 180		}
 181		
 182		FakePackage UninstallPackage()
 183		{
 184			FakePackage package = CreateFakePackage();
 185			testableProjectManager.FakeLocalRepository.FakePackages.Add(package);
 186			
 187			packageManager.UninstallPackage(package);
 188			return package;
 189		}
 190
 191		FakePackage UninstallPackageAndForceRemove()
 192		{
 193			FakePackage package = CreateFakePackage();
 194			testableProjectManager.FakeLocalRepository.FakePackages.Add(package);
 195			
 196			bool removeDependencies = false;
 197			bool forceRemove = true;
 198			packageManager.UninstallPackage(package, forceRemove, removeDependencies);
 199			
 200			return package;
 201		}
 202		
 203		FakePackage UninstallPackageAndRemoveDependencies()
 204		{
 205			FakePackage package = CreateFakePackage();
 206			testableProjectManager.FakeLocalRepository.FakePackages.Add(package);
 207			
 208			bool removeDependencies = true;
 209			bool forceRemove = false;
 210			packageManager.UninstallPackage(package, forceRemove, removeDependencies);
 211			
 212			return package;
 213		}
 214		
 215		PackageOperation CreateOneInstallPackageOperation(string id = "PackageToInstall", string version = "1.0")
 216		{
 217			FakePackage package = CreateFakePackage(id, version);
 218			return new PackageOperation(package, PackageAction.Install);
 219		}
 220		
 221		IEnumerable<PackageOperation> GetInstallPackageOperations(FakePackage package)
 222		{
 223			return GetInstallPackageOperations(package, false, false);
 224		}
 225		
 226		IEnumerable<PackageOperation> GetInstallPackageOperationsAndIgnoreDependencies(FakePackage package)
 227		{
 228			return GetInstallPackageOperations(package, true, false);
 229		}
 230		
 231		IEnumerable<PackageOperation> GetInstallPackageOperationsAndAllowPrereleaseVersions(FakePackage package)
 232		{
 233			return GetInstallPackageOperations(package, false, true);
 234		}
 235		
 236		IEnumerable<PackageOperation> GetInstallPackageOperations(
 237			FakePackage package,
 238			bool ignoreDependencies,
 239			bool allowPrereleaseVersions)
 240		{
 241			var fakeInstallAction = new FakeInstallPackageAction();
 242			fakeInstallAction.IgnoreDependencies = ignoreDependencies;
 243			fakeInstallAction.AllowPrereleaseVersions = allowPrereleaseVersions;
 244			return packageManager.GetInstallPackageOperations(package, fakeInstallAction);
 245		}
 246		
 247		FakePackage UpdatePackageWithNoPackageOperations()
 248		{
 249			FakePackage package = CreateFakePackage();
 250			var updateAction = new FakeUpdatePackageAction();
 251			updateAction.Operations = new List<PackageOperation>();
 252			updateAction.UpdateDependencies = true;
 253			packageManager.UpdatePackage(package, updateAction);
 254			return package;
 255		}
 256		
 257		FakePackage UpdatePackageWithPackageOperations(PackageOperation operation)
 258		{
 259			var operations = new PackageOperation[] {
 260				operation
 261			};
 262			FakePackage package = CreateFakePackage();
 263			var updateAction = new FakeUpdatePackageAction();
 264			updateAction.Operations = operations;
 265			updateAction.UpdateDependencies = true;
 266			packageManager.UpdatePackage(package, updateAction);
 267			return package;
 268		}
 269		
 270		FakePackage UpdatePackageWithNoPackageOperationsAndDoNotUpdateDependencies()
 271		{
 272			return UpdatePackageWithNoPackageOperations(false, false);
 273		}
 274		
 275		FakePackage UpdatePackageWithNoPackageOperationsAndAllowPrereleaseVersions()
 276		{
 277			return UpdatePackageWithNoPackageOperations(false, true);
 278		}
 279		
 280		FakePackage UpdatePackageWithNoPackageOperations(bool updateDependencies, bool allowPrereleaseVersions)
 281		{
 282			FakePackage package = CreateFakePackage();
 283			var updateAction = new FakeUpdatePackageAction();
 284			updateAction.Operations = new List<PackageOperation>();
 285			updateAction.UpdateDependencies = updateDependencies;
 286			updateAction.AllowPrereleaseVersions = allowPrereleaseVersions;
 287			packageManager.UpdatePackage(package, updateAction);
 288			return package;
 289		}
 290		
 291		UpdatePackagesAction CreateUpdatePackagesAction()
 292		{
 293			return new UpdatePackagesAction(new FakePackageManagementProject(), null);
 294		}
 295		
 296		UpdatePackagesAction CreateUpdatePackagesActionWithPackages(params IPackageFromRepository[] packages)
 297		{
 298			UpdatePackagesAction action = CreateUpdatePackagesAction();
 299			action.AddPackages(packages);
 300			return action;
 301		}
 302		
 303		UpdatePackagesAction CreateUpdatePackagesActionWithOperations(params PackageOperation[] operations)
 304		{
 305			UpdatePackagesAction action = CreateUpdatePackagesAction();
 306			action.AddOperations(operations);
 307			return action;
 308		}
 309		
 310		PackageOperation AddInstallOperationForPackage(IPackage package)
 311		{
 312			var operation = new PackageOperation(package, PackageAction.Install);
 313			AddInstallOperationsForPackage(package, operation);
 314			return operation;
 315		}
 316		
 317		void AddInstallOperationsForPackage(IPackage package, params PackageOperation[] operations)
 318		{
 319			fakePackageOperationResolver
 320				.Stub(resolver => resolver.ResolveOperations(package))
 321				.Return(operations);
 322		}
 323		
 324		void CreateFakePackageResolverForUpdatePackageOperations()
 325		{
 326			fakePackageOperationResolver = MockRepository.GenerateStub<IPackageOperationResolver>();
 327			fakePackageOperationResolverFactory.UpdatePackageOperationsResolver = fakePackageOperationResolver;
 328		}
 329		
 330		void RaisePackageRemovedEventWhenPackageReferenceUpdated(
 331			ISharpDevelopProjectManager projectManager,
 332			FakePackage updatedPackage,
 333			params PackageOperationEventArgs[] eventArgs)
 334		{
 335			projectManager
 336				.Stub(manager => manager.UpdatePackageReference(
 337					Arg<string>.Is.Equal(updatedPackage.Id),
 338					Arg<SemanticVersion>.Is.Equal(updatedPackage.Version),
 339					Arg<bool>.Is.Anything,
 340					Arg<bool>.Is.Anything))
 341				.WhenCalled(call => eventArgs.ToList().ForEach(eventArg => projectManager.Raise(manager => manager.PackageReferenceRemoved += null, projectManager, eventArg)));
 342		}
 343		
 344		void RaisePackageRemovedEventWhenPackageReferenceAdded(
 345			ISharpDevelopProjectManager projectManager,
 346			FakePackage newPackage,
 347			params PackageOperationEventArgs[] eventArgs)
 348		{
 349			projectManager
 350				.Stub(manager => manager.AddPackageReference(
 351					Arg<string>.Is.Equal(newPackage.Id),
 352					Arg<SemanticVersion>.Is.Equal(newPackage.Version),
 353					Arg<bool>.Is.Anything,
 354					Arg<bool>.Is.Anything))
 355				.WhenCalled(call => eventArgs.ToList().ForEach(eventArg => projectManager.Raise(manager => manager.PackageReferenceRemoved += null, projectManager, eventArg)));
 356		}
 357		
 358		[Test]
 359		public void ProjectManager_InstanceCreated_SourceRepositoryIsSharedRepositoryPassedToPackageManager()
 360		{
 361			CreatePackageManager();
 362			Assert.AreEqual(fakeSolutionSharedRepository, packageManager.ProjectManager.SourceRepository);
 363		}
 364		
 365		[Test]
 366		public void ProjectManager_InstanceCreated_LocalRepositoryIsPackageReferenceRepository()
 367		{
 368			CreatePackageManager();
 369			PackageReferenceRepository packageRefRepository = packageManager.ProjectManager.LocalRepository as PackageReferenceRepository;
 370			Assert.IsNotNull(packageRefRepository);
 371		}
 372		
 373		[Test]
 374		public void ProjectManager_InstanceCreated_LocalRepositoryIsRegisteredWithSharedRepository()
 375		{
 376			CreateTestProject();
 377			CreatePackageReferenceRepositoryHelper();
 378			
 379			string expectedPath = @"c:\projects\Test\MyProject";
 380			packageRefRepositoryHelper.FakeProjectSystem.PathToReturnFromGetFullPath = expectedPath;
 381			
 382			CreatePackageManager(testProject, packageRefRepositoryHelper);
 383			
 384			string actualPath = fakeSolutionSharedRepository.PathPassedToRegisterRepository;
 385			
 386			Assert.AreEqual(expectedPath, actualPath);
 387		}
 388		
 389		[Test]
 390		public void ProjectManager_InstanceCreated_PathResolverIsPackageManagerPathResolver()
 391		{
 392			CreatePackageManager();
 393			
 394			Assert.AreEqual(packageManager.PathResolver, packageManager.ProjectManager.PathResolver);
 395		}
 396		
 397		[Test]
 398		public void InstallPackage_PackageInstancePassed_AddsReferenceToProject()
 399		{
 400			CreatePackageManager();
 401			FakePackage package = InstallPackage();
 402			
 403			Assert.AreEqual(package, testableProjectManager.PackagePassedToAddPackageReference);
 404		}
 405		
 406		[Test]
 407		public void InstallPackage_PackageInstancePassed_DependenciesNotIgnoredWhenAddingReferenceToProject()
 408		{
 409			CreatePackageManager();
 410			CreateTestableProjectManager();
 411			InstallPackage();
 412			
 413			Assert.IsFalse(testableProjectManager.IgnoreDependenciesPassedToAddPackageReference);
 414		}
 415		
 416		[Test]
 417		public void InstallPackage_PackageInstancePassed_PrereleaseVersionsNotAllowedWhenAddingReferenceToProject()
 418		{
 419			CreatePackageManager();
 420			CreateTestableProjectManager();
 421			InstallPackage();
 422			
 423			Assert.IsFalse(testableProjectManager.AllowPrereleaseVersionsPassedToAddPackageReference);
 424		}
 425		
 426		[Test]
 427		public void InstallPackage_PackageInstanceAndPackageOperationsPassed_AddsReferenceToProject()
 428		{
 429			CreatePackageManager();
 430			CreateTestableProjectManager();
 431			FakePackage package = InstallPackageWithNoPackageOperations();
 432				
 433			Assert.AreEqual(package, testableProjectManager.PackagePassedToAddPackageReference);
 434		}
 435		
 436		[Test]
 437		public void InstallPackage_PackageInstanceAndPackageOperationsPassed_DoNotIgnoreDependenciesWhenAddingReferenceToProject()
 438		{
 439			CreatePackageManager();
 440			CreateTestableProjectManager();
 441			InstallPackageWithNoPackageOperations();
 442				
 443			Assert.IsFalse(testableProjectManager.IgnoreDependenciesPassedToAddPackageReference);
 444		}
 445		
 446		[Test]
 447		public void InstallPackage_PackageInstanceAndPackageOperationsPassed_DoNotAllowPrereleaseVersionsWhenAddingReferenceToProject()
 448		{
 449			CreatePackageManager();
 450			CreateTestableProjectManager();
 451			InstallPackageWithNoPackageOperations();
 452				
 453			Assert.IsFalse(testableProjectManager.AllowPrereleaseVersionsPassedToAddPackageReference);
 454		}
 455		
 456		[Test]
 457		public void InstallPackage_PackageInstanceAndPackageOperationsPassedAndIgnoreDependenciesIsTrue_IgnoreDependenciesWhenAddingReferenceToProject()
 458		{
 459			CreatePackageManager();
 460			CreateTestableProjectManager();
 461			InstallPackageWithNoPackageOperationsAndIgnoreDependencies();
 462				
 463			Assert.IsTrue(testableProjectManager.IgnoreDependenciesPassedToAddPackageReference);
 464		}
 465		
 466		[Test]
 467		public void InstallPackage_PackageInstanceAndPackageOperationsPassedAndAllowPrereleaseVersionsIsTrue_PrereleaseVersionsallowedWhenAddingReferenceToProject()
 468		{
 469			CreatePackageManager();
 470			CreateTestableProjectManager();
 471			InstallPackageWithNoPackageOperationsAndAllowPrereleaseVersions();
 472				
 473			Assert.IsTrue(testableProjectManager.AllowPrereleaseVersionsPassedToAddPackageReference);
 474		}
 475		
 476		[Test]
 477		public void InstallPackage_PackageInstanceAndOneInstallPackageOperationPassed_PackageDefinedInOperationIsInstalledInLocalRepository()
 478		{
 479			CreatePackageManager();
 480			CreateTestableProjectManager();
 481			
 482			PackageOperation operation = CreateOneInstallPackageOperation();
 483			InstallPackageWithPackageOperations(operation);
 484			
 485			Assert.AreEqual(operation.Package, fakeSolutionSharedRepository.FirstPackageAdded);
 486		}
 487		
 488		[Test]
 489		public void InstallPackage_PackageDependenciesIgnored_IgnoreDependenciesPassedToProjectManager()
 490		{
 491			CreatePackageManager();
 492			CreateTestableProjectManager();
 493			InstallPackageAndIgnoreDependencies();
 494			
 495			Assert.IsTrue(testableProjectManager.IgnoreDependenciesPassedToAddPackageReference);
 496		}
 497		
 498		[Test]
 499		public void InstallPackage_AllowPrereleaseVersions_AllowPrereleaseVersionsPassedToProjectManager()
 500		{
 501			CreatePackageManager();
 502			CreateTestableProjectManager();
 503			InstallPackageAndAllowPrereleaseVersions();
 504			
 505			Assert.IsTrue(testableProjectManager.AllowPrereleaseVersionsPassedToAddPackageReference);
 506		}
 507		
 508		[Test]
 509		public void InstallPackage_PackageDependenciesIgnored_AddsReferenceToPackage()
 510		{
 511			CreatePackageManager();
 512			CreateTestableProjectManager();
 513			FakePackage package = InstallPackageAndIgnoreDependencies();
 514			
 515			Assert.AreEqual(package, testableProjectManager.PackagePassedToAddPackageReference);
 516		}
 517		
 518		[Test]
 519		public void InstallPackage_PackageDependenciesNotIgnored_IgnoreDependenciesPassedToProjectManager()
 520		{
 521			CreatePackageManager();
 522			CreateTestableProjectManager();
 523			InstallPackageAndDoNotIgnoreDependencies();
 524			
 525			Assert.IsFalse(testableProjectManager.IgnoreDependenciesPassedToAddPackageReference);
 526		}
 527		
 528		[Test]
 529		public void InstallPackage_PackageDependenciesNotIgnored_AddsReferenceToPackage()
 530		{
 531			CreatePackageManager();
 532			CreateTestableProjectManager();
 533			FakePackage package = InstallPackageAndDoNotIgnoreDependencies();
 534			
 535			Assert.AreEqual(package, testableProjectManager.PackagePassedToAddPackageReference);
 536		}
 537		
 538		[Test]
 539		public void UninstallPackage_PackageInProjectLocalRepository_RemovesReferenceFromProject()
 540		{
 541			CreatePackageManager();
 542			CreateTestableProjectManager();
 543			FakePackage package = UninstallPackage();
 544			
 545			Assert.AreEqual(package.Id, testableProjectManager.PackagePassedToRemovePackageReference.Id);
 546		}
 547		
 548		[Test]
 549		public void UninstallPackage_PackageInProjectLocalRepository_DoesNotRemoveReferenceForcefullyFromProject()
 550		{
 551			CreatePackageManager();
 552			CreateTestableProjectManager();
 553			UninstallPackage();
 554			
 555			Assert.IsFalse(testableProjectManager.ForcePassedToRemovePackageReference);
 556		}
 557		
 558		[Test]
 559		public void UninstallPackage_PackageInProjectLocalRepository_DependenciesNotRemovedWhenPackageReferenceRemovedFromProject()
 560		{
 561			CreatePackageManager();
 562			CreateTestableProjectManager();
 563			UninstallPackage();
 564			
 565			Assert.IsFalse(testableProjectManager.RemoveDependenciesPassedToRemovePackageReference);
 566		}
 567		
 568		[Test]
 569		public void UninstallPackage_PassingForceRemove_ReferenceForcefullyRemovedFromProject()
 570		{
 571			CreatePackageManager();
 572			CreateTestableProjectManager();
 573			
 574			UninstallPackageAndForceRemove();
 575			
 576			Assert.IsTrue(testableProjectManager.ForcePassedToRemovePackageReference);
 577		}
 578		
 579		[Test]
 580		public void UninstallPackage_PassingRemoveDependencies_DependenciesRemovedWhenPackageReferenceRemovedFromProject()
 581		{
 582			CreatePackageManager();
 583			CreateTestableProjectManager();
 584			
 585			UninstallPackageAndRemoveDependencies();
 586			
 587			Assert.IsTrue(testableProjectManager.RemoveDependenciesPassedToRemovePackageReference);
 588		}
 589		
 590		[Test]
 591		public void UninstallPackage_ProjectLocalRepositoryHasPackage_PackageRemovedFromProjectRepositoryBeforeSolutionRepository()
 592		{
 593			CreatePackageManager();
 594			CreateTestableProjectManager();
 595			
 596			FakePackage package = CreateFakePackage();
 597			package.Id = "Test";
 598			
 599			testableProjectManager.FakeLocalRepository.FakePackages.Add(package);
 600			
 601			IPackage packageRemovedFromProject = null;
 602			packageManager.PackageUninstalled += (sender, e) => {
 603				packageRemovedFromProject = testableProjectManager.PackagePassedToRemovePackageReference;
 604			};
 605			packageManager.UninstallPackage(package);
 606			
 607			Assert.AreEqual("Test", packageRemovedFromProject.Id);
 608		}
 609		
 610		[Test]
 611		public void UninstallPackage_PackageReferencedByNoProjects_PackageIsRemovedFromSharedSolutionRepository()
 612		{
 613			CreatePackageManager();
 614			CreateTestableProjectManager();
 615			
 616			FakePackage package = CreateFakePackage();
 617			package.Id = "MyPackageId";
 618			
 619			testableProjectManager.FakeLocalRepository.FakePackages.Add(package);
 620			fakeSolutionSharedRepository.FakePackages.Add(package);
 621
 622			packageManager.UninstallPackage(package);
 623			
 624			bool containsPackage = fakeSolutionSharedRepository.FakePackages.Contains(package);
 625			
 626			Assert.IsFalse(containsPackage);
 627		}
 628		
 629		[Test]
 630		public void UninstallPackage_PackageReferencedByTwoProjects_PackageIsNotRemovedFromSharedSolutionRepository()
 631		{
 632			CreatePackageManager();
 633			CreateTestableProjectManager();
 634			
 635			var package = new FakePackage("MyPackageId", "1.4.5.2");
 636			
 637			testableProjectManager.FakeLocalRepository.FakePackages.Add(package);
 638			fakeSolutionSharedRepository.FakePackages.Add(package);
 639			fakeSolutionSharedRepository.PackageIdsReferences.Add("MyPackageId");
 640
 641			packageManager.UninstallPackage(package);
 642			
 643			bool containsPackage = fakeSolutionSharedRepository.FakePackages.Contains(package);
 644			
 645			Assert.IsTrue(containsPackage);
 646			Assert.AreEqual("MyPackageId", fakeSolutionSharedRepository.PackageIdPassedToIsReferenced);
 647			Assert.AreEqual(package.Version, fakeSolutionSharedRepository.VersionPassedToIsReferenced);
 648		}
 649		
 650		[Test]
 651		public void GetInstallPackageOperations_PackageOperationResolverFactoryUsed_PackageOperationsReturnedFromPackageOperationsResolverCreated()
 652		{
 653			CreatePackageManager();
 654			var package = new FakePackage();
 655			IEnumerable<PackageOperation> operations = GetInstallPackageOperations(package);
 656			
 657			IEnumerable<PackageOperation> expectedOperations = fakePackageOperationResolverFactory.FakeInstallPackageOperationResolver.PackageOperations;
 658			
 659			Assert.AreEqual(expectedOperations, operations);
 660		}
 661		
 662		[Test]
 663		public void GetInstallPackageOperations_PackageOperationResolverFactoryUsed_PackageManagerUsesLocalRepositoryWhenGettingPackageOperations()
 664		{
 665			CreatePackageManager();
 666			var package = new FakePackage();
 667			GetInstallPackageOperations(package);
 668			
 669			IPackageRepository expectedRepository = packageManager.LocalRepository;
 670			IPackageRepository actualRepository = fakePackageOperationResolverFactory.LocalRepositoryPassedToCreateInstallPackageOperationsResolver;
 671			
 672			Assert.AreEqual(expectedRepository, actualRepository);
 673		}
 674		
 675		[Test]
 676		public void GetInstallPackageOperations_PackageOperationResolverFactoryUsed_PackageManagerUsesSourceRepositoryWhenGettingPackageOperations()
 677		{
 678			CreatePackageManager();
 679			var package = new FakePackage();
 680			GetInstallPackageOperations(package);
 681			
 682			IPackageRepository expectedRepository = packageManager.SourceRepository;
 683			IPackageRepository actualRepository = fakePackageOperationResolverFactory.SourceRepositoryPassedToCreateInstallPackageOperationsResolver;
 684			
 685			Assert.AreEqual(expectedRepository, actualRepository);
 686		}
 687		
 688		[Test]
 689		public void GetInstallPackageOperations_PackageOperationResolverFactoryUsed_DependenciesNotIgnored()
 690		{
 691			CreatePackageManager();
 692			var package = new FakePackage();
 693			GetInstallPackageOperations(package);
 694			
 695			bool result = fakePackageOperationResolverFactory.IgnoreDependenciesPassedToCreateInstallPackageOperationResolver;
 696			
 697			Assert.IsFalse(result);
 698		}
 699		
 700		[Test]
 701		public void GetInstallPackageOperations_PackageOperationResolverFactoryUsed_PackageManagerUsesLoggerWhenGettingPackageOperations()
 702		{
 703			CreatePackageManager();
 704			var package = new FakePackage();
 705			GetInstallPackageOperations(package);
 706			
 707			ILogger expectedLogger = packageManager.Logger;
 708			ILogger actualLogger = fakePackageOperationResolverFactory.LoggerPassedToCreateInstallPackageOperationResolver;
 709			
 710			Assert.AreEqual(expectedLogger, actualLogger);
 711		}
 712		
 713		[Test]
 714		public void GetInstallPackageOperations_PackageOperationResolverFactoryUsed_PackageUsedWhenGettingPackageOperations()
 715		{
 716			CreatePackageManager();
 717			var package = new FakePackage();
 718			GetInstallPackageOperations(package);
 719			
 720			IPackage actualPackage = fakePackageOperationResolverFactory
 721				.FakeInstallPackageOperationResolver
 722				.PackagePassedToResolveOperations;
 723			
 724			Assert.AreEqual(package, actualPackage);
 725		}
 726		
 727		[Test]
 728		public void GetInstallPackageOperations_IgnoreDependenciesIsTrue_PackageOperationResolverIgnoresDependencies()
 729		{
 730			CreatePackageManager();
 731			var package = new FakePackage();
 732			GetInstallPackageOperationsAndIgnoreDependencies(package);
 733			
 734			bool result = fakePackageOperationResolverFactory.IgnoreDependenciesPassedToCreateInstallPackageOperationResolver;
 735			
 736			Assert.IsTrue(result);
 737		}
 738		
 739		[Test]
 740		public void GetInstallPackageOperations_AllowPrereleaseVersionsIsTrue_PackageOperationResolverAllowsPrereleaseVersions()
 741		{
 742			CreatePackageManager();
 743			var package = new FakePackage();
 744			GetInstallPackageOperationsAndAllowPrereleaseVersions(package);
 745			
 746			bool result = fakePackageOperationResolverFactory.AllowPrereleaseVersionsPassedToCreateInstallPackageOperationResolver;
 747			
 748			Assert.IsTrue(result);
 749		}
 750		
 751		[Test]
 752		public void GetInstallPackageOperations_AllowPrereleaseVersionsIsFalse_PackageOperationResolverDoesNotAllowPrereleaseVersions()
 753		{
 754			CreatePackageManager();
 755			var package = new FakePackage();
 756			GetInstallPackageOperations(package);
 757			
 758			bool result = fakePackageOperationResolverFactory.AllowPrereleaseVersionsPassedToCreateInstallPackageOperationResolver;
 759			
 760			Assert.IsFalse(result);
 761		}
 762		
 763		public void UpdatePackage_PackageInstanceAndNoPackageOperationsPassed_UpdatesReferenceInProject()
 764		{
 765			CreatePackageManager();
 766			CreateTestableProjectManager();
 767			FakePackage package = UpdatePackageWithNoPackageOperations();
 768			
 769			Assert.AreEqual(package, testableProjectManager.PackagePassedToUpdatePackageReference);
 770		}
 771		
 772		[Test]
 773		public void UpdatePackage_PackageInstanceAndNoPackageOperationsPassed_UpdatesDependenciesInProject()
 774		{
 775			CreatePackageManager();
 776			CreateTestableProjectManager();
 777			FakePackage package = UpdatePackageWithNoPackageOperations();
 778			
 779			Assert.IsTrue(testableProjectManager.UpdateDependenciesPassedToUpdatePackageReference);
 780		}
 781		
 782		[Test]
 783		public void UpdatePackage_PackageInstanceAndAllowPrereleaseVersionsIsTrue_PrereleaseVersionsAllowedToUpdateProject()
 784		{
 785			CreatePackageManager();
 786			CreateTestableProjectManager();
 787			FakePackage package = UpdatePackageWithNoPackageOperationsAndAllowPrereleaseVersions();
 788			
 789			Assert.IsTrue(testableProjectManager.AllowPrereleaseVersionsPassedToUpdatePackageReference);
 790		}
 791		
 792		[Test]
 793		public void UpdatePackage_PackageInstanceAndAllowPrereleaseVersionsIsFalse_PrereleaseVersionsNotAllowedToUpdateProject()
 794		{
 795			CreatePackageManager();
 796			CreateTestableProjectManager();
 797			FakePackage package = UpdatePackageWithNoPackageOperations();
 798			
 799			Assert.IsFalse(testableProjectManager.AllowPrereleaseVersionsPassedToUpdatePackageReference);
 800		}
 801		
 802		[Test]
 803		public void UpdatePackage_PackageInstanceAndOneInstallPackageOperationPassed_PackageDefinedInOperationIsInstalledInLocalRepository()
 804		{
 805			CreatePackageManager();
 806			CreateTestableProjectManager();
 807			
 808			PackageOperation operation = CreateOneInstallPackageOperation();
 809			UpdatePackageWithPackageOperations(operation);
 810			
 811			Assert.AreEqual(operation.Package, fakeSolutionSharedRepository.FirstPackageAdded);
 812		}
 813		
 814		[Test]
 815		public void UpdatePackage_UpdateDependenciesSetToFalse_DependenciesInProjectNotUpdated()
 816		{
 817			CreatePackageManager();
 818			CreateTestableProjectManager();
 819			UpdatePackageWithNoPackageOperationsAndDoNotUpdateDependencies();
 820			
 821			Assert.IsFalse(testableProjectManager.UpdateDependenciesPassedToUpdatePackageReference);
 822		}
 823		
 824		[Test]
 825		public void UpdatePackages_OnePackage_PackageReferencedIsAddedToProject()
 826		{
 827			CreatePackageManager();
 828			CreateTestableProjectManager();
 829			FakePackage package = CreateFakePackage("Test", "1.1");
 830			UpdatePackagesAction action = CreateUpdatePackagesActionWithPackages(package);
 831			
 832			packageManager.UpdatePackages(action);
 833			
 834			Assert.AreEqual(package, testableProjectManager.PackagePassedToUpdatePackageReference);
 835		}
 836		
 837		[Test]
 838		public void UpdatePackages_TwoPackages_PackageReferencedIsAddedToProjectForBothPackages()
 839		{
 840			CreatePackageManager();
 841			CreateTestableProjectManager();
 842			FakePackage package1 = CreateFakePackage("First", "1.1");
 843			FakePackage package2 = CreateFakePackage("Second", "2.0");
 844			var expectedPackages = new FakePackage[] { package1, package2 };
 845			UpdatePackagesAction action = CreateUpdatePackagesActionWithPackages(expectedPackages);
 846			
 847			packageManager.UpdatePackages(action);
 848			
 849			PackageCollectionAssert.AreEqual(expectedPackages, testableProjectManager.PackagesPassedToUpdatePackageReference);
 850		}
 851		
 852		[Test]
 853		public void UpdatePackages_UpdateDependenciesIsTrue_UpdateDependenciesPassedToProjectManager()
 854		{
 855			CreatePackageManager();
 856			CreateTestableProjectManager();
 857			FakePackage package = CreateFakePackage("Test", "1.1");
 858			UpdatePackagesAction action = CreateUpdatePackagesActionWithPackages(package);
 859			action.UpdateDependencies = true;
 860			
 861			packageManager.UpdatePackages(action);
 862			
 863			Assert.IsTrue(testableProjectManager.UpdateDependenciesPassedToUpdatePackageReference);
 864		}
 865		
 866		[Test]
 867		public void UpdatePackages_UpdateDependenciesIsFalse_UpdateDependenciesPassedToProjectManager()
 868		{
 869			CreatePackageManager();
 870			CreateTestableProjectManager();
 871			FakePackage package = CreateFakePackage("Test", "1.1");
 872			UpdatePackagesAction action = CreateUpdatePackagesActionWithPackages(package);
 873			action.UpdateDependencies = false;
 874			
 875			packageManager.UpdatePackages(action);
 876			
 877			Assert.IsFalse(testableProjectManager.UpdateDependenciesPassedToUpdatePackageReference);
 878		}
 879		
 880		[Test]
 881		public void UpdatePackages_AllowPrereleaseVersionsIsTrue_AllowPrereleaseVersionsPassedToProjectManager()
 882		{
 883			CreatePackageManager();
 884			CreateTestableProjectManager();
 885			FakePackage package = CreateFakePackage("Test", "1.1");
 886			UpdatePackagesAction action = CreateUpdatePackagesActionWithPackages(package);
 887			action.AllowPrereleaseVersions = true;
 888			
 889			packageManager.UpdatePackages(action);
 890			
 891			Assert.IsTrue(testableProjectManager.AllowPrereleaseVersionsPassedToUpdatePackageReference);
 892		}
 893		
 894		[Test]
 895		public void UpdatePackages_AllowPrereleaseVersionsIsFalse_AllowPrereleaseVersionsPassedToProjectManager()
 896		{
 897			CreatePackageManager();
 898			CreateTestableProjectManager();
 899			FakePackage package = CreateFakePackage("Test", "1.1");
 900			UpdatePackagesAction action = CreateUpdatePackagesActionWithPackages(package);
 901			action.AllowPrereleaseVersions = false;
 902			
 903			packageManager.UpdatePackages(action);
 904			
 905			Assert.IsFalse(testableProjectManager.AllowPrereleaseVersionsPassedToUpdatePackageReference);
 906		}
 907		
 908		[Test]
 909		public void UpdatePackages_TwoPackageOperations_BothPackagesInOperationsAddedToSharedRepository()
 910		{
 911			CreatePackageManager();
 912			CreateTestableProjectManager();
 913			PackageOperation operation1 = CreateOneInstallPackageOperation("First", "1.0");
 914			PackageOperation operation2 = CreateOneInstallPackageOperation("Second", "1.0");
 915			UpdatePackagesAction action = CreateUpdatePackagesActionWithOperations(operation1, operation2);
 916			var expectedPackages = new FakePackage[] {
 917				operation1.Package as FakePackage,
 918				operation2.Package as FakePackage
 919			};
 920			
 921			packageManager.UpdatePackages(action);
 922			
 923			PackageCollectionAssert.AreEqual(expectedPackages, fakeSolutionSharedRepository.PackagesAdded);
 924		}
 925		
 926		[Test]
 927		public void GetUpdatePackageOperations_PackageOperationResolverFactoryUsed_PackageManagerUsesLoggerWhenGettingPackageOperations()
 928		{
 929			CreatePackageManager();
 930			FakePackage package = CreateFakePackage("Test", "1.1");
 931			UpdatePackagesAction updateAction = CreateUpdatePackagesActionWithPackages(package);
 932			
 933			packageManager.GetUpdatePackageOperations(updateAction.Packages, updateAction);
 934			
 935			ILogger expectedLogger = packageManager.Logger;
 936			ILogger actualLogger = fakePackageOperationResolverFactory.LoggerPassedToCreateUpdatePackageOperationResolver;
 937			Assert.AreEqual(expectedLogger, actualLogger);
 938		}
 939		
 940		[Test]
 941		public void GetUpdatePackageOperations_PackageOperationResolverFactoryUsed_PackageManagerUsesLocalRepositoryWhenGettingPackageOperations()
 942		{
 943			CreatePackageManager();
 944			FakePackage package = CreateFakePackage("Test", "1.1");
 945			UpdatePackagesAction updateAction = CreateUpdatePackagesActionWithPackages(package);
 946			
 947			packageManager.GetUpdatePackageOperations(updateAction.Packages, updateAction);
 948			
 949			IPackageRepository expectedRepository = packageManager.LocalRepository;
 950			IPackageRepository actualRepository = fakePackageOperationResolverFactory.LocalRepositoryPassedToCreateUpdatePackageOperationsResolver;
 951			Assert.AreEqual(expectedRepository, actualRepository);
 952		}
 953		
 954		[Test]
 955		public void GetUpdatePackageOperations_PackageOperationResolverFactoryUsed_PackageManagerUsesSourceRepositoryWhenGettingPackageOperations()
 956		{
 957			CreatePackageManager();
 958			FakePackage package = CreateFakePackage("Test", "1.1");
 959			UpdatePackagesAction updateAction = CreateUpdatePackagesActionWithPackages(package);
 960			
 961			packageManager.GetUpdatePackageOperations(updateAction.Packages, updateAction);
 962			
 963			IPackageRepository expectedRepository = packageManager.SourceRepository;
 964			IPackageRepository actualRepository = fakePackageOperationResolverFactory.SourceRepositoryPassedToCreateUpdatePackageOperationsResolver;
 965			Assert.AreEqual(expectedRepository, actualRepository);
 966		}
 967		
 968		[Test]
 969		public void GetUpdatePackageOperations_PackageOperationResolverFactoryUsed_PackageManagerUsesUpdatePackageSettingsWhenGettingPackageOperations()
 970		{
 971			CreatePackageManager();
 972			FakePackage package = CreateFakePackage("Test", "1.1");
 973			UpdatePackagesAction updateAction = CreateUpdatePackagesActionWithPackages(package);
 974			
 975			packageManager.GetUpdatePackageOperations(updateAction.Packages, updateAction);
 976			
 977			IUpdatePackageSettings settings = fakePackageOperationResolverFactory.SettingsPassedToCreatePackageOperationResolver;
 978			Assert.AreEqual(updateAction, settings);
 979		}
 980		
 981		[Test]
 982		public void GetUpdatePackageOperations_TwoPackages_ReturnsPackageOperationsForBothPackages()
 983		{
 984			CreatePackageManager();
 985			CreateFakePackageResolverForUpdatePackageOperations();
 986			IPackageFromRepository package1 = CreateFakePackage("Test", "1.0");
 987			IPackageFromRepository package2 = CreateFakePackage("Test2", "1.0");
 988			PackageOperation operation1 = AddInstallOperationForPackage(package1);
 989			PackageOperation operation2 = AddInstallOperationForPackage(package2);
 990			UpdatePackagesAction updateAction = CreateUpdatePackagesActionWithPackages(package1, package2);
 991			
 992			List<PackageOperation> operations = packageManager.GetUpdatePackageOperations(updateAction.Packages, updateAction).ToList();
 993			
 994			Assert.AreEqual(2, operations.Count());
 995			Assert.Contains(operation1, operations);
 996			Assert.Contains(operation2, operations);
 997		}
 998		
 999		[Test]
1000		public void RunPackageOperations_TwoPackageOperations_BothPackagesInOperationsAddedToSharedRepository()
1001		{
1002			CreatePackageManager();
1003			CreateTestableProjectManager();
1004			PackageOperation operation1 = CreateOneInstallPackageOperation("First", "1.0");
1005			PackageOperation operation2 = CreateOneInstallPackageOperation("Second", "1.0");
1006			var operations = new PackageOperation[] { operation1, operation2 };
1007			var expectedPackages = new FakePackage[] {
1008				operation1.Package as FakePackage,
1009				operation2.Package as FakePackage
1010			};
1011			
1012			packageManager.RunPackageOperations(operations);
1013			
1014			PackageCollectionAssert.AreEqual(expectedPackages, fakeSolutionSharedRepository.PackagesAdded);
1015		}
1016		
1017		[Test]
1018		public void UpdatePackage_OldPackageReferenceIsRemovedOnUpdating_OldPackageIsUninstalled()
1019		{
1020			CreatePackageManager();
1021			var fakeProjectManager = MockRepository.GenerateStub<ISharpDevelopProjectManager>();
1022			packageManager.ProjectManager = fakeProjectManager;
1023			FakePackage installedPackage = fakeSolutionSharedRepository.AddFakePackageWithVersion("MyPackage", "1.0");
1024			FakePackage updatedPackage = fakeFeedSourceRepository.AddFakePackageWithVersion("MyPackage", "1.1");
1025			var eventArgs = new PackageOperationEventArgs(installedPackage, null, null);
1026			RaisePackageRemovedEventWhenPackageReferenceUpdated(fakeProjectManager, updatedPackage, eventArgs);
1027			var updateAction = new FakeUpdatePackageAction {
1028				Operations = new List<PackageOperation>(),
1029				UpdateDependencies = false
1030			};
1031			
1032			packageManager.UpdatePackage(updatedPackage, updateAction);
1033			
1034			Assert.IsFalse(fakeSolutionSharedRepository.FakePackages.Contains(installedPackage));
1035		}
1036		
1037		[Test]
1038		public void UpdatePackage_TwoOldPackageReferencesAreRemovedOnUpdating_BothOldPackagesAreUninstalled()
1039		{
1040			CreatePackageManager();
1041			var fakeProjectManager = MockRepository.GenerateStub<ISharpDevelopProjectManager>();
1042			packageManager.ProjectManager = fakeProjectManager;
1043			FakePackage installedPackage1 = fakeSolutionSharedRepository.AddFakePackageWithVersion("MyPackage-Core", "1.0");
1044			FakePackage installedPackage2 = fakeSolutionSharedRepository.AddFakePackageWithVersion("MyPackage", "1.0");
1045			FakePackage updatedPackage = fakeFeedSourceRepository.AddFakePackageWithVersion("MyPackage", "1.1");
1046			var eventArgs1 = new PackageOperationEventArgs(installedPackage1, null, null);
1047			var eventArgs2 = new PackageOperationEventArgs(installedPackage2, null, null);
1048			RaisePackageRemovedEventWhenPackageReferenceUpdated(fakeProjectManager, updatedPackage, eventArgs1, eventArgs2);
1049			var updateAction = new FakeUpdatePackageAction {
1050				Operations = new List<PackageOperation>(),
1051				UpdateDependencies = false
1052			};
1053			
1054			packageManager.UpdatePackage(updatedPackage, updateAction);
1055			
1056			Assert.IsFalse(fakeSolutionSharedRepository.FakePackages.Contains(installedPackage2));
1057			Assert.IsFalse(fakeSolutionSharedRepository.FakePackages.Contains(installedPackage1));
1058		}
1059		
1060		[Test]
1061		public void UpdatePackage_OldPackageReferenceIsRemovedOnUpdatingButAnotherProjectStillReferencesThePackage_OldPackageIsNotUninstalled()
1062		{
1063			CreatePackageManager();
1064			var fakeProjectManager = MockRepository.GenerateStub<ISharpDevelopProjectManager>();
1065			packageManager.ProjectManager = fakeProjectManager;
1066			FakePackage installedPackage = fakeSolutionSharedRepository.AddFakePackageWithVersion("MyPackage-Core", "1.0");
1067			FakePackage updatedPackage = fakeFeedSourceRepository.AddFakePackageWithVersion("MyPackage", "1.1");
1068			var eventArgs = new PackageOperationEventArgs(installedPackage, null, null);
1069			RaisePackageRemovedEventWhenPackageReferenceUpdated(fakeProjectManager, updatedPackage, eventArgs);
1070			var updateAction = new FakeUpdatePackageAction {
1071				Operations = new List<PackageOperation>(),
1072				UpdateDependencies = false
1073			};
1074			fakeSolutionSharedRepository.PackageIdsReferences.Add("MyPackage-Core");
1075			
1076			packageManager.UpdatePackage(updatedPackage, updateAction);
1077			
1078			Assert.IsTrue(fakeSolutionSharedRepository.FakePackages.Contains(installedPackage));
1079		}
1080		
1081		[Test]
1082		public void InstallPackage_OldPackageReferenceIsRemovedOnInstalling_OldPackageIsUninstalled()
1083		{
1084			CreatePackageManager();
1085			var fakeProjectManager = MockRepository.GenerateStub<ISharpDevelopProjectManager>();
1086			packageManager.ProjectManager = fakeProjectManager;
1087			FakePackage installedPackage = fakeSolutionSharedRepository.AddFakePackageWithVersion("MyPackage", "1.0");
1088			FakePackage newPackage = fakeFeedSourceRepository.AddFakePackageWithVersion("MyPackage", "1.1");
1089			var eventArgs = new PackageOperationEventArgs(installedPackage, null, null);
1090			RaisePackageRemovedEventWhenPackageReferenceAdded(fakeProjectManager, newPackage, eventArgs);
1091			var installAction = new FakeInstallPackageAction {
1092				Operations = new List<PackageOperation>()
1093			};
1094			
1095			packageManager.InstallPackage(newPackage, installAction);
1096			
1097			Assert.IsFalse(fakeSolutionSharedRepository.FakePackages.Contains(installedPackage));
1098		}
1099		
1100		[Test]
1101		public void InstallPackage_OldPackageReferenceIsRemovedOnInstallingButOtherProjectsReferencesOldPackage_OldPackageIsNotUninstalled()
1102		{
1103			CreatePackageManager();
1104			var fakeProjectManager = MockRepository.GenerateStub<ISharpDevelopProjectManager>();
1105			packageManager.ProjectManager = fakeProjectManager;
1106			FakePackage installedPackage = fakeSolutionSharedRepository.AddFakePackageWithVersion("MyPackage.Core", "1.0");
1107			FakePackage newPackage = fakeFeedSourceRepository.AddFakePackageWithVersion("MyPackage", "1.1");
1108			fakeSolutionSharedRepository.PackageIdsReferences.Add("MyPackage.Core");
1109			var eventArgs = new PackageOperationEventArgs(installedPackage, null, null);
1110			RaisePackageRemovedEventWhenPackageReferenceAdded(fakeProjectManager, newPackage, eventArgs);
1111			var installAction = new FakeInstallPackageAction {
1112				Operations = new List<PackageOperation>()
1113			};
1114			
1115			packageManager.InstallPackage(newPackage, installAction);
1116			
1117			Assert.IsTrue(fakeSolutionSharedRepository.FakePackages.Contains(installedPackage));
1118		}
1119	}
1120}