Skip to content
This repository was archived by the owner on Jun 30, 2023. It is now read-only.

Conversation

@kzu
Copy link
Member

@kzu kzu commented Jan 17, 2018

No description provided.

kzu added 3 commits January 17, 2018 02:23
The `IMocked` interface should typically only be used to
gain access to the instrospection API via its `Mock` property,
and nothing more. All other interactions should happen directly
with the `IMock` instead.

This simplifies the API and makes it more explicit what each
interface is intended for.
Renamed the MockBehavior to DefaultMockBehavior so it does not
collide with the enum MockBehavior from Moq (former is from Sdk,
implementing IMockBehavior).

Did the same with MockInfo -> DefaultMock, since the reason for
not using Mock for it is that the generic factory for mocks (.Of<T>),
which needs to live in the test project, is also called Mock.

Finally, the InvocationInfo was also a confusing name for something
that was essentially the extraction of the InvokeBehavior delegate
from IStuntBehavior so that it was independent of its AppliesTo.
In the context of Stunts, both the AppliesTo and the InvokeBehavior
go together, since that's how you conditionally apply them. In the
context of Moq, however, the AppliesTo becomes IMockSetup, which
is more complex than a simple lambda (needs to perform argument
matching, allow comparisons for equality, etc.), and it's the key
into the list of actual delegates that implement the set of mock
behaviors to apply when an invocation matches the setup (very
much an inner pipeline for the matching setup+behaviors within
the larger overall stunt pipeline).

So the new interface containing just the *behavior* sans the
AppliesTo from IStuntBehavior, is called simply IBehavior (yes,
the term is quickly becoming super overloaded :( ). Hence, the
former InvocationInfo is now just Behavior. By making it an interface,
we can also simplify the implementation of the ReturnsBehavior,
since it doesn't need to adhere to the contract of having Kind+
Name like before.

Took the chance to leverage [DebuggerDisplay] for the ReturnsBehavior
instead of ToString, and also made the DisplayName in IBehavior a
Lazy<string> for cases where computing the value may be costly.
By moving the set up of the default mock behaviors to
the extension method IMocked.SetBehaviors(MockBehavior),
we can reuse directly from both VB and C# content files
APIs, as well as provide uniformity for custom mocks
created manually that also want to have the default
mock behaviors set up quickly and consistently with
factory-created Mock.Of<T> mocks.
@kzu kzu merged commit 2f2a0c3 into master Jan 17, 2018
@kzu kzu deleted the consistency branch January 17, 2018 06:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants