forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOnDeleteFixture.cs
79 lines (64 loc) · 1.76 KB
/
OnDeleteFixture.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System.Collections;
using NHibernate.Stat;
using NUnit.Framework;
namespace NHibernate.Test.Ondelete
{
[TestFixture]
public class OnDeleteFixture : TestCase
{
protected override string MappingsAssembly
{
get { return "NHibernate.Test"; }
}
protected override string[] Mappings
{
get { return new string[] { "Ondelete.Person.hbm.xml" }; }
}
protected override void Configure(Cfg.Configuration configuration)
{
cfg.SetProperty(Cfg.Environment.GenerateStatistics, "true");
}
protected override bool AppliesTo(NHibernate.Dialect.Dialect dialect)
{
return dialect.SupportsCircularCascadeDeleteConstraints;
}
[Test]
public void JoinedSubclass()
{
IStatistics statistics = Sfi.Statistics;
statistics.Clear();
ISession s = OpenSession();
ITransaction t = s.BeginTransaction();
Salesperson mark = new Salesperson();
mark.Name = "Mark";
mark.Title = "internal sales";
mark.Sex = 'M';
mark.Address.address = "buckhead";
mark.Address.zip = "30305";
mark.Address.country = "USA";
Person joe = new Person();
joe.Name = "Joe";
joe.Address.address = "San Francisco";
joe.Address.zip = "XXXXX";
joe.Address.country = "USA";
joe.Sex = 'M';
joe.Salesperson = mark;
mark.Customers.Add(joe);
s.Save(mark);
t.Commit();
Assert.AreEqual(2, statistics.EntityInsertCount);
Assert.IsTrue(5 >= statistics.PrepareStatementCount);
statistics.Clear();
t = s.BeginTransaction();
s.Delete(mark);
t.Commit();
Assert.AreEqual(2, statistics.EntityDeleteCount);
Assert.AreEqual(1, statistics.PrepareStatementCount);
t = s.BeginTransaction();
IList names = s.CreateQuery("select p.name from Person p").List();
Assert.AreEqual(0, names.Count);
t.Commit();
s.Close();
}
}
}