Commit a4bb66de authored by Marc Gravell's avatar Marc Gravell

Test cleanup; enable lots more tests hidden previously as EXTERNALS

parent 19afe1ed
#if EXTERNALS
#if ENTITY_FRAMEWORK
using System.Data.Common;
using System.Data.Entity;
......
#if EXTERNALS
#if NHIBERNATE
using NHibernate;
using NHibernate.Cfg;
......
......@@ -9,20 +9,34 @@
using Dapper.Contrib.Extensions;
#if EXTERNALS
#if SOMA
using Soma.Core;
#endif
#if NHIBERNATE
using NHibernate.Criterion;
using NHibernate.Linq;
using Dapper.Tests.NHibernate;
#endif
#if LINQ2SQL
using System.Data.Linq;
#endif
#if MASSIVE
using Massive;
using NHibernate.Criterion;
using NHibernate.Linq;
#endif
#if ORMLITE
using ServiceStack.OrmLite;
using ServiceStack.OrmLite.SqlServer;
using ServiceStack.OrmLite.Converters;
using ServiceStack.OrmLite.Dapper;
#endif
#if BLTOOLKIT
using BLToolkit.Data;
#endif
#if ENTITY_FRAMEWORK
using Dapper.Tests.EntityFramework;
#endif
#if SUSANOO
using Susanoo;
using ServiceStack.OrmLite.Converters;
using ServiceStack.OrmLite.Dapper;
#endif
......@@ -76,12 +90,14 @@ public void Run(int iterations)
}
}
}
#if EXTERNALS
#if LINQ2SQL
static DataClassesDataContext GetL2SContext(SqlConnection connection)
{
return new DataClassesDataContext(connection);
}
#endif
#if SOMA
internal class SomaConfig : Soma.Core.MsSqlConfig
{
......@@ -94,13 +110,24 @@ public override Action<PreparedStatement> Logger
static readonly Action<PreparedStatement> noOp = x => { };
}
#endif
static void Try(Action action, string blame)
{
try
{
action();
} catch(Exception ex)
{
Console.Error.WriteLine($"{blame}: {ex.Message}");
}
}
public void Run(int iterations)
{
using (var connection = TestSuite.GetOpenConnection())
{
var tests = new Tests();
#if EXTERNALS
#if LINQ2SQL
Try(() =>
{
var l2scontext1 = GetL2SContext(connection);
tests.Add(id => l2scontext1.Posts.First(p => p.Id == id), "Linq 2 SQL");
......@@ -110,7 +137,12 @@ public void Run(int iterations)
var l2scontext3 = GetL2SContext(connection);
tests.Add(id => l2scontext3.ExecuteQuery<Post>("select * from Posts where Id = {0}", id).First(), "Linq 2 SQL ExecuteQuery");
}, "LINQ-to-SQL");
#endif
#if ENTITY_FRAMEWORK
Try(() =>
{
var entityContext = new EFContext(connection);
tests.Add(id => entityContext.Posts.First(p => p.Id == id), "Entity framework");
......@@ -126,7 +158,10 @@ public void Run(int iterations)
var entityContext5 = new EFContext(connection);
tests.Add(id => entityContext5.Posts.AsNoTracking().First(p => p.Id == id), "Entity framework No Tracking");
}, "Entity Framework");
#endif
Try(() =>
{
var mapperConnection = TestSuite.GetOpenConnection();
tests.Add(id => mapperConnection.Query<Post>("select * from Posts where Id = @Id", new { Id = id }, buffered: true).First(), "Mapper Query (buffered)");
tests.Add(id => mapperConnection.Query<Post>("select * from Posts where Id = @Id", new { Id = id }, buffered: false).First(), "Mapper Query (non-buffered)");
......@@ -140,14 +175,22 @@ public void Run(int iterations)
// dapper.contrib
var mapperConnection3 = TestSuite.GetOpenConnection();
tests.Add(id => mapperConnection3.Get<Post>(id), "Dapper.Cotrib");
tests.Add(id => mapperConnection3.Get<Post>(id), "Dapper.Contrib");
}, "Dapper");
#if EXTERNALS
#if MASSIVE
Try(() =>
{
// massive
var massiveModel = new DynamicModel(TestSuite.ConnectionString);
var massiveConnection = TestSuite.GetOpenConnection();
tests.Add(id => massiveModel.Query("select * from Posts where Id = @0", massiveConnection, id).First(), "Dynamic Massive ORM Query");
}, "Massive");
#endif
#if PETAPOCO
Try(() =>
{
// PetaPoco test with all default options
var petapoco = new PetaPoco.Database(TestSuite.ConnectionString, "System.Data.SqlClient");
petapoco.OpenSharedConnection();
......@@ -160,18 +203,24 @@ public void Run(int iterations)
petapocoFast.EnableNamedParams = false;
petapocoFast.ForceDateTimesToUtc = false;
tests.Add(id => petapocoFast.Fetch<Post>("SELECT * from Posts where Id=@0", id).First(), "PetaPoco (Fast)");
}, "PetaPoco");
#endif
#if SUBSONIC
Try(() =>
{
// Subsonic ActiveRecord
tests.Add(id => SubSonic.Post.SingleOrDefault(x => x.Id == id), "SubSonic ActiveRecord.SingleOrDefault");
// Subsonic coding horror
SubSonic.tempdbDB db = new SubSonic.tempdbDB();
tests.Add(id => new SubSonic.Query.CodingHorror(db.Provider, "select * from Posts where Id = @0", id).ExecuteTypedList<Post>(), "SubSonic Coding Horror");
}, "Subsonic");
#endif
// NHibernate
#if NHIBERNATE
Try(() => {
var nhSession1 = NHibernateHelper.OpenSession();
tests.Add(id => nhSession1.CreateSQLQuery(@"select * from Posts where Id = :id")
.SetInt32("id", id)
......@@ -194,20 +243,28 @@ public void Run(int iterations)
var nhSession5 = NHibernateHelper.OpenSession();
tests.Add(id => nhSession5.Get<Post>(id), "NHibernate Session.Get");
}, "NHibernate");
#endif
#if BLTOOLKIT
// bltoolkit
var db1 = new DbManager(TestSuite.GetOpenConnection());
tests.Add(id => db1.SetCommand("select * from Posts where Id = @id", db1.Parameter("id", id)).ExecuteList<Post>(), "BLToolkit");
#endif
#if SIMPLEDATA
// Simple.Data
Try(() =>
{
var sdb = Simple.Data.Database.OpenConnection(TestSuite.ConnectionString);
tests.Add(id => sdb.Posts.FindById(id), "Simple.Data");
}, "Simple.Data");
#endif
#if SUSANOO
//Susanoo
var susanooDb = new DatabaseManager("Smackdown.Properties.Settings.tempdbConnectionString");
var susanooDb2 = new DatabaseManager("Smackdown.Properties.Settings.tempdbConnectionString");
var susanooPreDefinedCommand =
CommandManager.DefineCommand("SELECT * FROM Posts WHERE Id = @Id", CommandType.Text)
.DefineResults<Post>()
......@@ -237,19 +294,23 @@ public void Run(int iterations)
tests.Add(Id =>
susanooPreDefinedCommand
.Execute(susanooDb, new { Id }).First(), "Susanoo Mapping Static");
#endif
#if SOMA
// Soma
// DISABLED: assembly fail loading FSharp.PowerPack, Version=2.0.0.0
// var somadb = new Soma.Core.Db(new SomaConfig());
// tests.Add(id => somadb.Find<Post>(id), "Soma");
#endif
#if ORMLITE
//ServiceStack's OrmLite:
OrmLiteConfig.DialectProvider = SqlServerOrmLiteDialectProvider.Instance; //Using SQL Server
IDbCommand ormLiteCmd = TestSuite.GetOpenConnection().CreateCommand();
tests.Add(id => ormLiteCmd.QueryById<Post>(id), "OrmLite QueryById");
// DISABLED: can't find QueryById
//OrmLiteConfig.DialectProvider = SqlServerOrmLiteDialectProvider.Instance; //Using SQL Server
//IDbCommand ormLiteCmd = TestSuite.GetOpenConnection().CreateCommand();
// tests.Add(id => ormLiteCmd.QueryById<Post>(id), "OrmLite QueryById");
#endif
#endif // EXTERNALS
// HAND CODED
var postCommand = new SqlCommand();
......@@ -315,6 +376,8 @@ public void Run(int iterations)
}
}, "DataTable via IDataReader.GetValues");
#endif
Console.WriteLine();
Console.WriteLine("Running...");
tests.Run(iterations);
}
}
......
......@@ -2,13 +2,15 @@
namespace Dapper.Tests
{
#if EXTERNALS
#if ORMLITE
[ServiceStack.DataAnnotations.Alias("Posts")]
#endif
#if SOMA
[Soma.Core.Table(Name = "Posts")]
#endif
public class Post
{
#if EXTERNALS
#if SOMA
[Soma.Core.Id(Soma.Core.IdKind.Identity)]
#endif
public int Id { get; set; }
......
......@@ -192,7 +192,7 @@ public async Task TestMultiClosedConnAsyncViaFirstOrDefault()
}
}
#if EXTERNALS
#if !COREFX
[Fact]
public async Task ExecuteReaderOpenAsync()
{
......
......@@ -114,7 +114,7 @@ public bool GetWentThroughProperConstructor()
}
}
#if EXTERNALS
#if LINQ2SQL
class NoDefaultConstructorWithBinary
{
public System.Data.Linq.Binary Value { get; set; }
......
......@@ -9,7 +9,7 @@
using System.Linq;
using Xunit;
#if EXTERNALS
#if ENTITY_FRAMEWORK
using System.Data.Entity.Spatial;
using Microsoft.SqlServer.Types;
#endif
......@@ -114,7 +114,7 @@ public void AddParameter(IDbCommand command, string name)
}
#if EXTERNALS
#if !COREFX
[Fact]
public void TestTVPWithAnonymousObject()
{
......@@ -346,7 +346,9 @@ public void DataTableParametersWithExtendedProperty()
ex.Message.Equals("The table type parameter 'ids' must have a valid type name.");
}
}
#endif
#if !COREFX
[Fact]
public void SupportInit()
{
......@@ -354,7 +356,9 @@ public void SupportInit()
obj.Value.Equals("abc");
obj.Flags.Equals(31);
}
#endif
#if ENTITY_FRAMEWORK
class HazGeo
{
public int Id { get; set; }
......@@ -445,6 +449,10 @@ public class HazSqlHierarchy
public SqlHierarchyId Path { get; set; }
}
#endif
#if OLEDB
// see http://stackoverflow.com/q/18847510/23354
[Fact]
public void TestOleDbParameters()
......
......@@ -26,16 +26,20 @@
using System.Diagnostics;
using Xunit;
using System.Data.Common;
#if EXTERNALS
#if FIREBIRD
using FirebirdSql.Data.FirebirdClient;
#endif
#if ENTITY_FRAMEWORK
using System.Data.Entity.Spatial;
using Microsoft.SqlServer.Types;
#endif
#if SQL_CE
using System.Data.SqlServerCe;
#endif
using SqlServerTypes;
#if POSTGRESQL
using Npgsql;
#endif
#endif
#if COREFX
namespace System.ComponentModel {
......@@ -116,10 +120,16 @@ static TestSuite()
#endif
Console.WriteLine("Dapper: " + typeof(SqlMapper).AssemblyQualifiedName);
Console.WriteLine("Using Connectionstring: {0}", ConnectionString);
#if EXTERNALS && !DNX
#if !COREFX
Console.Write("Loading native assemblies for SQL types...");
try {
Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
Console.WriteLine("done.");
} catch(Exception ex)
{
Console.WriteLine("failed.");
Console.Error.WriteLine(ex.Message);
}
#endif
}
......@@ -726,7 +736,7 @@ public void TestInheritance()
list.First().Base2.IsEqualTo("Four");
}
#if EXTERNALS
#if !COREFX
[Fact]
public void ExecuteReader()
{
......@@ -739,7 +749,9 @@ public void ExecuteReader()
((int)dt.Rows[0][0]).IsEqualTo(3);
((int)dt.Rows[0][1]).IsEqualTo(4);
}
#endif
#if SQL_CE
[Fact]
public void MultiRSSqlCE()
{
......@@ -784,7 +796,8 @@ public class AuthorCE
public int ID { get; set; }
public string Name { get; set; }
}
#endif
#if LINQ2SQL
[Fact]
public void TestLinqBinaryToClass()
{
......@@ -2226,7 +2239,7 @@ public void SO24605346_ProcsAndStrings()
class PracticeRebateOrders
{
public string fTaxInvoiceNumber;
#if EXTERNALS
#if !COREFX
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
#endif
public string TaxInvoiceNumber { get { return fTaxInvoiceNumber; } set { fTaxInvoiceNumber = value; } }
......@@ -2385,7 +2398,7 @@ public void Issue22_ExecuteScalar()
int? k = connection.ExecuteScalar<int?>("select @i", new { i = default(int?) });
k.IsNull();
#if EXTERNALS
#if ENTITY_FRAMEWORK
Dapper.EntityFramework.Handlers.Register();
var geo = DbGeography.LineFromText("LINESTRING(-122.360 47.656, -122.343 47.656 )", 4326);
var geo2 = connection.ExecuteScalar<DbGeography>("select @geo", new { geo });
......@@ -3022,7 +3035,7 @@ class Issue295Person
public DateTime? DoB { get; set; }
public DateTime? DoB2 { get; set; }
}
#if EXTERNALS
#if FIREBIRD
[Fact(Skip="Bug in Firebird; a PR to fix it has been submitted")]
public void Issue178_Firebird()
{
......@@ -3059,7 +3072,9 @@ public void Issue178_Firebird()
count.IsEqualTo(1);
}
}
#endif
#if OLEDB
[Fact]
public void PseudoPositionalParameters_Simple()
{
......@@ -3204,9 +3219,9 @@ class Cat
};
[Fact]
public void TestPostresqlArrayParameters()
public void TestPostgresqlArrayParameters()
{
using (var conn = new NpgsqlConnection("Server=localhost;Port=5432;User Id=dappertest;Password=dapperpass;Database=dappertest;Encoding=UNICODE"))
using (var conn = new NpgsqlConnection("Server=localhost;Port=5432;User Id=dappertest;Password=dapperpass;Database=dappertest")) // ;Encoding=UNICODE
{
conn.Open();
IDbTransaction transaction = conn.BeginTransaction();
......
......@@ -26,7 +26,18 @@
"frameworks": {
"net40": {
"compilationOptions": {
"define": [ "MYSQL" ]
"define": [
"MYSQL",
"ENTITY_FRAMEWORK",
"LINQ2SQL",
"FIREBIRD",
"SQL_CE",
"OLEDB",
"MASSIVE",
"ORMLITE",
"SOMA",
"SIMPLEDATA"
]
},
"frameworkAssemblies": {
"System.Configuration": "4.0.0.0",
......@@ -35,17 +46,40 @@
"System.Xml": "4.0.0.0"
},
"dependencies": {
"Dapper.EntityFramework": {
"target": "project"
},
"EntityFramework": "6.1.3",
"FirebirdSql.Data.FirebirdClient": "4.10.0",
"Microsoft.SqlServer.Types": "11.0.2",
"MySql.Data": "6.9.8",
"NHibernate": "4.0.4.4000",
"ServiceStack.OrmLite": "4.0.48",
"ServiceStack.OrmLite.SqlServer": "4.0.48",
"Simple.Data.Ado": "1.0.0-rc3",
"Simple.Data.Core": "1.0.0-rc3",
"Simple.Data.SqlServer": "1.0.0-rc3",
"Soma": "1.8.0.7",
"xunit": "1.9.2",
"MySql.Data": "6.9.8"
"System.Data.SqlServerCe_unofficial": "4.0.8482.1",
"xunit": "1.9.2"
}
},
"net45": {
"compilationOptions": {
"define": [ "ASYNC", "MYSQL" ]
"define": [
"ASYNC",
"MYSQL",
"ENTITY_FRAMEWORK",
"LINQ2SQL",
"FIREBIRD",
"SQL_CE",
"POSTGRESQL",
"OLEDB",
"MASSIVE",
"ORMLITE",
"SOMA",
"SIMPLEDATA"
]
},
"frameworkAssemblies": {
"System.Configuration": "4.0.0.0",
......@@ -55,12 +89,25 @@
"System.Xml": "4.0.0.0"
},
"dependencies": {
"Dapper.EntityFramework": {
"target": "project"
},
"EntityFramework": "6.1.3",
"FirebirdSql.Data.FirebirdClient": "4.10.0",
"Microsoft.SqlServer.Types": "11.0.2",
"MySql.Data": "6.9.8",
"NHibernate": "4.0.4.4000",
"Npgsql": "3.0.5",
"ServiceStack.OrmLite": "4.0.48",
"ServiceStack.OrmLite.SqlServer": "4.0.48",
"Simple.Data.Ado": "2.0.0-alpha1",
"Simple.Data.Core": "2.0.0-alpha1",
"Simple.Data.SqlServer": "2.0.0-alpha1",
"Soma": "1.8.0.7",
"xunit": "2.1.0",
"MySql.Data": "6.9.8"
"Susanoo.Core": "1.2.4",
"Susanoo.SqlServer": "1.2.4",
"System.Data.SqlServerCe_unofficial": "4.0.8482.1",
"xunit": "2.1.0"
}
},
"dotnet5.4": {
......@@ -80,37 +127,50 @@
},
"dnx451": {
"compilationOptions": {
"define": [ "ASYNC", "EXTERNALS", "DNX", "MYSQL" ]
"define": [
"ASYNC",
"MYSQL",
"ENTITY_FRAMEWORK",
"LINQ2SQL",
"FIREBIRD",
"SQL_CE",
"POSTGRESQL",
"OLEDB",
"MASSIVE",
"ORMLITE",
"SOMA",
"SIMPLEDATA"
]
},
"frameworkAssemblies": {
"System.Configuration": "4.0.0.0",
"System.Data.Linq": "4.0.0.0"
"System.Data": "4.0.0.0",
"System.Data.Linq": "4.0.0.0",
"System.Runtime": "4.0.0.0",
"System.Xml": "4.0.0.0"
},
"dependencies": {
"NHibernate": "4.0.4.4000",
"NHibernate.ByteCode.LinFu": "1.1.0",
"NHibernate.ByteCode.Castle": "3.3.3.4000",
"Dapper.EntityFramework": {
"target": "project"
},
"EntityFramework": "6.1.3",
"FirebirdSql.Data.FirebirdClient": "4.10.0",
"Microsoft.SqlServer.Types": "11.0.2",
"MySql.Data": "6.9.8",
"NHibernate": "4.0.4.4000",
"Npgsql": "3.0.5",
"ServiceStack.OrmLite": "4.0.48",
"ServiceStack.OrmLite.SqlServer": "4.0.48",
"Microsoft.SqlServer.Compact": "4.0.8876.1",
"Microsoft.SqlServer.Types": "11.0.2",
"Npgsql": "2.1.0",
"Soma": "1.8.0.7",
"xunit": "2.1.0",
"xunit.runner.dnx": "2.1.0-*",
"BLToolkit": "4.1.21",
"Susanoo.Core": "0.8.4.36",
"SubSonic": "3.0.0.4",
"Simple.Data.Ado": "2.0.0-alpha1",
"Simple.Data.Core": "2.0.0-alpha1",
"Simple.Data.SqlServer": "2.0.0-alpha1",
"FirebirdSql.Data.FirebirdClient": "4.8.1.1",
"Dapper.EntityFramework": {
"target": "project"
},
"MySql.Data": "6.9.8"
"Soma": "1.8.0.7",
"Susanoo.Core": "1.2.4",
"Susanoo.SqlServer": "1.2.4",
"System.Data.SqlServerCe_unofficial": "4.0.8482.1",
"xunit": "2.2.0-beta1-build3239",
"xunit.runner.dnx": "2.1.0-rc1-build204"
}
},
"dnxcore50": {
"compilationOptions": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment