-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathTestManyPrimitives.fs
102 lines (95 loc) · 2.78 KB
/
TestManyPrimitives.fs
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
module Rezoom.SQL.Test.ManyPrimitives
open NUnit.Framework
open FsUnit
open Rezoom.SQL.Mapping
open Rezoom.SQL.Mapping.CodeGeneration
open System
open System.Collections.Generic
type Friend =
{ Id : int
Name : string
Aliases : string array
}
[<Test>]
let ``read friend`` () =
let colMap =
[| "Id", ColumnType.Int32
"Name", ColumnType.String
"Aliases", ColumnType.String
|] |> ColumnMap.Parse
let rows =
[ ObjectRow(3, "Robert", "Bob")
ObjectRow(3, "Robert", "Bobby")
ObjectRow(3, "Robert", "Rob")
ObjectRow(3, "Robert", "Robby")
]
let reader = ReaderTemplate<Friend>.Template().CreateReader()
reader.ProcessColumns(colMap)
for row in rows do
reader.Read(row)
let friend = reader.ToEntity()
Assert.IsNotNull(friend)
Assert.AreEqual(3, friend.Id)
Assert.AreEqual("Robert", friend.Name)
Assert.AreEqual(4, friend.Aliases.Length)
Assert.IsTrue([| "Bob"; "Bobby"; "Rob"; "Robby" |] = friend.Aliases)
type StringPair = // notice no key properties
{ Left : string
Right : string
}
[<Test>]
let ``read string pairs`` () =
let colMap =
[| "Left", ColumnType.String
"Right", ColumnType.String
|] |> ColumnMap.Parse
let rows =
[ ObjectRow("a", "1")
ObjectRow("b", "2")
ObjectRow("b", "2") // duplicate should appear in results
ObjectRow("a", "1")
]
let reader = ReaderTemplate<StringPair array>.Template().CreateReader()
reader.ProcessColumns(colMap)
for row in rows do
reader.Read(row)
let pairs = reader.ToEntity()
Assert.AreEqual
( [| { Left = "a"; Right = "1" }
{ Left = "b"; Right = "2" }
{ Left = "b"; Right = "2" }
{ Left = "a"; Right = "1" }
|]
, pairs
)
[<BlueprintNoKey>]
type IgnoredIds =
{ [<BlueprintKey>]
Le : string
Ri : string
}
[<Test>]
let ``ignored ids`` () =
let colMap =
[| "Le", ColumnType.String
"Ri", ColumnType.String
|] |> ColumnMap.Parse
let rows =
[ ObjectRow("a", "1")
ObjectRow("b", "2")
ObjectRow("b", "2") // duplicate should appear in results
ObjectRow("a", "1")
]
let reader = ReaderTemplate<IgnoredIds IReadOnlyList>.Template().CreateReader()
reader.ProcessColumns(colMap)
for row in rows do
reader.Read(row)
let pairs = reader.ToEntity()
Assert.AreEqual
( [| { Le = "a"; Ri = "1" }
{ Le = "b"; Ri = "2" }
{ Le = "b"; Ri = "2" }
{ Le = "a"; Ri = "1" }
|]
, pairs |> Array.ofSeq
)