Skip to content

Instantly share code, notes, and snippets.

@ursenzler
Created September 26, 2023 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ursenzler/def9bd67e7ee00fd6183af14d850369e to your computer and use it in GitHub Desktop.
Save ursenzler/def9bd67e7ee00fd6183af14d850369e to your computer and use it in GitHub Desktop.
A function in F# that can create dummy strings and integers (can be extended).
open FsToolkit.ErrorHandling
open Xunit
open Swensen.Unquote
let factoryFunction<'a> () : 'a =
let value =
if typeof<'a> = typeof<string> then "String" :> obj
elif typeof<'a> = typeof<int> then 1 :> obj
else failwith "Unsupported type"
downcast value
[<Fact>]
let ``factory can create dummy string value`` () =
let result = factoryFunction ()
test <@ result = "String" @>
[<Fact>]
let ``factory can create dummy int value`` () =
let result = factoryFunction ()
test <@ result = 1 @>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment