-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding method to set public property setters after object is constructed #2
Comments
Here's what I mean:
Usage:
|
If you like it, I can send you a pull request later. |
Hi mate - good to hear from you! Thanks for the suggestion :) In this case it's actually a deliberate design choice that you reference the properties explicitly when initialising the object. This framework was explicitly designed for creating domain models with protected setters on properties and constructors that enforce domain invariants. By forcing you to use the constructor it ensures you are meeting all domain invariants of the objects generated for your test and the test code is performing tests using objects that can exist in production (rather than objects that are potentially inconsistent). If you have objects that don't conform to that then either you will have public setters (in which case newing up the objects with the setters being set at the same time is just as terse) or you can easily use NBuilder to do it. Alternatively, the .AsProxy() functionality in NTestDataBuilder will set .Returns on all public properties based on the values you have set and achieves the same result (except of course all virtual methods will be mocked). If there are other scenarios that NTestDataBuilder accommodates that you think NBuilder doesn't, but it would require this change, or other changes I'm all ears :) |
:) Hm... it doesn't break the domain invariance - you still have to call the ctor yourself - it's just that properties are set automatically, without creating a proxy. You could run a check for non public setters and throw to avoid use private setters. I guess it's not worth doing if AsProxy() does the same job, though I'm not sure how it would affect calculated properties etc. |
You can break invariance if you set a property that doesn't have a public setter. Most of the classes we create have protected setters which is the viewpoint I was coming from. If you see a use for the library and you have public property setters and would find that method useful I'm more than happy to put it in, I would just want to change it to only set public setters. AsProxy would work for calculated properties if they aren't virtual, ortherwise you would need to set what value they should be. |
Whatever you think, it's your project after all - I'm happy just implementing this behavior on my project! And yes, limiting to public setters makes sense Date: Sat, 10 Aug 2013 01:59:35 -0700 You can break invariance if you set a property that doesn't have a public setter. Most of the classes we create have protected setters which is the viewpoint I was coming from. If you are a use for the library and you have public property setters and would find that method useful I'm more than happy to put it in, I would just want to change it to only set public setters. AsProxy would work for calculated properties if they aren't virtual, ortherwise you would need to set what value they should be. — |
Cool. While it's an easy change to make it's not high on my priorities at the moment - there are a few other projects that have more important changes I have lined up. If this becomes important for you though feel free to ping back and I'll make some time to add it in. |
No rush, you've done well and made an interface for this so I can customize to my heart's content :) |
What is actually |
Robert! Looks like you have a knack for testing frameworks (I've made some fuss about Seleno) :)
Say, isn't it quite redundant to manually apply the lambda expressions to the test object in BuildObject() - any reason why you didn't just loop over them and set them yourself?
The text was updated successfully, but these errors were encountered: