Replace all uses of the Uri class for getting assembly local path names.

This commit is contained in:
Brad Wilson 2014-03-22 14:07:46 -07:00
Родитель 86705cd175
Коммит f58fe1dc85
21 изменённых файлов: 52 добавлений и 16 удалений

Просмотреть файл

@ -0,0 +1,17 @@
using System;
using System.Reflection;
internal static class AssemblyExtensions
{
public static string GetLocalCodeBase(this Assembly assembly)
{
string codeBase = assembly.CodeBase;
if (codeBase == null)
return null;
if (!codeBase.StartsWith("file:///"))
throw new ArgumentException(String.Format("Code base {0} in wrong format; must start with file:///", codeBase), "assembly");
return codeBase.Substring(8).Replace('/', '\\');
}
}

Просмотреть файл

@ -1,21 +1,18 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
namespace Xunit.ConsoleClient
{
public class CommandLine
{
readonly Stack<string> arguments = new Stack<string>();
readonly string executablePath;
protected CommandLine(string[] args)
{
for (int i = args.Length - 1; i >= 0; i--)
arguments.Push(args[i]);
executablePath = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
TeamCity = Environment.GetEnvironmentVariable("TEAMCITY_PROJECT_NAME") != null;
ParallelizeAssemblies = false;
ParallelizeTestCollections = true;

Просмотреть файл

@ -86,7 +86,7 @@ namespace Xunit.ConsoleClient
static void PrintUsage()
{
string executableName = Path.GetFileNameWithoutExtension(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
string executableName = Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().GetLocalCodeBase());
Console.WriteLine("usage: {0} <assemblyFile> [configFile] [options]", executableName);
Console.WriteLine();

Просмотреть файл

@ -18,7 +18,7 @@ namespace Xunit.ConsoleClient
protected TransformFactory()
{
var executablePath = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
var executablePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetLocalCodeBase());
var exeConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var configSection = (XunitConsoleConfigurationSection)exeConfiguration.GetSection("xunit") ?? new XunitConsoleConfigurationSection();

Просмотреть файл

@ -57,6 +57,9 @@
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\common\AssemblyExtensions.cs">
<Link>Common\AssemblyExtensions.cs</Link>
</Compile>
<Compile Include="..\common\DictionaryExtensions.cs">
<Link>Common\DictionaryExtensions.cs</Link>
</Compile>

Просмотреть файл

@ -35,7 +35,7 @@ namespace Xunit.Sdk
public Assembly Assembly { get; private set; }
/// <inheritdoc/>
public string AssemblyPath { get { return new Uri(Assembly.CodeBase).LocalPath; } }
public string AssemblyPath { get { return Assembly.GetLocalCodeBase(); } }
/// <inheritdoc/>
public string Name { get { return Assembly.FullName; } }

Просмотреть файл

@ -41,6 +41,9 @@
<Reference Include="System.Transactions" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\common\AssemblyExtensions.cs">
<Link>Common\AssemblyExtensions.cs</Link>
</Compile>
<Compile Include="..\common\DictionaryExtensions.cs">
<Link>Common\DictionaryExtensions.cs</Link>
</Compile>

Просмотреть файл

@ -22,7 +22,7 @@ namespace Xunit.Runner.TdNet
{
this.testListener = testListener;
xunit = new Xunit2(new NullSourceInformationProvider(), new Uri(assembly.CodeBase).LocalPath);
xunit = new Xunit2(new NullSourceInformationProvider(), assembly.GetLocalCodeBase());
toDispose.Push(xunit);
}

Просмотреть файл

@ -56,6 +56,9 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\common\AssemblyExtensions.cs">
<Link>Common\AssemblyExtensions.cs</Link>
</Compile>
<Compile Include="..\common\GlobalAssemblyInfo.cs">
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>

Просмотреть файл

@ -56,7 +56,7 @@ namespace Xunit
/// <returns>An object which, when disposed, un-subscribes.</returns>
public static IDisposable SubscribeResolve()
{
return new AssemblyHelper(Path.GetDirectoryName(new Uri(typeof(AssemblyHelper).Assembly.CodeBase).LocalPath));
return new AssemblyHelper(Path.GetDirectoryName(typeof(AssemblyHelper).Assembly.GetLocalCodeBase()));
}
}
}

Просмотреть файл

@ -14,7 +14,7 @@ namespace Xunit
{
session = new DiaSession(assemblyFilename);
var assemblyFileName = new Uri(typeof(DiaSessionWrapperHelper).Assembly.CodeBase).LocalPath;
var assemblyFileName = typeof(DiaSessionWrapperHelper).Assembly.GetLocalCodeBase();
appDomainManager = new RemoteAppDomainManager(assemblyFileName, null, true);
helper = appDomainManager.CreateObject<DiaSessionWrapperHelper>(typeof(DiaSessionWrapperHelper).Assembly.FullName, typeof(DiaSessionWrapperHelper).FullName, assemblyFilename);

Просмотреть файл

@ -42,6 +42,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\common\AssemblyExtensions.cs">
<Link>Common\AssemblyExtensions.cs</Link>
</Compile>
<Compile Include="..\common\DictionaryExtensions.cs">
<Link>Common\DictionaryExtensions.cs</Link>
</Compile>

Просмотреть файл

@ -21,7 +21,7 @@ public class AcceptanceTest : IDisposable
public List<IMessageSinkMessage> Run(Type[] types, Func<IMessageSinkMessage, bool> cancellationThunk = null)
{
Xunit2 = new Xunit2(new NullSourceInformationProvider(), new Uri(types[0].Assembly.CodeBase).LocalPath, configFileName: null, shadowCopy: true);
Xunit2 = new Xunit2(new NullSourceInformationProvider(), types[0].Assembly.GetLocalCodeBase(), configFileName: null, shadowCopy: true);
bool cancelled = false;
Func<IMessageSinkMessage, bool> wrapper = msg =>

Просмотреть файл

@ -30,7 +30,7 @@ public class AcceptanceTestAssembly : IDisposable
public static string BasePath
{
get { return Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath); }
get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetLocalCodeBase()); }
}
public string FileName

Просмотреть файл

@ -105,6 +105,9 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\src\common\AssemblyExtensions.cs">
<Link>Common\AssemblyExtensions.cs</Link>
</Compile>
<Compile Include="..\..\src\common\DictionaryExtensions.cs">
<Link>Common\DictionaryExtensions.cs</Link>
</Compile>

Просмотреть файл

@ -80,7 +80,7 @@ public class Xunit1TestCaseTests
public void UniqueIDIsStable()
{
var typeUnderTest = typeof(ClassUnderTest);
var assemblyFileName = new Uri(typeUnderTest.Assembly.CodeBase).LocalPath;
var assemblyFileName = typeUnderTest.Assembly.GetLocalCodeBase();
var result = Create(typeUnderTest, "TestMethod").UniqueID;
@ -96,7 +96,8 @@ public class Xunit1TestCaseTests
static Xunit1TestCase Create(Type typeUnderTest, string methodName, Dictionary<string, List<string>> traits = null)
{
var assemblyFileName = new Uri(typeUnderTest.Assembly.CodeBase).LocalPath;
var assemblyFileName = typeUnderTest.Assembly.GetLocalCodeBase();
return new Xunit1TestCase(assemblyFileName, typeUnderTest.FullName, methodName, null, traits);
}
}

Просмотреть файл

@ -10,7 +10,7 @@ public class Xunit2Tests
{
static AssemblyName GetXunitAssemblyName()
{
string path = Path.Combine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), "xunit.execution.dll");
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetLocalCodeBase()), "xunit.execution.dll");
return Assembly.LoadFile(path).GetName();
}

