mirror of
https://github.com/DapperLib/Dapper.git
synced 2026-10-17 05:12:13 +08:00
ae7a29a9f1
Due to the way VS test works (by injecting an executable entry point), the performance tests needed to be factored out. I also organized all of our existing tests better along the way. Actual code changes to Dapper itself are very minor, only formatting and documentation fixes (which we need many more of). The build.ps1 script is upated to work, but note that <frameworkAssemblies> is not working in .nuspec inside the packages in the new .csproj system. I consider this to be a blocker. Issue is here: https://github.com/NuGet/Home/issues/4853
85 lines
2.7 KiB
C#
85 lines
2.7 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Globalization;
|
|
#if !COREFX
|
|
using System.Threading;
|
|
#endif
|
|
|
|
namespace Dapper.Tests
|
|
{
|
|
public abstract class TestBase : IDisposable
|
|
{
|
|
protected static readonly bool IsAppVeyor = Environment.GetEnvironmentVariable("Appveyor")?.ToUpperInvariant() == "TRUE";
|
|
|
|
public static string ConnectionString =>
|
|
IsAppVeyor
|
|
? @"Server=(local)\SQL2014;Database=tempdb;User ID=sa;Password=Password12!"
|
|
: "Data Source=.;Initial Catalog=tempdb;Integrated Security=True";
|
|
|
|
protected SqlConnection _connection;
|
|
protected SqlConnection connection => _connection ?? (_connection = GetOpenConnection());
|
|
|
|
public static SqlConnection GetOpenConnection(bool mars = false)
|
|
{
|
|
var cs = ConnectionString;
|
|
if (mars)
|
|
{
|
|
var scsb = new SqlConnectionStringBuilder(cs)
|
|
{
|
|
MultipleActiveResultSets = true
|
|
};
|
|
cs = scsb.ConnectionString;
|
|
}
|
|
var connection = new SqlConnection(cs);
|
|
connection.Open();
|
|
return connection;
|
|
}
|
|
|
|
public SqlConnection GetClosedConnection()
|
|
{
|
|
var conn = new SqlConnection(ConnectionString);
|
|
if (conn.State != ConnectionState.Closed) throw new InvalidOperationException("should be closed!");
|
|
return conn;
|
|
}
|
|
|
|
protected static CultureInfo ActiveCulture
|
|
{
|
|
#if COREFX
|
|
get { return CultureInfo.CurrentCulture; }
|
|
set { CultureInfo.CurrentCulture = value; }
|
|
#else
|
|
get { return Thread.CurrentThread.CurrentCulture; }
|
|
set { Thread.CurrentThread.CurrentCulture = value; }
|
|
#endif
|
|
}
|
|
|
|
static TestBase()
|
|
{
|
|
Console.WriteLine("Dapper: " + typeof(SqlMapper).AssemblyQualifiedName);
|
|
Console.WriteLine("Using Connectionstring: {0}", ConnectionString);
|
|
#if COREFX
|
|
Console.WriteLine("CoreCLR");
|
|
#else
|
|
Console.WriteLine(".NET: " + Environment.Version);
|
|
Console.Write("Loading native assemblies for SQL types...");
|
|
try
|
|
{
|
|
SqlServerTypesLoader.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
|
|
Console.WriteLine("done.");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("failed.");
|
|
Console.Error.WriteLine(ex.Message);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
connection?.Dispose();
|
|
}
|
|
}
|
|
}
|