Skip to content

Commit

Permalink
feat(conf): new conf
Browse files Browse the repository at this point in the history
  • Loading branch information
natalie-o-perret authored Jan 7, 2021
2 parents f9352d6 + 7b34120 commit 1d2685a
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 77 deletions.
2 changes: 1 addition & 1 deletion Vp.FSharp.Sql.Tests/Mocks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ let makeDeps (valToParam: (string -> 'DbType -> 'DbParameter) option) =
ExecuteReaderAsync = (fun cmd -> cmd.ExecuteReaderAsync)
DbValueToParameter = valToParam |> Option.defaultValue (fun _ _ -> failwith "") }

let makeGlobalConf logger =
let makeConf logger =
{ DefaultLogger = logger }

let makeReader data _ =
Expand Down
16 changes: 8 additions & 8 deletions Vp.FSharp.Sql.Tests/SqlCommand for executeNonQuery should.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ let ``open and then close the connection if initially closed`` () =
Mocks.NonQuery 0
|> Mocks.makeConnection "toto" ConnectionState.Closed openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf None
let conf = Mocks.makeConf None
let! outcome =
SqlCommand.text "update"
|> SqlCommand.noLogger
|> SqlCommand.executeNonQuery connection deps globalConf
|> SqlCommand.executeNonQuery connection deps conf
outcome =! 0
PartialCallCounter.assertEqual callCounter 1 1
}
Expand All @@ -37,11 +37,11 @@ let ``leave the connection open if initially open`` () =
Mocks.NonQuery 1
|> Mocks.makeConnection "toto" ConnectionState.Connecting openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf None
let conf = Mocks.makeConf None
let! outcome =
SqlCommand.text "update"
|> SqlCommand.noLogger
|> SqlCommand.executeNonQuery connection deps globalConf
|> SqlCommand.executeNonQuery connection deps conf
outcome =! 1
PartialCallCounter.assertEqual callCounter 0 0
}
Expand All @@ -55,10 +55,10 @@ let ``log for all events on globalLogger if connection initially closed`` () =
Mocks.NonQuery 2
|> Mocks.makeConnection "toto" ConnectionState.Closed openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf (Some loggerCallback)
let conf = Mocks.makeConf (Some loggerCallback)
let! outcome =
SqlCommand.text "update"
|> SqlCommand.executeNonQuery connection deps globalConf
|> SqlCommand.executeNonQuery connection deps conf
outcome =! 2
FullCallCounter.assertEqual callCounter 1 1 1 1 1 1
}
Expand All @@ -72,10 +72,10 @@ let ``log just command events on globalLogger if connection initially not closed
Mocks.NonQuery 3
|> Mocks.makeConnection "toto" ConnectionState.Connecting openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf (Some loggerCallback)
let conf = Mocks.makeConf (Some loggerCallback)
let! outcome =
SqlCommand.text "update"
|> SqlCommand.executeNonQuery connection deps globalConf
|> SqlCommand.executeNonQuery connection deps conf
outcome =! 3
FullCallCounter.assertEqual callCounter 0 0 0 0 1 1
}
16 changes: 8 additions & 8 deletions Vp.FSharp.Sql.Tests/SqlCommand for executeScalar should.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ let ``open and then close the connection if initially closed`` () =
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Closed openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf None
let conf = Mocks.makeConf None
let! outcome =
SqlCommand.text "select 1"
|> SqlCommand.noLogger
|> SqlCommand.executeScalar connection deps globalConf
|> SqlCommand.executeScalar connection deps conf
outcome =! 14
PartialCallCounter.assertEqual callCounter 1 1
}
Expand All @@ -57,11 +57,11 @@ let ``leave the connection open if initially open`` () =
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Connecting openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf None
let conf = Mocks.makeConf None
let! outcome =
SqlCommand.text "select 1"
|> SqlCommand.noLogger
|> SqlCommand.executeScalar connection deps globalConf
|> SqlCommand.executeScalar connection deps conf
outcome =! 15
PartialCallCounter.assertEqual callCounter 0 0
}
Expand All @@ -84,10 +84,10 @@ let ``log for all events on globalLogger if connection initially closed`` () =
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Closed openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf (Some loggerCallback)
let conf = Mocks.makeConf (Some loggerCallback)
let! outcome =
SqlCommand.text "select 1"
|> SqlCommand.executeScalar connection deps globalConf
|> SqlCommand.executeScalar connection deps conf
outcome =! 16
FullCallCounter.assertEqual callCounter 1 1 1 1 1 1
}
Expand All @@ -110,10 +110,10 @@ let ``log for just command events on globalLogger if connection initially not cl
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Connecting openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf (Some loggerCallback)
let conf = Mocks.makeConf (Some loggerCallback)
let! outcome =
SqlCommand.text "select 1"
|> SqlCommand.executeScalar connection deps globalConf
|> SqlCommand.executeScalar connection deps conf
outcome =! 17
FullCallCounter.assertEqual callCounter 0 0 0 0 1 1
}
32 changes: 16 additions & 16 deletions Vp.FSharp.Sql.Tests/SqlCommand for executeScalarOrNone should.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ let ``open and then close the connection if initially closed`` () =
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Closed openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf None
let conf = Mocks.makeConf None
let! outcome =
SqlCommand.text "select 1"
|> SqlCommand.noLogger
|> SqlCommand.executeScalarOrNone connection deps globalConf
|> SqlCommand.executeScalarOrNone connection deps conf
outcome.IsSome =! true
outcome
|> Option.defaultValue 42
Expand Down Expand Up @@ -62,11 +62,11 @@ let ``leave the connection open if initially not closed`` () =
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Connecting openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf None
let conf = Mocks.makeConf None
let! outcome =
SqlCommand.text "select 1"
|> SqlCommand.noLogger
|> SqlCommand.executeScalarOrNone connection deps globalConf
|> SqlCommand.executeScalarOrNone connection deps conf
outcome.IsSome =! true
outcome
|> Option.defaultValue 42
Expand All @@ -93,10 +93,10 @@ let ``log for all events on globalLogger if connection initially closed`` () =
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Closed openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf (Some loggerCallback)
let conf = Mocks.makeConf (Some loggerCallback)
let! outcome =
SqlCommand.text "select 1"
|> SqlCommand.executeScalarOrNone connection deps globalConf
|> SqlCommand.executeScalarOrNone connection deps conf
outcome.IsSome =! true
outcome
|> Option.defaultValue 42
Expand All @@ -122,10 +122,10 @@ let ``log for just command events on globalLogger if connection initially not cl
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Connecting openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf (Some loggerCallback)
let conf = Mocks.makeConf (Some loggerCallback)
let! outcome =
SqlCommand.text "select 1"
|> SqlCommand.executeScalarOrNone connection deps globalConf
|> SqlCommand.executeScalarOrNone connection deps conf
outcome.IsSome =! true
outcome
|> Option.defaultValue 42
Expand Down Expand Up @@ -153,11 +153,11 @@ let ``open and then close connection if initially closed and retrieve None`` ()
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Closed openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf None
let conf = Mocks.makeConf None
let! outcome =
SqlCommand.text "select 1"
|> SqlCommand.noLogger
|> SqlCommand.executeScalarOrNone connection deps globalConf
|> SqlCommand.executeScalarOrNone connection deps conf
outcome.IsNone =! true
PartialCallCounter.assertEqual callCounter 1 1
}
Expand All @@ -181,11 +181,11 @@ let ``leave connection open if initially not closed and retrieve None`` () =
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Connecting openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf None
let conf = Mocks.makeConf None
let! outcome =
SqlCommand.text "select 1"
|> SqlCommand.noLogger
|> SqlCommand.executeScalarOrNone connection deps globalConf
|> SqlCommand.executeScalarOrNone connection deps conf
outcome.IsNone =! true
PartialCallCounter.assertEqual callCounter 0 0
}
Expand All @@ -208,10 +208,10 @@ let ``log for all events on globalLogger if connection initially closed and retr
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Closed openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf (Some loggerCallback)
let conf = Mocks.makeConf (Some loggerCallback)
let! outcome =
SqlCommand.text "select 1"
|> SqlCommand.executeScalarOrNone connection deps globalConf
|> SqlCommand.executeScalarOrNone connection deps conf
outcome.IsNone =! true
FullCallCounter.assertEqual callCounter 1 1 1 1 1 1
}
Expand All @@ -234,10 +234,10 @@ let ``log for just command events on globalLogger if connection initially not cl
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Connecting openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf (Some loggerCallback)
let conf = Mocks.makeConf (Some loggerCallback)
let! outcome =
SqlCommand.text "select 1"
|> SqlCommand.executeScalarOrNone connection deps globalConf
|> SqlCommand.executeScalarOrNone connection deps conf
outcome.IsNone =! true
FullCallCounter.assertEqual callCounter 0 0 0 0 1 1
}
28 changes: 14 additions & 14 deletions Vp.FSharp.Sql.Tests/SqlCommand for queryAsyncSeq should.fs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ let ``open and then close the connection if initially closed and access value by
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Closed openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf None
let conf = Mocks.makeConf None
let outcome =
SqlCommand.text "select 1"
|> SqlCommand.noLogger
|> SqlCommand.queryAsyncSeq connection deps globalConf
|> SqlCommand.queryAsyncSeq connection deps conf
(readValueByFieldName ([2;1;0] |> toFieldNames))
|> AsyncSeq.toListSynchronously
|> List.sortBy (fun values -> snd values.[0])
Expand Down Expand Up @@ -105,11 +105,11 @@ let ``open and then close the connection if initially closed and access value by
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Closed openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf None
let conf = Mocks.makeConf None
let outcome =
SqlCommand.text "select 1"
|> SqlCommand.noLogger
|> SqlCommand.queryAsyncSeq connection deps globalConf
|> SqlCommand.queryAsyncSeq connection deps conf
(readValueByIndex [2;1;0])
|> AsyncSeq.toListSynchronously
|> List.sortBy (fun values -> values.[0])
Expand Down Expand Up @@ -146,11 +146,11 @@ let ``open and then close the connection if initially closed and access valueOrN
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Closed openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf None
let conf = Mocks.makeConf None
let outcome =
SqlCommand.text "select 1"
|> SqlCommand.noLogger
|> SqlCommand.queryAsyncSeq connection deps globalConf
|> SqlCommand.queryAsyncSeq connection deps conf
(readValueOrNoneByFieldName (toFieldNames [2;1;0]))
|> AsyncSeq.toListSynchronously
|> List.sortBy (fun values -> snd values.[0])
Expand Down Expand Up @@ -187,11 +187,11 @@ let ``open and then close connection if initially closed and access valueOrNone
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Closed openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf None
let conf = Mocks.makeConf None
let outcome =
SqlCommand.text "select 1"
|> SqlCommand.noLogger
|> SqlCommand.queryAsyncSeq connection deps globalConf
|> SqlCommand.queryAsyncSeq connection deps conf
(readValueOrNoneByIndex [2;1;0])
|> AsyncSeq.toListSynchronously
|> List.sortBy (fun values -> values.[0])
Expand Down Expand Up @@ -228,11 +228,11 @@ let ``leave the connection open if initially not closed with access valueOrNone
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Connecting openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf None
let conf = Mocks.makeConf None
let outcome =
SqlCommand.text "select 1"
|> SqlCommand.noLogger
|> SqlCommand.queryAsyncSeq connection deps globalConf
|> SqlCommand.queryAsyncSeq connection deps conf
(readValueOrNoneByIndex [2;1;0])
|> AsyncSeq.toListSynchronously
|> List.sortBy (fun values -> values.[0])
Expand Down Expand Up @@ -269,10 +269,10 @@ let ``log all events on globalLogger if connection initially closed with access
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Closed openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf (Some loggerCallback)
let conf = Mocks.makeConf (Some loggerCallback)
let outcome =
SqlCommand.text "select 1"
|> SqlCommand.queryAsyncSeq connection deps globalConf
|> SqlCommand.queryAsyncSeq connection deps conf
(readValueOrNoneByIndex [2;1;0])
|> AsyncSeq.toListSynchronously
|> List.sortBy (fun values -> values.[0])
Expand Down Expand Up @@ -309,10 +309,10 @@ let ``log for just command events on globalLogger if connection initially not cl
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Connecting openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf (Some loggerCallback)
let conf = Mocks.makeConf (Some loggerCallback)
let outcome =
SqlCommand.text "select 1"
|> SqlCommand.queryAsyncSeq connection deps globalConf
|> SqlCommand.queryAsyncSeq connection deps conf
(readValueOrNoneByIndex [2;1;0])
|> AsyncSeq.toListSynchronously
|> List.sortBy (fun values -> values.[0])
Expand Down
12 changes: 6 additions & 6 deletions Vp.FSharp.Sql.Tests/SqlCommand for querySetListN should.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ let ``have querySetList should open and then close the connection if initially c
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Closed openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf None
let conf = Mocks.makeConf None
let! r0 =
SqlCommand.text "select 1"
|> SqlCommand.noLogger
|> SqlCommand.querySetList connection
deps globalConf
deps conf
(readValueByIndex columnsIndex 0)
r0.Length =! 2
r0 =! ([1..6] |> List.splitInto 2)
Expand All @@ -68,11 +68,11 @@ let ``have querySetList2 should open and then close the connection if initially
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Closed openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf None
let conf = Mocks.makeConf None
let! (r0, r1) =
SqlCommand.text "select 1"
|> SqlCommand.noLogger
|> SqlCommand.querySetList2 connection deps globalConf
|> SqlCommand.querySetList2 connection deps conf
(readValueByIndex columnsIndex 0)
(readValueByIndex columnsIndex 1)
r0.Length =! 2
Expand All @@ -99,11 +99,11 @@ let ``have querySetList3 open and then close the connection if initially closed
Mocks.Reader (Mocks.makeReader data)
|> Mocks.makeConnection "toto" ConnectionState.Closed openCallback closeCallback
let deps = Mocks.makeDeps None
let globalConf = Mocks.makeGlobalConf None
let conf = Mocks.makeConf None
let! (r0, r1, r2) =
SqlCommand.text "select 1"
|> SqlCommand.noLogger
|> SqlCommand.querySetList3 connection deps globalConf
|> SqlCommand.querySetList3 connection deps conf
(readValueByIndex columnsIndex 0)
(readValueByIndex columnsIndex 1)
(readValueByIndex columnsIndex 2)
Expand Down
Loading

0 comments on commit 1d2685a

Please sign in to comment.