public void UpdatePackageUpdateToUnlistedPackageIfVersionIsSet(string versionA1, string versionA2) { // Arrange var packageA1 = PackageUtility.CreatePackage("A", versionA1, dependencies: new[] { new PackageDependency("B") }); var packageA2 = PackageUtility.CreatePackage("A", versionA2, listed: false); var sharedRepository = new Mock <ISharedPackageRepository>(); sharedRepository.Setup(s => s.GetPackages()).Returns(new[] { packageA1 }.AsQueryable()); sharedRepository.Setup(s => s.AddPackage(packageA2)).Verifiable(); var packageRepository = new MockPackageRepository { packageA1, packageA2 }; var packageManager = new VsPackageManager(TestUtils.GetSolutionManagerWithProjects("foo"), packageRepository, new Mock <IFileSystemProvider>().Object, new MockFileSystem(), sharedRepository.Object, new Mock <IDeleteOnRestartManager>().Object, new VsPackageInstallerEvents()); var packageManagerFactory = new Mock <IVsPackageManagerFactory>(MockBehavior.Strict); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager); // Act var cmdlet = new UpdatePackageCommand(TestUtils.GetSolutionManager(), packageManagerFactory.Object, null, new Mock <IVsPackageSourceProvider>().Object, new Mock <IHttpClientEvents>().Object, null, new Mock <IVsCommonOperations>().Object, new Mock <IDeleteOnRestartManager>().Object); cmdlet.Id = "A"; cmdlet.Version = new SemanticVersion(versionA2); cmdlet.Execute(); // Assert sharedRepository.Verify(); }
public void UpdatePackageCmdletPassesParametersCorrectlyWhenIdAndVersionAreSpecified() { // Arrange var vsPackageManager = new MockVsPackageManager(); var packageManagerFactory = new Mock <IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(vsPackageManager); var mockPackageRepository = new MockPackageRepository(); var sourceProvider = GetPackageSourceProvider(new PackageSource("somesource")); var repositoryFactory = new Mock <IPackageRepositoryFactory>(); repositoryFactory.Setup(c => c.CreateRepository(It.Is <string>(s => s == "somesource"))).Returns(mockPackageRepository); var cmdlet = new UpdatePackageCommand(TestUtils.GetSolutionManagerWithProjects("foo"), packageManagerFactory.Object, repositoryFactory.Object, sourceProvider, null, null, new Mock <IVsCommonOperations>().Object, new Mock <IDeleteOnRestartManager>().Object); cmdlet.Id = "my-id"; cmdlet.Version = new SemanticVersion("2.8"); cmdlet.ProjectName = "foo"; // Act cmdlet.Execute(); // Assert Assert.Equal("my-id", vsPackageManager.PackageId); Assert.Equal(new SemanticVersion("2.8"), vsPackageManager.Version); }
public void SafeUpdatePackageDoNotUpdateToUnlistedPackage(string versionA1, string versionA2) { // Arrange var packageA1 = PackageUtility.CreatePackage("A", versionA1); var packageA2 = PackageUtility.CreatePackage("A", versionA2, listed: false); var packageRepository = new MockPackageRepository { packageA1, packageA2 }; var packageManager = new MockVsPackageManager2( @"c:\solution", packageRepository); InstallPackage(packageA1.Id, packageA1.Version, packageManager); var installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(new[] { packageA1 }, installedPackages, PackageEqualityComparer.IdAndVersion); var packageManagerFactory = new Mock <IVsPackageManagerFactory>(MockBehavior.Strict); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager); // Act var cmdlet = new UpdatePackageCommand(packageManager.SolutionManager, packageManagerFactory.Object, null, new Mock <IVsPackageSourceProvider>().Object, new Mock <IHttpClientEvents>().Object, null, new Mock <IVsCommonOperations>().Object, new Mock <IDeleteOnRestartManager>().Object); cmdlet.Id = "A"; cmdlet.Safe = true; cmdlet.Execute(); // Assert: Since packageA2 is unlisted, packageA1 is not updated to packageA2. installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(new[] { packageA1 }, installedPackages, PackageEqualityComparer.IdAndVersion); }
public void UpdatePackageCmdletDoNotInvokeProductUpdateCheckWhenSourceIsNotHttpAddress() { // Arrange string source = "ftp://bing.com"; var productUpdateService = new Mock <IProductUpdateService>(); var sourceRepository = new Mock <IPackageRepository>(); sourceRepository.Setup(p => p.Source).Returns(source); var vsPackageManager = new MockVsPackageManager(sourceRepository.Object); var packageManagerFactory = new Mock <IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager(sourceRepository.Object, true)).Returns(vsPackageManager); var sourceProvider = GetPackageSourceProvider(new PackageSource(source, "bing")); var repositoryFactory = new Mock <IPackageRepositoryFactory>(); repositoryFactory.Setup(c => c.CreateRepository(source)).Returns(sourceRepository.Object); var cmdlet = new UpdatePackageCommand(TestUtils.GetSolutionManagerWithProjects("foo"), packageManagerFactory.Object, repositoryFactory.Object, sourceProvider, null, productUpdateService.Object, new Mock <IVsCommonOperations>().Object, new Mock <IDeleteOnRestartManager>().Object); cmdlet.Id = "my-id"; cmdlet.Version = new SemanticVersion("2.8"); cmdlet.IgnoreDependencies = new SwitchParameter(isPresent: true); cmdlet.Source = source; cmdlet.ProjectName = "foo"; // Act cmdlet.Execute(); // Assert productUpdateService.Verify(p => p.CheckForAvailableUpdateAsync(), Times.Never()); }
public void SafeUpdatePackageDoNotUpdateToUnlistedPackage(string versionA1, string versionA2) { // Arrange var packageA1 = PackageUtility.CreatePackage("A", versionA1); var packageA2 = PackageUtility.CreatePackage("A", versionA2, listed: false); var sharedRepository = new MockSharedPackageRepository(); sharedRepository.AddPackage(packageA1); var packageRepository = new MockPackageRepository { packageA1, packageA2 }; var packageManager = new MockVsPackageManager( TestUtils.GetSolutionManagerWithProjects(), packageRepository, sharedRepository); var packageManagerFactory = new Mock <IVsPackageManagerFactory>(MockBehavior.Strict); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager); // Act var cmdlet = new UpdatePackageCommand(TestUtils.GetSolutionManager(), packageManagerFactory.Object, null, new Mock <IVsPackageSourceProvider>().Object, new Mock <IHttpClientEvents>().Object, null, new Mock <IVsCommonOperations>().Object, new Mock <IDeleteOnRestartManager>().Object); cmdlet.Id = "A"; cmdlet.Safe = true; cmdlet.Execute(); // Assert Assert.True(sharedRepository.Contains(packageA1)); Assert.False(sharedRepository.Contains(packageA2)); }
public void UpdatePackageCmdletUsesPackageManangerWithSourceIfSpecified() { // Arrange var packageManagerFactory = new Mock <IVsPackageManagerFactory>(); var vsPackageManager = new MockVsPackageManager(); var sourceVsPackageManager = new MockVsPackageManager(); var mockPackageRepository = new MockPackageRepository(); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(vsPackageManager); packageManagerFactory.Setup(m => m.CreatePackageManager(mockPackageRepository, true)).Returns(sourceVsPackageManager); var sourceProvider = GetPackageSourceProvider(new PackageSource("somesource")); var repositoryFactory = new Mock <IPackageRepositoryFactory>(); repositoryFactory.Setup(c => c.CreateRepository(It.Is <string>(s => s == "somesource"))).Returns(mockPackageRepository); var cmdlet = new UpdatePackageCommand(TestUtils.GetSolutionManagerWithProjects("foo"), packageManagerFactory.Object, repositoryFactory.Object, sourceProvider, null, null, new Mock <IVsCommonOperations>().Object); cmdlet.Source = "somesource"; cmdlet.Id = "my-id"; cmdlet.Version = new SemanticVersion("2.8"); cmdlet.ProjectName = "foo"; // Act cmdlet.Execute(); // Assert Assert.Same(sourceVsPackageManager, cmdlet.PackageManager); }
public void UpdatePackageCmdletSpecifiesReinstallOperationDuringReinstall() { // Arrange var mockPackageRepository = new MockPackageRepository(); var projectManager = new Mock <IProjectManager>(); projectManager.Setup(p => p.LocalRepository).Returns(new MockPackageRepository()); var vsPackageManager = new Mock <IVsPackageManager>(); vsPackageManager.Setup(v => v.SourceRepository).Returns(mockPackageRepository); vsPackageManager.Setup(v => v.GetProjectManager(It.IsAny <Project>())).Returns(projectManager.Object); var packageManagerFactory = new Mock <IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(vsPackageManager.Object); var sourceProvider = GetPackageSourceProvider(new PackageSource("somesource")); var repositoryFactory = new Mock <IPackageRepositoryFactory>(); repositoryFactory.Setup(c => c.CreateRepository(It.Is <string>(s => s == "somesource"))).Returns(mockPackageRepository); var cmdlet = new UpdatePackageCommand( TestUtils.GetSolutionManagerWithProjects("foo"), packageManagerFactory.Object, repositoryFactory.Object, sourceProvider, null, null, new Mock <IVsCommonOperations>().Object, new Mock <IDeleteOnRestartManager>().Object); cmdlet.Id = "my-id"; cmdlet.Reinstall = true; cmdlet.ProjectName = "foo"; // Act cmdlet.Execute(); // Assert Assert.Equal(RepositoryOperationNames.Reinstall, mockPackageRepository.LastOperation); }
public void UpdatePackageCmdletPassesParametersCorrectlyWhenIdAndVersionAreSpecified() { // Arrange var vsPackageManager = new MockVsPackageManager(); var packageManagerFactory = new Mock<IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(vsPackageManager); var mockPackageRepository = new MockPackageRepository(); var sourceProvider = GetPackageSourceProvider(new PackageSource("somesource")); var repositoryFactory = new Mock<IPackageRepositoryFactory>(); repositoryFactory.Setup(c => c.CreateRepository(It.Is<string>(s => s == "somesource"))).Returns(mockPackageRepository); var cmdlet = new UpdatePackageCommand(TestUtils.GetSolutionManagerWithProjects("foo"), packageManagerFactory.Object, repositoryFactory.Object, sourceProvider, null, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object); cmdlet.Id = "my-id"; cmdlet.Version = new SemanticVersion("2.8"); cmdlet.ProjectName = "foo"; // Act cmdlet.Execute(); // Assert Assert.Equal("my-id", vsPackageManager.PackageId); Assert.Equal(new SemanticVersion("2.8"), vsPackageManager.Version); }
public void UpdatePackageCmdletUsesPackageManangerWithSourceIfSpecified() { // Arrange var packageManagerFactory = new Mock<IVsPackageManagerFactory>(); var vsPackageManager = new MockVsPackageManager(); var sourceVsPackageManager = new MockVsPackageManager(); var mockPackageRepository = new MockPackageRepository(); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(vsPackageManager); packageManagerFactory.Setup(m => m.CreatePackageManager(mockPackageRepository, true)).Returns(sourceVsPackageManager); var sourceProvider = GetPackageSourceProvider(new PackageSource("somesource")); var repositoryFactory = new Mock<IPackageRepositoryFactory>(); repositoryFactory.Setup(c => c.CreateRepository(It.Is<string>(s => s == "somesource"))).Returns(mockPackageRepository); var cmdlet = new UpdatePackageCommand(TestUtils.GetSolutionManagerWithProjects("foo"), packageManagerFactory.Object, repositoryFactory.Object, sourceProvider, null, null, new Mock<IVsCommonOperations>().Object); cmdlet.Source = "somesource"; cmdlet.Id = "my-id"; cmdlet.Version = new SemanticVersion("2.8"); cmdlet.ProjectName = "foo"; // Act cmdlet.Execute(); // Assert Assert.Same(sourceVsPackageManager, cmdlet.PackageManager); }
public void UpdatePackageUpdateToUnlistedPackageIfVersionIsSet(string versionA1, string versionA2) { // Arrange var packageA1 = PackageUtility.CreatePackage("A", versionA1, dependencies: new[] { new PackageDependency("B") }); var packageA2 = PackageUtility.CreatePackage("A", versionA2, listed: false); var sharedRepository = new Mock<ISharedPackageRepository>(); sharedRepository.Setup(s => s.GetPackages()).Returns(new[] { packageA1 }.AsQueryable()); sharedRepository.Setup(s => s.AddPackage(packageA2)).Verifiable(); var packageRepository = new MockPackageRepository { packageA1, packageA2 }; var packageManager = new VsPackageManager(TestUtils.GetSolutionManagerWithProjects("foo"), packageRepository, new Mock<IFileSystemProvider>().Object, new MockFileSystem(), sharedRepository.Object, new Mock<IDeleteOnRestartManager>().Object, new VsPackageInstallerEvents()); var packageManagerFactory = new Mock<IVsPackageManagerFactory>(MockBehavior.Strict); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager); // Act var cmdlet = new UpdatePackageCommand(TestUtils.GetSolutionManager(), packageManagerFactory.Object, null, new Mock<IVsPackageSourceProvider>().Object, new Mock<IHttpClientEvents>().Object, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object); cmdlet.Id = "A"; cmdlet.Version = new SemanticVersion(versionA2); cmdlet.Execute(); // Assert sharedRepository.Verify(); }
public void UpdatePackageCmdletDoNotInvokeProductUpdateCheckWhenSourceIsNotHttpAddress() { // Arrange string source = "ftp://bing.com"; var productUpdateService = new Mock<IProductUpdateService>(); var sourceRepository = new Mock<IPackageRepository>(); sourceRepository.Setup(p => p.Source).Returns(source); var vsPackageManager = new MockVsPackageManager(sourceRepository.Object); var packageManagerFactory = new Mock<IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager(sourceRepository.Object, true)).Returns(vsPackageManager); var sourceProvider = GetPackageSourceProvider(new PackageSource(source, "bing")); var repositoryFactory = new Mock<IPackageRepositoryFactory>(); repositoryFactory.Setup(c => c.CreateRepository(source)).Returns(sourceRepository.Object); var cmdlet = new UpdatePackageCommand(TestUtils.GetSolutionManagerWithProjects("foo"), packageManagerFactory.Object, repositoryFactory.Object, sourceProvider, null, productUpdateService.Object, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object); cmdlet.Id = "my-id"; cmdlet.Version = new SemanticVersion("2.8"); cmdlet.IgnoreDependencies = new SwitchParameter(isPresent: true); cmdlet.Source = source; cmdlet.ProjectName = "foo"; // Act cmdlet.Execute(); // Assert productUpdateService.Verify(p => p.CheckForAvailableUpdateAsync(), Times.Never()); }
public void UpdatePackageCmdletSpecifiesReinstallOperationDuringReinstallWhenIdAndProjectNameAreNull() { // Arrange var mockPackageRepository = new MockPackageRepository(); var projectManager = new Mock<IProjectManager>(); projectManager.Setup(p => p.LocalRepository).Returns(new MockPackageRepository()); var vsPackageManager = new Mock<IVsPackageManager>(); vsPackageManager.Setup(v => v.SourceRepository).Returns(mockPackageRepository); vsPackageManager.Setup(v => v.GetProjectManager(It.IsAny<Project>())).Returns(projectManager.Object); var packageManagerFactory = new Mock<IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(vsPackageManager.Object); var sourceProvider = GetPackageSourceProvider(new PackageSource("somesource")); var repositoryFactory = new Mock<IPackageRepositoryFactory>(); repositoryFactory.Setup(c => c.CreateRepository(It.Is<string>(s => s == "somesource"))).Returns(mockPackageRepository); var cmdlet = new UpdatePackageCommand( TestUtils.GetSolutionManagerWithProjects("foo"), packageManagerFactory.Object, repositoryFactory.Object, sourceProvider, null, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object); cmdlet.Reinstall = true; // Act cmdlet.Execute(); // Assert Assert.Equal(RepositoryOperationNames.Reinstall, mockPackageRepository.LastOperation); }
public void UpdatePackageUpdateToUnlistedPackageIfVersionIsSet(string versionA1, string versionA2) { // Arrange var packageA1 = PackageUtility.CreatePackage("A", versionA1); var packageA2 = PackageUtility.CreatePackage("A", versionA2, listed: false); var localRepository = new Mock<MockPackageRepository>() { CallBase = true }; var sharedRepository = localRepository.As<ISharedPackageRepository>(); localRepository.Object.AddPackage(packageA1); var packageRepository = new MockPackageRepository { packageA1, packageA2 }; var packageManager = new MockVsPackageManager( TestUtils.GetSolutionManagerWithProjects(), packageRepository, sharedRepository.Object); var packageManagerFactory = new Mock<IVsPackageManagerFactory>(MockBehavior.Strict); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager); // Act var cmdlet = new UpdatePackageCommand(TestUtils.GetSolutionManager(), packageManagerFactory.Object, null, new Mock<IVsPackageSourceProvider>().Object, new Mock<IHttpClientEvents>().Object, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object); cmdlet.Id = "A"; cmdlet.Version = new SemanticVersion(versionA2); cmdlet.Execute(); // Assert Assert.False(localRepository.Object.Contains(packageA1)); Assert.True(localRepository.Object.Contains(packageA2)); }
public void SafeUpdatePackageDoNotUpdateToUnlistedPackageWithPrerelease(string versionA1, string versionA2) { // Arrange var packageA1 = PackageUtility.CreatePackage("A", versionA1); var packageA2 = PackageUtility.CreatePackage("A", versionA2, listed: false); var sharedRepository = new MockSharedPackageRepository(); sharedRepository.AddPackage(packageA1); var packageRepository = new MockPackageRepository { packageA1, packageA2 }; var packageManager = new MockVsPackageManager( TestUtils.GetSolutionManagerWithProjects(), packageRepository, sharedRepository); var packageManagerFactory = new Mock<IVsPackageManagerFactory>(MockBehavior.Strict); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager); // Act var cmdlet = new UpdatePackageCommand(TestUtils.GetSolutionManager(), packageManagerFactory.Object, null, new Mock<IVsPackageSourceProvider>().Object, new Mock<IHttpClientEvents>().Object, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object); cmdlet.Id = "A"; cmdlet.IncludePrerelease = true; cmdlet.Safe = true; cmdlet.Execute(); // Assert Assert.False(sharedRepository.Contains(packageA2)); }
public void SafeUpdatePackageDoNotUpdateToUnlistedPackage(string versionA1, string versionA2) { // Arrange var packageA1 = PackageUtility.CreatePackage("A", versionA1); var packageA2 = PackageUtility.CreatePackage("A", versionA2, listed: false); var packageRepository = new MockPackageRepository { packageA1, packageA2 }; var packageManager = new MockVsPackageManager2( @"c:\solution", packageRepository); InstallPackage(packageA1.Id, packageA1.Version, packageManager); var installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(new[] { packageA1 }, installedPackages, PackageEqualityComparer.IdAndVersion); var packageManagerFactory = new Mock<IVsPackageManagerFactory>(MockBehavior.Strict); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager); // Act var cmdlet = new UpdatePackageCommand(packageManager.SolutionManager, packageManagerFactory.Object, null, new Mock<IVsPackageSourceProvider>().Object, new Mock<IHttpClientEvents>().Object, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object); cmdlet.Id = "A"; cmdlet.Safe = true; cmdlet.Execute(); // Assert: Since packageA2 is unlisted, packageA1 is not updated to packageA2. installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(new[] { packageA1 }, installedPackages, PackageEqualityComparer.IdAndVersion); }