Example #1
0
        public void UpdatePackageWithMultipleSharedDependencies()
        {
            // Arrange
            var localRepository = new Mock <MockPackageRepository>()
            {
                CallBase = true
            }.As <ISharedPackageRepository>();
            var projectRepository = new MockProjectPackageRepository(localRepository.Object);
            var sourceRepository  = new MockPackageRepository();
            var fileSystem        = new MockFileSystem();
            var projectSystem     = new MockProjectSystem();
            var pathResolver      = new DefaultPackagePathResolver(fileSystem);
            // A1 -> B1, C1
            // A2 -> B1
            var A10 = PackageUtility.CreatePackage("A", "1.0", assemblyReferences: new[] { "A1.dll" }, dependencies: new[] {
                new PackageDependency("B", VersionUtility.ParseVersionSpec("1.0")),
                new PackageDependency("C", VersionUtility.ParseVersionSpec("1.0")),
            });
            var A20 = PackageUtility.CreatePackage("A", "2.0", assemblyReferences: new[] { "A2.dll" }, dependencies: new[] {
                new PackageDependency("B", VersionUtility.ParseVersionSpec("1.0"))
            });
            var B10 = PackageUtility.CreatePackage("B", "1.0", assemblyReferences: new[] { "B1.dll" });
            var C10 = PackageUtility.CreatePackage("C", "1.0", assemblyReferences: new[] { "C1.dll" });

            sourceRepository.AddPackage(A10);
            sourceRepository.AddPackage(A20);
            sourceRepository.AddPackage(B10);
            sourceRepository.AddPackage(C10);
            localRepository.Object.AddPackage(A10);
            localRepository.Object.AddPackage(A20);
            localRepository.Object.AddPackage(B10);
            localRepository.Object.AddPackage(C10);
            var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, fileSystem, localRepository.Object, new Mock <IRecentPackageRepository>().Object);
            var projectManager = new ProjectManager(localRepository.Object, pathResolver, projectSystem, projectRepository);

            projectManager.AddPackageReference("A", new Version("1.0"));

            // Act
            packageManager.UpdatePackage(projectManager, "A", version: null, updateDependencies: true, logger: NullLogger.Instance);

            // Assert
            Assert.IsFalse(packageManager.LocalRepository.Exists(A10));
            Assert.IsFalse(projectSystem.ReferenceExists("A1.dll"));
            Assert.IsFalse(packageManager.LocalRepository.Exists(C10));
            Assert.IsFalse(projectSystem.ReferenceExists("C1.dll"));
            Assert.IsTrue(packageManager.LocalRepository.Exists(B10));
            Assert.IsTrue(projectSystem.ReferenceExists("B1.dll"));
            Assert.IsTrue(packageManager.LocalRepository.Exists(A20));
            Assert.IsTrue(projectSystem.ReferenceExists("A2.dll"));
        }