GetPackages() приватный Метод

private GetPackages ( ) : IEnumerable
Результат IEnumerable
Пример #1
0
        public void GetPackagesUsesSourceIfDefined()
        {
            // Arrange
            IPackageRepositoryFactory factory = CreatePackageRepositoryFactory();
            IConsole console = new Mock<IConsole>().Object;
            ListCommand cmd = new ListCommand(factory, GetSourceProvider());
            cmd.Console = console;
            cmd.Source.Add(NonDefaultRepoUrl1);

            // Act
            var packages = cmd.GetPackages();

            // Assert
            Assert.Equal("CustomUrlUsed", packages.Single().Id);
        }
Пример #2
0
        public void GetPackageUsesSearchTermsIfPresent()
        {
            // Arrange
            IPackageRepositoryFactory factory = CreatePackageRepositoryFactory();
            IConsole console = new Mock<IConsole>().Object;
            ListCommand cmd = new ListCommand(factory, GetSourceProvider());
            cmd.Source.Add(DefaultRepoUrl);
            cmd.Console = console;
            cmd.Arguments.Add("SearchPackage");


            // Act
            var packages = cmd.GetPackages();

            // Assert
            Assert.Equal(1, packages.Count());
            Assert.Equal("SearchPackage", packages.First().Id);
        }
Пример #3
0
        public void GetPackageCollapsesVersionsByDefault()
        {
            // Arrange
            var factory = CreatePackageRepositoryFactory();
            var console = new Mock<IConsole>().Object;
            var cmd = new ListCommand(factory);
            cmd.Source = NonDefaultRepoUrl2;
            cmd.Console = console;

            // Act
            var packages = cmd.GetPackages();

            // Assert
            Assert.AreEqual(2, packages.Count());
            Assert.AreEqual("NHibernate", packages.First().Id);
            Assert.AreEqual(new Version("1.2"), packages.First().Version);
            Assert.AreEqual("jQuery", packages.Last().Id);
            Assert.AreEqual(new Version("1.50"), packages.Last().Version);
        }
Пример #4
0
        public void GetPackagesUsesAggregateSourceIfNoSourceDefined()
        {
            // Arrange
            IPackageRepositoryFactory factory = CreatePackageRepositoryFactory();
            IConsole console = new Mock<IConsole>().Object;
            ListCommand cmd = new ListCommand(factory, GetSourceProvider());
            cmd.Console = console;

            // Act
            var packages = cmd.GetPackages();

            // Assert
            Assert.Equal(6, packages.Count());
            AssertPackage(new { Id = "AnotherTerm", Ver = "1.0" }, packages.ElementAt(0));
            AssertPackage(new { Id = "CustomUrlUsed", Ver = "1.0" }, packages.ElementAt(1));
            AssertPackage(new { Id = "DefaultUrlUsed", Ver = "1.0" }, packages.ElementAt(2));
            AssertPackage(new { Id = "jQuery", Ver = "1.50" }, packages.ElementAt(3));
            AssertPackage(new { Id = "NHibernate", Ver = "1.2" }, packages.ElementAt(4));
            AssertPackage(new { Id = "SearchPackage", Ver = "1.0" }, packages.ElementAt(5));
        }
Пример #5
0
        public void GetPackagesUsesSourceIfDefined()
        {
            // Arrange
            IPackageRepositoryFactory factory = CreatePackageRepositoryFactory();
            IConsole console = new Mock<IConsole>().Object;
            ListCommand cmd = new ListCommand(factory);
            cmd.Console = console;
            cmd.Source = NonDefaultRepoUrl1;

            // Act
            var packages = cmd.GetPackages();

            // Assert
            Assert.AreEqual("CustomUrlUsed", packages.First().Id);
        }
Пример #6
0
        public void GetPackagesUsesDefaultSourceIfNoSourceDefined()
        {
            // Arrange
            IPackageRepositoryFactory factory = CreatePackageRepositoryFactory();
            IConsole console = new Mock<IConsole>().Object;
            ListCommand cmd = new ListCommand(factory);
            cmd.Console = console;

            // Act
            var packages = cmd.GetPackages();

            // Assert
            Assert.AreEqual(3, packages.Count());
            Assert.AreEqual("DefaultUrlUsed", packages.First().Id);
        }
