FsFaker 0.1.0-beta.52

This is a prerelease version of FsFaker.
dotnet add package FsFaker --version 0.1.0-beta.52
NuGet\Install-Package FsFaker -Version 0.1.0-beta.52
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FsFaker" Version="0.1.0-beta.52" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FsFaker --version 0.1.0-beta.52
#r "nuget: FsFaker, 0.1.0-beta.52"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FsFaker as a Cake Addin
#addin nuget:?package=FsFaker&version=0.1.0-beta.52&prerelease

// Install FsFaker as a Cake Tool
#tool nuget:?package=FsFaker&version=0.1.0-beta.52&prerelease

CI Nuget


Easily define data builders with Bogus

Getting started

NuGet package available:

$ dotnet add package FsFaker

Simple Builders

type AddressType = Principal | Secondary
type Address =
    { Street: string
      City: string
      Type: AddressType }

// defining builders
let addressBuilder =
    Builder.create (fun f ->
        { City = f.Address.City()
          Street = f.Address.StreetName()
          Type = f.Random.Union<AddressType>() })

let addresses = addressBuilder.Generate(10) 

// extending / updating builders
let addressesChanged =
    |> Builder.update (fun f model ->
        { model with City = $"TEST {f.Random.Int()}" })
    |> Builder.one

Defining Builders

open System
open FsFaker

type Status =
    | Enabled
    | Disabled

type MaritalStatus =
    | Single = 1
    | Married = 2
    | Widowed = 3

type AddressType =
    | Principal
    | Secondary

type Address =
    { Street: string
      City: string
      Type: AddressType }

type Person =
    { Id: Guid
      Name: string
      Email: string
      Age: int
      Status: string
      BirthDate: DateTime
      MaritalStatusEnum: MaritalStatus
      Address: Address
      OtherAddresses: Address list }

// default locale 
FsFakerConfig.setLocale "pt_BR"

let address' =
    BuilderFor<Address>() {
        locale "en"
        build into address
        set address.City (fun f -> f.Address.City())
        set address.Street (fun f -> f.Address.StreetName())
        set address.Type (fun f -> f.Random.Union<AddressType>())

let person' =
    BuilderFor<Person>() {
        build into person
        set person.Name (fun f -> f.Person.FirstName)
        set person.Email (fun f -> f.Person.Email)
        set person.BirthDate (fun f -> f.Date.Past())
        set person.Age (fun f p -> DateTime.Today.Subtract(p.BirthDate).TotalDays |> int)
        set person.Address address'
        set person.OtherAddresses address' 2

        rand person.Id
        rand person.MaritalStatusEnum
        rand person.Status "active" "disabled"

let person1 = person'.Generate()

let person2 =
    person' {
        rule (fun p -> p.Name) "Lucas"
        rule (fun p -> p.BirthDate) (DateTime.Today.AddYears -32)

let persons =
    person' {
        rule (fun p -> p.Status) "other"
        list 5

let infinitePersons = person' { lazy_seq }

Extending Builders

You can extend builders with your own operations:

open FsFaker
open FsFaker.Types

type CustomPersonBuilder(?faker) =
    inherit BaseBuilder<Person, CustomPersonBuilder>(faker)

    member _.WithName(faker: LazyFaker<Person>, name: string) =
            .RuleFor((fun x -> x.Name), name)
            .RuleFor((fun x -> x.Email), (fun f -> $"{name}@{f.Internet.DomainName()}.com"))

    member _.CanDrive(faker: LazyFaker<Person>) =
            .RuleFor((fun x -> x.Age), 18)
            .RuleFor((fun x -> x.BirthDate), (fun _ p -> DateTime.Today.AddYears(-p.Age)))

let customResult =
    CustomPersonBuilder() {
        // your operations
        withName "Artorias"

        // you can mix with property rules
        rule (fun p -> p.Address) address'
        rule (fun p -> p.OtherAddresses) []

        // or even with build syntax
        build into person
        rand person.Id
        set person.Status "active"
        set person.MaritalStatusEnum MaritalStatus.Single

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.0-beta.52 110 4/6/2024
0.1.0-beta.38 49 4/6/2024
0.1.0-beta.26 72 4/6/2024
0.1.0-beta.15 103 1/9/2024
0.1.0-beta.14 52 1/9/2024
0.1.0-beta.8 902 5/13/2023
0.1.0-beta.3 160 2/26/2023
0.1.0-beta.1 91 2/26/2023