Skip to content

Commit 67c2e77

Browse files
committed
Port some tests to work on MS SQL
1 parent 8203501 commit 67c2e77

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

tests/NpgsqlFSharpAnalyzer.Tests/Tests.fs

+13-11
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ let tests =
7474
use db = createTestDatabase()
7575

7676
Sql.connect db.ConnectionString
77-
|> Sql.query "CREATE EXTENSION IF NOT EXISTS citext;CREATE SCHEMA test; CREATE TABLE test.articles (id BIGINT PRIMARY KEY NOT NULL,art_name CITEXT UNIQUE NOT NULL, stock BIGINT NOT NULL);"
77+
|> Sql.query "CREATE SCHEMA test CREATE TABLE test.articles (id BIGINT PRIMARY KEY NOT NULL,art_name TEXT NOT NULL, stock BIGINT NOT NULL);"
7878
|> Sql.executeNonQuery
79-
|> raiseWhenFailed
79+
|> ignore
8080

8181
match context (find "../examples/hashing/MultipleNestedModules.fs") with
8282
| None -> failwith "Could not crack project"
@@ -89,16 +89,16 @@ let tests =
8989
| Result.Ok schema ->
9090
let errors = SqlAnalysis.analyzeOperation operations.[0] db.ConnectionString schema
9191
Expect.equal 1 errors.Length "There should be one error message"
92-
Expect.stringContains errors.[0].Message "column \"x\" does not exist" "There should be an error message"
92+
Expect.stringContains errors.[0].Message "Invalid column name 'x'" "There should be an error message"
9393
}
9494

9595
test "Semantic analysis using FSX: finding SQL blocks in multiple nested modules which query a non-public schema" {
9696
use db = createTestDatabase()
9797

9898
Sql.connect db.ConnectionString
99-
|> Sql.query "CREATE EXTENSION IF NOT EXISTS citext;CREATE SCHEMA test; CREATE TABLE test.articles (id BIGINT PRIMARY KEY NOT NULL,art_name CITEXT UNIQUE NOT NULL, stock BIGINT NOT NULL);"
99+
|> Sql.query "CREATE SCHEMA test CREATE TABLE test.articles (id BIGINT PRIMARY KEY NOT NULL,art_name TEXT NOT NULL, stock BIGINT NOT NULL);"
100100
|> Sql.executeNonQuery
101-
|> raiseWhenFailed
101+
|> ignore
102102

103103
match context (find "../examples/hashing/MultipleNestedModules.fsx") with
104104
| None -> failwith "Could not crack project"
@@ -111,7 +111,7 @@ let tests =
111111
| Result.Ok schema ->
112112
let errors = SqlAnalysis.analyzeOperation operations.[0] db.ConnectionString schema
113113
Expect.equal 1 errors.Length "There should be one error message"
114-
Expect.stringContains errors.[0].Message "column \"x\" does not exist" "There should be an error message"
114+
Expect.stringContains errors.[0].Message "Invalid column name 'x'" "There should be an error message"
115115
}
116116

117117
test "Syntactic analysis: SQL block found from top-level expression in module" {
@@ -337,13 +337,14 @@ let tests =
337337
Expect.isEmpty messages "No errors returned"
338338
}
339339

340-
test "Semantic analysis: casting non-nullable columns stays non-nullable" {
340+
// https://sqlsunday.com/2019/06/05/cast-convert-makes-expressions-nullable/
341+
test "Semantic analysis: casting non-nullable columns doesn't stay non-nullable in MS SQL" {
341342
use db = createTestDatabase()
342343

343344
Sql.connect db.ConnectionString
344-
|> Sql.query "CREATE TABLE users (user_id bigserial primary key, username text not null)"
345+
|> Sql.query "CREATE TABLE users (user_id bigint identity(1,1) NOT NULL primary key, username text not null)"
345346
|> Sql.executeNonQuery
346-
|> raiseWhenFailed
347+
|> ignore
347348

348349
match context (find "../examples/hashing/castingNonNullableStaysNonNullable.fs") with
349350
| None -> failwith "Could not crack project"
@@ -354,7 +355,7 @@ let tests =
354355
| Result.Ok schema ->
355356
let blocks = SyntacticAnalysis.findSqlOperations context
356357
let messages = blocks |> List.collect (fun block -> SqlAnalysis.analyzeOperation block db.ConnectionString schema)
357-
Expect.isEmpty messages "No errors returned"
358+
Expect.equal 3 messages.Length "Three errors returned"
358359
}
359360

360361
test "Semantic analysis: incorrect queries in executeTransaction are detected" {
@@ -502,7 +503,8 @@ let tests =
502503
Expect.isFalse rolesColumn.Nullable "The column is not nullable"
503504
}
504505

505-
test "SQL schema analysis with user defined arrays" {
506+
// skip this test
507+
ptest "SQL schema analysis with user defined arrays" {
506508
use db = createTestDatabase ()
507509

508510
Sql.connect db.ConnectionString

tests/examples/hashing/castingNonNullableStaysNonNullable.fs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ open Npgsql.FSharp
55
let userIds connection =
66
connection
77
|> Sql.connect
8-
|> Sql.query "SELECT user_id::text AS useridtext FROM users"
8+
|> Sql.query "SELECT CAST(user_id as nvarchar) AS useridtext FROM users"
99
|> Sql.execute (fun read -> read.text "useridtext")
1010

1111
let moreIds connection =
1212
connection
1313
|> Sql.connect
14-
|> Sql.query "SELECT user_id::text as useridtext FROM users"
14+
|> Sql.query "SELECT CAST (user_id as nvarchar) as useridtext FROM users"
1515
|> Sql.execute (fun read -> read.text "useridtext")
1616

1717
let withoutAlias connection =
1818
connection
1919
|> Sql.connect
20-
|> Sql.query "SELECT user_id::text FROM users"
20+
|> Sql.query "SELECT CAST (user_id as nvarchar) FROM users"
2121
|> Sql.execute (fun read -> read.text "user_id")

0 commit comments

Comments
 (0)