コード例 #1
0
        public void GetPackagesCacheResultsWhenIncludePrereleaseIsTrue()
        {
            // Arrange
            MockPackageRepository localRepository = new MockPackageRepository();

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

            MockPackageRepository sourceRepository = new MockPackageRepository();

            sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "1.5-alpha"));


            PackagesProviderBase provider = new MockPackagesProvider();

            IVsExtensionsTreeNode parentTreeNode = new Mock <IVsExtensionsTreeNode>().Object;
            var node = new UpdatesTreeNode(provider, "Mock", parentTreeNode, localRepository, sourceRepository);

            // Act 1
            var packages = node.GetPackages(searchTerm: null, allowPrereleaseVersions: true).ToList();

            // Assert 1
            Assert.Equal(1, packages.Count);
            AssertPackage(packages[0], "A", "1.5-alpha");

            // Act 2

            // now we modify the source repository to test if the GetPackages() return the old results
            sourceRepository.AddPackage(PackageUtility.CreatePackage("B", "2.0-beta"));
            packages = node.GetPackages(searchTerm: null, allowPrereleaseVersions: true).ToList();

            // Assert 2
            Assert.Equal(1, packages.Count);
            AssertPackage(packages[0], "A", "1.5-alpha");
        }
コード例 #2
0
        public void GetPackagesReturnsUpdatesIgnoreConstraintIfConstraintIsNull()
        {
            // Arrange
            var localRepository = new Mock <IPackageRepository>();

            localRepository.Setup(l => l.GetPackages()).Returns(new IPackage[] { PackageUtility.CreatePackage("A", "1.0") }.AsQueryable());

            Mock <IPackageConstraintProvider> constraintProvider = localRepository.As <IPackageConstraintProvider>();

            constraintProvider.Setup(c => c.GetConstraint("A")).Returns((IVersionSpec)null);

            MockPackageRepository sourceRepository = new MockPackageRepository();

            sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "1.5"));
            sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "2.5"));

            UpdatesTreeNode node = CreateUpdatesTreeNode(localRepository.Object, sourceRepository, includePrerelease: false);

            // Act
            var packages = node.GetPackages(searchTerm: null, allowPrereleaseVersions: true).ToList();

            // Assert
            Assert.Equal(1, packages.Count);
            AssertPackage(packages[0], "A", "2.5");
        }
コード例 #3
0
        public void GetPackagesFindsUpdatesForFilteredSetOfPackages()
        {
            // Arrange
            var packageA        = PackageUtility.CreatePackage("Foo", "1.0");
            var packageB        = PackageUtility.CreatePackage("Qux", "1.0");
            var localRepository = new MockPackageRepository {
                packageA, packageB
            };
            IEnumerable <IPackage> actual = null;

            var sourceRepository = new Mock <IServiceBasedRepository>(MockBehavior.Strict);

            sourceRepository.Setup(s => s.GetUpdates(It.IsAny <IEnumerable <IPackage> >(), true, false, It.IsAny <IEnumerable <FrameworkName> >(), It.IsAny <IEnumerable <IVersionSpec> >()))
            .Returns(new[] { PackageUtility.CreatePackage("Foo", "1.1") })
            .Callback((IEnumerable <IPackage> a, bool includePrerelease, bool includeAllVersions, IEnumerable <FrameworkName> frameworks, IEnumerable <IVersionSpec> constraints) => actual = a)
            .Verifiable();

            PackagesProviderBase provider = new MockPackagesProvider(new string[] { ".NETFramework,Version=3.0" });

            IVsExtensionsTreeNode parentTreeNode = new Mock <IVsExtensionsTreeNode>().Object;
            var node = new UpdatesTreeNode(provider, "Mock", parentTreeNode, localRepository, sourceRepository.As <IPackageRepository>().Object);

            // Act
            var result = node.GetPackages(searchTerm: "Foo", allowPrereleaseVersions: true).ToList();

            // Assert
            sourceRepository.Verify();
            Assert.Equal(new[] { packageA }, actual);
            AssertPackage(result.Single(), "Foo", "1.1");
        }
コード例 #4
0
        public void GetPackagesOnlyReturnPackagesCompatibleWithTheProjects()
        {
            // Arrange
            MockPackageRepository localRepository = new MockPackageRepository();

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

            MockPackageRepository sourceRepository = new MockPackageRepository();

            sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "1.5"));
            sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "1.9", assemblyReferences: new string[] { "lib\\sl4\\a.dll" }));
            sourceRepository.AddPackage(PackageUtility.CreatePackage("B", "2.0", assemblyReferences: new string[] { "lib\\net20\\b.dll" }));

            PackagesProviderBase provider = new MockPackagesProvider(new string[] { ".NETFramework,Version=3.0" });

            IVsExtensionsTreeNode parentTreeNode = new Mock <IVsExtensionsTreeNode>().Object;
            var node = new UpdatesTreeNode(provider, "Mock", parentTreeNode, localRepository, sourceRepository);

            // Act
            var packages = node.GetPackages(searchTerm: null, allowPrereleaseVersions: true).ToList();

            // Assert
            Assert.Equal(2, packages.Count);
            AssertPackage(packages[0], "A", "1.5");
            AssertPackage(packages[1], "B", "2.0");
        }
