Creating a dummy for a type with PRIVATE default constructor
See original GitHub issueCurrently when FakeItEasy goes to make a type with a private constructor we just get back null
and no warnings / exceptions.
Here’s a test:
public interface Thing { }
public interface Foo
{
Task<TThing> Bar<TThing>() where TThing : Thing;
}
public class FakeThing : Thing {
private FakeThing() { }
}
[Fact]
public async Task Test1()
{
var foo = A.Fake<Foo>();
var bar = await foo.Bar<FakeThing>();
Assert.NotNull(bar);
}
Personally - I’d like to see a real dummy actually be created. Just because the constructor is private shouldn’t prevent a dummy from being created. In my app I make users define aggregate root’s as private constructor so a new developer doesn’t go and do var entity = new InvoiceAggregateRoot()
so there is a real use case for creating these objects even though they’re marked private.
But the bug is IMO if this behavior is not supported it should throw a “Could not create dummy” exception - not just return null like everything is fine.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Is it possible to create an object of the class which has ...
The answer to this is both yes and no. If we are making a constructor private then we can make the object of...
Read more >does adding a dummy parameter to constructors of a class ...
I think it violates my taste. I would code it like this: enum Unit { Centimeter = 100, Meter = 1 }; Rect(int...
Read more >Default Constructor in Java – Class Constructor Example
In this article, we will talk about constructors, how to create our own constructors, and what default constructors are in Java.
Read more >Should my classes have separate constructors just for unit ...
I like to write classes with two constructors: a primary constructor used in production code, and a default constructor just for unit tests....
Read more >default constructor Line class - C++ Forum
The default argument for p is a private static member of the class called dummy. You have to define this is the file...
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
@novak, the ability to configure all of a Fake’s members to return values from AutoFixture can be accessed like this:
I can’t find proper user documentation for it, but you can see the API Docs on the wonderful fuget.
I’m glad you’re up and running, @volak.