SaturnFramework / Saturn

Opinionated, web development framework for F# which implements the server-side, functional MVC pattern
https://saturnframework.org
MIT License
705 stars 108 forks source link

Integration testing #229

Closed joshuacrew closed 4 years ago

joshuacrew commented 4 years ago

I was wondering if there is a defined way for integration testing saturn applications?

I have been trying to use TestServer() to test my application routes, but this involves setting up WebHostBuilder() in the conventional ASP.NET Core way which doesn't seem to work well for Saturn apps.

My Program:

let application = application {
    use_router webApp
    app_config appConfig
    service_config serviceConfig
}

My test :

let createHost() =
    WebHostBuilder()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .Configure(Action<IApplicationBuilder> appConfig)
        .ConfigureServices(Action<IServiceCollection> (fun _  -> serviceConfig |> ignore))
        .ConfigureTestServices(Action<IServiceCollection> testServices)
let server = new TestServer(createHost())

This gives the error: Type mismatch. Expecting a 'IApplicationBuilder -> unit' but given a 'IApplicationBuilder -> IApplicationBuilder' on the Configure() method.

How can I solve this problem without reimplementing my appConfig in the test project?

Apologies if this question has a very obvious answer but I am very new to Saturn.

Krzysztof-Cieslak commented 4 years ago

I haven't really used ASP TetsServer thingy... but from an error message you get - wouldn't .Configure(Action<IApplicationBuilder> (appConfig >> ignore)) help?

joshuacrew commented 4 years ago

That worked great! Thank you very much for having a look at my issue. Now to learn about the function composition operator....