question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make Dummy ValueTuples' members Dummies, to match Tuple

See original GitHub issue

Repreod 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:closed
  • Created 4 years ago
  • Comments:19 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
thomaslevesquecommented, Oct 3, 2019

@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:

Tuple<int, string> tmp =  await fake2.Make();
tmp.Deconstruct(out int id, out string name);

(Deconstruct is an extension method on Tuple<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:

What’s the signature of CreateStorageAccountAsync? Did it change between WORKS and DOESN’T WORK?

If you didn’t change the signature, but only the call site, the problem is probably not related to FakeItEasy.

0reactions
blairconradcommented, Oct 16, 2019

This change has been released as part of FakeItEasy 5.3.0.

Thanks, @TimLovellSmith. Look for your name in the release notes! 🏆

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found