I want to mock the hidden property Identity
, but MyChannelMock.Object.Identity
is null
after constructor is called.
The class looks like this:
public abstract class CommunicationRouter<TChannelType>
where TChannelType : class, ICommunicationChannel
{
protected readonly Mock<TChannelType> MyChannelMock;
protected CommunicationRouter()
{
MyChannelMock = new Mock<TChannelType>();
// object that's not null
var identity = new SomeIdentity();
// 1st method I've tried to mock but return is null
MyChannelMock.Setup(_ => _.Identity).Returns(identity);
// 2nd method I've tried to mock but return is also null
MyChannelMock.As<ICommunicationChannel>().Setup(_ => _.Identity).Returns(identity);
}
}
interface ICommunicationChannel
{
public MyType Identity{get;set;}
}
interface ICustomChannel : ICommunicationChannel
{
public new MyType2 Identity{get;set;}
}
I can not find the problem of this mock nowhere, so I'll appreciate if u can give me any others tips.