|
3 | 3 |
|
4 | 4 | namespace NHibernate.Test.TypedManyToOne |
5 | 5 | { |
6 | | - [TestFixture] |
7 | | - public class TypedManyToOneTest : TestCase |
8 | | - { |
9 | | - protected override string MappingsAssembly |
10 | | - { |
11 | | - get { return "NHibernate.Test"; } |
12 | | - } |
| 6 | + [TestFixture] |
| 7 | + public class TypedManyToOneTest : TestCase |
| 8 | + { |
| 9 | + protected override string MappingsAssembly |
| 10 | + { |
| 11 | + get { return "NHibernate.Test"; } |
| 12 | + } |
13 | 13 |
|
14 | | - protected override IList Mappings |
15 | | - { |
16 | | - get { return new[] { "TypedManyToOne.Customer.hbm.xml" }; } |
17 | | - } |
| 14 | + protected override IList Mappings |
| 15 | + { |
| 16 | + get { return new[] { "TypedManyToOne.Customer.hbm.xml" }; } |
| 17 | + } |
18 | 18 |
|
19 | | - [Test] |
20 | | - public void TestCreateQuery() |
21 | | - { |
22 | | - var cust = new Customer(); |
23 | | - cust.CustomerId = "abc123"; |
24 | | - cust.Name = "Matt"; |
| 19 | + [Test] |
| 20 | + public void TestCreateQuery() |
| 21 | + { |
| 22 | + var cust = new Customer(); |
| 23 | + cust.CustomerId = "abc123"; |
| 24 | + cust.Name = "Matt"; |
25 | 25 |
|
26 | | - var ship = new Address(); |
27 | | - ship.Street = "peachtree rd"; |
28 | | - ship.State = "GA"; |
29 | | - ship.City = "ATL"; |
30 | | - ship.Zip = "30326"; |
31 | | - ship.AddressId = new AddressId("SHIPPING", "xyz123"); |
32 | | - ship.Customer = cust; |
| 26 | + var ship = new Address(); |
| 27 | + ship.Street = "peachtree rd"; |
| 28 | + ship.State = "GA"; |
| 29 | + ship.City = "ATL"; |
| 30 | + ship.Zip = "30326"; |
| 31 | + ship.AddressId = new AddressId("SHIPPING", "xyz123"); |
| 32 | + ship.Customer = cust; |
33 | 33 |
|
34 | | - var bill = new Address(); |
35 | | - bill.Street = "peachtree rd"; |
36 | | - bill.State = "GA"; |
37 | | - bill.City = "ATL"; |
38 | | - bill.Zip = "30326"; |
39 | | - bill.AddressId = new AddressId("BILLING", "xyz123"); |
40 | | - bill.Customer = cust; |
| 34 | + var bill = new Address(); |
| 35 | + bill.Street = "peachtree rd"; |
| 36 | + bill.State = "GA"; |
| 37 | + bill.City = "ATL"; |
| 38 | + bill.Zip = "30326"; |
| 39 | + bill.AddressId = new AddressId("BILLING", "xyz123"); |
| 40 | + bill.Customer = cust; |
41 | 41 |
|
42 | | - cust.BillingAddress = bill; |
43 | | - cust.ShippingAddress = ship; |
| 42 | + cust.BillingAddress = bill; |
| 43 | + cust.ShippingAddress = ship; |
44 | 44 |
|
45 | | - using(ISession s = sessions.OpenSession()) |
46 | | - using (ITransaction t = s.BeginTransaction()) |
47 | | - { |
48 | | - s.Persist(cust); |
49 | | - t.Commit(); |
50 | | - } |
| 45 | + using (ISession s = sessions.OpenSession()) |
| 46 | + using (ITransaction t = s.BeginTransaction()) |
| 47 | + { |
| 48 | + s.Persist(cust); |
| 49 | + t.Commit(); |
| 50 | + } |
51 | 51 |
|
52 | | - using(ISession s = sessions.OpenSession()) |
53 | | - using(ITransaction t = s.BeginTransaction()) |
54 | | - { |
55 | | - try |
56 | | - { |
57 | | - IList results = s.CreateQuery("from Customer cust left join fetch cust.BillingAddress where cust.CustomerId='abc123'").List(); |
58 | | - //IList results = s.CreateQuery("from Customer cust left join fetch cust.BillingAddress left join fetch cust.ShippingAddress").List(); |
59 | | - cust = (Customer)results[0]; |
60 | | - Assert.That(NHibernateUtil.IsInitialized(cust.ShippingAddress), Is.False); |
61 | | - Assert.That(NHibernateUtil.IsInitialized(cust.BillingAddress), Is.True); |
62 | | - Assert.That(cust.BillingAddress.Zip, Is.EqualTo("30326")); |
63 | | - Assert.That(cust.ShippingAddress.Zip, Is.EqualTo("30326")); |
64 | | - Assert.That(cust.BillingAddress.AddressId.Type, Is.EqualTo("BILLING")); |
65 | | - Assert.That(cust.ShippingAddress.AddressId.Type, Is.EqualTo("SHIPPING")); |
66 | | - t.Commit(); |
67 | | - } |
68 | | - catch |
69 | | - { |
70 | | - throw; |
71 | | - } |
72 | | - } |
| 52 | + using (ISession s = sessions.OpenSession()) |
| 53 | + using (ITransaction t = s.BeginTransaction()) |
| 54 | + { |
| 55 | + IList results = s.CreateQuery("from Customer cust left join fetch cust.BillingAddress where cust.CustomerId='abc123'").List(); |
| 56 | + //IList results = s.CreateQuery("from Customer cust left join fetch cust.BillingAddress left join fetch cust.ShippingAddress").List(); |
| 57 | + cust = (Customer)results[0]; |
| 58 | + Assert.That(NHibernateUtil.IsInitialized(cust.ShippingAddress), Is.False); |
| 59 | + Assert.That(NHibernateUtil.IsInitialized(cust.BillingAddress), Is.True); |
| 60 | + Assert.That(cust.BillingAddress.Zip, Is.EqualTo("30326")); |
| 61 | + Assert.That(cust.ShippingAddress.Zip, Is.EqualTo("30326")); |
| 62 | + Assert.That(cust.BillingAddress.AddressId.Type, Is.EqualTo("BILLING")); |
| 63 | + Assert.That(cust.ShippingAddress.AddressId.Type, Is.EqualTo("SHIPPING")); |
| 64 | + t.Commit(); |
| 65 | + } |
73 | 66 |
|
74 | | - using(ISession s = sessions.OpenSession()) |
75 | | - using(ITransaction t = s.BeginTransaction()) |
76 | | - { |
77 | | - try |
78 | | - { |
79 | | - s.SaveOrUpdate(cust); |
80 | | - ship = cust.ShippingAddress; |
81 | | - cust.ShippingAddress = null; |
82 | | - s.Delete("ShippingAddress", ship); |
83 | | - s.Flush(); |
| 67 | + using (ISession s = sessions.OpenSession()) |
| 68 | + using (ITransaction t = s.BeginTransaction()) |
| 69 | + { |
| 70 | + s.SaveOrUpdate(cust); |
| 71 | + ship = cust.ShippingAddress; |
| 72 | + cust.ShippingAddress = null; |
| 73 | + s.Delete("ShippingAddress", ship); |
| 74 | + s.Flush(); |
84 | 75 |
|
85 | | - Assert.That(s.Get("ShippingAddress", ship.AddressId), Is.Null); |
86 | | - s.Delete(cust); |
87 | | - |
88 | | - t.Commit(); |
89 | | - } |
90 | | - catch |
91 | | - { |
92 | | - throw; |
93 | | - } |
94 | | - } |
95 | | - } |
| 76 | + Assert.That(s.Get("ShippingAddress", ship.AddressId), Is.Null); |
| 77 | + s.Delete(cust); |
96 | 78 |
|
97 | | - [Test] |
98 | | - public void TestCreateQueryNull() |
99 | | - { |
100 | | - var cust = new Customer(); |
101 | | - cust.CustomerId = "xyz123"; |
102 | | - cust.Name = "Matt"; |
| 79 | + t.Commit(); |
| 80 | + } |
| 81 | + } |
103 | 82 |
|
104 | | - using(ISession s = sessions.OpenSession()) |
105 | | - using(ITransaction t = s.BeginTransaction()) |
106 | | - { |
107 | | - s.Persist(cust); |
108 | | - t.Commit(); |
109 | | - } |
| 83 | + [Test] |
| 84 | + public void TestCreateQueryNull() |
| 85 | + { |
| 86 | + var cust = new Customer(); |
| 87 | + cust.CustomerId = "xyz123"; |
| 88 | + cust.Name = "Matt"; |
110 | 89 |
|
111 | | - using(ISession s = sessions.OpenSession()) |
112 | | - using(ITransaction t = s.BeginTransaction()) |
113 | | - { |
114 | | - try |
115 | | - { |
116 | | - IList results = s.CreateQuery("from Customer cust left join fetch cust.BillingAddress where cust.CustomerId='xyz123'").List(); |
117 | | - //IList results = s.CreateQuery("from Customer cust left join fetch cust.BillingAddress left join fetch cust.ShippingAddress").List(); |
118 | | - cust = (Customer)results[0]; |
119 | | - Assert.That(cust.ShippingAddress, Is.Null); |
120 | | - Assert.That(cust.BillingAddress, Is.Null); |
121 | | - s.Delete(cust); |
122 | | - t.Commit(); |
123 | | - } |
124 | | - catch |
125 | | - { |
126 | | - throw; |
127 | | - } |
128 | | - } |
129 | | - } |
130 | | - } |
| 90 | + using (ISession s = sessions.OpenSession()) |
| 91 | + using (ITransaction t = s.BeginTransaction()) |
| 92 | + { |
| 93 | + s.Persist(cust); |
| 94 | + t.Commit(); |
| 95 | + } |
| 96 | + |
| 97 | + using (ISession s = sessions.OpenSession()) |
| 98 | + using (ITransaction t = s.BeginTransaction()) |
| 99 | + { |
| 100 | + IList results = s.CreateQuery("from Customer cust left join fetch cust.BillingAddress where cust.CustomerId='xyz123'").List(); |
| 101 | + //IList results = s.CreateQuery("from Customer cust left join fetch cust.BillingAddress left join fetch cust.ShippingAddress").List(); |
| 102 | + cust = (Customer)results[0]; |
| 103 | + Assert.That(cust.ShippingAddress, Is.Null); |
| 104 | + Assert.That(cust.BillingAddress, Is.Null); |
| 105 | + s.Delete(cust); |
| 106 | + t.Commit(); |
| 107 | + } |
| 108 | + } |
| 109 | + } |
131 | 110 | } |
0 commit comments