Skip to content

Commit 56cb5f5

Browse files
Tests fixes. run-tests.bat added. DataAccess empty projects added.
1 parent f7ebdc1 commit 56cb5f5

39 files changed

+434
-61
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{E5C76E4E-0E87-4297-9288-AB4430BFD785}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>BetterModules.Core.DataAccess.nHibernate</RootNamespace>
11+
<AssemblyName>BetterModules.Core.DataAccess.nHibernate</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="System" />
34+
<Reference Include="System.Core" />
35+
<Reference Include="System.Xml.Linq" />
36+
<Reference Include="System.Data.DataSetExtensions" />
37+
<Reference Include="Microsoft.CSharp" />
38+
<Reference Include="System.Data" />
39+
<Reference Include="System.Net.Http" />
40+
<Reference Include="System.Xml" />
41+
</ItemGroup>
42+
<ItemGroup>
43+
<Compile Include="..\SharedAssemblyInfo.cs">
44+
<Link>Properties\SharedAssemblyInfo.cs</Link>
45+
</Compile>
46+
<Compile Include="Properties\AssemblyInfo.cs" />
47+
</ItemGroup>
48+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
49+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
50+
Other similar extension points exist, see Microsoft.Common.targets.
51+
<Target Name="BeforeBuild">
52+
</Target>
53+
<Target Name="AfterBuild">
54+
</Target>
55+
-->
56+
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("BetterModules.Core.DataAccess.nHibernate")]
9+
[assembly: AssemblyDescription("")]
10+
11+
12+
// Setting ComVisible to false makes the types in this assembly not visible
13+
// to COM components. If you need to access a type in this assembly from
14+
// COM, set the ComVisible attribute to true on that type.
15+
[assembly: ComVisible(false)]
16+
17+
// The following GUID is for the ID of the typelib if this project is exposed to COM
18+
[assembly: Guid("e5c76e4e-0e87-4297-9288-ab4430bfd785")]
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{AC302C3A-AFE5-4F0E-8FA2-A22F46407EE6}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>BetterModules.Core.DataAccess</RootNamespace>
11+
<AssemblyName>BetterModules.Core.DataAccess</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="System" />
34+
<Reference Include="System.Core" />
35+
<Reference Include="System.Xml.Linq" />
36+
<Reference Include="System.Data.DataSetExtensions" />
37+
<Reference Include="Microsoft.CSharp" />
38+
<Reference Include="System.Data" />
39+
<Reference Include="System.Net.Http" />
40+
<Reference Include="System.Xml" />
41+
</ItemGroup>
42+
<ItemGroup>
43+
<Compile Include="..\SharedAssemblyInfo.cs">
44+
<Link>Properties\SharedAssemblyInfo.cs</Link>
45+
</Compile>
46+
<Compile Include="Properties\AssemblyInfo.cs" />
47+
</ItemGroup>
48+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
49+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
50+
Other similar extension points exist, see Microsoft.Common.targets.
51+
<Target Name="BeforeBuild">
52+
</Target>
53+
<Target Name="AfterBuild">
54+
</Target>
55+
-->
56+
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("BetterModules.Core.DataAccess")]
9+
[assembly: AssemblyDescription("")]
10+
11+
// Setting ComVisible to false makes the types in this assembly not visible
12+
// to COM components. If you need to access a type in this assembly from
13+
// COM, set the ComVisible attribute to true on that type.
14+
[assembly: ComVisible(false)]
15+
16+
// The following GUID is for the ID of the typelib if this project is exposed to COM
17+
[assembly: Guid("ac302c3a-afe5-4f0e-8fa2-a22f46407ee6")]

BetterModules.Core.Database.Tests/BetterModules.Core.Database.Tests.csproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<Private>True</Private>
6161
</Reference>
6262
<Reference Include="Iesi.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
63-
<HintPath>..\packages\Iesi.Collections.4.0.1.4000\lib\net40\Iesi.Collections.dll</HintPath>
63+
<HintPath>..\packages\Iesi.Collections.4.0.0.4000\lib\net40\Iesi.Collections.dll</HintPath>
6464
<Private>True</Private>
6565
</Reference>
6666
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
@@ -71,8 +71,8 @@
7171
<HintPath>..\packages\NHibernate.4.0.4.4000\lib\net40\NHibernate.dll</HintPath>
7272
<Private>True</Private>
7373
</Reference>
74-
<Reference Include="nunit.framework, Version=3.0.5813.39031, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
75-
<HintPath>..\packages\NUnit.3.0.1\lib\net45\nunit.framework.dll</HintPath>
74+
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
75+
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
7676
<Private>True</Private>
7777
</Reference>
7878
<Reference Include="System" />
@@ -88,6 +88,7 @@
8888
<Compile Include="DataAccess\DataContext\EventListeners\DeleteEventListenerIntegrationTests.cs" />
8989
<Compile Include="DataAccess\DataContext\EventListeners\SaveOrUpdateEventListenerTests.cs" />
9090
<Compile Include="DataAccess\DataContext\Fetching\DefaultFetchingProviderIntegrationTests.cs" />
91+
<Compile Include="DataAccess\DataContext\Interceptors\StaleInterceptorIntegrationTests - Copy.cs" />
9192
<Compile Include="DataAccess\DataContext\Interceptors\StaleInterceptorIntegrationTests.cs" />
9293
<Compile Include="DataAccess\DataContext\Migrations\DefaultMigrationTests.cs" />
9394
<Compile Include="DataAccess\DataContext\Migrations\DefaultVersionCheckerIntegrationTests.cs" />
@@ -160,6 +161,9 @@
160161
<Name>BetterModules.Sample.Module</Name>
161162
</ProjectReference>
162163
</ItemGroup>
164+
<ItemGroup>
165+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
166+
</ItemGroup>
163167
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
164168
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
165169
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

BetterModules.Core.Database.Tests/DataAccess/DataContext/EventListeners/SaveOrUpdateEventListenerTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Autofac;
1+
using System;
2+
using System.Threading;
3+
using Autofac;
24
using BetterModules.Core.Security;
35
using BetterModules.Sample.Module.Models;
46
using NUnit.Framework;
@@ -37,7 +39,8 @@ public void Should_Update_Entity_Properties_When_Updating()
3739
Assert.IsNotNull(entity.ModifiedOn);
3840
Assert.AreEqual(entity.ModifiedByUser, principalProvider.CurrentPrincipalName);
3941

40-
var modified = entity.ModifiedOn;
42+
var modified = new DateTime(entity.ModifiedOn.Ticks);
43+
Thread.Sleep(25);
4144

4245
var loadedEntity = Repository.FirstOrDefault<TestItemModel>(entity.Id);
4346
loadedEntity.Name = TestDataProvider.ProvideRandomString(100);

BetterModules.Core.Database.Tests/DataAccess/DataContext/Interceptors/StaleInterceptorIntegrationTests.cs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using BetterModules.Core.Exceptions.DataTier;
1+
using System;
2+
using BetterModules.Core.Exceptions.DataTier;
23
using NUnit.Framework;
34

45
namespace BetterModules.Core.Database.Tests.DataAccess.DataContext.Interceptors
@@ -48,39 +49,24 @@ public void Should_Throw_Concurrent_Data_Exception_Saving()
4849
{
4950
var model = DatabaseTestDataProvider.ProvideRandomTestItemModel();
5051

51-
Assert.AreEqual(model.Version, 0);
52-
53-
Repository.Save(model);
54-
UnitOfWork.Commit();
55-
56-
model.Name = TestDataProvider.ProvideRandomString();
57-
model.Version = 3;
58-
59-
Assert.Throws<ConcurrentDataException>(() =>
60-
{
61-
Repository.Save(model);
62-
UnitOfWork.Commit();
63-
});
64-
}
52+
Assert.AreEqual(0, model.Version);
53+
Assert.AreEqual(0, model.Category.Version);
6554

66-
[Test]
67-
public void Should_Throw_Concurrent_Data_Exception_Deleting()
68-
{
69-
var model = DatabaseTestDataProvider.ProvideRandomTestItemModel();
70-
71-
Assert.AreEqual(model.Version, 0);
72-
7355
Repository.Save(model);
7456
UnitOfWork.Commit();
7557

58+
Assert.AreEqual(1, model.Version);
59+
Assert.AreEqual(1, model.Category.Version);
60+
7661
model.Name = TestDataProvider.ProvideRandomString();
7762
model.Version = 3;
7863

7964
Assert.Throws<ConcurrentDataException>(() =>
8065
{
81-
Repository.Delete(model);
66+
Repository.Save(model);
8267
UnitOfWork.Commit();
8368
});
8469
}
70+
8571
}
8672
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using BetterModules.Core.Exceptions.DataTier;
3+
using NUnit.Framework;
4+
5+
namespace BetterModules.Core.Database.Tests.DataAccess.DataContext.Interceptors
6+
{
7+
[TestFixture]
8+
public class StaleInterceptorIntegrationTests2 : DatabaseTestBase
9+
{
10+
[Test]
11+
public void Should_Throw_Concurrent_Data_Exception_Deleting()
12+
{
13+
var model = DatabaseTestDataProvider.ProvideRandomTestItemModel();
14+
15+
Assert.AreEqual(model.Version, 0);
16+
17+
Repository.Save(model);
18+
UnitOfWork.Commit();
19+
20+
model.Name = TestDataProvider.ProvideRandomString();
21+
model.Version = 3;
22+
23+
Assert.Throws<ConcurrentDataException>(() =>
24+
{
25+
Repository.Delete(model);
26+
UnitOfWork.Commit();
27+
});
28+
}
29+
}
30+
}

BetterModules.Core.Database.Tests/DatabaseTestBase.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,31 @@ public abstract class DatabaseTestBase : TestBase
1313
{
1414
private DatabaseRandomTestDataProvider testDataProvider;
1515

16-
private static LocalDatabase database;
16+
private static readonly object lockObject = new object();
17+
18+
private volatile static LocalDatabase database;
1719

1820
private IRepository repository;
1921

2022
private IUnitOfWork unitOfWork;
2123

2224
protected SqlConnection SqlConnection
2325
{
24-
get { return database.SqlConnection; }
26+
get
27+
{
28+
if (database == null)
29+
{
30+
lock (lockObject)
31+
{
32+
if (database == null)
33+
{
34+
InitializeDatabase();
35+
}
36+
}
37+
}
38+
39+
return database.SqlConnection;
40+
}
2541
}
2642

2743
protected IRepository Repository
@@ -44,7 +60,13 @@ protected DatabaseTestBase()
4460
{
4561
if (database == null)
4662
{
47-
InitializeDatabase();
63+
lock (lockObject)
64+
{
65+
if (database == null)
66+
{
67+
InitializeDatabase();
68+
}
69+
}
4870
}
4971
}
5072

@@ -56,14 +78,15 @@ private void InitializeDatabase()
5678
configuration.Database.ConnectionString = database.ConnectionString;
5779
}
5880

59-
protected override void OnTextFixtureDown()
81+
protected override void OnTestFixtureDown()
6082
{
83+
6184
if (database != null)
6285
{
63-
database.Dispose();
86+
// database.Dispose();
6487
}
6588

66-
base.OnTextFixtureDown();
89+
base.OnTestFixtureDown();
6790
}
6891

6992
public virtual DatabaseRandomTestDataProvider DatabaseTestDataProvider

BetterModules.Core.Database.Tests/TestHelpers/TestDatabaseCreator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public LocalDatabase()
5757
}
5858
File.Copy(originalFile, tempFile);
5959

60-
connectionString = string.Format("Data Source=(LocalDb)\\v11.0; Initial Catalog=BetterModulesTestsDataSet; Integrated Security=SSPI; AttachDBFilename={0}", tempFile.TrimEnd('\\'));
60+
connectionString = string.Format("Data Source=(LocalDb)\\v12.0; Initial Catalog=BetterModulesTestsDataSet; Integrated Security=SSPI; AttachDBFilename={0}", tempFile.TrimEnd('\\'));
6161
}
6262

6363
public void Dispose()

0 commit comments

Comments
 (0)