Model View Presenter, ObjectContainerDataSource and ECO

by john 2/10/2008 8:14:00 AM

I have recently been following the model view presenter pattern when developing web applications. The DataSource components found in ASP.Net won't work, so I began using ObjectContainerDataSource found in the Web Client Software Factory.

I particularly like ECO, a model powered framework for dotnet. I have therefore been investigating using ECO as the model with ObjectContainerDataSource. The datasource component requires that domain objects in the model have a parameterless constructor which I don't believe fits too well with ECO.

I have extended ObjectContainerDataSource by adding events which allow the model to construct the domain objects. 

I figured others might like the results of my investigation so I have placed the the sample code in CodeCentral.

The example is composed of a package with the extended ObjectContainerDataSource component and an ECO powered ASP.Net web application. Persistence is provided by Blackfish.

The web application is composed of 2 webpages.

 AllEmployees.aspx displays a list of employees as can be seen below. Two hyperlinks are available for inserting and editing the selected employee.

 

The second webform is for inserting, editing and deleting employees.

 

Common to each aspx is a Presenter class that handles the interaction between the webform and the model. Thats AllEmployeesPresenter and EmployeePresenter.

Each webform implements an interface through which the presenter moves domain objects back and forth to the model. There is a single model class used by both presenter classes. The model uses ECO as the data access layer.

 One of the primary reasons to use the MVP pattern is that it makes testing easy. I have a unit for each aspx file  that contains unit tests.

The picture below shows ECOMvPWebApplication.dll loaded in NUnit.

 

The tests are exercising the presenter objects. Presenter objects access the user interface through a interface. Objects implementing the interface are passed into the constructor of each presenter.

Each of the WebForms implement the appropriate interface  IAllEmployeeView or IEmployeeView. It would be quite difficult to pass in an actual instance of a webform so I've used NMock a mocking library to provide fake implementations of objects that implement the required interfaces.

The end result is that I can concentrate on directly testing my code. 

Notes

To run the webapplication you should just need to build the projectgroup. I have included the NUnit and NMock runtimes in the lib subdirectory. There is also a copy of the server control assembly from the Web Client software factory.

The sample uses ECO and Blackfish currently available in CodeGears Delphi 2007.

The Blackfish database is in the WebApplications App_Data. You will probably need to modify the database connection string in PersistanceMapperProvider.pas, currently its

 

Self.dataStoreConnection1.ConnectionString := 'host=LocalHost;database=c:\' +  'develop\moshine\ExtendedObjectContainerDataSource\EcoMVPWebApplication\App_Data\EcoWebApplication6.js;user=' +
  'sysdba;password=masterkey;create=false';



Conclusion

In my opinion the following are true:- 

Developing database centric web applications is alot easier and faster using Eco.

Using the MVP pattern makes it easier to test and well tested code is important.

The code for this sample can be found here in CodeCentral

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Delphi | CodeGear | ASP.Net 2.0 | NUnit | NMock | TDD | Blackfish | ECO | MVP

Related posts

Comments

2/11/2008 5:42:35 PM

http://

Hi John
Thanks for writing this ECO Delphi article for MVP.Till now i have found all ECO gurus writing only C# articles for MVP with ECO..
While I could run every thing I was not able to test the Test application.How to load ECOMvPWebApplication.dll n NUnit.(i am able to compile the test application .But i get no teat cases in the treeview)
Venkatesh

http://

2/11/2008 8:15:59 PM

http://

Your welcome.

What version of NUnit are you using ?

I'm using 2.4.3. In this version the GUI runner is called NUnit.exe and can be located in the NUnit bin directory.

http://

2/12/2008 12:10:19 AM

http://

I am using 2.4.6.I just ran the test application & i got only an empty GUI without any test cases.Do you have to separately load the EcoMVPApplication.dll
Venkatesh

http://

2/12/2008 11:18:46 AM

http://

You run the nunit application, do open project from the menu and select ecomvpapplication.dll You can also pass the assembly name as a parameter to nunit so that you can run the tests from the IDE.

http://

2/13/2008 4:00:11 AM

http://

Where is the source for your unit tests?

http://

2/13/2008 4:57:37 AM

Hi John

I'd be willing to share my ECO->MonoRail integration if you'd like to try that MVC approach to writing web apps? Smile

Peter Morris

2/13/2008 9:29:37 AM

http://

There is no separate unit tests.They are all part of the main application.Once can just load the main dll into nUnit to test
Venkatesh

http://

2/13/2008 9:41:08 AM

http://

Hi Peter,

Thanks for the offer, unfortunately I'm currently updating an existing asp.net application. Mind you I do learning stuff from your blog, the Inversion of Control post was really good.

The unit tests are part of the EcoMVPWebApplication project in
AllEmployeesTests.pas and EmployeeTests.pas

http://

2/13/2008 10:38:20 AM

http://

HI John
Is it possible for you to write a more detailed article (in spite of your busy schedule )about the whole thing to help out the Delphi ECO guys like me..While i have been able to run the tests now , where odes one start?
I feel you are the only delphi expert seriously perusing Delphi & ECO & hence I am asking you
Venkatesh

http://

2/13/2008 3:09:41 PM

http://

This wikipedia article gives reasons as to why you want to do unit tests for your code

http://en.wikipedia.org/wiki/Unit_testing

I think testing asp.net web applications can be quite difficult. The mvp pattern makes it easier because you can test more of the code.
Even a few tests is better than nothing.

What kind of things would you like in a more detailed article ?

http://

2/13/2008 4:27:47 PM

http://

Hi John
Thanks for asking

MVC Pattern-What,why & how.
MVC pattern with ECO asp.net & Delphi -How to write the test cases
ObjectDataSource-Why it requires to be extended?
Why Mock Objects are required ?
Finally you know best what a new comer to these topics require ?
Further I feel CO should hire you to do more indepth articles on ECO & Delphi since they are focussing on C# (forgetting that alienating their existing Delphi ECO customers is bad for their business)
Many people including Bob Swart have given up on ECO.May ne you can bring back more Delphi people to ECO
Venkatesh

http://

Comments are closed

Powered by BlogEngine.NET 1.3.0.0
Theme by Mads Kristensen

About the author

Name of author John Moshakis
I'm a software developer living in Toronto..

E-mail me Send mail

Calendar

<<  August 2019  >>
MoTuWeThFrSaSu
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar

Pages

    Recent posts

    Recent comments

    Authors

    Tags

    Don't show

      Disclaimer

      The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

      © Copyright 2019

      Sign in