本文整理汇总了C#中NuGet.VisualStudio.Test.MockProjectPackageRepository.Add方法的典型用法代码示例。如果您正苦于以下问题:C# MockProjectPackageRepository.Add方法的具体用法?C# MockProjectPackageRepository.Add怎么用?C# MockProjectPackageRepository.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NuGet.VisualStudio.Test.MockProjectPackageRepository
的用法示例。
在下文中一共展示了MockProjectPackageRepository.Add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdatePackageWithSharedDependency
public void UpdatePackageWithSharedDependency()
{
// 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 pathResolver = new DefaultPackagePathResolver(fileSystem);
// A1 -> B1
// A2 -> B2
// F1 -> G1
// G1 -> B1
var A10 = PackageUtility.CreatePackage("A", "1.0", new[] { "hello" }, dependencies: new[] { new PackageDependency("B", VersionUtility.ParseVersionSpec("1.0")) });
var A20 = PackageUtility.CreatePackage("A", "2.0", new[] { "hello" }, dependencies: new[] { new PackageDependency("B", VersionUtility.ParseVersionSpec("2.0")) });
var B10 = PackageUtility.CreatePackage("B", "1.0", new[] { "hello" });
var B20 = PackageUtility.CreatePackage("B", "2.0", new[] { "hello" });
var F10 = PackageUtility.CreatePackage("F", "1.0", new[] { "hello" }, dependencies: new[] { new PackageDependency("G", VersionUtility.ParseVersionSpec("1.0")) });
var G10 = PackageUtility.CreatePackage("G", "1.0", new[] { "hello" }, dependencies: new[] { new PackageDependency("B", VersionUtility.ParseVersionSpec("1.0")) });
sourceRepository.AddPackage(A10);
sourceRepository.AddPackage(A20);
sourceRepository.AddPackage(B10);
sourceRepository.AddPackage(B20);
sourceRepository.AddPackage(F10);
sourceRepository.AddPackage(G10);
localRepository.Object.AddPackage(A10);
localRepository.Object.AddPackage(A20);
localRepository.Object.AddPackage(B10);
localRepository.Object.AddPackage(B20);
localRepository.Object.AddPackage(F10);
localRepository.Object.AddPackage(G10);
projectRepository.Add(A10);
projectRepository.Add(B10);
var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, fileSystem, localRepository.Object, new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object);
var projectManager = new ProjectManager(localRepository.Object, pathResolver, new MockProjectSystem(), projectRepository);
// Act
packageManager.UpdatePackage(projectManager, "A", version: null, updateDependencies: true, allowPrereleaseVersions: false, logger: NullLogger.Instance);
// Assert
Assert.False(packageManager.LocalRepository.Exists(A10));
Assert.False(packageManager.LocalRepository.Exists(B10));
Assert.True(packageManager.LocalRepository.Exists(A20));
Assert.True(packageManager.LocalRepository.Exists(B20));
Assert.True(packageManager.LocalRepository.Exists(F10));
Assert.True(packageManager.LocalRepository.Exists(G10));
}
示例2: UpdatePackagesWithOperationsAddPackageCorrectly
public void UpdatePackagesWithOperationsAddPackageCorrectly()
{
// Arrange
var localRepository = new MockSharedPackageRepository();
var projectRepository = new MockProjectPackageRepository(localRepository);
var sourceRepository = new MockPackageRepository();
var fileSystem = new MockFileSystem();
var pathResolver = new DefaultPackagePathResolver(fileSystem);
var A1 = PackageUtility.CreatePackage("A", "1.0", new[] { "hello1" });
var A2 = PackageUtility.CreatePackage("A", "2.0", new[] { "hello2" });
var A3 = PackageUtility.CreatePackage("A", "3.0", new[] { "hello3" });
var B1 = PackageUtility.CreatePackage("B", "1.0", new[] { "world1" });
var B2 = PackageUtility.CreatePackage("B", "2.0", new[] { "world2" });
sourceRepository.AddPackage(A2);
sourceRepository.AddPackage(A3);
sourceRepository.AddPackage(B1);
sourceRepository.AddPackage(B2);
localRepository.AddPackage(A1);
localRepository.AddPackage(B1);
projectRepository.Add(A1);
projectRepository.Add(B1);
var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, fileSystem, localRepository, new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object);
var projectManager = new ProjectManager(localRepository, pathResolver, new MockProjectSystem(), projectRepository);
var operations = new PackageOperation[] {
new PackageOperation(A3, PackageAction.Install),
new PackageOperation(B2, PackageAction.Install)
};
// Act
packageManager.UpdatePackages(projectManager, new[] { A3, B2 }, operations, updateDependencies: true, allowPrereleaseVersions: true, logger: NullLogger.Instance);
// Assert
Assert.True(localRepository.Exists("A", new SemanticVersion("3.0")));
Assert.False(localRepository.Exists("A", new SemanticVersion("2.0")));
Assert.False(localRepository.Exists("A", new SemanticVersion("1.0")));
Assert.True(localRepository.Exists("B", new SemanticVersion("2.0")));
Assert.False(localRepository.Exists("B", new SemanticVersion("1.0")));
Assert.True(projectRepository.Exists("A", new SemanticVersion("3.0")));
Assert.True(projectRepository.Exists("B", new SemanticVersion("2.0")));
}
示例3: UpdatePackageThrowsIfNewPackageHasMinClientVersionNotSatisfied
public void UpdatePackageThrowsIfNewPackageHasMinClientVersionNotSatisfied()
{
// Arrange
Version nugetVersion = typeof(IPackage).Assembly.GetName().Version;
Version requiredVersion = new Version(nugetVersion.Major, nugetVersion.Minor, nugetVersion.Build, nugetVersion.Revision + 1);
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
localRepository.Setup(m => m.IsReferenced("A", new SemanticVersion("1.0"))).Returns(false);
var projectRepository = new MockProjectPackageRepository(localRepository.Object);
var sourceRepository = new MockPackageRepository();
var fileSystem = new MockFileSystem();
var pathResolver = new DefaultPackagePathResolver(fileSystem);
var A10 = PackageUtility.CreatePackage("A", "1.0", new[] { "hello" });
var A20 = PackageUtility.CreatePackage("A", "2.0", new[] { "hello" }, minClientVersion: requiredVersion.ToString());
sourceRepository.AddPackage(A10);
sourceRepository.AddPackage(A20);
localRepository.Object.AddPackage(A10);
localRepository.Object.AddPackage(A20);
projectRepository.Add(A10);
var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, fileSystem, localRepository.Object, new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object);
var projectManager = new ProjectManager(localRepository.Object, pathResolver, new MockProjectSystem(), projectRepository);
string expectedErrorMessage =
String.Format("The '{0}' package requires NuGet client version '{1}' or above, but the current NuGet version is '{2}'.", "A 2.0", requiredVersion.ToString(), nugetVersion.ToString());
// Act && Assert
ExceptionAssert.Throws<NuGetVersionNotSatisfiedException>(
() => packageManager.UpdatePackage(projectManager, "A", version: null, updateDependencies: true, allowPrereleaseVersions: false, logger: NullLogger.Instance),
expectedErrorMessage);
}
示例4: UpdatePackageDoesNotRemovesPackageIfPackageIsReferenced
public void UpdatePackageDoesNotRemovesPackageIfPackageIsReferenced()
{
// Arrange
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
localRepository.Setup(m => m.IsReferenced("A", new SemanticVersion("1.0"))).Returns(true);
var projectRepository = new MockProjectPackageRepository(localRepository.Object);
var sourceRepository = new MockPackageRepository();
var fileSystem = new MockFileSystem();
var pathResolver = new DefaultPackagePathResolver(fileSystem);
var A10 = PackageUtility.CreatePackage("A", "1.0", new[] { "hello" });
var A20 = PackageUtility.CreatePackage("A", "2.0", new[] { "hello" });
sourceRepository.AddPackage(A10);
sourceRepository.AddPackage(A20);
localRepository.Object.AddPackage(A10);
localRepository.Object.AddPackage(A20);
projectRepository.Add(A10);
var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, fileSystem, localRepository.Object, new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object);
var projectManager = new ProjectManager(localRepository.Object, pathResolver, new MockProjectSystem(), projectRepository);
// Act
packageManager.UpdatePackage(projectManager, "A", version: null, updateDependencies: true, allowPrereleaseVersions: false, logger: NullLogger.Instance);
// Assert
Assert.True(packageManager.LocalRepository.Exists(A10));
}
示例5: UpdatePackagesEndToEndWhereNewerVersionPackageDoesNotHaveDependencyLikeOlderVersion
public void UpdatePackagesEndToEndWhereNewerVersionPackageDoesNotHaveDependencyLikeOlderVersion()
{
// Arrange
var localRepository = new MockSharedPackageRepository();
var projectRepository = new MockProjectPackageRepository(localRepository);
var sourceRepository = new MockPackageRepository();
var fileSystem = new MockFileSystem();
var pathResolver = new DefaultPackagePathResolver(fileSystem);
var A1 = PackageUtility.CreatePackage("A", "1.0", new[] { "hello1" }, dependencies: new[] { PackageDependency.CreateDependency("B", "1.0") });
var A2 = PackageUtility.CreatePackage("A", "2.0", new[] { "hello2" }, dependencies: new[] { PackageDependency.CreateDependency("C", "1.0") });
var B1 = PackageUtility.CreatePackage("B", "1.0", new[] { "world1" });
var B2 = PackageUtility.CreatePackage("B", "2.0", new[] { "world2" });
var C1 = PackageUtility.CreatePackage("C", "1.0", new[] { "galaxy1" });
var C2 = PackageUtility.CreatePackage("C", "2.0", new[] { "galaxy2" });
sourceRepository.AddPackage(A1);
sourceRepository.AddPackage(A2);
sourceRepository.AddPackage(B1);
sourceRepository.AddPackage(B2);
sourceRepository.AddPackage(C1);
sourceRepository.AddPackage(C2);
localRepository.AddPackage(A1);
localRepository.AddPackage(B1);
localRepository.AddPackage(C1);
projectRepository.Add(A1);
projectRepository.Add(B1);
projectRepository.Add(C1);
var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, fileSystem, localRepository, new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object);
var projectManager = new ProjectManager(localRepository, pathResolver, new MockProjectSystem(), projectRepository);
var installWalker = new InstallWalker(
localRepository,
sourceRepository,
null,
logger: NullLogger.Instance,
ignoreDependencies: false,
allowPrereleaseVersions: true);
IList<IPackage> updatePackagesByDependencyOrder;
var updatePackages = new List<IPackage> { A2, B2, C2 };
var operationsForShowingLicense = installWalker.ResolveOperations(updatePackages, out updatePackagesByDependencyOrder);
// Act
packageManager.UpdatePackages(projectManager, updatePackagesByDependencyOrder, operationsForShowingLicense, updateDependencies: true, allowPrereleaseVersions: true, logger: NullLogger.Instance);
// Assert
// NOTE THAT BELOW, there is no uninstall operation for B1 but only for C1. Because A2 depends on C1 only where A1 depends on B1 only
// And, the operations are resolved for A2 NOT A1
Assert.True(operationsForShowingLicense.Count == 4);
Assert.True(operationsForShowingLicense[0].Package == A2 && operationsForShowingLicense[0].Action == PackageAction.Install);
Assert.True(operationsForShowingLicense[1].Package == B2 && operationsForShowingLicense[1].Action == PackageAction.Install);
Assert.True(operationsForShowingLicense[2].Package == C1 && operationsForShowingLicense[2].Action == PackageAction.Uninstall);
Assert.True(operationsForShowingLicense[3].Package == C2 && operationsForShowingLicense[3].Action == PackageAction.Install);
Assert.True(updatePackagesByDependencyOrder.Count == 3);
Assert.True(updatePackagesByDependencyOrder[0] == C2);
Assert.True(updatePackagesByDependencyOrder[1] == A2);
Assert.True(updatePackagesByDependencyOrder[2] == B2);
Assert.True(localRepository.Exists("A", new SemanticVersion("2.0")));
Assert.False(localRepository.Exists("A", new SemanticVersion("1.0")));
Assert.True(localRepository.Exists("B", new SemanticVersion("2.0")));
Assert.False(localRepository.Exists("B", new SemanticVersion("1.0")));
Assert.True(localRepository.Exists("C", new SemanticVersion("2.0")));
Assert.False(localRepository.Exists("C", new SemanticVersion("1.0")));
Assert.True(projectRepository.Exists("A", new SemanticVersion("2.0")));
Assert.True(projectRepository.Exists("B", new SemanticVersion("2.0")));
Assert.True(projectRepository.Exists("C", new SemanticVersion("2.0")));
}