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
Exceptions in event accessors fail tests when using .Monitor() #1948
Comments
I'm not sure how we can fix this. The job of |
The method |
OK. That would be possible. However, unless somebody is willing to contribute that change, I don't think it's going to get a lot of priority. |
@dennisdoomen I already forked and implemented it. The default behavior won't be changed. I added an optional So a normal call would look like this:
Would you be OK with that? |
I recommend to ignore specific events instead of "exception when accessing any event". This looks very specific to your scenario. |
I see your argument. I have no strong opinion about how to resolve this. What you are suggesting is closer to the rest of the framework, which I think is a good thing to do. I never used the BeEquivalentTo exclusions. I will have a look at them next week and come up with a suggestion. My approach is more pragmatic to solve the problem, as it will ignore all events which have "broken" event accessors and leave the rest as is. So you do not have to change the test when some more not used event accessors may get broken in the future, too. This is following the SOLID principles (SRP - Only one reason to change). Which I think is also a good thing to consider. But I am also a fan of having choices, so why not both approaches? I just don't want to do both in one merge request / feature request. |
I would change it to:
|
I had this with the |
Description
When an event handler accessor has an explicit implementation, which throws an exception on the setter,
.Monitor()
is failing the test completely.What is my motivation?
I need to test the class behavior without changing the other base event handler accessors behavior. It could cause unwanted side effects. But I do not need to test this event. I just wanted to test PropertyChanged events being raised. Therefore, I would like to have the benefit of having the full class available to write expressions in the assertion.
Suggestion:
Make some more configuration options for the Monitor. Like ignoring failing events, or just subscribing to a subset of interfaces with those events, or putting some events on ignore, without changing the generic Type, which is used to assert / monitor.
Benefit:
Using the great syntax you introduced in monitor on brown field projects or if you are not able to change the behavior of some event accessors. Therefore, write better and cleaner test code from the beginning.
Complete minimal example reproducing the issue
Expected behavior:
FluentAssertions is able to have options in the monitor to ignore failing event handlers.
Actual behavior:
It throws an exception when .Monitor() is called and I can do nothing about it, event though I do not want to test this specific event.
Versions
FluentAssertions Version 6.7.0
Additional Information
I already implemented my custom implementation of the monitor and would offer to contribute my suggestion above to the FluentAssertions project. I just wanted to talk to you first, if you would approve of such an enhancement of the monitor or if you disagree on this feature for some reason.
So let me know if you agree or disagree.
cheers!
The text was updated successfully, but these errors were encountered: