-
-
Notifications
You must be signed in to change notification settings - Fork 802
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
Mock.As behavior change #1051
Comments
Could you please provide a complete minimal code example that compiles without errrors? |
I have been able to fix my immediate issue but i'll still get a repro together for the example. |
I have been able to get my specific tests working but will continue with this issue so one of the maintainers of Moq can determine if this is an intentional impact or represents a bug in how moq now works. I realize out interface hierarchy is perhaps a little convoluted. The attached Zip contains a minimal sample that represents our setup closely enough. [ In the WidgetTestExtensions class, there are two methods I want to mention: The first is the version of the method that worked under Mock 4.7.8. The second is the version I have got working under Mock 4.14.5. |
Thanks for the repro code @bluechrism. Will take a look sometime during the next few days. |
This change was introduced with 9f65584, between Moq versions 4.7.63 and 4.7.99. If memory serves, back then, As to your particular scenario @bluechrism, yes, your type hierarchy is rather involved. Can you simplify your repro solution any further? |
Closing this issue due to inactivity. |
We recently updated from Moq 4.7.8 to Moq 4.14.5 and while most of the breaking changes were easy enough to work out, a few things are becoming much more painful. One of those things seems to be a change in the behavior of some properties on a class that uses Mock.As to mock out various interfaces where the same property is present in each.
It may be a fairly convoluted interface hierarchy, but these things represent a value that can change between a defined set of positions of T, as long as the object is enabled. The version with index is something that changes by index of the target value rather than providing the actual value we want to use. The ReadOnly version is used if we don't want a consumer to be able to make changes. For now, I'm going to use the name Widget for these. We create these objects as concrete classes of Widget and pass them around by interface. There are tests that are attempting to verify a mocked Thing's value is updated, or where the change of value of a mocked Thing is a trigger for some other change. A mock that might be passed into a class might be as IWidget or IWidgetWithIndex, but then in a child method, or event handler used as IReadOnlyWidget, and so changes that are made need to be reflected in the mock object regardless which interface is being used.
Example interface hierarchy
Example extension class for testing - the two public extensions call the private one.
After banging around at the real tests that expected the states of these Widgets to be changing and seeing them not change,
I ended up creating a test to test the Moq extensions for the Enabled property and it looks like this:
With Moq 4.7.8 this test passes.
After updating to 4.14.5, without the change motioned in the extensions class, it would now fail at the first checks to verify the original enabled value is set. Now it fails checking the updated state as IWidget or IReadOnlyWidget.
I can't figure out any version of the extension method to setup the setter which works for IWidgetWithIndexas well as IWidget and IReadOnlyWidget - if I get IWidgetWithIndex working, the other two break, and vice versa.
Note that a similar test for Mock does work (take the above and strip out the last of each set of asserts). Also similar tests for Position also work, but Position isn't on the IWidgetWithIndex interface.
The text was updated successfully, but these errors were encountered: