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
|
Why does Repository<T> defines UnitOfWorkScope rather than UnitOfWork? Doesn't that seem to violate the Law of Demeter as well as make testing somewhat harder? |
|
|
I'm having problems unit testing a presenter which takes UnitOfWorkScopeBase (Which does not have a public constructor) could any-one refer me to an example of that?
|
|
|
I believe the reason was to facilitate the use of a singleton repository instance rather than e.g. instantiating it on each request. By using a scope, a repository could be shared across e.g. multiple Web requests but each request would still automatically get its own unit of work. This would have eased porting for customers migrating from LightSpeed 1 where Repository was a static class and units of work were not explicit. I've passed your question about unit testing presenters to someone else who has more experience than I do of unit testing LightSpeed applications. |
|
|
Great! Correction- i accidentally wrote "presenter" where i meant a reopsitory (inheriting from lightspeed's repository base class). I have been really struggling with this (trying to mock a uowScope and a uow). |
|
|
Do you have any examples of mocking the uowBase? |
|
|
Hi, As UnitOfWorkScopeBase is abstract you will need to implement your own testing scope for testing purposes. There are only two properties that you need to implement. You can then pass this object in place of your normal unit of work scope. Here's an example: public class TestScope : UnitOfWorkScopeBase<Model.UnitOfWork> I hope that helps, John-Daniel Trask |
|
|
Thank you, How do i mock a UnitOfWork?
|
|
|
Hi, The quickest approach is to inherit from the UnitOfWorkBase class which is abstract and implement the members as you see fit. If you're a LightSpeed 3.0 user then we include the Mindscape.LightSpeed.Testing.TestUnitOfWork class which is a pre-canned test unit of work that allows you to set the expected results on and have it return the expected results when various methods are called. I hope that helps, John-Daniel Trask |
|