-
Notifications
You must be signed in to change notification settings - Fork 3
/
SqlLinterTests.cs
61 lines (54 loc) · 1.91 KB
/
SqlLinterTests.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
using System.IO;
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using static FunnyDB.Dialect;
namespace FunnyDB.Test
{
[TestFixture]
public class SqlLinterTests
{
[Test]
public void SqlLinter_ShouldFoundErrors()
{
var codeWithError = @"
[Test]
public void SqlQuery_ShouldUseNamedParameters()
{
var accountId = (777, ""account_id"");
var query = sql(() => $@""
|SELECT event_time, balance
| FROM charges
| WHERE account_id = {p(accountId)}
| UNION ALL
|SELECT event_time, balance
| FROM withdraws
| WHERE account_id = {accountId}"");
";
SqlQueryLinter.Validate(codeWithError, out var errors).Should().BeFalse();
errors.Count.Should().Be(1);
errors.First().Line.Should().Be(14);
errors.First().Position.Should().Be(30);
}
[Test]
public void SqlLinter_ShouldFoundErrorsInFolder()
{
var accountId = (777, "account_id");
sql(() => $@"
|SELECT event_time, balance
| FROM charges
| WHERE account_id = {p(accountId)}
| UNION ALL
|SELECT event_time, balance
| FROM withdraws
| WHERE account_id = {accountId}"); // <----------- ERROR RIGHT HERE
var assemblyPath = GetType().Assembly.Location;
var projectFolder = Enumerable.Range(0, 4).Aggregate(assemblyPath, (p, _) => Path.GetDirectoryName(p));
SqlQueryLinter.ValidateFolder(projectFolder, out var errors).Should().BeFalse();
errors.Count.Should().Be(1);
errors.First().Path.Should().Be(Path.Combine(projectFolder, "SqlLinterTests.cs"));
errors.First().Error.Line.Should().Be(49);
errors.First().Error.Position.Should().Be(38);
}
}
}