Comments (9)
Hi
Any update with this? with this feature Bogus can fully replace nbuilder + faker.net combi.
I.e. you can make simple type fakes, and randomize properties in an object.
Can't wait.. :-)
from bogus.
I am totally fine with AutoBogus beeing a separate project. When referencing the NuGet, I only reference AutoBogus and get Bogus as a dependency for free. So there should be some technical reason for a merge (ie. easier versioning).
from bogus.
Hi Chris,
Nothing to report at the moment.
Current suggestion is to use AutoBogus separately. AFAIK, AutoBogus still works wonderfully and gets the job done.
Automatic rule generation at runtime is difficult problem to get right for all use cases. We're lucky to have AutoBogus.
But before we add any new features to Bogus, I personally prefer to get it right (more or less) the first time than to trigger a maintenance/support crisis for thousands of users.
from bogus.
G'day Bogus Fans,
So the foundations are currently being put down to address the auto-magic population of Faker<T>
types (see #8). We are at the stage now where we are piecing together a public API to invoke an auto generate and are calling on the community to help shape how this will be useful to you.
Under the hood we are planning on using a 'conventions' concept that will drive the population pipeline and allow for things like mocking of interfaces using your preferred framework (Moq, FakeItEasy, etc.).
So, how do you see this working for you? Options considered so far are:
-
A separate
AutoFaker<T>
class, but does this mean 2 models need to be maintained (one forFaker<T>
and one forAutoFaker<T>
)? -
An extension method on
Faker<T>
, but with the conventions concept seems to put a double responsibility on the method to both configure and generate. -
Leverage the design of AutoFixture and have an
AutoGenerator
class which allows conventions to be registered on a global basis (e.g. the setup process of a unit test). Then expose aGenerate()
method that can create instances based on aFaker<T>
definition or just a generic type (Generate<T>()
). The latter would cater for scenarios likeGenerate<int>()
whereFaker<T>
definitions are not possible. Are we doubling up on the non-genericFaker
role though?
That has been our consideration journey so far, each with their own pros/cons. What does the community prefer? Is there another approach that would work well?
Add your comments and help shape the awesome :-)
Nick.
from bogus.
Hi @nickdodd79,
Replying to your previous post here:
As an example, if I have
Faker<Person>
and want to generate 2 instances for my unit test I would callFaker<T>.Generate()
twice. However, I then want the first to set the manager to be null, but keep the second to have an auto generated manager, so I apply.RuleFor(p => p.Manager, f => null)
before callingGenerate()
on the first. If we use a method of applying these rules through conventions and mutateFaker<T>
then the second instance would also have a manager of null. Having said that, a workaround for this is to use the ruleset string parameter ofGenerate()
. Is that an approach a developer would use for this scenario?
You hit the nail on the head, the workaround in today's Bogus release is to use a "RuleSet" as a way to specify additional rules for specific scenarios. I shamelessly copied the concept from FluentValidation's RuleSet.
Using your scenario as a thread for to revive an older idea, I'm starting to think the concept "Cloning" a Faker<T>
is something developers are expecting to be part of Bogus API and feature set. Conceptually, I'm seeing "Cloning" as a more pragmatic approach to some scenarios over RuleSets. The issue of "Cloning" came up about a year ago in Issue #28. I thought back then "RuleSets" would solve the issue and "softly" guide developers to write rules in single place. I'm starting to think "Cloning" still can serve as a valuable alternative.
So, a major question for you @nickdodd79:
Suppose we had a Faker<T>.Clone()
method that completely deep-cloned a Faker<T>
.... would that: 1) resolve your specific use-case more elegantly? and 2) make the API implementation of "Conventions" easier?
Conceptually, "Conventions" would still mutate the underlying Faker<T>
as we described before with .RuleFor
s. With Faker<T>
's new ability to "clone" itself, "Convention" mutations would still mutate on Faker<T>
except this time, you'd be in specific control of "when" cloning is appropriate (as with your case, loading DB data vs unit tests). And you'd be able to apply various "Conventions" to cloned Faker<T>
without having to worry about modifying the original Faker<T>
.
Let me know what you think π
Brian
πΆββοΈ πΆββοΈ Missing Persons - Walking in L.A.
from bogus.
Similar bump, status questionmark
from bogus.
Hey there everyone!
I'm going to close this issue for now. I think Nick is doing an awesome job of developing and maintaining AutoBogus. He just reached 100K downloads on NuGet!
There doesn't seem to be any issues keeping the projects separate. Right now each library can iterate and bugfix independently. If there's ever an issue regarding incompatibility, we should still be able to work things out.
Someday, if we decide its easier to develop inside the Bogus repository for access to internal types or under the Bogus.Xyz NuGet namespace, merging projects will always be an option!
from bogus.
Unfortunately it seems that the development of AutoBogus is stalled. Maybe re-consider this?
For example, DateOnly
still doesn't work: nickdodd79/AutoBogus#76
Just closing to keep your issue tracker clean. bchavez/Bogus#74 (comment) The TLDR: merging can always be an option if or when the time is right.
Maybe now it the time right.
from bogus.
@304NotModified, thinking about it a bit, I think I would probably take a different approach in 2023 and use Source Generators instead of on-the-fly-runtime-reflection and runtime-only-rule generation (which I think AutoBogus still employs); it was a good solution at the time, but we have some new tools at our disposal.
It's probably not very different from how Bogus Premium Tools Analyzer does it; but that's a paid/premium feature for the OSS project.
I think, with Source Generators, a big benefit would be to see what source code is being generated which could help with troubleshooting large object graphs and relations via F12 navigation.
The real trick part to solve would probably be how to weave seed/determinism into source-generated code. That is, how do you not destroy a deterministic sequence just by adding a new Field or Property in the source-generated code?
from bogus.
Related Issues (20)
- Bogus is slow on Blazor WASM HOT 1
- Add Amka number (Greek social security number) to Extensions.Greece
- Option to filter out en_AU_ocker
- Generating a deep object graph based on rules HOT 1
- Xamarin fails to publish due to Nordic characters in Method names HOT 2
- Add Direct License Information In Nuget metadata HOT 2
- Foreign Key Constraint Violation Issue with Bogus and EF Core
- Binder throw ambiguous match exception for object with read only indexer property that has two implementations in base class HOT 2
- First and Full names are incorrectly generated with locale "sv" HOT 2
- Request to add language English (Hong Kong) / locale en_HK
- Faker.Tv() is missing from Bogus.Hollywood HOT 3
- Feature request: New localized data: Word(s).
- Add ability to except random numbers HOT 2
- Update Denmark (da) locale from faker-js
- Nuget for .NET 8.0.x HOT 4
- Random history facts generation
- Are Randomizer's number ranges inclusive or exclusive? HOT 3
- bogus is missing NuGet package README file HOT 1
- .NET 8 support HOT 9
- Gender-digit is incorrect for Swedish Personnummer generation HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bogus.