You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into an exception when trying to write a test using the 4.3.2 version of the library. The exception was from linq but originating in the library code
System.InvalidOperationException : Sequence contains more than one matching element
Stack Trace:
at System.Linq.ThrowHelper.ThrowMoreThanOneMatchException()
The exception seems to be caused by naming a method parameter in the given when then chain the same as one of the example variables in the test. So the parameter in the TheNumberShouldBe method is number. There is also a example table variable for number.
Obviously, this a forced example but I ran into this unintentionally by just naming variables and parameters what I thought made sense. Renaming it to anything other than number fixes the test. Including renaming it to expectedNumber.
Now that I know what the cause is it is easy enough to fix and avoid but it took a while and a lot of hacking around to find an answer. The way the library determines the variable mappings might mean this cannot be fixed but perhaps could the library throw a more descriptive exception? Potentially including the name of the conflicting variable to make it easy for people to discover the fix?
The text was updated successfully, but these errors were encountered:
michaelsw95
changed the title
Undescriptive 'more than one match exception'
Example table variable conflicts with method parameters
Feb 3, 2022
michaelsw95
added a commit
to michaelsw95/TestStack.BDDfy
that referenced
this issue
Mar 25, 2022
I ran into an exception when trying to write a test using the 4.3.2 version of the library. The exception was from linq but originating in the library code
Here is an example of how to trigger it
The exception seems to be caused by naming a method parameter in the given when then chain the same as one of the example variables in the test. So the parameter in the
TheNumberShouldBe
method isnumber
. There is also a example table variable fornumber
.Obviously, this a forced example but I ran into this unintentionally by just naming variables and parameters what I thought made sense. Renaming it to anything other than
number
fixes the test. Including renaming it toexpectedNumber
.Now that I know what the cause is it is easy enough to fix and avoid but it took a while and a lot of hacking around to find an answer. The way the library determines the variable mappings might mean this cannot be fixed but perhaps could the library throw a more descriptive exception? Potentially including the name of the conflicting variable to make it easy for people to discover the fix?
The text was updated successfully, but these errors were encountered: