PageRenderTime 91ms CodeModel.GetById 14ms app.highlight 69ms RepoModel.GetById 1ms app.codeStats 1ms

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

https://github.com/ajadex/SharpDevelop
C# | 1379 lines | 1075 code | 280 blank | 24 comment | 0 complexity | d986383a3a66c110319f034147bc7ffa MD5 | raw file
   1// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
   2// 
   3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
   4// software and associated documentation files (the "Software"), to deal in the Software
   5// without restriction, including without limitation the rights to use, copy, modify, merge,
   6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
   7// to whom the Software is furnished to do so, subject to the following conditions:
   8// 
   9// The above copyright notice and this permission notice shall be included in all copies or
  10// substantial portions of the Software.
  11// 
  12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17// DEALINGS IN THE SOFTWARE.
  18
  19using System;
  20using System.Collections.Generic;
  21using System.Collections.ObjectModel;
  22using System.ComponentModel;
  23using System.Linq;
  24using ICSharpCode.PackageManagement;
  25using ICSharpCode.PackageManagement.Design;
  26using NuGet;
  27using NUnit.Framework;
  28using PackageManagement.Tests.Helpers;
  29
  30namespace PackageManagement.Tests
  31{
  32	[TestFixture]
  33	public class PackagesViewModelTests
  34	{
  35		TestablePackagesViewModel viewModel;
  36		FakeTaskFactory taskFactory;
  37		FakeRegisteredPackageRepositories registeredPackageRepositories;
  38		
  39		void CreateViewModel(FakeRegisteredPackageRepositories registeredPackageRepositories)
  40		{
  41			viewModel = new TestablePackagesViewModel(registeredPackageRepositories);
  42			this.registeredPackageRepositories = registeredPackageRepositories;
  43			taskFactory = viewModel.FakeTaskFactory;
  44		}
  45		
  46		void CreateViewModel()
  47		{
  48			CreateRegisteredRepositoriesService();
  49			CreateViewModel(registeredPackageRepositories);
  50		}
  51		
  52		void CreateRegisteredRepositoriesService()
  53		{
  54			registeredPackageRepositories = new FakeRegisteredPackageRepositories();
  55		}
  56		
  57		void CompleteReadPackagesTask()
  58		{
  59			taskFactory.ExecuteAllFakeTasks();
  60		}
  61		
  62		void ClearReadPackagesTasks()
  63		{
  64			taskFactory.ClearAllFakeTasks();
  65		}
  66
  67		[Test]
  68		public void IsPaged_OnePackageAndPageSizeIsFive_ReturnsFalse()
  69		{
  70			CreateViewModel();
  71			viewModel.PageSize = 5;
  72			viewModel.AddOneFakePackage();
  73			viewModel.ReadPackages();
  74			CompleteReadPackagesTask();
  75			
  76			bool paged = viewModel.IsPaged;
  77			
  78			Assert.IsFalse(paged);
  79		}
  80		
  81		[Test]
  82		public void IsPaged_SixPackagesAndPageSizeIsFive_ReturnsTrue()
  83		{
  84			CreateViewModel();
  85			viewModel.PageSize = 5;
  86			viewModel.AddSixFakePackages();
  87			viewModel.ReadPackages();
  88			CompleteReadPackagesTask();
  89			
  90			bool paged = viewModel.IsPaged;
  91			
  92			Assert.IsTrue(paged);
  93		}
  94		
  95		[Test]
  96		public void SelectedPageNumber_ByDefault_ReturnsOne()
  97		{
  98			CreateViewModel();
  99			
 100			int pageNumber = viewModel.SelectedPageNumber;
 101			
 102			Assert.AreEqual(1, pageNumber);
 103		}
 104		
 105		[Test]
 106		public void HasPreviousPage_SixPackagesSelectedPageNumberIsOneAndPageSizeIsFive_ReturnsFalse()
 107		{
 108			CreateViewModel();
 109			viewModel.PageSize = 5;
 110			viewModel.AddSixFakePackages();
 111			viewModel.ReadPackages();
 112			CompleteReadPackagesTask();
 113			viewModel.SelectedPageNumber = 1;
 114			
 115			Assert.IsFalse(viewModel.HasPreviousPage);
 116		}
 117		
 118		[Test]
 119		public void HasPreviousPage_SixPackagesSelectedPageNumberIsTwoAndPageSizeIsFive_ReturnsTrue()
 120		{
 121			CreateViewModel();
 122			viewModel.PageSize = 5;
 123			viewModel.AddSixFakePackages();
 124			viewModel.ReadPackages();
 125			CompleteReadPackagesTask();
 126			viewModel.SelectedPageNumber = 2;
 127			
 128			Assert.IsTrue(viewModel.HasPreviousPage);
 129		}
 130		
 131		[Test]
 132		public void HasPreviousPage_SelectedPagesChangesFromFirstPageToSecond_PropertyChangedEventFiredForAllProperties()
 133		{
 134			CreateViewModel();
 135			viewModel.PageSize = 5;
 136			viewModel.AddSixFakePackages();
 137			viewModel.SelectedPageNumber = 1;
 138			viewModel.ReadPackages();
 139			CompleteReadPackagesTask();
 140			
 141			PropertyChangedEventArgs propertyChangedEvent = null;
 142			viewModel.PropertyChanged += (sender, e) => propertyChangedEvent = e;
 143			viewModel.SelectedPageNumber = 2;
 144			
 145			string propertyName = propertyChangedEvent.PropertyName;
 146			
 147			Assert.IsNull(propertyName);
 148		}
 149		
 150		[Test]
 151		public void HasNextPage_SixPackagesSelectedPageNumberIsOneAndPageSizeIsFive_ReturnsTrue()
 152		{
 153			CreateViewModel();
 154			viewModel.PageSize = 5;
 155			viewModel.AddSixFakePackages();
 156			viewModel.ReadPackages();
 157			CompleteReadPackagesTask();
 158			viewModel.SelectedPageNumber = 1;
 159			
 160			Assert.IsTrue(viewModel.HasNextPage);
 161		}
 162		
 163		[Test]
 164		public void HasNextPage_SixPackagesSelectedPageNumberIsTwoAndPageSizeIsFive_ReturnsFalse()
 165		{
 166			CreateViewModel();
 167			viewModel.PageSize = 5;
 168			viewModel.AddSixFakePackages();
 169			viewModel.ReadPackages();
 170			CompleteReadPackagesTask();
 171			viewModel.SelectedPageNumber = 2;
 172			
 173			Assert.IsFalse(viewModel.HasNextPage);
 174		}
 175		
 176		[Test]
 177		public void HasNextPage_SixPackagesSelectedPageNumberIsTwoAndPageSizeIsTwo_ReturnsTrue()
 178		{
 179			CreateViewModel();
 180			viewModel.PageSize = 2;
 181			viewModel.AddSixFakePackages();
 182			viewModel.ReadPackages();
 183			CompleteReadPackagesTask();
 184			viewModel.SelectedPageNumber = 2;
 185			
 186			Assert.IsTrue(viewModel.HasNextPage);
 187		}
 188		
 189		[Test]
 190		public void Pages_SixPackagesSelectedPageNumberIsTwoAndPageSizeIsFive_ReturnsTwoPagesWithSecondOneSelected()
 191		{
 192			CreateViewModel();
 193			viewModel.PageSize = 5;
 194			viewModel.AddSixFakePackages();
 195			viewModel.ReadPackages();
 196			CompleteReadPackagesTask();
 197			viewModel.SelectedPageNumber = 2;
 198			
 199			Page[] expectedPages = new Page[] {
 200				new Page() { Number = 1 },
 201				new Page() { Number = 2, IsSelected = true }
 202			};
 203			
 204			var actualPages = viewModel.Pages;
 205			
 206			PageCollectionAssert.AreEqual(expectedPages, actualPages);
 207		}
 208		
 209		[Test]
 210		public void Pages_SixPackagesSelectedPageNumberIsOneAndPageSizeIsFive_ReturnsTwoPagesWithFirstOneSelected()
 211		{
 212			CreateViewModel();
 213			viewModel.PageSize = 5;
 214			viewModel.AddSixFakePackages();
 215			viewModel.ReadPackages();
 216			CompleteReadPackagesTask();
 217			viewModel.SelectedPageNumber = 1;
 218			
 219			Page[] expectedPages = new Page[] {
 220				new Page() { Number = 1, IsSelected = true },
 221				new Page() { Number = 2 }
 222			};
 223			
 224			var actualPages = viewModel.Pages;
 225			
 226			PageCollectionAssert.AreEqual(expectedPages, actualPages);
 227		}
 228		
 229		[Test]
 230		public void Pages_SixPackagesSelectedPageNumberIsOneAndPageSizeIsTwo_ReturnsThreePagesWithFirstOneSelected()
 231		{
 232			CreateViewModel();
 233			viewModel.PageSize = 2;
 234			viewModel.AddSixFakePackages();
 235			viewModel.ReadPackages();
 236			CompleteReadPackagesTask();
 237			viewModel.SelectedPageNumber = 1;
 238			
 239			Page[] expectedPages = new Page[] {
 240				new Page() { Number = 1, IsSelected = true },
 241				new Page() { Number = 2 },
 242				new Page() { Number = 3 }
 243			};
 244			
 245			var actualPages = viewModel.Pages;
 246			
 247			PageCollectionAssert.AreEqual(expectedPages, actualPages);
 248		}
 249		
 250		[Test]
 251		public void Pages_SixPackagesSelectedPageNumberIsOneAndPageSizeIsTwoAndMaximumSelectablePagesIsTwo_ReturnsTwoPagesWithFirstOneSelected()
 252		{
 253			CreateViewModel();
 254			viewModel.PageSize = 2;
 255			viewModel.AddSixFakePackages();
 256			viewModel.ReadPackages();
 257			CompleteReadPackagesTask();
 258			viewModel.SelectedPageNumber = 1;
 259			viewModel.MaximumSelectablePages = 2;
 260			
 261			Page[] expectedPages = new Page[] {
 262				new Page() { Number = 1, IsSelected = true },
 263				new Page() { Number = 2 }
 264			};
 265			
 266			var actualPages = viewModel.Pages;
 267			
 268			PageCollectionAssert.AreEqual(expectedPages, actualPages);
 269		}
 270		
 271		[Test]
 272		public void Pages_SixPackagesSelectedPageNumberIsOneAndPageSizeIsFiveGetPagesTwice_ReturnsTwoPagesWithFirstOneSelected()
 273		{
 274			CreateViewModel();
 275			viewModel.PageSize = 5;
 276			viewModel.AddSixFakePackages();
 277			viewModel.ReadPackages();
 278			CompleteReadPackagesTask();
 279			viewModel.SelectedPageNumber = 1;
 280			
 281			Page[] expectedPages = new Page[] {
 282				new Page() { Number = 1, IsSelected = true },
 283				new Page() { Number = 2 }
 284			};
 285			
 286			var actualPages = viewModel.Pages;
 287			actualPages = viewModel.Pages;
 288			
 289			PageCollectionAssert.AreEqual(expectedPages, actualPages);
 290		}
 291		
 292		[Test]
 293		public void Pages_SixPackagesSelectedPageNumberIsThreeAndPageSizeIsTwoAndMaximumSelectablePagesIsTwo_ReturnsPagesTwoAndThreeWithPageThreeSelected()
 294		{
 295			CreateViewModel();
 296			viewModel.PageSize = 2;
 297			viewModel.AddSixFakePackages();
 298			viewModel.ReadPackages();
 299			CompleteReadPackagesTask();
 300			viewModel.SelectedPageNumber = 3;
 301			viewModel.MaximumSelectablePages = 2;
 302			
 303			Page[] expectedPages = new Page[] {
 304				new Page() { Number = 2 },
 305				new Page() { Number = 3, IsSelected = true }
 306			};
 307			
 308			var actualPages = viewModel.Pages;
 309			
 310			PageCollectionAssert.AreEqual(expectedPages, actualPages);
 311		}
 312
 313		[Test]
 314		public void Pages_TenPackagesSelectedPageNumberIsFiveAndPageSizeIsTwoAndMaximumSelectablePagesIsThree_ReturnsPagesThreeAndFourAndFive()
 315		{
 316			CreateViewModel();
 317			viewModel.PageSize = 2;
 318			viewModel.AddTenFakePackages();
 319			viewModel.ReadPackages();
 320			CompleteReadPackagesTask();
 321			viewModel.SelectedPageNumber = 5;
 322			viewModel.MaximumSelectablePages = 3;
 323			
 324			Page[] expectedPages = new Page[] {
 325				new Page() { Number = 3 },
 326				new Page() { Number = 4 },
 327				new Page() { Number = 5, IsSelected = true }
 328			};
 329			
 330			var actualPages = viewModel.Pages;
 331			
 332			PageCollectionAssert.AreEqual(expectedPages, actualPages);
 333		}
 334		
 335		[Test]
 336		public void ReadPackages_SecondQueryFinishesBeforeFirst_PackagesInViewModelAreForSecondQuery()
 337		{
 338			CreateViewModel();
 339			viewModel.AddThreeFakePackages();
 340			FakePackage package = viewModel.AddFakePackage("MyTest");
 341			viewModel.ReadPackages();
 342			viewModel.SearchTerms = "MyTest";
 343			
 344			var expectedPackages = new FakePackage [] { package };
 345			
 346			viewModel.ReadPackages();
 347			taskFactory.ExecuteTask(1);
 348			taskFactory.ExecuteTask(0);
 349			ClearReadPackagesTasks();
 350			
 351			PackageCollectionAssert.AreEqual(expectedPackages, viewModel.PackageViewModels);
 352		}
 353		
 354		[Test]
 355		public void ReadPackages_RepositoryHasSixPackagesWhenSelectedPageIsOneAndPageSizeIsThree_ThreePackageViewModelsCreatedForFirstThreePackages()
 356		{
 357			CreateViewModel();
 358			viewModel.PageSize = 3;
 359			viewModel.SelectedPageNumber = 1;
 360			viewModel.AddSixFakePackages();
 361			viewModel.ReadPackages();
 362			CompleteReadPackagesTask();
 363			
 364			var expectedPackages = new List<FakePackage>();
 365			expectedPackages.Add(viewModel.FakePackages[0]);
 366			expectedPackages.Add(viewModel.FakePackages[1]);
 367			expectedPackages.Add(viewModel.FakePackages[2]);
 368
 369			ClearReadPackagesTasks();
 370			viewModel.ReadPackages();
 371			CompleteReadPackagesTask();
 372			
 373			PackageCollectionAssert.AreEqual(expectedPackages, viewModel.PackageViewModels);
 374		}
 375		
 376		[Test]
 377		public void Pages_PageSizeChanged_PagesRecalcuatedBasedOnNewPageSize()
 378		{
 379			CreateViewModel();
 380			viewModel.PageSize = 10;
 381			viewModel.AddSixFakePackages();
 382			viewModel.ReadPackages();
 383			CompleteReadPackagesTask();
 384			
 385			int oldPageCount = viewModel.Pages.Count;
 386			viewModel.PageSize = 5;
 387			int newPageCount = viewModel.Pages.Count;
 388			
 389			Assert.AreEqual(2, newPageCount);
 390			Assert.AreEqual(1, oldPageCount);
 391		}
 392
 393		[Test]
 394		public void Pages_SelectedPageNumberChanged_PagesRecalculatedBasedOnNewSelectedPage()
 395		{
 396			CreateViewModel();
 397			viewModel.PageSize = 3;
 398			viewModel.SelectedPageNumber = 1;
 399			viewModel.AddSixFakePackages();
 400			viewModel.ReadPackages();
 401			CompleteReadPackagesTask();
 402			
 403			ClearReadPackagesTasks();
 404			var oldPages = viewModel.Pages;
 405			viewModel.SelectedPageNumber = 2;
 406			CompleteReadPackagesTask();
 407			var newPages = viewModel.Pages;
 408			
 409			Page[] expectedPages = new Page[] {
 410				new Page() { Number = 1 },
 411				new Page() { Number = 2, IsSelected = true }
 412			};
 413			
 414			PageCollectionAssert.AreEqual(expectedPages, newPages);
 415		}
 416		
 417		[Test]
 418		public void ShowNextPageCommand_TwoPagesAndFirstPageSelectedWhenCommandExecuted_PageTwoIsSelected()
 419		{
 420			CreateViewModel();
 421			viewModel.PageSize = 3;
 422			viewModel.SelectedPageNumber = 1;
 423			viewModel.AddSixFakePackages();
 424			viewModel.ReadPackages();
 425			CompleteReadPackagesTask();
 426			
 427			viewModel.ShowNextPageCommand.Execute(null);
 428			
 429			int selectedPage = viewModel.SelectedPageNumber;
 430			
 431			Assert.AreEqual(2, selectedPage);
 432		}
 433		
 434		[Test]
 435		public void ShowNextPageCommand_TwoPagesAndFirstPageSelectedWhenCommandExecuted_SecondPageOfPackagesDisplayed()
 436		{
 437			CreateViewModel();
 438			viewModel.AddThreeFakePackages();
 439			viewModel.PageSize = 2;
 440			viewModel.SelectedPageNumber = 1;
 441			viewModel.ReadPackages();
 442			CompleteReadPackagesTask();
 443			
 444			ClearReadPackagesTasks();
 445			viewModel.ShowNextPageCommand.Execute(null);
 446			CompleteReadPackagesTask();
 447			
 448			var expectedPackages = new List<FakePackage>();
 449			expectedPackages.Add(viewModel.FakePackages[2]);
 450			
 451			PackageCollectionAssert.AreEqual(expectedPackages, viewModel.PackageViewModels);
 452		}
 453		
 454		[Test]
 455		public void ShowPreviousPageCommand_TwoPagesAndSecondPageSelectedWhenCommandExecuted_PageOneIsSelected()
 456		{
 457			CreateViewModel();
 458			viewModel.PageSize = 3;
 459			viewModel.AddSixFakePackages();
 460			viewModel.ReadPackages();
 461			CompleteReadPackagesTask();
 462			viewModel.SelectedPageNumber = 2;
 463			
 464			viewModel.ShowPreviousPageCommand.Execute(null);
 465			
 466			int selectedPage = viewModel.SelectedPageNumber;
 467			
 468			Assert.AreEqual(1, selectedPage);
 469		}
 470		
 471		[Test]
 472		public void ShowPreviousPageCommand_TwoPagesAndSecondPageSelectedWhenCommandExecuted_FirstPageOfPackagesDisplayed()
 473		{
 474			CreateViewModel();
 475			viewModel.AddThreeFakePackages();
 476			viewModel.PageSize = 2;
 477			viewModel.ReadPackages();
 478			CompleteReadPackagesTask();
 479			viewModel.SelectedPageNumber = 2;
 480			ClearReadPackagesTasks();
 481			
 482			viewModel.ShowPreviousPageCommand.Execute(null);
 483			CompleteReadPackagesTask();
 484			
 485			var expectedPackages = new List<FakePackage>();
 486			expectedPackages.Add(viewModel.FakePackages[0]);
 487			expectedPackages.Add(viewModel.FakePackages[1]);
 488			
 489			PackageCollectionAssert.AreEqual(expectedPackages, viewModel.PackageViewModels);
 490		}
 491		
 492		[Test]
 493		public void ShowPageCommand_PageNumberOneToBeShownWhenCurrentlySelectedPageIsTwo_PageOneIsSelected()
 494		{
 495			CreateViewModel();
 496			viewModel.PageSize = 2;
 497			viewModel.AddSixFakePackages();
 498			viewModel.ReadPackages();
 499			CompleteReadPackagesTask();
 500			viewModel.SelectedPageNumber = 2;
 501			
 502			int pageNumber = 1;
 503			viewModel.ShowPageCommand.Execute(pageNumber);
 504			
 505			int selectedPage = viewModel.SelectedPageNumber;
 506			
 507			Assert.AreEqual(1, selectedPage);
 508		}
 509		
 510		[Test]
 511		public void Pages_ReadPackagesAndIsPagedCalled_PackagesReadFromRepositoryOnlyOnce()
 512		{
 513			CreateViewModel();
 514			viewModel.AddSixFakePackages();
 515			viewModel.ReadPackages();
 516			CompleteReadPackagesTask();
 517			bool result = viewModel.IsPaged;
 518			int count = viewModel.Pages.Count;
 519			
 520			Assert.AreEqual(1, viewModel.GetAllPackagesCallCount);
 521		}
 522		
 523		[Test]
 524		public void ReadPackages_CalledThreeTimesAndThenSelectedPageChanged_ViewModelPropertiesChangedEventFiresOnceWhenSelectedPageChanged()
 525		{
 526			CreateViewModel();
 527			viewModel.PageSize = 3;
 528			viewModel.AddSixFakePackages();
 529
 530			viewModel.ReadPackages();
 531			CompleteReadPackagesTask();
 532
 533			viewModel.ReadPackages();
 534			CompleteReadPackagesTask();
 535
 536			viewModel.ReadPackages();
 537			CompleteReadPackagesTask();
 538			
 539			int count = 0;
 540			viewModel.PropertyChanged += (sender, e) => count++;
 541			viewModel.SelectedPageNumber = 2;
 542			
 543			Assert.AreEqual(1, count);
 544		}
 545		
 546		[Test]
 547		public void IsSearchable_ByDefault_ReturnsFalse()
 548		{
 549			CreateViewModel();
 550			
 551			Assert.IsFalse(viewModel.IsSearchable);
 552		}
 553		
 554		[Test]
 555		public void SearchCommand_SearchTextEntered_PackageViewModelsFilteredBySearchCriteria()
 556		{
 557			CreateViewModel();
 558			viewModel.IsSearchable = true;
 559			viewModel.AddSixFakePackages();
 560			
 561			var package = new FakePackage() {
 562				Id = "SearchedForId",
 563				Description = "Test"
 564			};
 565			viewModel.FakePackages.Add(package);
 566			
 567			viewModel.ReadPackages();
 568			CompleteReadPackagesTask();
 569			
 570			ClearReadPackagesTasks();
 571			viewModel.SearchTerms = "SearchedForId";
 572			viewModel.SearchCommand.Execute(null);
 573			CompleteReadPackagesTask();
 574			
 575			var expectedPackages = new FakePackage[] {
 576				package
 577			};
 578			
 579			PackageCollectionAssert.AreEqual(expectedPackages, viewModel.PackageViewModels);
 580		}
 581		
 582		[Test]
 583		public void PackageExtensionsFind_TwoPackagesInCollection_FindsOnePackageId()
 584		{
 585			List<IPackage> packages = new List<IPackage>();
 586			var package1 = new FakePackage() {
 587				Id = "Test"
 588			};
 589			var package2 = new FakePackage() {
 590				Id = "Another"
 591			};
 592			packages.Add(package1);
 593			packages.Add(package2);
 594			
 595			IQueryable<IPackage> query = packages.AsQueryable();
 596			
 597			IQueryable<IPackage> filteredResults = query.Find("Test");
 598			
 599			IPackage foundPackage = filteredResults.First();
 600			
 601			Assert.AreEqual("Test", foundPackage.Id);
 602		}
 603		
 604		[Test]
 605		public void PackageExtensionsFind_TwoPackagesInCollectionAndQueryableResultsPutInBufferedEnumerable_OnePackageInBufferedEnumerable()
 606		{
 607			List<IPackage> packages = new List<IPackage>();
 608			
 609			// Need to add descriptiosn otherwise we get a null reference when enumerating results 
 610			// in BufferedEnumerable
 611			var package1 = new FakePackage() {
 612				Id = "Test", Description = "b"
 613			};
 614			var package2 = new FakePackage() {
 615				Id = "Another", Description = "a"
 616			};
 617			packages.Add(package1);
 618			packages.Add(package2);
 619			
 620			IQueryable<IPackage> query = packages.AsQueryable();
 621			
 622			IQueryable<IPackage> filteredResults = query.Find("Test");
 623			
 624			var collection = new BufferedEnumerable<IPackage>(filteredResults, 10);
 625			IPackage foundPackage = collection.First();
 626			
 627			Assert.AreEqual("Test", foundPackage.Id);
 628		}
 629		
 630		[Test]
 631		public void Search_SearchTextChangedAndPackagesWerePagedBeforeSearch_PagesUpdatedAfterFilteringBySearchCriteria()
 632		{
 633			CreateViewModel();
 634			viewModel.IsSearchable = true;
 635			viewModel.PageSize = 2;
 636			viewModel.MaximumSelectablePages = 5;
 637			viewModel.AddSixFakePackages();
 638			
 639			var package = new FakePackage() {
 640				Id = "SearchedForId",
 641				Description = "Test"
 642			};
 643			viewModel.FakePackages.Add(package);
 644			
 645			viewModel.ReadPackages();
 646			CompleteReadPackagesTask();
 647			
 648			ObservableCollection<Page> pages = viewModel.Pages;
 649			
 650			ClearReadPackagesTasks();
 651			viewModel.SearchTerms = "SearchedForId";
 652			viewModel.Search();
 653			CompleteReadPackagesTask();
 654			
 655			var expectedPages = new Page[] {
 656				new Page() { Number = 1, IsSelected = true }
 657			};
 658			
 659			PageCollectionAssert.AreEqual(expectedPages, pages);
 660		}
 661		
 662		[Test]
 663		public void Pages_SixPackagesButPackagesNotRead_HasNoPages()
 664		{
 665			CreateViewModel();
 666			viewModel.PageSize = 2;
 667			viewModel.AddSixFakePackages();
 668			
 669			Assert.AreEqual(0, viewModel.Pages.Count);
 670		}
 671		
 672		[Test]
 673		public void HasPreviousPage_SixPackagesAndSecondPageSelectedButPackagesNotRead_ReturnsFalse()
 674		{
 675			CreateViewModel();
 676			viewModel.PageSize = 2;
 677			viewModel.SelectedPageNumber = 2;
 678			viewModel.AddSixFakePackages();
 679			
 680			Assert.IsFalse(viewModel.HasPreviousPage);
 681		}
 682		
 683		[Test]
 684		public void HasNextPage_SixPackagesAndFirstPageSelectedButPackagesNotRead_ReturnsFalse()
 685		{
 686			CreateViewModel();
 687			viewModel.PageSize = 2;
 688			viewModel.SelectedPageNumber = 1;
 689			viewModel.AddSixFakePackages();
 690			
 691			Assert.IsFalse(viewModel.HasNextPage);
 692		}
 693		
 694		[Test]
 695		public void IsPaged_SixPackagesAndFirstPageSelectedButPackagesNotRead_ReturnsFalse()
 696		{
 697			CreateViewModel();
 698			viewModel.PageSize = 2;
 699			viewModel.SelectedPageNumber = 1;
 700			viewModel.AddSixFakePackages();
 701			
 702			Assert.IsFalse(viewModel.IsPaged);
 703		}
 704		
 705		[Test]
 706		public void Search_SelectedPageInitiallyIsPageTwoAndThenUserSearches_SelectedPageNumberIsSetToPageOne()
 707		{
 708			CreateViewModel();
 709			viewModel.PageSize = 2;
 710			viewModel.AddSixFakePackages();
 711			
 712			var package = new FakePackage() {
 713				Id = "SearchedForId",
 714				Description = "Test"
 715			};
 716			viewModel.FakePackages.Add(package);
 717			viewModel.ReadPackages();
 718			CompleteReadPackagesTask();
 719
 720			viewModel.SelectedPageNumber = 2;
 721			
 722			ClearReadPackagesTasks();
 723			viewModel.SearchTerms = "SearchedForId";
 724			viewModel.Search();
 725			CompleteReadPackagesTask();
 726			
 727			Assert.AreEqual(1, viewModel.SelectedPageNumber);
 728		}
 729		
 730		/// <summary>
 731		/// Ensures that the total number of packages is determined from all packages and not
 732		/// the filtered set. All packages will be retrieved from the repository
 733		/// if this is not done when we only want 30 retrieved in one go.
 734		/// </summary>
 735		[Test]
 736		public void ReadPackages_SixPackagesInRepository_TotalItemsSetBeforePackagesFiltered()
 737		{
 738			CreateViewModel();
 739			viewModel.PageSize = 2;
 740			viewModel.AddSixFakePackages();
 741			viewModel.ReadPackages();
 742			CompleteReadPackagesTask();
 743			
 744			int expectedTotal = 6;
 745			Assert.AreEqual(expectedTotal, viewModel.TotalItems);
 746		}
 747		
 748		[Test]
 749		public void Search_ThreePagesOfPackagesBeforeSearchReturnsNoPackages_IsPagedIsFalseWhenPropertyChangedEventFired()
 750		{
 751			CreateViewModel();
 752			viewModel.PageSize = 2;
 753			viewModel.AddSixFakePackages();
 754			viewModel.ReadPackages();
 755			CompleteReadPackagesTask();
 756			
 757			viewModel.SearchTerms = "SearchedForId";
 758			
 759			ClearReadPackagesTasks();
 760			bool paged = true;
 761			viewModel.PropertyChanged += (sender, e) => paged = viewModel.IsPaged;
 762			viewModel.Search();
 763			CompleteReadPackagesTask();
 764			
 765			Assert.IsFalse(paged);
 766		}
 767		
 768		[Test]
 769		public void Search_BeforeSearchFivePagesOfPackagesShownAndSearchReturnsTwoPages_TwoPagesShownAfterSearch()
 770		{
 771			CreateViewModel();
 772			viewModel.IsSearchable = true;
 773			viewModel.PageSize = 2;
 774			viewModel.MaximumSelectablePages = 5;
 775			viewModel.AddSixFakePackages();
 776			
 777			viewModel.FakePackages.Add(new FakePackage("SearchedForId1"));
 778			viewModel.FakePackages.Add(new FakePackage("SearchedForId2"));
 779			viewModel.FakePackages.Add(new FakePackage("SearchedForId3"));
 780			
 781			viewModel.ReadPackages();
 782			CompleteReadPackagesTask();
 783			
 784			ObservableCollection<Page> pages = viewModel.Pages;
 785			
 786			ClearReadPackagesTasks();
 787			viewModel.SearchTerms = "SearchedForId";
 788			viewModel.Search();
 789			CompleteReadPackagesTask();
 790			
 791			var expectedPages = new Page[] {
 792				new Page() { Number = 1, IsSelected = true },
 793				new Page() { Number = 2 }
 794			};
 795			
 796			PageCollectionAssert.AreEqual(expectedPages, pages);
 797		}
 798		
 799		[Test]
 800		public void ShowPackageSources_ByDefault_ReturnsFalse()
 801		{
 802			CreateViewModel();
 803			
 804			Assert.IsFalse(viewModel.ShowPackageSources);
 805		}
 806		
 807		[Test]
 808		public void ReadPackages_OnePackageInRepository_CreatesTask()
 809		{
 810			CreateViewModel();
 811			viewModel.AddOneFakePackage();
 812			
 813			viewModel.ReadPackages();
 814			
 815			Assert.IsTrue(taskFactory.IsCreateTaskCalled);
 816		}
 817		
 818		[Test]
 819		public void ReadPackages_OnePackageInRepository_TaskStartMethodCalled()
 820		{
 821			CreateViewModel();
 822			viewModel.AddOneFakePackage();
 823			
 824			viewModel.ReadPackages();
 825			
 826			Assert.IsTrue(taskFactory.FirstFakeTaskCreated.IsStartCalled);
 827		}
 828		
 829		[Test]
 830		public void IsReadingPackages_ReadPackagesNotCalled_ReturnsFalse()
 831		{
 832			CreateViewModel();
 833			
 834			Assert.IsFalse(viewModel.IsReadingPackages);
 835		}
 836		
 837		[Test]
 838		public void IsReadingPackages_ReadPackagesCalled_ReturnsTrue()
 839		{
 840			CreateViewModel();
 841			viewModel.ReadPackages();
 842			
 843			Assert.IsTrue(viewModel.IsReadingPackages);
 844		}
 845		
 846		[Test]
 847		public void ReadPackages_OnePackageInRepositoryWhenBackgroundTaskExecuted_ReadsOnePackage()
 848		{
 849			CreateViewModel();
 850			viewModel.AddOneFakePackage();
 851			
 852			viewModel.ReadPackages();
 853			
 854			PackagesForSelectedPageResult result = taskFactory.FirstFakeTaskCreated.ExecuteTaskButNotContinueWith();
 855			
 856			CollectionAssert.AreEqual(viewModel.FakePackages, result.Packages);
 857		}
 858		
 859		[Test]
 860		public void ReadPackages_OnePackageInRepositoryWhenFirstPartOfBackgroundTaskExecuted_PackageCountReadInBackgroundTask()
 861		{
 862			CreateViewModel();
 863			viewModel.AddOneFakePackage();
 864			
 865			viewModel.ReadPackages();
 866			
 867			PackagesForSelectedPageResult result = taskFactory.FirstFakeTaskCreated.ExecuteTaskButNotContinueWith();
 868			
 869			Assert.AreEqual(1, result.TotalPackagesOnPage);
 870		}
 871		
 872		[Test]
 873		public void ReadPackages_OnePackageInRepositoryWhenBackgroundTaskExecutedAndResultsReturned_PackagesUpdatedInViewModel()
 874		{
 875			CreateViewModel();
 876			viewModel.AddOneFakePackage();
 877			
 878			viewModel.ReadPackages();
 879			
 880			CompleteReadPackagesTask();
 881			
 882			PackageCollectionAssert.AreEqual(viewModel.FakePackages, viewModel.PackageViewModels);
 883		}
 884		
 885		[Test]
 886		public void IsReadingPackages_OnePackageInRepositoryWhenBackgroundTaskExecutedAndResultsReturned_SetToFalseAfterPackagesRead()
 887		{
 888			CreateViewModel();
 889			viewModel.AddOneFakePackage();
 890			
 891			viewModel.ReadPackages();
 892			
 893			CompleteReadPackagesTask();
 894			
 895			Assert.IsFalse(viewModel.IsReadingPackages);
 896		}
 897		
 898		[Test]
 899		public void IsReadingPackages_OnePackageInRepositoryWhenBackgroundTaskExecutedAndResultsReturned_NotifyPropertyChangedFiredAfterIsReadingPackagesSetToFalse()
 900		{
 901			CreateViewModel();
 902			viewModel.AddOneFakePackage();
 903			
 904			viewModel.ReadPackages();
 905			
 906			bool readingPackages = true;
 907			viewModel.PropertyChanged += (sender, e) => readingPackages = viewModel.IsReadingPackages;
 908			CompleteReadPackagesTask();
 909			
 910			Assert.IsFalse(readingPackages);
 911		}
 912		
 913		[Test]
 914		public void ReadPackages_SixPackagesInRepositoryAndPageSizeIsTwoWhenFirstPartOfBackgroundTaskExecuted_PackageCountReadInBackgroundTask()
 915		{
 916			CreateViewModel();
 917			viewModel.PageSize = 2;
 918			viewModel.AddSixFakePackages();
 919			
 920			viewModel.ReadPackages();
 921			
 922			PackagesForSelectedPageResult result = taskFactory.FirstFakeTaskCreated.ExecuteTaskButNotContinueWith();
 923			
 924			Assert.AreEqual(6, result.TotalPackages);
 925		}
 926		
 927		[Test]
 928		public void ReadPackages_SixPackagesInRepositoryAndPageSizeIsTwoWhenFirstPartOfBackgroundTaskExecuted_PageSizeNotChangedDuringBackgroundTaskExecution()
 929		{
 930			CreateViewModel();
 931			viewModel.PageSize = 2;
 932			viewModel.AddSixFakePackages();
 933			
 934			viewModel.ReadPackages();
 935			
 936			PackagesForSelectedPageResult result = taskFactory.FirstFakeTaskCreated.ExecuteTaskButNotContinueWith();
 937			
 938			Assert.IsFalse(viewModel.IsPaged);
 939		}
 940		
 941		[Test]
 942		public void ReadPackages_SixPackagesInRepositoryAndPageSizeIsTwoWhenBackgroundTaskExecutedAndResultsReturned_ResultsArePaged()
 943		{
 944			CreateViewModel();
 945			viewModel.PageSize = 2;
 946			viewModel.AddSixFakePackages();
 947			
 948			viewModel.ReadPackages();
 949			
 950			CompleteReadPackagesTask();
 951			
 952			Assert.IsTrue(viewModel.IsPaged);
 953		}
 954		
 955		[Test]
 956		public void ReadPackages_CalledSecondTimeBeforeFirstReadPackagesTaskCompletes_FirstReadPackagesTaskIsCancelled()
 957		{
 958			CreateViewModel();
 959			viewModel.AddOneFakePackage();
 960			
 961			viewModel.ReadPackages();
 962			viewModel.ReadPackages();
 963			
 964			Assert.IsTrue(taskFactory.FirstFakeTaskCreated.IsCancelCalled);
 965		}
 966		
 967		[Test]
 968		public void ReadPackages_FirstReadPackagesTaskCompletesAfterBeingCancelled_PackagesNotUpdated()
 969		{
 970			CreateViewModel();
 971			viewModel.AddOneFakePackage();
 972			
 973			viewModel.ReadPackages();
 974			taskFactory.FirstFakeTaskCreated.IsCancelled = true;
 975			viewModel.ReadPackages();
 976			taskFactory.FirstFakeTaskCreated.ExecuteTaskCompletely();
 977			
 978			Assert.AreEqual(0, viewModel.PackageViewModels.Count);
 979		}
 980		
 981		[Test]
 982		public void SelectedPage_ChangedTwoPageTwo_IsReadingPackagesReturnsTrue()
 983		{
 984			CreateViewModel();
 985			viewModel.AddSixFakePackages();
 986			viewModel.ReadPackages();
 987			CompleteReadPackagesTask();
 988			ClearReadPackagesTasks();
 989			
 990			viewModel.SelectedPageNumber = 2;
 991			
 992			Assert.IsTrue(viewModel.IsReadingPackages);
 993		}
 994		
 995		[Test]
 996		public void ReadPackages_SixPackagesDisplayedWhenReadPackagesCalledAgain_DisplayedPackagesAreRemoved()
 997		{
 998			CreateViewModel();
 999			viewModel.AddSixFakePackages();
1000			viewModel.ReadPackages();
1001			CompleteReadPackagesTask();
1002			
1003			viewModel.ReadPackages();
1004			
1005			Assert.AreEqual(0, viewModel.PackageViewModels.Count);
1006		}
1007		
1008		[Test]
1009		public void SelectedPage_ChangedTwoPageTwo_DisplayedPackagesAreRemoved()
1010		{
1011			CreateViewModel();
1012			viewModel.AddSixFakePackages();
1013			viewModel.ReadPackages();
1014			CompleteReadPackagesTask();
1015			ClearReadPackagesTasks();
1016			
1017			viewModel.SelectedPageNumber = 2;
1018			
1019			Assert.AreEqual(0, viewModel.PackageViewModels.Count);
1020		}
1021		
1022		[Test]
1023		public void HasError_BackgroundTaskHasExceptionWhenItFinishes_ReturnsTrue()
1024		{
1025			CreateViewModel();
1026			viewModel.ReadPackages();
1027			taskFactory.FirstFakeTaskCreated.IsFaulted = true;
1028			CompleteReadPackagesTask();
1029			
1030			Assert.IsTrue(viewModel.HasError);
1031		}
1032		
1033		[Test]
1034		public void HasError_ByDefault_ReturnsFalse()
1035		{
1036			CreateViewModel();
1037			
1038			Assert.IsFalse(viewModel.HasError);
1039		}
1040		
1041		[Test]
1042		public void IsReadingPackages_BackgroundTaskHasExceptionWhenItFinishes_ReturnsFalse()
1043		{
1044			CreateViewModel();
1045			viewModel.ReadPackages();
1046			taskFactory.FirstFakeTaskCreated.IsFaulted = true;
1047			CompleteReadPackagesTask();
1048			
1049			Assert.IsFalse(viewModel.IsReadingPackages);
1050		}
1051		
1052		[Test]
1053		public void PropertyChanged_BackgroundTaskHasExceptionWhenItFinishes_PropertyChangedEventFiredWhenTaskCompletes()
1054		{
1055			CreateViewModel();
1056			viewModel.ReadPackages();
1057			taskFactory.FirstFakeTaskCreated.IsFaulted = true;
1058			taskFactory.FirstFakeTaskCreated.ExecuteTaskButNotContinueWith();
1059			
1060			string propertyName = "Nothing";
1061			viewModel.PropertyChanged += (sender, e) => propertyName = e.PropertyName;
1062			taskFactory.FirstFakeTaskCreated.ExecuteContinueWith();
1063			
1064			Assert.IsNull(propertyName);
1065		}
1066		
1067		[Test]
1068		public void ReadPackages_BackgroundTaskHasExceptionWhenItFinishes_PackagesNotUpdated()
1069		{
1070			CreateViewModel();
1071			viewModel.AddSixFakePackages();
1072			viewModel.ReadPackages();
1073			var query = new PackagesForSelectedPageQuery(viewModel, null, null);
1074			taskFactory.FirstFakeTaskCreated.Result = new PackagesForSelectedPageResult(viewModel.FakePackages, query);
1075			taskFactory.FirstFakeTaskCreated.IsFaulted = true;
1076			CompleteReadPackagesTask();
1077			
1078			Assert.AreEqual(0, viewModel.PackageViewModels.Count);
1079		}
1080		
1081		[Test]
1082		public void ErrorMessage_BackgroundTaskHasExceptionWhenItFinishes_ErrorMessageTakenFromException()
1083		{
1084			CreateViewModel();
1085			viewModel.AddSixFakePackages();
1086			viewModel.ReadPackages();
1087			
1088			Exception ex = new Exception("Test");
1089			AggregateException aggregateEx = new AggregateException(ex);
1090			taskFactory.FirstFakeTaskCreated.Exception = aggregateEx;
1091			taskFactory.FirstFakeTaskCreated.IsFaulted = true;
1092			CompleteReadPackagesTask();
1093			
1094			Assert.AreEqual("Test", viewModel.ErrorMessage);
1095		}
1096		
1097		[Test]
1098		public void ErrorMessage_BackgroundTaskHasAggregateExceptionWithNestedInnerAggregateException_ErrorMessageTakenFromInnerException()
1099		{
1100			CreateViewModel();
1101			viewModel.AddSixFakePackages();
1102			viewModel.ReadPackages();
1103			
1104			Exception innerEx1 = new Exception("Test1");
1105			Exception innerEx2 = new Exception("Test2");
1106			AggregateException innerAggregateEx = new AggregateException(innerEx1, innerEx2);
1107			AggregateException aggregateEx = new AggregateException(innerAggregateEx);
1108			taskFactory.FirstFakeTaskCreated.Exception = aggregateEx;
1109			taskFactory.FirstFakeTaskCreated.IsFaulted = true;
1110			CompleteReadPackagesTask();
1111			
1112			string expectedErrorMessage = 
1113				"Test1\r\n" +
1114				"Test2";
1115			
1116			Assert.AreEqual(expectedErrorMessage, viewModel.ErrorMessage);
1117		}
1118		
1119		[Test]
1120		public void ErrorMessage_BackgroundTaskHasAggregateExceptionWithTwoInnerExceptionsWhenItFinishes_ErrorMessageTakenFromAllInnerExceptions()
1121		{
1122			CreateViewModel();
1123			viewModel.AddSixFakePackages();
1124			viewModel.ReadPackages();
1125			
1126			Exception innerEx1 = new Exception("Test1");
1127			Exception innerEx2 = new Exception("Test2");
1128			Exception innerEx3 = new Exception("Test3");
1129			AggregateException aggregateEx = new AggregateException(innerEx1, innerEx2, innerEx3);
1130			taskFactory.FirstFakeTaskCreated.Exception = aggregateEx;
1131			taskFactory.FirstFakeTaskCreated.IsFaulted = true;
1132			CompleteReadPackagesTask();
1133			
1134			string expectedErrorMessage = 
1135				"Test1\r\n" +
1136				"Test2\r\n" +
1137				"Test3";
1138			
1139			Assert.AreEqual(expectedErrorMessage, viewModel.ErrorMessage);
1140		}
1141		
1142		[Test]
1143		public void HasError_ErrorMessageDisplayedAndReadPackagesRetriedAfterFailure_ReturnsFalse()
1144		{
1145			CreateViewModel();
1146			viewModel.ReadPackages();
1147			taskFactory.FirstFakeTaskCreated.IsFaulted = true;
1148			CompleteReadPackagesTask();
1149			viewModel.ReadPackages();
1150			
1151			Assert.IsFalse(viewModel.HasError);
1152		}
1153		
1154		[Test]
1155		public void HasError_ErrorMessageDisplayedAndSelectedPageChangedAfterFailure_ReturnsFalse()
1156		{
1157			CreateViewModel();
1158			viewModel.PageSize = 2;
1159			viewModel.AddSixFakePackages();
1160			viewModel.ReadPackages();
1161			CompleteReadPackagesTask();
1162			ClearReadPackagesTasks();
1163			
1164			viewModel.SelectedPageNumber = 2;
1165			taskFactory.FirstFakeTaskCreated.IsFaulted = true;
1166			CompleteReadPackagesTask();
1167			
1168			viewModel.SelectedPageNumber = 3;
1169			
1170			Assert.IsFalse(viewModel.HasError);
1171		}
1172		
1173		[Test]
1174		public void ReadPackages_PackagesReturnedNotSortedFromRepository_PackagesDisplayedSortedById()
1175		{
1176			CreateViewModel();
1177			viewModel.AddFakePackage("Z");
1178			viewModel.AddFakePackage("C");
1179			viewModel.AddFakePackage("A");
1180			viewModel.AddFakePackage("B");
1181			viewModel.ReadPackages();
1182			
1183			CompleteReadPackagesTask();
1184			
1185			var expectedPackages = new FakePackage[] {
1186				viewModel.FakePackages[2],
1187				viewModel.FakePackages[3],
1188				viewModel.FakePackages[1],
1189				viewModel.FakePackages[0]
1190			};
1191			
1192			PackageCollectionAssert.AreEqual(expectedPackages, viewModel.PackageViewModels);
1193		}
1194		
1195		[Test]
1196		public void SelectedPageNumber_SixPackagesAndPageSizeIsFiveAndSelectedPageNumberIsChangedToTwo_OneReadPackagesTaskCreated()
1197		{
1198			CreateViewModel();
1199			viewModel.PageSize = 5;
1200			viewModel.AddSixFakePackages();
1201			viewModel.ReadPackages();
1202			CompleteReadPackagesTask();
1203			ClearReadPackagesTasks();
1204			
1205			viewModel.SelectedPageNumber = 2;
1206			
1207			Assert.AreEqual(1, taskFactory.FakeTasksCreated.Count);
1208		}
1209		
1210		[Test]
1211		public void SelectedPageNumber_SixPackagesAndSelectedPageNumberIsSetToPageOneButUnchanged_NoReadPackagesTaskCreated()
1212		{
1213			CreateViewModel();
1214			viewModel.PageSize = 5;
1215			viewModel.AddSixFakePackages();
1216			viewModel.ReadPackages();
1217			CompleteReadPackagesTask();
1218			ClearReadPackagesTasks();
1219			
1220			viewModel.SelectedPageNumber = 1;
1221			
1222			Assert.AreEqual(0, taskFactory.FakeTasksCreated.Count);
1223		}
1224		
1225		[Test]
1226		public void SelectedPageNumber_SixPackagesAndPageSizeIsFiveAndSelectedPageNumberIsChangedToTwo_PropertyChangedEventFiredAfterSelectedPageNumberChanged()
1227		{
1228			CreateViewModel();
1229			viewModel.PageSize = 5;
1230			viewModel.AddSixFakePackages();
1231			viewModel.ReadPackages();
1232			CompleteReadPackagesTask();
1233			ClearReadPackagesTasks();
1234			
1235			int selectedPageNumber = 0;
1236			viewModel.PropertyChanged += (source, e) => selectedPageNumber = viewModel.SelectedPageNumber;
1237			viewModel.SelectedPageNumber = 2;
1238			
1239			Assert.AreEqual(2, selectedPageNumber);
1240		}
1241		
1242		[Test]
1243		public void SelectedPageNumber_SixPackagesAndPageSizeIsFiveAndSelectedPageNumberIsChangedToTwo_SelectedPageNumberChangedBeforeReadPackagesTaskStarted()
1244		{
1245			CreateViewModel();
1246			viewModel.PageSize = 5;
1247			viewModel.AddSixFakePackages();
1248			viewModel.ReadPackages();
1249			CompleteReadPackagesTask();
1250			ClearReadPackagesTasks();
1251			
1252			taskFactory.RunTasksSynchronously = true;
1253			viewModel.SelectedPageNumber = 2;
1254			
1255			Assert.AreEqual(1, viewModel.PackageViewModels.Count);
1256		}
1257		
1258		[Test]
1259		public void Search_RepositoryHasPackageWithIdOfEmptyString_SearchCriteriaUsedIsNull()
1260		{
1261			CreateViewModel();
1262			viewModel.PageSize = 2;
1263			viewModel.FakePackages.Add(new FakePackage() {
1264				Id = "",
1265				Description = "abc"
1266			});
1267			taskFactory.RunTasksSynchronously = true;
1268			viewModel.ReadPackages();
1269			
1270			ClearReadPackagesTasks();
1271			
1272			viewModel.SearchTerms = "";
1273			viewModel.Search();
1274			
1275			Assert.IsNull(viewModel.SearchCriteriaPassedToFilterPackagesBySearchCriteria);
1276		}
1277		
1278		[Test]
1279		public void Search_RepositoryHasPackageWithIdOfWhitespaceString_SearchCriteriaUsedIsNull()
1280		{
1281			CreateViewModel();
1282			viewModel.PageSize = 2;
1283			viewModel.FakePackages.Add(new FakePackage() {
1284				Id = "",
1285				Description = "abc"
1286			});
1287			taskFactory.RunTasksSynchronously = true;
1288			viewModel.ReadPackages();
1289			
1290			ClearReadPackagesTasks();
1291			
1292			viewModel.SearchTerms = "   ";
1293			viewModel.Search();
1294			
1295			Assert.IsNull(viewModel.SearchCriteriaPassedToFilterPackagesBySearchCriteria);
1296		}
1297		
1298		[Test]
1299		public void IsDisposed_DisposeMethodCalled_ReturnsTrue()
1300		{
1301			CreateViewModel();
1302			viewModel.Dispose();
1303			
1304			Assert.IsTrue(viewModel.IsDisposed);
1305		}
1306		
1307		[Test]
1308		public void IsDisposed_DisposeMethodNotCalled_ReturnsFalse()
1309		{
1310			CreateViewModel();
1311			
1312			Assert.IsFalse(viewModel.IsDisposed);
1313		}
1314		
1315		[Test]
1316		public void IncludePrerelease_ChangedToTrue_PackagesAreReadAgain()
1317		{
1318			CreateViewModel();
1319			viewModel.IncludePrerelease = false;
1320			viewModel.AddSixFakePackages();
1321			viewModel.ReadPackages();
1322			CompleteReadPackagesTask();
1323			ClearReadPackagesTasks();
1324			
1325			viewModel.IncludePrerelease = true;
1326			
1327			Assert.IsTrue(viewModel.IsReadingPackages);
1328		}
1329		
1330		[Test]
1331		public void IncludePrerelease_ChangedToFalse_PackagesAreReadAgain()
1332		{
1333			CreateViewModel();
1334			viewModel.IncludePrerelease = true;
1335			viewModel.AddSixFakePackages();
1336			viewModel.ReadPackages();
1337			CompleteReadPackagesTask();
1338			ClearReadPackagesTasks();
1339			
1340			viewModel.IncludePrerelease = false;
1341			
1342			Assert.IsTrue(viewModel.IsReadingPackages);
1343		}
1344		
1345		[Test]
1346		public void IncludePrerelease_ChangedToTrue_PropertyChangedEventIsFired()
1347		{
1348			CreateViewModel();
1349			viewModel.IncludePrerelease = false;
1350			viewModel.AddSixFakePackages();
1351			viewModel.ReadPackages();
1352			CompleteReadPackagesTask();
1353			ClearReadPackagesTasks();
1354			PropertyChangedEventArgs propertyChangedEvent = null;
1355			viewModel.PropertyChanged += (sender, e) => propertyChangedEvent = e;
1356			
1357			viewModel.IncludePrerelease = true;
1358			
1359			Assert.IsNull(propertyChangedEvent.PropertyName);
1360		}
1361		
1362		[Test]
1363		public void IncludePrerelease_SetToTrueWhenAlreadyTrue_PropertyChangedEventIsNotFired()
1364		{
1365			CreateViewModel();
1366			viewModel.IncludePrerelease = true;
1367			viewModel.AddSixFakePackages();
1368			viewModel.ReadPackages();
1369			CompleteReadPackagesTask();
1370			ClearReadPackagesTasks();
1371			bool fired = false;
1372			viewModel.PropertyChanged += (sender, e) => fired = true;
1373			
1374			viewModel.IncludePrerelease = true;
1375			
1376			Assert.IsFalse(fired);
1377		}
1378	}
1379}