-
-
Notifications
You must be signed in to change notification settings - Fork 514
/
Copy pathParameterTypeTests.cs
52 lines (45 loc) · 1.8 KB
/
ParameterTypeTests.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
using System;
using System.Collections.Generic;
using System.Globalization;
using SqlKata.Compilers;
using Xunit;
using System.Collections;
using SqlKata.Tests.Infrastructure;
namespace SqlKata.Tests
{
public class ParameterTypeTests : TestSupport
{
public enum EnumExample
{
First,
Second,
Third,
}
public class ParameterTypeGenerator : IEnumerable<object[]>
{
private readonly List<object[]> _data = new List<object[]>
{
new object[] {"1", 1},
new object[] {Convert.ToSingle("10.5", CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture), 10.5},
new object[] {"-2", -2},
new object[] {Convert.ToSingle("-2.8", CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture), -2.8},
new object[] {"cast(1 as bit)", true},
new object[] {"cast(0 as bit)", false},
new object[] {"'2018-10-28 19:22:00'", new DateTime(2018, 10, 28, 19, 22, 0)},
new object[] {"0 /* First */", EnumExample.First},
new object[] {"1 /* Second */", EnumExample.Second},
new object[] {"'a string'", "a string"},
};
public IEnumerator<object[]> GetEnumerator() => _data.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
[Theory]
[ClassData(typeof(ParameterTypeGenerator))]
public void CorrectParameterTypeOutput(string rendered, object input)
{
var query = new Query("Table").Where("Col", input);
var c = Compile(query);
Assert.Equal($"SELECT * FROM [Table] WHERE [Col] = {rendered}", c[EngineCodes.SqlServer]);
}
}
}