Attributes for similar experience of xUnit, AutoFixture & Moq? #532
-
I'm not so experienced with the Bogus ecosystem, but looking into it as a potential replacement for AutoFixture used with Moq and xUnit. Are there any "official" or community supported projects that helps with getting support for a similar setup that you can achieve with AutoFixture, Moq and xUnit by decorating your tests with attributes? E.g. [Theory]
[AutoData]
public void SomeTest(
SomeDto dto,
MyService sut)
{
// dto: auto created and populated with data
// sut: auto created (no dependencies)
} [Theory]
[CustomAutoData(typeof(MyCustomization)]
public void SomeTest(
SomeDto dto,
MyService sut)
{
// CustomAutoData: Custom attribute to allow for passing generalized customizations to affect e.g. how properties are populated
// dto: auto created and populated with data, with customizations from MyCustomization
// sut: auto created (no dependencies)
} [Theory]
[AutoMoqData]
public void SomeTest(
SomeDto dto,
[Frozen] ISomeDependency dependencyOfSut,
MyService sut)
{
// AutoMoqData: Custom attribute that hooks in Moq, to automatically create mocked implementations of types
// dto: auto created and populated with data
// dependencyOfSut: auto mocked using (Moq) to have mocked return values etc
// sut: auto created, with mocked dependency "dependencyOfSut"
// [Frozen] "fixed" reference to the mocked dependency to interact with in the test
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello. Thanks for the question. There's nothing "official"; but the community has developed a small ecosystem around Bogus. Most of the "community extensions" I'm familiar with are documented in the README here:
If you're looking for something to populate a DTO automatically without explicitly specifying rules; there's a community project called "AutoBogus":
So the options above solve the "how to generate a DTO without explicitly specifying rules" part; and my guess is the next part is integrating with I'm only speculating, but I'm guessing that it is probably not too difficult to wire up |
Beta Was this translation helpful? Give feedback.
Hello. Thanks for the question.
There's nothing "official"; but the community has developed a small ecosystem around Bogus. Most of the "community extensions" I'm familiar with are documented in the README here:
and there's probably more that can be found on NuGet.
If you're looking for something to populate a DTO automatically without explicitly specifying rules; there's a community project called "AutoBogus":