File tree Expand file tree Collapse file tree
tests/Moq.Tests/Regressions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3740,6 +3740,48 @@ public void Pass_byte_array_indirectly_via_method_call()
37403740
37413741 #endregion
37423742
3743+ #region 1240
3744+
3745+ public class Issue1240
3746+ {
3747+ public interface IFoo { IBar Bar { get ; } }
3748+ public interface IBar
3749+ {
3750+ string Prop1 { get ; }
3751+ string Prop2 { get ; set ; }
3752+ }
3753+
3754+ [ Fact ]
3755+ public void Property_on_submock_should_be_stubbed_1 ( )
3756+ {
3757+ const string prop2 = "Prop2" ;
3758+ var mock = new Mock < IFoo > ( ) ;
3759+
3760+ // mock.SetupGet(m => m.Bar.Prop1).Returns("Prop1");
3761+ // ^ This line being commented out is the only difference from the test below.
3762+ // Its absence would cause a `NullReferenceException` later.
3763+
3764+ mock . SetupProperty ( m => m . Bar . Prop2 ) ;
3765+ mock . Object . Bar . Prop2 = prop2 ;
3766+ Assert . Equal ( prop2 , mock . Object . Bar . Prop2 ) ;
3767+ }
3768+
3769+ [ Fact ]
3770+ public void Property_on_submock_should_be_stubbed_2 ( )
3771+ {
3772+ const string prop2 = "Prop2" ;
3773+ var mock = new Mock < IFoo > ( ) ;
3774+
3775+ mock . SetupGet ( m => m . Bar . Prop1 ) . Returns ( "Prop1" ) ;
3776+
3777+ mock . SetupProperty ( m => m . Bar . Prop2 ) ;
3778+ mock . Object . Bar . Prop2 = prop2 ;
3779+ Assert . Equal ( prop2 , mock . Object . Bar . Prop2 ) ;
3780+ }
3781+ }
3782+
3783+ #endregion
3784+
37433785 // Old @ Google Code
37443786
37453787 #region #47
You can’t perform that action at this time.
0 commit comments