Identify precise mismatch when a complex argument constraint fails to match an argument
See original GitHub issueFrom http://stackoverflow.com/a/43781563/131809
Consider the following assertion
var fake = A.Fake<ICustomerService>();
A.CallTo(() => fake.Add(
A<Customer>.That.Matches(c =>
c.Property == "123" &&
c.OtherProperty == "345" &&
c.AnotherProperty == "456" &&
c.YetAnotherProperty == "567"
)
)).MustHaveHappened();
This gets a bit messy.
If c.AnotherProperty
is infact “890” my unit test will not tell me.
It won’t tell me that AnotherProperty
is wrong. It’ll just fail (correctly)
To work around this, I quite often do this:
var fake = A.Fake<ICustomerService>();
Customer addedCustomer;
A.CallTo(() => fake.Add(A<Customer>._))
.Invokes(c => addedCustomer = c.GetArgument<Customer>(0));
Assert.IsNotNull(addedCustomer);
Assert.AreEqual("123", addedCustomer.Property);
Assert.AreEqual("345", addedCustomer.OtherProperty);
Assert.AreEqual("456", addedCustomer.AnotherProperty);
Assert.AreEqual("567", addedCustomer.YetAnotherProperty);
I guess it’d be nice if the exception MustHaveHappened
throws if the matcher does not validate, somehow includes which property or properties didn’t match
Issue Analytics
- State:
- Created 6 years ago
- Comments:26 (21 by maintainers)
Top Results From Across the Web
Type Constraints - Configuration Language | Terraform
Type constructors are unquoted symbols followed by a pair of parentheses, which contain an argument that specifies more information about the type.
Read more >Practical heuristics to improve precision for erroneous ...
Any development or comprehension effort is set back by questioning why a particular expression was passed to a particular parameter even though the...
Read more >FIO47-C. Use valid format strings
Mismatches between arguments and conversion specifications may result in undefined behavior. Compilers may diagnose type mismatches in formatted output function ...
Read more >elm - TYPE MISMATCH - This function cannot handle the ...
You are constructing a Model value by only specifying two parameters ( Model key TopPage ). The value of that expression does not...
Read more >Error conditions in Databricks
Databricks Runtime and Databricks SQL. AGGREGATE_FUNCTION_WITH_NONDETERMINISTIC_EXPRESSION. SQLSTATE: none assigned. Non-deterministic ...
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
@alexjamesbrown, thanks for making this.
I may be missing something, but are not the calls output when
MustHaveHappened
fails to match? e.g.If you can’t tell what’s wrong, have you considered augmenting the
Customer
rendering? Either a ToString or an ArgumentValueFormatter likeyields
Given the complexity of implementing a solution where the particular failing clause is pinpointed, as well as the potential expansion of the error messages (as we’d have to indicate for each argument of each call which clause of the matcher failed), I propose that we close this wont-fix.
Objections?