Improve interface of Invokes to allow specifing number of calls
See original GitHub issueCurrently it is not possible to directly specify a number of calls when configuring Invokes, e.g. given the following interface:
public interface ITest
{
int Test(int testNumber);
}
a configuration like:
[Test]
public void Test()
{
var counter = 0;
var test = A.Fake<ITest>();
A.CallTo(() => test.Test(1))
.Invokes((int testNumber) => counter++)
.Once();
}
does not compile.
However, all it takes is a cast and it works flawlessly:
[Test]
public void Test()
{
var counter1 = 0;
var counter2 = 0;
var test = A.Fake<ITest>();
((IAfterCallConfiguredConfiguration<IReturnValueConfiguration<int>>)A.CallTo(() => test.Test(1))
.Invokes((int testNumber) => counter1++))
.Once()
.Then
.Invokes(() => counter2++);
test.Test(1);
test.Test(1);
test.Test(1);
Assert.That(counter1, Is.EqualTo(1));
Assert.That(counter2, Is.EqualTo(2));
}
I suppose this is unintended and the number of calls specification should be available directly, without a cast.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
java - Design pattern for interface that determines order of ...
I want to create a Java interface with a number methods. But I want the user of the interface to only be able...
Read more >Interface defining a constructor signature?
Interfaces define contracts that other objects implement and therefore have no state that needs to be initialized.
Read more >Explicit Interface Implementation - C# Programming Guide
An explicit interface implementation is a class member that is only called through the specified interface. Name the class member by ...
Read more >How to make thread-safe calls to controls - Windows Forms ...
Invoke method to call a delegate created in the main thread, which in turn calls the control. Or, implement a System.ComponentModel.
Read more >Invoke - AWS Lambda
Invokes a Lambda function. You can invoke a function synchronously (and wait for the response), or asynchronously. By default, Lambda invokes your function ......
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
Unfortunately, that would be a major breaking change that would impact every current user of FakeItEasy, just to solve a problem very few people have…
I’m sorry I seem so reluctant to accept your suggestions. They’re not necessarily bad ideas, but we need to be very careful when evolving the library. Many users rely on it, and we try to minimize breaking changes. When we do introduce a breaking change, it’s usually:
The change you propose is the worst kind of breaking change : no API change (so existing code will keep compiling without error), but a major behavior change (so existing code will suddenly start to fail at runtime without any apparent reason).
This change has also been released as part of FakeItEasy 7.0.0.