zengcheng / codesmith

Automatically exported from code.google.com/p/codesmith
0 stars 0 forks source link

Enhancement of CSLA templates to allow Mockable DataAccess Layer #426

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I have only converted the fetch method on the Order Business Object to use a 
mock DAL. I have converted more objects in our own code but I am unable to send 
that out, so I would have to do more of the petshop application if you want to 
see more.

I think the best way to include this in the current templates would be to add 
another option to the list of Data Access Implementations called 
ObjectFactoryStoredProceduresWithDtos. If you don’t like adding Unity as a 
dependency in this situation I would still see a lot of value in just making it 
so the Object factory uses a hard coded DAL object which returns a DTO. The 
hard work is in creating all the DTOs and DALs which are really just 
boilerplate code. In fact the DALs are almost exactly what you have in the 
object factories at the moment. By adding this extra abstraction though you 
allow for mocking as you can see by the test I have written. It also follows 
the Single Responsibility pattern by making the object factory just a factory 
not a DAL as well.

These are the changes I have made to the solution I downloaded from the 
codesmith site:

There are no changes at all to the petshop.business project, all the changes 
required are in the petshop.data project.
Add UnitySingleton Class
Add reference to Micosoft.Practices.Unity
Create a DTO per entity
Create a Dao per entity
Create a Dao Interface per Entity
Add one line to the top of every factory class to create a dao and resolve its 
type from the unity Singleton.
Modify the map helper method to take a dto
I have removed the Web UI and Test Project
I have created another test project which uses rhino mocks and Nunit to show 
how I use a mock to insulate the test from any real external DB.

Original issue reported on code.google.com by alancjoh...@gmail.com on 22 Jun 2010 at 1:14

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 22 Jun 2010 at 2:02

GoogleCodeExporter commented 9 years ago
Hello,

I took a look into this, I like how this is implemented, but I think if you are 
not using Object Factory than you are left out in the dark :s.

I think that a lot of code could be reduced by making the IObjectDao into a 
generic interface like IStore<DTO>. I'd really like to get rid of a dto object, 
but if it is only present in the data project than I can live with that :).

I think that I would move the Interfaces to an \Inteface folder, move the dto's 
to reside under the ObjectFactory classes and make them use merge regions.

I don't think it would take very much to generate this. Would you be interested 
in updating the templates? I'd add a new generation option for unit tests.

Thanks
-Blake Niemyjski

Original comment by bniemyjski on 8 Jul 2010 at 9:34

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 15 Jul 2010 at 3:48

GoogleCodeExporter commented 9 years ago
Blake,

Mock data would make a great topic for some blog posts. I would love to see how 
folks are unit testing there CSLA objects. I wonder if alancjohnson, might be 
posting anyway about this.

Original comment by madcoo...@gmail.com on 15 Jul 2010 at 9:38

GoogleCodeExporter commented 9 years ago
bump

Original comment by gyo...@gmail.com on 28 Oct 2011 at 12:03

GoogleCodeExporter commented 9 years ago
I'd like to see this happen as well :)

Original comment by bniemyjski on 1 Nov 2011 at 3:43

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 9 Mar 2012 at 1:10