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

Commit 1d94f66

Browse files
committed
Add Self Join Alias test
1 parent 31461c7 commit 1d94f66

File tree

4 files changed

+61
-16
lines changed

4 files changed

+61
-16
lines changed

tests/ServiceStack.OrmLite.FirebirdTests/ServiceStack.Common.Tests/ServiceStack.Common.Tests.Models/TaskQueue.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
using ServiceStack.Text;
55
using ServiceStack.DataAnnotations;
66

7-
namespace ServiceStack.Common.Tests.Models{
7+
namespace ServiceStack.Common.Tests.Models
8+
{
89

910
public class TaskQueue
1011
{
11-
private readonly static ILog Log;
12+
private static readonly ILog Log;
1213

1314
public const int PriorityHigh = 2;
1415

@@ -115,13 +116,15 @@ public static void AssertIsEqual(TaskQueue actual, TaskQueue expected)
115116

116117
public static TaskQueue Create(int id)
117118
{
118-
TaskQueue taskQueue = new TaskQueue();
119-
taskQueue.ContentUrn = string.Concat("urn:track:", id);
120-
taskQueue.CreatedDate = DateTime.Now;
121-
taskQueue.Task = "Load";
122-
taskQueue.Status = "Pending";
123-
taskQueue.NoOfAttempts = 0;
124-
return taskQueue;
119+
var taskQueue = new TaskQueue
120+
{
121+
ContentUrn = string.Concat("urn:track:", id),
122+
CreatedDate = DateTime.Now,
123+
Task = "Load",
124+
Status = "Pending",
125+
NoOfAttempts = 0
126+
};
127+
return taskQueue;
125128
}
126129
}
127130
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using NUnit.Framework;
3+
using ServiceStack.DataAnnotations;
4+
using ServiceStack.Text;
5+
6+
namespace ServiceStack.OrmLite.Tests.Expression
7+
{
8+
public class Task
9+
{
10+
[AutoIncrement]
11+
public long Id { get; set; }
12+
13+
public long? ParentId { get; set; }
14+
15+
public DateTime Created { get; set; }
16+
}
17+
18+
[TestFixture]
19+
public class JoinAliasTests : OrmLiteTestBase
20+
{
21+
[Test]
22+
public void Can_use_JoinAlias_in_condition()
23+
{
24+
using (var db = OpenDbConnection())
25+
{
26+
db.DropAndCreateTable<Task>();
27+
28+
var parentId = db.Insert(new Task { Created = new DateTime(2000, 01, 01) }, selectIdentity: true);
29+
var childId = db.Insert(new Task { ParentId = parentId, Created = new DateTime(2001, 01, 01) }, selectIdentity:true);
30+
31+
var fromDateTime = new DateTime(2000, 02, 02);
32+
33+
var q = db.From<Task>()
34+
.LeftJoin<Task>((parent, history) => parent.Id == history.ParentId, db.JoinAlias("history"))
35+
.Where("history.\"Created\" >= {0} OR Task.\"Created\" >= {0}", fromDateTime);
36+
37+
//TODO: JOIN Alias doesn't support self-joins
38+
39+
var results = db.Select(q);
40+
41+
db.GetLastSql().Print();
42+
43+
results.PrintDump();
44+
}
45+
}
46+
}
47+
}

tests/ServiceStack.OrmLite.Tests/ServiceStack.OrmLite.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
<Compile Include="Async\SqlExpressionTests.cs" />
141141
<Compile Include="Async\SqlServerProviderTestsAsync.cs" />
142142
<Compile Include="Async\UpdateAsyncTests.cs" />
143+
<Compile Include="Expression\JoinAliasTests.cs" />
143144
<Compile Include="Expression\SqlExpressionDeleteTests.cs" />
144145
<Compile Include="Expression\SqlExpressionJoinTests.cs" />
145146
<Compile Include="Issues\JoinAliasWithSchemaIssue.cs" />

tests/ServiceStack.OrmLite.Tests/Shared/SampleOrderLine.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@ public class SampleOrderLine
1111
{
1212
public string Id { get; set; }
1313

14-
public string OrderUrn
15-
{
16-
get
17-
{
18-
return CreateUrn(this.UserId, this.OrderId, this.OrderLineId);
19-
}
20-
}
14+
public string OrderUrn => CreateUrn(this.UserId, this.OrderId, this.OrderLineId);
2115

2216
public long OrderId { get; set; }
2317

0 commit comments

Comments
 (0)