Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create a Fake #1044

Closed
mjfreelancing opened this issue Jun 4, 2018 · 4 comments
Closed

Unable to create a Fake #1044

mjfreelancing opened this issue Jun 4, 2018 · 4 comments
Labels

Comments

@mjfreelancing
Copy link

mjfreelancing commented Jun 4, 2018

I'm in the process of updating a project I was working on a few years ago. In the process I have updated to the latest of FakeItEasy and AutoFixture.

I have 40 tests that are failing with an error similar to:

AutoFixture was unable to create an instance from
FakeItEasy.Fake1[System.Collections.Generic.IList1[AllOverIt.Evaluator.AoiFormulaTokenProcessorContext]] because creation unexpectedly failed with exception.

Where the inner exception reports:
Failed to create fake of type System.Collections.Generic.IList1[AllOverIt.Evaluator.AoiFormulaTokenProcessorContext]`

The line that's failing is the equivalent of this:
Fixture.Create<Fake<IList<AoiFormulaTokenProcessorContext>>>();

As a test I tried something simpler:
Fixture.Create<Fake<IList<int>>>();

This did not throw so I went looking at the constructor of AoiFormulaTokenProcessorContext. It looks like this:

public AoiFormulaTokenProcessorContext(Func<char, bool, bool> predicate, Func<char, bool, bool> processor)

After some reading at #984 I tried adding 'GenerateDelegates' to this:
Fixture.Customize(new AutoFakeItEasyCustomization {GenerateDelegates = true});

But I've still got the same problem.

As this code was working I can only assume there's another breaking change somewhere that I haven't yet stumbled across. Hoping someone can throw a suggestion or two my way.

TIA.

@zvirja
Copy link
Member

zvirja commented Jun 4, 2018

Thanks for sharing the scenario!

As usual, may I ask you to provide Minimal, Complete, and Verifiable example, so I can copy-paste it to deeply investigate the reason? The devil is often in some specifics, so even if you described the scenario good, it could still happen that some non-mentioned detail matters.

Thanks a lot in advance! 😌

@zvirja zvirja added the question label Jun 4, 2018
@mjfreelancing
Copy link
Author

Sorry, I should have gone and created another (possibly pair of) projects - I was hoping my question may have prompted something obvious before I went off and did that as it would have involved converting my wrapper methods into raw AutoFixture / FakeItEasy code.

The good news is I seem to have fixed it.

The AoiFormulaTokenProcessorContext class causing the problem is internal (in another project). When I changed it to public the error goes away.

I already had [assembly: InternalsVisibleTo("...")] in the AssemblyInfo.cs file but I just remembered my old projects also included [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")].

I don't recall what the latter does but the errors are now all gone.

@zvirja
Copy link
Member

zvirja commented Jun 4, 2018

Good news the issue is mitigated ☺️ That's the reason I asked for the sample - it's always easier when other factors are isolated.

I don't recall what the latter does but the errors are now all gone.

I know 😄 It's related to the Fakes and Castle's proxies, used under the hood. Yep, if class is internal, then it indeed should help.

@zvirja zvirja closed this as completed Jun 4, 2018
@mjfreelancing
Copy link
Author

I understand. With the decades of experience I have I should know better - I've been in the same boat and ask the very same. Thanks for the responses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants