This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi - I'm trying to mock some entities and having difficulties because none of the properties are marked up virtual. Testing works great when I've defined transient properties in an entity partial class but the LS generated entity class hasn't marked up anything as virtual. mocks go splat. Is there an option anywhere i could define an entity property as virtual (I looked in the designer under entity properties)? cheers justin |
|
|
This is not currently supported in the designer. We can look at adding this, but we would like to be sure that it is required first. Do you need the virtual members because you want to override them, or are you just wanting to use the entities in a mocking framework? If the latter, depending on your framework, an alternative is to extract the (relevant) properties into an interface, mark the entity class as implementing that interface (via a partial class), and let the framework spin up a mock implementation for you. Of course this has a broader impact on your design because it means you end up passing interface references around rather than objects... |
|
|
this is just for mocking purposes. i agree, i could use IEntities all over the place but I'd really rather not as in this case the only purpose for this would be to allow mocking. It's a lot more overhead (for me, maybe not for you ;) to change everything to use interfaces rather than objects, particularly when I only need that one property to be virtualised... it would be especially useful given that mocking out IUnitofwork (and not being able to set entitystate) is such a pain and so I'm having to deal with real objects in my tests, not just ones I construct in memory... so - to answer your question, no, it's not absolutely required, but it would be a very handy feature - there are currently some things I simply can't test (without going down the interface route) because LS generated properties aren't virtual. |
|
|
Okay, you've sold me *grin*. I will try to add virtual property support in the next day or so. By the way, concerning mocking of IUnitOfWork and not being able to set entity state, we have added a helper method OnMockSavingEntity to UnitOfWorkBase. If you call this from your mock implementation of SaveChanges, it will update the entity state and generally simulate what the real object mapper does at save time. |
|
|
The next nightly build (12 Dec 2008) will include support for marking properties as virtual. (Set the Inheritance property to Virtual.) At present this does not include association-related properties (the collection, backreference or backreference ID) or properties of value object type. If these are important for your scenario then let me know! |
|
|
okay... 1) hooray 2) um, yes, I think i do need association-related properties to be virtual please. I'm wanting to override Record.Folder which is a through association (Folders contains RecordSets which contain Records). So for a given record I'm wanting to set expectations on properties of the Folder... 3) wrt setting entitystate - that's great too. prob won't be able to do that for this project now but I'm keen to be able to create an inmemory repository for the next project so I will get onto using that. cheers justin |
|
|
Wow, tough crowd *grin*. Okay, this is now done for one-to-many associations, which should handle your Folder / RecordSets / Records scenario, and will be in tonight's nightly build. If you've got one-to-one associations in the mix as well, let me know and I'll try to get them done too. |
|
|
As an added extension to this, is it possible to default the properties to virtual?
Craig |
|
|
I'm afraid that's not currently possible. Sorry. As a workaround, the .lsmodel files are just XML, so it wouldn't be too hard to create a VS macro or other script that just ran over the XML file and inserted the appropriate attribute on entities where it wasn't specified. I realise this is ugly (and we haven't tested it!) but it might still save time (and errors) compared to doing them by hand. |
|