public void UpdatePackagesSetOperationToUpdate1()
        {
            // Arrange
            var localRepository   = new MockSharedPackageRepository();
            var sourceRepository  = new MockPackageRepository();
            var projectRepository = new MockPackageRepository();
            var projectSystem     = new MockProjectSystem();
            var pathResolver      = new DefaultPackagePathResolver(projectSystem);
            var projectManager    = new ProjectManager(localRepository, pathResolver, new MockProjectSystem(), projectRepository);
            var packageManager    = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock <IFileSystemProvider>().Object, projectSystem, localRepository, new Mock <IDeleteOnRestartManager>().Object, new Mock <VsPackageInstallerEvents>().Object);

            var package = PackageUtility.CreatePackage("phuong", "1.0", new[] { "hello" });

            localRepository.AddPackage(package);
            projectRepository.AddPackage(package);

            var package2 = PackageUtility.CreatePackage("phuong", "2.0", new[] { "hello" });

            sourceRepository.AddPackage(package2);

            // Act
            packageManager.UpdatePackages(
                projectManager,
                updateDependencies: true,
                allowPrereleaseVersions: true,
                logger: NullLogger.Instance);

            // Assert
            Assert.Equal("Update", sourceRepository.LastOperation);
            Assert.Equal("phuong", sourceRepository.LastMainPackageId);
            Assert.Equal("2.0", sourceRepository.LastMainPackageVersion);
        }
        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 UpdatePackageWithVersionSpecSetOperationToUpdate()
        {
            // Arrange
            var localRepository   = new MockSharedPackageRepository();
            var sourceRepository  = new MockPackageRepository();
            var projectRepository = new MockPackageRepository();
            var projectSystem     = new MockProjectSystem();
            var pathResolver      = new DefaultPackagePathResolver(projectSystem);
            var projectManager    = new ProjectManager(localRepository, pathResolver, new MockProjectSystem(), projectRepository);

            var project = TestUtils.GetProject("project runway", projectFiles: new[] { "dotnetjunky.cs" });

            var packageManager = new MockVsPackageManager(
                TestUtils.GetSolutionManager(defaultProjectName: "project runway", projects: new[] { project }),
                sourceRepository,
                new Mock <IFileSystemProvider>().Object,
                projectSystem,
                localRepository,
                new Mock <IDeleteOnRestartManager>().Object,
                new Mock <VsPackageInstallerEvents>().Object);

            packageManager.RegisterProjectManager(project, projectManager);

            var package = PackageUtility.CreatePackage("phuong", "1.0", new[] { "hello" });

            localRepository.AddPackage(package);
            projectRepository.AddPackage(package);

            var package2 = PackageUtility.CreatePackage("phuong", "2.0", new[] { "hello" });

            sourceRepository.AddPackage(package2);

            // Act
            packageManager.UpdatePackage(
                "phuong",
                new VersionSpec(new SemanticVersion("1.0")),
                updateDependencies: true,
                allowPrereleaseVersions: true,
                logger: NullLogger.Instance,
                eventListener: new Mock <IPackageOperationEventListener>().Object);

            // Assert
            Assert.Equal("Update", sourceRepository.LastOperation);
            Assert.Equal("phuong", sourceRepository.LastMainPackageId);
            Assert.Null(sourceRepository.LastMainPackageVersion);
        }
Esempio n. 4
0
        public void CallingCheckForMissingPackagesRaisesThePackagesMissingStatusChangedEventWithFalseValue()
        {
            // Scenario:
            // Project's packages.config specifies: A[1.0], B[1.2-alpha]
            // The solution's packages folder contains only A[1.0], B[1.2-alpha]

            // Arrange
            string tempSolutionPath = "x:\\project1";

            var project = new Mock <Project>();

            // setup SolutionManager
            var solutionManager = new Mock <ISolutionManager>();

            solutionManager.Setup(p => p.IsSolutionOpen).Returns(true);
            solutionManager.Setup(p => p.SolutionDirectory).Returns(tempSolutionPath);
            solutionManager.Setup(p => p.GetProjects()).Returns(new[] { project.Object });

            // setup file system
            var fileSystem = new Mock <IFileSystem>();

            fileSystem.Setup(p => p.DirectoryExists(".nuget")).Returns(true);
            fileSystem.Setup(p => p.FileExists(".nuget\\NuGet.exe")).Returns(true);
            fileSystem.Setup(p => p.FileExists(".nuget\\NuGet.targets")).Returns(true);

            var fileSystemProvider = new Mock <IFileSystemProvider>();

            fileSystemProvider.Setup(p => p.GetFileSystem(tempSolutionPath)).Returns(fileSystem.Object);

            // setup VsPackageManager
            var projectFileSystem = new MockFileSystem();

            projectFileSystem.AddFile("packages.config",
                                      @"<?xml version=""1.0"" encoding=""utf-8""?>
                <packages>
                    <package id=""A"" version=""1.0.0.0"" />
                    <package id=""B"" version=""1.2-alpha"" />
                </packages>");

            var packageReferenceRepository = new PackageReferenceRepository(projectFileSystem, projectName: null, sourceRepository: new Mock <ISharedPackageRepository>().Object);
            var projectManager             = new Mock <IProjectManager>();

            projectManager.Setup(p => p.LocalRepository).Returns(packageReferenceRepository);

            var localRepository = new MockSharedPackageRepository();

            localRepository.AddPackage(PackageUtility.CreatePackage("A", "1.0"));
            localRepository.AddPackage(PackageUtility.CreatePackage("B", "1.2-alpha"));

            var packageManager = new Mock <IVsPackageManager>();

            packageManager.Setup(p => p.GetProjectManager(project.Object)).Returns(projectManager.Object);
            packageManager.Setup(p => p.LocalRepository).Returns(localRepository);

            var packageManagerFactory = new Mock <IVsPackageManagerFactory>();

            packageManagerFactory.Setup(p => p.CreatePackageManager()).Returns(packageManager.Object);

            var packageRestore = CreateInstance(
                fileSystemProvider: fileSystemProvider.Object,
                solutionManager: solutionManager.Object,
                packageManagerFactory: packageManagerFactory.Object);

            bool?packagesMissing = null;

            packageRestore.PackagesMissingStatusChanged += (o, e) =>
            {
                packagesMissing = e.PackagesMissing;
            };

            // Act
            packageRestore.CheckForMissingPackages();

            // Assert
            Assert.Equal(false, packagesMissing);
        }