本文整理汇总了C#中MockPackageRepository.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# MockPackageRepository.AddRange方法的具体用法?C# MockPackageRepository.AddRange怎么用?C# MockPackageRepository.AddRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockPackageRepository
的用法示例。
在下文中一共展示了MockPackageRepository.AddRange方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdatePackageUpdatesPackagesWithCommonDependency
public void UpdatePackageUpdatesPackagesWithCommonDependency()
{
// Arrange
var localRepository = new MockPackageRepository();
var sourceRepository = new MockPackageRepository();
var constraintProvider = NullConstraintProvider.Instance;
var fileSystem = new MockFileSystem();
var pathResolver = new DefaultPackagePathResolver(fileSystem);
var projectSystem = new MockProjectSystem();
var packages = new List<IPackage>();
var package_A10 = PackageUtility.CreatePackage("A", "1.0", content: new[] { "A.txt" }, dependencies: new[] { new PackageDependency("C", VersionUtility.ParseVersionSpec("1.0")) });
var package_B10 = PackageUtility.CreatePackage("B", "1.0", content: new[] { "B.txt" }, dependencies: new[] { new PackageDependency("C", VersionUtility.ParseVersionSpec("1.0")) });
var package_A12 = PackageUtility.CreatePackage("A", "1.2", content: new[] { "A.txt" }, dependencies: new[] { new PackageDependency("C", VersionUtility.ParseVersionSpec("1.0")) });
var package_B20 = PackageUtility.CreatePackage("B", "2.0", content: new[] { "B.txt" });
var package_C10 = PackageUtility.CreatePackage("C", "1.0", content: new[] { "C.txt" });
localRepository.AddRange(new[] { package_A10, package_B10, package_C10});
sourceRepository.AddRange(new[] { package_A12, package_B20 });
var sharedRepository = new Mock<ISharedPackageRepository>(MockBehavior.Strict);
sharedRepository.Setup(s => s.AddPackage(package_A12)).Callback<IPackage>(p => packages.Add(p)).Verifiable();
sharedRepository.Setup(s => s.AddPackage(package_B20)).Callback<IPackage>(p => packages.Add(p)).Verifiable();
sharedRepository.Setup(s => s.GetPackages()).Returns(packages.AsQueryable());
var repositoryFactory = new Mock<IPackageRepositoryFactory>();
repositoryFactory.Setup(s => s.CreateRepository(It.IsAny<string>())).Returns(sourceRepository);
var packageSourceProvider = new Mock<IPackageSourceProvider>();
packageSourceProvider.Setup(s => s.LoadPackageSources()).Returns(new[] { new PackageSource("foo-source") });
var updateCommand = new UpdateCommand()
{
RepositoryFactory = repositoryFactory.Object,
SourceProvider = packageSourceProvider.Object
};
// Act
updateCommand.UpdatePackages(localRepository, fileSystem, sharedRepository.Object, sourceRepository, constraintProvider, pathResolver, projectSystem);
// Assert
sharedRepository.Verify();
}
示例2: RecentPackageRepositoryDoesNotReturnPackagesFromSourcesThatAreDisabled
public void RecentPackageRepositoryDoesNotReturnPackagesFromSourcesThatAreDisabled()
{
// Arrange
var sources = new List<PackageSource> { new PackageSource("Source1"), new PackageSource("Source2", "Source2", isEnabled: false) };
var factory = new Mock<IPackageRepositoryFactory>();
factory.Setup(c => c.CreateRepository(It.IsAny<string>())).Returns<string>(c =>
{
switch (c)
{
case "Source1":
var repo1 = new MockPackageRepository();
repo1.AddRange(new[] { PackageUtility.CreatePackage("Pack1") });
return repo1;
case "Source2":
var repo2 = new MockPackageRepository();
repo2.AddRange(new[] { PackageUtility.CreatePackage("Pack2", "1.1") });
return repo2;
}
return null;
});
var settingsManager = new MockSettingsManager();
settingsManager.SavePackageMetadata(new[] {
new PersistencePackageMetadata("Pack1", "1.0", new DateTime(2011, 01, 01)),
new PersistencePackageMetadata("Pack2", "1.1", new DateTime(2011, 01, 01)),
new PersistencePackageMetadata("Pack3", "1.0", new DateTime(2011, 01, 01)),
});
var sourceProvider = new Mock<IPackageSourceProvider>();
sourceProvider.Setup(c => c.LoadPackageSources()).Returns(sources);
var repository = new RecentPackageRepository(
null,
factory.Object,
sourceProvider.Object,
settingsManager,
new MockPackageRepository());
// Act
var packages = repository.GetPackages();
// Assert
Assert.Equal(1, packages.Count());
AssertPackage(packages.First(), "Pack1", "1.0");
//AssertPackage(packages.Last(), "Pack2", "1.1");
}
示例3: GetPackageRepository
private static IPackageRepository GetPackageRepository(IEnumerable<IPackage> packages = null)
{
var repository = new MockPackageRepository();
packages = packages ?? new[] { PackageUtility.CreatePackage("P1", "1.4"), PackageUtility.CreatePackage("P6") };
repository.AddRange(packages);
return repository;
}