Skip to content

Commit 2cd0125

Browse files
iss-182: add tests
1 parent f3d7c92 commit 2cd0125

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

QueryBuilder.Tests/DeleteTests.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using SqlKata.Compilers;
2+
using SqlKata.Extensions;
3+
using SqlKata.Tests.Infrastructure;
4+
using System;
5+
using System.Linq;
6+
using Xunit;
7+
8+
namespace SqlKata.Tests
9+
{
10+
public class DeleteTests : TestSupport
11+
{
12+
[Fact]
13+
public void BasicDelete()
14+
{
15+
var q = new Query("Posts").AsDelete();
16+
17+
var c = Compile(q);
18+
19+
Assert.Equal("DELETE FROM [Posts]", c[EngineCodes.SqlServer]);
20+
}
21+
22+
[Fact]
23+
public void DeleteWithJoin()
24+
{
25+
var q = new Query("Posts")
26+
.Join("Authors", "Authors.Id", "Posts.AuthorId")
27+
.Where("Authors.Id", 5)
28+
.AsDelete();
29+
30+
var c = Compile(q);
31+
32+
Assert.Equal("DELETE [Posts] FROM [Posts] \nINNER JOIN [Authors] ON [Authors].[Id] = [Posts].[AuthorId] WHERE [Authors].[Id] = 5", c[EngineCodes.SqlServer]);
33+
Assert.Equal("DELETE `Posts` FROM `Posts` \nINNER JOIN `Authors` ON `Authors`.`Id` = `Posts`.`AuthorId` WHERE `Authors`.`Id` = 5", c[EngineCodes.MySql]);
34+
}
35+
36+
[Fact]
37+
public void DeleteWithJoinAndAlias()
38+
{
39+
var q = new Query("Posts as P")
40+
.Join("Authors", "Authors.Id", "P.AuthorId")
41+
.Where("Authors.Id", 5)
42+
.AsDelete();
43+
44+
var c = Compile(q);
45+
46+
Assert.Equal("DELETE [P] FROM [Posts] AS [P] \nINNER JOIN [Authors] ON [Authors].[Id] = [P].[AuthorId] WHERE [Authors].[Id] = 5", c[EngineCodes.SqlServer]);
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)