Reputation: 65
I want to create a mock of ImageSource for unit test purposes. ImageSource has an internal constructor and I can't neither create a mock nor create an inherited class. As is explained here for brushes, but it also fits for ImageSource: How do I implement a custom Brush in WPF?
Is there any workaround for that?
Upvotes: 1
Views: 325
Reputation: 5417
If I understand your situation correctly you want to create a mock for a sealed class with no public constructor.
You can't do this with Moq.
As a workaround you coudl use other "mocking/isolation" frameworks, ie: TypeMock, which supports this feature. You may also have luck with Microsoft Moles.
On the other hand, if you are trying to inject a mocked instance of ImageSource in a framework class, that would be a smell that something may be wrong with your test.
At the very least, you could abstract away the framework class with another class that you could mock, removing the need for your this to use this class and ImageSource directly.
Upvotes: 2