No way to assert a call to a setter wasnt made.
See original GitHub issueBig fan of framework, found a small annoyance:
I’d like to assert that a property setter was not called. I’m looking at your documentation, and I cant find a way to do this.
private class IntBox
{
public int IntProperty { get; set; }
}
[Test]
public void when_using_A_callTo_on_a_property_set_call()
{
var fake = A.Fake<IntBox>();
fake.IntProperty = 4;
A.CallTo(() => fake.IntProperty).WithAnyArguments().MustNotHaveHappened();
//ahhh so set calls are excluded...
// A.CallTo(() => fake.IntProperty = -1).WithAnyArguments().MustHaveHappened();
//and of course an expression cannot contain an assignment operator...
}
I would argue that the expected behavior is that
A.CallTo(() => fake.IntProperty).MustNotHaveHappened()
would check for both get
and set
calls, but this would be a breaking change in your framework and might anger a good number of people, so perhaps the simple static methods Get
and Set
on IReturnValueArgumentValidationConfiguration<T>
would suffice, so that my assertion could be:
A.CallTo.Get(() => fake.IntProperty).MustNotHaveHappened()
A.CallTo.Set(() => fake.IntProperty).MustNotHaveHappened()
Cheers!
-Geoff
Issue Analytics
- State:
- Created 11 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Rhino Mocks 3.5 Test that property setter was not called
Set the property to some known value in the test. Call the code that won't change the property, then assert that the property...
Read more >Checking received calls
The Received() extension method will assert that at least one call was made to a member, and DidNotReceive() asserts that zero calls were...
Read more >How to spy on a property (getter or setter) with Jasmine
As I mentioned earlier, it is just like spyOn so we can assign its returned reference to a new variable, we can stub...
Read more >java - Unit testing when you have no getters and setters
My question is how can you do unit tests for this class. Consider the following example: public class Account { private Money money;...
Read more >Avoid getters and setters whenever possible
The best way, though, is to not expose the member in any way at all and instead bring the behavior that manipulates the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I can confirm that @patrik-hagne 's solution above works correctly.
The “set” value is passed as the first argument, so you can do this to match the arguments (for example, to check that “IntProperty” is set to 4:
You can do it this way (from the top of my head):