[Feature Request] Add a `WithFactoryMethod` option to IFakeOptions
See original GitHub issueCurrently, I have classes with a factory creation method instead of a public constructor and I can’t fake them.
What would you guys think of a new method to handle the creation with the factory method vs a constructor?
For example, say I have a class like this.
public class Recipe : BaseEntity
{
public string Title { get; private set; }
public string Directions { get; private set; }
public int? Rating { get; private set; }
public Author Author { get; private set; }
public ICollection<Ingredient> Ingredients { get; private set; }
public static Recipe Create(RecipeForCreationDto recipeForCreationDto)
{
new RecipeForCreationDtoValidator().ValidateAndThrow(recipeForCreationDto);
var mapper = new Mapper(new MapperConfiguration(cfg => {
cfg.AddProfile<RecipeProfile>();
}));
var newRecipe = mapper.Map<Recipe>(recipeForCreationDto);
newRecipe.QueueDomainEvent(new RecipeCreated(){ Recipe = newRecipe });
return newRecipe;
}
public void Update(RecipeForUpdateDto recipeForUpdateDto)
{
new RecipeForUpdateDtoValidator().ValidateAndThrow(recipeForUpdateDto);
var mapper = new Mapper(new MapperConfiguration(cfg => {
cfg.AddProfile<RecipeProfile>();
}));
mapper.Map(recipeForUpdateDto, this);
QueueDomainEvent(new RecipeUpdated(){ Recipe = this });
}
private Recipe() { } // For EF
}
I could then create a fake for it it like this:
RecipeForCreationDto fakeDto = new FakeRecipeForCreationDto();
var fakeTracking = A.Fake<Reccipe>(x =>
x.WithFactoryMethod(x => x.Create(fakeDto)));
Totally open to other APIs, but this is a gap in the current API that is making things hard for this use case.
Happy to make a contribution if you guys aren’t up for it, but I haven’t looked at your codebase at all yet, so any guidance would be appreciated!
Issue Analytics
- State:
- Created a year ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
allow developers to extend or change the options
I see three possible extensions: 1. Allow developers to add their own options to the admin interface. 2. Allow developers to disable/enable ...
Read more >(Feature request) Add 'Expandable' option to Include Note ...
Describe feature Currently there are three options when 'including' notes: It would be nice if there was one more option called something like...
Read more >🚀 Feature Request: · Issue #19620 · elementor ...
I would like to suggest a feature that would be very useful... Add an option in the popup to open the popup already...
Read more >Feature Request Content
This page covers the content found in a feature request for your iOS app. Suggest Edits. Users can add new feature requests or...
Read more >Showing the Feature Requests List
Described here is how to invoke the list of feature requests inside your React ... new feature requests, add comments, and up-vote other...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Awesome. Thanks for the help!
No, Moq and NSubstitute would have about the same powers as FakeItEasy. We all build on the same base.
I was thinking of something like Isolator, which I used a very long time ago, and I think there’s another. Oh! JustMock. I’ve never used that one. There may be others…