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

Ensure incorrect implementations of ISerializable are caught properly #370

Merged
merged 2 commits into from
Jun 12, 2017

Conversation

stakx
Copy link
Contributor

@stakx stakx commented Jun 11, 2017

This fixes #340.

Moq tries to work around DynamicProxy's refusal to proxy types that implement ISerializable improperly. It does so by defaulting to EmptyDefaultValueProvider for such types (which will never try to mock them, but simply returns null instead).

Moq's logic to detect bad ISerializable implementations however is currently faulty itself: It checks for the presence of a deserialization constructor and/or a virtual GetObjectData method without first checking whether the type in question implements ISerializable.

This issue gets fixed here. All necessary logic is moved to SerializableTypesValueProvider where it belongs. Additionally, tests are added that document why that class was added to Moq in the first place.

`SerializableTypesValueProvider` is supposed to work around Castle
DynamicProxy refusing to proxy classes that implement ISerializable
incorrectly. In such cases, Moq is supposed to just fall back to
the empty default value provider, even when a mock has been set up
to use the mock default value provider.

The problem was mentioned in GitHub issue devlooped#163, and there was even
a test demonstrating how Moq previously propagated DynamicProxy's
exception. A fix was then added to Moq, but no tests. This commit
adds some. Better late than never.
Until now, Moq checked the presence of a deserialization ctor and of
a virtual `GetObjectData` method without first checking whether a
type actually implements `ISerializable`.

These checks happen inside `SerializedTypesValueProvider`, so all
related methods are moved there. Also, this value provider is exclu-
ded from .NET Core builds, since .NET Core does not have `ISerializ-
able` in the first place.
@stakx stakx merged commit 8299edc into devlooped:develop Jun 12, 2017
@stakx stakx deleted the iserializable branch June 12, 2017 21:00
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