Skip to content

Commit

Permalink
#4 Add missing tests for shimming setters on value types
Browse files Browse the repository at this point in the history
  • Loading branch information
sguldmund committed Jan 13, 2024
1 parent 5505eba commit ada9c53
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion test/Pose.Tests/ShimTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,50 @@ public void Can_shim_property_setter_of_specific_instance()

public class ValueTypes
{
private struct Instance
{
public string Text { get; set; }
}

}
[Fact]
public void Can_shim_property_setter_of_any_instance()
{
// Arrange
var invocationCount = 0;

var shim = Shim
.Replace(() => Is.A<Instance>().Text, true)
.With((ref Instance @this, string prop) => { invocationCount++; });

// Pre-act assert
invocationCount.Should().Be(0, because: "the shim has not been called yet");

// Act
PoseContext.Isolate(
() =>
{
var instance1 = new Instance { Text = "Hello" };
var instance2 = new Instance { Text = "Hello" };
}, shim);

// Assert
invocationCount.Should().Be(2, because: "the shim was invoked 2 times");
}

[Fact]
public void Cannot_shim_property_setter_of_specific_instance()
{
// Arrange
var instance = new Instance();
Action act = () => Shim
.Replace(() => instance.Text, setter: true)
.With((ref Instance @this) => string.Empty);

// Assert
act.Should().Throw<NotSupportedException>(because: "instance methods on specific value type instances cannot be replaced");
}
}

public class SealedTypes
{
private sealed class SealedClass
Expand Down

0 comments on commit ada9c53

Please sign in to comment.