Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit f2e537b

Browse files
committed
Rename CustomerJoin to FullCustomerInfo
1 parent e39b19f commit f2e537b

File tree

1 file changed

+57
-64
lines changed

1 file changed

+57
-64
lines changed

tests/ServiceStack.OrmLite.Tests/LoadReferencesJoinTests.cs

Lines changed: 57 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ private Customer AddCustomerWithOrders()
4545
Name = "Customer 1",
4646
PrimaryAddress = new CustomerAddress
4747
{
48-
AddressLine1 = "1 Humpty Street",
49-
City = "Humpty Doo",
50-
State = "Northern Territory",
48+
AddressLine1 = "1 Australia Street",
5149
Country = "Australia"
5250
},
5351
Orders = new[]
@@ -62,7 +60,7 @@ private Customer AddCustomerWithOrders()
6260
return customer;
6361
}
6462

65-
public class CustomerJoin
63+
public class FullCustomerInfo
6664
{
6765
public int Id { get; set; }
6866
public string Name { get; set; }
@@ -78,7 +76,7 @@ public void Can_do_multiple_joins_with_SqlExpression()
7876
{
7977
AddCustomerWithOrders();
8078

81-
var results = db.Select<CustomerJoin, Customer>(q => q
79+
var results = db.Select<FullCustomerInfo, Customer>(q => q
8280
.Join<Customer, CustomerAddress>()
8381
.Join<Customer, Order>());
8482

@@ -89,7 +87,7 @@ public void Can_do_multiple_joins_with_SqlExpression()
8987
.Join<Customer, CustomerAddress>()
9088
.Join<Customer, Order>();
9189

92-
results = db.Select<CustomerJoin>(expr);
90+
results = db.Select<FullCustomerInfo>(expr);
9391

9492
costs = results.ConvertAll(x => x.Cost);
9593
Assert.That(costs, Is.EquivalentTo(new[] { 1.99m, 2.99m }));
@@ -100,7 +98,7 @@ public void Can_do_joins_with_wheres_using_SqlExpression()
10098
{
10199
AddCustomerWithOrders();
102100

103-
var results = db.Select<CustomerJoin, Customer>(q => q
101+
var results = db.Select<FullCustomerInfo, Customer>(q => q
104102
.Join<Customer, CustomerAddress>()
105103
.Join<Customer, Order>((c, o) => c.Id == o.CustomerId && o.Cost < 2));
106104

@@ -116,15 +114,15 @@ public void Can_do_joins_with_wheres_using_SqlExpression()
116114
costs = orders.ConvertAll(x => x.Cost);
117115
Assert.That(costs, Is.EquivalentTo(new[] { 1.99m }));
118116

119-
results = db.Select<CustomerJoin, Customer>(q => q
117+
results = db.Select<FullCustomerInfo, Customer>(q => q
120118
.Join<Customer, CustomerAddress>()
121119
.Join<Customer, Order>()
122120
.Where<Order>(o => o.Cost < 2));
123121

124122
costs = results.ConvertAll(x => x.Cost);
125123
Assert.That(costs, Is.EquivalentTo(new[] { 1.99m }));
126124

127-
results = db.Select<CustomerJoin, Customer>(q => q
125+
results = db.Select<FullCustomerInfo, Customer>(q => q
128126
.Join<Customer, CustomerAddress>()
129127
.Join<Customer, Order>()
130128
.Where<Order>(o => o.Cost < 2 || o.LineItem == "Line 2"));
@@ -136,7 +134,7 @@ public void Can_do_joins_with_wheres_using_SqlExpression()
136134
.Join<Customer, CustomerAddress>()
137135
.Join<Customer, Order>()
138136
.Where<Order>(o => o.Cost < 2 || o.LineItem == "Line 2");
139-
results = db.Select<CustomerJoin>(expr);
137+
results = db.Select<FullCustomerInfo>(expr);
140138

141139
costs = results.ConvertAll(x => x.Cost);
142140
Assert.That(costs, Is.EquivalentTo(new[] { 1.99m, 2.99m }));
@@ -145,61 +143,65 @@ public void Can_do_joins_with_wheres_using_SqlExpression()
145143
[Test]
146144
public void Can_do_joins_with_complex_wheres_using_SqlExpression()
147145
{
148-
var customer1 = new Customer
146+
var customers = new[]
149147
{
150-
Name = "Customer 1",
151-
PrimaryAddress = new CustomerAddress
148+
new Customer
152149
{
153-
AddressLine1 = "1 Humpty Street",
154-
City = "Humpty Doo",
155-
State = "Northern Territory",
156-
Country = "Australia"
150+
Name = "Customer 1",
151+
PrimaryAddress = new CustomerAddress {
152+
AddressLine1 = "1 Australia Street",
153+
Country = "Australia"
154+
},
155+
Orders = new[] {
156+
new Order { LineItem = "Line 1", Qty = 1, Cost = 1.99m },
157+
new Order { LineItem = "Line 1", Qty = 2, Cost = 3.98m },
158+
new Order { LineItem = "Line 2", Qty = 1, Cost = 1.49m },
159+
new Order { LineItem = "Line 2", Qty = 2, Cost = 2.98m },
160+
new Order { LineItem = "Australia Flag", Qty = 1, Cost = 9.99m },
161+
}.ToList(),
157162
},
158-
Orders = new[]
159-
{
160-
new Order {LineItem = "Line 1", Qty = 1, Cost = 1.99m},
161-
new Order {LineItem = "Line 1", Qty = 2, Cost = 3.98m},
162-
new Order {LineItem = "Line 2", Qty = 1, Cost = 1.49m},
163-
new Order {LineItem = "Line 2", Qty = 2, Cost = 2.98m},
164-
new Order {LineItem = "Australia Flag", Qty = 1, Cost = 9.99m},
165-
}.ToList(),
166-
};
167-
168-
db.Save(customer1, references: true);
169-
170-
var customer2 = new Customer
171-
{
172-
Name = "Customer 2",
173-
PrimaryAddress = new CustomerAddress
163+
new Customer
174164
{
175-
AddressLine1 = "2 Prospect Park",
176-
City = "Brooklyn",
177-
State = "New York",
178-
Country = "USA"
165+
Name = "Customer 2",
166+
PrimaryAddress = new CustomerAddress {
167+
AddressLine1 = "2 Prospect Park",
168+
Country = "USA"
169+
},
170+
Orders = new[] {
171+
new Order { LineItem = "USA", Qty = 1, Cost = 20m },
172+
}.ToList(),
179173
},
180-
Orders = new[]
181-
{
182-
new Order {LineItem = "USA", Qty = 1, Cost = 20m},
183-
}.ToList(),
184174
};
185175

186-
db.Save(customer2, references: true);
176+
customers.Each(c =>
177+
db.Save(c, references: true));
187178

188179
db.Insert(
189180
new Country { CountryName = "Australia", CountryCode = "AU" },
190181
new Country { CountryName = "USA", CountryCode = "US" });
191182

192-
var results = db.Select<CustomerJoin, Customer>(q => q
193-
.Join<Customer, CustomerAddress>()
194-
.Join<Customer, Order>()
183+
var results = db.Select<FullCustomerInfo, Customer>(q => q
184+
.Join<CustomerAddress>() //implicit
185+
.Join<Customer, Order>() //explicit
195186
.Where(c => c.Name == "Customer 1")
196187
.And<Order>(o => o.Cost < 2)
197188
.Or<Order>(o => o.LineItem == "Australia Flag"));
198189

199190
var costs = results.ConvertAll(x => x.Cost);
200191
Assert.That(costs, Is.EquivalentTo(new[] { 1.99m, 1.49m, 9.99m }));
201192

202-
results = db.Select<CustomerJoin, Customer>(q => q
193+
//Same as above using using db.From<Customer>()
194+
results = db.Select<FullCustomerInfo>(db.From<Customer>()
195+
.Join<CustomerAddress>() //implicit
196+
.Join<Customer, Order>() //explicit
197+
.Where(c => c.Name == "Customer 1")
198+
.And<Order>(o => o.Cost < 2)
199+
.Or<Order>(o => o.LineItem == "Australia Flag"));
200+
201+
costs = results.ConvertAll(x => x.Cost);
202+
Assert.That(costs, Is.EquivalentTo(new[] { 1.99m, 1.49m, 9.99m }));
203+
204+
results = db.Select<FullCustomerInfo, Customer>(q => q
203205
.Join<Customer, CustomerAddress>()
204206
.Join<Customer, Order>()
205207
.Where(c => c.Name == "Customer 2")
@@ -208,9 +210,9 @@ public void Can_do_joins_with_complex_wheres_using_SqlExpression()
208210
costs = results.ConvertAll(x => x.Cost);
209211
Assert.That(costs, Is.EquivalentTo(new[] { 20m }));
210212

211-
var countryResults = db.Select<CustomerJoin>(db.From<Customer>()
212-
.Join<Order>((c, o) => c.Id == o.CustomerId) //explicit join condition
213+
var countryResults = db.Select<FullCustomerInfo>(db.From<Customer>()
213214
.Join<CustomerAddress>() //implicit join with Customer
215+
.Join<Order>((c, o) => c.Id == o.CustomerId) //explicit join condition
214216
.Join<CustomerAddress, Country>((ca, c) => ca.Country == c.CountryName)
215217
.Where(c => c.Name == "Customer 2") //implicit condition with Customer
216218
.And<CustomerAddress, Order>((a, o) => a.Country == o.LineItem));
@@ -230,41 +232,32 @@ public void Can_do_LeftJoins_using_SqlExpression()
230232
new Customer
231233
{
232234
Name = "Customer 1",
233-
PrimaryAddress = new CustomerAddress
234-
{
235-
AddressLine1 = "1 Humpty Street",
236-
City = "Humpty Doo",
237-
State = "Northern Territory",
235+
PrimaryAddress = new CustomerAddress {
236+
AddressLine1 = "1 Australia Street",
238237
Country = "Australia"
239238
},
240239
},
241240
new Customer
242241
{
243242
Name = "Customer 2",
244-
PrimaryAddress = new CustomerAddress
245-
{
246-
AddressLine1 = "2 Humpty Street",
247-
City = "Humpty Doo",
248-
State = "Northern Territory",
243+
PrimaryAddress = new CustomerAddress {
244+
AddressLine1 = "2 America Street",
249245
Country = "USA"
250246
},
251247
},
252248
new Customer
253249
{
254250
Name = "Customer 3",
255-
PrimaryAddress = new CustomerAddress
256-
{
257-
AddressLine1 = "3 Humpty Street",
258-
City = "Humpty Doo",
259-
State = "Northern Territory",
251+
PrimaryAddress = new CustomerAddress {
252+
AddressLine1 = "3 Canada Street",
260253
Country = "Canada"
261254
},
262255
},
263256
};
264257

265258
customers.Each(c =>
266259
db.Save(c, references: true));
267-
260+
268261
db.Insert(
269262
new Country { CountryName = "Australia", CountryCode = "AU" },
270263
new Country { CountryName = "USA", CountryCode = "US" },

0 commit comments

Comments
 (0)