Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/pmrogala/Buildenator
- Owner: pmrogala
- License: mit
- Created: 2021-06-04T19:57:24.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-24T19:15:47.000Z (27 days ago)
- Last Synced: 2024-10-26T17:49:07.088Z (25 days ago)
- Topics: analyzer, builder, builders, csharp, dotnet, dotnet-standard, dotnetcore, sourcegenerator
- Language: C#
- Homepage:
- Size: 250 KB
- Stars: 19
- Watchers: 3
- Forks: 1
- Open Issues: 8
-
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 **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!