Bump.
Suppose I've got 3 classes, B, C, and D, all of which inherit from the
abstract class A, and I'm writing a web service. When I deserialize
JSON, I need to deserialize it as the child class, otherwise it will
lose all of the child's information. In my mocks, is there any way to
replace three mocks with just one? Something like replacing :
_serviceHelpers.Setup(sh =>
sh.DeserializeRepresentation<B>(It.IsAny<string>(),
It.IsAny<string>())).Returns((() => _testA as B)).Verifiable(); //
cast as B so the types agree
_serviceHelpers.Setup(sh =>
sh.DeserializeRepresentation<C>(It.IsAny<string>(),
It.IsAny<string>())).Returns((() => _testA as C)).Verifiable();
_serviceHelpers.Setup(sh =>
sh.DeserializeRepresentation<D>(It.IsAny<string>(),
It.IsAny<string>())).Returns((() => _testA as D)).Verifiable();
with:
_serviceHelpers.Setup(sh =>
sh.DeserializeRepresentation<A>(It.IsAny<string>(),
It.IsAny<string>())).Returns((() => _testA).Verifiable();
And have it fire for any subclass of A?