void SetNestedPropertyNoSetup() { var moq = new Mock <IPropertyType>(); var sut = new APropertyUser(moq.Object, 42); Assert.Throws <NullReferenceException>( () => sut.CompareCustom() ); }
void SetNestedPropertySimpler() { var moqType = new Mock <IPropertyType>(); var sut = new APropertyUser(moqType.Object, 42); // Works only if the property is virtual moqType.Setup(x => x.CustomTypeProperty.Property).Returns(42); Assert.True(sut.CompareCustom()); }
void SetNestedProperty() { var moqType = new Mock <IPropertyType>(); var moqValue = new Mock <AClassWithProperty>(); var sut = new APropertyUser(moqType.Object, 42); moqValue.Setup(x => x.Property).Returns(42); moqType.Setup(x => x.CustomTypeProperty).Returns(moqValue.Object); Assert.True(sut.CompareCustom()); }