本文整理汇总了C#中NuGet.Test.Mocks.MockFileSystem.OpenFile方法的典型用法代码示例。如果您正苦于以下问题:C# MockFileSystem.OpenFile方法的具体用法?C# MockFileSystem.OpenFile怎么用?C# MockFileSystem.OpenFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NuGet.Test.Mocks.MockFileSystem
的用法示例。
在下文中一共展示了MockFileSystem.OpenFile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddingBindingRedirectToEmptyConfig
public void AddingBindingRedirectToEmptyConfig()
{
// Arrange
var mockFileSystem = new MockFileSystem();
mockFileSystem.AddFile("config", @"<configuration></configuration>");
var bindingRedirectManager = new BindingRedirectManager(mockFileSystem, "config");
AssemblyBinding assemblyBinding = GetAssemblyBinding("AssemblyName", "token", "3.0.0.0");
// Act
bindingRedirectManager.AddBindingRedirects(new[] { assemblyBinding });
// Assert
string outputContent = mockFileSystem.OpenFile("config").ReadToEnd();
Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<runtime>
<assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1"">
<dependentAssembly>
<assemblyIdentity name=""AssemblyName"" publicKeyToken=""token"" culture=""neutral"" />
<bindingRedirect oldVersion=""0.0.0.0-3.0.0.0"" newVersion=""3.0.0.0"" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>", outputContent);
}
示例2: CallAddPackageWillAddNuspecWhichHasReferencesData
public void CallAddPackageWillAddNuspecWhichHasReferencesData()
{
// Arrange
var fileSystem = new MockFileSystem("x:\\root");
var configFileSystem = new MockFileSystem();
var repository = new SharedPackageRepository(new DefaultPackagePathResolver(fileSystem), fileSystem, configFileSystem);
// Act
repository.AddPackage(PackageUtility.CreatePackage("A",
"1.0",
assemblyReferences: new[] { "lib\\net40\\A.dll", "lib\\B.dll" }));
// Assert
Assert.True(fileSystem.FileExists("A.1.0\\A.1.0.nuspec"));
Stream manifestContentStream = fileSystem.OpenFile("A.1.0\\A.1.0.nuspec");
Manifest manifest = Manifest.ReadFrom(manifestContentStream, validateSchema: true);
Assert.Equal(2, manifest.Metadata.ReferenceSets.Count);
var set1 = manifest.Metadata.ReferenceSets[0];
Assert.Equal(".NETFramework4.0", set1.TargetFramework);
Assert.Equal(1, set1.References.Count);
Assert.Equal("A.dll", set1.References[0].File);
var set2 = manifest.Metadata.ReferenceSets[1];
Assert.Null(set2.TargetFramework);
Assert.Equal(1, set2.References.Count);
Assert.Equal("B.dll", set2.References[0].File);
}
示例3: AddingBindingRedirectWithMultipleAssemblyBindingSectionsAddsToFirstOne
public void AddingBindingRedirectWithMultipleAssemblyBindingSectionsAddsToFirstOne()
{
// Arrange
var mockFileSystem = new MockFileSystem();
mockFileSystem.AddFile("config", @"
<configuration>
<runtime>
<assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1"">
<dependentAssembly>
<assemblyIdentity name=""System.Web.Mvc"" publicKeyToken=""31bf3856ad364e35"" />
<bindingRedirect oldVersion=""1.0.0.0"" newVersion=""2.0.0.0"" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1"">
<dependentAssembly>
<assemblyIdentity name=""A.Library"" publicKeyToken=""a34a755ec277222f"" />
<bindingRedirect oldVersion=""1.0.0.0-2.0.0.0"" newVersion=""2.0.0.0"" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>");
var bindingRedirectManager = new BindingRedirectManager(mockFileSystem, "config");
AssemblyBinding assemblyBinding = GetAssemblyBinding("AssemblyName", "token", "3.0.0.0");
// Act
bindingRedirectManager.AddBindingRedirects(new[] { assemblyBinding });
// Assert
string outputContent = mockFileSystem.OpenFile("config").ReadToEnd();
Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<runtime>
<assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1"">
<dependentAssembly>
<assemblyIdentity name=""System.Web.Mvc"" publicKeyToken=""31bf3856ad364e35"" />
<bindingRedirect oldVersion=""1.0.0.0"" newVersion=""2.0.0.0"" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name=""AssemblyName"" publicKeyToken=""token"" culture=""neutral"" />
<bindingRedirect oldVersion=""0.0.0.0-3.0.0.0"" newVersion=""3.0.0.0"" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1"">
<dependentAssembly>
<assemblyIdentity name=""A.Library"" publicKeyToken=""a34a755ec277222f"" />
<bindingRedirect oldVersion=""1.0.0.0-2.0.0.0"" newVersion=""2.0.0.0"" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>", outputContent);
}
示例4: AddedNuspecDoesNotAddReferencesSectionIfNotPresent
public void AddedNuspecDoesNotAddReferencesSectionIfNotPresent()
{
// Arrange
var fileSystem = new MockFileSystem("x:\\root");
var configFileSystem = new MockFileSystem();
var repository = new SharedPackageRepository(new DefaultPackagePathResolver(fileSystem), fileSystem, configFileSystem);
// Act
var package = PackageUtility.CreatePackage("A", "1.0", content: new[] { "A.txt", "scripts\\b.txt" });
repository.AddPackage(package);
// Assert
Assert.True(fileSystem.FileExists("A.1.0\\A.1.0.nuspec"));
Stream manifestContentStream = fileSystem.OpenFile("A.1.0\\A.1.0.nuspec");
Manifest manifest = Manifest.ReadFrom(manifestContentStream, validateSchema: true);
Assert.Equal(0, manifest.Metadata.ReferenceSets.Count);
}
示例5: CallAddPackageWillAddNuspecWhichHasReferencesData
public void CallAddPackageWillAddNuspecWhichHasReferencesData()
{
// Arrange
var fileSystem = new MockFileSystem("x:\root");
var configFileSystem = new MockFileSystem();
var repository = new SharedPackageRepository(new DefaultPackagePathResolver(fileSystem), fileSystem, configFileSystem);
// Act
repository.AddPackage(PackageUtility.CreatePackage("A",
"1.0",
assemblyReferences: new [] { "net40\\A.dll", "sl45\\B.dll", "A.dll", "win8\\C.dll" }));
// Assert
Assert.True(fileSystem.FileExists("A.1.0\\A.1.0.nuspec"));
Stream manifestContentStream = fileSystem.OpenFile("A.1.0\\A.1.0.nuspec");
Manifest manifest = Manifest.ReadFrom(manifestContentStream);
Assert.Equal(3, manifest.Metadata.References.Count);
Assert.Equal("A.dll", manifest.Metadata.References[0].File);
Assert.Equal("B.dll", manifest.Metadata.References[1].File);
Assert.Equal("C.dll", manifest.Metadata.References[2].File);
}
示例6: CallAddPackageWillAddNuspecWithReferencesPreserved
public void CallAddPackageWillAddNuspecWithReferencesPreserved()
{
// Arrange
var fileSystem = new MockFileSystem("x:\\root");
var configFileSystem = new MockFileSystem();
var repository = new SharedPackageRepository(new DefaultPackagePathResolver(fileSystem), fileSystem, configFileSystem);
// Act
var package = PackageUtility.CreatePackage("A", "1.0", content: new[] { "A.txt", "scripts\\b.txt" });
var mockedPackage = Mock.Get(package);
mockedPackage.Setup(m => m.PackageAssemblyReferences).Returns(
new PackageReferenceSet[] {
new PackageReferenceSet(new FrameworkName(".NETFramework, Version=4.0"), new [] { "A.dll" }),
new PackageReferenceSet(null, new [] { "B.dll" }),
});
repository.AddPackage(package);
// Assert
Assert.True(fileSystem.FileExists("A.1.0\\A.1.0.nuspec"));
Stream manifestContentStream = fileSystem.OpenFile("A.1.0\\A.1.0.nuspec");
Manifest manifest = Manifest.ReadFrom(manifestContentStream, validateSchema: true);
Assert.Equal(2, manifest.Metadata.ReferenceSets.Count);
var set1 = manifest.Metadata.ReferenceSets[0];
Assert.Equal(".NETFramework4.0", set1.TargetFramework);
Assert.Equal(1, set1.References.Count);
Assert.Equal("A.dll", set1.References[0].File);
var set2 = manifest.Metadata.ReferenceSets[1];
Assert.Null(set2.TargetFramework);
Assert.Equal(1, set2.References.Count);
Assert.Equal("B.dll", set2.References[0].File);
}
示例7: AddBindingRedirectUpdatesElementsPreservingCommentsAndWhitespace
public void AddBindingRedirectUpdatesElementsPreservingCommentsAndWhitespace()
{
// Arrange
var mockFileSystem = new MockFileSystem();
mockFileSystem.AddFile("config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<runtime>
<assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1"">
<dependentAssembly><assemblyIdentity name=""AssemblyName"" publicKeyToken=""token"" culture=""neutral"" />
<!-- This is a comment that should not be removed -->
<bindingRedirect oldVersion=""2.0.0.0"" newVersion=""3.0.0.0"" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>");
var bindingRedirectManager = new BindingRedirectManager(mockFileSystem, "config");
AssemblyBinding assemblyBinding = GetAssemblyBinding("AssemblyName", "token", "4.0.0.0");
// Act
bindingRedirectManager.AddBindingRedirects(new[] { assemblyBinding });
// Assert
string outputContent = mockFileSystem.OpenFile("config").ReadToEnd();
Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<runtime>
<assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1"">
<dependentAssembly><assemblyIdentity name=""AssemblyName"" publicKeyToken=""token"" culture=""neutral"" />
<!-- This is a comment that should not be removed -->
<bindingRedirect oldVersion=""0.0.0.0-4.0.0.0"" newVersion=""4.0.0.0"" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>", outputContent);
}