Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NHibernate.SqlAzure.Tests/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<configuration>
<appSettings>
<add key="SqlServerServiceName" value="MSSQL$SQLEXPRESS" />
<add key="UseNHibernateProfiler" value="false" />
</appSettings>
<connectionStrings>
<add name="PooledDatabase" connectionString="Data Source=.\SQLEXPRESS;Integrated Security=True;Initial Catalog=NHibernateSqlAzureTests"/>
Expand Down
4 changes: 4 additions & 0 deletions NHibernate.SqlAzure.Tests/Config/FluentRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ private void Execute()
Database = _database,
Task = _task,
Connection = _connectionString,
#if NET45
Target = _migrationAssembly.CodeBase.Replace("file:///", ""),
#else
Targets = new string[] { _migrationAssembly.CodeBase.Replace("file:///", "") },
#endif
Version = _version
};

Expand Down
9 changes: 7 additions & 2 deletions NHibernate.SqlAzure.Tests/Config/NHibernateConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ public class NHibernateConfiguration<T> where T : SqlClientDriver
{
private readonly string _connectionString;
private readonly IPersistenceConfigurer _databaseConfig;
private readonly bool _useNHibernateProfiler;

public NHibernateConfiguration(string connectionString, IPersistenceConfigurer databaseConfig = null)
public NHibernateConfiguration(string connectionString, IPersistenceConfigurer databaseConfig = null, bool useNHibernateProfiler = false)
{
_connectionString = connectionString;
_databaseConfig = databaseConfig ?? MsSqlConfiguration.MsSql2008.ConnectionString(_connectionString).Driver<T>();
_useNHibernateProfiler = useNHibernateProfiler;
}

public ISessionFactory GetSessionFactory()
{
NHibernateProfiler.Initialize();
if (_useNHibernateProfiler)
{
NHibernateProfiler.Initialize();
}

var config = Fluently.Configure()
.Database(_databaseConfig)
Expand Down
8 changes: 6 additions & 2 deletions NHibernate.SqlAzure.Tests/Config/NHibernateTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ public abstract class NHibernateTestBase<T> where T: SqlClientDriver
protected FluentRunner Migrator;

protected abstract string ConnectionString { get; }
protected bool UseNHibernateProfiler
{
get { return bool.Parse(ConfigurationManager.AppSettings["UseNHibernateProfiler"]); }
}

[TestFixtureSetUp]
[OneTimeSetUp]
public void TestFixtureSetup()
{
CreateTestDatabase();
Expand All @@ -46,7 +50,7 @@ public void TestFixtureSetup()

Migrator.MigrateToLatest();

var nHibernateConfig = new NHibernateConfiguration<T>(ConnectionString);
var nHibernateConfig = new NHibernateConfiguration<T>(ConnectionString, useNHibernateProfiler: UseNHibernateProfiler);
_sessionFactory = nHibernateConfig.GetSessionFactory();
}

Expand Down
158 changes: 24 additions & 134 deletions NHibernate.SqlAzure.Tests/NHibernate.SqlAzure.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,146 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{887FD0A4-B8E0-4B3D-BF7E-4CC7090EB829}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NHibernate.SqlAzure.Tests</RootNamespace>
<AssemblyName>NHibernate.SqlAzure.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<TargetFramework>net45</TargetFramework>
<AssemblyTitle>NHibernate.SqlAzure.Tests</AssemblyTitle>
<Product>NHibernate.SqlAzure.Tests</Product>
<Copyright>Copyright © 2012</Copyright>
</PropertyGroup>
<ItemGroup>
<Reference Include="FizzWare.NBuilder, Version=3.0.1.0, Culture=neutral, PublicKeyToken=5651b03e12e42c12, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NBuilder.3.0.1.1\lib\FizzWare.NBuilder.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator, Version=1.1.2.1, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\FluentMigrator.1.1.2.1\lib\40\FluentMigrator.dll</HintPath>
</Reference>
<Reference Include="FluentMigrator.Runner, Version=1.1.2.1, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\FluentMigrator.Runner.1.1.1.26\lib\NET40\FluentMigrator.Runner.dll</HintPath>
</Reference>
<Reference Include="FluentNHibernate, Version=1.4.0.0, Culture=neutral, PublicKeyToken=8aa435e3cb308880, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\FluentNHibernate.1.4.0.0\lib\net35\FluentNHibernate.dll</HintPath>
</Reference>
<Reference Include="HibernatingRhinos.Profiler.Appender.v4.0, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0774796e73ebf640, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NHibernateProfiler.1.0.0.951\lib\Net40\HibernatingRhinos.Profiler.Appender.v4.0.dll</HintPath>
</Reference>
<Reference Include="Iesi.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Iesi.Collections.3.2.0.4000\lib\Net35\Iesi.Collections.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling">
<HintPath>..\packages\EnterpriseLibrary.TransientFaultHandling.6.0.1304.0\lib\portable-net45+win+wp8\Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.Data">
<HintPath>..\packages\EnterpriseLibrary.TransientFaultHandling.Data.6.0.1304.1\lib\NET45\Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.Data.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
</Reference>
<Reference Include="NHibernate, Version=3.3.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NHibernate.3.3.3.4001\lib\Net35\NHibernate.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<PackageReference Include="EnterpriseLibrary.TransientFaultHandling" Version="6.0.1304.0" />
<PackageReference Include="EnterpriseLibrary.TransientFaultHandling.Data" Version="6.0.1304.1" />
<PackageReference Include="FluentMigrator" Version="1.1.2.1" />
<PackageReference Include="FluentMigrator.Runner" Version="1.1.1.26" />
<PackageReference Include="FluentNHibernate" Version="1.4.0.0" />
<PackageReference Include="Iesi.Collections" Version="3.2.0.4000" />
<PackageReference Include="Microsoft.VisualStudio.SlowCheetah" Version="3.0.61" />
<PackageReference Include="NBuilder" Version="3.0.1.1" />
<PackageReference Include="NHibernate" Version="3.3.3.4001" />
<PackageReference Include="NHibernateProfiler" Version="1.0.0.951" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Transactions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WebActivator, Version=1.4.4.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\WebActivator.1.4.4\lib\net40\WebActivator.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Config\FluentRunner.cs" />
<Compile Include="Config\NHibernateConfiguration.cs" />
<Compile Include="Config\NHibernateTestBase.cs" />
<Compile Include="Config\LocalTestingReliableSql2008ClientDriver.cs" />
<Compile Include="Config\SqlExpressTransientErrorDetectionStrategy.cs" />
<Compile Include="ConnectionTests.cs" />
<Compile Include="Entities\User.cs" />
<Compile Include="Entities\UserProperty.cs" />
<Compile Include="Migrations\20120801141148_CreateUserTable.cs" />
<Compile Include="Migrations\20120809201500_CreateUserPropertyTable.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SqlClientDriverTests.cs" />
<Compile Include="TransientErrorDetectionTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
<TransformOnBuild>true</TransformOnBuild>
</None>
<None Include="App.Release.config">
<DependentUpon>App.config</DependentUpon>
<IsTransformFile>True</IsTransformFile>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NHibernate.SqlAzure\NHibernate.SqlAzure.csproj">
<Project>{C51908DF-FAEA-4EAA-8F75-096346537C33}</Project>
<Name>NHibernate.SqlAzure</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
<ProjectReference Include="..\NHibernate.SqlAzure\NHibernate.SqlAzure.csproj" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Microsoft.VisualStudio.SlowCheetah.3.0.61\build\Microsoft.VisualStudio.SlowCheetah.targets" Condition="Exists('..\packages\Microsoft.VisualStudio.SlowCheetah.3.0.61\build\Microsoft.VisualStudio.SlowCheetah.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.VisualStudio.SlowCheetah.3.0.61\build\Microsoft.VisualStudio.SlowCheetah.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.VisualStudio.SlowCheetah.3.0.61\build\Microsoft.VisualStudio.SlowCheetah.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
36 changes: 0 additions & 36 deletions NHibernate.SqlAzure.Tests/Properties/AssemblyInfo.cs

This file was deleted.

65 changes: 34 additions & 31 deletions NHibernate.SqlAzure.Tests/SqlClientDriverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,53 +55,56 @@ class SqlAzureClientDriverWithTimeoutRetriesShould : SqlClientDriverShould<SqlAz
class Sql2008ClientDriverShould : SqlClientDriverShould<Sql2008ClientDriver>
{
[Test]
[ExpectedException(typeof(ExpectedErrorException))]
public void Fail_to_execute_non_batching_commands_during_temporary_shutdown_of_sql_server()
{
try
Assert.Throws<ExpectedErrorException>(() =>
{
using (TemporarilyShutdownSqlServerExpress())
try
{
for (var i = 0; i < 100; i++)
using (TemporarilyShutdownSqlServerExpress())
{
Insert_and_select_entity();
Thread.Sleep(50);
for (var i = 0; i < 100; i++)
{
Insert_and_select_entity();
Thread.Sleep(50);
}
}
}
}
catch (GenericADOException e)
{
Console.WriteLine(e);
throw new ExpectedErrorException();
}
Assert.Fail("There was no exception when executing non batching commands during temporary shutdown of SQL server, but one was expected.");
catch (GenericADOException e)
{
Console.WriteLine(e);
throw new ExpectedErrorException();
}
}, "There was no exception when executing non batching commands during temporary shutdown of SQL server, but one was expected.");
}

[Test]
[ExpectedException(typeof(ExpectedErrorException))]
public void Fail_to_execute_batching_commands_during_temporary_shutdown_of_sql_server()
{
try
Assert.Throws<ExpectedErrorException>(() =>
{
using (TemporarilyShutdownSqlServerExpress())
try
{
for (var i = 0; i < 100; i++)
using (TemporarilyShutdownSqlServerExpress())
{
Insert_and_select_multiple_entities();
Thread.Sleep(50);
for (var i = 0; i < 100; i++)
{
Insert_and_select_multiple_entities();
Thread.Sleep(50);
}
}
}
}
catch (GenericADOException e)
{
Console.WriteLine(e);
throw new ExpectedErrorException();
}
catch (TransactionException e)
{
Console.WriteLine(e);
throw new ExpectedErrorException();
}
catch (GenericADOException e)
{
Console.WriteLine(e);
throw new ExpectedErrorException();
}
catch (TransactionException e)
{
Console.WriteLine(e);
throw new ExpectedErrorException();
}
});
}
public class ExpectedErrorException : Exception { }
}
Expand Down Expand Up @@ -237,7 +240,7 @@ public void Insert_and_update_multiple_entities()
Assert.That(dbUsers, Has.Count.EqualTo(users.Count));
foreach (var u in dbUsers)
{
Assert.That(u.Name, Is.StringEnding("_2_"));
Assert.That(u.Name, Does.EndWith("_2_"));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions NHibernate.SqlAzure.Tests/TransientErrorDetectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ internal static class SqlExceptionGenerator
public static SqlException GetSqlException(int errorCode)
{
var collection = (SqlErrorCollection)Activator.CreateInstance(typeof(SqlErrorCollection), true);
var error = (SqlError)Activator.CreateInstance(typeof(SqlError), BindingFlags.NonPublic | BindingFlags.Instance, null, new object[] { errorCode, (byte)2, (byte)3, "server name", "error message", "proc", 100 }, null);

var error = (SqlError)Activator.CreateInstance(typeof(SqlError), BindingFlags.NonPublic | BindingFlags.Instance, null, new object[] { errorCode, (byte)2, (byte)3, "server name", "error message", "proc", 100, (Exception)null }, null);
typeof(SqlErrorCollection)
.GetMethod("Add", BindingFlags.NonPublic | BindingFlags.Instance)
.Invoke(collection, new object[] { error });
Expand Down
Loading