本文整理汇总了C#中IPackage.AsQueryable方法的典型用法代码示例。如果您正苦于以下问题:C# IPackage.AsQueryable方法的具体用法?C# IPackage.AsQueryable怎么用?C# IPackage.AsQueryable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPackage
的用法示例。
在下文中一共展示了IPackage.AsQueryable方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSortByDependencyComplex
public void TestSortByDependencyComplex()
{
// A
// / \
// B C
// \ /
// D
// Arrange
var packageA = PackageUtility.CreatePackage("A", "1.0", dependencies: new PackageDependency[] { new PackageDependency("B") });
var packageB = PackageUtility.CreatePackage("B", "1.0", dependencies: new PackageDependency[] { new PackageDependency("D") });
var packageC = PackageUtility.CreatePackage("C", "1.0", dependencies: new PackageDependency[] { new PackageDependency("D") });
var packageD = PackageUtility.CreatePackage("D", "1.0");
var list = new IPackage[] { packageD, packageB, packageC, packageA };
var mockRepository = new Mock<IPackageRepository>();
mockRepository.Setup(p => p.GetPackages()).Returns(list.AsQueryable());
var sorter = new PackageSorter();
// Act
var sortedPackages = sorter.GetPackagesByDependencyOrder(mockRepository.Object).ToList();
// Assert
Assert.Equal(4, sortedPackages.Count);
Assert.Same(packageD, sortedPackages[0]);
Assert.True((sortedPackages[1] == packageB && sortedPackages[2] == packageC) ||
(sortedPackages[1] == packageC && sortedPackages[2] == packageB));
Assert.Same(packageA, sortedPackages[3]);
}
示例2: TestSortByDependencySimple
public void TestSortByDependencySimple()
{
// A --> B --> C
// Arrange
var packageA = PackageUtility.CreatePackage("A", "1.0", dependencies: new PackageDependency[] { new PackageDependency("B") });
var packageB = PackageUtility.CreatePackage("B", "1.0", dependencies: new PackageDependency[] { new PackageDependency("C") });
var packageC = PackageUtility.CreatePackage("C", "1.0");
var list = new IPackage[] { packageB, packageC, packageA };
var mockRepository = new Mock<IPackageRepository>();
mockRepository.Setup(p => p.GetPackages()).Returns(list.AsQueryable());
var sorter = new PackageSorter();
// Act
var sortedPackages = sorter.GetPackagesByDependencyOrder(mockRepository.Object).ToList();
// Assert
Assert.Equal(3, sortedPackages.Count);
Assert.Same(packageC, sortedPackages[0]);
Assert.Same(packageB, sortedPackages[1]);
Assert.Same(packageA, sortedPackages[2]);
}
示例3: FindPackagesByIdRecognizeICultureAwareRepositoryInterface
public void FindPackagesByIdRecognizeICultureAwareRepositoryInterface()
{
var turkeyCulture = new CultureInfo("tr-TR");
string smallPackageName = "YUI".ToLower(turkeyCulture);
// Arrange
var packages = new IPackage[]
{
PackageUtility.CreatePackage("YUI"),
PackageUtility.CreatePackage("DUI")
};
var repository = new Mock<IPackageRepository>();
repository.Setup(p => p.GetPackages()).Returns(packages.AsQueryable());
var cultureRepository = repository.As<ICultureAwareRepository>().Setup(p => p.Culture).Returns(turkeyCulture);
var savedCulture = Thread.CurrentThread.CurrentCulture;
try
{
// simulate running on Turkish locale
Thread.CurrentThread.CurrentCulture = turkeyCulture;
// Act
// notice the lowercase Turkish I character in the packageId to search for
var foundPackages = PackageRepositoryExtensions.FindPackagesById(repository.Object, "yuı").ToList();
// Assert
Assert.Equal(1, foundPackages.Count);
Assert.Equal("YUI", foundPackages[0].Id);
}
finally
{
// restore culture
Thread.CurrentThread.CurrentCulture = savedCulture;
}
}
示例4: GetPackageDoNotShowUnlistedPackagesForUpdates2
public void GetPackageDoNotShowUnlistedPackagesForUpdates2()
{
// Arrange
var sourceRepository = new MockPackageRepository()
{
PackageUtility.CreatePackage("C", "1.0.0", listed: true),
PackageUtility.CreatePackage("C", "2.0.0", listed: false),
PackageUtility.CreatePackage("C", "2.0.1", listed: true),
PackageUtility.CreatePackage("C", "2.0.3.4-alpha", listed: false),
PackageUtility.CreatePackage("C", "2.0.3.5-alpha", listed: true),
PackageUtility.CreatePackage("C", "2.5.0", listed: false),
};
var repositoryFactory = new Mock<IPackageRepositoryFactory>(MockBehavior.Strict);
repositoryFactory.Setup(r => r.CreateRepository("NuGet Official Source")).Returns(sourceRepository);
var solutionManager = TestUtils.GetSolutionManager();
var localPackages = new IPackage[]
{
PackageUtility.CreatePackage("C", "1.0.0")
};
var localRepository = new Mock<ISharedPackageRepository>(MockBehavior.Strict);
localRepository.Setup(p => p.GetPackages()).Returns(localPackages.AsQueryable()).Verifiable();
var packageManager = new VsPackageManager(
solutionManager,
sourceRepository,
new Mock<IFileSystemProvider>().Object,
new Mock<IFileSystem>().Object,
localRepository.Object,
new Mock<IDeleteOnRestartManager>().Object,
new VsPackageInstallerEvents());
var mockPackageManagerFactory = new Mock<IVsPackageManagerFactory>(MockBehavior.Strict);
mockPackageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager).Verifiable();
var cmdlet = new GetPackageCommand(
repositoryFactory.Object,
GetSourceProvider("NuGet Official Source"),
solutionManager,
mockPackageManagerFactory.Object,
new Mock<IHttpClient>().Object,
new Mock<IProductUpdateService>().Object);
cmdlet.Updates = true;
cmdlet.IncludePrerelease = true;
cmdlet.AllVersions = true;
cmdlet.Source = "NuGet Official Source";
// Act
var packages = cmdlet.GetResults<dynamic>();
// Assert
localRepository.Verify();
Assert.Equal(2, packages.Count());
AssertPackageResultsEqual(packages.ElementAt(0), new { Id = "C", Version = new SemanticVersion("2.0.1") });
AssertPackageResultsEqual(packages.ElementAt(1), new { Id = "C", Version = new SemanticVersion("2.0.3.5-alpha") });
}
示例5: EmptySearchTerm_ReturnAllPackages
public void EmptySearchTerm_ReturnAllPackages()
{
var repoPackages = new IPackage[] { new MockPackage("A", "1.0"), new MockPackage("AB", "2.0")};
var expected = new IPackage[] { new MockPackage("A", "1.0"), new MockPackage("AB", "2.0") };
// act
var results = WebNuGetProject.GetPackages(repoPackages.AsQueryable<IPackage>(), null);
// assert
Assert.Equal(expected, results.AsEnumerable<IPackage>(), new MockPackage.StubPackageComparer());
// act
results = WebNuGetProject.GetPackages(repoPackages.AsQueryable<IPackage>(), string.Empty);
// assert
Assert.Equal(expected, results.AsEnumerable<IPackage>(), new MockPackage.StubPackageComparer());
}
示例6: ReturnMultiplePackages
public void ReturnMultiplePackages()
{
// arrange
var repoPackages = new IPackage[] { new MockPackage("A", "1.0"), new MockPackage("AB", "2.0"), new MockPackage("B", "2.0") };
var searchTerm = "A";
var expected = new IPackage[] { new MockPackage("A", "1.0"), new MockPackage("AB", "2.0") };
// act
var results = WebNuGetProject.GetPackages(repoPackages.AsQueryable<IPackage>(), searchTerm);
// assert
Assert.Equal(expected, results.AsEnumerable<IPackage>(), new MockPackage.StubPackageComparer());
}
示例7: CreateRecentPackageRepository
private RecentPackagesRepository CreateRecentPackageRepository(IPackage[] packagesList = null, IPersistencePackageMetadata[] settingsMetadata = null)
{
if (packagesList == null) {
var packageA = PackageUtility.CreatePackage("A", "1.0");
var packageC = PackageUtility.CreatePackage("C", "2.0");
packagesList = new[] { packageA, packageC };
}
var mockRepository = new Mock<IPackageRepository>();
mockRepository.Setup(p => p.GetPackages()).Returns(packagesList.AsQueryable());
var mockRepositoryFactory = new Mock<IPackageRepositoryFactory>();
mockRepositoryFactory.Setup(f => f.CreateRepository(It.IsAny<PackageSource>())).Returns(mockRepository.Object);
var mockSettingsManager = new MockSettingsManager();
if (settingsMetadata == null) {
var A = new PersistencePackageMetadata("A", "1.0", new DateTime(2010, 8, 12));
var B = new PersistencePackageMetadata("B", "2.0", new DateTime(2011, 3, 2));
settingsMetadata = new[] { A, B };
}
mockSettingsManager.SavePackageMetadata(settingsMetadata);
var mockPackageSourceProvider = new Mock<IPackageSourceProvider>();
mockPackageSourceProvider.Setup(p => p.AggregateSource).Returns(new PackageSource("All") { IsAggregate = true });
return new RecentPackagesRepository(null, mockRepositoryFactory.Object, mockPackageSourceProvider.Object, mockSettingsManager);
}