Skip to content

Commit

Permalink
Failing tests for SetupProperty on sub-mock
Browse files Browse the repository at this point in the history
  • Loading branch information
stakx committed Mar 6, 2022
1 parent dcf631e commit f160ad8
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/Moq.Tests/Regressions/IssueReportsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3740,6 +3740,48 @@ public void Pass_byte_array_indirectly_via_method_call()

#endregion

#region 1240

public class Issue1240
{
public interface IFoo { IBar Bar { get; } }
public interface IBar
{
string Prop1 { get; }
string Prop2 { get; set; }
}

[Fact]
public void Property_on_submock_should_be_stubbed_1()
{
const string prop2 = "Prop2";
var mock = new Mock<IFoo>();

// mock.SetupGet(m => m.Bar.Prop1).Returns("Prop1");
// ^ This line being commented out is the only difference from the test below.
// Its absence would cause a `NullReferenceException` later.

mock.SetupProperty(m => m.Bar.Prop2);
mock.Object.Bar.Prop2 = prop2;
Assert.Equal(prop2, mock.Object.Bar.Prop2);
}

[Fact]
public void Property_on_submock_should_be_stubbed_2()
{
const string prop2 = "Prop2";
var mock = new Mock<IFoo>();

mock.SetupGet(m => m.Bar.Prop1).Returns("Prop1");

mock.SetupProperty(m => m.Bar.Prop2);
mock.Object.Bar.Prop2 = prop2;
Assert.Equal(prop2, mock.Object.Bar.Prop2);
}
}

#endregion

// Old @ Google Code

#region #47
Expand Down

0 comments on commit f160ad8

Please sign in to comment.