public void UpdatePackageUpdateToUnlistedPackageIfVersionIsSet(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.Version = new SemanticVersion(versionA2); cmdlet.GetResults(); // Assert: packageA1 is updated to packageA2. installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(new[] { packageA2 }, installedPackages, PackageEqualityComparer.IdAndVersion); }
public void UpdatePackageCmdletThrowsWhenSolutionIsClosed() { // Arrange var packageManagerFactory = new Mock<IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns((IVsPackageManager)null); var cmdlet = new UpdatePackageCommand(TestUtils.GetSolutionManager(isSolutionOpen: false), packageManagerFactory.Object, null, null, null, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object); // Act and Assert ExceptionAssert.Throws<InvalidOperationException>(() => cmdlet.GetResults(), "The current environment doesn't have a solution open."); }
public void UpdatePackageCmdletThrowsWhenSolutionIsClosed() { // Arrange var packageManagerFactory = new Mock <IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns((IVsPackageManager)null); var cmdlet = new UpdatePackageCommand(TestUtils.GetSolutionManager(isSolutionOpen: false), packageManagerFactory.Object, null, null, null, null, new Mock <IVsCommonOperations>().Object, new Mock <IDeleteOnRestartManager>().Object); // Act and Assert ExceptionAssert.Throws <InvalidOperationException>(() => cmdlet.GetResults(), "The current environment doesn't have a solution open."); }
public void UpdatePackageUpdateToUnlistedPackageIfVersionIsSet(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.Version = new SemanticVersion(versionA2); cmdlet.GetResults(); // Assert: packageA1 is updated to packageA2. installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(new[] { packageA2 }, installedPackages, PackageEqualityComparer.IdAndVersion); }