public void ShowUpdatableAddIns()
		{
			CreateAddIns();
			_addIn1.Enabled = true;
			
			// Package to be shown in repository
			FakePackage fakePackage1_old = new FakePackage()
			{
				Id = _addIn1.Manifest.PrimaryIdentity,
				Version = new SemanticVersion(_addIn1.Version),
				Tags = SharpDevelopAddInTag,
				IsLatestVersion = false
			};
			FakePackage fakePackage1_new = new FakePackage()
			{
				Id = _addIn1_new.Manifest.PrimaryIdentity,
				Version = new SemanticVersion(_addIn1_new.Version),
				Tags = SharpDevelopAddInTag,
				IsLatestVersion = true
			};
			FakePackage fakePackage2 = new FakePackage()
			{
				Id = _addIn2.Manifest.PrimaryIdentity,
				Version = new SemanticVersion(_addIn2.Version),
				Tags = SharpDevelopAddInTag,
				IsLatestVersion = true
			};
			
			_addIn1.Properties.Set(ManagedAddIn.NuGetPackageIDManifestAttribute, fakePackage1_old.Id);
			_addIn1.Properties.Set(ManagedAddIn.NuGetPackageVersionManifestAttribute, fakePackage1_old.Version.ToString());
			_addIn2.Properties.Set(ManagedAddIn.NuGetPackageIDManifestAttribute, fakePackage2.Id);
			_addIn2.Properties.Set(ManagedAddIn.NuGetPackageVersionManifestAttribute, fakePackage2.Version.ToString());
			
			// List of NuGet repositories
			List<PackageSource> registeredPackageSources = new List<PackageSource>();
			registeredPackageSources.Add(new PackageSource("", "Test Repository"));
			_services.FakeRepositories.RegisteredPackageSources = registeredPackageSources;
			
			List<IPackageRepository> registeredPackageRepositories = new List<IPackageRepository>();
			FakeCorePackageRepository remoteRepository = new FakeCorePackageRepository();
			remoteRepository.Source = registeredPackageSources[0].Source;
			remoteRepository.ReturnedPackages = (new IPackage[] { fakePackage1_new, fakePackage2 }).AsQueryable();
			_services.FakeRepositories.RegisteredPackageRepositories = registeredPackageRepositories;
			
			// PackageRepository service should return remoteRepository instance
			_services.FakeRepositories.GetRepositoryFromSourceCallback = delegate(PackageSource packageSource)
			{
				return remoteRepository;
			};
			
			FakeCorePackageRepository localRepository = new FakeCorePackageRepository();
			_services.FakeNuGet.FakeCorePackageManager.LocalRepository = localRepository;
			localRepository.ReturnedPackages = (new IPackage[] { fakePackage1_old, fakePackage2 }).AsQueryable();
			
			// Simulate list of AddIns
			_services.FakeSDAddInManagement.RegisteredAddIns.Add(_addIn1);
			_services.FakeSDAddInManagement.RegisteredAddIns.Add(_addIn2);
			
			// Simulation of resolving AddIns <-> NuGet packages
			_services.FakeSetup.GetAddInForNuGetPackageCallback = delegate(IPackage package, bool withAddInsMarkedForInstallation)
			{
				if (package.Id == _addIn1.Properties[ManagedAddIn.NuGetPackageIDManifestAttribute])
				{
					return _addIn1;
				}
				else if (package.Id == _addIn2.Properties[ManagedAddIn.NuGetPackageIDManifestAttribute])
				{
					return _addIn2;
				}
				
				return null;
			};
			
			var viewModel = new AvailableAddInsViewModel(_services);
			viewModel.ReadPackagesAndWaitForUpdate();
			
			Assert.That(viewModel.AddInPackages.Count, Is.EqualTo(2), "AddIn list must contain 2 items.");
			
			AddInPackageViewModelBase firstAddIn = viewModel.AddInPackages[0];
			Assert.That(firstAddIn.Id, Is.EqualTo(_addIn1_new.Manifest.PrimaryIdentity), "Primary identity of 1st AddIn");
			Assert.That(firstAddIn.Name, Is.EqualTo(_addIn1_new.Manifest.PrimaryIdentity), "Name of 1st AddIn");
			Assert.That(firstAddIn.Version, Is.EqualTo(_addIn1_new.Version), "Version of 1st AddIn");
			Assert.That(firstAddIn.IsInstalled, Is.True, "1st AddIn must be 'installed''");
			Assert.That(firstAddIn.IsOffline, Is.False, "1st AddIn must not be 'offline'");
			Assert.That(firstAddIn.IsEnabled, Is.True, "1st AddIn must be 'enabled'");
			Assert.That(firstAddIn.IsUpdate, Is.True, "1st AddIn must be 'update'");
			Assert.That(firstAddIn.IsAdded, Is.False, "1st AddIn must not be 'added'");
			Assert.That(firstAddIn.IsRemoved, Is.False, "1st AddIn must not be 'removed'");
			Assert.That(firstAddIn.HasNuGetConnection, Is.False, "1st AddIn must not have 'NuGet connection'");
			Assert.That(viewModel.AddInPackages[0].IsExternallyReferenced, Is.False, "1st AddIn must not be 'externally referenced'");
			Assert.That(viewModel.AddInPackages[1].IsExternallyReferenced, Is.False, "2nd AddIn must not be 'externally referenced'");
			
			AddInPackageViewModelBase secondAddIn = viewModel.AddInPackages[1];
			Assert.That(secondAddIn.Id, Is.EqualTo(_addIn2.Manifest.PrimaryIdentity), "Primary identity of 2nd AddIn");
			Assert.That(secondAddIn.Name, Is.EqualTo(_addIn2.Manifest.PrimaryIdentity), "Name of 2nd AddIn");
			Assert.That(secondAddIn.Version, Is.EqualTo(_addIn2.Version), "Version of 2nd AddIn");
			Assert.That(secondAddIn.IsInstalled, Is.True, "2nd AddIn must be 'installed''");
			Assert.That(secondAddIn.IsOffline, Is.False, "2nd AddIn must not be 'offline'");
			Assert.That(secondAddIn.IsEnabled, Is.True, "2nd AddIn must be 'enabled'");
			Assert.That(secondAddIn.IsUpdate, Is.False, "2nd AddIn mustnot  be 'update'");
			Assert.That(secondAddIn.IsAdded, Is.False, "2nd AddIn must not be 'added'");
			Assert.That(secondAddIn.IsRemoved, Is.False, "2nd AddIn must not be 'removed'");
			Assert.That(secondAddIn.HasNuGetConnection, Is.False, "2nd AddIn must not have 'NuGet connection'");
		}
		public void ShowInstallableAddIns()
		{
			CreateAddIns();
			_addIn1.Enabled = true;
			
			// Packages to be shown in repository
			FakePackage fakePackage1_old = new FakePackage()
			{
				Id = _addIn1.Manifest.PrimaryIdentity,
				Version = new SemanticVersion(_addIn1.Version),
				Tags = SharpDevelopAddInTag,
				IsLatestVersion = false
			};
			FakePackage fakePackage1_new = new FakePackage()
			{
				Id = _addIn1_new.Manifest.PrimaryIdentity,
				Version = new SemanticVersion(_addIn1_new.Version),
				Tags = SharpDevelopAddInTag,
				IsLatestVersion = true
			};
			FakePackage fakePackage2 = new FakePackage()
			{
				Id = _addIn2.Manifest.PrimaryIdentity,
				Version = new SemanticVersion(_addIn2.Version),
				Tags = SharpDevelopAddInTag,
				IsLatestVersion = true
			};
			
			// List of NuGet repositories
			List<PackageSource> registeredPackageSources = new List<PackageSource>();
			registeredPackageSources.Add(new PackageSource("", "Test Repository"));
			_services.FakeRepositories.RegisteredPackageSources = registeredPackageSources;
			
			List<IPackageRepository> registeredPackageRepositories = new List<IPackageRepository>();
			FakeCorePackageRepository remoteRepository = new FakeCorePackageRepository();
			remoteRepository.Source = registeredPackageSources[0].Source;
			remoteRepository.ReturnedPackages = (new IPackage[] { fakePackage1_old, fakePackage1_new, fakePackage2 }).AsQueryable();
			_services.FakeRepositories.RegisteredPackageRepositories = registeredPackageRepositories;
			
			// PackageRepository service should return remoteRepository instance
			_services.FakeRepositories.GetRepositoryFromSourceCallback = delegate(PackageSource packageSource)
			{
				return remoteRepository;
			};
			
			FakeCorePackageRepository localRepository = new FakeCorePackageRepository();
			_services.FakeNuGet.FakeCorePackageManager.LocalRepository = localRepository;
			localRepository.ReturnedPackages = (new IPackage[] { }).AsQueryable();
			
			var viewModel = new AvailableAddInsViewModel(_services);
			viewModel.ReadPackagesAndWaitForUpdate();
			
			Assert.That(viewModel.AddInPackages.Count, Is.EqualTo(2), "AddIn list must contain 2 items.");
			
			AddInPackageViewModelBase firstAddIn = viewModel.AddInPackages[0];
			Assert.That(firstAddIn.Id, Is.EqualTo(_addIn1_new.Manifest.PrimaryIdentity), "Primary identity of 1st AddIn");
			Assert.That(firstAddIn.Name, Is.EqualTo(_addIn1_new.Manifest.PrimaryIdentity), "Name of 1st AddIn");
			Assert.That(firstAddIn.Version, Is.EqualTo(_addIn1_new.Version), "Version of 1st AddIn");
			Assert.That(firstAddIn.IsInstalled, Is.False, "1st AddIn must not be 'installed''");
			Assert.That(firstAddIn.IsOffline, Is.False, "1st AddIn must not be 'offline'");
			Assert.That(firstAddIn.IsEnabled, Is.True, "1st AddIn must be 'enabled'");
			Assert.That(firstAddIn.IsUpdate, Is.False, "1st AddIn must not be 'update'");
			Assert.That(firstAddIn.IsAdded, Is.False, "1st AddIn must not be 'added'");
			Assert.That(firstAddIn.IsRemoved, Is.False, "1st AddIn must not be 'removed'");
			Assert.That(firstAddIn.HasNuGetConnection, Is.False, "1st AddIn must not have 'NuGet connection'");
			Assert.That(viewModel.AddInPackages[0].IsExternallyReferenced, Is.False, "1st AddIn must not be 'externally referenced'");
			Assert.That(viewModel.AddInPackages[1].IsExternallyReferenced, Is.False, "2nd AddIn must not be 'externally referenced'");
		}
		public void SearchInstallableAddInsWithMultipleReleasesAndDownloadCountSorting()
		{
			CreateAddIns();
			_addIn1.Enabled = true;
			
			// Packages to be shown in repository
			// To test correct sorting we let the newer release of addIn2 appear before the older one.
			FakePackage fakePackage2_new = new FakePackage()
			{
				Id = _addIn2_new.Manifest.PrimaryIdentity,
				Version = new SemanticVersion(_addIn2_new.Version),
				Tags = SharpDevelopAddInTag,
				DownloadCount = 30,
				IsLatestVersion = true
			};
			FakePackage fakePackage1 = new FakePackage()
			{
				Id = _addIn1.Manifest.PrimaryIdentity,
				Version = new SemanticVersion(_addIn1.Version),
				Tags = SharpDevelopAddInTag,
				DownloadCount = 10,
				IsLatestVersion = true
			};
			FakePackage fakePackage2 = new FakePackage()
			{
				Id = _addIn2.Manifest.PrimaryIdentity,
				Version = new SemanticVersion(_addIn2.Version),
				Tags = SharpDevelopAddInTag,
				IsLatestVersion = false
			};
			
			// List of NuGet repositories
			List<PackageSource> registeredPackageSources = new List<PackageSource>();
			registeredPackageSources.Add(new PackageSource("", "Test Repository"));
			_services.FakeRepositories.RegisteredPackageSources = registeredPackageSources;
			
			List<IPackageRepository> registeredPackageRepositories = new List<IPackageRepository>();
			FakeCorePackageRepository remoteRepository = new FakeCorePackageRepository();
			remoteRepository.Source = registeredPackageSources[0].Source;
			remoteRepository.ReturnedPackages = (new IPackage[] { fakePackage2_new, fakePackage1, fakePackage2 }).AsQueryable();
			_services.FakeRepositories.RegisteredPackageRepositories = registeredPackageRepositories;
			
			// PackageRepository service should return remoteRepository instance
			_services.FakeRepositories.GetRepositoryFromSourceCallback = delegate(PackageSource packageSource)
			{
				return remoteRepository;
			};
			
			FakeCorePackageRepository localRepository = new FakeCorePackageRepository();
			_services.FakeNuGet.FakeCorePackageManager.LocalRepository = localRepository;
			localRepository.ReturnedPackages = (new IPackage[] { }).AsQueryable();
			
			var viewModel = new AvailableAddInsViewModel(_services);
			viewModel.ReadPackagesAndWaitForUpdate();
			
			// There must be only 2 packages in list, because user should see only latest releases
			Assert.That(viewModel.AddInPackages.Count, Is.EqualTo(2), "AddIn list must contain 2 items.");
			
			// fakePackage2_new is the first one, because it has a greater download count
			AddInPackageViewModelBase firstAddIn = viewModel.AddInPackages[0];
			Assert.That(firstAddIn.Id, Is.EqualTo(_addIn2_new.Manifest.PrimaryIdentity), "Primary identity of 1st AddIn");
			Assert.That(firstAddIn.Name, Is.EqualTo(_addIn2_new.Manifest.PrimaryIdentity), "Name of 1st AddIn");
			Assert.That(firstAddIn.Version, Is.EqualTo(_addIn2_new.Version), "Version of 1st AddIn");
		}
		public void ShowInstallableAddInsWithPaging()
		{
			CreateAddIns();
			_addIn1.Enabled = true;
			
			// Packages to be shown in repository
			FakePackage[] fakePackages = new FakePackage[35];
			for (int i = 0; i < fakePackages.Length; i++)
			{
				fakePackages[i] = new FakePackage()
				{
					Id = _addIn1.Manifest.PrimaryIdentity + i.ToString("00"),
					Version = new SemanticVersion(_addIn1.Version),
					Tags = SharpDevelopAddInTag,
					IsLatestVersion = true
				};
			}
			
			// List of NuGet repositories
			List<PackageSource> registeredPackageSources = new List<PackageSource>();
			registeredPackageSources.Add(new PackageSource("", "Test Repository"));
			_services.FakeRepositories.RegisteredPackageSources = registeredPackageSources;
			
			List<IPackageRepository> registeredPackageRepositories = new List<IPackageRepository>();
			FakeCorePackageRepository remoteRepository = new FakeCorePackageRepository();
			remoteRepository.Source = registeredPackageSources[0].Source;
			remoteRepository.ReturnedPackages = fakePackages.AsQueryable();
			_services.FakeRepositories.RegisteredPackageRepositories = registeredPackageRepositories;
			
			// PackageRepository service should return remoteRepository instance
			_services.FakeRepositories.GetRepositoryFromSourceCallback = delegate(PackageSource packageSource)
			{
				return remoteRepository;
			};
			
			FakeCorePackageRepository localRepository = new FakeCorePackageRepository();
			_services.FakeNuGet.FakeCorePackageManager.LocalRepository = localRepository;
			localRepository.ReturnedPackages = (new IPackage[] { }).AsQueryable();
			
			var viewModel = new AvailableAddInsViewModel(_services);
			viewModel.ReadPackagesAndWaitForUpdate();
			
			int itemsPerPage = 10;
			int assumedPageCount = (fakePackages.Length / itemsPerPage) + 1;
			Assert.That(viewModel.Pages.Count, Is.EqualTo(assumedPageCount), "There must be " + assumedPageCount + " pages");
			
			// First page
			Assert.That(viewModel.AddInPackages.Count, Is.EqualTo(itemsPerPage), "First page contains " + itemsPerPage + " AddIns.");
			for (int i = 0; i < itemsPerPage; i++)
			{
				int realIndex = i;
				AddInPackageViewModelBase firstAddIn = viewModel.AddInPackages[i];
				Assert.That(firstAddIn.Id, Is.EqualTo(fakePackages[realIndex].Id), "Primary identity of AddIn " + realIndex);
				Assert.That(firstAddIn.Version, Is.EqualTo(fakePackages[realIndex].Version.Version), "Version of AddIn " + realIndex);
			}
			
			viewModel.SetPageAndWaitForUpdate(2);
			
			// Second page
			Assert.That(viewModel.AddInPackages.Count, Is.EqualTo(itemsPerPage), "Second page contains " + itemsPerPage + " AddIns.");
			for (int i = 0; i < itemsPerPage; i++)
			{
				int realIndex = i + itemsPerPage;
				AddInPackageViewModelBase firstAddIn = viewModel.AddInPackages[i];
				Assert.That(firstAddIn.Id, Is.EqualTo(fakePackages[realIndex].Id), "Primary identity of AddIn " + realIndex);
				Assert.That(firstAddIn.Version, Is.EqualTo(fakePackages[realIndex].Version.Version), "Version of AddIn " + realIndex);
			}
			
			viewModel.SetPageAndWaitForUpdate(3);
			
			// Third page
			Assert.That(viewModel.AddInPackages.Count, Is.EqualTo(itemsPerPage), "Third page contains " + itemsPerPage + " AddIns.");
			for (int i = 0; i < itemsPerPage; i++)
			{
				int realIndex = i + (itemsPerPage * 2);
				AddInPackageViewModelBase firstAddIn = viewModel.AddInPackages[i];
				Assert.That(firstAddIn.Id, Is.EqualTo(fakePackages[realIndex].Id), "Primary identity of AddIn " + realIndex);
				Assert.That(firstAddIn.Version, Is.EqualTo(fakePackages[realIndex].Version.Version), "Version of AddIn " + realIndex);
			}
		}
		public void ShowInstalledOfflineAddIns()
		{
			CreateAddIns();
			_addIn1.Enabled = true;
			
			// Empty list of NuGet repositories
			_services.FakeRepositories.RegisteredPackageSources = new List<PackageSource>();
			_services.FakeRepositories.RegisteredPackageRepositories = new List<IPackageRepository>();
			FakeCorePackageRepository localRepository = new FakeCorePackageRepository();
			_services.FakeNuGet.FakeCorePackageManager.LocalRepository = localRepository;
			localRepository.ReturnedPackages = (new IPackage[] { }).AsQueryable();
			
			// Simulate list of AddIns
			_services.FakeSDAddInManagement.RegisteredAddIns.Add(_addIn1);
			_services.FakeSDAddInManagement.RegisteredAddIns.Add(_addIn2);
			
			var viewModel = new InstalledAddInsViewModel(_services);
			viewModel.ReadPackagesAndWaitForUpdate();
			
			Assert.That(viewModel.AddInPackages.Count, Is.EqualTo(2), "AddIn list must contain 2 items.");
			
			AddInPackageViewModelBase firstAddIn = viewModel.AddInPackages[0];
			Assert.That(firstAddIn.Id, Is.EqualTo(_addIn1.Manifest.PrimaryIdentity), "Primary identity of 1st AddIn");
			Assert.That(firstAddIn.Name, Is.EqualTo(_addIn1.Name), "Name of 1st AddIn");
			Assert.That(firstAddIn.Version, Is.EqualTo(_addIn1.Version), "Version of 1st AddIn");
			Assert.That(firstAddIn.IsInstalled, Is.True, "1st AddIn must be 'installed''");
			Assert.That(firstAddIn.IsOffline, Is.True, "1st AddIn must be 'offline'");
			Assert.That(firstAddIn.IsEnabled, Is.True, "1st AddIn must be 'enabled'");
			Assert.That(firstAddIn.IsUpdate, Is.False, "1st AddIn must not be 'update'");
			Assert.That(firstAddIn.IsAdded, Is.False, "1st AddIn must not be 'added'");
			Assert.That(firstAddIn.IsRemoved, Is.False, "1st AddIn must not be 'removed'");
			Assert.That(firstAddIn.HasNuGetConnection, Is.False, "1st AddIn must not have 'NuGet connection'");
			
			// Check 'externally referenced' status of both AddIns
			// (simulating that IsAddInManifestIinExternalPath() returns true for 1st AddIn and false for 2nd)
			_services.FakeSDAddInManagement.IsAddInManifestInExternalPathCallback = (addIn) => addIn == _addIn1;
			Assert.That(viewModel.AddInPackages[0].IsExternallyReferenced, Is.True, "1st AddIn must be 'externally referenced'");
			Assert.That(viewModel.AddInPackages[1].IsExternallyReferenced, Is.False, "2nd AddIn must not be 'externally referenced'");
		}
		public void SearchInstallableAddIns()
		{
			CreateAddIns();
			_addIn1.Enabled = true;
			
			// Packages to be shown in repository
			FakePackage fakePackage1 = new FakePackage()
			{
				Id = _addIn1.Manifest.PrimaryIdentity,
				Version = new SemanticVersion(_addIn1.Version),
				Tags = SharpDevelopAddInTag,
				IsLatestVersion = true
			};
			FakePackage fakePackage2 = new FakePackage()
			{
				Id = _addIn2.Manifest.PrimaryIdentity,
				Version = new SemanticVersion(_addIn2.Version),
				Tags = SharpDevelopAddInTag,
				IsLatestVersion = true
			};
			
			// List of NuGet repositories
			List<PackageSource> registeredPackageSources = new List<PackageSource>();
			registeredPackageSources.Add(new PackageSource("", "Test Repository"));
			_services.FakeRepositories.RegisteredPackageSources = registeredPackageSources;
			
			List<IPackageRepository> registeredPackageRepositories = new List<IPackageRepository>();
			FakeCorePackageRepository remoteRepository = new FakeCorePackageRepository();
			remoteRepository.Source = registeredPackageSources[0].Source;
			remoteRepository.ReturnedPackages = (new IPackage[] { fakePackage1, fakePackage2 }).AsQueryable();
			_services.FakeRepositories.RegisteredPackageRepositories = registeredPackageRepositories;
			
			// PackageRepository service should return remoteRepository instance
			_services.FakeRepositories.GetRepositoryFromSourceCallback = delegate(PackageSource packageSource)
			{
				return remoteRepository;
			};
			
			FakeCorePackageRepository localRepository = new FakeCorePackageRepository();
			_services.FakeNuGet.FakeCorePackageManager.LocalRepository = localRepository;
			localRepository.ReturnedPackages = (new IPackage[] { }).AsQueryable();
			
			var viewModel = new AvailableAddInsViewModel(_services);
			viewModel.SearchTerms = fakePackage2.Id;
			viewModel.ReadPackagesAndWaitForUpdate();
			
			Assert.That(viewModel.AddInPackages.Count, Is.EqualTo(1), "AddIn list must contain 1 item.");
			
			AddInPackageViewModelBase firstAddIn = viewModel.AddInPackages[0];
			Assert.That(firstAddIn.Id, Is.EqualTo(_addIn2.Manifest.PrimaryIdentity), "Primary identity of 1st AddIn");
			Assert.That(firstAddIn.Name, Is.EqualTo(_addIn2.Manifest.PrimaryIdentity), "Name of 1st AddIn");
			Assert.That(firstAddIn.Version, Is.EqualTo(_addIn2.Version), "Version of 1st AddIn");
		}
		public void ShowNuGetAddInMarkedForUninstallation()
		{
			CreateAddIns();
			_addIn1.Enabled = true;
			_addIn1.Action = AddInAction.Uninstall;
			
			// Create a fake package
			FakePackage fakePackage = new FakePackage()
			{
				Id = _addIn1.Manifest.PrimaryIdentity,
				Version = new SemanticVersion(_addIn1.Version),
				Tags = SharpDevelopAddInTag
			};
			_addIn1.Properties.Set(ManagedAddIn.NuGetPackageIDManifestAttribute, fakePackage.Id);
			_addIn1.Properties.Set(ManagedAddIn.NuGetPackageVersionManifestAttribute, fakePackage.Version.ToString());
			
			// Empty list of NuGet repositories
			_services.FakeRepositories.RegisteredPackageSources = new List<PackageSource>();
			_services.FakeRepositories.RegisteredPackageRepositories = new List<IPackageRepository>();
			FakeCorePackageRepository localRepository = new FakeCorePackageRepository();
			_services.FakeNuGet.FakeCorePackageManager.LocalRepository = localRepository;
			localRepository.ReturnedPackages = (new IPackage[] { fakePackage }).AsQueryable();
			
			// Simulate list of AddIns
			_services.FakeSDAddInManagement.RegisteredAddIns.Add(_addIn1);
			_services.FakeSDAddInManagement.RegisteredAddIns.Add(_addIn2);
			
			var viewModel = new InstalledAddInsViewModel(_services);
			viewModel.ReadPackagesAndWaitForUpdate();
			
			Assert.That(viewModel.AddInPackages.Count, Is.EqualTo(2), "AddIn list must contain 2 items.");
			
			AddInPackageViewModelBase firstAddIn = viewModel.AddInPackages[0];
			Assert.That(firstAddIn.Id, Is.EqualTo(_addIn1.Manifest.PrimaryIdentity), "Primary identity of 1st AddIn");
			Assert.That(firstAddIn.Name, Is.EqualTo(_addIn1.Name), "Name of 1st AddIn");
			Assert.That(firstAddIn.Version, Is.EqualTo(_addIn1.Version), "Version of 1st AddIn must be the one of the update");
			Assert.That(firstAddIn.IsInstalled, Is.True, "1st AddIn must be 'installed''");
			Assert.That(firstAddIn.IsOffline, Is.True, "1st AddIn must be 'offline'");
			Assert.That(firstAddIn.IsEnabled, Is.True, "1st AddIn must be 'enabled'");
			Assert.That(firstAddIn.IsUpdate, Is.False, "1st AddIn must not be 'update'");
			Assert.That(firstAddIn.IsAdded, Is.False, "1st AddIn must not be 'added'");;
			Assert.That(firstAddIn.IsRemoved, Is.True, "1st AddIn must be 'removed'");
			Assert.That(firstAddIn.HasNuGetConnection, Is.True, "1st AddIn must have 'NuGet connection'");
		}
