WS.Gen.ObjectMother 2.0.1

dotnet add package WS.Gen.ObjectMother --version 2.0.1
                    
NuGet\Install-Package WS.Gen.ObjectMother -Version 2.0.1
                    
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="WS.Gen.ObjectMother" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WS.Gen.ObjectMother" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="WS.Gen.ObjectMother" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WS.Gen.ObjectMother --version 2.0.1
                    
#r "nuget: WS.Gen.ObjectMother, 2.0.1"
                    
#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.
#:package WS.Gen.ObjectMother@2.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WS.Gen.ObjectMother&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=WS.Gen.ObjectMother&version=2.0.1
                    
Install as a Cake Tool

Object Mothers - Generate Builder Objects

For full information, please visit: https://github.com/WebbertSolutions/SourceGenerators/tree/main/Generators/GenerateObjectMother

Quick Start

  • Add namespace: using WS.Gen.ObjectMother;

  • Create a class in your test project

    • Name doesn't matter
    • "Builder" not required
  • Add attribute

  • Type should be your class you want a builder for

using WS.Gen.ObjectMother;

[ObjectMotherBuilder(typeof(Address), true)]
public partial class AddressBuilder
{
}
  • Under your test project navigate down Anzlyzers → GenerateObjectMother → WS.Gen.ObjectMother.ObjectMotherGenerator
  • Double click on your class builder.
  • Copy the code at the bottom and paste into your class
public static AddressBuilder Required()
{
    return new AddressBuilder()
        .WithAddress1(() => xx)
        .WithAddress2(() => xx)
        .WithCity(() => xx)
        .WithPostalCode(() => xx)
        .WithState(() => xx)
        ;
}

public static AddressBuilder Typical()
{
    return Required();
}
  • Change the parameter value xx to suite your needs
  • Add additional methods as needed
public static AddressBuilder BeverlyHills()
{
    return new AddressBuilder()
        .WithAddress1("123 Main Street")
        .WithAddress2("Suite 200")
        .WithCity("Beverly Hills")
        .WithState(() => StateBuilder.Typical().WithName("CA").Build())
        .WithPostalCode("90210")
        ;
}
There are no supported framework assets in this 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
2.0.1 142 7/3/2025
2.0.0 123 2/6/2025
1.0.5 320 8/5/2024
1.0.4 233 4/11/2024
1.0.3 211 4/10/2024
1.0.2 260 4/4/2024
1.0.1 259 4/1/2024
1.0.0 327 4/1/2024