本文整理汇总了C#中MockPackageRepository.Exists方法的典型用法代码示例。如果您正苦于以下问题:C# MockPackageRepository.Exists方法的具体用法?C# MockPackageRepository.Exists怎么用?C# MockPackageRepository.Exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockPackageRepository
的用法示例。
在下文中一共展示了MockPackageRepository.Exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanExecuteReturnsCorrectResult
public void CanExecuteReturnsCorrectResult()
{
// Local repository contains Package A and Package B
// We test the CanExecute() method on Package A and Package C
// Arrange
var repository = new MockPackageRepository();
var packageA = PackageUtility.CreatePackage("A", "1.0");
repository.AddPackage(packageA);
var packageB = PackageUtility.CreatePackage("B", "2.0");
repository.AddPackage(packageB);
var packageC = PackageUtility.CreatePackage("C", "2.0");
var projectManager = new Mock<IProjectManager>();
projectManager.Setup(p => p.IsInstalled(It.IsAny<IPackage>())).Returns<IPackage>(p => repository.Exists(p));
var provider = CreateInstalledProvider(null, projectManager.Object);
var extensionA = new PackageItem(provider, packageA, null);
var extensionC = new PackageItem(provider, packageC, null);
// Act
bool canExecuteA = provider.CanExecute(extensionA);
bool canExecuteC = provider.CanExecute(extensionC);
// Assert
Assert.IsTrue(canExecuteA);
Assert.IsFalse(canExecuteC);
}
示例2: InstallingPackageWithUnknownDependencyAndIgnoreDepencenciesInstallsPackageWithoutDependencies
public void InstallingPackageWithUnknownDependencyAndIgnoreDepencenciesInstallsPackageWithoutDependencies()
{
// Arrange
var localRepository = new MockPackageRepository();
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
IPackage packageA = PackageUtility.CreatePackage("A", "1.0",
dependencies: new List<PackageDependency> {
new PackageDependency("C")
});
IPackage packageC = PackageUtility.CreatePackage("C", "1.0");
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageC);
// Act
packageManager.InstallPackage("A", version: null, ignoreDependencies: true, allowPrereleaseVersions: true);
// Assert
Assert.True(localRepository.Exists(packageA));
Assert.False(localRepository.Exists(packageC));
}
示例3: CanExecuteReturnsCorrectResult
public void CanExecuteReturnsCorrectResult()
{
// Arrange
var packageA = PackageUtility.CreatePackage("A", "1.0");
var packageB = PackageUtility.CreatePackage("B", "2.0");
var packageC = PackageUtility.CreatePackage("C", "3.0");
var sourceRepository = new MockPackageRepository();
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageC);
sourceRepository.AddPackage(packageB);
var localRepository = new MockPackageRepository();
localRepository.AddPackage(packageA);
var projectManager = new Mock<IProjectManager>();
projectManager.Setup(p => p.IsInstalled(It.IsAny<IPackage>())).Returns<IPackage>(p => localRepository.Exists(p));
var packageManager = new Mock<IVsPackageManager>();
packageManager.Setup(p => p.SourceRepository).Returns(sourceRepository);
var provider = CreateOnlineProvider(packageManager.Object, projectManager.Object);
var extensionA = new PackageItem(provider, packageA, null);
var extensionB = new PackageItem(provider, packageB, null);
var extensionC = new PackageItem(provider, packageC, null);
// Act
bool canExecuteA = provider.CanExecute(extensionA);
bool canExecuteB = provider.CanExecute(extensionB);
bool canExecuteC = provider.CanExecute(extensionC);
// Assert
Assert.IsTrue(canExecuteC);
Assert.IsTrue(canExecuteB);
Assert.IsFalse(canExecuteA);
}
示例4: AddPackageReferenceRecognizeEmptyFrameworkFolder2
public void AddPackageReferenceRecognizeEmptyFrameworkFolder2()
{
// Arrange
var projectSystem = new MockProjectSystem(new FrameworkName("Silverlight", new Version("4.0")));
var localRepository = new MockPackageRepository();
var mockRepository = new MockPackageRepository();
var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
var packageA = PackageUtility.CreatePackage("A", "1.0",
new[] { "sl20\\contentFile", "sl20\\sub\\no.txt", "sl3\\_._", "foo.css" },
new[] { "reference.dll" });
mockRepository.AddPackage(packageA);
// Act
projectManager.AddPackageReference("A");
// Assert
Assert.Equal(0, projectSystem.Paths.Count);
Assert.False(projectSystem.FileExists(@"_._"));
Assert.True(localRepository.Exists("A"));
}
示例5: AddPackageReferenceAcceptsMetaPackage
public void AddPackageReferenceAcceptsMetaPackage()
{
// Arrange
var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework", new Version("4.0")));
var localRepository = new MockPackageRepository();
var mockRepository = new MockPackageRepository();
var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
var packageA = PackageUtility.CreatePackage("A", "1.0", dependencies: new [] { new PackageDependency("B") });
var packageB = PackageUtility.CreatePackage("B", "1.0-alpha", new [] { "net\\hello.txt" });
mockRepository.AddPackage(packageA);
mockRepository.AddPackage(packageB);
// Act
projectManager.AddPackageReference("A", version: null, ignoreDependencies: false, allowPrereleaseVersions: true);
// Assert
Assert.True(localRepository.Exists("A"));
Assert.True(localRepository.Exists("B"));
}
示例6: AddPackageReferenceThrowsIfThereIsNoCompatibleFrameworkFolderUnderContentAndLib
public void AddPackageReferenceThrowsIfThereIsNoCompatibleFrameworkFolderUnderContentAndLib()
{
// Arrange
var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework", new Version("4.0")));
var localRepository = new MockPackageRepository();
var mockRepository = new MockPackageRepository();
var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
var packageA = PackageUtility.CreatePackage("A", "1.0",
content: new[] { "silverlight\\reference.txt" },
assemblyReferences: new string[] { "lib\\windows8\\one.dll" });
mockRepository.AddPackage(packageA);
// Act
ExceptionAssert.Throws<InvalidOperationException>(() => projectManager.AddPackageReference("A"));
// Assert
Assert.False(localRepository.Exists("A"));
}
示例7: AddPackageReferenceAddsContentAccordingToTargetFramework3
public void AddPackageReferenceAddsContentAccordingToTargetFramework3()
{
// Arrange
var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework", new Version("2.0")));
var localRepository = new MockPackageRepository();
var mockRepository = new MockPackageRepository();
var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
var packageA = PackageUtility.CreatePackage("A", "1.0",
new[] { "sl3\\contentFile", "winrt45\\jQuery.js" },
new[] { "lib\\reference.dll" });
mockRepository.AddPackage(packageA);
// Act
projectManager.AddPackageReference("A");
// Assert
Assert.Equal(0, projectSystem.Paths.Count);
Assert.True(localRepository.Exists("A"));
}
示例8: AddPackageReferenceAllowsAddingMetadataPackage
public void AddPackageReferenceAllowsAddingMetadataPackage()
{
// Arrange
var projectSystem = new MockProjectSystem();
var localRepository = new MockPackageRepository();
var mockRepository = new MockPackageRepository();
var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
var packageA = PackageUtility.CreatePackage("A", "1.0", new [] { "hello.txt" });
var packageB = PackageUtility.CreatePackage("B", "2.0", dependencies: new[] { new PackageDependency("A") });
var mockPackageB = Mock.Get(packageB);
var files = PackageUtility.CreateFiles(new[] { "readme.txt", "foo.bar" });
mockPackageB.Setup(p => p.GetFiles()).Returns(files);
mockRepository.AddPackage(packageA);
mockRepository.AddPackage(packageB);
// Act
projectManager.AddPackageReference("B");
// Assert
Assert.True(localRepository.Exists("A"));
Assert.True(localRepository.Exists("B"));
}
示例9: AddPackageReferenceWithAnyNonCompatibleReferenceThrowsAndPackageIsNotReferenced
public void AddPackageReferenceWithAnyNonCompatibleReferenceThrowsAndPackageIsNotReferenced()
{
// Arrange
var mockProjectSystem = new Mock<MockProjectSystem>() { CallBase = true };
var localRepository = new MockPackageRepository();
var sourceRepository = new MockPackageRepository();
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(mockProjectSystem.Object), mockProjectSystem.Object, localRepository);
mockProjectSystem.Setup(m => m.TargetFramework).Returns(new FrameworkName(".NETFramework", new Version("2.0")));
var mockPackage = new Mock<IPackage>();
mockPackage.Setup(m => m.Id).Returns("A");
mockPackage.Setup(m => m.Version).Returns(new SemanticVersion("1.0"));
mockPackage.Setup(m => m.Listed).Returns(true);
var assemblyReference = PackageUtility.CreateAssemblyReference("foo.dll", new FrameworkName(".NETFramework", new Version("5.0")));
mockPackage.Setup(m => m.AssemblyReferences).Returns(new[] { assemblyReference });
sourceRepository.AddPackage(mockPackage.Object);
// Act & Assert
ExceptionAssert.Throws<InvalidOperationException>(
() => projectManager.AddPackageReference("A"),
"Could not install package 'A 1.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v2.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.");
Assert.False(localRepository.Exists(mockPackage.Object));
}
示例10: InstallPackageInstallsLowerReleaseVersionIfPrereleaseFlagIsNotSet
public void InstallPackageInstallsLowerReleaseVersionIfPrereleaseFlagIsNotSet()
{
// Arrange
var localRepository = new MockPackageRepository();
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
IPackage packageA = PackageUtility.CreatePackage("A", "1.0.0",
dependencies: new[] {
new PackageDependency("C")
});
IPackage packageC_RC = PackageUtility.CreatePackage("C", "1.0.0-RC-1");
IPackage packageC = PackageUtility.CreatePackage("C", "0.9");
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageC);
sourceRepository.AddPackage(packageC_RC);
// Act
packageManager.InstallPackage("A", version: null, ignoreDependencies: false, allowPrereleaseVersions: false);
// Assert
Assert.True(localRepository.Exists(packageA));
Assert.True(localRepository.Exists(packageC));
}
示例11: InstallPackageDisregardTargetFrameworkOfDependencies
public void InstallPackageDisregardTargetFrameworkOfDependencies()
{
// Arrange
var localRepository = new MockPackageRepository();
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var packageManager = new PackageManager(
sourceRepository,
new DefaultPackagePathResolver(projectSystem),
projectSystem,
localRepository);
IPackage packageA = PackageUtility.CreatePackage("A", "1.0.0",
dependencies: new[] {
new PackageDependency("C", null)
});
IPackage packageC = PackageUtility.CreatePackage("C", "1.0.0");
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageC);
// Act
packageManager.InstallPackage("A", version: null, ignoreDependencies: false, allowPrereleaseVersions: true);
// Assert
Assert.True(localRepository.Exists(packageA));
Assert.True(localRepository.Exists(packageC));
}
示例12: UpdatePackageDoesNothingIfNoUpdatesAvailable
public void UpdatePackageDoesNothingIfNoUpdatesAvailable()
{
// Arrange
var localRepository = new MockPackageRepository();
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
PackageManager packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
IPackage A10 = PackageUtility.CreatePackage("A", "1.0");
localRepository.Add(A10);
// Act
packageManager.UpdatePackage("A", updateDependencies: true, allowPrereleaseVersions: false);
// Assert
Assert.True(localRepository.Exists("A", new SemanticVersion("1.0")));
}
示例13: ReInstallingPackageAfterUninstallingDependencyShouldReinstallAllDependencies
public void ReInstallingPackageAfterUninstallingDependencyShouldReinstallAllDependencies()
{
// Arrange
var localRepository = new MockPackageRepository();
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
PackageManager packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
IPackage packageA = PackageUtility.CreatePackage("A", "1.0",
dependencies: new List<PackageDependency> {
new PackageDependency("B")
});
IPackage packageB = PackageUtility.CreatePackage("B", "1.0",
dependencies: new List<PackageDependency> {
new PackageDependency("C")
});
var packageC = PackageUtility.CreatePackage("C", "1.0");
localRepository.AddPackage(packageA);
localRepository.AddPackage(packageB);
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageB);
sourceRepository.AddPackage(packageC);
// Act
packageManager.InstallPackage("A");
// Assert
Assert.True(localRepository.Exists(packageA));
Assert.True(localRepository.Exists(packageB));
Assert.True(localRepository.Exists(packageC));
}
示例14: InstallPackageDoesNotPerformWalkInfoCheckWhenPassingTheFlag
public void InstallPackageDoesNotPerformWalkInfoCheckWhenPassingTheFlag()
{
// In this test, we simulate installing a solution-level package which depends on
// a project-level package. Under normal condition, this is disallowed by NuGet.
// However, if passing the 'ignoreWalkInfo' parameter with value of 'true',
// NuGet will happily accept that. Hence the installation will succeed.
// This is used by the package restore mode.
var localRepository = new MockPackageRepository();
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
// A is solution-level package
IPackage packageA = PackageUtility.CreatePackage("A", "1.0.0",
tools: new string[] { "init.ps1"},
dependencies: new[] {
new PackageDependency("C")
});
IPackage packageC = PackageUtility.CreatePackage("C", "1.0.0-RC-1", content: new string[] { "a.txt" } );
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageC);
// Act
packageManager.InstallPackage(packageA, ignoreDependencies: false, allowPrereleaseVersions: true, ignoreWalkInfo: true);
// Assert
Assert.True(localRepository.Exists(packageA));
Assert.True(localRepository.Exists(packageC));
}
示例15: ExecuteMethodCallsUninstallPackageMethodOnPackageManager
public void ExecuteMethodCallsUninstallPackageMethodOnPackageManager()
{
// Arrange
var packageA = PackageUtility.CreatePackage("A", "1.0");
var packageB = PackageUtility.CreatePackage("B", "2.0");
var packageC = PackageUtility.CreatePackage("C", "3.0");
var sourceRepository = new MockPackageRepository();
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageC);
sourceRepository.AddPackage(packageB);
var localRepository = new MockPackageRepository();
localRepository.AddPackage(packageB);
var projectManager1 = new Mock<IProjectManager>();
projectManager1.Setup(p => p.LocalRepository).Returns(localRepository);
projectManager1.Setup(p => p.IsInstalled(It.IsAny<IPackage>())).Returns<IPackage>(p => localRepository.Exists(p));
var projectManager2 = new Mock<IProjectManager>();
projectManager2.Setup(p => p.LocalRepository).Returns(localRepository);
projectManager2.Setup(p => p.IsInstalled(It.IsAny<IPackage>())).Returns<IPackage>(p => localRepository.Exists(p));
var project1 = MockProjectUtility.CreateMockProject("Project1");
var project2 = MockProjectUtility.CreateMockProject("Project2");
var packageManager = new Mock<IVsPackageManager>();
packageManager.Setup(p => p.SourceRepository).Returns(sourceRepository);
packageManager.Setup(p => p.GetProjectManager(It.Is<Project>(s => s == project1))).Returns(projectManager1.Object);
packageManager.Setup(p => p.GetProjectManager(It.Is<Project>(s => s == project2))).Returns(projectManager2.Object);
packageManager.Setup(p => p.IsProjectLevel(It.IsAny<IPackage>())).Returns(true);
var solutionManager = new Mock<ISolutionManager>();
solutionManager.Setup(p => p.GetProject(It.Is<string>(s => s == "Project1"))).Returns(project1);
solutionManager.Setup(p => p.GetProject(It.Is<string>(s => s == "Project2"))).Returns(project2);
solutionManager.Setup(p => p.GetProjects()).Returns(new Project[] { project1, project2 });
var mockWindowService = new Mock<IUserNotifierServices>();
mockWindowService.Setup(p => p.ShowProjectSelectorWindow(
It.IsAny<string>(),
It.IsAny<IPackage>(),
It.IsAny<Predicate<Project>>(),
It.IsAny<Predicate<Project>>())).Returns(Enumerable.Empty<Project>());
var provider = CreateSolutionInstalledProvider(packageManager.Object, localRepository, solutionManager: solutionManager.Object, userNotifierServices: mockWindowService.Object);
var extensionTree = provider.ExtensionsTree;
var firstTreeNode = (SimpleTreeNode)extensionTree.Nodes[0];
provider.SelectedNode = firstTreeNode;
var manualEvent = new ManualResetEventSlim(false);
provider.ExecuteCompletedCallback = delegate
{
// Assert
packageManager.Verify(p => p.UninstallPackage(
projectManager1.Object,
packageB.Id,
null,
false,
false,
provider),
Times.Once());
packageManager.Verify(p => p.UninstallPackage(
projectManager2.Object,
packageB.Id,
null,
false,
false,
provider),
Times.Once());
manualEvent.Set();
};
var extensionB = new PackageItem(provider, packageB);
// Act
provider.Execute(extensionB);
// do not allow the method to return
manualEvent.Wait();
}