Giter Site home page Giter Site logo

autofixture.community.fsharp's Introduction

AutoFixture.Community.FSharp

Build

Package Version Downloads
AutoFixture.Community.FSharp AutoFixture.Community.FSharp Downloads
AutoFixture.Community.FSharp.Xunit AutoFixture.Community.FSharp.Xunit Downloads

This is a small library that builds on top of AutoFixture to add support for F#-specific types. Specifically, the important additions that are't currently handled well with vanilla AutoFixture are:

  1. Discriminated Unions
  2. F# lists

Everything else seems to work pretty well out of the box.

Useful bits:

FSharpSpecimenBuilder:

Can be inserted onto any existing IFixture by doing the following

let fixture = Fixture()
//...

fixture.Customizations.Add(FSharpSpecimenBuilder(fixture))

fsFixture

A pre-made fixture with only the F# features applied.

randVal and friends

Helper functions for creating random data inline, e.g.:

type MyDto =
  { Foo : int
    Bar : string
    Baz : DateTime }

[<Fact>]
let ``My test method when Foo is 5`` () =
  // Generate random values explicitly for specific properties
  let myDto =
    { Foo = 5
      Bar = randVal()
      Baz = randVal() }

  // Or generate a full random value and only override specific properties
  let otherDto =
    { randVal<MyDto>() with Foo = 5 }
  ~~// Do assertions~~

Thanks to F#'s type system, most of the time you can omi~~~~t the type arguments. Similar helper functions include:

  • randVal<'a>() : create a single random value
  • randVals<'a>() : create an 'a seq
  • randValsN<'a> (n: int) : create an 'a seq that is n elements long
  • randValExceptWhere<'a> (fn: 'a -> bool) : create a single random value for which fn returns false.
  • randValExcept<'a> (x: 'a) : create a random value that is not x
  • randValsExceptWhere<'a> (fn: 'a -> bool) : create an infinite sequence of random values where fn returns false
  • randValsExcept<'a> (x: 'a) : create an infinite sequence of random values except x
  • randValsNExceptWhere<'a> (n: int) (fn: 'a -> bool) : create a sequence of n random values where fn returns false
  • randValsNExcept<'a> (n: int) (x: 'a) : create a sequence of n random values except for x

AutoFixture.Community.FSharp.Xunit

This package defines just two attributes:

  1. AutoDataFSharpAttribute
  2. InlineAutoDataFSharpAttribute

Which respectively correspond to the AutoDatAttribute and InlineAutoDataAttribute from AutoFixture.Xunit2

autofixture.community.fsharp's People

Contributors

josh-degraw avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.