Просмотреть файл

@ -42,6 +42,9 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\src\common\AssemblyExtensions.cs">
<Link>Common\AssemblyExtensions.cs</Link>
</Compile>
<Compile Include="..\..\src\common\DictionaryExtensions.cs">
<Link>Common\DictionaryExtensions.cs</Link>
</Compile>

Просмотреть файл

@ -61,6 +61,9 @@
</None>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\src\common\AssemblyExtensions.cs">
<Link>utility\AssemblyExtensions.cs</Link>
</Compile>
<Compile Include="utility\AcceptanceTest.cs" />
<Compile Include="utility\AcceptanceTestInNewAppDomain.cs" />
<Compile Include="utility\MockAssembly.cs" />

Просмотреть файл

@ -33,7 +33,7 @@ namespace TestUtility
public static string BasePath
{
get { return Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath); }
get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetLocalCodeBase()); }
}
public string FileName

Просмотреть файл

@ -20,7 +20,7 @@ namespace Xunit1.Extensions
try
{
string executable = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
string executable = Assembly.GetExecutingAssembly().GetLocalCodeBase();
Directory.SetCurrentDirectory(Path.GetDirectoryName(executable));
MethodInfo method = typeof(TestMethodCommandClass).GetMethod("TestViaOleDb");
TheoryAttribute attr = (TheoryAttribute)(method.GetCustomAttributes(typeof(TheoryAttribute), false))[0];