Exemplo n.º 8
0
        public void InstallAddInFromNuGetPackageAndInvalidUpdateCancel()
        {
            CreateAddIns();

            // Create a fake package
            FakePackage fakePackage = new FakePackage()
            {
                Id = _addIn1.Manifest.PrimaryIdentity,
                Version = new SemanticVersion(_addIn1.Version)
            };

            // Prepare all (fake) services needed for AddInSetup and its instance, itself
            PrepareAddInSetup();

            // Prepare event handlers
            bool addInInstalledEventReceived = false;
            _events.AddInInstalled += delegate(object sender, AddInInstallationEventArgs e)
            {
                if (e.AddIn.Manifest.PrimaryIdentity == _addIn1.Manifest.PrimaryIdentity)
                {
                    addInInstalledEventReceived = true;
                }
            };
            bool addInUninstalledEventReceived = false;
            _events.AddInUninstalled += delegate(object sender, AddInInstallationEventArgs e)
            {
                if (e.AddIn.Manifest.PrimaryIdentity == _addIn1.Manifest.PrimaryIdentity)
                {
                    addInUninstalledEventReceived = true;
                }
            };
            bool nuGetPackageUninstalled = false;
            _nuGet.FakeCorePackageManager.UninstallPackageCallback = delegate(IPackage package, bool forceRemove, bool removeDependencies)
            {
                if ((package == fakePackage) && forceRemove && !removeDependencies)
                {
                    nuGetPackageUninstalled = true;
                }
            };

            // Simulate download by NuGet Core PackageManager
            _sdAddInManagement.AddInToLoad = _addIn1;
            _events.OnAddInPackageDownloaded(new PackageOperationEventArgs(fakePackage, null, "TestResources"));

            // The AddIn must have been added to AddInTree
            Assert.That(_sdAddInManagement.RegisteredAddIns, Contains.Item(_addIn1), "AddIn object added to AddInTree");

            // Look if we find a ManagedAddIn object for the new AddIn
            var foundAddIns =
                _addInSetup.AddInsWithMarkedForInstallation.Where(ma => ma.AddIn.Manifest.PrimaryIdentity == _addIn1.Manifest.PrimaryIdentity);

            Assert.That(foundAddIns.Any(), "ManagedAddIn found in AddInsWithMarkedForInstallation");

            var foundAddIn = foundAddIns.First();
            Assert.That(foundAddIn.IsTemporary, Is.True, "ManagedAddIn is temporary");
            Assert.That(foundAddIn.IsUpdate, Is.False, "ManagedAddIn is not an update");
            Assert.That(foundAddIn.InstallationSource, Is.EqualTo(AddInInstallationSource.NuGetRepository), "ManagedAddIn's installation source is 'NuGet'");

            Assert.That(addInInstalledEventReceived, "AddInInstalled event sent with correct AddIn");

            // Cancel the installation
            _sdAddInManagement.TempInstallDirectory = "";
            _sdAddInManagement.UserInstallDirectory = "";

            FakeCorePackageRepository localRepository = new FakeCorePackageRepository();
            _nuGet.FakeCorePackageManager.LocalRepository = localRepository;
            localRepository.ReturnedPackages = (new IPackage[] { fakePackage }).AsQueryable();

            _addInSetup.CancelUpdate(_addIn1);

            // Now check AddInTree, again
            foundAddIns =
                _addInSetup.AddInsWithMarkedForInstallation.Where(ma => ma.AddIn.Manifest.PrimaryIdentity == _addIn1.Manifest.PrimaryIdentity);

            Assert.That(foundAddIns.Any(), "ManagedAddIn still found in AddInsWithMarkedForInstallation");
            Assert.That(_sdAddInManagement.RemovedExternalAddIns.Contains(_addIn1), Is.False, "External AddIn has not been removed.");

            Assert.That(addInUninstalledEventReceived, Is.False, "AddInUninstalled event sent with correct AddIn");
            Assert.That(nuGetPackageUninstalled, Is.False, "Downloaded NuGet package should be uninstalled.");
        }
