本文整理汇总了C#中NuGet.Test.Mocks.MockProjectSystem.FileExists方法的典型用法代码示例。如果您正苦于以下问题:C# MockProjectSystem.FileExists方法的具体用法?C# MockProjectSystem.FileExists怎么用?C# MockProjectSystem.FileExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NuGet.Test.Mocks.MockProjectSystem
的用法示例。
在下文中一共展示了MockProjectSystem.FileExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddPackageWithXdtTransformFile
public void AddPackageWithXdtTransformFile()
{
// Arrange
var mockProjectSystem = new MockProjectSystem();
var mockRepository = new MockPackageRepository();
mockProjectSystem.AddFile("web.config",
@"<configuration>
<system.web>
<compilation debug=""true"" />
</system.web>
</configuration>
".AsStream());
var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(new MockProjectSystem()), mockProjectSystem, new MockPackageRepository());
var package = new Mock<IPackage>();
package.Setup(m => m.Id).Returns("A");
package.Setup(m => m.Version).Returns(new SemanticVersion("1.0"));
package.Setup(m => m.Listed).Returns(true);
var file = new Mock<IPackageFile>();
file.Setup(m => m.Path).Returns(@"content\web.config.install.xdt");
file.Setup(m => m.EffectivePath).Returns("web.config.install.xdt");
file.Setup(m => m.GetStream()).Returns(() =>
@"<configuration xmlns:xdt=""http://schemas.microsoft.com/XML-Document-Transform"">
<system.web>
<compilation xdt:Locator=""Condition('@debug=true')"" debug=""false"" xdt:Transform=""Replace"" />
</system.web>
</configuration>".AsStream());
var file2 = new Mock<IPackageFile>();
file2.Setup(m => m.Path).Returns(@"content\web.config.uninstall.xdt");
file2.Setup(m => m.EffectivePath).Returns("web.config.uninstall.xdt");
file2.Setup(m => m.GetStream()).Returns(() =>
@"<configuration xmlns:xdt=""http://schemas.microsoft.com/XML-Document-Transform"">
<system.web>
<compilation xdt:Locator=""Match(debug)"" debug=""false"" xdt:Transform=""Remove"" />
</system.web>
</configuration>".AsStream());
package.Setup(m => m.GetFiles()).Returns(new[] { file.Object, file2.Object });
mockRepository.AddPackage(package.Object);
// Act
projectManager.AddPackageReference("A");
// Assert
Assert.False(mockProjectSystem.FileExists("web.config.install.xdt"));
Assert.False(mockProjectSystem.FileExists("web.config.uninstall.xdt"));
Assert.True(mockProjectSystem.FileExists("web.config"));
Assert.Equal(
@"<configuration>
<system.web>
<compilation debug=""false""/>
</system.web>
</configuration>
", mockProjectSystem.OpenFile("web.config").ReadToEnd());
}
示例2: AddFilesAddFilesToProjectSystem
public void AddFilesAddFilesToProjectSystem()
{
// Arrange
var fileSystem = new MockProjectSystem();
var files = PackageUtility.CreateFiles(new[] { "A", "B", "C" });
// Act
fileSystem.AddFiles(files, String.Empty);
// Assert
Assert.True(fileSystem.FileExists("A"));
Assert.True(fileSystem.FileExists("B"));
Assert.True(fileSystem.FileExists("C"));
}
示例3: AddingPackageReferenceAddsPreprocessedFileToTargetPathWithRemovedExtension
public void AddingPackageReferenceAddsPreprocessedFileToTargetPathWithRemovedExtension()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
IPackage packageA = PackageUtility.CreatePackage("A", "1.0", new[] { @"foo\bar\file.pp" });
sourceRepository.AddPackage(packageA);
// Act
projectManager.AddPackageReference("A");
// Assert
Assert.False(projectSystem.FileExists(@"foo\bar\file.pp"));
Assert.True(projectSystem.FileExists(@"foo\bar\file"));
}
示例4: AddPackageAddsFileToFileSystem
public void AddPackageAddsFileToFileSystem()
{
// Arrange
var mockFileSystem = new MockProjectSystem();
var repository = new LocalPackageRepository(new DefaultPackagePathResolver(mockFileSystem),
mockFileSystem);
IPackage package = PackageUtility.CreatePackage("A", "1.0");
// Act
repository.AddPackage(package);
// Assert
Assert.IsTrue(mockFileSystem.FileExists(@"A.1.0\A.1.0.nupkg"));
}
示例5: RemovingPackageWithModifiedContentFileWithinIgnoreMarkersSucceeds2
public void RemovingPackageWithModifiedContentFileWithinIgnoreMarkersSucceeds2()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var projectManager = new ProjectManager(
sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
var packageA = PackageUtility.CreatePackage("A", "1.0", content: new[] { "a.file" });
var contentFile = PackageUtility.CreateMockedPackageFile("content", "a.file", @"this is awesome.
*******NUGET: BEGIN LICENSE TEXT------------------
SDAFLKDSAJFL;KJDSAL;KFJL;DSAKJFL;KDSA
******NUGET: END LICENSE TEXT-------");
var mockPackageA = Mock.Get<IPackage>(packageA);
mockPackageA.Setup(p => p.GetFiles()).Returns(new[] { contentFile.Object });
sourceRepository.AddPackage(packageA);
projectManager.AddPackageReference("A");
Assert.True(projectManager.LocalRepository.Exists(packageA));
Assert.True(projectSystem.FileExists("a.file"));
projectSystem.ReadAllText("a.file");
// now modify 'a.file' to include ignore line markers
projectSystem.AddFile("a.file", @"this is awesome.");
// Act
projectManager.RemovePackageReference("A");
// Assert
Assert.False(projectManager.LocalRepository.Exists(packageA));
Assert.False(projectSystem.FileExists("a.file"));
}
示例6: AddPackageReferencePicksThePortableLibraryWithMoreMatchingVersionsWhenInstalledIntoPortableProject2
public void AddPackageReferencePicksThePortableLibraryWithMoreMatchingVersionsWhenInstalledIntoPortableProject2()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(VersionUtility.ParseFrameworkName("portable-net45+sl5+wp71"));
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
IPackage packageA = PackageUtility.CreatePackage(
"A",
"1.0",
new[] { "portable-net45+sl5+wp8\\one.txt",
"portable-net45+sl5+wp8\\two.txt",
"portable-net45+sl5+wp71+win8\\three.txt",
"portable-net45+sl4+wp71+win8\\four.txt",
"portable-net40+sl4+wp71+win8\\five.txt",
"portable-net40+sl4+wp7+win8\\six.txt",
"portable-wp8+win8\\seven.txt" });
sourceRepository.AddPackage(packageA);
// Act
projectManager.AddPackageReference("A");
// Assert
Assert.False(projectSystem.FileExists("one.txt"));
Assert.False(projectSystem.FileExists("two.txt"));
Assert.True(projectSystem.FileExists("three.txt"));
Assert.False(projectSystem.FileExists("four.txt"));
Assert.False(projectSystem.FileExists("five.txt"));
Assert.False(projectSystem.FileExists("six.txt"));
Assert.False(projectSystem.FileExists("seven.txt"));
}
示例7: AddPackageReferencePicksMatchingProfileEvenIfItIsEmpty
public void AddPackageReferencePicksMatchingProfileEvenIfItIsEmpty()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(VersionUtility.ParseFrameworkName("sl4"));
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
IPackage packageA = PackageUtility.CreatePackage("A", "1.0", new[] { "sl3\\_._", "me.txt" });
sourceRepository.AddPackage(packageA);
// Act
projectManager.AddPackageReference("A");
// Assert
Assert.False(projectSystem.FileExists("me.txt"));
Assert.False(projectSystem.FileExists("_._"));
}
示例8: AddPackageReferencePrefersFullProfileOverClientProfileWhenInstallIntoFullProfileProject
public void AddPackageReferencePrefersFullProfileOverClientProfileWhenInstallIntoFullProfileProject()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework, Version=4.5"));
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
IPackage packageA = PackageUtility.CreatePackage(
"A",
"1.0",
content: new[] { "net40-client\\b.txt", "net40\\a.txt" },
assemblyReferences: new[] { "lib\\net40\\a.dll", "lib\\net40-client\\b.dll" });
sourceRepository.AddPackage(packageA);
// Act
projectManager.AddPackageReference("A");
// Assert
Assert.False(projectSystem.ReferenceExists("b.dll"));
Assert.False(projectSystem.FileExists("b.txt"));
Assert.True(projectSystem.ReferenceExists("a.dll"));
Assert.True(projectSystem.FileExists("a.txt"));
}
示例9: AddPackageReferencePickPortableDependencySetOverFallbackDependencySet
public void AddPackageReferencePickPortableDependencySetOverFallbackDependencySet()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(VersionUtility.ParseFrameworkName("portable-net45+wp8+windows8"));
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
var dependencySets = new PackageDependencySet[]
{
new PackageDependencySet(targetFramework: null, dependencies: new [] { PackageDependency.CreateDependency("B", "1.0.0")}),
new PackageDependencySet(targetFramework: VersionUtility.ParseFrameworkName("net45"), dependencies: new PackageDependency[0] { }),
new PackageDependencySet(targetFramework: VersionUtility.ParseFrameworkName("win8"), dependencies: new PackageDependency[0] { }),
new PackageDependencySet(targetFramework: VersionUtility.ParseFrameworkName("wp8"), dependencies: new PackageDependency[0] { }),
new PackageDependencySet(targetFramework: VersionUtility.ParseFrameworkName("portable-net45+win8+wp8"), dependencies: new PackageDependency[0] { }),
};
IPackage packageA = PackageUtility.CreatePackageWithDependencySets("A", "1.0", new[] { "me.txt" }, dependencySets: dependencySets);
IPackage packageB = PackageUtility.CreatePackage("B", "1.0", new[] { "you.txt" });
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageB);
// Act
projectManager.AddPackageReference("A", null, ignoreDependencies: false, allowPrereleaseVersions: true);
// Assert
Assert.True(projectManager.LocalRepository.Exists("A"));
Assert.False(projectManager.LocalRepository.Exists("B"));
Assert.True(projectSystem.FileExists("me.txt"));
Assert.False(projectSystem.FileExists("you.txt"));
}
示例10: UpdatePackageReferenceIncludeDependencyPackageCorrectly2
public void UpdatePackageReferenceIncludeDependencyPackageCorrectly2()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework", new Version("4.0")));
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
var dependency = new PackageDependency("B", null);
var dependencySet = CreateDependencySet(".NETFramework, Version=4.0", dependency);
IPackage packageA = PackageUtility.CreatePackageWithDependencySets("A", "1.0",
dependencySets: new List<PackageDependencySet> { dependencySet },
content: new[] { "a.txt" });
var dependency2 = new PackageDependency("B", null);
var dependencySet2 = CreateDependencySet(".NETFramework, Version=4.5", dependency2);
IPackage packageA2 = PackageUtility.CreatePackageWithDependencySets("A", "2.0",
dependencySets: new List<PackageDependencySet> { dependencySet2 },
content: new[] { "a2.txt" });
IPackage packageB = PackageUtility.CreatePackage("B", "1.0", content: new[] { "b.txt" });
sourceRepository.AddPackage(packageB);
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageA2);
projectManager.AddPackageReference("A", new SemanticVersion("1.0"));
Assert.True(projectManager.LocalRepository.Exists("A"));
Assert.True(projectManager.LocalRepository.Exists("B"));
// Act
projectManager.UpdatePackageReference("A");
// Assert
Assert.False(projectManager.LocalRepository.Exists("A", new SemanticVersion("1.0")));
Assert.True(projectManager.LocalRepository.Exists("A", new SemanticVersion("2.0")));
Assert.False(projectManager.LocalRepository.Exists("B"));
Assert.True(projectSystem.FileExists("a2.txt"));
Assert.False(projectSystem.FileExists("b.txt"));
}
示例11: RemovePackageReferenceExcludesFileIfAnotherPackageUsesThem
public void RemovePackageReferenceExcludesFileIfAnotherPackageUsesThem()
{
// Arrange
var mockProjectSystem = new MockProjectSystem();
var mockRepository = new MockPackageRepository();
var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(new MockProjectSystem()), mockProjectSystem, new MockPackageRepository());
IPackage packageA = PackageUtility.CreatePackage("A", "1.0",
new[] { "fileA", "commonFile" });
IPackage packageB = PackageUtility.CreatePackage("B", "1.0",
new[] { "fileB", "commonFile" });
mockRepository.AddPackage(packageA);
mockRepository.AddPackage(packageB);
projectManager.AddPackageReference("A");
projectManager.AddPackageReference("B");
// Act
projectManager.RemovePackageReference("A");
// Assert
Assert.True(mockProjectSystem.Deleted.Contains(@"fileA"));
Assert.True(mockProjectSystem.FileExists(@"commonFile"));
}
示例12: AddPackageReferenceAddsContentAndReferencesProjectSystem
public void AddPackageReferenceAddsContentAndReferencesProjectSystem()
{
// 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[] { "contentFile" },
new[] { "reference.dll" },
new[] { "tool" });
mockRepository.AddPackage(packageA);
// Act
projectManager.AddPackageReference("A");
// Assert
Assert.Equal(1, projectSystem.Paths.Count);
Assert.Equal(1, projectSystem.References.Count);
Assert.True(projectSystem.References.ContainsKey(@"reference.dll"));
Assert.True(projectSystem.FileExists(@"contentFile"));
Assert.True(localRepository.Exists("A"));
}
示例13: ReinstallPackagesRestoresPackageInAllProjectsWithNewContentIfSourcePackageChanges
public void ReinstallPackagesRestoresPackageInAllProjectsWithNewContentIfSourcePackageChanges()
{
// Arrange
var localRepositoryMock = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
var localRepository = localRepositoryMock.Object;
var sourceRepository = new MockPackageRepository();
var projectSystem1 = new MockProjectSystem();
var pathResolver1 = new DefaultPackagePathResolver(projectSystem1);
var packageReferenceRepository1 = new PackageReferenceRepository(projectSystem1, localRepository);
var projectManager1 = new ProjectManager(localRepository, pathResolver1, projectSystem1, packageReferenceRepository1);
var projectSystem2 = new MockProjectSystem();
var pathResolver2 = new DefaultPackagePathResolver(projectSystem2);
var packageReferenceRepository2 = new PackageReferenceRepository(projectSystem2, localRepository);
var projectManager2 = new ProjectManager(localRepository, pathResolver2, projectSystem2, packageReferenceRepository2);
var project1 = TestUtils.GetProject("Project1");
var project2 = TestUtils.GetProject("Project2");
var packageManager = new MockVsPackageManager(
TestUtils.GetSolutionManager(projects: new[] { project1, project2 }),
sourceRepository,
new Mock<IFileSystemProvider>().Object,
projectSystem2,
localRepository,
new Mock<IDeleteOnRestartManager>().Object,
new Mock<VsPackageInstallerEvents>().Object);
packageManager.RegisterProjectManager(project1, projectManager1);
packageManager.RegisterProjectManager(project2, projectManager2);
var packageA = PackageUtility.CreatePackage(
"A",
"1.2-alpha",
new[] { "content.txt" },
new[] { "lib\\ref.dll" });
var packageA2 = PackageUtility.CreatePackage(
"A",
"1.2-alpha",
new[] { "foo.txt" },
new[] { "lib\\bar.dll" });
var packageB = PackageUtility.CreatePackage(
"B",
"2.0",
new[] { "hello.txt" },
new[] { "lib\\comma.dll" });
var packageB2 = PackageUtility.CreatePackage(
"B",
"2.0",
new[] { "world.txt" },
new[] { "lib\\dude.dll" });
sourceRepository.Add(packageA);
sourceRepository.Add(packageB);
// install package A -> project 1
// and package B -> project 2
packageManager.InstallPackage(projectManager1, "A", new SemanticVersion("1.2-alpha"), ignoreDependencies: false, allowPrereleaseVersions: true, logger: null);
packageManager.InstallPackage(projectManager2, "B", new SemanticVersion("2.0"), ignoreDependencies: false, allowPrereleaseVersions: true, logger: null);
Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
Assert.True(projectManager1.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
Assert.True(projectSystem1.FileExists("content.txt"));
Assert.True(projectSystem1.ReferenceExists("ref.dll"));
Assert.True(packageManager.LocalRepository.Exists("B", new SemanticVersion("2.0")));
Assert.True(projectManager2.LocalRepository.Exists("B", new SemanticVersion("2.0")));
Assert.True(projectSystem2.FileExists("hello.txt"));
Assert.True(projectSystem2.ReferenceExists("comma.dll"));
// now change the package A and B to different packages
sourceRepository.RemovePackage(packageA);
sourceRepository.RemovePackage(packageB);
sourceRepository.AddPackage(packageA2);
sourceRepository.AddPackage(packageB2);
localRepositoryMock.Setup(p => p.IsReferenced("A", new SemanticVersion("1.2-alpha"))).Returns((string id, SemanticVersion version) => projectManager1.LocalRepository.Exists(id, version));
localRepositoryMock.Setup(p => p.IsReferenced("B", new SemanticVersion("2.0"))).Returns((string id, SemanticVersion version) => projectManager2.LocalRepository.Exists(id, version));
// Act
packageManager.ReinstallPackages(updateDependencies: true, allowPrereleaseVersions: false, logger: NullLogger.Instance, eventListener: NullPackageOperationEventListener.Instance);
// Assert
Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
Assert.True(projectManager1.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
Assert.False(projectSystem1.FileExists("content.txt"));
Assert.True(projectSystem1.FileExists("foo.txt"));
Assert.False(projectSystem1.ReferenceExists("ref.dll"));
Assert.True(projectSystem1.ReferenceExists("bar.dll"));
Assert.True(packageManager.LocalRepository.Exists("B", new SemanticVersion("2.0")));
Assert.True(projectManager2.LocalRepository.Exists("B", new SemanticVersion("2.0")));
Assert.False(projectSystem2.FileExists("hello.txt"));
Assert.True(projectSystem2.FileExists("world.txt"));
//.........这里部分代码省略.........
示例14: ReinstallPackagesSkipRestallingForOneProjectButProceedWithTheOther
public void ReinstallPackagesSkipRestallingForOneProjectButProceedWithTheOther()
{
// Arrange
var localRepositoryMock = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
var localRepository = localRepositoryMock.Object;
var sourceRepository = new MockPackageRepository();
var projectSystem1 = new MockProjectSystem(new FrameworkName(".NETFramework, Version=v3.0"));
var pathResolver1 = new DefaultPackagePathResolver(projectSystem1);
var packageReferenceRepository1 = new PackageReferenceRepository(projectSystem1, localRepository);
var projectManager1 = new ProjectManager(localRepository, pathResolver1, projectSystem1, packageReferenceRepository1);
var projectSystem2 = new MockProjectSystem(new FrameworkName(".NETCore, Version=v4.5"));
var pathResolver2 = new DefaultPackagePathResolver(projectSystem2);
var packageReferenceRepository2 = new PackageReferenceRepository(projectSystem2, localRepository);
var projectManager2 = new ProjectManager(localRepository, pathResolver2, projectSystem2, packageReferenceRepository2);
var project1 = TestUtils.GetProject("Project1");
var project2 = TestUtils.GetProject("Project2");
var packageManager = new MockVsPackageManager(
TestUtils.GetSolutionManager(projects: new[] { project1, project2 }),
sourceRepository,
new Mock<IFileSystemProvider>().Object,
projectSystem2,
localRepository,
new Mock<IDeleteOnRestartManager>().Object,
new Mock<VsPackageInstallerEvents>().Object);
packageManager.RegisterProjectManager(project1, projectManager1);
packageManager.RegisterProjectManager(project2, projectManager2);
var packageA = PackageUtility.CreatePackage(
"A",
"1.2-alpha",
new[] { "net30\\content.txt", "silverlight40\\content4.txt" },
new[] { "lib\\net30\\ref.dll", "lib\\silverlight40\\refsl.dll" });
var packageB = PackageUtility.CreatePackage(
"B",
"2.0",
new[] { "winrt45\\hello.txt", "sl4-wp71\\world.txt" },
new[] { "lib\\winrt45\\comma.dll", "lib\\sl4-wp71\\dude.dll" });
sourceRepository.Add(packageA);
localRepository.AddPackage(packageA);
localRepository.AddPackage(packageB);
// install package A -> project 1
// and package B -> project 2
packageManager.InstallPackage(projectManager1, "A", new SemanticVersion("1.2-alpha"), ignoreDependencies: false, allowPrereleaseVersions: true, logger: null);
packageManager.InstallPackage(projectManager2, "B", new SemanticVersion("2.0"), ignoreDependencies: false, allowPrereleaseVersions: true, logger: null);
// now change project's target framework to silverlight
projectSystem1.ChangeTargetFramework(new FrameworkName("Silverlight, Version=v4.0"));
projectSystem2.ChangeTargetFramework(new FrameworkName("Silverlight, Version=v4.0, Profile=WindowsPhone71"));
localRepositoryMock.Setup(p => p.IsReferenced("A", new SemanticVersion("1.2-alpha"))).Returns((string id, SemanticVersion version) => projectManager1.LocalRepository.Exists(id, version));
localRepositoryMock.Setup(p => p.IsReferenced("B", new SemanticVersion("2.0"))).Returns((string id, SemanticVersion version) => projectManager2.LocalRepository.Exists(id, version));
var logger = new Mock<ILogger>();
logger.Setup(s => s.Log(
MessageLevel.Warning,
"Skipped reinstalling package '{0}' in project '{1}' because the package does not exist in the package source.",
"B 2.0",
"Project2")
).Verifiable();
// Act
packageManager.ReinstallPackages(updateDependencies: true, allowPrereleaseVersions: false, logger: logger.Object, eventListener: NullPackageOperationEventListener.Instance);
// Assert
logger.Verify();
Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
Assert.True(projectManager1.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
Assert.False(projectSystem1.FileExists("content.txt"));
Assert.True(projectSystem1.FileExists("content4.txt"));
Assert.False(projectSystem1.ReferenceExists("ref.dll"));
Assert.True(projectSystem1.ReferenceExists("refsl.dll"));
Assert.True(packageManager.LocalRepository.Exists("B", new SemanticVersion("2.0")));
Assert.True(projectManager2.LocalRepository.Exists("B", new SemanticVersion("2.0")));
Assert.True(projectSystem2.FileExists("hello.txt"));
Assert.False(projectSystem2.FileExists("world.txt"));
Assert.True(projectSystem2.ReferenceExists("comma.dll"));
Assert.False(projectSystem2.ReferenceExists("dude.dll"));
}
示例15: ReinstallPackagesRestoresAllPackagesInAProjectWithNewContentIfProjectFrameworkChanges
public void ReinstallPackagesRestoresAllPackagesInAProjectWithNewContentIfProjectFrameworkChanges()
{
// Arrange
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object;
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework, Version=v3.0"));
var pathResolver = new DefaultPackagePathResolver(projectSystem);
var packageReferenceRepository = new PackageReferenceRepository(projectSystem, localRepository);
var projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, packageReferenceRepository);
var packageManager = new VsPackageManager(
TestUtils.GetSolutionManager(),
sourceRepository,
new Mock<IFileSystemProvider>().Object,
projectSystem,
localRepository,
new Mock<IDeleteOnRestartManager>().Object,
new Mock<VsPackageInstallerEvents>().Object);
var packageA = PackageUtility.CreatePackage(
"A",
"1.2-alpha",
new[] { "net30\\content.txt", "silverlight40\\content4.txt" },
new[] { "lib\\net30\\ref.dll", "lib\\silverlight40\\refsl.dll" });
var packageB = PackageUtility.CreatePackage(
"B",
"2.0",
new[] { "net30\\contentB.txt", "silverlight40\\content4B.txt" },
new[] { "lib\\net30\\refB.dll", "lib\\silverlight40\\refslB.dll" });
sourceRepository.Add(packageA);
sourceRepository.Add(packageB);
packageManager.InstallPackage(projectManager, "A", new SemanticVersion("1.2-alpha"), ignoreDependencies: false, allowPrereleaseVersions: true, logger: null);
packageManager.InstallPackage(projectManager, "B", new SemanticVersion("2.0"), ignoreDependencies: false, allowPrereleaseVersions: true, logger: null);
Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
Assert.True(projectManager.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
Assert.True(projectSystem.FileExists("content.txt"));
Assert.False(projectSystem.FileExists("content4.txt"));
Assert.True(projectSystem.ReferenceExists("ref.dll"));
Assert.False(projectSystem.ReferenceExists("refsl.dll"));
Assert.True(packageManager.LocalRepository.Exists("B"));
Assert.True(projectManager.LocalRepository.Exists("B"));
Assert.True(projectSystem.FileExists("contentB.txt"));
Assert.False(projectSystem.FileExists("content4B.txt"));
Assert.True(projectSystem.ReferenceExists("refB.dll"));
Assert.False(projectSystem.ReferenceExists("refslB.dll"));
// now change project's target framework to silverlight
projectSystem.ChangeTargetFramework(new FrameworkName("Silverlight, Version=v4.0"));
// Act
packageManager.ReinstallPackages(projectManager, updateDependencies: true, allowPrereleaseVersions: false, logger: null);
// Assert
Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
Assert.True(projectManager.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
Assert.False(projectSystem.FileExists("content.txt"));
Assert.True(projectSystem.FileExists("content4.txt"));
Assert.False(projectSystem.ReferenceExists("ref.dll"));
Assert.True(projectSystem.ReferenceExists("refsl.dll"));
Assert.True(packageManager.LocalRepository.Exists("B"));
Assert.True(projectManager.LocalRepository.Exists("B"));
Assert.False(projectSystem.FileExists("contentB.txt"));
Assert.True(projectSystem.FileExists("content4B.txt"));
Assert.False(projectSystem.ReferenceExists("refB.dll"));
Assert.True(projectSystem.ReferenceExists("refslB.dll"));
}