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.

Shortcut for "ignore all arguments" when using A.CallTo. Again after 5 years.

See original GitHub issue

[Edit by @blaiconrad: Previous issue (#287 - “Shortcut for “ignore all arguments” when using A.CallTo”) from 2016 is not current available due to some GitHub server error)]

Maybe technology from 2021 allows to implement this? It would be great to replace

A.CallTo(() => varDefDataReader.ReadVarDefItems(
                         A<string>.Ignored, A<VisibleVariables>.Ignored, A<List<VarDefTreeItem>>.Ignored, 
                         A<string>.Ignored, A<CancellationToken>.Ignored))
                .Returns(varDefItemsPage);

with

A.CallTo(() => varDefDataReader.ReadVarDefItems(A.AllIgnored).Returns(varDefItemsPage);

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
vdurantecommented, Jun 14, 2021

I have implemented the following:

public static partial class IWhereConfigurationExtensions
{
    public static TReturn WithMethod<TReturn>(this IWhereConfiguration<TReturn> configuration, string methodName)
    {
        return configuration.Where(call => call.Method.Name == methodName);
    }
}

And I use as follows:

A.CallTo(_permissionService)
    .WithMethod(nameof(_permissionService.ValidateAsync))
    .WithReturnType<Task<bool>>()
    .Returns(true);

It doens’t have full intellisense, but it works

1reaction
thomaslevesquecommented, Jan 19, 2021

Of course, you still have to provide the correct number of arguments, and with type-compatible values.

That’s why I like to use default instead of null, because it works for any type.

I’m using nullable reference types and can’t use null as a parameter. The best solution seems to be add #nullable disable/enable section:

You can use null! or default!. That’s usually not a good idea because it’s literally saying “null is not null”, but in this case I think it’s OK, as it’s just a placeholder.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Shortcut to delete command but keep arguments
Shortcut to delete command but keep arguments · 1. You can save all the right arrow movements after Ctrl+A with one Alt-D –...
Read more >
What is keyboard shortcut for Spelling > Ignore All?
In Word, I can find keyboard shortcuts by pressing the Alt key. It then displays shortcut keys to the various parts of the...
Read more >
python - How to properly ignore exceptions
If you definitely want to ignore all errors, catch Exception rather than a bare except: statement. Again, why?
Read more >
How to prevent the command prompt from closing after ...
I have a solution which can only apply on .cmd and .bat files: Open regedit and go to each one of:
Read more >
The 10 Most Common Mistakes in C# Programming
Don't fall into one of these C# programming mistakes that even savvy developers can find problematic. Read on to see all 10.
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