Skip to content

Instantly share code, notes, and snippets.

@bartelink
Created February 5, 2014 14:13
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 bartelink/8824390 to your computer and use it in GitHub Desktop.
Save bartelink/8824390 to your computer and use it in GitHub Desktop.
F# wrapper for having AutoFixture perform post-processing on AutoFixture Specimens of a given type
type TypeThatIsARequestSpecification<'T>() =
interface IRequestSpecification with
member this.IsSatisfiedBy request =
match request with
| :? System.Type as requestType -> typeof<'T>.IsAssignableFrom( requestType)
| _ -> false
type PrepareSpecimenCommand<'T>( action) =
interface ISpecimenCommand with
member this.Execute( specimen, context) =
let instance = specimen :?> 'T
action instance
type WarmupCustomization<'T>( prepareAction) =
interface ICustomization with
member this.Customize fixture =
fixture.Customizations.Add(
new FilteringSpecimenBuilder(
Postprocessor(
MethodInvoker(
ModestConstructorQuery()),
PrepareSpecimenCommand<'T>( prepareAction)),
TypeThatIsARequestSpecification<'T>()))
type Context() as this =
inherit AutoDataAttribute()
let initializeSut (sut:IDynamicAllocationCache) =
sut.Purge()
do this.Fixture.Customize <| WarmupCustomization initializeSut |> ignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment