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

Check.ThatCode immediatly executes the lambda function before extension method is used #152

Open
hahn-kev opened this issue May 26, 2016 · 1 comment

Comments

@hahn-kev
Copy link

hahn-kev commented May 26, 2016

I would like to write an extension method to use with Check.ThatCode, however in my case I would like to do some setup before the lambda function provided gets called.

Currently when calling ThatCode the lambda function gets executed and the result, possible exception and execution time get stored so that the extension methods can Check against those.

However I would like to write my own check to use a mocking framework to test if a method was called on a object in a static context. The check might look something like this
Check.ThatCode(() => StaticClass.Instance.Execute()).Not.CallsExecute()

However in order to do that I need to replace the object in StaticClass.Instance with one from my mocking framework BEFORE the code gets executed. Would it make sense to change how Check.ThatCode works to wait to execute the provided function until ExecuteCheck is called

@dupdob
Copy link
Collaborator

dupdob commented May 27, 2016

Thanks for a pretty clear description of your need.
This request is actually tricky: ExecuteCheck is called for every tests done on the code. Which means if we simply delayed the run until ExecuteCheck, the checked code could be run several time, which is not desirable.
The proper approach implies being able to provide custom code to be executed before and after execution. Alternatively and probably better, a chain of responsibility for ExecuteCheck

@dupdob dupdob changed the title Check.ThatCode immidatly executes the lambda function before extension method is used Check.ThatCode immediatly executes the lambda function before extension method is used Jun 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants