Skip to content

Latest commit

 

History

History
95 lines (77 loc) · 2.93 KB

fsharp.md

File metadata and controls

95 lines (77 loc) · 2.93 KB

Usage in FSharp

NullValueHandling

By default DefaultValueHandling is Ignore. Since F# Option.None is treated as null, it will be ignored by default. To include Option.None use VerifierSettings.AddExtraSettings at module startup:

VerifierSettings.AddExtraSettings(fun settings ->
  settings.NullValueHandling <- NullValueHandling.Include)

snippet source | anchor

Async Qwerks

F# does not respect implicit operator conversion. SettingsTask uses implicit operator conversion to provide a fluent api in combination with an instance that can be awaited. As such SettingsTask.ToTask() needs to be awaited when used inside F#.

[<Fact>]
let MyTest () =
  async {
    do! Verifier.Verify(15)
          .ToTask() |> Async.AwaitTask
  }

snippet source | anchor

Tasks can also be used directly via a task computation expression builder, such as the ones included in Ply, TaskBuilder.fs, or (starting with F# 6.0) FSharp.Core:

[<Fact>]
let MyTaskTest () =
  task {
    do! Verifier.Verify(15)
  }

snippet source | anchor

Full tests

[<VerifyXunit.UsesVerify>]
module Tests

open Xunit
open VerifyTests
open VerifyXunit
open Newtonsoft.Json

VerifierSettings.AddExtraSettings(fun settings ->
  settings.NullValueHandling <- NullValueHandling.Include)

[<Fact>]
let MyTest () =
  async {
    do! Verifier.Verify(15)
          .ToTask() |> Async.AwaitTask
  }

[<Fact>]
let MyTaskTest () =
  task {
    do! Verifier.Verify(15)
  }

[<Fact>]
let WithFluentSetting () =
  async {
    do! Verifier.Verify(15)
          .UseMethodName("customName")
          .ToTask() |> Async.AwaitTask
  }
do ()

snippet source | anchor