コード例 #5
0
        public void GetPackagesReturnsUpdatesWhenThereAreMultipleVersionsOfTheSamePackageId()
        {
            // Arrange
            var localRepository  = new MockPackageRepository();
            var sourceRepository = new MockServiceBasePackageRepository();

            UpdatesTreeNode node = CreateUpdatesTreeNode(localRepository, sourceRepository, includePrerelease: false);

            localRepository.AddPackage(PackageUtility.CreatePackage("A", "9.0-rtm"));
            localRepository.AddPackage(PackageUtility.CreatePackage("B", "1.0"));
            localRepository.AddPackage(PackageUtility.CreatePackage("A", "9.0"));
            localRepository.AddPackage(PackageUtility.CreatePackage("A", "10.0"));

            sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "9.5"));
            sourceRepository.AddPackage(PackageUtility.CreatePackage("B", "4.0-beta"));
            sourceRepository.AddPackage(PackageUtility.CreatePackage("C", "1.2.3.4-alpha"));

            // Act
            var packages = node.GetPackages(searchTerm: null, allowPrereleaseVersions: true).ToList();

            // Assert
            Assert.Equal(2, packages.Count);
            AssertPackage(packages[0], "A", "9.5");
            AssertPackage(packages[1], "B", "4.0-beta");
        }
コード例 #6
0
        public void GetPackagesReturnsPrereleasePackagesIfIncludePrereleaseIsTrue()
        {
            // Arrange
            MockPackageRepository localRepository  = new MockPackageRepository();
            MockPackageRepository sourceRepository = new MockPackageRepository();

            UpdatesTreeNode node = CreateUpdatesTreeNode(localRepository, sourceRepository, includePrerelease: true);

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

            sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "1.5"));
            sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "1.9-alpha"));
            sourceRepository.AddPackage(PackageUtility.CreatePackage("B", "2.0"));

            // Act
            var packages = node.GetPackages(searchTerm: null, allowPrereleaseVersions: true).ToList();

            packages.Sort(PackageComparer.Version);

            // Assert
            Assert.Equal(2, packages.Count);
            AssertPackage(packages[0], "A", "1.9-alpha");
            AssertPackage(packages[1], "B", "2.0");
        }
コード例 #7
0
        public void GetPackagesReturnsNoResultsIfPackageDoesNotExistInSourceRepository()
        {
            // Arrange
            MockPackageRepository localRepository  = new MockPackageRepository();
            MockPackageRepository sourceRepository = new MockPackageRepository();

            UpdatesTreeNode node = CreateUpdatesTreeNode(localRepository, sourceRepository, includePrerelease: false);

            localRepository.AddPackage(PackageUtility.CreatePackage("A", "1.0"));

            sourceRepository.AddPackage(PackageUtility.CreatePackage("B", "1.5"));

            // Act
            var packages = node.GetPackages(searchTerm: null, allowPrereleaseVersions: true).ToList();

            // Assert
            Assert.Equal(0, packages.Count);
        }
コード例 #8
0
        public void GetPackagesReturnsCorrectPackages2()
        {
            // Arrange
            MockPackageRepository localRepository  = new MockPackageRepository();
            MockPackageRepository sourceRepository = new MockPackageRepository();

            UpdatesTreeNode node = CreateSimpleTreeNode(localRepository, sourceRepository);

            localRepository.AddPackage(PackageUtility.CreatePackage("A", "1.0"));

            sourceRepository.AddPackage(PackageUtility.CreatePackage("B", "1.5"));

            // Act
            var packages = node.GetPackages().ToList();

            // Assert
            Assert.AreEqual(0, packages.Count);
        }
コード例 #9
0
        public void GetPackagesReturnsCorrectPackages1()
        {
            // Arrange
            MockPackageRepository localRepository  = new MockPackageRepository();
            MockPackageRepository sourceRepository = new MockPackageRepository();

            UpdatesTreeNode node = CreateUpdatesTreeNode(localRepository, sourceRepository, includePrerelease: false);

            localRepository.AddPackage(PackageUtility.CreatePackage("A", "1.0"));

            sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "1.5"));

            // Act
            var packages = node.GetPackages(allowPrereleaseVersions: true).ToList();

            // Assert
            Assert.Equal(1, packages.Count);
            AssertPackage(packages[0], "A", "1.5");
        }
コード例 #10
0
        public void GetPackagesReturnsUpdatesForEachPackageFoundInTheSourceRepository()
        {
            // Arrange
            MockPackageRepository localRepository  = new MockPackageRepository();
            MockPackageRepository sourceRepository = new MockPackageRepository();

            UpdatesTreeNode node = CreateUpdatesTreeNode(localRepository, sourceRepository, includePrerelease: false);

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

            sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "1.5"));
            sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "1.9"));
            sourceRepository.AddPackage(PackageUtility.CreatePackage("B", "2.0"));

            // Act
            var packages = node.GetPackages(searchTerm: null, allowPrereleaseVersions: true).ToList();

            // Assert
            Assert.Equal(2, packages.Count);
            AssertPackage(packages[0], "A", "1.9");
            AssertPackage(packages[1], "B", "2.0");
        }