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

Move state (fields) from Mock into Mock<T> #540

Merged
merged 8 commits into from
Dec 3, 2017

Conversation

stakx
Copy link
Contributor

@stakx stakx commented Dec 3, 2017

Mock state and initialization is currently split across both Mock and Mock<T>. This is not ideal for at least three reasons:

  1. It is difficult to get an idea how much state a mock object really carries.

  2. It can be hard to understand control flow (e. g. with mock object initialization), which might bounce back and forth between methods defined in both Mock and Mock<T>.

  3. It's relatively easy to introduce As<TInterface>-related bugs by directly referencing backing fields instead of their corresponding properties. As<TInterface> mocks do not use their own backing fields (which remain completely uninitialized), but instead delegate all properties to the "owner" mock's. Therefore, for As<TInterface> mocks to work correctly, code should always reference the properties, and never the backing fields. Moving the fields away from Mock (where most logic sits) helps with enforcing this.

@stakx stakx merged commit 4f5ffb8 into devlooped:develop Dec 3, 2017
@stakx stakx deleted the mock-fields branch December 3, 2017 12:28
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

Successfully merging this pull request may close these issues.

None yet

1 participant