A few weeks ago, I blogged about building an alternative to Dynamic Data.  I have to say, it’s pretty sweet.  I added a new entity type yesterday, including a couple of minor overrides and I was done.

Here are the steps I had to take (testing left out for clarity):

  • Create the entity:
  •    1: public class ExcludedCounterparty : IAuditedWithId
       2: {
       3:     public virtual int Id { get; set; }
       4:     public virtual Counterparty Counterparty {get; set;}
       5:     public virtual string CreatedByUser { get; set; }
       6:     public virtual DateTime? CreatedOnDate { get; set; }
       7:     public virtual string ModifiedByUser { get; set; }
       8:     public virtual DateTime? ModifiedOnDate { get; set; }
       9: }
  • Override the Fluent NHibernate conventions:
  •    1: public void Override( AutoMap<ExcludedCounterparty> mapping )
       2: {
       3:     mapping.References( ec => ec.Counterparty, "FK_CounterpartyId" );
       4: }
  • Override the UI conventions:
  •    1: public override void Override()
       2: {
       3:     Config.AllowEdit = false;
       4:     Config.AllowDelete = true;
       5:     Field( ec => ec.ModifiedByUser ).ShouldDisplay = false;
       6:     Field( ec => ec.ModifiedOnDate ).ShouldDisplay = false;
       7: }
  • Add the menu configuration
  •    1: <siteMapNode url="~/../ManageEntities.aspx?type=ExcludedCounterparty" title="Counterparty Exclusions" roles="…"></siteMapNode>
  • Update security
  • Done.

Notice that nowhere did I say that I had to create a aspx page or ascx control.  How sweet is that!  Also, both Fluent and my UI automation automatically pick up the new entity based on the assembly configuration.  It’s days like this that makes software development fun.

A couple of weeks ago I was searching for an alternative to Dynamic Data.  My motivation was simple.  Integrating Dynamic Data with Oracle and/or NHibernate would be challenging.  I was amazed at how little I could find that would solve this problem.  Surely Dynamic Data wasn’t the first or only.  Eventually, I gave up and worked with a coworker to develop our own alternative.

Fresh off a Fluent Nhibernate implementation, we decided to take the convention-over-configuration approach.  The Fluent interface worked very well for us, in particular the auto-mapping feature.  This is what we wanted to accomplish with our UI automation.

Configuration Points:
First we had to identify the configuration points.  Things like, label or header text, visibility, formatting, editor, among others.  We introduced two basic configuration objects, one for the entity and one for the fields (properties).  Our goal was to have a simple CRUD user interface that would be completed automated by reading information from these configuration objects.  Everything from subtitles, to actions, to data grids would be automated.

Conventions:
To avoid wasting time configuring individual entity classes, we decided to “auto-map” our UI.  We started off with simple conventions.  For example, deriving the subtitle from the class name.  The subtitle for “BookStore” would be “Book Stores” by convention.  We handled the singular case as well to support our actions, like “Add Book Store” or “Edit Book Store”.  Also, fields would follow a similar convention for labels and headers.

Eventually as our needs grew, we defined more conventions.  The nice thing about this approach is that we are following the Open/Closed Principle.  If we need something new, we simply add another convention.

 

Overrides:
Clearly, there will be exceptions to these conventions.  We took another page out of the Fluent Nhibernate book and implemented an Override model.  We simple allow implementations of IOverride<T> that provide an opportunity to change the auto-mapping behavior.   For example, IOverride<Party> might include “config.PluralLabel = "Parties"”.  When the automation service is initialized, we register the assembly containing our overrides.

 

Consumption:
We created a few automation aware web controls that bring our entities to life.  Really all we needed was a custom grid view and data entry table.  Presenting the data in the grid view was really quite simple since grid views already support simple data binding.  Data entry turned out to be not so difficult as well, we simply kept track of a list of properties and values.  Then it was a matter of getting values from the entities with reflection, and later setting those values before persisting the entity. 

Of course, the fact that we are using Nhibernate with methods like Save<T>( object ) helped with generic CRUD a lot.

 

Cost Effectiveness:
Many will question, “Why reinvent the wheel?”  Others will ask, “Have you really saved that much development time by building this framework?” 

First, I felt that Dynamic Data would not meet our needs and I searched long and hard for an alternative to Dynamic Data and couldn’t find one.  So, I don’t feel like I am reinventing the wheel here.  Perhaps there are Nhibernate integrations now available for Dynamic Data, but there weren’t at the time.  Also, even if there were, being an infant, Dynamic Data would likely have problems that would take too long to resolve.  With our in house solution, we built only what we need.  And with the tests in place, we feel confident that we can make a change quickly if necessary.

Second, we already experienced productivity gains more than once since adding the UI automation.  After defining a new entity, a simple one line override, and a menu item we were able to perform all CRUD on that entity because of the automation both on the UI side and the data side.  We didn’t have to write a single additional line of ASP.Net code.  In fact, my coworker wrote a prototype that takes an existing Java application (not web) and port it to our web interface.  He basically plugged in the new web application to a Java web service and the rest was cake.  When my boss saw the prototype, he about fell out of his chair.

Tags: ,

image I was looking through my blog history to see which posts were visited the most.  To give you a point of reference, the next closest post to has around 3000 visits.  I’ve had more comments on “Oracle Update with Join” than any other as well.

Ironically, I’ve been using NHibernate more heavily and these types of Oracle statements/queries hold less value in my daily activities.

Tags:

It’s a little hard to believe that I haven’t posted a blog in over a month.  Where have I been?  Frankly, doing my job and trying to keep up with my personal life at the same time.  I’ve been hesitant to include personal jabbering in my mostly technical blog.  But, I want to express what is most important to me.  I hope that most of you have similar priorities.

At the beginning of the year, the church I attend lost it’s music director.  While we were looking for a replacement, I filled in as temporary director.  Suddenly, I had added a part-time job to my already busy schedule.  For Lent, I chose to participate in a bible study each Monday evening.  Also, I am involved with the Pastoral Council and we have been recently working very hard to prepare for discernment of new members. 

Finally, I ran completely out of one of our most precious resources, time.  I had been singing with the Archdiocesan Choir for special liturgies throughout the year.  I also, volunteered to direct music for a men’s retreat at our church.  When, the music director left our church, I became so overwhelmed, that I could not fulfill my obligations to both the Archdiocesan Choir and the men’s retreat.

All the while, I was trying to ensure my face was familiar to my family.  A few years ago, I returned from a business trip, at which time my younger daughter looked at me very inquisitively.  The look on her face is something I will scarcely forget.  It was the look of “who are you?”  I knew then that I needed to find a different job.

I’ve held two jobs since then.  Both have been great (so far).  I have been able to spend more time with my family.  I’ve been able to meet my daughters’ teachers, and attend other school and church functions.  I even directed the children’s choir (at church) for a month or so. 

One of the most rewarding things I’ve been able to do is go on daddy-daughter walks weekly, with my girls (individually).  It’s special time for them and for me.  Unfortunately, the events over the last couple of months put a strain on that time together, and I missed a few weeks.

I couldn’t have a better wife.  She is the most patient person I know.  And she is always looking out for me and my health.  Without her support, I suspect the stress would have overwhelmed me.  It sounds cliché, but she truly does make me a better person, and makes me want to be a better person.

On top of all of this, at work, I completed one project in late February, and started another at the same time.  The last project was pretty much a solo endeavor.  I am pleased that I’ve got a teammate for the new one.  We’ve been able to accomplish things in the last couple of months that I had put off on the previous project.  In the next few weeks I hope to share some of the things we have been working on. 

We recently incorporated a more BDD style to our testing, using SpecUnit.  Also, we are now using StructureMap to help manage dependencies.  We are using Nhibernate (including the Fluent interface) for the first time on our new project.  We started building our own brand of UI automation/templates for CRUD (Dynamic Data just didn’t cut it for us).  Finally, we decided to incorporate the Enterprise Library Validation Block as well.  We brought all of this together and still hit our deadline for the first milestone of the project.

The order in which I covered things in this blog was very purposeful.  What should be clear is that this blog is not one of my top priorities.  In fact, my job and career are, at best, third on my list.  So the question is, how do you keep it all together?  Can you give each aspect of your life adequate attention?  I think the key is to give proper attention at the proper time.  My wife humors me when I talk shop at home, but I know she appreciates it much more when I leave work at the office.  Similarly, taking breaks at work to talk about your personal life is fine, just don’t overdo it.

Live Better, Code Better.

About a year ago, I started to evaluate ASP.Net MVC, but decided to put it aside because it was still in heavy-duty development.  With the official release a couple of weeks ago, I decided to check it out once again.

MVC has a lot of things to offer, but there are a few critical things that we couldn’t overlook.  We have a few web applications that all have quite a lot invested in server controls (both third-party and developed in-house). 

In ASP.Net WebForms, for something as simple as a GridView with a ObjectDataSource, there is a lot handled behind the scenes.  The time it would take to mimic the necessary behavior in MVC appears to be unmanageable at this point.  I’ve done my share of HTML, and am comfortable doing it again, but it certainly feels like a step backward.  We would have to write a lot of HTML and JavaScript (with the help of jQuery) to accomplish what takes just a few lines with server controls.

Another issue that we cannot overcome is the fact that WebParts are basically server controls and are mostly incompatible with MVC.  One of our applications is highly dependent on WebParts.  Again, there is a lot of work handled for us by simply leveraging the WebPartManager.

So, it was easy to rule MVC out in regard to existing applications.  But, what about something new?  Well, for all the same reasons we’ve decided to stick with ASP.Net WebForms.  Basically, we have invested a lot in server controls, like menus, tree views, grid views, and in-house controls to promote common look and feel between our applications.  Moving to MVC would be no small task.

There is one place that I am considering MVC within our existing framework.  I’m wondering if we can leverage MVC to better handle our Ajax needs.  In a couple of occasions, we are using WebForms with no markup, that simply return xml data.  We also use Page Methods in a couple of places.  It seems like MVC could handle these types of requests more cleanly.

Perhaps in a few months the community will develop some slick MVC controls that save a lot of work.  Unfortunately, I don’t have the time (money) to build these controls myself.

Anyway, if I am totally off the mark, please someone pick me up and set me straight.

I few months back, I was having major problems with VS 2008 crashing on me left and right.  After trying numerous things to resolve my problem, I finally decided to uninstall all of the .Net Frameworks and VS, then reinstall.  My problems started shortly after I installed SP1 (both .Net Framework and VS 2008). 

I can’t say for certain that SP1 was causing my problems, but since then (after reinstalling without the service packs), I have not experienced the crashing.

There are other reasons that I wanted to skip SP1, many of which are documented by Microsoft themselves.  Not the least of these was the issue regarding transactions in Oracle.  That issue, as well as many others, has been since resolved.

I’ve been taking this week to do some technical research on tools and frameworks we might want to use on our next project.  One of those tools is ASP.Net MVC.  It turns out that the installer requires .Net 3.5 SP1, and to deploy MVC requires a couple of libraries from the service pack.  I also wanted to evaluate Microsoft’s chart controls, which also requires SP1.

So with much hesitation I decided to install SP1 once more.  Since VS was where I experienced so many problems, I only installed SP1 for the framework, and not VS.

image

Well, almost immediately I was discouraged by the this error.  Choosing Ignore didn’t seem to hurt anything.

So far, a few days after the install of SP1, I have had not experienced the same issues as before.  I’m still very hesitant to install VS SP1.

Funny thing is, I decided not to evaluate MVC beyond some internet research.  So, one reason to install SP1 fell to the wayside.

 

 

Tags: ,

So, I just ventured into tagging my blogs, partially because I think tag clouds are cool, but also it really can be helpful to find related posts.  The problem however, is I don’t know what provider I should use.  Being on GeeksWithBlogs, and thus Subtext, I can use the built in support for microformat.  However, the tag cloud works great, but the tags that I add to my post are incomplete.  Unfortunately, Subtext expects a “default.aspx” at the end of the url.  I’ve tried a number of ways to work around the issue with no luck.

What I would like to do is go back to all of my past blog entries and add tags.  I don’t want to do this until after I’ve resolve the tag link problems.  So, I guess at this point, I am interested in feedback regarding other tag providers like Technorati or del.icio.us.  There are so many to chose from and I am not even sure using a separate tag provider is the way to go.  Your comments are appreciated.

Tags:

So I just installed Live Writer and am writing this blog with it.  Integrating with my blog was painless.  I added a Code Snippet plug-in, hoping that it will work well for me.  I’ve been using CopySourceAsHtml (CSAH) to great success, but thought it best to try out the plug-ins that are available.  There are other code plug-ins, but this was the highest rated.  Do you, Dear Reader, have a favorite?

Here is a comparison between the CSAH and the plug-in:

CSAH:

    1 [Specification]
    2 public void the_job_end_date_should_be_set()
    3 {
    4     _view.AssertWasCalled( v => v.EndDate = EndDate );
    5 }

Plug-in:

   1: [Specification]
   2: public void the_job_end_date_should_be_set()
   3: {
   4:     _view.AssertWasCalled( v => v.EndDate = EndDate );
   5: }

