-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle protected and internal property setters
- Loading branch information
Showing
3 changed files
with
66 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
tests/NSubstitute.Acceptance.Specs/FieldReports/Issue262_NonPublicSetterCall.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using NUnit.Framework; | ||
|
||
namespace NSubstitute.Acceptance.Specs.FieldReports | ||
{ | ||
/// <summary> | ||
/// Scenarios for the issue: https://github.com/nsubstitute/NSubstitute/issues/626 | ||
/// | ||
/// Do not test internal members, as we don't want to set InternalsVisibleTo attribute. | ||
/// </summary> | ||
public class Issue262_NonPublicSetterCall | ||
{ | ||
[Test] | ||
public void ShouldHandleProtectedProperties() | ||
{ | ||
var substitute = Substitute.For<TestClass>(); | ||
|
||
substitute.ProtectedPropProxy = 42; | ||
|
||
var result = substitute.ProtectedPropProxy; | ||
Assert.That(result, Is.EqualTo(expected: 42)); | ||
substitute.Received().ProtectedPropProxy = Arg.Any<int>(); | ||
} | ||
|
||
[Test] | ||
public void ShouldHandlePropertiesWithDifferentAccessorVisibility() | ||
{ | ||
var subs = Substitute.For<TestClass>(); | ||
|
||
subs.PublicGetProtectedSetPropSetter = 42; | ||
|
||
var result = subs.PublicGetProtectedSetProp; | ||
Assert.That(result, Is.EqualTo(expected: 42)); | ||
} | ||
|
||
public abstract class TestClass | ||
{ | ||
protected abstract int ProtectedProp { get; set; } | ||
|
||
public int ProtectedPropProxy | ||
{ | ||
get => ProtectedProp; | ||
set => ProtectedProp = value; | ||
} | ||
|
||
public abstract int PublicGetProtectedSetProp { get; protected set; } | ||
|
||
public int PublicGetProtectedSetPropSetter | ||
{ | ||
set => PublicGetProtectedSetProp = value; | ||
} | ||
} | ||
} | ||
} |