PageRenderTime 73ms CodeModel.GetById 17ms app.highlight 46ms RepoModel.GetById 1ms app.codeStats 1ms

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

https://github.com/ajadex/SharpDevelop
C# | 1535 lines | 1185 code | 332 blank | 18 comment | 0 complexity | 591648aaf45aad6bfca6331c423b23ad MD5 | raw file

Large files files are truncated, but you can click here to view the full 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;
  28using Rhino.Mocks;
  29
  30namespace PackageManagement.Tests
  31{
  32	[TestFixture]
  33	public class PackageViewModelTests
  34	{
  35		TestablePackageViewModel viewModel;
  36		FakePackage fakePackage;
  37		FakePackageManagementSolution fakeSolution;
  38		FakePackageManagementEvents fakePackageManagementEvents;
  39		ExceptionThrowingPackageManagementSolution exceptionThrowingSolution;
  40		ExceptionThrowingPackageManagementProject exceptionThrowingProject;
  41		FakeUninstallPackageAction fakeUninstallPackageAction;
  42		FakeLogger fakeLogger;
  43		FakePackageActionRunner fakeActionRunner;
  44		List<FakeSelectedProject> fakeSelectedProjects;
  45		IPackageViewModelParent viewModelParent;
  46		
  47		void CreateFakeSolution()
  48		{
  49			fakeSolution = new FakePackageManagementSolution();
  50			fakeSolution.FakeActiveMSBuildProject = ProjectHelper.CreateTestProject();
  51		}
  52		
  53		void CreateViewModel()
  54		{
  55			CreateFakeSolution();
  56			CreateViewModel(fakeSolution);
  57		}
  58		
  59		void CreateViewModelWithExceptionThrowingSolution()
  60		{
  61			exceptionThrowingSolution = new ExceptionThrowingPackageManagementSolution();
  62			exceptionThrowingSolution.FakeActiveMSBuildProject = ProjectHelper.CreateTestProject();
  63			CreateViewModel(exceptionThrowingSolution);
  64		}
  65		
  66		void CreateViewModelWithExceptionThrowingProject()
  67		{
  68			CreateViewModel();
  69			exceptionThrowingProject = new ExceptionThrowingPackageManagementProject();
  70			viewModel.FakeSolution.FakeProjectToReturnFromGetProject = exceptionThrowingProject;
  71		}
  72		
  73		void CreateViewModel(FakePackageManagementSolution solution)
  74		{
  75			viewModelParent = MockRepository.GenerateStub<IPackageViewModelParent>();
  76			viewModel = new TestablePackageViewModel(viewModelParent, solution);
  77			fakePackage = viewModel.FakePackage;
  78			this.fakeSolution = solution;
  79			fakePackageManagementEvents = viewModel.FakePackageManagementEvents;
  80			fakeLogger = viewModel.FakeLogger;
  81			fakeUninstallPackageAction = solution.FakeProjectToReturnFromGetProject.FakeUninstallPackageAction;
  82			fakeActionRunner = viewModel.FakeActionRunner;
  83		}
  84		
  85		void AddProjectToSolution()
  86		{
  87			TestableProject project = ProjectHelper.CreateTestProject();
  88			fakeSolution.FakeMSBuildProjects.Add(project);
  89		}
  90		
  91		void CreateViewModelWithTwoProjectsSelected(string projectName1, string projectName2)
  92		{
  93			CreateFakeSolution();
  94			AddTwoProjectsSelected(projectName1, projectName2);
  95			CreateViewModel(fakeSolution);
  96		}
  97
  98		void AddTwoProjectsSelected(string projectName1, string projectName2)
  99		{			
 100			AddProjectToSolution();
 101			AddProjectToSolution();
 102			fakeSolution.FakeMSBuildProjects[0].Name = projectName1;
 103			fakeSolution.FakeMSBuildProjects[1].Name = projectName2;
 104			fakeSolution.NoProjectsSelected();
 105			
 106			fakeSolution.AddFakeProjectToReturnFromGetProject(projectName1);
 107			fakeSolution.AddFakeProjectToReturnFromGetProject(projectName2);
 108		}
 109		
 110		void SetPackageIdAndVersion(string id, string version)
 111		{
 112			fakePackage.Id = id;
 113			fakePackage.Version = new SemanticVersion(version);
 114		}
 115		
 116		void UserCancelsProjectSelection()
 117		{
 118			fakePackageManagementEvents.OnSelectProjectsReturnValue = false;
 119		}
 120		
 121		void UserAcceptsProjectSelection()
 122		{
 123			fakePackageManagementEvents.OnSelectProjectsReturnValue = true;
 124		}
 125		
 126		List<FakeSelectedProject> CreateTwoFakeSelectedProjects()
 127		{
 128			fakeSelectedProjects = new List<FakeSelectedProject>();
 129			fakeSelectedProjects.Add(new FakeSelectedProject("Project A"));
 130			fakeSelectedProjects.Add(new FakeSelectedProject("Project B"));
 131			return fakeSelectedProjects;
 132		}
 133		
 134		FakePackageOperation AddFakeInstallPackageOperationWithPackageThatRequiresLicenseAcceptance(FakeSelectedProject selectedProject)
 135		{
 136			return AddFakeInstallPackageOperationWithPackage(selectedProject, requireLicenseAcceptance: true);
 137		}
 138		
 139		FakePackageOperation AddFakeInstallPackageOperationWithPackageThatDoesNotRequireLicenseAcceptance(FakeSelectedProject selectedProject)
 140		{
 141			return AddFakeInstallPackageOperationWithPackage(selectedProject, requireLicenseAcceptance: false);
 142		}
 143		
 144		FakePackageOperation AddFakeInstallPackageOperationWithPackage(FakeSelectedProject selectedProject, bool requireLicenseAcceptance)
 145		{
 146			FakePackageOperation operation = selectedProject.AddFakeInstallPackageOperation();
 147			operation.FakePackage.RequireLicenseAcceptance = requireLicenseAcceptance;
 148			return operation;
 149		}
 150		
 151		FakePackageOperation AddFakeUninstallPackageOperationWithPackageThatRequiresLicenseAcceptance(FakeSelectedProject selectedProject)
 152		{
 153			FakePackageOperation uninstallOperation = selectedProject.AddFakeUninstallPackageOperation();
 154			uninstallOperation.FakePackage.RequireLicenseAcceptance = true;
 155			return uninstallOperation;
 156		}
 157		
 158		FakeSelectedProject FirstFakeSelectedProject {
 159			get { return fakeSelectedProjects[0]; }
 160		}
 161		
 162		FakeSelectedProject SecondFakeSelectedProject {
 163			get { return fakeSelectedProjects[1]; }
 164		}
 165		
 166		void ParentAllowsPrereleasePackages()
 167		{
 168			viewModelParent.Stub(parent => parent.IncludePrerelease).Return(true);
 169		}
 170		
 171		[Test]
 172		public void AddPackageCommand_CommandExecuted_InstallsPackage()
 173		{
 174			CreateViewModel();
 175			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 176			
 177			viewModel.AddPackageCommand.Execute(null);
 178			
 179			IPackage package = fakeSolution.FakeProjectToReturnFromGetProject.LastInstallPackageCreated.Package;
 180			Assert.AreEqual(fakePackage, package);
 181		}
 182		
 183		[Test]
 184		public void AddPackage_PackageAddedSuccessfully_SourcePackageRepositoryUsedToCreateProject()
 185		{
 186			CreateViewModel();
 187			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 188			
 189			viewModel.AddPackage();
 190						
 191			Assert.AreEqual(fakePackage.Repository, fakeSolution.RepositoryPassedToGetProject);
 192		}
 193		
 194		[Test]
 195		public void AddPackage_PackageAddedSuccessfully_PackageIsInstalled()
 196		{
 197			CreateViewModel();
 198			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 199			
 200			viewModel.AddPackage();
 201			
 202			IPackageAction actionExecuted = fakeActionRunner.ActionPassedToRun;
 203			IPackageAction action = fakeSolution.FakeProjectToReturnFromGetProject.LastInstallPackageCreated;
 204			Assert.AreEqual(action, actionExecuted);
 205		}
 206		
 207		[Test]
 208		public void AddPackage_PackageAddedSuccessfully_PackageOperationsUsedWhenInstallingPackage()
 209		{
 210			CreateViewModel();
 211			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 212			viewModel.AddPackage();
 213		
 214			PackageOperation[] expectedOperations = new PackageOperation[] {
 215				new PackageOperation(fakePackage, PackageAction.Install)
 216			};
 217			
 218			FakeInstallPackageAction action = fakeSolution.FakeProjectToReturnFromGetProject.LastInstallPackageCreated;
 219			CollectionAssert.AreEqual(expectedOperations, action.Operations);
 220		}
 221		
 222		[Test]
 223		public void PackageChanged_PackageAddedSuccessfully_PropertyNotifyChangedFiredForIsAddedProperty()
 224		{
 225			CreateViewModel();
 226			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 227			string propertyChangedName = null;
 228			viewModel.PropertyChanged += (sender, e) => propertyChangedName = e.PropertyName;
 229			viewModel.AddPackage();
 230		
 231			viewModel.PackageChanged();
 232			
 233			Assert.AreEqual("IsAdded", propertyChangedName);
 234		}
 235
 236		[Test]
 237		public void PackageChanged_PackageAddedSuccessfully_PropertyNotifyChangedFiredAfterPackageInstalled()
 238		{
 239			CreateViewModel();
 240			IPackage packagePassedToInstallPackageWhenPropertyNameChanged = null;
 241			viewModel.PropertyChanged += (sender, e) => {
 242				packagePassedToInstallPackageWhenPropertyNameChanged = 
 243					fakeSolution.FakeProjectToReturnFromGetProject.LastInstallPackageCreated.Package;
 244			};
 245			viewModel.AddPackage();
 246			
 247			viewModel.PackageChanged();
 248			
 249			Assert.AreEqual(fakePackage, packagePassedToInstallPackageWhenPropertyNameChanged);
 250		}
 251
 252		[Test]
 253		public void HasLicenseUrl_PackageHasLicenseUrl_ReturnsTrue()
 254		{
 255			CreateViewModel();
 256			fakePackage.LicenseUrl = new Uri("http://sharpdevelop.com");
 257			
 258			Assert.IsTrue(viewModel.HasLicenseUrl);
 259		}
 260		
 261		[Test]
 262		public void HasLicenseUrl_PackageHasNoLicenseUrl_ReturnsFalse()
 263		{
 264			CreateViewModel();
 265			fakePackage.LicenseUrl = null;
 266			
 267			Assert.IsFalse(viewModel.HasLicenseUrl);
 268		}
 269		
 270		[Test]
 271		public void HasProjectUrl_PackageHasProjectUrl_ReturnsTrue()
 272		{
 273			CreateViewModel();
 274			fakePackage.ProjectUrl = new Uri("http://sharpdevelop.com");
 275			
 276			Assert.IsTrue(viewModel.HasProjectUrl);
 277		}
 278		
 279		[Test]
 280		public void HasProjectUrl_PackageHasNoProjectUrl_ReturnsFalse()
 281		{
 282			CreateViewModel();
 283			fakePackage.ProjectUrl = null;
 284			
 285			Assert.IsFalse(viewModel.HasProjectUrl);
 286		}
 287		
 288		[Test]
 289		public void HasReportAbuseUrl_PackageHasReportAbuseUrl_ReturnsTrue()
 290		{
 291			CreateViewModel();
 292			fakePackage.ReportAbuseUrl = new Uri("http://sharpdevelop.com");
 293			
 294			Assert.IsTrue(viewModel.HasReportAbuseUrl);
 295		}
 296		
 297		[Test]
 298		public void HasReportAbuseUrl_PackageHasNoReportAbuseUrl_ReturnsFalse()
 299		{
 300			CreateViewModel();
 301			fakePackage.ReportAbuseUrl = null;
 302			
 303			Assert.IsFalse(viewModel.HasReportAbuseUrl);
 304		}
 305		
 306		[Test]
 307		public void IsAdded_ProjectHasPackageAdded_ReturnsTrue()
 308		{
 309			CreateViewModel();
 310			fakeSolution.FakeProjectToReturnFromGetProject.FakePackages.Add(fakePackage);
 311			
 312			Assert.IsTrue(viewModel.IsAdded);
 313		}
 314		
 315		[Test]
 316		public void IsAdded_ProjectDoesNotHavePackageInstalled_ReturnsFalse()
 317		{
 318			CreateViewModel();
 319			fakeSolution.FakeProjectToReturnFromGetProject.FakePackages.Clear();
 320			
 321			Assert.IsFalse(viewModel.IsAdded);
 322		}
 323		
 324		[Test]
 325		public void RemovePackageCommand_CommandExecuted_UninstallsPackage()
 326		{
 327			CreateViewModel();
 328			viewModel.RemovePackageCommand.Execute(null);
 329						
 330			Assert.AreEqual(fakePackage, fakeUninstallPackageAction.Package);
 331		}
 332		
 333		[Test]
 334		public void RemovePackage_PackageRemovedSuccessfully_RepositoryUsedToCreateProject()
 335		{
 336			CreateViewModel();
 337			viewModel.RemovePackage();
 338			
 339			Assert.AreEqual(fakePackage.Repository, fakeSolution.RepositoryPassedToGetProject);
 340		}
 341		
 342		[Test]
 343		public void PackageChanged_PackageRemovedSuccessfully_PropertyNotifyChangedFiredForIsAddedProperty()
 344		{
 345			CreateViewModel();
 346			string propertyChangedName = null;
 347			viewModel.PropertyChanged += (sender, e) => propertyChangedName = e.PropertyName;
 348			viewModel.RemovePackage();
 349			
 350			viewModel.PackageChanged();
 351			
 352			Assert.AreEqual("IsAdded", propertyChangedName);
 353		}
 354		
 355		[Test]
 356		public void PackageChanged_PackageRemovedSuccessfully_PropertyNotifyChangedFiredAfterPackageUninstalled()
 357		{
 358			CreateViewModel();
 359			IPackage packagePassedToUninstallPackageWhenPropertyNameChanged = null;
 360			viewModel.PropertyChanged += (sender, e) => {
 361				packagePassedToUninstallPackageWhenPropertyNameChanged = fakeUninstallPackageAction.Package;
 362			};
 363			viewModel.RemovePackage();
 364			
 365			viewModel.PackageChanged();
 366			
 367			Assert.AreEqual(fakePackage, packagePassedToUninstallPackageWhenPropertyNameChanged);
 368		}
 369		
 370		[Test]
 371		public void HasDependencies_PackageHasNoDependencies_ReturnsFalse()
 372		{
 373			CreateViewModel();
 374			fakePackage.HasDependencies = false;
 375			
 376			Assert.IsFalse(viewModel.HasDependencies);
 377		}
 378		
 379		[Test]
 380		public void HasDependencies_PackageHasDependency_ReturnsTrue()
 381		{
 382			CreateViewModel();
 383			fakePackage.HasDependencies = true;
 384			
 385			Assert.IsTrue(viewModel.HasDependencies);
 386		}
 387		
 388		[Test]
 389		public void HasNoDependencies_PackageHasNoDependencies_ReturnsTrue()
 390		{
 391			CreateViewModel();
 392			fakePackage.HasDependencies = false;
 393			
 394			Assert.IsTrue(viewModel.HasNoDependencies);
 395		}
 396		
 397		[Test]
 398		public void HasNoDependencies_PackageHasOneDependency_ReturnsFalse()
 399		{
 400			CreateViewModel();
 401			fakePackage.HasDependencies = true;
 402			
 403			Assert.IsFalse(viewModel.HasNoDependencies);
 404		}
 405		
 406		[Test]
 407		public void HasDownloadCount_DownloadCountIsZero_ReturnsTrue()
 408		{
 409			CreateViewModel();
 410			fakePackage.DownloadCount = 0;
 411			
 412			Assert.IsTrue(viewModel.HasDownloadCount);
 413		}
 414		
 415		[Test]
 416		public void HasDownloadCount_DownloadCountIsMinusOne_ReturnsFalse()
 417		{
 418			CreateViewModel();
 419			fakePackage.DownloadCount = -1;
 420			
 421			Assert.IsFalse(viewModel.HasDownloadCount);
 422		}
 423		
 424		[Test]
 425		public void HasLastPublished_PackageHasPublishedDate_ReturnsTrue()
 426		{
 427			CreateViewModel();
 428			fakePackage.Published = new DateTime(2011, 1, 2);
 429			
 430			Assert.IsTrue(viewModel.HasLastPublished);
 431		}
 432		
 433		[Test]
 434		public void HasLastPublished_PackageHasNoPublishedDate_ReturnsFalse()
 435		{
 436			CreateViewModel();
 437			fakePackage.Published = null;
 438			
 439			Assert.IsFalse(viewModel.HasLastPublished);
 440		}
 441		
 442		[Test]
 443		public void LastPublished_PackageHasPublishedDate_ReturnsPackagePublishedDate()
 444		{
 445			CreateViewModel();
 446			fakePackage.Published = new DateTime(2011, 1, 2);
 447			
 448			Assert.AreEqual(fakePackage.Published, viewModel.LastPublished);
 449		}
 450		
 451		[Test]
 452		public void LastPublished_PackageHasNoPublishedDate_ReturnsNull()
 453		{
 454			CreateViewModel();
 455			fakePackage.Published = null;
 456			
 457			Assert.IsNull(viewModel.LastPublished);
 458		}
 459		
 460		[Test]
 461		public void AddPackage_PackageRequiresLicenseAgreementAcceptance_UserAskedToAcceptLicenseAgreementForPackageBeforeInstalling()
 462		{
 463			CreateViewModel();
 464			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 465			fakePackage.RequireLicenseAcceptance = true;
 466			fakePackageManagementEvents.OnAcceptLicensesReturnValue = true;
 467			
 468			viewModel.AddPackage();
 469			
 470			var expectedPackages = new FakePackage[] {
 471				fakePackage
 472			};
 473			
 474			IEnumerable<IPackage> actualPackages = fakePackageManagementEvents.LastPackagesPassedToOnAcceptLicenses;
 475			
 476			CollectionAssert.AreEqual(expectedPackages, actualPackages);
 477		}
 478		
 479		[Test]
 480		public void AddPackage_PackageRequiresLicenseAgreementAcceptanceButPackageInstalledInSolutionAlready_UserNotAskedToAcceptLicenseAgreementForPackageBeforeInstalling()
 481		{
 482			CreateViewModel();
 483			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 484			fakePackage.RequireLicenseAcceptance = true;
 485			fakePackageManagementEvents.OnAcceptLicensesReturnValue = true;
 486			fakeSolution.FakeInstalledPackages.Add(fakePackage);
 487			
 488			viewModel.AddPackage();
 489			
 490			bool acceptLicenses = fakePackageManagementEvents.IsOnAcceptLicensesCalled;
 491			
 492			Assert.IsFalse(acceptLicenses);
 493		}
 494		
 495		[Test]
 496		public void AddPackage_PackageDoesNotRequireLicenseAgreementAcceptance_UserNotAskedToAcceptLicenseAgreementBeforeInstalling()
 497		{
 498			CreateViewModel();
 499			fakePackage.RequireLicenseAcceptance = false;
 500			viewModel.AddPackage();
 501			
 502			Assert.IsFalse(fakePackageManagementEvents.IsOnAcceptLicensesCalled);
 503		}
 504		
 505		[Test]
 506		public void AddPackage_PackageRequiresLicenseAgreementAcceptanceAndUserDeclinesAgreement_PackageIsNotInstalled()
 507		{
 508			CreateViewModel();
 509			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 510			fakePackage.RequireLicenseAcceptance = true;
 511			fakePackageManagementEvents.OnAcceptLicensesReturnValue = false;
 512			
 513			viewModel.AddPackage();
 514			
 515			FakeInstallPackageAction action = fakeSolution.FakeProjectToReturnFromGetProject.LastInstallPackageCreated;
 516			Assert.IsFalse(action.IsExecuteCalled);
 517		}
 518		
 519		[Test]
 520		public void AddPackage_PackageRequiresLicenseAgreementAcceptanceAndUserDeclinesAgreement_PropertyChangedEventNotFired()
 521		{
 522			CreateViewModel();
 523			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 524			fakePackage.RequireLicenseAcceptance = true;
 525			fakePackageManagementEvents.OnAcceptLicensesReturnValue = false;
 526			bool propertyChangedEventFired = false;
 527			viewModel.PropertyChanged += (sender, e) => propertyChangedEventFired = true;
 528			
 529			viewModel.AddPackage();
 530			
 531			Assert.IsFalse(propertyChangedEventFired);
 532		}
 533		
 534		[Test]
 535		public void AddPackage_OnePackageOperationIsToUninstallPackageWhichRequiresLicenseAcceptance_UserIsNotAskedToAcceptLicenseAgreementForPackageToBeUninstalled()
 536		{
 537			CreateViewModel();
 538			fakePackage.RequireLicenseAcceptance = false;
 539			PackageOperation operation = viewModel.AddOneFakeUninstallPackageOperation();
 540			FakePackage packageToUninstall = operation.Package as FakePackage;
 541			packageToUninstall.RequireLicenseAcceptance = true;
 542			viewModel.AddPackage();
 543			
 544			Assert.IsFalse(fakePackageManagementEvents.IsOnAcceptLicensesCalled);
 545		}
 546		
 547		[Test]
 548		public void AddPackage_CheckLoggerUsed_PackageViewModelLoggerUsedWhenResolvingPackageOperations()
 549		{
 550			CreateViewModel();
 551			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 552			viewModel.AddPackage();
 553			
 554			ILogger expectedLogger = viewModel.OperationLoggerCreated;
 555			ILogger actualLogger = fakeSolution.FakeProjectToReturnFromGetProject.Logger;
 556			Assert.AreEqual(expectedLogger, actualLogger);
 557		}
 558		
 559		[Test]
 560		public void AddPackage_PackageAddedSuccessfully_InstallingPackageMessageIsFirstMessageLogged()
 561		{
 562			CreateViewModel();
 563			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 564			fakePackage.Id = "Test.Package";
 565			fakePackage.Version = new SemanticVersion(1, 2, 0, 55);
 566			viewModel.AddPackage();
 567			
 568			string expectedMessage = "------- Installing...Test.Package 1.2.0.55 -------";
 569			string actualMessage = fakeLogger.FirstFormattedMessageLogged;
 570			
 571			Assert.AreEqual(expectedMessage, actualMessage);
 572		}
 573		
 574		[Test]
 575		public void AddPackage_PackageAddedSuccessfully_NextToLastMessageLoggedMarksEndOfInstallation()
 576		{
 577			CreateViewModel();
 578			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 579			viewModel.AddPackage();
 580			
 581			string expectedMessage = "==============================";
 582			string actualMessage = fakeLogger.NextToLastFormattedMessageLogged;
 583						
 584			Assert.AreEqual(expectedMessage, actualMessage);
 585		}
 586		
 587		[Test]
 588		public void AddPackage_PackageAddedSuccessfully_LastMessageLoggedIsEmptyLine()
 589		{
 590			CreateViewModel();
 591			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 592			viewModel.AddPackage();
 593			
 594			string expectedMessage = String.Empty;
 595			string actualMessage = fakeLogger.LastFormattedMessageLogged;
 596						
 597			Assert.AreEqual(expectedMessage, actualMessage);
 598		}
 599		
 600		[Test]
 601		public void RemovePackage_PackageRemovedSuccessfully_UninstallingPackageMessageIsFirstMessageLogged()
 602		{
 603			CreateViewModel();
 604			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 605			fakePackage.Id = "Test.Package";
 606			fakePackage.Version = new SemanticVersion(1, 2, 0, 55);
 607			viewModel.RemovePackage();
 608			
 609			string expectedMessage = "------- Uninstalling...Test.Package 1.2.0.55 -------";
 610			string actualMessage = fakeLogger.FirstFormattedMessageLogged;
 611						
 612			Assert.AreEqual(expectedMessage, actualMessage);
 613		}
 614		
 615		[Test]
 616		public void RemovePackage_PackageRemovedSuccessfully_NextToLastMessageLoggedMarksEndOfInstallation()
 617		{
 618			CreateViewModel();
 619			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 620			viewModel.RemovePackage();
 621			
 622			string expectedMessage = "==============================";
 623			string actualMessage = fakeLogger.NextToLastFormattedMessageLogged;
 624						
 625			Assert.AreEqual(expectedMessage, actualMessage);
 626		}
 627		
 628		[Test]
 629		public void RemovePackage_PackageRemovedSuccessfully_LastMessageLoggedIsEmptyLine()
 630		{
 631			CreateViewModel();
 632			viewModel.RemovePackage();
 633			
 634			string expectedMessage = String.Empty;
 635			string actualMessage = fakeLogger.LastFormattedMessageLogged;
 636						
 637			Assert.AreEqual(expectedMessage, actualMessage);
 638		}
 639		
 640		[Test]
 641		public void AddPackage_ExceptionWhenInstallingPackage_ExceptionErrorMessageReported()
 642		{
 643			CreateViewModelWithExceptionThrowingProject();
 644			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 645			Exception ex = new Exception("Test");
 646			exceptionThrowingProject.ExceptionToThrowWhenCreateInstallPackageActionCalled = ex;
 647			viewModel.AddPackage();
 648			
 649			Assert.AreEqual(ex, fakePackageManagementEvents.ExceptionPassedToOnPackageOperationError);
 650		}
 651		
 652		[Test]
 653		public void AddPackage_PackageAddedSuccessfully_MessagesReportedPreviouslyAreCleared()
 654		{
 655			CreateViewModel();
 656			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 657			viewModel.AddPackage();
 658			
 659			Assert.IsTrue(fakePackageManagementEvents.IsOnPackageOperationsStartingCalled);
 660		}
 661		
 662		[Test]
 663		public void AddPackage_ExceptionWhenInstallingPackage_ExceptionLogged()
 664		{
 665			CreateViewModelWithExceptionThrowingProject();
 666			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 667			Exception ex = new Exception("Exception error message");
 668			exceptionThrowingProject.ExceptionToThrowWhenCreateInstallPackageActionCalled = ex;
 669			viewModel.AddPackage();
 670			
 671			string actualMessage = fakeLogger.SecondFormattedMessageLogged;
 672			bool containsExceptionErrorMessage = actualMessage.Contains("Exception error message");
 673			
 674			Assert.IsTrue(containsExceptionErrorMessage, actualMessage);
 675		}
 676		
 677		[Test]
 678		public void RemovePackage_ExceptionWhenUninstallingPackage_ExceptionErrorMessageReported()
 679		{
 680			CreateViewModelWithExceptionThrowingProject();
 681			Exception ex = new Exception("Test");
 682			exceptionThrowingProject.ExceptionToThrowWhenCreateUninstallPackageActionCalled = ex;
 683			viewModel.RemovePackage();
 684			
 685			Assert.AreEqual(ex, fakePackageManagementEvents.ExceptionPassedToOnPackageOperationError);
 686		}
 687		
 688		[Test]
 689		public void RemovePackage_PackageUninstalledSuccessfully_MessagesReportedPreviouslyAreCleared()
 690		{
 691			CreateViewModel();
 692			viewModel.RemovePackage();
 693			
 694			Assert.IsTrue(fakePackageManagementEvents.IsOnPackageOperationsStartingCalled);
 695		}
 696		
 697		[Test]
 698		public void RemovePackage_ExceptionWhenUninstallingPackage_ExceptionLogged()
 699		{
 700			CreateViewModelWithExceptionThrowingProject();
 701			Exception ex = new Exception("Exception error message");
 702			exceptionThrowingProject.ExceptionToThrowWhenCreateUninstallPackageActionCalled = ex;
 703			viewModel.RemovePackage();
 704			
 705			string actualMessage = fakeLogger.SecondFormattedMessageLogged;
 706			bool containsExceptionErrorMessage = actualMessage.Contains("Exception error message");
 707			
 708			Assert.IsTrue(containsExceptionErrorMessage, actualMessage);
 709		}
 710		
 711		[Test]
 712		public void AddPackage_ExceptionThrownWhenResolvingPackageOperations_ExceptionReported()
 713		{
 714			CreateViewModelWithExceptionThrowingSolution();
 715			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 716			
 717			var exception = new Exception("Test");
 718			exceptionThrowingSolution.ExceptionToThrowWhenGetProjectCalled = exception;
 719			viewModel.AddPackage();
 720			
 721			Assert.AreEqual(exception, fakePackageManagementEvents.ExceptionPassedToOnPackageOperationError);
 722		}
 723		
 724		[Test]
 725		public void AddPackage_PackagesInstalledSuccessfully_ViewModelPackageUsedWhenResolvingPackageOperations()
 726		{
 727			CreateViewModel();
 728			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 729			viewModel.AddPackage();
 730			
 731			FakePackage expectedPackage = fakePackage;
 732			IPackage actualPackage = fakeSolution
 733				.FakeProjectToReturnFromGetProject
 734				.PackagePassedToGetInstallPackageOperations;
 735			
 736			Assert.AreEqual(expectedPackage, actualPackage);
 737		}
 738		
 739		[Test]
 740		public void AddPackage_PackagesInstalledSuccessfully_PackageDependenciesNotIgnoredWhenCheckingForPackageOperations()
 741		{
 742			CreateViewModel();
 743			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 744			viewModel.AddPackage();
 745			
 746			bool result = fakeSolution
 747				.FakeProjectToReturnFromGetProject
 748				.IgnoreDependenciesPassedToGetInstallPackageOperations;
 749			
 750			Assert.IsFalse(result);
 751		}
 752		
 753		[Test]
 754		public void AddPackage_PackagesInstalledSuccessfully_PrereleaseVersionsNotAllowedWhenCheckingForPackageOperations()
 755		{
 756			CreateViewModel();
 757			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 758			viewModel.AddPackage();
 759			
 760			bool result = fakeSolution
 761				.FakeProjectToReturnFromGetProject
 762				.AllowPrereleaseVersionsPassedToGetInstallPackageOperations;
 763			
 764			Assert.IsFalse(result);
 765		}
 766		
 767		[Test]
 768		public void AddPackage_ParentHasIncludePrereleaseSetToTrueWhenInstalling_PrereleaseVersionsAllowedWhenCheckingForPackageOperations()
 769		{
 770			CreateViewModel();
 771			ParentAllowsPrereleasePackages();
 772			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 773			viewModel.AddPackage();
 774			
 775			bool result = fakeSolution
 776				.FakeProjectToReturnFromGetProject
 777				.AllowPrereleaseVersionsPassedToGetInstallPackageOperations;
 778			
 779			Assert.IsTrue(result);
 780		}
 781		
 782		[Test]
 783		public void RemovePackage_PackageRemovedSuccessfully_PackageIsRemoved()
 784		{
 785			CreateViewModel();
 786			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
 787			viewModel.RemovePackage();
 788			
 789			IPackageAction actionExecuted = fakeActionRunner.ActionPassedToRun;
 790			
 791			Assert.AreEqual(fakeUninstallPackageAction, actionExecuted);
 792		}
 793		
 794		[Test]
 795		public void IsAdded_SolutionSelectedContainingOneProjectAndPackageIsInstalledInSolutionSharedRepository_ReturnsTrue()
 796		{
 797			CreateFakeSolution();
 798			AddProjectToSolution();
 799			fakeSolution.NoProjectsSelected();
 800			fakeSolution.FakeInstalledPackages.Add(fakePackage);
 801			CreateViewModel(fakeSolution);
 802			
 803			bool added = viewModel.IsAdded;
 804			
 805			Assert.IsTrue(added);
 806		}
 807		
 808		[Test]
 809		public void IsAdded_SolutionSelectedContainingOneProjectAndPackageIsNotInstalledInSolutionSharedRepository_ReturnsFalse()
 810		{
 811			CreateViewModel();
 812			AddProjectToSolution();
 813			fakeSolution.NoProjectsSelected();
 814			
 815			bool added = viewModel.IsAdded;
 816			
 817			Assert.IsFalse(added);
 818		}
 819		
 820		[Test]
 821		public void IsManaged_SolutionSelectedContainingTwoProjects_ReturnsFalsew()
 822		{
 823			CreateFakeSolution();
 824			AddProjectToSolution();
 825			AddProjectToSolution();
 826			fakeSolution.NoProjectsSelected();
 827			CreateViewModel(fakeSolution);
 828			
 829			bool managed = viewModel.IsManaged;
 830			
 831			// Only installed project-level package "IsManaged"
 832			Assert.IsFalse(managed);
 833		}
 834		
 835		[Test]
 836		public void IsManaged_SolutionSelectedContainingOneProject_ReturnsFalse()
 837		{
 838			CreateFakeSolution();
 839			AddProjectToSolution();
 840			fakeSolution.NoProjectsSelected();
 841			CreateViewModel(fakeSolution);
 842			
 843			bool managed = viewModel.IsManaged;
 844			
 845			Assert.IsFalse(managed);
 846		}
 847		
 848		[Test]
 849		public void IsManaged_SolutionWithOneProjectSelected_ReturnsFalse()
 850		{
 851			CreateFakeSolution();
 852			AddProjectToSolution();
 853			fakeSolution.FakeActiveMSBuildProject = fakeSolution.FakeMSBuildProjects[0];
 854			CreateViewModel(fakeSolution);
 855			
 856			bool managed = viewModel.IsManaged;
 857			
 858			Assert.IsFalse(managed);
 859		}
 860		
 861		[Test]
 862		public void ManagePackageCommand_TwoProjectsSelectedAndCommandExecuted_UserPromptedToSelectTwoProjects()
 863		{
 864			CreateViewModelWithTwoProjectsSelected("Project A", "Project B");
 865			UserCancelsProjectSelection();
 866			viewModel.ManagePackageCommand.Execute(null);
 867			
 868			IEnumerable<IPackageManagementSelectedProject> selectedProjects = 
 869				fakePackageManagementEvents.SelectedProjectsPassedToOnSelectProjects;
 870			
 871			var expectedSelectedProjects = new List<IPackageManagementSelectedProject>();
 872			expectedSelectedProjects.Add(new FakeSelectedProject("Project A"));
 873			expectedSelectedProjects.Add(new FakeSelectedProject("Project B"));
 874			
 875			SelectedProjectCollectionAssert.AreEqual(expectedSelectedProjects, selectedProjects);
 876		}
 877		
 878		[Test]
 879		public void ManagePackage_TwoProjectsSelectedAndUserAcceptsSelectedProjects_MessagesReportedPreviouslyAreCleared()
 880		{
 881			CreateViewModelWithTwoProjectsSelected("Project A", "Project B");
 882			UserAcceptsProjectSelection();
 883			
 884			viewModel.ManagePackage();
 885			
 886			Assert.IsTrue(fakePackageManagementEvents.IsOnPackageOperationsStartingCalled);
 887		}
 888		
 889		[Test]
 890		public void ManagePackage_TwoProjectsSelectedAndUserCancelsSelectedProjects_MessagesReportedPreviouslyAreNotCleared()
 891		{
 892			CreateViewModelWithTwoProjectsSelected("Project A", "Project B");
 893			UserCancelsProjectSelection();
 894			
 895			viewModel.ManagePackage();
 896			
 897			Assert.IsFalse(fakePackageManagementEvents.IsOnPackageOperationsStartingCalled);
 898		}
 899		
 900		[Test]
 901		public void PackageChanged_TwoProjectsSelectedAndUserAcceptsSelectedProjects_IsAddedPropertyChanged()
 902		{
 903			CreateViewModelWithTwoProjectsSelected("Project A", "Project B");
 904			viewModel.FakePackageManagementEvents.ProjectsToSelect.Add("Project A");
 905			viewModel.FakePackageManagementEvents.ProjectsToSelect.Add("Project B");
 906			UserAcceptsProjectSelection();
 907			string propertyChangedName = null;
 908			viewModel.PropertyChanged += (sender, e) => propertyChangedName = e.PropertyName;
 909			viewModel.ManagePackage();
 910			
 911			viewModel.PackageChanged();
 912			
 913			Assert.AreEqual("IsAdded", propertyChangedName);
 914		}
 915		
 916		[Test]
 917		public void ManagePackage_TwoProjectsSelectedAndUserAcceptsSelectedProjects_NextToLastMessageLoggedMarksEndOfInstallation()
 918		{
 919			CreateViewModelWithTwoProjectsSelected("Project A", "Project B");
 920			UserAcceptsProjectSelection();
 921			
 922			viewModel.ManagePackage();
 923			
 924			string expectedMessage = "==============================";
 925			string actualMessage = fakeLogger.NextToLastFormattedMessageLogged;
 926						
 927			Assert.AreEqual(expectedMessage, actualMessage);
 928		}
 929		
 930		[Test]
 931		public void ManagePackage_TwoProjectsSelectedAndUserAcceptsSelectedProjects_LastMessageLoggedIsEmptyLine()
 932		{
 933			CreateViewModelWithTwoProjectsSelected("Project A", "Project B");
 934			UserAcceptsProjectSelection();
 935			
 936			viewModel.ManagePackage();
 937			
 938			string expectedMessage = String.Empty;
 939			string actualMessage = fakeLogger.LastFormattedMessageLogged;
 940			
 941			Assert.AreEqual(expectedMessage, actualMessage);
 942		}
 943		
 944		[Test]
 945		public void ManagePackagesForSelectedProjects_OneProjectIsSelected_OneProjectIsInstalled()
 946		{
 947			CreateViewModel();
 948			CreateTwoFakeSelectedProjects();
 949			FakeSelectedProject project = fakeSelectedProjects[1];
 950			project.IsSelected = true;
 951			
 952			viewModel.ManagePackagesForSelectedProjects(fakeSelectedProjects);
 953			
 954			List<IPackageAction> actions = fakeActionRunner.GetActionsRunInOneCallAsList();
 955			InstallPackageAction action = actions[0] as InstallPackageAction;
 956			InstallPackageAction expectedAction = project.FakeProject.LastInstallPackageCreated;
 957			Assert.AreEqual(1, actions.Count);
 958			Assert.AreEqual(fakePackage, action.Package);
 959			Assert.AreEqual(expectedAction, action);
 960		}
 961		
 962		[Test]
 963		public void ManagePackagesForSelectedProjects_ParentAllowsPrereleasePackagesAndOneProjectIsSelected_OneProjectIsInstalledAllowingPrereleasePackages()
 964		{
 965			CreateViewModel();
 966			CreateTwoFakeSelectedProjects();
 967			ParentAllowsPrereleasePackages();
 968			FakeSelectedProject project = fakeSelectedProjects[1];
 969			project.IsSelected = true;
 970			
 971			viewModel.ManagePackagesForSelectedProjects(fakeSelectedProjects);
 972			
 973			List<IPackageAction> actions = fakeActionRunner.GetActionsRunInOneCallAsList();
 974			InstallPackageAction action = actions[0] as InstallPackageAction;
 975			Assert.IsTrue(action.AllowPrereleaseVersions);
 976		}
 977		
 978		[Test]
 979		public void ManagePackagesForSelectedProjects_ParentDoesNotAllowPrereleasePackagesAndOneProjectIsSelected_OneProjectIsInstalledNotAllowingPrereleasePackages()
 980		{
 981			CreateViewModel();
 982			CreateTwoFakeSelectedProjects();
 983			FakeSelectedProject project = fakeSelectedProjects[1];
 984			project.IsSelected = true;
 985			
 986			viewModel.ManagePackagesForSelectedProjects(fakeSelectedProjects);
 987			
 988			List<IPackageAction> actions = fakeActionRunner.GetActionsRunInOneCallAsList();
 989			InstallPackageAction action = actions[0] as InstallPackageAction;
 990			Assert.IsFalse(action.AllowPrereleaseVersions);
 991		}
 992		
 993		[Test]
 994		public void ManagePackagesForSelectedProjects_FirstProjectIsSelectedAndPackageOperationRequiresLicenseAcceptance_UserPromptedToAcceptLicenses()
 995		{
 996			CreateViewModel();
 997			CreateTwoFakeSelectedProjects();
 998			FakeSelectedProject selectedProject = fakeSelectedProjects[0];
 999			selectedProject.IsSelected = true;
1000			FakePackageOperation operation = selectedProject.AddFakeInstallPackageOperation();
1001			operation.FakePackage.RequireLicenseAcceptance = true;
1002			fakePackageManagementEvents.OnAcceptLicensesReturnValue = false;
1003			
1004			viewModel.ManagePackagesForSelectedProjects(fakeSelectedProjects);
1005			
1006			var expectedPackages = new FakePackage[] {
1007				operation.FakePackage
1008			};
1009			
1010			List<IPackage> actualPackages = fakePackageManagementEvents.GetPackagesPassedToOnAcceptLicensesAsList();
1011			
1012			CollectionAssert.AreEqual(expectedPackages, actualPackages);
1013		}
1014		
1015		[Test]
1016		public void ManagePackagesForSelectedProjects_FirstProjectIsSelectedAndPackageOperationRequiresLicenseAcceptance_PackageInViewModelUsedToGetPackageOperations()
1017		{
1018			CreateViewModel();
1019			CreateTwoFakeSelectedProjects();
1020			FakeSelectedProject selectedProject = fakeSelectedProjects[0];
1021			selectedProject.IsSelected = true;
1022			FakePackageOperation operation = selectedProject.AddFakeInstallPackageOperation();
1023			operation.FakePackage.RequireLicenseAcceptance = true;
1024			fakePackageManagementEvents.OnAcceptLicensesReturnValue = false;
1025			
1026			viewModel.ManagePackagesForSelectedProjects(fakeSelectedProjects);
1027			
1028			IPackage actualPackage = selectedProject.FakeProject.PackagePassedToGetInstallPackageOperations;
1029			
1030			Assert.AreEqual(fakePackage, actualPackage);
1031		}
1032		
1033		[Test]
1034		public void ManagePackagesForSelectedProjects_FirstProjectIsSelectedAndPackageOperationRequiresLicenseAcceptance_PackageDependenciesAreNotIgnored()
1035		{
1036			CreateViewModel();
1037			CreateTwoFakeSelectedProjects();
1038			FakeSelectedProject selectedProject = fakeSelectedProjects[0];
1039			selectedProject.IsSelected = true;
1040			FakePackageOperation operation = selectedProject.AddFakeInstallPackageOperation();
1041			operation.FakePackage.RequireLicenseAcceptance = true;
1042			fakePackageManagementEvents.OnAcceptLicensesReturnValue = false;
1043			
1044			viewModel.ManagePackagesForSelectedProjects(fakeSelectedProjects);
1045			
1046			bool ignored = selectedProject.FakeProject.IgnoreDependenciesPassedToGetInstallPackageOperations;
1047			
1048			Assert.IsFalse(ignored);
1049		}
1050		
1051		[Test]
1052		public void ManagePackagesForSelectedProjects_FirstProjectIsSelectedAndPackageOperationRequiresLicenseAcceptance_PrereleaseVersionsAreNotAllowed()
1053		{
1054			CreateViewModel();
1055			CreateTwoFakeSelectedProjects();
1056			FakeSelectedProject selectedProject = fakeSelectedProjects[0];
1057			selectedProject.IsSelected = true;
1058			FakePackageOperation operation = selectedProject.AddFakeInstallPackageOperation();
1059			operation.FakePackage.RequireLicenseAcceptance = true;
1060			fakePackageManagementEvents.OnAcceptLicensesReturnValue = false;
1061			
1062			viewModel.ManagePackagesForSelectedProjects(fakeSelectedProjects);
1063			
1064			bool allowed = selectedProject.FakeProject.AllowPrereleaseVersionsPassedToGetInstallPackageOperations;
1065			
1066			Assert.IsFalse(allowed);
1067		}
1068		
1069		[Test]
1070		public void ManagePackagesForSelectedProjects_ParentAllowsPrereleasesAndFirstProjectIsSelectedAndPackageOperationRequiresLicenseAcceptance_PrereleaseVersionsAreAllowedInPackageOperations()
1071		{
1072			CreateViewModel();
1073			CreateTwoFakeSelectedProjects();
1074			FakeSelectedProject selectedProject = fakeSelectedProjects[0];
1075			selectedProject.IsSelected = true;
1076			FakePackageOperation operation = selectedProject.AddFakeInstallPackageOperation();
1077			operation.FakePackage.RequireLicenseAcceptance = true;
1078			fakePackageManagementEvents.OnAcceptLicensesReturnValue = false;
1079			ParentAllowsPrereleasePackages();
1080			
1081			viewModel.ManagePackagesForSelectedProjects(fakeSelectedProjects);
1082			
1083			bool allowed = selectedProject.FakeProject.AllowPrereleaseVersionsPassedToGetInstallPackageOperations;
1084			
1085			Assert.IsTrue(allowed);
1086		}
1087		
1088		[Test]
1089		public void ManagePackagesForSelectedProjects_FirstProjectIsSelectedAndTwoPackageOperationsRequireLicenseAcceptance_UserPromptedToAcceptLicensesForTwoPackages()
1090		{
1091			CreateViewModel();
1092			CreateTwoFakeSelectedProjects();
1093			FirstFakeSelectedProject.IsSelected = true;
1094			
1095			FakePackageOperation firstOperation = 
1096				AddFakeInstallPackageOperationWithPackageThatRequiresLicenseAcceptance(FirstFakeSelectedProject);
1097			
1098			FakePackageOperation secondOperation = 
1099				AddFakeInstallPackageOperationWithPackageThatRequiresLicenseAcceptance(FirstFakeSelectedProject);
1100			
1101			fakePackageManagementEvents.OnAcceptLicensesReturnValue = false;
1102			
1103			viewModel.ManagePackagesForSelectedProjects(fakeSelectedProjects);
1104			
1105			var expectedPackages = new FakePackage[] {
1106				firstOperation.FakePackage,
1107				secondOperation.FakePackage
1108			};
1109			
1110			List<IPackage> actualPackages = fakePackageManagementEvents.GetPackagesPassedToOnAcceptLicensesAsList();
1111			
1112			CollectionAssert.AreEqual(expectedPackages, actualPackages);
1113		}
1114		
1115		[Test]
1116		public void ManagePackagesForSelectedProjects_TwoPackageOperationsRequireLicenseAcceptanceButOneIsUninstallPackageOperation_UserPromptedToAcceptLicenseForInstallPackageOperationOnly()
1117		{
1118			CreateViewModel();
1119			CreateTwoFakeSelectedProjects();
1120			FirstFakeSelectedProject.IsSelected = true;
1121			FakePackageOperation installOperation = 
1122				AddFakeInstallPackageOperationWithPackageThatRequiresLicenseAcceptance(FirstFakeSelectedProject);
1123			AddFakeUninstallPackageOperationWithPackageThatRequiresLicenseAcceptance(FirstFakeSelectedProject);
1124						
1125			fakePackageManagementEvents.OnAcceptLicensesReturnValue = false;
1126			
1127			viewModel.ManagePackagesForSelectedProjects(fakeSelectedProjects);
1128			
1129			var expectedPackages = new FakePackage[] {
1130				installOperation.FakePackage
1131			};
1132			
1133			List<IPackage> actualPackages = fakePackageManagementEvents.GetPackagesPassedToOnAcceptLicensesAsList();
1134			
1135			CollectionAssert.AreEqual(expectedPackages, actualPackages);
1136		}
1137		
1138		[Test]
1139		public void ManagePackagesForSelectedProjects_OneInstallPackageOperationsDoesNotRequireLicenseAcceptance_UserIsNotPromptedToAcceptLicense()
1140		{
1141			CreateViewModel();
1142			CreateTwoFakeSelectedProjects();
1143			FirstFakeSelectedProject.IsSelected = true;
1144			AddFakeInstallPackageOperationWithPackageThatDoesNotRequireLicenseAcceptance(FirstFakeSelectedProject);
1145			
1146			fakePackageManagementEvents.OnAcceptLicensesReturnValue = false;
1147			
1148			viewModel.ManagePackagesForSelectedProjects(fakeSelectedProjects);
1149			
1150			Assert.IsFalse(fakePackageManagementEvents.IsOnAcceptLicensesCalled);
1151		}
1152		
1153		[Test]
1154		public void ManagePackagesForSelectedProjects_OneInstallPackageOperationsRequiresLicenseAcceptanceButIsInstalledInSolutionAlready_UserIsNotPromptedToAcceptLicense()
1155		{
1156			CreateViewModel();
1157			CreateTwoFakeSelectedProjects();
1158			FirstFakeSelectedProject.IsSelected = true;
1159			
1160			FakePackageOperation installOperation = 
1161				AddFakeInstallPackageOperationWithPackageThatRequiresLicenseAcceptance(FirstFakeSelectedProject);
1162			
1163			fakeSolution.FakeInstalledPackages.Add(installOperation.FakePackage);
1164			
1165			fakePackageManagementEvents.OnAcceptLicensesReturnValue = false;
1166			
1167			viewModel.ManagePackagesForSelectedProjects(fakeSelectedProjects);
1168			
1169			Assert.IsFalse(fakePackageManagementEvents.IsOnAcceptLicensesCalled);
1170		}
1171		
1172		[Test]
1173		public void ManagePackagesForSelectedProjects_FirstProjectIsSelectedAndUserDoesNotAcceptPackageLicense_PackageIsNotInstalled()
1174		{
1175			CreateViewModel();
1176			CreateTwoFakeSelectedProjects();
1177			FirstFakeSelectedProject.IsSelected = true;
1178			
1179			AddFakeInstallPackageOperationWithPackageThatRequiresLicenseAcceptance(FirstFakeSelectedProject);
1180			
1181			fakePackageManagementEvents.OnAcceptLicensesReturnValue = false;
1182			
1183			viewModel.ManagePackagesForSelectedProjects(fakeSelectedProjects);
1184			
1185			Assert.IsFalse(fakeActionRunner.IsRunCalled);
1186		}
1187		
1188		[Test]
1189		public void ManagePackagesForSelectedProjects_TwoProjectsButNeitherIsSelected_NoPackageActionsAreRun()
1190		{
1191			CreateViewModel();
1192			CreateTwoFakeSelectedProjects();
1193			
1194			viewModel.ManagePackagesForSelectedProjects(fakeSelectedProjects);
1195			
1196			Assert.IsFalse(fakeActionRunner.IsRunCalled);
1197		}
1198		
1199		[Test]
1200		public void ManagePackagesForSelectedProjects_FirstProjectIsSelectedAndUserAcceptsPackageLicense_PackageIsInstalled()
1201		{
1202			CreateViewModel();
1203			CreateTwoFakeSelectedProjects();
1204			FirstFakeSelectedProject.IsSelected = true;
1205			
1206			AddFakeInstallPackageOperationWithPackageThatRequiresLicenseAcceptance(FirstFakeSelectedProject);
1207			
1208			fakePackageManagementEvents.OnAcceptLicensesReturnValue = true;
1209				
1210			viewModel.ManagePackagesForSelectedProjects(fakeSelectedProjects);
1211			
1212			InstallPackageAction expectedAction = FirstFakeSelectedProject.FakeProject.LastInstallPackageCreated;
1213			List<IPackageAction> actions = fakeActionRunner.GetActionsRunInOneCallAsList();
1214			InstallPackageAction action = actions[0] as InstallPackageAction;
1215			
1216			Assert.AreEqual(1, actions.Count);
1217			Assert.AreEqual(fakePackage, action.Package);
1218			Assert.AreEqual(expectedAction, action);
1219		}
1220		
1221		[Test]
1222		public void ManagePackagesForSelectedProjects_TwoProjectsAreSelectedAndUserAcceptsPackageLicense_UserIsNotPromptedTwiceToAcceptLicenses()
1223		{
1224			CreateViewModel();
1225			CreateTwoFakeSelectedProjects();
1226			FirstFakeSelectedProject.IsSelected = true;
1227			AddFakeInstallPackageOperationWithPackageThatRequiresLicenseAcceptance(FirstFakeSelectedProject);
1228			
1229			SecondFakeSelectedProject.IsSelected = true;
1230			AddFakeInstallPackageOperationWithPackageThatRequiresLicenseAcceptance(SecondFakeSelectedProject);
1231			
1232			fakePackageManagementEvents.OnAcceptLicensesReturnValue = true;
1233				
1234			viewModel.ManagePackagesForSelectedProjects(fakeSelectedProjects);
1235			
1236			List<IEnumerable<IPackage>> packagesPassedToAcceptLicenses =
1237				fakePackageManagementEvents.PackagesPassedToAcceptLicenses;
1238			Assert.AreEqual(1, packagesPassedToAcceptLicenses.Count);
1239		}
1240		
1241		[Test]
1242		public void ManagePackagesForSelectedProjects_FirstProjectSelectedAndExceptionThrownWhenResolvingPackageOperations_ExceptionReported()
1243		{
1244			CreateViewModel();
1245			CreateTwoFakeSelectedProjects();
1246			FirstFakeSelectedProject.IsSelected = true;
1247			var exceptionThrowingProject = new ExceptionThrowingPackageManagementProject();
1248			FirstFakeSelectedProject.FakeProject = exceptionThrowingProject;
1249			AddFakeInstallPackageOperationWithPackageThatDoesNotRequireLicenseAcceptance(FirstFakeSelectedProject);
1250			
1251			var exception = new Exception("Test");
1252			exceptionThrowingProject.ExceptionToThrowWhenGetInstallPackageOperationsCalled = exception;
1253			viewModel.ManagePackagesForSelectedProjects(fakeSelectedProjects);
1254			
1255			Assert.AreEqual(exception, fakePackageManagementEvents.ExceptionPassedToOnPackageOperationError);
1256		}
1257		
1258		[Test]
1259		public void ManagePackagesForSelectedProjects_FirstProjectSelectedAndExceptionThrownWhenCreatingInstallAction_ExceptionLogged()
1260		{
1261			CreateViewModel();
1262			CreateTwoFakeSelectedProjects();
1263			FirstFakeSelectedProject.IsSelected = true;
1264			var exceptionThrowingProject = new ExceptionThrowingPackageManagementProject();
1265			FirstFakeSelectedProject.FakeProject = exceptionThrowingProject;
1266			AddFakeInstallPackageOperationWithPackageThatDoesNotRequireLicenseAcceptance(FirstFakeSelectedProject);
1267			
1268			var exception = new Exception("Exception error message");
1269			exceptionThrowingProject.ExceptionToThrowWhenCreateInstallPackageActionCalled = exception;
1270			viewModel.ManagePackagesForSelectedProjects(fakeSelectedProjects);
1271			
1272			bool contains = fakeLogger.FormattedMessagesLoggedContainsText("Exception error message");
1273			
1274			Assert.IsTrue(contains);
1275		}
1276		
1277		[Test]
1278		public void ManagePackagesForSelectedProjects_TwoProjectsOneSelectedAndPackageRequiresLicenseAcceptance_PackageViewModelLoggerUsedWhenResolvingPackageOperations()
1279		{
1280			CreateViewModel();
1281			CreateTwoFakeSelectedProjects();
1282			FirstFakeSelectedProject.IsSelected = true;
1283			AddFakeInstallPackageOperationWithPackageThatRequiresLicenseAcceptance(FirstFakeSelectedProject);
1284			fakePackageManagementEvents.OnAcceptLicensesReturnValue = true;
1285			
1286			viewModel.ManagePackagesForSelectedProjects(fakeSelectedProjects);
1287			
1288			ILogger expectedLogger = viewModel.OperationLoggerCreated;
1289			ILogger actualLogger = FirstFakeSelectedProject.Project.Logger;
1290			Assert.AreEqual(expectedLogger, actualLogger);
1291		}
1292		
1293		[Test]
1294		public void ManagePackage_UserAcceptsProjectSelection_ManagingPackageMessageIsFirstMessageLogged()
1295		{
1296			CreateViewModelWithTwoProjectsSelected("Project A", "Project B");
1297			UserAcceptsProjectSelection();
1298			fakePackage.Id = "Test.Package";
1299			fakePackage.Version = new SemanticVersion(1, 2, 0, 55);
1300			viewModel.ManagePackage();
1301			
1302			string expectedMessage = "------- Managing...Test.Package 1.2.0.55 -------";
1303			string actualMessage = fakeLogger.FirstFormattedMessageLogged;
1304			
1305			Assert.AreEqual(expectedMessage, actualMessage);
1306		}
1307		
1308		[Test]
1309		public void ManagePackagesForSelectedProjects_TwoProjectsNoneSelectedAndFirstPackageHasLicense_UserIsNotPromptedToAcceptLicense()
1310		{
1311			CreateViewModel();
1312			CreateTwoFakeSelectedProjects();
1313			AddFakeInstallPackageOperationWithPackageThatRequiresLicenseAcceptance(FirstFakeSelectedProject);
1314				
1315			viewModel.ManagePackagesForSelectedProjects(fakeSelectedProjects);
1316			
1317			Assert.IsFalse(fakePackageManagementEvents.IsOnAcceptLicensesCalled);
1318		}
1319		
1320		[Test]
1321		public void ManagePackage_TwoProjectsAndFirstSelectedInDialog_PackageIsInstalled()
1322		{
1323			CreateViewModelWithTwoProjectsSelected("Project A", "Project B");
1324			UserAcceptsProjectSelection();
1325			fakePackageManagementEvents.ProjectsToSelect.Add("Project A");
1326			
1327			viewModel.ManagePackage();
1328			
1329			List<IPackageAction> actions = fakeActionRunner.GetActionsRunInOneCallAsList();
1330			var action = actions[0] as ProcessPackageAction;
1331			FakePackageManagementProject expectedProject = fakeSolution.FakeProjectsToReturnFromGetProject["Project A"];
1332			Assert.AreEqual(expectedProject, action.Project);
1333		}
1334		
1335		[Test]
1336		public void ManagePackage_TwoProjectsAndSecondSelectedInDialog_ProjectHasLoggerSet()
1337		{
1338			CreateViewModelWithTwoProjectsSelected("Project A", "Project B");
1339			UserAcceptsProjectSelection();
1340			fakePackageManagementEvents.ProjectsToSelect.Add("Project B");
1341			viewModel.ManagePackage();
1342			
1343			FakePackageManagementProject project = fakeSolution.FakeProjectsToReturnFromGetProject["Project B"];
1344			ILogger expectedLogger = viewModel.OperationLoggerCreated;
1345			ILogger actualLogger = project.Logger;
1346			Assert.AreEqual(expectedLogger, actualLogger);
1347		}
1348		
1349		[Test]
1350		public void Summary_PackageHasSummary_PackageSummaryReturned()
1351		{
1352			CreateViewModel();
1353			fakePackage.Summary = "Expected summary";
1354			
1355			string summary = viewModel.Summary;
1356			
1357			Assert.AreEqual("Expected summary", summary);
1358		}
1359		
1360		[Test]
1361		public void Summary_PackageHasDescriptionButNoSummary_PackageDescriptionReturned()
1362		{
1363			CreateViewModel();
1364			fakePackage.Summary = String.Empty;
1365			fakePackage.Description = "Expected description";
1366			
1367			string summary = viewModel.Summary;
1368			
1369			Assert.AreEqual("Expected description", summary);
1370		}
1371		
1372		[Test]
1373		public void AddPackage_ParentAllowsPrereleasePackages_PackageIsInstalledAllowingPrereleasePackages()
1374		{
1375			CreateViewModel();
1376			ParentAllowsPrereleasePackages();
1377			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
1378			
1379			viewModel.AddPackage();
1380			
1381			var action = fakeActionRunner.ActionPassedToRun as InstallPackageAction;
1382			Assert.IsTrue(action.AllowPrereleaseVersions);
1383		}
1384		
1385		[Test]
1386		public void AddPackage_ParentDoesNotAllowPrereleasePackages_PackageIsInstalledNotAllowingPrereleasePackages()
1387		{
1388			CreateViewModel();
1389			viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
1390			
1391			viewModel.AddPackage();
1392			
1393			var action = fakeActionRunner.ActionPassedToRun as InstallPackageAction;
1394			Assert.IsFalse(action.AllowPrereleaseVersions);
1395		}
1396		
1397		[Test]
1398		public void Name_PackageHasIdButNoTitle_ReturnsPackageId()
1399		{
1400			CreateViewModel();
1401			fakePackage.Id = "MyPackage";
1402			
1403			string name = viewModel.Name;
1404			
1405			Assert.AreEqual("MyPackage", name);
1406		}
1407		
1408		[Test]
1409		public void Name_PackageHasIdAndTitle_ReturnsPackageId()
1410		{
1411			CreateViewModel();
1412			fakePackage.Id = "MyPackage";
1413			fakePackage.Title = "My Package Title";
1414			
1415			string name = viewModel.Name;
1416			
1417			Assert.AreEqual("My Package Title", name);
1418		}
1419		
1420		[Test]
1421		public void GalleryUrl_PackageHasGalleryUrl_ReturnsUrl()
1422		{
1423			CreateViewModel();
1424			var expectedUrl = new Uri("http://test.com/MyPackage");
1425			fakePackage.GalleryUrl = expectedUrl;
1426			
1427			Uri url = viewModel.GalleryUrl;
1428			
1429			Assert.AreEqual(expectedUrl, url);
1430		}
1431		
1432		[Test]
1433		public void HasGalleryUrl_PackageHasGalleryUrl_ReturnsTrue()
1434		{
1435			CreateViewModel();
1436			var expectedUrl = new Uri("http://test.com/MyPackage");
1437			fakePackage.GalleryUrl = expectedUrl;
1438			
1439			bool result = viewModel.HasGalleryUrl;
1440			
1441			Assert.IsTrue(result);
1442		}
1443		
1444		[Test]
1445		public void HasNoGalleryUrl_PackageHasNoGalleryUrl_ReturnsFalse()
1446		{
1447			CreateViewModel();
1448			fakePackage.GalleryUrl = null;
1449			
1450			bool result = viewModel.HasGalleryUrl;
1451			
1452			Assert.IsFalse(result);
1453		}
1454		
1455		[Test]
1456		public void HasNoGalleryUrl_PackageHasGalleryUrl_ReturnsFalse()
1457		{
1458			CreateViewModel();
1459			var expectedUrl = new Uri("http://test.com/MyPackage");
1460			fakePackage.GalleryUrl = expectedUrl;
1461			
1462			bool result = viewModel.HasNoG

Large files files are truncated, but you can click here to view the full file