Пример #7
0
        public void GetPackageReturnsAllVersionsIfAllVersionsFlagIsSet()
        {
            // Arrange
            var factory = CreatePackageRepositoryFactory();
            var console = new Mock<IConsole>().Object;
            var cmd = new ListCommand(factory);
            cmd.Source = NonDefaultRepoUrl2;
            cmd.Console = console;
            cmd.AllVersions = true;

            // Act
            var packages = cmd.GetPackages();

            // Assert
            Assert.AreEqual(5, packages.Count());
            Assert.AreEqual("NHibernate", packages.ElementAt(0).Id);
            Assert.AreEqual(new Version("1.0"), packages.ElementAt(0).Version);
            Assert.AreEqual("NHibernate", packages.ElementAt(1).Id);
            Assert.AreEqual(new Version("1.1"), packages.ElementAt(1).Version);
            Assert.AreEqual("NHibernate", packages.ElementAt(2).Id);
            Assert.AreEqual(new Version("1.2"), packages.ElementAt(2).Version);
            Assert.AreEqual("jQuery", packages.ElementAt(3).Id);
            Assert.AreEqual(new Version("1.44"), packages.ElementAt(3).Version);
            Assert.AreEqual("jQuery", packages.ElementAt(4).Id);
            Assert.AreEqual(new Version("1.50"), packages.ElementAt(4).Version);
        }
Пример #8
0
        public void GetPackageThatHasLicensesWithVerbositySetToDetailed()
        {
            // Arrange
            IPackageRepositoryFactory factory = CreatePackageRepositoryFactory();
            Mock<IConsole> consoleMock = new Mock<IConsole>();
            IConsole console = consoleMock.Object;

            consoleMock.Setup(x => x.PrintJustified(1, "License url: ftp://test/somelicense.txts")).Verifiable("could not find license url");
            ListCommand cmd = new ListCommand()
            {
                RepositoryFactory = factory,
                SourceProvider = GetSourceProvider()
            };
            cmd.Source.Add(DefaultRepoUrl);
            cmd.Console = console;
            cmd.Arguments.Add("SearchPackage");
            cmd.Verbosity = Verbosity.Detailed;

            // Act
            var packages = cmd.GetPackages();
            cmd.ExecuteCommand();

            // Assert
            var url = packages.First().LicenseUrl;
            Assert.Equal(1, packages.Count());
            Assert.Equal(new Uri("ftp://test/somelicense.txts"), packages.First().LicenseUrl);
            consoleMock.Verify();
        }
Пример #9
0
        public void GetPackageResolvesSources()
        {
            // Arrange
            var factory = CreatePackageRepositoryFactory();
            var console = new Mock<IConsole>().Object;
            var provider = new Mock<IPackageSourceProvider>();
            provider.Setup(c => c.LoadPackageSources()).Returns(new[] { new PackageSource(NonDefaultRepoUrl1, "Foo") });
            var cmd = new ListCommand()
            {
                RepositoryFactory = factory,
                SourceProvider = provider.Object
            };
            cmd.Source.Add("Foo");
            cmd.Console = console;

            // Act
            var packages = cmd.GetPackages();

            // Assert
            AssertPackage(new { Id = "CustomUrlUsed", Ver = "1.0" }, packages.Single());
        }
Пример #10
0
        public void GetPackageUsesIsAbsoluteLatestVersionIfPrereleaseIfSpecifiedAndRespositoriesSupportsPrerelease()
        {
            // Arrange
            var packageA = new Mock<IPackage>(MockBehavior.Strict);
            packageA.SetupGet(p => p.Id).Returns("A");
            packageA.SetupGet(p => p.Version).Returns(new SemanticVersion("1.0.0"));
            packageA.SetupGet(p => p.IsAbsoluteLatestVersion).Returns(true).Verifiable();
            packageA.SetupGet(pA => pA.Listed).Returns(false);
            packageA.SetupGet(p => p.Published).Returns(DateTime.Now);

            var packageB = new Mock<IPackage>(MockBehavior.Strict);
            packageB.SetupGet(p => p.Id).Returns("B");
            packageB.SetupGet(p => p.Version).Returns(new SemanticVersion("1.0.2"));
            packageB.SetupGet(pB => pB.Listed).Returns(true);
            packageB.SetupGet(p => p.IsAbsoluteLatestVersion).Returns(false).Verifiable();


            var packageC = new Mock<IPackage>(MockBehavior.Strict);
            packageC.SetupGet(p => p.Id).Returns("C");
            packageC.SetupGet(p => p.Version).Returns(new SemanticVersion("1.0.0"));
            packageC.SetupGet(p => p.IsAbsoluteLatestVersion).Returns(true).Verifiable();
            packageC.SetupGet(pC => pC.Listed).Returns(true);

            var repository = new MockPackageRepository { packageA.Object, packageB.Object, packageC.Object };
            var factory = new Mock<IPackageRepositoryFactory>(MockBehavior.Strict);
            factory.Setup(f => f.CreateRepository(DefaultRepoUrl)).Returns(repository);

            var cmd = new ListCommand()
            {
                RepositoryFactory = factory.Object,
                SourceProvider = GetSourceProvider(),
                Console = new Mock<IConsole>().Object,
                Prerelease = true
            };
            cmd.Source.Add(DefaultRepoUrl);

            // Act
            var packages = cmd.GetPackages();

            // Assert
            Assert.Equal(2, packages.Count());
            AssertPackage(new { Id = "A", Ver = "1.0.0" }, packages.First());
            AssertPackage(new { Id = "C", Ver = "1.0.0" }, packages.Last());
        }
Пример #11
0
        public void GetPackageFiltersPackagesUsingIsLatestIfRepositoryDoesNotSupportPrerelease()
        {
            // Arrange
            var package = new Mock<IPackage>(MockBehavior.Strict);
            package.SetupGet(p => p.Id).Returns("A");
            package.SetupGet(p => p.Version).Returns(new SemanticVersion("1.0.0"));
            package.SetupGet(p => p.IsLatestVersion).Returns(true).Verifiable();
            package.SetupGet(p => p.Listed).Returns(true);
            package.SetupGet(p => p.IsAbsoluteLatestVersion).Throws(new Exception("Repository does not support this property."));

            var repository = new Mock<IPackageRepository>(MockBehavior.Strict);
            repository.SetupGet(r => r.SupportsPrereleasePackages).Returns(false).Verifiable();
            repository.Setup(r => r.GetPackages()).Returns(new[] { package.Object }.AsQueryable());
            var factory = new Mock<IPackageRepositoryFactory>(MockBehavior.Strict);
            factory.Setup(f => f.CreateRepository(DefaultRepoUrl)).Returns(repository.Object);

            var cmd = new ListCommand()
            {
                RepositoryFactory = factory.Object,
                SourceProvider = GetSourceProvider(),
                Console = new Mock<IConsole>().Object,
                Prerelease = true
            };
            cmd.Source.Add(DefaultRepoUrl);

            // Act
            var packages = cmd.GetPackages();

            // Assert
            Assert.Equal(1, packages.Count());
            AssertPackage(new { Id = "A", Ver = "1.0.0" }, packages.First());
            package.Verify();
            repository.Verify();
        }
Пример #12
0
        public void GetPackageReturnsAllVersionsIfAllVersionsFlagIsSet()
        {
            // Arrange
            var factory = CreatePackageRepositoryFactory();
            var console = new Mock<IConsole>().Object;
            var cmd = new ListCommand()
            {
                RepositoryFactory = factory,
                SourceProvider = GetSourceProvider()
            };
            cmd.Source.Add(NonDefaultRepoUrl2);
            cmd.Console = console;
            cmd.AllVersions = true;

            // Act
            var packages = cmd.GetPackages();

            // Assert
            Assert.Equal(5, packages.Count());
            AssertPackage(new { Id = "jQuery", Ver = "1.44" }, packages.ElementAt(0));
            AssertPackage(new { Id = "jQuery", Ver = "1.50" }, packages.ElementAt(1));
            AssertPackage(new { Id = "NHibernate", Ver = "1.0" }, packages.ElementAt(2));
            AssertPackage(new { Id = "NHibernate", Ver = "1.1" }, packages.ElementAt(3));
            AssertPackage(new { Id = "NHibernate", Ver = "1.2" }, packages.ElementAt(4));
        }
Пример #13
0
        public void GetPackageFiltersAndCollapsesVersions()
        {
            // Arrange
            var factory = CreatePackageRepositoryFactory();
            var console = new Mock<IConsole>().Object;
            var cmd = new ListCommand()
            {
                RepositoryFactory = factory,
                SourceProvider = GetSourceProvider()
            };
            cmd.Source.Add(NonDefaultRepoUrl2);
            cmd.Console = console;
            cmd.Arguments.Add("NHibernate");

            // Act
            var packages = cmd.GetPackages();

            // Assert
            Assert.Equal(1, packages.Count());
            AssertPackage(new { Id = "NHibernate", Ver = "1.2" }, packages.ElementAt(0));
        }
