Created
February 5, 2014 14:13
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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