本文整理汇总了C#中NuGet.Test.Mocks.MockProjectSystem类的典型用法代码示例。如果您正苦于以下问题:C# MockProjectSystem类的具体用法?C# MockProjectSystem怎么用?C# MockProjectSystem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockProjectSystem类属于NuGet.Test.Mocks命名空间,在下文中一共展示了MockProjectSystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InstallPackageSetOperationToInstall3
public void InstallPackageSetOperationToInstall3()
{
// Arrange
var localRepository = new MockSharedPackageRepository();
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var pathResolver = new DefaultPackagePathResolver(projectSystem);
var projectManager = new ProjectManager(localRepository, pathResolver, new MockProjectSystem(), new MockPackageRepository());
var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, projectSystem, localRepository, new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object);
var package = PackageUtility.CreatePackage("foo", "1.0", new[] { "hello" });
sourceRepository.AddPackage(package);
var package2 = PackageUtility.CreatePackage("bar", "2.0", new[] { "world" });
sourceRepository.AddPackage(package2);
// Act
packageManager.InstallPackage(
projectManager,
package2,
new PackageOperation[] {
new PackageOperation(package, PackageAction.Install),
new PackageOperation(package2, PackageAction.Install),
},
ignoreDependencies: false,
allowPrereleaseVersions: false,
logger: NullLogger.Instance);
// Assert
Assert.Equal("Install", sourceRepository.LastOperation);
Assert.Equal("bar", sourceRepository.LastMainPackageId);
Assert.Equal("2.0", sourceRepository.LastMainPackageVersion);
}
示例2: AddPackageReferenceAppliesPackageReferencesCorrectly2
public void AddPackageReferenceAppliesPackageReferencesCorrectly2()
{
// 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",
assemblyReferences: new[] { "lib\\net35\\a.dll", "lib\\net35\\b.dll" });
sourceRepository.AddPackage(packageA);
Mock<IPackage> mockPackageA = Mock.Get<IPackage>(packageA);
mockPackageA.Setup(m => m.PackageAssemblyReferences).Returns(
new PackageReferenceSet[] {
new PackageReferenceSet(VersionUtility.ParseFrameworkName("net40"), new [] { "a.dll" }),
new PackageReferenceSet(VersionUtility.ParseFrameworkName("net45"), new [] { "b.dll" })
}
);
// Act
projectManager.AddPackageReference("A");
// Assert
Assert.True(projectManager.LocalRepository.Exists("A"));
Assert.False(projectSystem.ReferenceExists("a.dll"));
Assert.True(projectSystem.ReferenceExists("b.dll"));
}
示例3: AddPackageReferenceLoadPackagesProjectNameConfigIfPresent
public void AddPackageReferenceLoadPackagesProjectNameConfigIfPresent()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(
new FrameworkName(".NETFramework, Version=4.5"));
projectSystem.ProjectName = "CoolProject";
projectSystem.AddFile("packages.CoolProject.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
<package id=""luan"" version=""3.0"" />
</packages>");
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
IPackage packageA = PackageUtility.CreatePackage(
"A",
"1.0",
assemblyReferences: new[] { "lib\\a.dll"});
sourceRepository.AddPackage(packageA);
// Act
projectManager.AddPackageReference("A");
// Assert
Assert.True(projectManager.LocalRepository.Exists("A"));
Assert.True(projectManager.Project.FileExists("packages.CoolProject.config"));
Assert.False(projectManager.Project.FileExists("packages.config"));
}
示例4: UninstallPackageExecutesUninstallScript
public void UninstallPackageExecutesUninstallScript()
{
// Arrange
var activeRepository = new MockPackageRepository();
var localRepository = new Mock<MockPackageRepository>() { CallBase = true };
localRepository.As<ISharedPackageRepository>();
var projectRepository = new MockProjectPackageRepository(localRepository.Object);
var project = TestUtils.GetProject("Foo");
var projectSystem = new MockProjectSystem();
var projectManager = new ProjectManager(activeRepository, new DefaultPackagePathResolver(new MockFileSystem()), projectSystem, projectRepository);
var package = PackageUtility.CreatePackage("A");
var scriptExecutor = new Mock<IScriptExecutor>(MockBehavior.Strict);
scriptExecutor.Setup(s => s.Execute(@"C:\MockFileSystem\A.1.0", "uninstall.ps1", package, project, NullLogger.Instance)).Returns(true).Verifiable();
var packageManager = new Mock<VsPackageManager>(TestUtils.GetSolutionManager(), activeRepository, new Mock<IFileSystemProvider>().Object, new MockFileSystem(), localRepository.Object,
new Mock<IRecentPackageRepository>().Object, new Mock<VsPackageInstallerEvents>().Object) { CallBase = true };
var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
packageManagerFactory.Setup(m => m.CreatePackageManager(activeRepository, false, false)).Returns(packageManager.Object);
packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager).Verifiable();
var packageUninstaller = new VsPackageUninstaller(packageManagerFactory.Object, activeRepository, scriptExecutor.Object);
// Act
localRepository.Object.AddPackage(package);
packageUninstaller.UninstallPackage(project, "A", removeDependencies: true);
// Assert
scriptExecutor.Verify();
Assert.False(localRepository.Object.Contains(package));
}
示例5: AddPackageReferenceWhenNewVersionOfPackageAlreadyReferencedThrows
public void AddPackageReferenceWhenNewVersionOfPackageAlreadyReferencedThrows()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
IPackage packageA10 = PackageUtility.CreatePackage("A", "1.0",
dependencies: new List<PackageDependency> {
new PackageDependency("B")
}, content: new[] { "foo" });
IPackage packageA20 = PackageUtility.CreatePackage("A", "2.0",
dependencies: new List<PackageDependency> {
new PackageDependency("B")
}, content: new[] { "foo" });
IPackage packageB10 = PackageUtility.CreatePackage("B", "1.0", content: new[] { "foo" });
projectManager.LocalRepository.AddPackage(packageA20);
projectManager.LocalRepository.AddPackage(packageB10);
sourceRepository.AddPackage(packageA20);
sourceRepository.AddPackage(packageB10);
sourceRepository.AddPackage(packageA10);
sourceRepository.AddPackage(packageA20);
sourceRepository.AddPackage(packageB10);
// Act & Assert
ExceptionAssert.Throws<InvalidOperationException>(() => projectManager.AddPackageReference("A", SemanticVersion.Parse("1.0")), @"Already referencing a newer version of 'A'.");
}
示例6: InstallPackageDoesNotUseFallbackRepository
public void InstallPackageDoesNotUseFallbackRepository()
{
// Arrange
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object;
var sourceRepository = new MockPackageRepository();
var projectRepository = new MockProjectPackageRepository(localRepository);
var fileSystem = new MockFileSystem();
var projectSystem = new MockProjectSystem();
var pathResolver = new DefaultPackagePathResolver(new MockProjectSystem());
var project = TestUtils.GetProject("Foo");
var projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, projectRepository);
var scriptExecutor = new Mock<IScriptExecutor>();
var packageManager = new Mock<VsPackageManager>(TestUtils.GetSolutionManager(), sourceRepository, fileSystem, localRepository, new Mock<IRecentPackageRepository>().Object,
new Mock<VsPackageInstallerEvents>().Object) { CallBase = true };
var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), false, false)).Returns(packageManager.Object);
packageManagerFactory.Setup(m => m.CreatePackageManager()).Throws(new Exception("A"));
packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), true, It.IsAny<bool>())).Throws(new Exception("B"));
packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager);
var package = NuGet.Test.PackageUtility.CreatePackage("foo", "1.0", new[] { "hello" }, tools: new[] { "init.ps1", "install.ps1" });
sourceRepository.AddPackage(package);
var installer = new VsPackageInstaller(packageManagerFactory.Object, scriptExecutor.Object, new Mock<IPackageRepositoryFactory>().Object);
// Act
installer.InstallPackage(sourceRepository, project, "foo", new SemanticVersion("1.0"), ignoreDependencies: false);
// Assert
packageManagerFactory.Verify(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), false, false), Times.Once());
packageManagerFactory.Verify(m => m.CreatePackageManager(), Times.Never());
packageManagerFactory.Verify(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), true, It.IsAny<bool>()), Times.Never());
}
示例7: XdtTransformOnXmlNodeWithAttributes
public void XdtTransformOnXmlNodeWithAttributes()
{
// Arrange
var mockProjectSystem = new MockProjectSystem();
var mockRepository = new MockPackageRepository();
mockProjectSystem.AddFile("test.xml",
@"<a attrib=""b""/>".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\test.xml.install.xdt");
file.Setup(m => m.EffectivePath).Returns("test.xml.install.xdt");
file.Setup(m => m.GetStream()).Returns(() =>
@"<a xmlns:xdt=""http://schemas.microsoft.com/XML-Document-Transform""><test xdt:Transform=""InsertIfMissing""/></a>".AsStream());
package.Setup(m => m.GetFiles()).Returns(new[] { file.Object });
mockRepository.AddPackage(package.Object);
// Act
projectManager.AddPackageReference("A");
// Assert
Assert.True(mockProjectSystem.FileExists("test.xml"));
var actual = mockProjectSystem.OpenFile("test.xml").ReadToEnd();
Assert.Equal("<a attrib=\"b\">\t<test/></a>", actual);
}
示例8: InstallPackageRunsInitAndInstallScripts
public void InstallPackageRunsInitAndInstallScripts()
{
// Arrange
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object;
var sourceRepository = new MockPackageRepository();
var projectRepository = new MockProjectPackageRepository(localRepository);
var fileSystem = new MockFileSystem();
var projectSystem = new MockProjectSystem();
var pathResolver = new DefaultPackagePathResolver(new MockProjectSystem());
var project = TestUtils.GetProject("Foo");
var projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, projectRepository);
var scriptExecutor = new Mock<IScriptExecutor>();
var packageManager = new Mock<VsPackageManager>(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, fileSystem, localRepository, new Mock<IRecentPackageRepository>().Object,
new Mock<VsPackageInstallerEvents>().Object) { CallBase = true };
var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), false, false)).Returns(packageManager.Object);
packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager);
var package = NuGet.Test.PackageUtility.CreatePackage("foo", "1.0", new[] { "hello" }, tools: new[] { "init.ps1", "install.ps1" });
sourceRepository.AddPackage(package);
var installer = new VsPackageInstaller(packageManagerFactory.Object, scriptExecutor.Object, new Mock<IPackageRepositoryFactory>().Object, new Mock<IVsCommonOperations>().Object, new Mock<ISolutionManager>().Object);
// Act
installer.InstallPackage(sourceRepository, project, "foo", new SemanticVersion("1.0"), ignoreDependencies: false, skipAssemblyReferences: false);
// Assert
scriptExecutor.Verify(e => e.Execute(It.IsAny<string>(), PowerShellScripts.Init, It.IsAny<IPackage>(), It.IsAny<Project>(), It.IsAny<ILogger>()), Times.Once());
scriptExecutor.Verify(e => e.Execute(It.IsAny<string>(), PowerShellScripts.Install, It.IsAny<IPackage>(), It.IsAny<Project>(), It.IsAny<ILogger>()), Times.Once());
}
示例9: InstallMetadataPackageWithReadMeInstallsIntoProjectAndPackageManager
public void InstallMetadataPackageWithReadMeInstallsIntoProjectAndPackageManager()
{
// Arrange
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object;
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var pathResolver = new DefaultPackagePathResolver(projectSystem);
var projectManager = new ProjectManager(localRepository, pathResolver, new MockProjectSystem(), new MockPackageRepository());
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.0", dependencies: new[] { new PackageDependency("B") });
var mockPackageA = Mock.Get(packageA);
mockPackageA.Setup(m => m.GetFiles()).Returns(PackageUtility.CreateFiles(new[] { "readme.txt" }));
var packageB = PackageUtility.CreatePackage("B", "1.0", content: new[] { "hello.txt" });
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageB);
// Act
packageManager.InstallPackage(projectManager, "A", new SemanticVersion("1.0"), ignoreDependencies: false, allowPrereleaseVersions: false, logger: NullLogger.Instance);
// Assert
Assert.True(packageManager.LocalRepository.Exists(packageA));
Assert.True(projectManager.LocalRepository.Exists(packageA));
Assert.True(packageManager.LocalRepository.Exists(packageB));
Assert.True(projectManager.LocalRepository.Exists(packageB));
}
示例10: InstallPackageWithOperationsExecuteAllOperations
public void InstallPackageWithOperationsExecuteAllOperations()
{
// Arrange
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object;
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var pathResolver = new DefaultPackagePathResolver(projectSystem);
var projectManager = new ProjectManager(localRepository, pathResolver, new MockProjectSystem(), new MockPackageRepository());
var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, projectSystem, localRepository, new Mock<IRecentPackageRepository>().Object);
var package = PackageUtility.CreatePackage("foo", "1.0", new[] { "hello" }, dependencies: new PackageDependency[] { new PackageDependency("bar") });
sourceRepository.AddPackage(package);
var package2 = PackageUtility.CreatePackage("bar", "2.0", new[] { "world" });
sourceRepository.AddPackage(package2);
var package3 = PackageUtility.CreatePackage("awesome", "1.0", new[] { "candy" });
localRepository.AddPackage(package3);
var operations = new PackageOperation[] {
new PackageOperation(package, PackageAction.Install),
new PackageOperation(package2, PackageAction.Install),
new PackageOperation(package3, PackageAction.Uninstall)
};
// Act
packageManager.InstallPackage(projectManager, package, operations, ignoreDependencies: false, logger: NullLogger.Instance);
// Assert
Assert.IsTrue(packageManager.LocalRepository.Exists(package));
Assert.IsTrue(packageManager.LocalRepository.Exists(package2));
Assert.IsTrue(!packageManager.LocalRepository.Exists(package3));
Assert.IsTrue(projectManager.LocalRepository.Exists(package));
Assert.IsTrue(projectManager.LocalRepository.Exists(package2));
}
示例11: InstallPackageAddsAllFilesToFileSystem
public void InstallPackageAddsAllFilesToFileSystem()
{
// Arrange
var projectSystem = new MockProjectSystem();
var sourceRepository = new MockPackageRepository();
var pathResolver = new DefaultPackagePathResolver(projectSystem);
var packageManager = new PackageManager(sourceRepository, pathResolver, projectSystem,
new SharedPackageRepository(pathResolver, projectSystem, projectSystem));
IPackage packageA = PackageUtility.CreatePackage("A", "1.0",
new[] { "contentFile", @"sub\contentFile" },
new[] { @"lib\reference.dll" },
new[] { @"readme.txt" });
sourceRepository.AddPackage(packageA);
// Act
Install("A", new NullProjectManager(packageManager));
// Assert
Assert.Equal(0, projectSystem.References.Count);
Assert.Equal(5, projectSystem.Paths.Count);
Assert.True(projectSystem.FileExists(@"A.1.0\content\contentFile"));
Assert.True(projectSystem.FileExists(@"A.1.0\content\sub\contentFile"));
Assert.True(projectSystem.FileExists(@"A.1.0\lib\reference.dll"));
Assert.True(projectSystem.FileExists(@"A.1.0\tools\readme.txt"));
Assert.True(projectSystem.FileExists(@"A.1.0\A.1.0.nupkg"));
}
示例12: ReinstallPackagesRestoresPackageWithTheSameVersion
public void ReinstallPackagesRestoresPackageWithTheSameVersion()
{
// Arrange
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object;
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var pathResolver = new DefaultPackagePathResolver(projectSystem);
var projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, new MockPackageRepository());
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", new[] { "content.txt" });
sourceRepository.Add(packageA);
localRepository.AddPackage(packageA);
projectManager.LocalRepository.AddPackage(packageA);
// Act
packageManager.ReinstallPackage(projectManager, "A", updateDependencies: true, allowPrereleaseVersions: true, logger: null);
// Assert
Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("1.2")));
Assert.True(projectManager.LocalRepository.Exists("A", new SemanticVersion("1.2")));
}
示例13: AddPackageReferenceAddingPackageWithDuplicateReferenceOverwritesReference
public void AddPackageReferenceAddingPackageWithDuplicateReferenceOverwritesReference()
{
// 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",
assemblyReferences: new[] { "reference.dll" });
var packageB = PackageUtility.CreatePackage("B", "1.0",
assemblyReferences: new[] { "reference.dll" });
mockRepository.AddPackage(packageA);
mockRepository.AddPackage(packageB);
// Act
projectManager.AddPackageReference("A");
projectManager.AddPackageReference("B");
// Assert
Assert.AreEqual(0, projectSystem.Paths.Count);
Assert.AreEqual(1, projectSystem.References.Count);
Assert.IsTrue(projectSystem.References.ContainsKey(@"reference.dll"));
Assert.IsTrue(projectSystem.References.ContainsValue(@"B.1.0\reference.dll"));
Assert.IsTrue(localRepository.Exists("A"));
Assert.IsTrue(localRepository.Exists("B"));
}
示例14: UninstallPackageDoesNotRemoveDependenciesIfFlagIsFalse
public void UninstallPackageDoesNotRemoveDependenciesIfFlagIsFalse()
{
// Arrange
var activeRepository = new MockPackageRepository();
var localRepository = new Mock<MockPackageRepository>() { CallBase = true };
localRepository.As<ISharedPackageRepository>();
var projectRepository = new MockProjectPackageRepository(localRepository.Object);
var project = TestUtils.GetProject("Foo");
var projectSystem = new MockProjectSystem(new FrameworkName(".NETCore, Version=4.5"));
var projectManager = new ProjectManager(activeRepository, new DefaultPackagePathResolver(new MockFileSystem()), projectSystem, projectRepository);
var packageA = PackageUtility.CreatePackage("A", dependencies: new[] { new PackageDependency("B") });
var packageB = PackageUtility.CreatePackage("B");
var scriptExecutor = new Mock<IScriptExecutor>(MockBehavior.Strict);
scriptExecutor.Setup(s => s.Execute(@"C:\MockFileSystem\A.1.0", "uninstall.ps1", packageA, project, new FrameworkName(".NETCore, Version=4.5"), NullLogger.Instance)).Returns(true).Verifiable();
var packageManager = new Mock<VsPackageManager>(TestUtils.GetSolutionManager(), activeRepository, new Mock<IFileSystemProvider>().Object, new MockFileSystem(), localRepository.Object,
new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object) { CallBase = true };
var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
packageManagerFactory.Setup(m => m.CreatePackageManager(activeRepository, false)).Returns(packageManager.Object);
packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager).Verifiable();
var packageUninstaller = new VsPackageUninstaller(packageManagerFactory.Object, activeRepository, scriptExecutor.Object);
// Act
localRepository.Object.AddPackage(packageA);
localRepository.Object.AddPackage(packageB);
packageUninstaller.UninstallPackage(project, "A", removeDependencies: false);
// Assert
scriptExecutor.Verify();
Assert.False(localRepository.Object.Contains(packageA));
Assert.True(localRepository.Object.Contains(packageB));
}
示例15: ReThrowWithMeaningfulErrorMessageWhenXdtFileHasSyntaxError
public void ReThrowWithMeaningfulErrorMessageWhenXdtFileHasSyntaxError()
{
// 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 xd: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
ExceptionAssert.Throws<InvalidDataException>(
() => projectManager.AddPackageReference("A"),
@"An error occurred while applying transformation to 'web.config' in project 'x:\MockFileSystem': 'xd' is an undeclared prefix. Line 3, position 22.");
// 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=""true"" />
</system.web>
</configuration>
", mockProjectSystem.OpenFile("web.config").ReadToEnd());
}