FsFaker 0.1.0-beta.26
This is a prerelease version of FsFaker.
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package FsFaker --version 0.1.0-beta.26
NuGet\Install-Package FsFaker -Version 0.1.0-beta.26
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.26" />
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.26
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FsFaker, 0.1.0-beta.26"
#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.26&prerelease // Install FsFaker as a Cake Tool #tool nuget:?package=FsFaker&version=0.1.0-beta.26&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
FsFaker
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 =
addressBuilder
|> 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
[<CLIMutable>]
type Address =
{ Street: string
City: string
Type: AddressType }
[<CLIMutable>]
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)
one
}
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)
[<CustomOperation("withName")>]
member _.WithName(faker: LazyFaker<Person>, name: string) =
faker
.RuleFor((fun x -> x.Name), name)
.RuleFor((fun x -> x.Email), (fun f -> $"{name}@{f.Internet.DomainName()}.com"))
[<CustomOperation("canDrive")>]
member _.CanDrive(faker: LazyFaker<Person>) =
faker
.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"
canDrive
// 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
one
}
Product | Versions 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.
-
net8.0
- Bogus (>= 35.5.0)
- FSharp.Core (>= 8.0.100)
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 | 223 | 4/6/2024 |
0.1.0-beta.38 | 56 | 4/6/2024 |
0.1.0-beta.26 | 81 | 4/6/2024 |
0.1.0-beta.15 | 111 | 1/9/2024 |
0.1.0-beta.14 | 61 | 1/9/2024 |
0.1.0-beta.8 | 911 | 5/13/2023 |
0.1.0-beta.3 | 167 | 2/26/2023 |
0.1.0-beta.1 | 99 | 2/26/2023 |