-
Notifications
You must be signed in to change notification settings - Fork 266
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
69 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
57 changes: 57 additions & 0 deletions
57
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,57 @@ | ||
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 subs = Substitute.For<TestClass>(); | ||
|
||
subs.SetProtectedProp(42); | ||
|
||
var result = subs.GetProtectedProp(); | ||
Assert.That(result, Is.EqualTo(expected: 42)); | ||
} | ||
|
||
[Test] | ||
public void ShouldHandlePropertyWithProtectedSetter() | ||
{ | ||
var subs = Substitute.For<TestClass>(); | ||
|
||
subs.SetProtectedSetterProp(42); | ||
|
||
var result = subs.ProtectedSetterProp; | ||
Assert.That(result, Is.EqualTo(expected: 42)); | ||
} | ||
[Test] | ||
public void ShouldHandlePropertyWithProtectedGetter() | ||
{ | ||
var subs = Substitute.For<TestClass>(); | ||
|
||
subs.ProtectedGetterProp = 42; | ||
|
||
var result = subs.GetProtectedGetterProp(); | ||
Assert.That(result, Is.EqualTo(expected: 42)); | ||
} | ||
|
||
public abstract class TestClass | ||
{ | ||
protected abstract int ProtectedProp { get; set; } | ||
public void SetProtectedProp(int value) => ProtectedProp = value; | ||
public int GetProtectedProp() => ProtectedProp; | ||
|
||
public abstract int ProtectedSetterProp { get; protected set; } | ||
public void SetProtectedSetterProp(int value) => ProtectedSetterProp = value; | ||
|
||
public abstract int ProtectedGetterProp { protected get; set; } | ||
public int GetProtectedGetterProp() => ProtectedGetterProp; | ||
} | ||
} | ||
} |