Exemplo n.º 9
0
        public void UpdateAddInFromDownloadedNuGetPackageWithOlderOfflineAddInAndCancel()
        {
            CreateAddIns();

            // Create fake packages
            FakePackage fakePackage = new FakePackage()
            {
                Id = _addIn1_new.Manifest.PrimaryIdentity,
                Version = new SemanticVersion(_addIn1_new.Version)
            };
            _addIn1_new.Properties[ManagedAddIn.NuGetPackageIDManifestAttribute] = _addIn1_new.Manifest.PrimaryIdentity;
            _addIn1_new.Properties[ManagedAddIn.NuGetPackageVersionManifestAttribute] = _addIn1_new.Version.ToString();

            // Prepare all (fake) services needed for AddInSetup and its instance, itself
            PrepareAddInSetup();

            // Prepare event handlers
            bool addInInstalledEventReceived = false;
            _events.AddInInstalled += delegate(object sender, AddInInstallationEventArgs e)
            {
                if (e.AddIn.Manifest.PrimaryIdentity == _addIn1_new.Manifest.PrimaryIdentity)
                {
                    addInInstalledEventReceived = true;
                }
            };
            bool addInUninstalledEventReceived = false;
            _events.AddInUninstalled += delegate(object sender, AddInInstallationEventArgs e)
            {
                if (e.AddIn.Manifest.PrimaryIdentity == _addIn1_new.Manifest.PrimaryIdentity)
                {
                    addInUninstalledEventReceived = true;
                }
            };
            bool nuGetPackageUninstalled = false;
            _nuGet.FakeCorePackageManager.UninstallPackageCallback = delegate(IPackage package, bool forceRemove, bool removeDependencies)
            {
                if ((package == fakePackage) && forceRemove && !removeDependencies)
                {
                    nuGetPackageUninstalled = true;
                }
            };

            // This AddIn is already installed
            _sdAddInManagement.RegisteredAddIns.Add(_addIn1_new);
            FakeCorePackageRepository localRepository = new FakeCorePackageRepository();
            _nuGet.FakeCorePackageManager.LocalRepository = localRepository;
            localRepository.ReturnedPackages = (new IPackage[] { fakePackage }).AsQueryable();

            // Install the new version of AddIn from manifest
            _sdAddInManagement.AddInToLoad = _addIn1;
            AddIn installedAddIn = _addInSetup.InstallAddIn(@"TestResources\AddInManager2Test.sdaddin");

            // Test updated AddIn in AddInTree
            Assert.That(installedAddIn, Is.Not.Null, "InstallAddIn() returns valid AddIn object");
            Assert.That(_sdAddInManagement.RegisteredAddIns, Contains.Item(_addIn1_new), "Old AddIn object still in AddInTree");
            Assert.That(_sdAddInManagement.RegisteredAddIns.Contains(_addIn1), Is.Not.True,
                        "New AddIn object not in AddInTree");

            // Look if we find a ManagedAddIn object for the new AddIn
            var foundAddIns =
                _addInSetup.AddInsWithMarkedForInstallation.Where(ma => ma.AddIn.Manifest.PrimaryIdentity == _addIn1_new.Manifest.PrimaryIdentity);

            Assert.That(foundAddIns.Any(), "ManagedAddIn found in AddInsWithMarkedForInstallation");

            var foundAddIn = foundAddIns.First();
            Assert.That(foundAddIn.AddIn.Version, Is.EqualTo(_addIn1.Version), "ManagedAddIn must have new version");
            Assert.That(foundAddIn.OldVersion, Is.EqualTo(_addIn1_new.Version), "ManagedAddIn must know installed (old) version");
            Assert.That(foundAddIn.IsTemporary, Is.True, "ManagedAddIn is temporary");
            Assert.That(foundAddIn.IsUpdate, Is.True, "ManagedAddIn is an update");
            Assert.That(foundAddIn.InstallationSource, Is.EqualTo(AddInInstallationSource.Offline), "ManagedAddIn's installation source is 'offline'");

            Assert.That(addInInstalledEventReceived, "AddInInstalled event sent with correct AddIn");

            // Cancel the update
            _sdAddInManagement.TempInstallDirectory = "";
            _sdAddInManagement.UserInstallDirectory = "";
            _addInSetup.CancelUpdate(_addIn1);

            // Now check AddInTree, again
            foundAddIns =
                _addInSetup.AddInsWithMarkedForInstallation.Where(ma => ma.AddIn.Manifest.PrimaryIdentity == _addIn1_new.Manifest.PrimaryIdentity);

            Assert.That(foundAddIns.Any(), "ManagedAddIn still found in AddInsWithMarkedForInstallation after cancel");

            foundAddIn = foundAddIns.First();
            Assert.That(foundAddIn.AddIn.Version, Is.EqualTo(_addIn1_new.Version), "ManagedAddIn now has old version");

            Assert.That(addInUninstalledEventReceived, "AddInUninstalled event sent with correct AddIn");
            Assert.That(nuGetPackageUninstalled, Is.False, "Already installed NuGet package must not be removed.");
        }
Exemplo n.º 10
0
        public void UninstallValidNuGetAddIn()
        {
            CreateAddIns();

            // Create a fake package
            FakePackage fakePackage = new FakePackage()
            {
                Id = _addIn1.Manifest.PrimaryIdentity,
                Version = new SemanticVersion(_addIn1.Version)
            };

            // Prepare all (fake) services needed for AddInSetup and its instance, itself
            PrepareAddInSetup();

            // Prepare event handlers
            bool addInUninstalledEventReceived = false;
            _events.AddInUninstalled += delegate(object sender, AddInInstallationEventArgs e)
            {
                if (e.AddIn.Manifest.PrimaryIdentity == _addIn1.Manifest.PrimaryIdentity)
                {
                    addInUninstalledEventReceived = true;
                }
            };

            // Simulate an installed AddIn
            _sdAddInManagement.TempInstallDirectory = "";
            _sdAddInManagement.UserInstallDirectory = "";
            _sdAddInManagement.RegisteredAddIns.Add(_addIn1);

            // Simulate the installed NuGet package in local repository
            FakeCorePackageRepository localRepository = new FakeCorePackageRepository();
            _nuGet.FakeCorePackageManager.LocalRepository = localRepository;
            localRepository.ReturnedPackages = (new IPackage[] { fakePackage }).AsQueryable();
            bool nuGetPackageUninstalled = false;
            _nuGet.FakeCorePackageManager.UninstallPackageCallback = delegate(IPackage package, bool forceRemove, bool removeDependencies)
            {
                if ((package == fakePackage) && forceRemove && !removeDependencies)
                {
                    nuGetPackageUninstalled = true;
                }
            };

            // Remove the AddIn
            _addInSetup.UninstallAddIn(_addIn1);

            Assert.That(addInUninstalledEventReceived, "AddInUninstalled event sent with correct AddIn");
            Assert.That(_addIn1.Action, Is.EqualTo(AddInAction.Uninstall), "AddIn action must be set to 'Uninstall'");

            // Simulate removing unreferenced NuGet packages
            _addInSetup.RemoveUnreferencedNuGetPackages();

            Assert.That(nuGetPackageUninstalled, Is.True, "NuGet package must be removed after restart.");
        }
Exemplo n.º 11
0
        public void RemoveUnreferencedNuGetPackage()
        {
            CreateAddIns();

            // Create a fake package
            FakePackage fakePackage1 = new FakePackage()
            {
                Id = _addIn1.Manifest.PrimaryIdentity,
                Version = new SemanticVersion(_addIn1.Version)
            };
            _addIn1.Properties.Set(ManagedAddIn.NuGetPackageIDManifestAttribute, fakePackage1.Id);
            _addIn1.Properties.Set(ManagedAddIn.NuGetPackageVersionManifestAttribute, fakePackage1.Version.ToString());
            FakePackage fakePackage1_new = new FakePackage()
            {
                Id = _addIn1_new.Manifest.PrimaryIdentity,
                Version = new SemanticVersion(_addIn1_new.Version)
            };
            _addIn1_new.Properties.Set(ManagedAddIn.NuGetPackageIDManifestAttribute, fakePackage1_new.Id);
            _addIn1_new.Properties.Set(ManagedAddIn.NuGetPackageVersionManifestAttribute, fakePackage1_new.Version.ToString());
            FakePackage fakePackage2 = new FakePackage()
            {
                Id = _addIn2.Manifest.PrimaryIdentity,
                Version = new SemanticVersion(_addIn2.Version)
            };
            _addIn2.Properties.Set(ManagedAddIn.NuGetPackageIDManifestAttribute, fakePackage2.Id);
            _addIn2.Properties.Set(ManagedAddIn.NuGetPackageVersionManifestAttribute, fakePackage2.Version.ToString());

            // Prepare all (fake) services needed for AddInSetup and its instance, itself
            PrepareAddInSetup();

            // Simulate an installed AddIn, which is not related to installed NuGet package
            _sdAddInManagement.TempInstallDirectory = "";
            _sdAddInManagement.UserInstallDirectory = "";

            // Simulate the installed NuGet package in local repository
            FakeCorePackageRepository localRepository = new FakeCorePackageRepository();
            _nuGet.FakeCorePackageManager.LocalRepository = localRepository;
            bool nuGetPackageUninstalled = false;
            IPackage packageForUninstallEvent = null;
            _nuGet.FakeCorePackageManager.UninstallPackageCallback = delegate(IPackage package, bool forceRemove, bool removeDependencies)
            {
                if ((package == packageForUninstallEvent) && forceRemove && !removeDependencies)
                {
                    nuGetPackageUninstalled = true;
                }
            };

            // Case 1: AddIn of local NuGet package is completely same as installed
            nuGetPackageUninstalled = false;
            localRepository.ReturnedPackages = (new IPackage[] { fakePackage1 }).AsQueryable();
            packageForUninstallEvent = fakePackage1;
            _sdAddInManagement.RegisteredAddIns.Clear();
            _sdAddInManagement.RegisteredAddIns.Add(_addIn1);
            _addInSetup.RemoveUnreferencedNuGetPackages();
            Assert.That(nuGetPackageUninstalled, Is.False, "fakePackage1 must not be removed, because identical to installed.");

            // Case 2: AddIn of local NuGet package not installed at all
            nuGetPackageUninstalled = false;
            localRepository.ReturnedPackages = (new IPackage[] { fakePackage1 }).AsQueryable();
            packageForUninstallEvent = fakePackage1;
            _sdAddInManagement.RegisteredAddIns.Clear();
            _sdAddInManagement.RegisteredAddIns.Add(_addIn2);
            _addInSetup.RemoveUnreferencedNuGetPackages();
            Assert.That(nuGetPackageUninstalled, Is.True, "fakePackage1 must be removed, because unreferenced.");

            // Case 3a: AddIn of local NuGet package is older than the one installed
            nuGetPackageUninstalled = false;
            localRepository.ReturnedPackages = (new IPackage[] { fakePackage1 }).AsQueryable();
            packageForUninstallEvent = fakePackage1;
            _sdAddInManagement.RegisteredAddIns.Clear();
            _sdAddInManagement.RegisteredAddIns.Add(_addIn1_new);
            _addInSetup.RemoveUnreferencedNuGetPackages();
            Assert.That(nuGetPackageUninstalled, Is.False, "fakePackage1 must not be removed, because older but the only one.");

            // Case 3b: There exists a local NuGet package identical to installed AddIn and an older one
            nuGetPackageUninstalled = false;
            localRepository.ReturnedPackages = (new IPackage[] { fakePackage1, fakePackage1_new }).AsQueryable();
            packageForUninstallEvent = fakePackage1;
            _sdAddInManagement.RegisteredAddIns.Clear();
            _sdAddInManagement.RegisteredAddIns.Add(_addIn1_new);
            _addInSetup.RemoveUnreferencedNuGetPackages();
            Assert.That(nuGetPackageUninstalled, Is.True, "fakePackage1 must be removed, because older and a better fitting package exists.");

            // Case 4a: AddIn of local NuGet package is newer than the one installed
            nuGetPackageUninstalled = false;
            localRepository.ReturnedPackages = (new IPackage[] { fakePackage1_new }).AsQueryable();
            packageForUninstallEvent = fakePackage1_new;
            _sdAddInManagement.RegisteredAddIns.Clear();
            _sdAddInManagement.RegisteredAddIns.Add(_addIn1);
            _addInSetup.RemoveUnreferencedNuGetPackages();
            Assert.That(nuGetPackageUninstalled, Is.False, "fakePackage1_new must not be removed, because newer but the only one.");

            // Case 4b: There exists a local NuGet package identical to installed AddIn and a newer one
            nuGetPackageUninstalled = false;
            localRepository.ReturnedPackages = (new IPackage[] { fakePackage1, fakePackage1_new }).AsQueryable();
            packageForUninstallEvent = fakePackage1_new;
            _sdAddInManagement.RegisteredAddIns.Clear();
            _sdAddInManagement.RegisteredAddIns.Add(_addIn1);
            _addInSetup.RemoveUnreferencedNuGetPackages();
            Assert.That(nuGetPackageUninstalled, Is.True, "fakePackage1_new must be removed, because newer and a better fitting package exists.");

            // Case 5: Installed AddIn has no NuGet version tag in manifest, and there are two versions of local NuGet packages
            nuGetPackageUninstalled = false;
            _addIn1.Properties.Remove(ManagedAddIn.NuGetPackageVersionManifestAttribute);
            localRepository.ReturnedPackages = (new IPackage[] { fakePackage1, fakePackage1_new }).AsQueryable();
            packageForUninstallEvent = fakePackage1;
            _sdAddInManagement.RegisteredAddIns.Clear();
            _sdAddInManagement.RegisteredAddIns.Add(_addIn1);
            _addInSetup.RemoveUnreferencedNuGetPackages();
            Assert.That(nuGetPackageUninstalled, Is.True, "fakePackage1 must be removed, only the latest package is left for AddIn without version info.");
        }