question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New syntax for configuration of property setters

See original GitHub issue

I have simple class

public class Simple
{
    public virtual int VirtualProperty { get; set; }
}

When i run (FakeItEasy.1.13.1)

var strict = A.Fake<Simple>(options => options.Strict());
A.CallTo(() => strict.VirtualProperty).CallsBaseMethod();
strict.VirtualProperty = 999;

I get an error Call to non configured method “set_VirtualProperty” of strict fake.

And I have to

var strict = A.Fake<Simple>(options => options.Strict());
A.CallTo(strict).Where(a => a.Method.Name == "get_VirtualProperty").CallsBaseMethod();
A.CallTo(strict).Where(a => a.Method.Name == "set_VirtualProperty").CallsBaseMethod();
strict.VirtualProperty = 999;

Does CallBaseMethod () works for virtual property? What am I doing wrong


Update

The proposed syntax is:

A.CallToSet(() => foo.Bar)…
A.CallToSet(() => foo.Bar).To(42)…
A.CallToSet(() => foo.Bar["the answer"]).To(42)…
A.CallToSet(() => foo.Bar).To(() => A<int>.That.IsGreaterThan(0)))…
A.CallToSet(() => …).WithAnyArguments()…
A.CallToSet(() => …).WhenArgumentsMatch(call => …)…

These methods would allow configuration of the call in the same way that is currently provided by

A.CallTo(foo).Where(a => a.Method.Name == "set_Foo" ... )...

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:132 (121 by maintainers)

github_iconTop GitHub Comments

2reactions
adamralphcommented, Apr 20, 2016

How about:

Given a fake with a property # I think "configurable" can be assumed
  And assignment of the property is configured for any value
 When I assign the property
 Then the configured behaviour is used
1reaction
adamralphcommented, Apr 5, 2016
A.CallToSet(() => foo.Bar["the answer"]]).To(42)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Property getters and setters
Accessor properties are represented by “getter” and “setter” methods. In an object literal they are denoted by get and set :.
Read more >
Guide to @ConfigurationProperties in Spring Boot
A quick and practical guide to @ConfigurationProperties annotation in Spring Boot.
Read more >
Init only setters - C# 9.0 draft feature specifications
This feature specification describes the rules for 'init' only setters in properties. These can be set only as part of an instantiation, ...
Read more >
Immutable @ConfigurationProperties - java
So your actual code without any setter is now fine : @ConstructorBinding @ConfigurationProperties(prefix = "example") public final class ...
Read more >
Learn C# Properties: Getters and Setters at Intermediate ...
"To create a property, use the same syntax as for fields, but add a get; to generate a getter and a set; to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found