Skip to content

Commit cb03ccd

Browse files
committed
Added tests for Table
1 parent 13a0661 commit cb03ccd

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

src/NHibernate.Test/MappingTest/TableFixture.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Linq;
2+
using System.Threading;
13
using NHibernate.Dialect;
24
using NHibernate.Mapping;
35
using NUnit.Framework;
@@ -59,5 +61,44 @@ public void SchemaNameQuoted()
5961

6062
Assert.AreEqual("[schema].name", tbl.GetQualifiedName(dialect));
6163
}
62-
}
64+
65+
[Test]
66+
public void TablesUniquelyNamed()
67+
{
68+
Table tbl1 = new Table();
69+
Table tbl2 = new Table();
70+
71+
Assert.AreEqual(tbl1.UniqueInteger + 1, tbl2.UniqueInteger);
72+
}
73+
74+
[Test]
75+
public void TablesUniquelyNamedOnlyWithinThread()
76+
{
77+
var uniqueIntegerList = new System.Collections.Concurrent.ConcurrentBag<int>();
78+
var method = new ThreadStart(() =>
79+
{
80+
Table tbl1 = new Table();
81+
Table tbl2 = new Table();
82+
83+
// Store these values for later comparison
84+
uniqueIntegerList.Add(tbl1.UniqueInteger);
85+
uniqueIntegerList.Add(tbl2.UniqueInteger);
86+
87+
// Ensure that within a thread we have unique integers
88+
Assert.AreEqual(tbl1.UniqueInteger + 1, tbl2.UniqueInteger);
89+
});
90+
91+
var thread1 = new Thread(method);
92+
var thread2 = new Thread(method);
93+
94+
thread1.Start();
95+
thread2.Start();
96+
97+
thread1.Join();
98+
thread2.Join();
99+
100+
Assert.AreEqual(4, uniqueIntegerList.Count);
101+
Assert.AreEqual(2, uniqueIntegerList.Distinct().Count());
102+
}
103+
}
63104
}

0 commit comments

Comments
 (0)