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

Additional methods in fluent syntax causes exception 'variable referenced from scope ... but it is not defined' #251

Open
develorem opened this issue Jun 5, 2017 · 2 comments

Comments

@develorem
Copy link

System: Nunit test, resharper test runner, .Net 4.6, BDDfy version 4.1.2

Example code:

this.Given(x => x.GivenTheSiteCoverageService())
       .And(x => x.GivenTheFirstAerialJobSite().WithCoverage(80m).OverSite(FirstSite))
       ....

Effectively, putting the additional methods "WithCoverage" and "OverSite" causes BDDFY to fail with exception:

An exception of type 'System.InvalidOperationException' occurred in System.Core.dll but was not handled in user code

Additional information: variable 'x' of type '' referenced from scope '', but it is not defined

Removing the fluent extensions I created for my types allows it to work.
But the alternative of complex unreadable constructors for all my permutations is wrong (shouldn't have to change the object under test). Is there a way to achieve what I'm trying to achieve here?

@develorem
Copy link
Author

Sorry, stack trace would have been helpful:

at System.Linq.Expressions.Compiler.VariableBinder.Reference(ParameterExpression node, VariableStorageKind storage)
at System.Linq.Expressions.Compiler.VariableBinder.VisitParameter(ParameterExpression node)
at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
at System.Linq.Expressions.Compiler.VariableBinder.VisitUnary(UnaryExpression node)
at System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection1 nodes) at System.Linq.Expressions.Compiler.VariableBinder.VisitLambda[T](Expression1 node)
at System.Linq.Expressions.Compiler.LambdaCompiler.Compile(LambdaExpression lambda, DebugInfoGenerator debugInfoGenerator)
at TestStack.BDDfy.ExpressionExtensions.ArgumentExtractorVisitor.GetValue(Expression a)
at TestStack.BDDfy.ExpressionExtensions.ArgumentExtractorVisitor.ExtractStepArgument(Expression a)
at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Collections.Generic.List1.InsertRange(Int32 index, IEnumerable1 collection) at TestStack.BDDfy.ExpressionExtensions.ArgumentExtractorVisitor.VisitMethodCall(MethodCallExpression node) at System.Linq.Expressions.ExpressionVisitor.VisitLambda[T](Expression1 node)
at TestStack.BDDfy.ExpressionExtensions.ExtractArguments[T](LambdaExpression expression, T value)
at TestStack.BDDfy.FluentScanner1.AddStep(Action1 action, LambdaExpression stepAction, String stepTextTemplate, Boolean includeInputsInStepTitle, Boolean reports, ExecutionOrder executionOrder, Boolean asserts, String stepPrefix)
at TestStack.BDDfy.FluentStepBuilder1.And(Expression1 step)

@develorem
Copy link
Author

develorem commented Jun 5, 2017

I suspect the offending code is the fact that the ExpressionExtensions.ArgumentExtractorVisitor.GetValue() method assumes a Func<object> when in fact the first call in my method chain returns an object as well.

I added another method onto the chain that returned the current TScenario, and then called yet another method from TScenario (which did nothing) and it now works. Having these two extra methods is a bit lame. Also it sees that last method in the call chain as the one doing the work so it pulls name information from that one, rather than the first one (no problem on that, can specify the string to show).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant