Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/SqlClient.DesignTime/DesignTimeConnectionString.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ type internal DesignTimeConnectionString =
| NameInConfig of name: string * value: string * provider: string

static member Parse(s: string, resolutionFolder, fileName) =
match s.Trim().Split([|'='|], 2, StringSplitOptions.RemoveEmptyEntries) with
// Use StringSplitOptions.None so that the empty-string guard actually fires:
// RemoveEmptyEntries turns "" into [||] which skips the [|""|] branch.
match s.Trim().Split([|'='|], 2, StringSplitOptions.None) with
| [| "" |] -> invalidArg "ConnectionStringOrName" "Value is empty!"
| [| prefix; tail |] when prefix.Trim().ToLower() = "name" ->
let name = tail.Trim()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,37 @@ let RuntimeConfig() =
let x = DesignTimeConnectionString.Parse("name=AdventureWorks", __SOURCE_DIRECTORY__, "app.config")
let actual = Linq.RuntimeHelpers.LeafExpressionConverter.EvaluateQuotation( x.RunTimeValueExpr(isHostedExecution = false)) |> unbox
Assert.Equal<string>( adventureWorks, actual)

// ---- Edge case tests for Parse ----

[<Fact>]
let ``Empty string throws ArgumentException`` () =
// The [| "" |] guard in Parse must fire β€” not be skipped by RemoveEmptyEntries.
Assert.Throws<System.ArgumentException>(
fun () -> DesignTimeConnectionString.Parse("", resolutionFolder = "", fileName = "") |> box
) |> ignore

[<Fact>]
let ``Whitespace-only string throws ArgumentException`` () =
Assert.Throws<System.ArgumentException>(
fun () -> DesignTimeConnectionString.Parse(" ", resolutionFolder = "", fileName = "") |> box
) |> ignore

[<Fact>]
let ``Literal connection string is parsed correctly`` () =
let cs = "Data Source=.;Initial Catalog=Test;Integrated Security=True"
let x = DesignTimeConnectionString.Parse(cs, resolutionFolder = "", fileName = "")
match x with
| Literal value -> Assert.Equal<string>(cs, value)
| _ -> failwith "Expected Literal"

[<Fact>]
let ``Literal IsDefinedByLiteral is true`` () =
let x = DesignTimeConnectionString.Parse("Server=.;Database=Test", resolutionFolder = "", fileName = "")
Assert.True(x.IsDefinedByLiteral)

[<Fact>]
let ``Literal Value returns the connection string`` () =
let cs = "Server=.;Database=Northwind"
let x = DesignTimeConnectionString.Parse(cs, resolutionFolder = "", fileName = "")
Assert.Equal<string>(cs, x.Value)
Loading