-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathExecuteTests.cs
More file actions
68 lines (56 loc) · 1.41 KB
/
ExecuteTests.cs
File metadata and controls
68 lines (56 loc) · 1.41 KB
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
62
63
64
65
66
67
68
using NUnit.Framework;
using System;
using System.Data;
using Microsoft.Data.SqlClient;
using unQuery.SqlTypes;
namespace unQuery.Tests
{
public class ExecuteTests : TestFixture
{
[Test]
public void StoredProcedure()
{
DB.Execute("CREATE TABLE XYZ (A int)");
DB.Execute("sp_rename", new {
objname = Col.NVarChar("XYZ"),
newname = Col.NVarChar("ABC")
}, new QueryOptions {
CommandType = CommandType.StoredProcedure
});
DB.Execute("DROP TABLE ABC");
}
[Test]
public void EmptySql()
{
Assert.Throws<InvalidOperationException>(() => DB.Execute(""));
string x = null;
Assert.Throws<InvalidOperationException>(() => DB.Execute(x));
}
[Test]
public void WithRowsModified()
{
var result = DB.Execute("UPDATE Persons SET Name = Name");
Assert.AreEqual(5, result);
}
[Test]
public void WithParameters()
{
var result = DB.Execute("UPDATE Persons SET Name = Name, Age = Age WHERE Name = @Name AND Age = @Age", new {
Age = 25,
Name = Col.NVarChar("Daniel Gallagher", 128)
});
Assert.AreEqual(1, result);
}
[Test]
public void WithNoRowsModified()
{
var result = DB.Execute("UPDATE Persons SET Name = Name WHERE 1=0");
Assert.AreEqual(0, result);
}
[Test]
public void ThrowsSqlException()
{
Assert.Throws<SqlException>(() => DB.Execute("x"));
}
}
}