I had to set up additional styles in my blog CSS because the class names for the plug-in are different than CSAH.  It wasn’t a big deal though since I was able to simply reuse the existing styles.  Also, I lose some of the coloring that CSAH gives because CSAH grabs the colors directly from Visual Studio.  It’s not a big loss.  In fact, I have either option with Live Writer as you can see.  I just have to “Paste Special…” when using CSAH.  Maybe I will try a couple of the other code snippet plug-ins later tonight.

Live Writer advantages over built-in GeeksWithBlogs editor.

  • I have had to work around a problem with the built-in edit regarding hyperlinks.  Live Writer doesn’t exhibit the same problem.
  • With Live Writer, while writing my blog it is already displayed using my blog CSS.  With the built-in, I have to wait until after I publish.  Yikes!
  • Saving a draft is a breeze with LW.  I’ve frequently lost blog posts because of errors posting with the built-in.
  • Preview mode is nice, as it shows me what the post will look like after it is published, including blog headers, side-bars, etc.
  • Both support a Source view.
  • Plug-in support.  It took me no time at all to find a plug-in for code snippets.  There are a bunch more out there too.
  • Categories are much easier to assign.  With the built-in, the list of category checkboxes are not alphabetized and the text is frequently misaligned.

Other things of note:

  • With LW, you can specify a publish date.  Sounds cool, but I haven’t had a need for it yet.
  • I have to set up different “keywords” (Auto Linking in LW).  Fortunately, I don’t have a ton of key words yet, so, it’s not a big deal.
Visual Studio had a problem where it would added "a lot of nbsp" when toggling from Design to HTML mode with certain custom controls.  I blogged about it originally here.  It appeared to be fixed as I described on another post, but it only seemed to occur less often.

Finally, there is an official fix.  It's not truly a "hotfix" though.  It asked me to reboot to complete the update.
With my new job, I’ve not been able to take advantage of a lot of Agile/XP practices.  In a company of four, where each is effectively working on a different project, collaboration is minimal.  Also, for the projects that I am working on, the customer is very adamant about getting a detailed proposal up front, including a list of all of the screens and how they will operate.  I’ve managed to get by without too much detail, but it is still more than I am generally comfortable with.

TDD and Continuous Integration are about the only Agile practices that I have kept up.  I have neglected to document user stories and acceptance tests.  I’ve let my unit tests be the extent of my documentation beyond the initial proposal.  As much as I would have liked to use something like Fit/Fitnesse to interact with my users for acceptance, it just wasn’t going to work.

Blah, blah, blah… and more to the point.

After reading extensively about BDD, I’ve discovered that the primary purpose is not to change how tests are arranged, but to bring acceptance criteria from the customer to the code with as little translation as possible.

I’ve written hundreds of tests for my new project in the last year.  I have also extensively refactored my test code and introduced a variety of classes to simplify testing my MVP classes.  I’ve hidden as much of the noise as I can.

My tests typically look something like this:
    1 [Test]
    2 public void MyVeryWellDescriptedTest()
    3 {
    4     Test.WithExpectations( () => ...)
    5         .WithActions( () => ...)
    6         .WithAssertions( () => ...)
    7         .Execute();
    8 }

The combination of this TestBuilder wrapper along with my base test classes has really simplified my tests.  Switching to BDD style would be a lot of work and it didn’t appear that it would add a lot of benefits.  I didn’t like the fact that I would have to add a separate class for each scenario.  I didn’t like that the pieces important to my test would be broken up between multiple methods.  I didn’t like the fact that I would need significantly more lines of code noise to write my tests.

I played around with my naming conventions for my tests to be more BDD like.  I added underscores and have been a lot more verbose.  I still haven’t decided if I really like the new naming convention.

But this all misses the point of BDD.  I look at my tests and think, these are readable.  Well, I’m just fooling myself.  First, a glance at my tests doesn’t immediately give an indication of the behavior that they are testing.  Second, only someone familiar with Rhino Mocks would really understand the tests without some guidance.  Finally, you can’t call your own code readable, just like you can’t give yourself a nickname.

In fact, I have gone back to some tests that I wrote toward the beginning this project.  The tests are about nine months old.  They are not easy to read and I am the author.  They are not horrible, but I think BDD could have improved them dramatically.

I am starting a couple of new projects soon, so I think I will go full bore into BDD.  In fact, I prototyped some ideas with a coworker while he was visiting from out of town.  We both agreed that the BDD tests were easier to read, and they clearly expressed the intended behavior of the system.

What are your experiences with transitioning from TDD to BDD?