Automated Testing Using WebClient and HTML Agility Pack

I researched options for testing my ASP.NET website. I decided to use Scott Hanselman’s solution where simulate IIS using Cassini and simulate a browser using WebClient.

Good Points
It works!
It’s free!
Doesn’t require a massive refactoring or rewrite.

Challenges
Cassini should be a singleton. Unless you are testing something that is IIS dependent, you should not destroy Cassini inbetween each test or test fixture.

Built in Exceptions you should use

I’ve been using FxCops which looks down on “throw new Exception();”

Here are some more narrow exceptions that already exist in the framework that you should throw, hey it saves you the effort of writing a custom error class.

ArgumentNullException – Argument is null
ArgumentException – Argument not valid
ArgumentOutOfRangeException– arguement too big or small, or not on the list
ArithmeticException — The root of a negative number
InvalidOperationException -given state,

Targeting 1.1 with VS2005

Why would we want to? All truly difficult questions will at first immediately ellict dismissals and unhelpfully overly simple advice.

Why not just move to 2.0? Upgrading to 2.0 usually is effortless, unless: your organization has burdensome rules about doing anything, like upgrading to 2.0.

Recommended to-do list for Classfieds Starter Kit

-1. Download the Classifieds Starter Kit.

0. Read up on issues address on the Classified Starter Kit forum.

1. Search for “lorum ipsum” and replace with suitable text. I created a Help.aspx page, since most of the lorum ipsums where place holders for a link list of help/support pages.

2. Add application name to all providers, especially if you use the same aspnetdb for several applications.

3. Get yourself access to the Admin folder. I did it this way:

<location path=”Admin”>
<system.web>
<authorization>
<allow users=”myuserID”/>
<allow roles=”Administrators”/>
<deny users=”*”/>
</authorization>
</system.web>
</location>

Ideally there would be some user/role management pages built into the administrative section.

4. If you get the “There is no unicode byte order mark:cannot switch to unicode” error, you may need to change your xml declaration for the file App_Data/site-config.xml to encoding=”utf-8″ or encoding=”utf-16″ depending which one works

5. Switch from user instance to a ordinary instance. You’ll want to run classifieds-add.sql, modify classifieds-categories.sql for your tastes and run it. Classifieds-remove.sql is for restarting from scratch.

6. You’ll want to update your connectionStrings and mailSettings sections of your web.config, especially the LocalSqlServer connection string which is used by ASP.NET membership providers.

7. If you are getting “Can’t find page logon.aspx” then you may have a weird set up with cascading web.config files (i.e. web.config files in folders above where you application lives) then you may need to add this:
<authorization>
<allow users=”*”/>
</authorization>

That allows the anonymous access users to get to the anonymous pages. If for some reason ASP.NET thinks you are in a secured folder (i.e. forms authentication is active), it will try to forward unauthenticated users to a default page of logon.aspx, even it doesn’t exist!

8. Update the theme by modifying MasterPage.master. Optimally, one would implement masterpage and theme switching.

9. Register.aspx has a lorem ipsum help section that seems aimed at helping creating ads instead of users. Also Register.aspx renders wrong on Firefox (labels align to the wrong box!)

9b. Admin/Ads.aspx renders wrong in Firefox.

10. Error reporting is inadequate. All errors forward an error page that says contact the administrator.

11. Create User wizard seems unreliable. I think this is because it isn’t properly reporting success and failure (i.e. feedback about password strength)

12. The site desperately needs an RSS feed. It is unreasonable to expect users to visit the site everyday, like one might for craigslist.

13. Add google analytics tracking to the masterpage.

Options for community websites

I was looking for a free, works-out-of-the-box community website I could use. In particuar I wanted to write a website aimed at locavores in near where I live. So optimally, some link exchanging (like digg or delicious), some classified ads (like craigslist), because the number one challenge for a locavore is finding local suppliers. Recipes also would be useful.

dotNetNuke: It was too hard to install. It is too complex to figure out by reading the code and the installer is too unreliable to finish. I decided not to invest further time into it.

dotNetKicks: Compiles and works, but, only installs on the root, not on virtual directories. This is a deal breaker for me as I use my hosted account to run several applications. Also, re-theming it looked challenging.

Kigg: Didn’t work. Period. I may keep at it just to learn about the MVC project type though.

Community Server/dasBlog: These are forum/blog engines. I can’t create enough content for a blog and the site needs to be able to scale down (work with few or no users). Forums scale don’t scale down at all. Without a crowd of people, a forum turns into a useless web ghost town.

Classifieds starter kit. I’m leaning towards using this.

Wiki…. working on this.. I’ll have to finish this post later

Embedded databases for speed and simplicity

(blog entry brought to you by time snapper.  This entry would have been lost to an electricity outage if not for my screen recorder.)

When I want a relational database, I might want something that can handle a billion transactions per second, never loses data, and can be updated by 1000 users simutaneously without corrupting data.  If my application just needs a single small table, the overhead of a relational DB is overkill.

[likewise for ETL scenarios-- writing SQL based ETL code in a full-blown RDBMS for an ETL process incurs a lot of overhead that just slows data processing down.  On the otherhand, dropping back to using text isn't very good either as you forego the power of SQL]

In particular I want an embedded database that is:

  • free
  • works in ASP.NET & ADO.NET
  • supports all important SQL statements
  • is very fast
  • does’t require setting up a secure service (i.e. daemons or windows services)
  • Support for bi-directional databinding in .NET
  • Doesn’t require an installer/COM component registration, etc. i.e. nothing that would be a barrier on a hosted account
  • Runs in medium trust
  • Secure against executable code (should be able to call OS shell functions like one can in MS-SQL, MS-Access and the like)
  • Can zip up the data with the source code and send in an email

MS-SQL 2005, MySQL, etc

These require an install, administrator rights to set up, some non-trivial know how to configure the database and users.  Nope.  Too much work.

Text and Excel

Database drivers for text files tend to be pretty primitive, low performance and often don’t support updating.  Excel has limitations on the number of rows you can deal with.

MS-SQL SQL Compact/Mobile Etc

Doesn’t allow for hosting inside of an ASP.NET worker process. End of story.

XML

Not supported for bidirectional databinding with default ASP.NET controls.  I’m pretty sure this works in medium trust

MS-Access/Fox Pro

If MDAC is available, you probably can use the Microsoft.Jet.OLEDB4.0 driver. 

Berkley DB

Berkley DB was bought by Oracle.  Oracles distribution is slanted towards support of the Java world, but a .NET driver does exist.

SQLite

See my blog entry on SQLite.  Of all my options, this is the one I liked the most.  It runs well in ASP.NET, can support large numbers of users, has Visual Studio support (better in the full version than the express versions).