本文整理汇总了C#中NuGet.Test.Mocks.MockProjectSystem.AddFile方法的典型用法代码示例。如果您正苦于以下问题:C# MockProjectSystem.AddFile方法的具体用法?C# MockProjectSystem.AddFile怎么用?C# MockProjectSystem.AddFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NuGet.Test.Mocks.MockProjectSystem
的用法示例。
在下文中一共展示了MockProjectSystem.AddFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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"));
}
示例2: 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);
}
示例3: UpdatePackageOverwriteAllFilesWhenFileConflictActionSetToOverwrite
public void UpdatePackageOverwriteAllFilesWhenFileConflictActionSetToOverwrite()
{
// 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();
projectSystem.AddFile("one.txt", "this is one");
projectSystem.AddFile("two.txt", "this is two");
var packages = new List<IPackage>();
var package_A10 = PackageUtility.CreatePackage("A", "1.0", content: new[] { "1.txt" });
var package_A12 = PackageUtility.CreatePackage("A", "1.2", content: new[] { "one.txt", "two.txt" });
localRepository.Add(package_A10);
sourceRepository.Add(package_A12);
var sharedRepository = new Mock<ISharedPackageRepository>(MockBehavior.Strict);
sharedRepository.Setup(s => s.AddPackage(package_A12)).Callback<IPackage>(p => packages.Add(p));
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 console = new Mock<IConsole>();
console.Setup(c => c.ResolveFileConflict(It.IsAny<string>())).Returns(FileConflictResolution.Ignore);
var updateCommand = new UpdateCommand()
{
RepositoryFactory = repositoryFactory.Object,
SourceProvider = packageSourceProvider.Object,
Console = console.Object,
FileConflictAction = FileConflictAction.Overwrite
};
// Act
updateCommand.UpdatePackages(localRepository, fileSystem, sharedRepository.Object, sourceRepository, constraintProvider, pathResolver, projectSystem);
// Assert
Assert.True(localRepository.Exists("A", new SemanticVersion("1.2")));
Assert.Equal("content\\one.txt", projectSystem.ReadAllText("one.txt"));
Assert.Equal("content\\two.txt", projectSystem.ReadAllText("two.txt"));
}
示例4: 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());
}
示例5: GetPackageFilesOnlyDetectsFilesWithPackageExtension
public void GetPackageFilesOnlyDetectsFilesWithPackageExtension()
{
// Arrange
var mockFileSystem = new MockProjectSystem();
mockFileSystem.AddFile("foo.nupkg");
mockFileSystem.AddFile("bar.zip");
var repository = new LocalPackageRepository(new DefaultPackagePathResolver(mockFileSystem),
mockFileSystem);
// Act
var files = repository.GetPackageFiles().ToList();
// Assert
Assert.Equal(1, files.Count);
Assert.Equal("foo.nupkg", files[0]);
}
示例6: 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());
}
示例7: GetPackageFilesDetectsFilesInRootOrFirstLevelOfFolders
public void GetPackageFilesDetectsFilesInRootOrFirstLevelOfFolders()
{
// Arrange
var mockFileSystem = new MockProjectSystem();
mockFileSystem.AddFile("P1.nupkg");
mockFileSystem.AddFile("bar.zip");
mockFileSystem.AddFile(PathFixUtility.FixPath(@"baz\P2.nupkg"));
mockFileSystem.AddFile(PathFixUtility.FixPath(@"A\B\P3.nupkg"));
mockFileSystem.AddFile(PathFixUtility.FixPath(@"A\P4.nupkg"));
var repository = new LocalPackageRepository(new DefaultPackagePathResolver(mockFileSystem),
mockFileSystem);
// Act
var files = repository.GetPackageFiles().ToList();
// Assert
Assert.Equal(3, files.Count);
Assert.Equal(PathFixUtility.FixPath(@"baz\P2.nupkg"), files[0]);
Assert.Equal(PathFixUtility.FixPath(@"A\P4.nupkg"), files[1]);
Assert.Equal("P1.nupkg", files[2]);
}
示例8: RemovingPackageWithModifiedContentFileWithinBeginMarkersRemoveFile
public void RemovingPackageWithModifiedContentFileWithinBeginMarkersRemoveFile()
{
// 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" });
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", @"content\a.file
-----------------NUGET: BEGIN LICENSE TEXT
dsaflkdjsal;fkjdsal;kjf
sdafkljdsal;kjfl;dkasjfl;kdas
fdsalk;fj;lkdsajfl;kdsa");
// Act
projectManager.RemovePackageReference("A");
// Assert
Assert.False(projectManager.LocalRepository.Exists(packageA));
Assert.False(projectSystem.FileExists("a.file"));
}
示例9: 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"));
}
示例10: RemovePackageReferenceRemoveContentAccordingToTargetFramework
public void RemovePackageReferenceRemoveContentAccordingToTargetFramework()
{
// Arrange
var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework", new Version("2.0")));
projectSystem.AddFile("jQuery.js", "content\\[net35]\\jQuery.js");
projectSystem.AddFile("foo.css", "content\\foo.css");
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[] { "net20\\contentFile", "net35\\jQuery.js", "foo.css" },
new[] { "lib\\eference.dll" });
mockRepository.AddPackage(packageA);
projectManager.AddPackageReference("A");
Assert.True(projectSystem.FileExists(@"contentFile"));
// Act
projectManager.RemovePackageReference("A");
// Assert
Assert.Equal(2, projectSystem.Paths.Count);
Assert.True(projectSystem.FileExists(@"jQuery.js"));
Assert.True(projectSystem.FileExists(@"foo.css"));
Assert.False(localRepository.Exists("A"));
}
示例11: RemovePackageWithTransformFileThatThrowsContinuesRemovingPackage
public void RemovePackageWithTransformFileThatThrowsContinuesRemovingPackage()
{
// Arrange
var mockProjectSystem = new MockProjectSystem();
var mockRepository = new MockPackageRepository();
var localRepository = new MockPackageRepository();
mockProjectSystem.AddFile("web.config", () => { throw new UnauthorizedAccessException(); });
mockProjectSystem.AddFile("foo.txt");
var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(new MockProjectSystem()), mockProjectSystem, localRepository);
var package = new Mock<IPackage>();
package.Setup(m => m.Id).Returns("A");
package.Setup(m => m.Version).Returns(new SemanticVersion("1.0"));
var file = new Mock<IPackageFile>();
var contentFile = new Mock<IPackageFile>();
contentFile.Setup(m => m.Path).Returns(@"content\foo.txt");
contentFile.Setup(m => m.GetStream()).Returns(new MemoryStream());
contentFile.Setup(m => m.EffectivePath).Returns("foo.txt");
file.Setup(m => m.Path).Returns(@"content\web.config.transform");
file.Setup(m => m.EffectivePath).Returns("web.config.transform");
file.Setup(m => m.GetStream()).Returns(() =>
@"<configuration>
<system.web>
<compilation debug=""true"" targetFramework=""4.0"" />
</system.web>
</configuration>
".AsStream());
package.Setup(m => m.GetFiles()).Returns(new[] { file.Object, contentFile.Object });
mockRepository.AddPackage(package.Object);
projectManager.LocalRepository.AddPackage(package.Object);
// Act
projectManager.RemovePackageReference("A");
// Assert
Assert.False(mockProjectSystem.FileExists("foo.txt"));
Assert.False(localRepository.Exists(package.Object));
}
示例12: RemovePackageWithTransformFile
public void RemovePackageWithTransformFile()
{
// Arrange
var mockProjectSystem = new MockProjectSystem();
var mockRepository = new MockPackageRepository();
mockProjectSystem.AddFile("web.config",
@"<configuration>
<system.web>
<compilation debug=""true"" targetFramework=""4.0"" baz=""test"" />
</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"));
var file = new Mock<IPackageFile>();
file.Setup(m => m.Path).Returns(@"content\web.config.transform");
file.Setup(m => m.EffectivePath).Returns("web.config.transform");
file.Setup(m => m.GetStream()).Returns(() =>
@"<configuration>
<system.web>
<compilation debug=""true"" targetFramework=""4.0"" />
</system.web>
</configuration>
".AsStream());
package.Setup(m => m.GetFiles()).Returns(new[] { file.Object });
mockRepository.AddPackage(package.Object);
projectManager.LocalRepository.AddPackage(package.Object);
// Act
projectManager.RemovePackageReference("A");
// Assert
Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<system.web>
<compilation baz=""test"" />
</system.web>
</configuration>
", mockProjectSystem.OpenFile("web.config").ReadToEnd());
}
示例13: AddPackageAskToResolveConflictForEveryFileWithDependency
public void AddPackageAskToResolveConflictForEveryFileWithDependency()
{
// Arrange
var sourceRepository = new MockPackageRepository();
var localRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
projectSystem.AddFile("one.txt", "this is one");
projectSystem.AddFile("two.txt", "this is two");
var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
IPackage packageA = PackageUtility.CreatePackage(
"A", "1.0", content: new[] { "one.txt" }, dependencies: new PackageDependency[] { new PackageDependency("B") });
sourceRepository.AddPackage(packageA);
IPackage packageB = PackageUtility.CreatePackage("B", "1.0", content: new[] { "two.txt" });
sourceRepository.AddPackage(packageB);
var logger = new Mock<ILogger>();
logger.Setup(l => l.ResolveFileConflict(It.IsAny<string>())).Returns(FileConflictResolution.OverwriteAll);
projectManager.Logger = projectSystem.Logger = logger.Object;
// Act
projectManager.AddPackageReference("A");
// Assert
Assert.True(localRepository.Exists("A"));
Assert.Equal("content\\one.txt", projectSystem.ReadAllText("one.txt"));
Assert.Equal("content\\two.txt", projectSystem.ReadAllText("two.txt"));
logger.Verify(l => l.ResolveFileConflict(It.IsAny<string>()), Times.Exactly(2));
}
示例14: AddPackageWithTransformFile
public void AddPackageWithTransformFile()
{
// Arrange
var mockProjectSystem = new MockProjectSystem();
var mockRepository = new MockPackageRepository();
mockProjectSystem.AddFile("web.config",
@"<configuration>
<system.web>
<compilation debug=""true"" targetFramework=""4.0"" />
</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.transform");
file.Setup(m => m.EffectivePath).Returns("web.config.transform");
// in the transform snippet below, we put the <add> tag on the same line
// as <configSections> tag to verify that the transform engine preserves
// formatting of the transform file.
file.Setup(m => m.GetStream()).Returns(() =>
@"<configuration>
<configSections> <add a=""n"" />
</configSections>
</configuration>
".AsStream());
package.Setup(m => m.GetFiles()).Returns(new[] { file.Object });
mockRepository.AddPackage(package.Object);
// Act
projectManager.AddPackageReference("A");
// Assert
// TODO Config transformation should preserve white-space (formatting)
// It does not at the moment, therefore <system.web> element has different indent than <configSections>.
Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<configSections> <add a=""n"" />
</configSections>
<system.web>
<compilation debug=""true"" targetFramework=""4.0"" />
</system.web>
</configuration>
", mockProjectSystem.OpenFile("web.config").ReadToEnd());
}
示例15: RemovePackageDoesNotRemovesRootIfNotEmpty
public void RemovePackageDoesNotRemovesRootIfNotEmpty()
{
// Arrange
var mockFileSystem = new MockProjectSystem();
mockFileSystem.AddFile(PathFixUtility.FixPath(@"A.1.0\A.1.0.nupkg"));
mockFileSystem.AddFile(PathFixUtility.FixPath(@"B.1.0\B.1.0.nupkg"));
var repository = new LocalPackageRepository(new DefaultPackagePathResolver(mockFileSystem),
mockFileSystem);
IPackage package = PackageUtility.CreatePackage("A", "1.0");
// Act
repository.RemovePackage(package);
// Assert
Assert.Equal(2, mockFileSystem.Deleted.Count);
Assert.True(mockFileSystem.Deleted.Contains(Path.Combine(mockFileSystem.Root, @"A.1.0")));
Assert.True(mockFileSystem.Deleted.Contains(Path.Combine(mockFileSystem.Root, PathFixUtility.FixPath(@"A.1.0\A.1.0.nupkg"))));
}