Skip to content

Commit

Permalink
Repro for #13.
Browse files Browse the repository at this point in the history
This works fine in .NET proper - only an issue for mono then, which will hopefully be rectified as they adopt more of the Microsoft OS stack.
  • Loading branch information
kentcb committed Sep 19, 2015
1 parent 67df40a commit b7129e2
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Src/Kent.Boogaart.PCLMock.UnitTests/MockBaseFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,18 @@ public void verification_takes_into_account_any_argument_filters()
mock.Verify(x => x.SomeMethodTakingString(It.IsAny<string>())).WasCalledExactly(times: 3);
}

[Fact]
public void issue13_repro()
{
var mock = new TestTargetMock(MockBehavior.Loose);
var subMock = new TestSubTargetMock(MockBehavior.Loose);
subMock.When(x => x.Height).Return(3);

mock.SomeMethodTakingComplexType(subMock);

mock.Verify(x => x.SomeMethodTakingComplexType(It.Matches<ITestSubTarget>(y => y.Height.HasValue))).WasCalledExactlyOnce();
}

#region Supporting Members

private interface ITestSubTarget
Expand All @@ -1050,6 +1062,11 @@ string Name
set;
}

int? Height
{
get;
}

int GetAge();
}

Expand Down Expand Up @@ -1088,6 +1105,8 @@ ITestSubTarget SomeComplexProperty

int SomeMethodWithReturnValue(int i, float f);

void SomeMethodTakingComplexType(ITestSubTarget a);

void SomeMethodTakingString(string s);

int SomeMethodTakingStringWithReturnValue(string s);
Expand All @@ -1107,6 +1126,24 @@ ITestSubTarget SomeComplexProperty
bool SomeMethodWithAMixtureOfParameterTypes(int i, string s, out int i2, out string s2, ref int i3, ref string s3);
}

private sealed class TestSubTargetMock : MockBase<ITestSubTarget>, ITestSubTarget
{
public TestSubTargetMock(MockBehavior behavior)
: base(behavior)
{
}

public int? Height => this.Apply(x => x.Height);

public string Name
{
get { return this.Apply(x => x.Name); }
set { this.ApplyPropertySet(x => x.Name, value); }
}

public int GetAge() => this.Apply(x => x.GetAge());
}

private sealed class TestTargetMock : MockBase<ITestTarget>, ITestTarget
{
public TestTargetMock(MockBehavior behavior = MockBehavior.Strict)
Expand Down Expand Up @@ -1162,6 +1199,11 @@ public int SomeMethodWithReturnValue(int i, float f)
return this.Apply(x => x.SomeMethodWithReturnValue(i, f));
}

public void SomeMethodTakingComplexType(ITestSubTarget a)
{
this.Apply(x => x.SomeMethodTakingComplexType(a));
}

public void SomeMethodTakingString(string s)
{
this.Apply(x => x.SomeMethodTakingString(s));
Expand Down

0 comments on commit b7129e2

Please sign in to comment.