You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an interface A with a read-only property P, and a derived interface B
that shadows P as read/write. When I mock using interface B to write P,
and pass that mocked object to a service expecting interface A, P “becomes” null.
I observed this behaviour on both v4.8.2 and v4.13.0.
using Moq;using NUnit.Framework;publicinterfaceIReadOnly{intValue{get;}}publicinterfaceIReadWrite:IReadOnly{newintValue{get;set;}}publicclassTester{[Test]publicvoidTestMock(){varreadWrite=newMock<IReadWrite>();
readWrite.SetupAllProperties();
readWrite.Object.Value =42;IReadOnlyreadOnly= readWrite.Object;
Assert.AreEqual(readWrite.Object.Value, readOnly.Value);}}
The text was updated successfully, but these errors were encountered:
Simple answer, IReadOnly.Value and IReadWrite.Value are two distinct properties. You're telling the compiler via the new keyword. So obviously setting one property won't affect the other one.
I have an interface A with a read-only property P, and a derived interface B
that shadows P as read/write. When I mock using interface B to write P,
and pass that mocked object to a service expecting interface A, P “becomes” null.
I observed this behaviour on both v4.8.2 and v4.13.0.
The text was updated successfully, but these errors were encountered: