Skip to content

Instantly share code, notes, and snippets.

@mFingers
Created January 4, 2016 21:29
Show Gist options
  • Save mFingers/3d33b055dbcc5fdd5407 to your computer and use it in GitHub Desktop.
Save mFingers/3d33b055dbcc5fdd5407 to your computer and use it in GitHub Desktop.
Example of testing the internals of SQLProvider

This is what I was thinking along the lines of testing the "internals" of SQLProvider. queryTemplate acts as a stub that we can use to create different query conditions.

However, in order to make this work, I had to expose a number of types and methods by removing the internal access modifier. I'm not sure how that feels for you. I don't understand the architecture well enough yet to make any kind of opinion.

But that stuff aside, would something like this be desirable?

module ``Generate FROM clause``
    open NUnit.Framework
    open FSharp.Data.Sql.Common
    open FSharp.Data.Sql.Providers
    open FSharp.Data.Sql.Schema

    let theTable = {
        Schema = "dbo"
        Name = "Foo"
        Type = "theType"  //Not sure what this is for
    }

    //I see how this is used, but I could use some background on where the key and values come from.
    let projections = new System.Collections.Generic.Dictionary<string, ResizeArray<string>>()

    let queryTemplate = {
                            Filters = []
                            Links = []
                            Aliases = Map.empty
                            Ordering = []
                            Projection = None
                            Distinct = false
                            UltimateChild = None
                            Skip = None
                            Take = None
                            Count = false
                        }

    [<Test>]
    let ``Single table`` () =
        let provider = MSSqlServerProvider() :> ISqlProvider
        let query = provider.GenerateQueryText (queryTemplate, "", theTable, projections)
        Assert.That(query, Is.EqualTo(""))

This actually works, in that GenerateQueryText returns a value: ("SELECT FROM [dbo].[Foo] as []" , System.Collections.Generic.List``1[System.Data.IDbDataParameter])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment