Commit ae7a29a9 authored by Nick Craver's avatar Nick Craver

VS 2017 .csproj Migration

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
parent 71c16e66
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NuGet.CommandLine" version="2.8.3" />
</packages>
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Dapper.Contrib</AssemblyName>
<PackageTags>orm;sql;micro-orm;dapper</PackageTags>
<Title>Dapper.Contrib</Title>
<Description>The official collection of get, insert, update and delete helpers for Dapper.net. Also handles lists of entities and optional "dirty" tracking of interface-based entities.</Description>
<Authors>Sam Saffron;Johan Danforth</Authors>
<TargetFrameworks>net40;net45;netstandard1.3</TargetFrameworks>
<!-- TODO: Docs -->
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Dapper\TypeExtensions.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' ">
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>4e409f8f-cfbb-4332-8b0a-fd5a283051fd</ProjectGuid>
<RootNamespace>Dapper.Contrib</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
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("Dapper.Contrib")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Dapper.Contrib")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("6dde1c15-4e92-45e7-93fc-88778d15ff31")]
// 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 Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.50.0.0")]
[assembly: AssemblyFileVersion("1.50.0.0")]
{
"packOptions": {
"summary": "Dapper.Contrib",
"tags": [ "orm", "sql", "micro-orm", "dapper" ],
"owners": [ "johandanforth", "marc.gravell", "nick.craver" ],
"projectUrl": "https://github.com/StackExchange/dapper-dot-net",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0",
"repository": {
"type": "git",
"url": "https://github.com/StackExchange/dapper-dot-net"
}
},
"authors": [ "Sam Saffron", "Johan Danforth" ],
"description": "The official collection of get, insert, update and delete helpers for dapper.net. Also handles lists of entities and optional \"dirty\" tracking of interface-based entities.",
"version": "1.50.2-*",
"title": "Dapper.Contrib",
"copyright": "2017 Stack Exchange, Inc.",
"dependencies": {
"Dapper": {
"version": "1.50.2-*",
"target": "project"
}
},
"buildOptions": {
"warningsAsErrors": true,
"compile": {
"include": [
"**/*.cs"
],
"includeFiles": [
"../Dapper/TypeExtensions.cs"
]
}
},
"frameworks": {
"net40": {
"frameworkAssemblies": {
"System.Data": "4.0.0.0",
"System.Data.Linq": "4.0.0.0"
}
},
"net45": {
"buildOptions": {
"define": [ "ASYNC" ]
},
"frameworkAssemblies": {
"System.Data": "4.0.0.0",
"System.Data.Linq": "4.0.0.0"
},
"dependencies": {
}
},
"netstandard1.3": {
"buildOptions": {
"define": [ "ASYNC", "COREFX" ]
},
"dependencies": {
"Microsoft.CSharp": "4.0.1"
}
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>1a70b6d7-244e-41ed-8ff5-6f0e8e26a764</ProjectGuid>
<RootNamespace>Dapper.EntityFramework.StrongName</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
\ No newline at end of file
{
"packOptions": {
"summary": "Adds support for DbGeography, etc.",
"tags": [ "orm", "sql", "micro-orm" ],
"owners": [ "marc.gravell", "nick.craver" ],
"projectUrl": "https://github.com/StackExchange/dapper-dot-net",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0",
"repository": {
"type": "git",
"url": "https://github.com/StackExchange/dapper-dot-net"
}
},
"authors": [ "Marc Gravell", "Nick Craver" ],
"description": "Extension handlers for entity framework",
"version": "1.50.2-*",
"title": "Dapper entity framework type handlers (with a strong name)",
"copyright": "2017 Stack Exchange, Inc.",
"dependencies": {
"Dapper.StrongName": {
"version": "1.50.2-*",
"target": "project"
}
},
"buildOptions": {
"xmlDoc": true,
"warningsAsErrors": true,
"keyFile": "../Dapper.snk",
"compile": {
"include": [
"../Dapper.EntityFramework/**/*.cs"
],
"exclude": [
"../Dapper.EntityFramework/obj/"
]
}
},
"frameworks": {
"net40": {
"frameworkAssemblies": {
"System.Configuration": "4.0.0.0",
"System.Data": "4.0.0.0",
"System.Data.Linq": "4.0.0.0",
"System.Xml": "4.0.0.0"
},
"dependencies": {
"EntityFramework": "6.1.3",
"Microsoft.SqlServer.Types": "11.0.2"
}
},
"net45": {
"buildOptions": {
"define": [ "ASYNC" ]
},
"frameworkAssemblies": {
"System.Configuration": "4.0.0.0",
"System.Data": "4.0.0.0",
"System.Data.Linq": "4.0.0.0",
"System.Xml": "4.0.0.0"
},
"dependencies": {
"EntityFramework": "6.1.3",
"Microsoft.SqlServer.Types": "11.0.2"
}
}
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Dapper.EntityFramework.StrongName</AssemblyName>
<Title>Dapper: Entity Framework type handlers (with a strong name)</Title>
<Description>Extension handlers for entity framework</Description>
<Authors>Marc Gravell;Nick Craver</Authors>
<TargetFrameworks>net40;net45</TargetFrameworks>
<AssemblyOriginatorKeyFile>../Dapper.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<PackageId>Dapper.EntityFramework.StrongName</PackageId>
<PackageTags>orm;sql;micro-orm</PackageTags>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.StrongName.csproj" />
<PackageReference Include="EntityFramework" Version="6.1.3" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="11.0.2" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.Xml" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Dapper.EntityFramework</AssemblyName>
<Description>Extension handlers for entity framework</Description>
<AssemblyTitle>Dapper entity framework type handlers</AssemblyTitle>
<VersionPrefix>1.50.2</VersionPrefix>
<Authors>Marc Gravell;Nick Craver</Authors>
<TargetFrameworks>net40;net45</TargetFrameworks>
<PackageTags>orm;sql;micro-orm</PackageTags>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
<PackageReference Include="EntityFramework" Version="6.1.3" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="11.0.2" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.Xml" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>be401f7b-8611-4a1e-aeaa-5cb700128c16</ProjectGuid>
<RootNamespace>Dapper.EntityFramework</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
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("Dapper.EntityFramework")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Dapper.EntityFramework")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("2400e6b9-a925-45d8-ab5a-07f119b0eedb")]
// 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 Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
{
"packOptions": {
"summary": "Adds support for DbGeography, etc.",
"tags": [ "orm", "sql", "micro-orm" ],
"owners": [ "marc.gravell", "nick.craver" ],
"projectUrl": "https://github.com/StackExchange/dapper-dot-net",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0",
"repository": {
"type": "git",
"url": "https://github.com/StackExchange/dapper-dot-net"
}
},
"authors": [ "Marc Gravell", "Nick Craver" ],
"description": "Extension handlers for entity framework",
"version": "1.50.2-*",
"title": "Dapper entity framework type handlers",
"copyright": "2017 Stack Exchange, Inc.",
"dependencies": {
"Dapper": {
"version": "1.50.2-*",
"target": "project"
}
},
"buildOptions": {
"xmlDoc": true,
"warningsAsErrors": true
},
"frameworks": {
"net40": {
"frameworkAssemblies": {
"System.Configuration": "4.0.0.0",
"System.Data": "4.0.0.0",
"System.Data.Linq": "4.0.0.0",
"System.Xml": "4.0.0.0"
},
"dependencies": {
"EntityFramework": "6.1.3",
"Microsoft.SqlServer.Types": "11.0.2"
}
},
"net45": {
"buildOptions": {
"define": [ "ASYNC" ]
},
"frameworkAssemblies": {
"System.Configuration": "4.0.0.0",
"System.Data": "4.0.0.0",
"System.Data.Linq": "4.0.0.0",
"System.Xml": "4.0.0.0"
},
"dependencies": {
"EntityFramework": "6.1.3",
"Microsoft.SqlServer.Types": "11.0.2"
}
}
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Dapper.Rainbow</AssemblyName>
<PackageTags>orm;sql;micro-orm</PackageTags>
<Title>Dapper.Rainbow</Title>
<Description>Trivial micro-orm implemented on Dapper, provides with CRUD helpers.</Description>
<Authors>Sam Saffron</Authors>
<Copyright>2017 Sam Saffron</Copyright>
<TargetFrameworks>net40;net45;netstandard1.3</TargetFrameworks>
<!-- TODO: Docs -->
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Dapper\TypeExtensions.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' ">
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>8a74f0b6-188f-45d2-8a4b-51e4f211805a</ProjectGuid>
<RootNamespace>Dapper.Rainbow</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
\ No newline at end of file
...@@ -106,7 +106,7 @@ public IEnumerable<T> All() ...@@ -106,7 +106,7 @@ public IEnumerable<T> All()
return database.Query<T>("select * from " + TableName); return database.Query<T>("select * from " + TableName);
} }
static ConcurrentDictionary<Type, List<string>> paramNameCache = new ConcurrentDictionary<Type, List<string>>(); private static ConcurrentDictionary<Type, List<string>> paramNameCache = new ConcurrentDictionary<Type, List<string>>();
internal static List<string> GetParamNames(object o) internal static List<string> GetParamNames(object o)
{ {
...@@ -127,7 +127,7 @@ internal static List<string> GetParamNames(object o) ...@@ -127,7 +127,7 @@ internal static List<string> GetParamNames(object o)
if (attr==null || (!attr.Value)) if (attr==null || (!attr.Value))
{ {
paramNames.Add(prop.Name); paramNames.Add(prop.Name);
} }
} }
paramNameCache[o.GetType()] = paramNames; paramNameCache[o.GetType()] = paramNames;
} }
...@@ -142,9 +142,9 @@ public Table(Database<TDatabase> database, string likelyTableName) ...@@ -142,9 +142,9 @@ public Table(Database<TDatabase> database, string likelyTableName)
} }
} }
DbConnection _connection; private DbConnection _connection;
int _commandTimeout; private int _commandTimeout;
DbTransaction _transaction; private DbTransaction _transaction;
public static TDatabase Init(DbConnection connection, int commandTimeout) public static TDatabase Init(DbConnection connection, int commandTimeout)
{ {
...@@ -240,7 +240,7 @@ protected Action<TDatabase> CreateTableConstructor(params Type[] tableTypes) ...@@ -240,7 +240,7 @@ protected Action<TDatabase> CreateTableConstructor(params Type[] tableTypes)
return (Action<TDatabase>)dm.CreateDelegate(typeof(Action<TDatabase>)); return (Action<TDatabase>)dm.CreateDelegate(typeof(Action<TDatabase>));
} }
static ConcurrentDictionary<Type, string> tableNameMap = new ConcurrentDictionary<Type, string>(); private static ConcurrentDictionary<Type, string> tableNameMap = new ConcurrentDictionary<Type, string>();
private string DetermineTableName<T>(string likelyTableName) private string DetermineTableName<T>(string likelyTableName)
{ {
string name; string name;
......
using System.Reflection;
using System.Runtime.CompilerServices;
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("Dapper.Rainbow")]
[assembly: AssemblyDescription("I sample mini ORM implementation using Dapper")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Dapper.Rainbow")]
[assembly: AssemblyCopyright("Sam Saffron Copyright © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e763c106-eef4-4654-afcc-c28fded057e5")]
// 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 Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("0.1.0.0")]
[assembly: AssemblyFileVersion("0.1.0.0")]
This diff is collapsed.
{
"packOptions": {
"summary": "A demo is available at https://gist.github.com/1599013",
"tags": [ "orm", "sql", "micro-orm" ],
"owners": [ "samsaffron" ],
"projectUrl": "https://github.com/StackExchange/dapper-dot-net",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0",
"repository": {
"type": "git",
"url": "https://github.com/StackExchange/dapper-dot-net"
}
},
"authors": [ "Sam Saffron" ],
"description": "Trivial micro-orm implemented on Dapper, provides with CRUD helpers.",
"version": "0.1.3-beta1",
"title": "Dapper.Rainbow",
"copyright": "2012 Sam Saffron",
"dependencies": {
"Dapper": {
"version": "1.50.2-*",
"target": "project"
}
},
"buildOptions": {
"warningsAsErrors": true,
"compile": {
"include": [
"**/*.cs"
],
"includeFiles": [
"../Dapper/TypeExtensions.cs"
]
}
},
"frameworks": {
"net40": {
"frameworkAssemblies": {
"System.Configuration": "4.0.0.0",
"System.Data": "4.0.0.0",
"System.Data.Linq": "4.0.0.0"
}
},
"net45": {
"buildOptions": {
"define": [ "ASYNC" ]
},
"frameworkAssemblies": {
"System.Configuration": "4.0.0.0",
"System.Data": "4.0.0.0",
"System.Data.Linq": "4.0.0.0"
}
},
"netstandard1.3": {
"buildOptions": {
"define": [ "ASYNC", "COREFX" ]
},
"dependencies": {
"Microsoft.CSharp": "4.0.1"
}
}
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Dapper.SqlBuilder</AssemblyName>
<PackageTags>orm;sql;micro-orm;query;sql-builder</PackageTags>
<Title>Dapper SqlBuilder component</Title>
<Description>The Dapper SqlBuilder component, for building SQL queries dynamically.</Description>
<Authors>Sam Saffron, Johan Danforth</Authors>
<TargetFrameworks>net40;net45;netstandard1.3</TargetFrameworks>
<!-- TODO: Docs -->
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' ">
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>196928f0-7052-4585-90e8-817bd720f5e3</ProjectGuid>
<RootNamespace>Dapper.SqlBuilder</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
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("Dapper.SqlBuilder")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Dapper.SqlBuilder")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("27491c26-c95d-44e5-b907-30559ef11265")]
// 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 Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.50.0.0")]
[assembly: AssemblyFileVersion("1.50.0.0")]
...@@ -21,7 +21,7 @@ class Clauses : List<Clause> ...@@ -21,7 +21,7 @@ class Clauses : List<Clause>
private readonly string _joiner; private readonly string _joiner;
private readonly string _prefix; private readonly string _prefix;
private readonly string _postfix; private readonly string _postfix;
public Clauses(string joiner, string prefix = "", string postfix = "") public Clauses(string joiner, string prefix = "", string postfix = "")
{ {
_joiner = joiner; _joiner = joiner;
...@@ -56,7 +56,7 @@ public class Template ...@@ -56,7 +56,7 @@ public class Template
private readonly SqlBuilder _builder; private readonly SqlBuilder _builder;
private readonly object _initParams; private readonly object _initParams;
private int _dataSeq = -1; // Unresolved private int _dataSeq = -1; // Unresolved
public Template(SqlBuilder builder, string sql, dynamic parameters) public Template(SqlBuilder builder, string sql, dynamic parameters)
{ {
_initParams = parameters; _initParams = parameters;
...@@ -110,73 +110,73 @@ protected void AddClause(string name, string sql, object parameters, string join ...@@ -110,73 +110,73 @@ protected void AddClause(string name, string sql, object parameters, string join
clauses.Add(new Clause { Sql = sql, Parameters = parameters, IsInclusive = isInclusive }); clauses.Add(new Clause { Sql = sql, Parameters = parameters, IsInclusive = isInclusive });
_seq++; _seq++;
} }
public SqlBuilder Intersect(string sql, dynamic parameters = null) public SqlBuilder Intersect(string sql, dynamic parameters = null)
{ {
AddClause("intersect", sql, parameters, "\nINTERSECT\n ", "\n ", "\n", false); AddClause("intersect", sql, parameters, "\nINTERSECT\n ", "\n ", "\n", false);
return this; return this;
} }
public SqlBuilder InnerJoin(string sql, dynamic parameters = null) public SqlBuilder InnerJoin(string sql, dynamic parameters = null)
{ {
AddClause("innerjoin", sql, parameters, "\nINNER JOIN ", "\nINNER JOIN ", "\n", false); AddClause("innerjoin", sql, parameters, "\nINNER JOIN ", "\nINNER JOIN ", "\n", false);
return this; return this;
} }
public SqlBuilder LeftJoin(string sql, dynamic parameters = null) public SqlBuilder LeftJoin(string sql, dynamic parameters = null)
{ {
AddClause("leftjoin", sql, parameters, "\nLEFT JOIN ", "\nLEFT JOIN ", "\n", false); AddClause("leftjoin", sql, parameters, "\nLEFT JOIN ", "\nLEFT JOIN ", "\n", false);
return this; return this;
} }
public SqlBuilder RightJoin(string sql, dynamic parameters = null) public SqlBuilder RightJoin(string sql, dynamic parameters = null)
{ {
AddClause("rightjoin", sql, parameters, "\nRIGHT JOIN ", "\nRIGHT JOIN ", "\n", false); AddClause("rightjoin", sql, parameters, "\nRIGHT JOIN ", "\nRIGHT JOIN ", "\n", false);
return this; return this;
} }
public SqlBuilder Where(string sql, dynamic parameters = null) public SqlBuilder Where(string sql, dynamic parameters = null)
{ {
AddClause("where", sql, parameters, " AND ", "WHERE ", "\n", false); AddClause("where", sql, parameters, " AND ", "WHERE ", "\n", false);
return this; return this;
} }
public SqlBuilder OrWhere(string sql, dynamic parameters = null) public SqlBuilder OrWhere(string sql, dynamic parameters = null)
{ {
AddClause("where", sql, parameters, " OR ", "WHERE ", "\n", true); AddClause("where", sql, parameters, " OR ", "WHERE ", "\n", true);
return this; return this;
} }
public SqlBuilder OrderBy(string sql, dynamic parameters = null) public SqlBuilder OrderBy(string sql, dynamic parameters = null)
{ {
AddClause("orderby", sql, parameters, " , ", "ORDER BY ", "\n", false); AddClause("orderby", sql, parameters, " , ", "ORDER BY ", "\n", false);
return this; return this;
} }
public SqlBuilder Select(string sql, dynamic parameters = null) public SqlBuilder Select(string sql, dynamic parameters = null)
{ {
AddClause("select", sql, parameters, " , ", "", "\n", false); AddClause("select", sql, parameters, " , ", "", "\n", false);
return this; return this;
} }
public SqlBuilder AddParameters(dynamic parameters) public SqlBuilder AddParameters(dynamic parameters)
{ {
AddClause("--parameters", "", parameters, "", "", "", false); AddClause("--parameters", "", parameters, "", "", "", false);
return this; return this;
} }
public SqlBuilder Join(string sql, dynamic parameters = null) public SqlBuilder Join(string sql, dynamic parameters = null)
{ {
AddClause("join", sql, parameters, "\nJOIN ", "\nJOIN ", "\n", false); AddClause("join", sql, parameters, "\nJOIN ", "\nJOIN ", "\n", false);
return this; return this;
} }
public SqlBuilder GroupBy(string sql, dynamic parameters = null) public SqlBuilder GroupBy(string sql, dynamic parameters = null)
{ {
AddClause("groupby", sql, parameters, " , ", "\nGROUP BY ", "\n", false); AddClause("groupby", sql, parameters, " , ", "\nGROUP BY ", "\n", false);
return this; return this;
} }
public SqlBuilder Having(string sql, dynamic parameters = null) public SqlBuilder Having(string sql, dynamic parameters = null)
{ {
AddClause("having", sql, parameters, "\nAND ", "HAVING ", "\n", false); AddClause("having", sql, parameters, "\nAND ", "HAVING ", "\n", false);
......
{
"packOptions": {
"summary": "Dapper.SqlBuilder",
"tags": [ "orm", "sql", "micro-orm", "query", "sql-builder" ],
"owners": [ "AEckenberger", "nick.craver" ],
"projectUrl": "https://github.com/StackExchange/dapper-dot-net",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0",
"repository": {
"type": "git",
"url": "https://github.com/StackExchange/dapper-dot-net"
}
},
"authors": [ "Sam Saffron, Johan Danforth" ],
"description": "The Dapper SqlBuilder component, for building SQL queries dynamically.",
"version": "1.50.2-*",
"title": "Dapper SqlBuilder component",
"copyright": "2017 Stack Exchange, Inc.",
"dependencies": {
"Dapper": {
"version": "1.50.2-*",
"target": "project"
}
},
"buildOptions": {
"warningsAsErrors": true
},
"frameworks": {
"net40": {
"frameworkAssemblies": {
"System.Data": "4.0.0.0",
"System.Data.Linq": "4.0.0.0"
}
},
"net45": {
"buildOptions": {
"define": [ "ASYNC" ]
},
"frameworkAssemblies": {
"System.Data": "4.0.0.0",
"System.Data.Linq": "4.0.0.0"
}
},
"netstandard1.3": {
"buildOptions": {
"define": [ "ASYNC", "COREFX" ]
},
"dependencies": {
"Microsoft.CSharp": "4.0.1"
}
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>549c51a1-222b-4e12-96f1-3aeff45a7709</ProjectGuid>
<RootNamespace>Dapper.StrongName</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
\ No newline at end of file
{
"packOptions": {
"summary": "A high performance Micro-ORM",
"tags": [ "orm", "sql", "micro-orm" ],
"owners": [ "marc.gravell", "nick.craver" ],
"releaseNotes": "http://stackexchange.github.io/dapper-dot-net/",
"projectUrl": "https://github.com/StackExchange/dapper-dot-net",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0",
"repository": {
"type": "git",
"url": "https://github.com/StackExchange/dapper-dot-net"
}
},
"authors": [ "Sam Saffron", "Marc Gravell", "Nick Craver" ],
"description": "A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc..",
"version": "1.50.2-*",
"title": "Dapper dot net (strong named)",
"copyright": "2017 Stack Exchange, Inc.",
"dependencies": {
},
"buildOptions": {
"xmlDoc": true,
"keyFile": "../Dapper.snk",
"warningsAsErrors": true,
"compile": {
"include": [
"../Dapper/**/*.cs"
],
"exclude": [
"../Dapper/obj/"
]
}
},
"frameworks": {
"net40": {
"frameworkAssemblies": {
"System.Data": "4.0.0.0",
"System.Xml": "4.0.0.0",
"System.Xml.Linq": "4.0.0.0"
}
},
"net45": {
"buildOptions": {
"define": [ "ASYNC" ]
},
"frameworkAssemblies": {
"System.Data": "4.0.0.0",
"System.Xml": "4.0.0.0",
"System.Xml.Linq": "4.0.0.0"
}
},
"net451": {
"buildOptions": {
"define": [ "ASYNC" ]
},
"frameworkAssemblies": {
"System.Data": "4.0.0.0",
"System.Xml": "4.0.0.0",
"System.Xml.Linq": "4.0.0.0"
}
},
"netstandard1.3": {
"buildOptions": {
"define": [ "ASYNC", "COREFX" ]
},
"dependencies": {
"System.Collections": "4.0.11",
"System.Collections.Concurrent": "4.0.12",
"System.Collections.NonGeneric": "4.0.1",
"System.Data.SqlClient": "4.1.0",
"System.Dynamic.Runtime": "4.0.11",
"System.Linq": "4.1.0",
"System.Reflection": "4.1.0",
"System.Reflection.Emit": "4.0.1",
"System.Reflection.Emit.Lightweight": "4.0.1",
"System.Reflection.Extensions": "4.0.1",
"System.Reflection.TypeExtensions": "4.1.0",
"System.Runtime": "4.1.0",
"System.Runtime.Extensions": "4.1.0",
"System.Runtime.InteropServices": "4.1.0",
"System.Text.RegularExpressions": "4.1.0",
"System.Threading": "4.0.11",
"System.Xml.XDocument": "4.0.11",
"System.Xml.XmlDocument": "4.0.1"
}
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Dapper.Tests.Contrib</AssemblyName>
<Title>Dapper.Tests.Contrib</Title>
<Description>Dapper Contrib Test Suite</Description>
<DebugType>portable</DebugType>
<OutputType>Exe</OutputType>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<DefineConstants>$(DefineConstants);COREFX;</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Dapper.Tests\Helpers\Assert.cs;..\Dapper.Tests\Helpers\XunitSkippable.cs;..\Dapper\TypeExtensions.cs" />
<None Remove="Test.DB.sdf" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
<ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" />
<ProjectReference Include="..\Dapper.SqlBuilder\Dapper.SqlBuilder.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="xunit" Version="2.2.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>dab3c5b7-bcd1-4a5f-bb6b-50d2bb63db4a</ProjectGuid>
<RootNamespace>Dapper.Tests.Contrib</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
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("Dapper.Tests.Contrib")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Dapper.Tests.Contrib")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("9d5920b6-d6af-41ca-b851-803ac922d933")]
// 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 Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
This diff is collapsed.
...@@ -9,11 +9,7 @@ ...@@ -9,11 +9,7 @@
using System.Data.SqlServerCe; using System.Data.SqlServerCe;
using System.Transactions; using System.Transactions;
#endif #endif
#if XUNIT2
using FactAttribute = Dapper.Tests.Contrib.SkippableFactAttribute; using FactAttribute = Dapper.Tests.Contrib.SkippableFactAttribute;
#else
using Xunit;
#endif
namespace Dapper.Tests.Contrib namespace Dapper.Tests.Contrib
{ {
...@@ -32,7 +28,7 @@ public class ObjectY ...@@ -32,7 +28,7 @@ public class ObjectY
public int ObjectYId { get; set; } public int ObjectYId { get; set; }
public string Name { get; set; } public string Name { get; set; }
} }
[Table("ObjectZ")] [Table("ObjectZ")]
public class ObjectZ public class ObjectZ
{ {
...@@ -171,7 +167,7 @@ public void InsertGetUpdateDeleteWithExplicitKey() ...@@ -171,7 +167,7 @@ public void InsertGetUpdateDeleteWithExplicitKey()
o2.IsNull(); o2.IsNull();
} }
} }
[Fact] [Fact]
public void GetAllWithExplicitKey() public void GetAllWithExplicitKey()
{ {
...@@ -187,7 +183,7 @@ public void GetAllWithExplicitKey() ...@@ -187,7 +183,7 @@ public void GetAllWithExplicitKey()
} }
} }
[Fact] [Fact]
public void InsertGetUpdateDeleteWithExplicitKeyNamedId() public void InsertGetUpdateDeleteWithExplicitKeyNamedId()
{ {
using (var connection = GetOpenConnection()) using (var connection = GetOpenConnection())
...@@ -208,8 +204,8 @@ public void InsertGetUpdateDeleteWithExplicitKeyNamedId() ...@@ -208,8 +204,8 @@ public void InsertGetUpdateDeleteWithExplicitKeyNamedId()
//o2.IsNull(); //o2.IsNull();
} }
} }
[Fact] [Fact]
public void ShortIdentity() public void ShortIdentity()
{ {
using (var connection = GetOpenConnection()) using (var connection = GetOpenConnection())
...@@ -233,7 +229,6 @@ public void NullDateTime() ...@@ -233,7 +229,6 @@ public void NullDateTime()
var stuff = connection.Query<Stuff>("select * from Stuff").ToList(); var stuff = connection.Query<Stuff>("select * from Stuff").ToList();
stuff.First().Created.IsNull(); stuff.First().Created.IsNull();
stuff.Last().Created.IsNotNull(); stuff.Last().Created.IsNotNull();
} }
} }
...@@ -342,7 +337,7 @@ private void UpdateHelper<T>(Func<IEnumerable<User>, T> helper) ...@@ -342,7 +337,7 @@ private void UpdateHelper<T>(Func<IEnumerable<User>, T> helper)
users.Count.IsEqualTo(numberOfEntities); users.Count.IsEqualTo(numberOfEntities);
foreach (var user in users) foreach (var user in users)
{ {
user.Name = user.Name + " updated"; user.Name += " updated";
} }
connection.Update(helper(users)); connection.Update(helper(users));
var name = connection.Query<User>("select * from Users").First().Name; var name = connection.Query<User>("select * from Users").First().Name;
...@@ -509,7 +504,6 @@ public void GetAll() ...@@ -509,7 +504,6 @@ public void GetAll()
for (var i = 0; i < numberOfEntities; i++) for (var i = 0; i < numberOfEntities; i++)
iusers[i].Age.IsEqualTo(i); iusers[i].Age.IsEqualTo(i);
} }
} }
[Fact] [Fact]
...@@ -622,7 +616,6 @@ public void InsertFieldWithReservedName() ...@@ -622,7 +616,6 @@ public void InsertFieldWithReservedName()
var result = connection.Get<Result>(id); var result = connection.Get<Result>(id);
result.Order.IsEqualTo(1); result.Order.IsEqualTo(1);
} }
} }
[Fact] [Fact]
......
...@@ -19,14 +19,14 @@ namespace Dapper.Tests.Contrib ...@@ -19,14 +19,14 @@ namespace Dapper.Tests.Contrib
// the entire set of tests without declarations per method // the entire set of tests without declarations per method
// If we want to support a new provider, they need only be added here - not in multiple places // If we want to support a new provider, they need only be added here - not in multiple places
#if XUNIT2
[XunitTestCaseDiscoverer("Dapper.Tests.SkippableFactDiscoverer", "Dapper.Tests.Contrib")] [XunitTestCaseDiscoverer("Dapper.Tests.SkippableFactDiscoverer", "Dapper.Tests.Contrib")]
public class SkippableFactAttribute : FactAttribute { } public class SkippableFactAttribute : FactAttribute
#endif {
}
public class SqlServerTestSuite : TestSuite public class SqlServerTestSuite : TestSuite
{ {
const string DbName = "tempdb"; private const string DbName = "tempdb";
public static string ConnectionString => public static string ConnectionString =>
IsAppVeyor IsAppVeyor
? @"Server=(local)\SQL2014;Database=tempdb;User ID=sa;Password=Password12!" ? @"Server=(local)\SQL2014;Database=tempdb;User ID=sa;Password=Password12!"
...@@ -115,10 +115,8 @@ static MySqlServerTestSuite() ...@@ -115,10 +115,8 @@ static MySqlServerTestSuite()
} }
} }
} }
#endif
#if !COREFX && !DNX451 // This doesn't work on COREFX right now due to:
// This doesn't work on DNX right now due to:
// In Visual Studio: Interop loads (works from console, though) // In Visual Studio: Interop loads (works from console, though)
// In general: parameter names, see https://github.com/StackExchange/dapper-dot-net/issues/375 // In general: parameter names, see https://github.com/StackExchange/dapper-dot-net/issues/375
public class SQLiteTestSuite : TestSuite public class SQLiteTestSuite : TestSuite
...@@ -148,9 +146,7 @@ static SQLiteTestSuite() ...@@ -148,9 +146,7 @@ static SQLiteTestSuite()
} }
} }
} }
#endif
#if !COREFX
public class SqlCETestSuite : TestSuite public class SqlCETestSuite : TestSuite
{ {
const string FileName = "Test.DB.sdf"; const string FileName = "Test.DB.sdf";
......
{
"packOptions": {
"summary": "Dapper Contrib Test Suite",
"tags": [ "orm", "sql", "micro-orm" ],
"owners": [ "johandanforth", "marc.gravell", "nick.craver" ],
"projectUrl": "https://github.com/StackExchange/dapper-dot-net",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0",
"repository": {
"type": "git",
"url": "https://github.com/StackExchange/dapper-dot-net"
}
},
"authors": [ "Sam Saffron", "Johan Danforth" ],
"description": "Dapper Contrib Test Suite",
"title": "Dapper.Tests.Contrib",
"version": "1.0.0",
"copyright": "2017 Stack Exchange, Inc.",
"dependencies": {
"Dapper": {
"target": "project"
},
"Dapper.Contrib": {
"target": "project"
},
"Dapper.SqlBuilder": {
"target": "project"
},
"xunit": "2.2.0-beta2-build3300",
"dotnet-test-xunit": "2.2.0-preview2-build1029"
},
"buildOptions": {
"warningsAsErrors": true,
"emitEntryPoint": true,
"debugType": "portable",
"compile": {
"include": [
"**/*.cs"
],
"includeFiles": [
"../Dapper.Tests/Assert.cs",
"../Dapper.Tests/XunitSkippable.cs",
"../Dapper/TypeExtensions.cs"
]
}
},
"testRunner": "xunit",
"frameworks": {
//"net40": {
// "frameworkAssemblies": {
// "System.Configuration": "4.0.0.0",
// "System.Data": "4.0.0.0",
// "System.Data.Linq": "4.0.0.0",
// "System.Transactions": "4.0.0.0",
// "System.Xml": "4.0.0.0"
// },
// "dependencies": {
// "Microsoft.SqlServer.Compact": "4.0.8876.1",
// "MySql.Data": "6.9.8",
// "System.Data.SQLite.Core": "1.0.98.1",
// "xunit": "1.9.2"
// }
//},
//"net45": {
// "compilationOptions": {
// "define": [ "ASYNC", "XUNIT2" ]
// },
// "frameworkAssemblies": {
// "System.Configuration": "4.0.0.0",
// "System.Data": "4.0.0.0",
// "System.Data.Linq": "4.0.0.0",
// "System.Runtime": "4.0.0.0",
// "System.Transactions": "4.0.0.0",
// "System.Xml": "4.0.0.0"
// },
// "dependencies": {
// "Microsoft.SqlServer.Compact": "4.0.8876.1",
// "MySql.Data": "6.9.8",
// "System.Data.SQLite.Core": "1.0.98.1",
// "xunit": "2.1.0"
// }
//},
//"net451": {
// "buildOptions": {
// "define": [ "ASYNC", "XUNIT2" ]
// },
// "frameworkAssemblies": {
// "System.Configuration": "4.0.0.0",
// "System.Data.Linq": "4.0.0.0",
// "System.Transactions": "4.0.0.0"
// },
// "dependencies": {
// "Microsoft.SqlServer.Compact": "4.0.8876.1",
// "MySql.Data": "6.9.8",
// "System.Data.SQLite.Core": "1.0.98.1",
// "xunit": "2.1.0",
// "dotnet-test-xunit": "1.0.0-rc3-*"
// }
//},
"netcoreapp1.0": {
"imports": [
"portable-net451+win8",
"dnxcore50"
],
"buildOptions": {
"define": [ "COREFX", "ASYNC", "XUNIT2" ]
},
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.Data.Sqlite": "1.0.0"
}
}
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Dapper.Tests.Performance</AssemblyName>
<Title>Dapper.Tests.Performance</Title>
<Description>Dapper Core Performance Suite</Description>
<OutputType>Exe</OutputType>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TargetFrameworks>net462</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
<ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" />
<ProjectReference Include="..\Dapper.EntityFramework\Dapper.EntityFramework.csproj" />
<PackageReference Include="Belgrade.Sql.Client" Version="0.7.0" />
<!--<PackageReference Include="BLToolkit" Version="4.3.6" />-->
<PackageReference Include="EntityFramework" Version="6.1.3" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="5.8.0" />
<PackageReference Include="Microsoft.SqlServer.Compact" Version="4.0.8876.1" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.314.76" />
<PackageReference Include="MySql.Data" Version="7.0.7-m61" />
<PackageReference Include="NHibernate" Version="4.1.1.4000" />
<PackageReference Include="Npgsql" Version="3.2.2" />
<PackageReference Include="PetaPoco" Version="5.1.244" />
<PackageReference Include="ServiceStack.OrmLite.SqlServer.Signed" Version="4.5.6" />
<PackageReference Include="Simple.Data.SqlServer" Version="2.0.0-alpha1" />
<PackageReference Include="Soma" Version="1.8.0.7" />
<PackageReference Include="SubSonic" Version="3.0.0.4" />
<PackageReference Include="Susanoo.SqlServer" Version="1.2.4.2" />
<PackageReference Include="System.Data.SQLite" Version="1.0.104" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<None Update="NHibernate\*.xml" CopyToOutputDirectory="Always" />
</ItemGroup>
</Project>
#if ENTITY_FRAMEWORK using System.Data.Common;
using System.Data.Common;
using System.Data.Entity; using System.Data.Entity;
namespace Dapper.Tests.EntityFramework namespace Dapper.Tests.Performance.EntityFramework
{ {
public class EFContext : DbContext public class EFContext : DbContext
{ {
public EFContext(DbConnection connection, bool owned = false) : base(connection, owned) { } public EFContext(DbConnection connection, bool owned = false) : base(connection, owned)
{
}
public DbSet<Post> Posts { get;set; } public DbSet<Post> Posts { get;set; }
} }
} }
#endif
<?xml version="1.0" encoding="utf-8"?><Database Name="tempdb" Class="DataClassesDataContext" xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007"> <?xml version="1.0" encoding="utf-8"?><Database Name="tempdb" Class="DataClassesDataContext" xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007">
<Connection Mode="AppSettings" ConnectionString="Data Source=.;Initial Catalog=tempdb;Integrated Security=True" SettingsObjectName="Dapper.Tests.Properties.Settings" SettingsPropertyName="tempdbConnectionString" Provider="System.Data.SqlClient" />
<Table Name="dbo.Posts" Member="Posts"> <Table Name="dbo.Posts" Member="Posts">
<Type Name="Post"> <Type Name="Post">
<Column Name="Id" Type="System.Int32" DbType="Int NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" /> <Column Name="Id" Type="System.Int32" DbType="Int NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Dapper.Tests.Linq2Sql namespace Dapper.Tests.Performance.Linq2Sql
{ {
using System.Data.Linq; using System.Data.Linq;
using System.Data.Linq.Mapping; using System.Data.Linq.Mapping;
...@@ -36,12 +36,6 @@ public partial class DataClassesDataContext : System.Data.Linq.DataContext ...@@ -36,12 +36,6 @@ public partial class DataClassesDataContext : System.Data.Linq.DataContext
partial void DeletePost(Post instance); partial void DeletePost(Post instance);
#endregion #endregion
public DataClassesDataContext() :
base(global::Dapper.Tests.Properties.Settings.Default.tempdbConnectionString, mappingSource)
{
OnCreated();
}
public DataClassesDataContext(string connection) : public DataClassesDataContext(string connection) :
base(connection, mappingSource) base(connection, mappingSource)
{ {
......
#if NHIBERNATE using NHibernate;
using NHibernate;
using NHibernate.Cfg; using NHibernate.Cfg;
namespace Dapper.Tests.NHibernate namespace Dapper.Tests.Performance.NHibernate
{ {
public class NHibernateHelper public static class NHibernateHelper
{ {
private static ISessionFactory _sessionFactory; private static ISessionFactory _sessionFactory;
...@@ -15,9 +14,9 @@ private static ISessionFactory SessionFactory ...@@ -15,9 +14,9 @@ private static ISessionFactory SessionFactory
if (_sessionFactory == null) if (_sessionFactory == null)
{ {
var configuration = new Configuration(); var configuration = new Configuration();
configuration.Configure(@"..\Dapper.Tests\NHibernate\hibernate.cfg.xml"); configuration.Configure(@".\NHibernate\hibernate.cfg.xml");
configuration.AddAssembly(typeof(Post).Assembly); configuration.AddAssembly(typeof(Post).Assembly);
configuration.AddXmlFile(@"..\Dapper.Tests\NHibernate\Post.hbm.xml"); configuration.AddXmlFile(@".\NHibernate\Post.hbm.xml");
_sessionFactory = configuration.BuildSessionFactory(); _sessionFactory = configuration.BuildSessionFactory();
} }
...@@ -30,5 +29,4 @@ public static IStatelessSession OpenSession() ...@@ -30,5 +29,4 @@ public static IStatelessSession OpenSession()
return SessionFactory.OpenStatelessSession(); return SessionFactory.OpenStatelessSession();
} }
} }
} }
#endif \ No newline at end of file
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping namespace="Dapper.Tests" assembly="Dapper.Tests" xmlns="urn:nhibernate-mapping-2.2" default-lazy="false"> <hibernate-mapping namespace="Dapper.Tests.Performance" assembly="Dapper.Tests.Performance" xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
<class name="Post" table="Posts" schema="dbo"> <class name="Post" table="Posts" schema="dbo">
<id name="Id" access="property" column="Id"> <id name="Id" access="property" column="Id">
<generator class="native" /> <generator class="native" />
......
...@@ -4,8 +4,7 @@ ...@@ -4,8 +4,7 @@
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string_name">Smackdown.Properties.Settings.tempdbConnectionString</property> <property name="connection.connection_string_name">Main</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
<property name="cache.use_minimal_puts">false</property> <property name="cache.use_minimal_puts">false</property>
<!--<property name="use_outer_join">false</property>--> <!--<property name="use_outer_join">false</property>-->
</session-factory> </session-factory>
......
...@@ -714,7 +714,7 @@ public IEnumerable<T> Query<T>(Sql sql) where T : new() ...@@ -714,7 +714,7 @@ public IEnumerable<T> Query<T>(Sql sql) where T : new()
public T Single<T>(string sql, params object[] args) where T : new() public T Single<T>(string sql, params object[] args) where T : new()
{ {
T val = SingleOrDefault<T>(sql, args); T val = SingleOrDefault<T>(sql, args);
if (val != null) if (!EqualityComparer<T>.Default.Equals(val, default(T)))
return val; return val;
else else
throw new InvalidOperationException("The sequence contains no elements"); throw new InvalidOperationException("The sequence contains no elements");
...@@ -722,7 +722,7 @@ public T Single<T>(string sql, params object[] args) where T : new() ...@@ -722,7 +722,7 @@ public T Single<T>(string sql, params object[] args) where T : new()
public T First<T>(string sql, params object[] args) where T : new() public T First<T>(string sql, params object[] args) where T : new()
{ {
T val = FirstOrDefault<T>(sql, args); T val = FirstOrDefault<T>(sql, args);
if (val != null) if (!EqualityComparer<T>.Default.Equals(val, default(T)))
return val; return val;
else else
throw new InvalidOperationException("The sequence contains no elements"); throw new InvalidOperationException("The sequence contains no elements");
......
using System;
using Soma.Core;
namespace Dapper.Tests.Performance
{
[ServiceStack.DataAnnotations.Alias("Posts")]
[Table(Name = "Posts")]
public class Post
{
[Id(IdKind.Identity)]
public int Id { get; set; }
public string Text { get; set; }
public DateTime CreationDate { get; set; }
public DateTime LastChangeDate { get; set; }
public int? Counter1 { get; set; }
public int? Counter2 { get; set; }
public int? Counter3 { get; set; }
public int? Counter4 { get; set; }
public int? Counter5 { get; set; }
public int? Counter6 { get; set; }
public int? Counter7 { get; set; }
public int? Counter8 { get; set; }
public int? Counter9 { get; set; }
}
}
using System; using System;
using System.Threading.Tasks;
namespace Dapper.Tests namespace Dapper.Tests.Performance
{ {
#if ORMLITE // Note: VSTest injects an entry point in .NET Core land...so we have to split this out into
[ServiceStack.DataAnnotations.Alias("Posts")] // a separate project...so here we are.
#endif // See https://github.com/Microsoft/vstest/issues/636 for details
#if SOMA public static class Program
[Soma.Core.Table(Name = "Posts")]
#endif
public class Post
{
#if SOMA
[Soma.Core.Id(Soma.Core.IdKind.Identity)]
#endif
public int Id { get; set; }
public string Text { get; set; }
public DateTime CreationDate { get; set; }
public DateTime LastChangeDate { get; set; }
public int? Counter1 { get; set; }
public int? Counter2 { get; set; }
public int? Counter3 { get; set; }
public int? Counter4 { get; set; }
public int? Counter5 { get; set; }
public int? Counter6 { get; set; }
public int? Counter7 { get; set; }
public int? Counter8 { get; set; }
public int? Counter9 { get; set; }
}
class Program
{ {
static void Main() public static void Main()
{ {
#if DEBUG #if DEBUG
var fg = Console.ForegroundColor; var fg = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Warning: DEBUG configuration; performance may be impacted"); Console.WriteLine("Warning: DEBUG configuration; performance may be impacted");
#if DNX
Console.WriteLine("use: dnx --configuration release perf");
#endif
Console.ForegroundColor = fg; Console.ForegroundColor = fg;
Console.WriteLine(); Console.WriteLine();
#endif #endif
Console.WriteLine("Using ConnectionString: " + PerformanceTests.ConnectionString);
EnsureDBSetup(); EnsureDBSetup();
RunPerformanceTests(); RunPerformanceTestsAsync().GetAwaiter().GetResult();
} }
private static void EnsureDBSetup() private static void EnsureDBSetup()
{ {
using (var cnn = TestSuite.GetOpenConnection()) using (var cnn = PerformanceTests.GetOpenConnection())
{ {
var cmd = cnn.CreateCommand(); var cmd = cnn.CreateCommand();
cmd.CommandText = @" cmd.CommandText = @"
...@@ -95,12 +72,12 @@ insert Posts ([Text],CreationDate, LastChangeDate) values (replicate('x', 2000), ...@@ -95,12 +72,12 @@ insert Posts ([Text],CreationDate, LastChangeDate) values (replicate('x', 2000),
} }
} }
static void RunPerformanceTests() private static async Task RunPerformanceTestsAsync()
{ {
var test = new PerformanceTests(); var test = new PerformanceTests();
const int iterations = 500; const int iterations = 500;
Console.WriteLine("Running {0} iterations that load up a post entity", iterations); Console.WriteLine("Running {0} iterations that load up a post entity", iterations);
test.Run(iterations); await test.RunAsync(iterations).ConfigureAwait(false);
} }
} }
} }
using Soma.Core;
using System;
namespace Dapper.Tests.Performance.Soma
{
internal class SomaConfig : MsSqlConfig
{
public override string ConnectionString => PerformanceTests.ConnectionString;
public override Action<PreparedStatement> Logger => noOp;
private static readonly Action<PreparedStatement> noOp = x => { };
}
}
using System;
using System.Data.SqlClient;
namespace Dapper.Tests.Performance
{
public static class SqlDataReaderHelper
{
public static string GetNullableString(this SqlDataReader reader, int index)
{
object tmp = reader.GetValue(index);
if (tmp != DBNull.Value)
{
return (string)tmp;
}
return null;
}
public static T? GetNullableValue<T>(this SqlDataReader reader, int index) where T : struct
{
object tmp = reader.GetValue(index);
if (tmp != DBNull.Value)
{
return (T)tmp;
}
return null;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="Main" connectionString="Data Source=.;Initial Catalog=tempdb;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
\ No newline at end of file
using Dapper; using System;
using System;
using System.Data; using System.Data;
using System.Linq; using System.Linq;
using Xunit; using Xunit;
namespace Dapper.Tests namespace Dapper.Tests
{ {
public partial class TestSuite public class ConstructorTests : TestBase
{ {
[Fact] [Fact]
public void TestAbstractInheritance() public void TestAbstractInheritance()
...@@ -35,7 +34,6 @@ public void TestConstructorsWithAccessModifiers() ...@@ -35,7 +34,6 @@ public void TestConstructorsWithAccessModifiers()
value.B.IsEqualTo("Dapper!"); value.B.IsEqualTo("Dapper!");
} }
[Fact] [Fact]
public void TestNoDefaultConstructor() public void TestNoDefaultConstructor()
{ {
...@@ -59,7 +57,6 @@ public void TestNoDefaultConstructorWithChar() ...@@ -59,7 +57,6 @@ public void TestNoDefaultConstructorWithChar()
nodef.Char3.IsEqualTo(c3); nodef.Char3.IsEqualTo(c3);
} }
[Fact] [Fact]
public void TestNoDefaultConstructorWithEnum() public void TestNoDefaultConstructorWithEnum()
{ {
...@@ -85,7 +82,8 @@ public void ExplicitConstructors() ...@@ -85,7 +82,8 @@ public void ExplicitConstructors()
rows[0].Field_1.IsEqualTo(1); rows[0].Field_1.IsEqualTo(1);
rows[0].GetWentThroughProperConstructor().IsTrue(); rows[0].GetWentThroughProperConstructor().IsTrue();
} }
class _ExplicitConstructors
private class _ExplicitConstructors
{ {
public int Field { get; set; } public int Field { get; set; }
public int Field_1 { get; set; } public int Field_1 { get; set; }
...@@ -105,9 +103,9 @@ public bool GetWentThroughProperConstructor() ...@@ -105,9 +103,9 @@ public bool GetWentThroughProperConstructor()
return WentThroughProperConstructor; return WentThroughProperConstructor;
} }
} }
#if LINQ2SQL #if LINQ2SQL
class NoDefaultConstructorWithBinary private class NoDefaultConstructorWithBinary
{ {
public System.Data.Linq.Binary Value { get; set; } public System.Data.Linq.Binary Value { get; set; }
public int Ynt { get; set; } public int Ynt { get; set; }
...@@ -116,6 +114,7 @@ public NoDefaultConstructorWithBinary(System.Data.Linq.Binary val) ...@@ -116,6 +114,7 @@ public NoDefaultConstructorWithBinary(System.Data.Linq.Binary val)
Value = val; Value = val;
} }
} }
[Fact] [Fact]
public void TestNoDefaultConstructorBinary() public void TestNoDefaultConstructorBinary()
{ {
...@@ -154,13 +153,13 @@ public void Issue461_TypeHandlerWorksInConstructor() ...@@ -154,13 +153,13 @@ public void Issue461_TypeHandlerWorksInConstructor()
parameterDoesNot.Id.IsEqualTo(1); parameterDoesNot.Id.IsEqualTo(1);
parameterDoesNot.SomeValue.IsEqualTo("what up?"); parameterDoesNot.SomeValue.IsEqualTo("what up?");
parameterDoesNot.SomeBlargValue.Value.IsEqualTo(Expected); parameterDoesNot.SomeBlargValue.Value.IsEqualTo(Expected);
} }
class Blarg // I would usually expect this to be a struct; using a class // I would usually expect this to be a struct; using a class
{ // so that we can't pass unexpectedly due to forcing an unsafe cast - want // so that we can't pass unexpectedly due to forcing an unsafe cast - want
// to see an InvalidCastException if it is wrong // to see an InvalidCastException if it is wrong
private class Blarg
{
public Blarg(string value) { Value = value; } public Blarg(string value) { Value = value; }
public string Value { get; } public string Value { get; }
public override string ToString() public override string ToString()
...@@ -168,7 +167,8 @@ public override string ToString() ...@@ -168,7 +167,8 @@ public override string ToString()
return Value; return Value;
} }
} }
class Issue461_BlargHandler : SqlMapper.TypeHandler<Blarg>
private class Issue461_BlargHandler : SqlMapper.TypeHandler<Blarg>
{ {
public override void SetValue(IDbDataParameter parameter, Blarg value) public override void SetValue(IDbDataParameter parameter, Blarg value)
{ {
...@@ -182,7 +182,7 @@ public override Blarg Parse(object value) ...@@ -182,7 +182,7 @@ public override Blarg Parse(object value)
} }
} }
class Issue461_ParameterlessTypeConstructor private class Issue461_ParameterlessTypeConstructor
{ {
public int Id { get; set; } public int Id { get; set; }
...@@ -190,7 +190,7 @@ class Issue461_ParameterlessTypeConstructor ...@@ -190,7 +190,7 @@ class Issue461_ParameterlessTypeConstructor
public Blarg SomeBlargValue { get; set; } public Blarg SomeBlargValue { get; set; }
} }
class Issue461_ParameterisedTypeConstructor private class Issue461_ParameterisedTypeConstructor
{ {
public Issue461_ParameterisedTypeConstructor(int id, string someValue, Blarg someBlargValue) public Issue461_ParameterisedTypeConstructor(int id, string someValue, Blarg someBlargValue)
{ {
...@@ -205,7 +205,7 @@ public Issue461_ParameterisedTypeConstructor(int id, string someValue, Blarg som ...@@ -205,7 +205,7 @@ public Issue461_ParameterisedTypeConstructor(int id, string someValue, Blarg som
public Blarg SomeBlargValue { get; } public Blarg SomeBlargValue { get; }
} }
public class AbstractInheritance public static class AbstractInheritance
{ {
public abstract class Order public abstract class Order
{ {
...@@ -222,36 +222,39 @@ public class ConcreteOrder : Order ...@@ -222,36 +222,39 @@ public class ConcreteOrder : Order
} }
} }
class MultipleConstructors private class MultipleConstructors
{ {
public MultipleConstructors() public MultipleConstructors()
{ {
} }
public MultipleConstructors(int a, string b) public MultipleConstructors(int a, string b)
{ {
A = a + 1; A = a + 1;
B = b + "!"; B = b + "!";
} }
public int A { get; set; } public int A { get; set; }
public string B { get; set; } public string B { get; set; }
} }
class ConstructorsWithAccessModifiers private class ConstructorsWithAccessModifiers
{ {
private ConstructorsWithAccessModifiers() private ConstructorsWithAccessModifiers()
{ {
} }
public ConstructorsWithAccessModifiers(int a, string b) public ConstructorsWithAccessModifiers(int a, string b)
{ {
A = a + 1; A = a + 1;
B = b + "!"; B = b + "!";
} }
public int A { get; set; } public int A { get; set; }
public string B { get; set; } public string B { get; set; }
} }
class NoDefaultConstructor private class NoDefaultConstructor
{ {
public NoDefaultConstructor(int a1, int? b1, float f1, string s1, Guid G1) public NoDefaultConstructor(int a1, int? b1, float f1, string s1, Guid G1)
{ {
...@@ -261,6 +264,7 @@ public NoDefaultConstructor(int a1, int? b1, float f1, string s1, Guid G1) ...@@ -261,6 +264,7 @@ public NoDefaultConstructor(int a1, int? b1, float f1, string s1, Guid G1)
S = s1; S = s1;
G = G1; G = G1;
} }
public int A { get; set; } public int A { get; set; }
public int? B { get; set; } public int? B { get; set; }
public float F { get; set; } public float F { get; set; }
...@@ -268,7 +272,7 @@ public NoDefaultConstructor(int a1, int? b1, float f1, string s1, Guid G1) ...@@ -268,7 +272,7 @@ public NoDefaultConstructor(int a1, int? b1, float f1, string s1, Guid G1)
public Guid G { get; set; } public Guid G { get; set; }
} }
class NoDefaultConstructorWithChar private class NoDefaultConstructorWithChar
{ {
public NoDefaultConstructorWithChar(char c1, char? c2, char? c3) public NoDefaultConstructorWithChar(char c1, char? c2, char? c3)
{ {
...@@ -276,12 +280,13 @@ public NoDefaultConstructorWithChar(char c1, char? c2, char? c3) ...@@ -276,12 +280,13 @@ public NoDefaultConstructorWithChar(char c1, char? c2, char? c3)
Char2 = c2; Char2 = c2;
Char3 = c3; Char3 = c3;
} }
public char Char1 { get; set; } public char Char1 { get; set; }
public char? Char2 { get; set; } public char? Char2 { get; set; }
public char? Char3 { get; set; } public char? Char3 { get; set; }
} }
class NoDefaultConstructorWithEnum private class NoDefaultConstructorWithEnum
{ {
public NoDefaultConstructorWithEnum(ShortEnum e1, ShortEnum? n1, ShortEnum? n2) public NoDefaultConstructorWithEnum(ShortEnum e1, ShortEnum? n1, ShortEnum? n2)
{ {
...@@ -289,9 +294,25 @@ public NoDefaultConstructorWithEnum(ShortEnum e1, ShortEnum? n1, ShortEnum? n2) ...@@ -289,9 +294,25 @@ public NoDefaultConstructorWithEnum(ShortEnum e1, ShortEnum? n1, ShortEnum? n2)
NE1 = n1; NE1 = n1;
NE2 = n2; NE2 = n2;
} }
public ShortEnum E { get; set; } public ShortEnum E { get; set; }
public ShortEnum? NE1 { get; set; } public ShortEnum? NE1 { get; set; }
public ShortEnum? NE2 { get; set; } public ShortEnum? NE2 { get; set; }
} }
private class WithPrivateConstructor
{
public int Foo { get; set; }
private WithPrivateConstructor()
{
}
}
[Fact]
public void TestWithNonPublicConstructor()
{
var output = connection.Query<WithPrivateConstructor>("select 1 as Foo").First();
output.Foo.IsEqualTo(1);
}
} }
} }
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Dapper.Tests</AssemblyName>
<Title>Dapper.Tests</Title>
<Description>Dapper Core Test Suite</Description>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<TargetFrameworks>net452;netcoreapp1.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net452' ">
<DefineConstants>$(DefineConstants);NET45;MYSQL;ENTITY_FRAMEWORK;LINQ2SQL;FIREBIRD;SQL_CE;POSTGRESQL;OLEDB;SQLITE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<DefineConstants>$(DefineConstants);COREFX</DefineConstants>
</PropertyGroup>
<ItemGroup>
<None Remove="Test.DB.sdf" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
<ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="xunit.runner.console" Version="2.2.0" />
<PackageReference Include="xunit" Version="2.2.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<ProjectReference Include="..\Dapper.EntityFramework\Dapper.EntityFramework.csproj" />
<PackageReference Include="EntityFramework" Version="6.1.3" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="5.8.0" />
<PackageReference Include="Microsoft.SqlServer.Compact" Version="4.0.8876.1" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.314.76" />
<PackageReference Include="MySql.Data" Version="7.0.7-m61" />
<PackageReference Include="Npgsql" Version="3.2.2" />
<PackageReference Include="System.Data.SQLite" Version="1.0.104" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<PackageReference Include="System.Ben" Version="1.0.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>052c0817-db26-4925-8929-8c5e42d148d5</ProjectGuid>
<RootNamespace>Dapper.Tests</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
\ No newline at end of file
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using Xunit; using Xunit;
namespace Dapper.Tests namespace Dapper.Tests
{ {
public partial class TestSuite public partial class DataReaderTests : TestBase
{ {
[Fact] [Fact]
public void GetSameReaderForSameShape() public void GetSameReaderForSameShape()
...@@ -82,7 +80,7 @@ union all ...@@ -82,7 +80,7 @@ union all
[Fact] [Fact]
public void DiscriminatedUnionWithMultiMapping() public void DiscriminatedUnionWithMultiMapping()
{ {
List<DiscriminatedWithMultiMapping_BaseType> result = new List<DiscriminatedWithMultiMapping_BaseType>(); var result = new List<DiscriminatedWithMultiMapping_BaseType>();
using (var reader = connection.ExecuteReader(@" using (var reader = connection.ExecuteReader(@"
select 'abc' as Name, 1 as Type, 3.0 as Value, 1 as Id, 'zxc' as Name select 'abc' as Name, 1 as Type, 3.0 as Value, 1 as Id, 'zxc' as Name
union all union all
...@@ -131,18 +129,20 @@ union all ...@@ -131,18 +129,20 @@ union all
bar.HazNameIdObject.Name.IsEqualTo("qwe"); bar.HazNameIdObject.Name.IsEqualTo("qwe");
} }
abstract class Discriminated_BaseType private abstract class Discriminated_BaseType
{ {
public abstract int Type { get; } public abstract int Type { get; }
} }
class Discriminated_Foo : Discriminated_BaseType
private class Discriminated_Foo : Discriminated_BaseType
{ {
public string Name { get; set; } public string Name { get; set; }
public override int Type { public override int Type {
get { return 1; } get { return 1; }
} }
} }
class Discriminated_Bar : Discriminated_BaseType
private class Discriminated_Bar : Discriminated_BaseType
{ {
public float Value { get; set; } public float Value { get; set; }
public override int Type public override int Type
...@@ -151,12 +151,12 @@ public override int Type ...@@ -151,12 +151,12 @@ public override int Type
} }
} }
private abstract class DiscriminatedWithMultiMapping_BaseType : Discriminated_BaseType
abstract class DiscriminatedWithMultiMapping_BaseType : Discriminated_BaseType
{ {
public abstract HazNameId HazNameIdObject { get; set; } public abstract HazNameId HazNameIdObject { get; set; }
} }
class DiscriminatedWithMultiMapping_Foo : DiscriminatedWithMultiMapping_BaseType
private class DiscriminatedWithMultiMapping_Foo : DiscriminatedWithMultiMapping_BaseType
{ {
public override HazNameId HazNameIdObject { get; set; } public override HazNameId HazNameIdObject { get; set; }
public string Name { get; set; } public string Name { get; set; }
...@@ -165,7 +165,8 @@ public override int Type ...@@ -165,7 +165,8 @@ public override int Type
get { return 1; } get { return 1; }
} }
} }
class DiscriminatedWithMultiMapping_Bar : DiscriminatedWithMultiMapping_BaseType
private class DiscriminatedWithMultiMapping_Bar : DiscriminatedWithMultiMapping_BaseType
{ {
public override HazNameId HazNameIdObject { get; set; } public override HazNameId HazNameIdObject { get; set; }
public float Value { get; set; } public float Value { get; set; }
...@@ -173,12 +174,6 @@ public override int Type ...@@ -173,12 +174,6 @@ public override int Type
{ {
get { return 2; } get { return 2; }
} }
}
public class HazNameId
{
public string Name { get; set; }
public int Id { get; set; }
} }
} }
} }
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace Dapper.Tests
{
public class DecimalTests : TestBase
{
[Fact]
public void Issue261_Decimals()
{
var parameters = new DynamicParameters();
parameters.Add("c", dbType: DbType.Decimal, direction: ParameterDirection.Output, precision: 10, scale: 5);
connection.Execute("create proc #Issue261 @c decimal(10,5) OUTPUT as begin set @c=11.884 end");
connection.Execute("#Issue261", parameters, commandType: CommandType.StoredProcedure);
var c = parameters.Get<Decimal>("c");
c.IsEqualTo(11.884M);
}
[Fact]
public void Issue261_Decimals_ADONET_SetViaBaseClass() => Issue261_Decimals_ADONET(true);
[Fact]
public void Issue261_Decimals_ADONET_SetViaConcreteClass() => Issue261_Decimals_ADONET(false);
private void Issue261_Decimals_ADONET(bool setPrecisionScaleViaAbstractApi)
{
try
{
using (var cmd = connection.CreateCommand())
{
cmd.CommandText = "create proc #Issue261Direct @c decimal(10,5) OUTPUT as begin set @c=11.884 end";
cmd.ExecuteNonQuery();
}
}
catch { /* we don't care that it already exists */ }
using (var cmd = connection.CreateCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "#Issue261Direct";
var c = cmd.CreateParameter();
c.ParameterName = "c";
c.Direction = ParameterDirection.Output;
c.Value = DBNull.Value;
c.DbType = DbType.Decimal;
if (setPrecisionScaleViaAbstractApi)
{
IDbDataParameter baseParam = c;
baseParam.Precision = 10;
baseParam.Scale = 5;
}
else
{
c.Precision = 10;
c.Scale = 5;
}
cmd.Parameters.Add(c);
cmd.ExecuteNonQuery();
decimal value = (decimal)c.Value;
value.IsEqualTo(11.884M);
}
}
[Fact]
public void BasicDecimals()
{
var c = connection.Query<decimal>("select @c", new { c = 11.884M }).Single();
c.IsEqualTo(11.884M);
}
[Fact]
public void TestDoubleDecimalConversions_SO18228523_RightWay()
{
var row = connection.Query<HasDoubleDecimal>(
"select cast(1 as float) as A, cast(2 as float) as B, cast(3 as decimal) as C, cast(4 as decimal) as D").Single();
row.A.Equals(1.0);
row.B.Equals(2.0);
row.C.Equals(3.0M);
row.D.Equals(4.0M);
}
[Fact]
public void TestDoubleDecimalConversions_SO18228523_WrongWay()
{
var row = connection.Query<HasDoubleDecimal>(
"select cast(1 as decimal) as A, cast(2 as decimal) as B, cast(3 as float) as C, cast(4 as float) as D").Single();
row.A.Equals(1.0);
row.B.Equals(2.0);
row.C.Equals(3.0M);
row.D.Equals(4.0M);
}
[Fact]
public void TestDoubleDecimalConversions_SO18228523_Nulls()
{
var row = connection.Query<HasDoubleDecimal>(
"select cast(null as decimal) as A, cast(null as decimal) as B, cast(null as float) as C, cast(null as float) as D").Single();
row.A.Equals(0.0);
row.B.IsNull();
row.C.Equals(0.0M);
row.D.IsNull();
}
private class HasDoubleDecimal
{
public double A { get; set; }
public double? B { get; set; }
public decimal C { get; set; }
public decimal? D { get; set; }
}
}
}
using Dapper; using System.Data;
using System;
using System.Data;
using System.Linq; using System.Linq;
using Xunit; using Xunit;
namespace Dapper.Tests namespace Dapper.Tests
{ {
public partial class TestSuite public class EnumTests : TestBase
{ {
[Fact] [Fact]
public void TestEnumWeirdness() public void TestEnumWeirdness()
...@@ -48,37 +46,84 @@ public void TestEnumParamsWithoutNullable() ...@@ -48,37 +46,84 @@ public void TestEnumParamsWithoutNullable()
obj.B.IsEqualTo(EnumParam.B); obj.B.IsEqualTo(EnumParam.B);
obj.C.IsEqualTo((EnumParam)0); obj.C.IsEqualTo((EnumParam)0);
} }
enum EnumParam : short
private enum EnumParam : short
{ {
None, A, B None = 0,
A = 1,
B = 2
} }
class EnumParamObject
private class EnumParamObject
{ {
public EnumParam A { get; set; } public EnumParam A { get; set; }
public EnumParam? B { get; set; } public EnumParam? B { get; set; }
public EnumParam? C { get; set; } public EnumParam? C { get; set; }
} }
class EnumParamObjectNonNullable
private class EnumParamObjectNonNullable
{ {
public EnumParam A { get; set; } public EnumParam A { get; set; }
public EnumParam? B { get; set; } public EnumParam? B { get; set; }
public EnumParam? C { get; set; } public EnumParam? C { get; set; }
} }
private enum TestEnum : byte
enum TestEnum : byte
{ {
Bla = 1 Bla = 1
} }
class TestEnumClass
private class TestEnumClass
{ {
public TestEnum? EnumEnum { get; set; } public TestEnum? EnumEnum { get; set; }
} }
class TestEnumClassNoNull
private class TestEnumClassNoNull
{ {
public TestEnum EnumEnum { get; set; } public TestEnum EnumEnum { get; set; }
} }
[Fact]
public void AdoNetEnumValue()
{
using (var cmd = connection.CreateCommand())
{
cmd.CommandText = "select @foo";
var p = cmd.CreateParameter();
p.ParameterName = "@foo";
p.DbType = DbType.Int32; // it turns out that this is the key piece; setting the DbType
p.Value = AnEnum.B;
cmd.Parameters.Add(p);
object value = cmd.ExecuteScalar();
AnEnum val = (AnEnum)value;
val.IsEqualTo(AnEnum.B);
}
}
[Fact]
public void DapperEnumValue_SqlServer() => Common.DapperEnumValue(connection);
private enum SO27024806Enum
{
Foo = 0,
Bar = 1
}
private class SO27024806Class
{
public SO27024806Class(SO27024806Enum myField)
{
MyField = myField;
}
public SO27024806Enum MyField { get; set; }
}
[Fact]
public void SO27024806_TestVarcharEnumMemberWithExplicitConstructor()
{
var foo = connection.Query<SO27024806Class>("SELECT 'Foo' AS myField").Single();
foo.MyField.IsEqualTo(SO27024806Enum.Foo);
}
} }
} }
...@@ -13,11 +13,12 @@ public static void IsSequenceEqualTo<T>(this IEnumerable<T> actual, IEnumerable< ...@@ -13,11 +13,12 @@ public static void IsSequenceEqualTo<T>(this IEnumerable<T> actual, IEnumerable<
{ {
Xunit.Assert.Equal(expected, actual ?? new T[0]); Xunit.Assert.Equal(expected, actual ?? new T[0]);
} }
public static void IsMoreThan(this int a, int b) public static void IsMoreThan(this int a, int b)
{ {
Xunit.Assert.True(a > b, $"{a} should be larger than {b}"); Xunit.Assert.True(a > b, $"{a} should be larger than {b}");
} }
public static void IsMoreThan(this long a, int b) public static void IsMoreThan(this long a, int b)
{ {
Xunit.Assert.True(a > b, $"{a} should be larger than {b}"); Xunit.Assert.True(a > b, $"{a} should be larger than {b}");
...@@ -27,6 +28,7 @@ public static void Fail(string message = null) ...@@ -27,6 +28,7 @@ public static void Fail(string message = null)
{ {
Xunit.Assert.True(false, message ?? "Expectation failed"); Xunit.Assert.True(false, message ?? "Expectation failed");
} }
public static void IsFalse(this bool b) public static void IsFalse(this bool b)
{ {
Xunit.Assert.False(b); Xunit.Assert.False(b);
......
...@@ -14,6 +14,7 @@ public FactUnlessCoreCLRAttribute(string url) ...@@ -14,6 +14,7 @@ public FactUnlessCoreCLRAttribute(string url)
#endif #endif
this.Url = url; this.Url = url;
} }
public string Url { get; private set; } public string Url { get; private set; }
} }
...@@ -26,8 +27,10 @@ public FactLongRunningAttribute() ...@@ -26,8 +27,10 @@ public FactLongRunningAttribute()
Skip = "Long running"; Skip = "Long running";
#endif #endif
} }
public string Url { get; private set; } public string Url { get; private set; }
} }
public class FactRequiredCompatibilityLevelAttribute : FactAttribute public class FactRequiredCompatibilityLevelAttribute : FactAttribute
{ {
public FactRequiredCompatibilityLevelAttribute(int level) : base() public FactRequiredCompatibilityLevelAttribute(int level) : base()
...@@ -37,21 +40,23 @@ public FactRequiredCompatibilityLevelAttribute(int level) : base() ...@@ -37,21 +40,23 @@ public FactRequiredCompatibilityLevelAttribute(int level) : base()
Skip = $"Compatibility level {level} required; detected {DetectedLevel}"; Skip = $"Compatibility level {level} required; detected {DetectedLevel}";
} }
} }
public const int SqlServer2016 = 130; public const int SqlServer2016 = 130;
public static readonly int DetectedLevel; public static readonly int DetectedLevel;
static FactRequiredCompatibilityLevelAttribute() static FactRequiredCompatibilityLevelAttribute()
{ {
using (var conn = TestSuite.GetOpenConnection()) using (var conn = TestBase.GetOpenConnection())
{ {
try try
{ {
DetectedLevel = conn.QuerySingle<int>("SELECT compatibility_level FROM sys.databases where name = DB_NAME()"); DetectedLevel = conn.QuerySingle<int>("SELECT compatibility_level FROM sys.databases where name = DB_NAME()");
} }
catch { } catch { /* don't care */ }
} }
} }
} }
public class FactUnlessCaseSensitiveDatabaseAttribute : FactAttribute
public class FactUnlessCaseSensitiveDatabaseAttribute : FactAttribute
{ {
public FactUnlessCaseSensitiveDatabaseAttribute() : base() public FactUnlessCaseSensitiveDatabaseAttribute() : base()
{ {
...@@ -64,7 +69,7 @@ public FactUnlessCaseSensitiveDatabaseAttribute() : base() ...@@ -64,7 +69,7 @@ public FactUnlessCaseSensitiveDatabaseAttribute() : base()
public static readonly bool IsCaseSensitive; public static readonly bool IsCaseSensitive;
static FactUnlessCaseSensitiveDatabaseAttribute() static FactUnlessCaseSensitiveDatabaseAttribute()
{ {
using (var conn = TestSuite.GetOpenConnection()) using (var conn = TestBase.GetOpenConnection())
{ {
try try
{ {
......
using System;
using System.Data;
using System.Data.Common;
namespace Dapper.Tests
{
public static class Common
{
public static Type GetSomeType() => typeof(SomeType);
public static void DapperEnumValue(IDbConnection connection)
{
// test passing as AsEnum, reading as int
var v = (AnEnum)connection.QuerySingle<int>("select @v, @y, @z", new { v = AnEnum.B, y = (AnEnum?)AnEnum.B, z = (AnEnum?)null });
v.IsEqualTo(AnEnum.B);
var args = new DynamicParameters();
args.Add("v", AnEnum.B);
args.Add("y", AnEnum.B);
args.Add("z", null);
v = (AnEnum)connection.QuerySingle<int>("select @v, @y, @z", args);
v.IsEqualTo(AnEnum.B);
// test passing as int, reading as AnEnum
var k = (int)connection.QuerySingle<AnEnum>("select @v, @y, @z", new { v = (int)AnEnum.B, y = (int?)(int)AnEnum.B, z = (int?)null });
k.IsEqualTo((int)AnEnum.B);
args = new DynamicParameters();
args.Add("v", (int)AnEnum.B);
args.Add("y", (int)AnEnum.B);
args.Add("z", null);
k = (int)connection.QuerySingle<AnEnum>("select @v, @y, @z", args);
k.IsEqualTo((int)AnEnum.B);
}
public static void TestDateTime(DbConnection connection)
{
DateTime? now = DateTime.UtcNow;
try { connection.Execute("DROP TABLE Persons"); } catch { /* don't care */ }
connection.Execute(@"CREATE TABLE Persons (id int not null, dob datetime null)");
connection.Execute(@"INSERT Persons (id, dob) values (@id, @dob)",
new { id = 7, dob = (DateTime?)null });
connection.Execute(@"INSERT Persons (id, dob) values (@id, @dob)",
new { id = 42, dob = now });
var row = connection.QueryFirstOrDefault<NullableDatePerson>(
"SELECT id, dob, dob as dob2 FROM Persons WHERE id=@id", new { id = 7 });
row.IsNotNull();
row.Id.IsEqualTo(7);
row.DoB.IsNull();
row.DoB2.IsNull();
row = connection.QueryFirstOrDefault<NullableDatePerson>(
"SELECT id, dob FROM Persons WHERE id=@id", new { id = 42 });
row.IsNotNull();
row.Id.IsEqualTo(42);
row.DoB.Equals(now);
row.DoB2.Equals(now);
}
private class NullableDatePerson
{
public int Id { get; set; }
public DateTime? DoB { get; set; }
public DateTime? DoB2 { get; set; }
}
}
}
...@@ -2,15 +2,15 @@ ...@@ -2,15 +2,15 @@
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace SqlServerTypes namespace Dapper.Tests
{ {
/// <summary> /// <summary>
/// Utility methods related to CLR Types for SQL Server /// Utility methods related to CLR Types for SQL Server
/// </summary> /// </summary>
internal class Utilities internal static class SqlServerTypesLoader
{ {
private static object _nativeLoadLock = new object(); private static readonly object _nativeLoadLock = new object();
private static bool _nativeAssembliesLoaded = false; private static bool _nativeAssembliesLoaded;
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern IntPtr LoadLibrary(string libname); private static extern IntPtr LoadLibrary(string libname);
...@@ -54,4 +54,4 @@ private static void LoadNativeAssembly(string nativeBinaryPath, string assemblyN ...@@ -54,4 +54,4 @@ private static void LoadNativeAssembly(string nativeBinaryPath, string assemblyN
} }
} }
} }
} }
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dapper.Tests
{
public class TransactedConnection : IDbConnection
{
private readonly IDbConnection _conn;
private readonly IDbTransaction _tran;
public TransactedConnection(IDbConnection conn, IDbTransaction tran)
{
_conn = conn;
_tran = tran;
}
public string ConnectionString
{
get { return _conn.ConnectionString; }
set { _conn.ConnectionString = value; }
}
public int ConnectionTimeout => _conn.ConnectionTimeout;
public string Database => _conn.Database;
public ConnectionState State => _conn.State;
public IDbTransaction BeginTransaction(IsolationLevel il)
{
throw new NotImplementedException();
}
public IDbTransaction BeginTransaction() => _tran;
public void ChangeDatabase(string databaseName) => _conn.ChangeDatabase(databaseName);
public void Close() => _conn.Close();
public IDbCommand CreateCommand()
{
// The command inherits the "current" transaction.
var command = _conn.CreateCommand();
command.Transaction = _tran;
return command;
}
public void Dispose() => _conn.Dispose();
public void Open() => _conn.Open();
}
}
using System; using System;
#if XUNIT2 // Not in .Net 4.0 (xUnit v1)...
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Xunit.Abstractions; using Xunit.Abstractions;
using Xunit.Sdk; using Xunit.Sdk;
#endif
namespace Dapper.Tests namespace Dapper.Tests
{ {
public class SkipTestException : Exception public class SkipTestException : Exception
{ {
public SkipTestException(string reason) : base(reason) { } public SkipTestException(string reason) : base(reason)
{
}
} }
#if XUNIT2
// Most of the below is a direct copy & port from the wonderful examples by Brad Wilson at // Most of the below is a direct copy & port from the wonderful examples by Brad Wilson at
// https://github.com/xunit/samples.xunit/tree/master/DynamicSkipExample // https://github.com/xunit/samples.xunit/tree/master/DynamicSkipExample
public class SkippableFactDiscoverer : IXunitTestCaseDiscoverer public class SkippableFactDiscoverer : IXunitTestCaseDiscoverer
{ {
readonly IMessageSink _diagnosticMessageSink; private readonly IMessageSink _diagnosticMessageSink;
public SkippableFactDiscoverer(IMessageSink diagnosticMessageSink) public SkippableFactDiscoverer(IMessageSink diagnosticMessageSink)
{ {
...@@ -33,15 +32,18 @@ public IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions disco ...@@ -33,15 +32,18 @@ public IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions disco
yield return new SkippableFactTestCase(_diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod); yield return new SkippableFactTestCase(_diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod);
} }
} }
public class SkippableFactTestCase : XunitTestCase public class SkippableFactTestCase : XunitTestCase
{ {
[Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")] [Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")]
public SkippableFactTestCase() { } public SkippableFactTestCase()
{
}
public SkippableFactTestCase(IMessageSink diagnosticMessageSink, TestMethodDisplay defaultMethodDisplay, ITestMethod testMethod, object[] testMethodArguments = null) public SkippableFactTestCase(IMessageSink diagnosticMessageSink, TestMethodDisplay defaultMethodDisplay, ITestMethod testMethod, object[] testMethodArguments = null)
: base(diagnosticMessageSink, defaultMethodDisplay, testMethod, testMethodArguments) : base(diagnosticMessageSink, defaultMethodDisplay, testMethod, testMethodArguments)
{ } {
}
public override async Task<RunSummary> RunAsync( public override async Task<RunSummary> RunAsync(
IMessageSink diagnosticMessageSink, IMessageSink diagnosticMessageSink,
...@@ -56,7 +58,7 @@ public SkippableFactTestCase(IMessageSink diagnosticMessageSink, TestMethodDispl ...@@ -56,7 +58,7 @@ public SkippableFactTestCase(IMessageSink diagnosticMessageSink, TestMethodDispl
skipMessageBus, skipMessageBus,
constructorArguments, constructorArguments,
aggregator, aggregator,
cancellationTokenSource); cancellationTokenSource).ConfigureAwait(false);
if (skipMessageBus.DynamicallySkippedTestCount > 0) if (skipMessageBus.DynamicallySkippedTestCount > 0)
{ {
result.Failed -= skipMessageBus.DynamicallySkippedTestCount; result.Failed -= skipMessageBus.DynamicallySkippedTestCount;
...@@ -69,7 +71,7 @@ public SkippableFactTestCase(IMessageSink diagnosticMessageSink, TestMethodDispl ...@@ -69,7 +71,7 @@ public SkippableFactTestCase(IMessageSink diagnosticMessageSink, TestMethodDispl
public class SkippableFactMessageBus : IMessageBus public class SkippableFactMessageBus : IMessageBus
{ {
readonly IMessageBus _innerBus; private readonly IMessageBus _innerBus;
public SkippableFactMessageBus(IMessageBus innerBus) public SkippableFactMessageBus(IMessageBus innerBus)
{ {
_innerBus = innerBus; _innerBus = innerBus;
...@@ -77,7 +79,9 @@ public SkippableFactMessageBus(IMessageBus innerBus) ...@@ -77,7 +79,9 @@ public SkippableFactMessageBus(IMessageBus innerBus)
public int DynamicallySkippedTestCount { get; private set; } public int DynamicallySkippedTestCount { get; private set; }
public void Dispose() { } public void Dispose()
{
}
public bool QueueMessage(IMessageSinkMessage message) public bool QueueMessage(IMessageSinkMessage message)
{ {
...@@ -94,5 +98,4 @@ public bool QueueMessage(IMessageSinkMessage message) ...@@ -94,5 +98,4 @@ public bool QueueMessage(IMessageSinkMessage message)
return _innerBus.QueueMessage(message); return _innerBus.QueueMessage(message);
} }
} }
#endif
} }
Copyright (c) 2010 Stack Overflow Internet Services, Inc
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
namespace Dapper.Tests.Linq2Sql
{
public partial class Post
{
/*
public int Bloat { get; set; }
public int Bloat1 { get; set; }
public int Bloat2 { get; set; }
public int Bloat3 { get; set; }
public int Bloat4 { get; set; }
public int Bloat5 { get; set; }
public int Bloat6 { get; set; }
public int Bloat7 { get; set; }
public int Bloat8 { get; set; }
public int Bloat10 { get; set; }
public int Bloat11 { get; set; }
public int Bloat12 { get; set; }
public int Bloat13 { get; set; }
public int Bloat14 { get; set; }
public int Bloat15 { get; set; }
public int Bloat16 { get; set; }
public int Bloat17 { get; set; }
public int Bloat18 { get; set; }
*/
}
}
using System.Linq;
using Xunit;
namespace Dapper.Tests
{
public class LiteralTests : TestBase
{
[Fact]
public void LiteralReplacementEnumAndString()
{
var args = new { x = AnEnum.B, y = 123.45M, z = AnotherEnum.A };
var row = connection.Query("select {=x} as x,{=y} as y,cast({=z} as tinyint) as z", args).Single();
AnEnum x = (AnEnum)(int)row.x;
decimal y = row.y;
AnotherEnum z = (AnotherEnum)(byte)row.z;
x.Equals(AnEnum.B);
y.Equals(123.45M);
z.Equals(AnotherEnum.A);
}
[Fact]
public void LiteralReplacementDynamicEnumAndString()
{
var args = new DynamicParameters();
args.Add("x", AnEnum.B);
args.Add("y", 123.45M);
args.Add("z", AnotherEnum.A);
var row = connection.Query("select {=x} as x,{=y} as y,cast({=z} as tinyint) as z", args).Single();
AnEnum x = (AnEnum)(int)row.x;
decimal y = row.y;
AnotherEnum z = (AnotherEnum)(byte)row.z;
x.Equals(AnEnum.B);
y.Equals(123.45M);
z.Equals(AnotherEnum.A);
}
[Fact]
public void LiteralReplacementBoolean()
{
var row = connection.Query<int?>("select 42 where 1 = {=val}", new { val = true }).SingleOrDefault();
row.IsNotNull();
row.IsEqualTo(42);
row = connection.Query<int?>("select 42 where 1 = {=val}", new { val = false }).SingleOrDefault();
row.IsNull();
}
[Fact]
public void LiteralReplacementWithIn()
{
var data = connection.Query<MyRow>("select @x where 1 in @ids and 1 ={=a}",
new { x = 1, ids = new[] { 1, 2, 3 }, a = 1 }).ToList();
}
private class MyRow
{
public int x { get; set; }
}
[Fact]
public void LiteralIn()
{
connection.Execute("create table #literalin(id int not null);");
connection.Execute("insert #literalin (id) values (@id)", new[] {
new { id = 1 },
new { id = 2 },
new { id = 3 },
});
var count = connection.Query<int>("select count(1) from #literalin where id in {=ids}",
new { ids = new[] { 1, 3, 4 } }).Single();
count.IsEqualTo(2);
}
[Fact]
public void LiteralReplacement()
{
connection.Execute("create table #literal1 (id int not null, foo int not null)");
connection.Execute("insert #literal1 (id,foo) values ({=id}, @foo)", new { id = 123, foo = 456 });
var rows = new[] { new { id = 1, foo = 2 }, new { id = 3, foo = 4 } };
connection.Execute("insert #literal1 (id,foo) values ({=id}, @foo)", rows);
var count = connection.Query<int>("select count(1) from #literal1 where id={=foo}", new { foo = 123 }).Single();
count.IsEqualTo(1);
int sum = connection.Query<int>("select sum(id) + sum(foo) from #literal1").Single();
sum.IsEqualTo(123 + 456 + 1 + 2 + 3 + 4);
}
[Fact]
public void LiteralReplacementDynamic()
{
var args = new DynamicParameters();
args.Add("id", 123);
connection.Execute("create table #literal2 (id int not null)");
connection.Execute("insert #literal2 (id) values ({=id})", args);
args = new DynamicParameters();
args.Add("foo", 123);
var count = connection.Query<int>("select count(1) from #literal2 where id={=foo}", args).Single();
count.IsEqualTo(1);
}
}
}
This diff is collapsed.
...@@ -2,18 +2,20 @@ ...@@ -2,18 +2,20 @@
using System.Linq; using System.Linq;
namespace Dapper.Tests namespace Dapper.Tests
{ {
public partial class TestSuite public class NullTests : TestBase
{ {
[Fact] [Fact]
public void TestNullableDefault() public void TestNullableDefault()
{ {
TestNullable(false); TestNullable(false);
} }
[Fact] [Fact]
public void TestNullableApplyNulls() public void TestNullableApplyNulls()
{ {
TestNullable(true); TestNullable(true);
} }
private void TestNullable(bool applyNulls) private void TestNullable(bool applyNulls)
{ {
bool oldSetting = SqlMapper.Settings.ApplyNullValues; bool oldSetting = SqlMapper.Settings.ApplyNullValues;
...@@ -62,7 +64,7 @@ private void TestNullable(bool applyNulls) ...@@ -62,7 +64,7 @@ private void TestNullable(bool applyNulls)
} }
} }
class NullTestClass private class NullTestClass
{ {
public int Id { get; set; } public int Id { get; set; }
public int A { get; set; } public int A { get; set; }
...@@ -70,7 +72,7 @@ class NullTestClass ...@@ -70,7 +72,7 @@ class NullTestClass
public string C { get; set; } public string C { get; set; }
public AnEnum D { get; set; } public AnEnum D { get; set; }
public AnEnum? E { get; set; } public AnEnum? E { get; set; }
public NullTestClass() public NullTestClass()
{ {
A = 2; A = 2;
......
This diff is collapsed.
using System.Reflection;
using System.Runtime.CompilerServices;
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("Smackdown")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Smackdown")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("77246f63-77a4-4d9f-a4d6-62282d67c8be")]
// 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 Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is automatically generated by Visual Studio .Net. It is
used to store generic object data source configuration information.
Renaming the file extension or editing the content of this file may
cause the file to be unrecognizable by the program.
-->
<GenericObjectDataSource DisplayName="tempdbEntities1" Identifier="SqlMapper.EntityFramework.tempdbEntities1" ProviderType="Microsoft.VisualStudio.DataDesign.DataSourceProviders.EntityDataModel.EdmDataSourceProvider" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<TypeInfo>SqlMapper.EntityFramework.tempdbEntities1, EntityFramework.Model.Designer.cs, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
</GenericObjectDataSource>
\ No newline at end of file
#if !COREFX
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Dapper.Tests.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)]
[global::System.Configuration.DefaultSettingValueAttribute("Data Source=.;Initial Catalog=tempdb;Integrated Security=True")]
public string tempdbConnectionString {
get {
return ((string)(this["tempdbConnectionString"]));
}
}
}
}
#endif
\ No newline at end of file
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="Smackdown.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="tempdbConnectionString" Type="(Connection string)" Scope="Application">
<DesignTimeValue Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;ConnectionString&gt;Data Source=.;Initial Catalog=tempdb;Integrated Security=True&lt;/ConnectionString&gt;
&lt;ProviderName&gt;System.Data.SqlClient&lt;/ProviderName&gt;
&lt;/SerializableConnectionString&gt;</DesignTimeValue>
<Value Profile="(Default)">Data Source=.;Initial Catalog=tempdb;Integrated Security=True</Value>
</Setting>
</Settings>
</SettingsFile>
\ No newline at end of file
{
"profiles": {
"test": {
"commandName": "test",
"sdkVersion": "dnx-coreclr-win-x86.1.0.0-rc1-update1"
}
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Dapper.Tests.Contrib namespace Dapper.Tests
{ {
public class Program public class Address
{ {
static void Main(string[] args) public int AddressId { get; set; }
{ public string Name { get; set; }
public int PersonId { get; set; }
}
} }
} }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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