Skip to content

Commit

Permalink
Support navigation property queries in mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorium committed Apr 9, 2024
1 parent 653b2be commit 8e12e53
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
3 changes: 3 additions & 0 deletions docs/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 1.3.35 - 09.04.2024
* Support navigation property queries in mocks

### 1.3.34 - 04.04.2024
* Minor performance improvement

Expand Down
8 changes: 4 additions & 4 deletions src/Common/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ open System.Reflection
[<assembly: AssemblyTitleAttribute("SQLProvider")>]
[<assembly: AssemblyProductAttribute("SQLProvider")>]
[<assembly: AssemblyDescriptionAttribute("Type providers for SQL database access.")>]
[<assembly: AssemblyVersionAttribute("1.3.33")>]
[<assembly: AssemblyFileVersionAttribute("1.3.33")>]
[<assembly: AssemblyVersionAttribute("1.3.35")>]
[<assembly: AssemblyFileVersionAttribute("1.3.35")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "SQLProvider"
let [<Literal>] AssemblyProduct = "SQLProvider"
let [<Literal>] AssemblyDescription = "Type providers for SQL database access."
let [<Literal>] AssemblyVersion = "1.3.33"
let [<Literal>] AssemblyFileVersion = "1.3.33"
let [<Literal>] AssemblyVersion = "1.3.35"
let [<Literal>] AssemblyFileVersion = "1.3.35"
28 changes: 25 additions & 3 deletions src/SQLProvider.Runtime/SqlRuntime.Common.fs
Original file line number Diff line number Diff line change
Expand Up @@ -988,8 +988,12 @@ module public OfflineTools =
let CreateMockSqlDataContext<'T> (dummydata: Map<string,obj>) =
let pendingChanges = System.Collections.Concurrent.ConcurrentDictionary<SqlEntity, DateTime>()
let x = { new ISqlDataContext with
member this.CallSproc(arg1: FSharp.Data.Sql.Schema.RunTimeSprocDefinition, arg2: FSharp.Data.Sql.Schema.QueryParameter array, arg3: obj array): obj = raise (System.NotImplementedException())
member this.CallSprocAsync(arg1: FSharp.Data.Sql.Schema.RunTimeSprocDefinition, arg2: FSharp.Data.Sql.Schema.QueryParameter array, arg3: obj array): Threading.Tasks.Task<SqlEntity> = raise (System.NotImplementedException())
member this.CallSproc(arg1: FSharp.Data.Sql.Schema.RunTimeSprocDefinition, arg2: FSharp.Data.Sql.Schema.QueryParameter array, arg3: obj array) =
// Note: Calling Sproc result on mock will still fail because SqlEntity "ResultSet" is null and not an array.
SqlEntity(this, arg1.Name.FullName, Array.empty |> ColumnLookup)
member this.CallSprocAsync(arg1: FSharp.Data.Sql.Schema.RunTimeSprocDefinition, arg2: FSharp.Data.Sql.Schema.QueryParameter array, arg3: obj array) =
// Note: Calling Sproc result on mock will still fail because SqlEntity "ResultSet" is null and not an array.
task { return SqlEntity(this, arg1.Name.FullName, Array.empty |> ColumnLookup) }
member this.ClearPendingChanges(): unit = pendingChanges.Clear()
member this.CommandTimeout: Option<int> = None
member this.CreateConnection(): Data.IDbConnection = raise (System.NotImplementedException())
Expand All @@ -1003,7 +1007,25 @@ module public OfflineTools =
let _, cols = makeColumns tableData
new SqlEntity(this, arg1, cols)
| false, _ -> new SqlEntity(this, arg1, Seq.empty |> ColumnLookup)
member this.CreateRelated(arg1: SqlEntity, arg2: string, arg3: string, arg4: string, arg5: string, arg6: string, arg7: RelationshipDirection): IQueryable<SqlEntity> = raise (System.NotImplementedException())
member this.CreateRelated(inst: SqlEntity, arg2: string, pe: string, pk: string, fe: string, fk: string, direction: RelationshipDirection): IQueryable<SqlEntity> =
if direction = RelationshipDirection.Children then
match dummydata.TryGetValue fe with
| true, tableData ->
let related = createMockEntitiesDc this fe tableData
match (inst.ColumnValues |> Map.ofSeq).TryGetValue pk with
| true, relevant ->
related.Where(fun e -> e.ColumnValues |> Seq.exists(fun (k, v) -> k = fk && v = relevant))
| false, _ -> failwith ("Key not found: " + arg2 + " " + pk)
| false, _ -> failwith ("Add table to dummydata: " + fe)
else
match dummydata.TryGetValue pe with
| true, tableData ->
let related = createMockEntitiesDc this pe tableData
match (inst.ColumnValues |> Map.ofSeq).TryGetValue fk with
| true, relevant ->
related.Where(fun e -> e.ColumnValues |> Seq.exists(fun (k, v) -> k = pk && v = relevant))
| false, _ -> failwith ("Key not found: " + arg2 + " " + fk)
| false, _ -> failwith ("Add table to dummydata: " + pe)
member this.GetIndividual(arg1: string, arg2: obj): SqlEntity = raise (System.NotImplementedException())
member this.GetPendingEntities(): SqlEntity list = (CommonTasks.sortEntities pendingChanges) |> Seq.toList
member this.GetPrimaryKeyDefinition(arg1: string): string = ""
Expand Down

0 comments on commit 8e12e53

Please sign in to comment.