Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/progala2/Buildenator

A test data builders source generator for .net 5 and later.
https://github.com/progala2/Buildenator

analyzer builder builders csharp dotnet dotnet-standard dotnetcore sourcegenerator

Last synced: 3 months ago
JSON representation

A test data builders source generator for .net 5 and later.

Awesome Lists containing this project

README

        

# Buildenator
A test data builders source generator for .net 5 and later.

## A simple usage example

The following code:
```csharp
using Buildenator.Abstraction;
using Buildenator.Abstraction.AutoFixture;
using SampleProject;

namespace SampleTestProject.Builders
{
[MakeBuilder(typeof(DomainEntity))]
[AutoFixtureConfiguration()]
public partial class DomainEntityBuilder
{
}
}
```
Will generate something very close to this source code:

```csharp
using System;
using System.Linq;
using Buildenator.Abstraction.Helpers;
using SampleProject;
using AutoFixture;

namespace SampleTestProject.Builders
{
public partial class DomainEntityBuilder
{
private readonly Fixture _fixture = new Fixture();

public DomainEntityBuilder()
{

}

private Nullbox? _propertyIntGetter;
private Nullbox? _propertyStringGetter;

public DomainEntityBuilder WithPropertyIntGetter(int value)
{
_propertyIntGetter = new Nullbox(value);
return this;
}

public DomainEntityBuilder WithPropertyStringGetter(string value)
{
_propertyStringGetter = new Nullbox(value);
return this;
}

public DomainEntity Build()
{
return new DomainEntity((_propertyIntGetter.HasValue ? _propertyIntGetter.Value : new Nullbox(_fixture.Create())).Object, (_propertyStringGetter.HasValue ? _propertyStringGetter.Value : new Nullbox(_fixture.Create())).Object)
{

};
}

public static DomainEntityBuilder DomainEntity => new DomainEntityBuilder();

public System.Collections.Generic.IEnumerable BuildMany(int count = 3)
{
return Enumerable.Range(0, count).Select(_ => Build());
}

public static DomainEntity BuildDefault(int _propertyIntGetter = default(int), string _propertyStringGetter = default(string))
{
return new DomainEntity(_propertyIntGetter, _propertyStringGetter)
{

};
}

}
}
```

Check ```Buildenator.IntegrationTests``` for more examples.

Feel free to contribute!