forked from ThatRendle/Simple.Data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionTest.cs
More file actions
67 lines (54 loc) · 2.53 KB
/
FunctionTest.cs
File metadata and controls
67 lines (54 loc) · 2.53 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Simple.Data.IntegrationTest.Query
{
using Mocking.Ado;
using NUnit.Framework;
[TestFixture]
public class FunctionTest : DatabaseIntegrationContext
{
protected override void SetSchema(MockSchemaProvider schemaProvider)
{
schemaProvider.SetTables(new[] { "dbo", "Users", "BASE TABLE" });
schemaProvider.SetColumns(new[] { "dbo", "Users", "Name" },
new[] { "dbo", "Users", "Password" });
}
private const string usersColumns = "[dbo].[Users].[Name], [dbo].[Users].[Password]";
[Test]
public void SubstringIsEnteredCorrectlyInFindAll()
{
const string expected = @"select [dbo].[users].[name],[dbo].[users].[password] from [dbo].[users] where substring([dbo].[users].[name],@p1,@p2) = @p3";
EatException<InvalidOperationException>(() =>
_db.Users.FindAll(_db.Users.Name.Substring(0, 1) == "A").ToList());
GeneratedSqlIs(expected);
Parameter(0).Is(0);
Parameter(1).Is(1);
Parameter(2).Is("A");
}
[Test]
public void SubstringIsEnteredCorrectlyInFindOne()
{
const string expected = @"select " + usersColumns + " from [dbo].[users] where substring([dbo].[users].[name],@p1,@p2) = @p3";
_db.Users.Find(_db.Users.Name.Substring(0, 1) == "A");
GeneratedSqlIs(expected);
Parameter(0).Is(0);
Parameter(1).Is(1);
Parameter(2).Is("A");
}
[Test]
public void GroupingAndOrderingOnFunction()
{
const string expected =
@"select substring([dbo].[users].[name],@p1,@p2) as [foo],max(substring([dbo].[users].[name],@p3,@p4)) as [bar] from [dbo].[users] group by substring([dbo].[users].[name],@p5,@p6) order by bar desc";
var column1 = _db.Users.Name.Substring(0, 5).As("Foo");
var column2 = _db.Users.Name.Substring(5, 5).Max().As("Bar");
EatException<InvalidOperationException>( () => _db.Users.All()
.Select(column1, column2)
.OrderByBarDescending()
.ToList());
GeneratedSqlIs(expected);
}
}
}