Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/pmrogala/Buildenator

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

analyzer builder builders csharp dotnet dotnet-standard dotnetcore sourcegenerator

Last synced: 12 days ago
JSON representation

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

Awesome Lists containing this project

README

        

# Buildenator
A test data **Builder Generator** for .net 5 and later.

Versioning:
N.X.Y.Z

- N - minimum version of .net required.
- X.Y.Z - standard semantic versioning.

## A simple usage example

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

namespace SampleTestProject.Builders
{
[MakeBuilder(typeof(DomainEntity))]
/* AutoFixture is optional. By adding it, the builder will use random data generator
for filling in not set up properties. */
[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!