Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/progala2/Buildenator
- Owner: progala2
- License: mit
- Created: 2021-06-04T19:57:24.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-05T13:17:49.000Z (10 months ago)
- Last Synced: 2024-06-22T05:03:27.687Z (5 months ago)
- Topics: analyzer, builder, builders, csharp, dotnet, dotnet-standard, dotnetcore, sourcegenerator
- Language: C#
- Homepage:
- Size: 195 KB
- Stars: 19
- Watchers: 3
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- RSCG_Examples - Buildenator
- csharp-source-generators - Buildenator - ![stars](https://img.shields.io/github/stars/progala2/Buildenator?style=flat-square&cacheSeconds=604800) ![last commit](https://img.shields.io/github/last-commit/progala2/Buildenator?style=flat-square&cacheSeconds=86400) Generate data builder classes for testing purposes (and not only) for your entities. Autofixture + Moq extensions. (Source Generators / Testing)
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!