-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathTestBlueprints.fs
More file actions
110 lines (99 loc) · 4.02 KB
/
Copy pathTestBlueprints.fs
File metadata and controls
110 lines (99 loc) · 4.02 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
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
103
104
105
106
107
108
109
110
module Rezoom.SQL.Test.Blueprints
open NUnit.Framework
open Rezoom.SQL.Mapping
open Rezoom.SQL.Mapping.CodeGeneration
open System
// Shim to make these tests work without having to specify a custom mapping.
module Blueprint =
let ofType (ty) =
Rezoom.SQL.Mapping.Blueprint.ofType UserTypeLibrary.Empty ty
type Folder =
{
Id : int
ParentFolder : Folder
ChildFolders : Folder list
}
[<Test>]
let ``folder blueprint makes sense`` () =
let blue = Blueprint.ofType typeof<Folder>
match blue.Cardinality with
| One { Shape = Composite folder } ->
match folder.Columns.["ParentFolder"].ReverseRelationship.Value with
| None -> failwith "No reverse relationship for parent folder"
| Some childFolders ->
Assert.That("ChildFolders".Equals(childFolders.Name, StringComparison.OrdinalIgnoreCase))
Assert.That(obj.ReferenceEquals(childFolders, folder.Columns.["ChildFolders"]))
match folder.Columns.["ChildFolders"].ReverseRelationship.Value with
| None -> failwith "No reverse relationship for child folders"
| Some parent ->
Assert.That("ParentFolder".Equals(parent.Name, StringComparison.OrdinalIgnoreCase))
| _ -> failwith "Wrong cardinality/shape"
type UserFriendMap =
{
Friend1 : User
Friend2 : User
}
and User =
{
Id : int
Friend1Maps : UserFriendMap list
Friend2Maps : UserFriendMap list
}
[<Test>]
let ``user blueprint makes sense`` () =
let blue = Blueprint.ofType typeof<User>
match blue.Cardinality with
| One { Shape = Composite user } ->
match user.Columns.["Friend1Maps"].ReverseRelationship.Value with
| None -> failwith "No reverse relationship for friend1maps"
| Some friend1Maps ->
Assert.That("Friend1".Equals(friend1Maps.Name, StringComparison.OrdinalIgnoreCase))
match user.Columns.["Friend2Maps"].ReverseRelationship.Value with
| None -> failwith "No reverse relationship for friend2maps"
| Some friend2Maps ->
Assert.That("Friend2".Equals(friend2Maps.Name, StringComparison.OrdinalIgnoreCase))
| _ -> failwith "Wrong cardinality/shape"
[<Test>]
let ``friend map blueprint makes sense`` () =
let blue = Blueprint.ofType typeof<UserFriendMap>
match blue.Cardinality with
| One { Shape = Composite friendMap } ->
match friendMap.Columns.["Friend1"].ReverseRelationship.Value with
| None -> failwith "No reverse relationship for friend1"
| Some friend1Maps ->
Assert.That("Friend1Maps".Equals(friend1Maps.Name, StringComparison.OrdinalIgnoreCase))
match friendMap.Columns.["Friend2"].ReverseRelationship.Value with
| None -> failwith "No reverse relationship for friend1"
| Some friend2Maps ->
Assert.That("Friend2Maps".Equals(friend2Maps.Name, StringComparison.OrdinalIgnoreCase))
| _ -> failwith "Wrong cardinality/shape"
type Foo =
{
FooId : int
ChildBars : Bar array
}
and Bar =
{
BarId : int
ParentFoo : Foo
}
[<Test>]
let ``foo blueprint makes sense`` () =
let blue = Blueprint.ofType typeof<Foo>
match blue.Cardinality with
| One { Shape = Composite fooMap } ->
match fooMap.Columns.["ChildBars"].ReverseRelationship.Value with
| None -> failwith "No reverse relationship for ChildBars"
| Some parentFoo ->
Assert.That("ParentFoo".Equals(parentFoo.Name, StringComparison.OrdinalIgnoreCase))
| _ -> failwith "Wrong cardinality/shape"
[<Test>]
let ``bar blueprint makes sense`` () =
let blue = Blueprint.ofType typeof<Bar>
match blue.Cardinality with
| One { Shape = Composite barMap } ->
match barMap.Columns.["ParentFoo"].ReverseRelationship.Value with
| None -> failwith "No reverse relationship for ParentFoo"
| Some childBars ->
Assert.That("ChildBars".Equals(childBars.Name, StringComparison.OrdinalIgnoreCase))
| _ -> failwith "Wrong cardinality/shape"