Make Dummy ValueTuples' members Dummies, to match Tuple
See original GitHub issueRepreod in 5.2 also.
I got bitten by unexpected behavior with FakeItEasy 2.3.0 (before I updated) while I was doing some ‘refactoring’. I was trying to take advantage of the new tuple language features. Unfortunately I found this not-quite-innocent-as-it-looks change actually broke my tests.
ArmCreatableResourceFactory
below is a fake that had no behavior configured for CreateStorageAccountAsync
, so it got the default call behavior…
WORKS:
Tuple<StorageAccount, string> storageAccountAndId = await ArmCreatableResourceFactory.CreateStorageAccountAsync(dep, scope, resourceGroup, token, ExecCtx);
storageAccount = storageAccountAndId.Item1;
string storageAccountId = storageAccountAndId.Item2;
var x = storageAccount.AccountName;
DOESN’T WORK:
var (storageAccount, storageAccountId) = await ArmCreatableResourceFactory.CreateStorageAccountAsync(dep, scope, resourceGroup, token, ExecCtx);
var x = storageAccount.AccountName;
The reason it doesn’t work is while the code runs, it results in different state, and when you dereference storageAccount.AccountName
, in the second instance it is null!
The main impact of the issue is this kind of brittleness makes the code harder to refactor.
Issue Analytics
- State:
- Created 4 years ago
- Comments:19 (14 by maintainers)
Top Results From Across the Web
Tuple unpacking: dummy variable vs index
What if the function was returning a tuple with more than 2 values? What if the program logic is interested in the 4th...
Read more >Dummies
If T is a tuple type ( Tuple<> or ValueTuple<> ), the Dummy will be a tuple whose elements are dummies, or default...
Read more >Advanced C#: Using ValueTuple
I'm talking about Tuple. The book definition of it goes as follows: The tuples feature provides concise syntax to group multiple data elements...
Read more >Working with ValueTuple in C# | CodeGuru.com
Learn how to work with ValueTuple in C# in this software development tutorial, which showcases code examples and use cases.
Read more >FakeItEasy/CHANGELOG and FakeItEasy Releases | LibHunt
Make Dummy ValueTuple s' members Dummies, to match Tuple (#1637); Detect and reject an "argument constraint factory method" that produces multiple ...
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
@blairconrad in this code you’re not using
ValueTuple
at all, you’re just using tuple deconstruction.var (id, name) = await fake2.Make()
is equivalent to this:(
Deconstruct
is an extension method onTuple<T1, T2>
)@TimLovellSmith I’m not sure I really understand what your problem is. A complete example would help, as well as the answer to this question:
If you didn’t change the signature, but only the call site, the problem is probably not related to FakeItEasy.
This change has been released as part of FakeItEasy 5.3.0.
Thanks, @TimLovellSmith. Look for your name in the release notes! 🏆