Skip to content

Commit 9358948

Browse files
committed
Test for #81
Release notes update
1 parent 14e20e1 commit 9358948

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed

src/Simplify.FluentNHibernate.Tests/Conventions/ForeignKeyConstraintNameConventionTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using FluentNHibernate.Cfg;
55
using FluentNHibernate.Conventions.Helpers;
66
using NHibernate.Cfg;
7+
using NHibernate.Tool.hbm2ddl;
78
using NUnit.Framework;
89
using Simplify.FluentNHibernate.Conventions;
910
using Simplify.FluentNHibernate.Tests.Mappings.Accounts;
@@ -13,7 +14,7 @@ namespace Simplify.FluentNHibernate.Tests.Conventions
1314
[TestFixture]
1415
public class ForeignKeyConstraintNameConventionTests : SessionExtensionsTestsBase
1516
{
16-
private NHibernate.Tool.hbm2ddl.SchemaUpdate _schemaUpdate;
17+
private SchemaUpdate _schemaUpdate;
1718

1819
[SetUp]
1920
public void Initialize()
@@ -25,7 +26,7 @@ public void Initialize()
2526

2627
configuration.BuildSessionFactory();
2728

28-
_schemaUpdate = new NHibernate.Tool.hbm2ddl.SchemaUpdate(config);
29+
_schemaUpdate = new SchemaUpdate(config);
2930
}
3031

3132
[Test]
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System.IO;
2+
using System.Linq;
3+
using System.Text.RegularExpressions;
4+
using FluentNHibernate.Cfg;
5+
using FluentNHibernate.Conventions.Helpers;
6+
using NHibernate.Cfg;
7+
using NHibernate.Tool.hbm2ddl;
8+
using NUnit.Framework;
9+
using Simplify.FluentNHibernate.Conventions;
10+
using Simplify.FluentNHibernate.Tests.Mappings.Accounts;
11+
12+
namespace Simplify.FluentNHibernate.Tests
13+
{
14+
[TestFixture]
15+
public class NHibernateConfigurationExtensionsTests : SessionExtensionsTestsBase
16+
{
17+
private SchemaUpdate _schemaUpdate;
18+
19+
[SetUp]
20+
public void Initialize()
21+
{
22+
var configuration = CreateConfiguration();
23+
24+
Configuration config = null;
25+
configuration.ExposeConfiguration(c => config = c);
26+
configuration.BuildSessionFactory();
27+
28+
config.CreateIndexesForForeignKeys();
29+
30+
_schemaUpdate = new SchemaUpdate(config);
31+
}
32+
33+
[Test]
34+
public void UpdateSchema_WithCreateIndexesForForeignKeys_IndexesCreated()
35+
{
36+
// Act
37+
38+
using var sw = new StringWriter();
39+
_schemaUpdate.Execute(sw.Write, false);
40+
41+
// Assert
42+
43+
var result = sw.ToString();
44+
var matches = Regex.Matches(result, @"IDX\w+");
45+
var indexes = (from Match match in matches select match.Value).ToList();
46+
47+
Assert.AreEqual(5, indexes.Count);
48+
Assert.AreEqual("IDX_FK_UsersGroups_UserID", indexes[0]);
49+
Assert.AreEqual("IDX_FK_UsersGroups_GroupID", indexes[1]);
50+
Assert.AreEqual("IDX_FK_Custom_UsersPrivileges_GroupID", indexes[2]);
51+
Assert.AreEqual("IDX_FK_User_OrganizationID", indexes[3]);
52+
Assert.AreEqual("IDX_FK_UsersPrivileges_UserID", indexes[4]);
53+
}
54+
55+
private static FluentConfiguration CreateConfiguration()
56+
{
57+
return Fluently.Configure()
58+
.InitializeFromConfigSqLiteInMemory(true)
59+
.AddMappingsFromAssemblyOf<UserMap>(
60+
ForeignKey.EndsWith("ID"),
61+
ForeignKeyConstraintNameConvention.WithConstraintNameConvention());
62+
}
63+
}
64+
}

src/Simplify.FluentNHibernate/Simplify.FluentNHibernate.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
<PackageTags>.NET FluentNHibernate ORM</PackageTags>
1414
<PackageReleaseNotes>
1515
New
16-
* Added ForeignKeyConstraintNameConvention (#82)
16+
* Configuration extension method to create indexes for foreign keys (#81)
17+
* Foreign key constraint name convention (#82)
1718
</PackageReleaseNotes>
1819
<OutputPath>bin\Any CPU\$(Configuration)\</OutputPath>
1920
<DocumentationFile>bin\Any CPU\$(Configuration)\$(TargetFramework)\Simplify.FluentNHibernate.xml</DocumentationFile>

0 commit comments

Comments
 (0)