Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>

View File

@@ -0,0 +1,268 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using Xunit;
namespace System.Web.WebPages.Deployment.Test
{
public class AssemblyUtilsTest
{
[Fact]
public void GetMaxAssemblyVersionReturnsMaximumAvailableVersion()
{
// Arrange
var assemblies = new[]
{
new AssemblyName("System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"),
new AssemblyName("System.Web.WebPages.Deployment, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"),
new AssemblyName("System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")
};
// Act
var maxVersion = AssemblyUtils.GetMaxWebPagesVersion(assemblies);
// Assert
Assert.Equal(new Version("2.1.0.0"), maxVersion);
}
[Fact]
public void GetMaxAssemblyVersionMatchesExactName()
{
// Arrange
var assemblies = new[]
{
new AssemblyName("System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"),
new AssemblyName("System.Web.WebPages.Development, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"),
new AssemblyName("System.Web.WebPages.Deployment, Version=2.1.0.0, Culture=neutral, PublicKeyToken=7777777777777777"),
new AssemblyName("System.Web.WebPages.Deployment, Version=2.3.0.0, Culture=en-US, PublicKeyToken=31bf3856ad364e35"),
new AssemblyName("System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")
};
// Act
var maxVersion = AssemblyUtils.GetMaxWebPagesVersion(assemblies);
// Assert
Assert.Equal(new Version("2.0.0.0"), maxVersion);
}
[Fact]
public void GetVersionFromBinReturnsNullIfNoFileWithDeploymentAssemblyNameIsFoundInBin()
{
// Arrange
var binDirectory = @"X:\test\project";
TestFileSystem fileSystem = new TestFileSystem();
// Act
var binVersion = AssemblyUtils.GetVersionFromBin(binDirectory, fileSystem, getAssemblyNameThunk: null);
// Assert
Assert.Null(binVersion);
}
[Fact]
public void GetVersionFromBinReturnsVersionFromBinIfLower()
{
// Arrange
var binDirectory = @"X:\test\project";
TestFileSystem fileSystem = new TestFileSystem();
fileSystem.AddFile(Path.Combine(binDirectory, "System.Web.WebPages.Deployment.dll"));
Func<string, AssemblyName> getAssembyName = _ => new AssemblyName("System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
// Act
var binVersion = AssemblyUtils.GetVersionFromBin(binDirectory, fileSystem, getAssembyName);
// Assert
Assert.Equal(new Version("1.0.0.0"), binVersion);
}
[Fact]
public void GetVersionFromBinReturnsVersionFromBinIfSameVersion()
{
// Arrange
var binDirectory = @"X:\test\project";
TestFileSystem fileSystem = new TestFileSystem();
fileSystem.AddFile(Path.Combine(binDirectory, "System.Web.WebPages.Deployment.dll"));
Func<string, AssemblyName> getAssembyName = _ => new AssemblyName("System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
// Act
var binVersion = AssemblyUtils.GetVersionFromBin(binDirectory, fileSystem, getAssembyName);
// Assert
Assert.Equal(new Version("2.0.0.0"), binVersion);
}
[Fact]
public void GetVersionFromBinReturnsVersionFromBinIfHigherVersion()
{
// Arrange
var binDirectory = @"X:\test\project";
TestFileSystem fileSystem = new TestFileSystem();
fileSystem.AddFile(Path.Combine(binDirectory, "System.Web.WebPages.Deployment.dll"));
Func<string, AssemblyName> getAssembyName = _ => new AssemblyName("System.Web.WebPages.Deployment, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
// Act
var binVersion = AssemblyUtils.GetVersionFromBin(binDirectory, fileSystem, getAssembyName);
// Assert
Assert.Equal(new Version("8.0.0.0"), binVersion);
}
[Fact]
public void GetVersionFromBinReturnsNullIfFileInBinIsNotAValidBinary()
{
// Arrange
var binDirectory = @"X:\test\project";
TestFileSystem fileSystem = new TestFileSystem();
fileSystem.AddFile(Path.Combine(binDirectory, "System.Web.WebPages.Deployment.dll"));
Func<string, AssemblyName> getAssembyName = _ => { throw new FileLoadException(); };
// Act
var binVersion = AssemblyUtils.GetVersionFromBin(binDirectory, fileSystem, getAssembyName);
// Assert
Assert.Null(binVersion);
}
[Fact]
public void GetAssembliesForVersionReturnsCorrectSetForV1()
{
// Arrange
var expectedAssemblies = new[]
{
"Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"System.Web.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"System.Web.WebPages.Administration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"WebMatrix.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"WebMatrix.WebData, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
};
// Act
var assemblies = AssemblyUtils.GetAssembliesForVersion(new Version("1.0.0.0"))
.Select(c => c.ToString())
.ToArray();
// Assert
Assert.Equal(expectedAssemblies, assemblies);
}
[Fact]
public void GetAssembliesForVersionReturnsCorrectSetForVCurrent()
{
// Arrange
var expectedAssemblies = new[]
{
"Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"System.Web.WebPages.Administration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"WebMatrix.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"WebMatrix.WebData, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
};
// Act
var assemblies = AssemblyUtils.GetAssembliesForVersion(new Version("2.0.0.0"))
.Select(c => c.ToString())
.ToArray();
// Assert
Assert.Equal(expectedAssemblies, assemblies);
}
[Fact]
public void GetMatchingAssembliesReturnsEmptyDictionaryIfNoReferencesMatchWebPagesAssemblies()
{
// Arrange
var assemblyReferences = new Dictionary<string, IEnumerable<string>>
{
{ @"x:\site\bin\A.dll", new List<string> { "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null" }},
{ @"x:\site\bin\B.dll", new List<string> { "System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" }},
};
var a = "1";
var b = "2";
var c = new { a, b };
Console.WriteLine(c.a);
// Act
var referencedAssemblies = AssemblyUtils.GetAssembliesMatchingOtherVersions(assemblyReferences);
// Assert
Assert.Empty(referencedAssemblies);
}
[Fact]
public void GetMatchingAssembliesReturnsReferencingAssemblyAndWebPagesVersionForMatchingReferences()
{
// Arrange
var assemblyReferences = new Dictionary<string, IEnumerable<string>>
{
{ @"x:\site\bin\A.dll", new[] { "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null" }},
{ @"x:\site\bin\B.dll", new[]
{
"mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null",
"System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
}
},
};
// Act
var referencedAssemblies = AssemblyUtils.GetAssembliesMatchingOtherVersions(assemblyReferences);
// Assert
Assert.Equal(1, referencedAssemblies.Count);
Assert.Equal(@"x:\site\bin\B.dll", referencedAssemblies.Single().Key);
Assert.Equal(new Version("1.0.0.0"), referencedAssemblies.Single().Value);
}
[Fact]
public void GetMatchingAssembliesFiltersWebPagesVersionsThatMatch()
{
// Arrange
var assemblyReferences = new Dictionary<string, IEnumerable<string>>
{
{ @"x:\site\bin\A.dll", new[] { "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null" }},
{ @"x:\site\bin\B.dll", new[]
{
"mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null",
String.Format(CultureInfo.InvariantCulture, "System.Web.WebPages, Version={0}, Culture=neutral, PublicKeyToken=31bf3856ad364e35", AssemblyUtils.ThisAssemblyName.Version),
String.Format(CultureInfo.InvariantCulture, "System.Web.Helpers, Version={0}, Culture=neutral, PublicKeyToken=31bf3856ad364e35", AssemblyUtils.ThisAssemblyName.Version)
}
},
{ @"x:\site\bin\C.dll", new[]
{
"mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null",
"System.Web.WebPages.Razor, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"System.Web.WebPages.Razor, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
}
},
};
// Act
var referencedAssemblies = AssemblyUtils.GetAssembliesMatchingOtherVersions(assemblyReferences);
// Assert
Assert.Equal(1, referencedAssemblies.Count);
Assert.Equal(@"x:\site\bin\C.dll", referencedAssemblies.Single().Key);
Assert.Equal(new Version("1.2.0.0"), referencedAssemblies.Single().Value);
}
private static void EnsureDirectory(string directory)
{
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
}
}
}

View File

@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.IO;
namespace System.Web.WebPages.Deployment.Test
{
internal static class DeploymentUtil
{
public static string GetBinDirectory()
{
var tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
return Path.Combine(tempDirectory, "bin");
}
}
}

View File

@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("System.Web.WebPages.Deployment.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("System.Web.WebPages.Deployment.Test")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM componenets. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory),Runtime.sln))\tools\WebStack.settings.targets" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{268DEE9D-F323-4A00-8ED8-3784388C3E3A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>System.Web.WebPages.Deployment.Test</RootNamespace>
<AssemblyName>System.Web.WebPages.Deployment.Test</AssemblyName>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>$(WebStackRootPath)\bin\Debug\Test\</OutputPath>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>$(WebStackRootPath)\bin\Release\Test\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'CodeCoverage' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>$(WebStackRootPath)\bin\CodeCoverage\Test\</OutputPath>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Web" />
<Reference Include="xunit">
<HintPath>..\..\packages\xunit.1.9.0.1566\lib\xunit.dll</HintPath>
</Reference>
<Reference Include="xunit.extensions">
<HintPath>..\..\packages\xunit.extensions.1.9.0.1566\lib\xunit.extensions.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyUtilsTest.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="DeploymentUtil.cs" />
<Compile Include="PreApplicationStartCodeTest.cs" />
<Compile Include="TestFileSystem.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WebPagesDeploymentTest.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\System.Web.WebPages.Deployment\System.Web.WebPages.Deployment.csproj">
<Project>{22BABB60-8F02-4027-AFFC-ACF069954536}</Project>
<Name>System.Web.WebPages.Deployment</Name>
</ProjectReference>
<ProjectReference Include="..\Microsoft.TestCommon\Microsoft.TestCommon.csproj">
<Project>{FCCC4CB7-BAF7-4A57-9F89-E5766FE536C0}</Project>
<Name>Microsoft.TestCommon</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="App.Config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="TestFiles\ConfigTestAssemblies\V2_Signed\System.Web.WebPages.Deployment.dll" />
<EmbeddedResource Include="TestFiles\ConfigTestAssemblies\V2_Unsigned\System.Web.WebPages.Deployment.dll" />
<EmbeddedResource Include="TestFiles\ConfigTestSites\CshtmlFileConfigV1\Default.cshtml" />
<EmbeddedResource Include="TestFiles\ConfigTestSites\CshtmlFileConfigV1\web.config" />
<EmbeddedResource Include="TestFiles\ConfigTestSites\CshtmlFileNoVersion\Default.cshtml" />
<EmbeddedResource Include="TestFiles\ConfigTestSites\NoCshtml\Default.htm" />
<EmbeddedResource Include="TestFiles\ConfigTestSites\NoCshtmlConfigV1\Default.htm" />
<EmbeddedResource Include="TestFiles\ConfigTestSites\NoCshtmlConfigV1\web.config" />
<EmbeddedResource Include="TestFiles\ConfigTestSites\NoCshtmlNoConfigSetting\Default.htm" />
<EmbeddedResource Include="TestFiles\ConfigTestSites\NoCshtmlNoConfigSetting\web.config" />
<EmbeddedResource Include="TestFiles\ConfigTestSites\NoCshtmlWithEnabledSetting\Default.htm" />
<EmbeddedResource Include="TestFiles\ConfigTestSites\NoCshtmlWithEnabledSetting\web.config" />
<EmbeddedResource Include="TestFiles\ConfigTestSites\NoCshtmlWithEnabledSettingFalse\Default.htm" />
<EmbeddedResource Include="TestFiles\ConfigTestSites\NoCshtmlWithEnabledSettingFalse\web.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -0,0 +1,52 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Internal.Web.Utils;
namespace System.Web.WebPages.Deployment.Test
{
public class TestFileSystem : IFileSystem
{
private readonly Dictionary<string, MemoryStream> _files = new Dictionary<string, MemoryStream>(StringComparer.OrdinalIgnoreCase);
public void AddFile(string file, MemoryStream content = null)
{
content = content ?? new MemoryStream();
_files[file] = content;
}
public bool FileExists(string path)
{
return _files.ContainsKey(path);
}
public Stream ReadFile(string path)
{
return _files[path];
}
public Stream OpenFile(string path)
{
MemoryStream memoryStream;
if (_files.TryGetValue(path, out memoryStream))
{
var copiedStream = new MemoryStream(memoryStream.ToArray());
_files[path] = copiedStream;
}
else
{
AddFile(path);
}
return _files[path];
}
public IEnumerable<string> EnumerateFiles(string path)
{
return from file in _files.Keys
where Path.GetDirectoryName(file).Equals(path, StringComparison.OrdinalIgnoreCase)
select file;
}
}
}

View File

@@ -0,0 +1,9 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
Not a plan9 app!
</body>
</html>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="webpages:Version" value="1.0" />
</appSettings>
</configuration>

View File

@@ -0,0 +1,9 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
Not a plan9 app!
</body>
</html>

View File

@@ -0,0 +1,9 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
Not a plan9 app!
</body>
</html>

View File

@@ -0,0 +1,9 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
Not a plan9 app!
</body>
</html>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="webPages:version" value="1.0" />
</appSettings>
</configuration>

View File

@@ -0,0 +1,9 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
Not a plan9 app!
</body>
</html>

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>

View File

@@ -0,0 +1,9 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
Not a plan9 app!
</body>
</html>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="webpages:Enabled" value="true" />
</appSettings>
</configuration>

View File

@@ -0,0 +1,9 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
Not a plan9 app!
</body>
</html>

Some files were not shown because too many files have changed in this diff Show More