Пример #14
0
        public void GetPackageCollapsesVersionsByDefault()
        {
            // Arrange
            var factory = CreatePackageRepositoryFactory();
            var console = new Mock<IConsole>().Object;
            var cmd = new ListCommand(factory, GetSourceProvider());
            cmd.Source.Add(NonDefaultRepoUrl2);
            cmd.Console = console;

            // Act
            var packages = cmd.GetPackages();

            // Assert
            Assert.Equal(2, packages.Count());
            AssertPackage(new { Id = "jQuery", Ver = "1.50" }, packages.ElementAt(0));
            AssertPackage(new { Id = "NHibernate", Ver = "1.2" }, packages.ElementAt(1));
        }
Пример #15
0
        public void GetPackageUsesSearchTermsIfPresent()
        {
            // Arrange
            IPackageRepositoryFactory factory = CreatePackageRepositoryFactory();
            IConsole console = new Mock<IConsole>().Object;
            ListCommand cmd = new ListCommand(factory);
            cmd.Console = console;
            List<string> searchTerms = new List<string>();
            searchTerms.Add("SearchPackage");
            searchTerms.Add("AnotherTerm");
            cmd.Arguments = searchTerms;

            // Act
            var packages = cmd.GetPackages();

            // Assert
            Assert.AreEqual(2, packages.Count());
            Assert.AreEqual("SearchPackage", packages.First().Id);
            Assert.AreEqual("AnotherTerm", packages.Last().Id);
        }
Пример #16
0
        public void GetPackageDoesNotShowUnlistedPackagesOrPackagesWithLegacyDates()
        {
            // Arrange
            var packageA = new Mock<IPackage>(MockBehavior.Strict);
            packageA.SetupGet(p => p.Id).Returns("A");
            packageA.SetupGet(p => p.Version).Returns(new SemanticVersion("1.0.0"));
            packageA.SetupGet(p => p.IsLatestVersion).Returns(true);
            packageA.SetupGet(pA => pA.Listed).Returns(false);
            packageA.SetupGet(p => p.Published).Returns(DateTime.Now);

            var packageB = new Mock<IPackage>(MockBehavior.Strict);
            packageB.SetupGet(p => p.Id).Returns("B");
            packageB.SetupGet(p => p.Version).Returns(new SemanticVersion("1.0.2"));
            packageB.SetupGet(pB => pB.Listed).Returns(true);
            packageB.SetupGet(p => p.IsLatestVersion).Returns(true);


            var packageC = new Mock<IPackage>(MockBehavior.Strict);
            packageC.SetupGet(p => p.Id).Returns("C");
            packageC.SetupGet(p => p.Version).Returns(new SemanticVersion("1.0.0"));
            packageC.SetupGet(p => p.IsLatestVersion).Returns(true);
            packageC.SetupGet(pC => pC.Listed).Returns(false);
            packageC.SetupGet(p => p.Published).Returns(new DateTime(1900, 1, 1, 0, 0, 0));

            var repository = new MockPackageRepository { packageA.Object, packageB.Object, packageC.Object };
            var factory = new Mock<IPackageRepositoryFactory>(MockBehavior.Strict);
            factory.Setup(f => f.CreateRepository(DefaultRepoUrl)).Returns(repository);

            var cmd = new ListCommand()
            {
                RepositoryFactory = factory.Object, 
                SourceProvider = GetSourceProvider(),
                Console = new Mock<IConsole>().Object,
            };
            cmd.Source.Add(DefaultRepoUrl);

            // Act
            var packages = cmd.GetPackages();

            // Assert
            Assert.Equal(2, packages.Count());
            AssertPackage(new { Id = "A", Ver = "1.0.0" }, packages.First());
            AssertPackage(new { Id = "B", Ver = "1.0.2" }, packages.Last());
        }
Пример #17
0
        //REVIEW Just in case we want to get away from using their list command....
        private IEnumerable<IPackage> GetInitialPackageList(bool allVersions, List<string> ids, IPackageSourceProvider sourceProvider)
        {
            var listCommand = new ListCommand(RepositoryFactory, sourceProvider)
            {
                AllVersions = allVersions,
                Console = this.Console,
            };

            if (ids != null && ids.Count != 0)
                listCommand.Arguments.AddRange(ids);
            var packages = listCommand.GetPackages();
            return packages;
        }