Automated .NET testing with WatiN

October 20th, 2008 by Sameer | No Comments | Filed in .NET articles, Software Engineering

This software is super cool.  WatiN – Automated Web Application Testing!

Here’s how you can use it.  Download it.  Download the test recorder (it’s not perfect, but its pretty good).  Create a trivial test case so you know it’s working.  Then build on that test case.    It will output code for NUnit, MBUnit, or even VS2005Test

Load up your VS IDE, then execute it from Visual Studio 2005 or 2008 Test Runner.    It will give you the results right there!  Super cool or what??

With this framework I was able to create some pretty simple test SUPER fast.  – Login test, check for correct page loaded.   Then I tested some shopping cart logic (adding items, removing items, clearing cart.)

In conclusion you can effectively create tests with WatiN.  Give it a try.  It’s compatible with practically every testing framework (including Fitnesse) that you probably use.

Tags:

.NET Blogging Softwares

October 7th, 2008 by Sameer | 2 Comments | Filed in Hosting

When I first started this blog, it was done in Subtext, which is a very impressive .NET blog software. It is a fork off the old .TEXT blog engine. To give you a bit of history, .TEXT codebase was left and eventually became Community Server. That was my preferred choice of blogging engines, but I did not want to pay money for it at this point in time when I wasn`t even sure if I was going to have time or energy to continue the site over the yeras.

Actually WordPress was really the option I wanted, being the most popular and the most feature comprehensive blogging software out there (tons of plugins, tons of templates/themes, and so on)…

Now, Subtext can work great for you if you are willing to contribute some features. Otherwise you will find yourself dependent on a code base maintained by just a few people (rapidly growing, no doubt), but really in this case my business is blogging, not contributing to .NET blogging softwares, so I am abandoning the Subtext ship and switching to WordPress.

Some of the new features on this site you will find

  • faster response rate due to caching plugin
  • see related posts at the bottom of each post
  • subscribe to comments so that you can continue the discussion if someone responds to you
  • and more coming…

I wanted to add these features to make the site more interactive for everyone, plus nicer looking (I don`t have time to develop my own theme, I plan to utilize an already existing one online).

Lets see where it goes :) So for me, the clear winner is WordPress (even though its not running .NET).
I claimed that .NET is superior to PHP, however, of course, that does not mean that every single software written in PHP sucks, nor that every .NET software rocks.. Far from it

Setup ASP.NET 1.1 on VISTA

October 7th, 2008 by Sameer | 2 Comments | Filed in Uncategorized

As strange as it sounds, yes, you might need to setup ASP.NET 1.1 and VISUAL STUDIO 2003 to work on VISTA.

Here’s how to do it. I read maybe ten other pages and tried tons of different things but this is the definite guide on how to make ASP.NET/VS2003 work on Vista.

Thanks dude!

A few comments about developing on Vista. I am running a lenovo T61 (Vista 32bit) with 2GB ram with VS, IIS7, SQL Server 2008 with Full Text catalog, and the whole works, so when memory was getting full (i.e. had Outlook open, Excel open, as well as all that other stuff) it was actually TOTALLY FREEZING for literally 5 minutes a time (even the clock was frozen).

I managed to remedy this problem by buying and using a ReadyBoost compatible USB disk and I don’t have this problem any more. Try it out. I think it’s a pretty creative and useful feature that they put in Vista!

Learn Faster

October 3rd, 2008 by Sameer | 1 Comment | Filed in Uncategorized, Visual SourceSafe, Work Related

Change of atmosphere is actually a much faster way to learn, as I recently found out due to a job change.  A lot of time spent in the same environment working with the same people and learning stagnates.  If you really want to learn something different, be bold, take a risk, and change jobs.  Another factor is type of company – changing company types can increase learning speed by working in a different environment.  Technical skills are not the only skills that matter, so keep that in mind.  By looking at how different companies work together and achieve goals is a learning experience in itself.  I was concerned that moving from a team with many talented developers to moving to a team of one developer (me) my learning would stagnate.  However, this is not the case.  I feel like I’ve learned so much in the last few days just by being in a different environment.  Take risks!  Be bold!

Factors to note

- Background of those you are working with
- People who you are working with (non technical)
- Location of new job/environment
- Number of work hours
- SMALL or LARGE COMPANY
- Technology used (is it old, is it new… )

You can find a lot of these things out by asking in the interview.  There are implications for each one of the factors above.  For example, large companies are more resistant to change.  They are usually late followers in adopting new technologies.  However, some people feel that in large companies they have job security…  So it all depends.

I think Justin of CodeThinked (a nice .NET blog that I subscribe to) sums it up pretty well why he changed jobs.

Keep in mind we humans are fussy beings.  We don’t like change (most of us, anyway).  You might find a lot of things uncomfortable in your new position.. It will take a while to adjust to the new area, new coworkers, new boss, and so on.   But hey, life is about taking risks, right?  Can’t be complacent all the time.

Follow The Leader

July 17th, 2008 by Sameer | 1 Comment | Filed in Software Engineering, Work Related
In order to succeed as a team, in any sort of team, you have to follow this basic principle, which has been applied and maybe is accepted universally.
The principle is simple. 
 
  1. Appoint a Leader
  2. Leader makes council with the team
  3. Leader makes a decision
  4. Team supports leader in his or her decision
 
Its that simple. In this way, an organization, a team, a family, or a company can move forward. Every decision that you need to make, is done in this manner. The team will work together for the best solution, but in the end the leader needs to make a decision. Once that leader makes a decision, the team needs to move forward WITH the leader. 

This means, the leader doesn’t necessarily dictate, but he or she has gathered input from the team and made a decision. Then they will have to choose a solution and go with it. If the team continues to argue and fight over the decision, progress will be slow. I believe this applies in families too. There has to be a decision maker in the family, for example that is appointed for financial decisions, and then having a discussion or gathering input from the family is great, but in the end one person has to make the decision, and the family needs to be supportive, even if they don’t all agree with it. However, this applies in normal circumstances and there are caveats.   There might be some cases where it would be unethical for team members to support a plan if its morally wrong or it goes against everything inside them and they feel it’s a plan headed for disaster.
 
It pains me that time and time again I see this happen – the leader makes a decision and the team continues to question him at every step of the way – “Why are we doing this”, “Why are we doing this”, and “why are we doing this” instead of understanding that they were appointed for this role (they might be your boss for example) and they are ultimately responsible for the decision, you need to do your job and support them.  I have seen some cases where I questioned my manager because I didn’t see the wisdom in the decision he made, but in the end it turned out he was right and it was just my foresight wasn’t as far as his…  So I learned my lesson, be patient, and be a team player. 

As a team member, sometimes I have to swallow my feelings and say, “okay I don’t think this is the smartest decision and my idea is actually better, but I will go with you on this”.
From a developers perspective, you can think of this as requirements. Your boss gives you the requirements, you implement it. How you implement is up to you, but you won’t be able to proceed if you start arguing about the requirements. Requirements are requirements, once they are agreed upon, please continue.

So in normal circumstances, if you want to succeed, get a leader, and help him with his decisions, but in the end.. Respect the decision he makes and go with it. (He or she, that is).
 
The best team isn’t necessarily the one with the best players, it’s the one that plays together the best. 

How to Waste Millions Of Dollars With Outsourcing (or Make Millions)

July 10th, 2008 by Sameer | No Comments | Filed in Software Engineering, Work Related

To management, the idea of outsourcing sounds very sexy…. The idea of producing the same content (code, or what not) at 1/2 or 1/3rd the cost is almost a wet dream for management, if I may be so bold. Even though it sounds great in theory, it’s actually a very tricky function to master. Here are some things I have learned with my outsourcing experience.

Keep in mind I am not discussing the outsourcing style of passing requirements and getting the end product complete. I am discussing the style of hiring outsiders and working with them on a daily basis.

You have to start by looking at what is the purpose of outsourcing. Is it to save money? Or is it to improve quality? Or is it so that your team can focus on other things? Get this straight first before going any further. My points below are in the context that you are a software company (or at least do some software development) and you are considering outsourcing to save money and cut costs.

From friends, I know that some very popular companies outsource, such as E-Trade Canada, Accenture, and recently the new online T.V. web site Hulu which outsourced its development to China.

  1. Before you start outsourcing, have your process solid – i.e. have regular scrum, know how much code you are generating each week, and so on. It’s very important that you have some idea of costs for developing software for your local team. If you have no idea, you won’t be able to see if you are really saving money or wasting it.
  2. Know velocities of individual team members so you can measure cost effectiveness of your outsourced work.
  3. Build your estimation skills. Read Joel’s article on estimation and his second article on estimation (which is really a promo for his bug tracking software but still worth reading) and Steve McConnell’s book on Software Estimation (highly recommended, very easy to understand).
  4. Get smart/able/competent guys. This can make or break your outsourcing project. If you are going to get developers that need baby sitting, then hire a baby sitter on their end to clean up their code, otherwise you are going to waste your valuable resources fixing and re-fixing and re-fixing their code. In this case you might not be actually saving money.
  5. Review their code. Someone on your side is going to have to review their code to make sure that they aren’t purposely obfuscating it in order to secure their jobs in the future. I have seen a Flash application that was built in this manner, the team overseas purposely messed up the code in such a way that it would be difficult for others to continue where they left off.
  6. Learn from those who have done it before. If not, you are going to mess up big time, in many ways. Might be worth getting a consultant who has been successful with such projects. Another idea is to find someone who has connections "back home", and go there to see how some of the shops work.
  7. Turnover is really high in India/Bangladesh/ and so on. This is because jobs start at really low salaries (like $200 a month) and go upwards to like $3000 a month (comparable to working in Canada or USA). You will need to find a way to solve this problem. Somehow you will need to get them to commit that guys will not drop like flies. This is so important because there is always an upfront cost to learn an application, and it becomes more as the complexity and lines of code increase.
  8. Consider a cross-cultural learning program, you send some people there for a while, they come over here for a while. A lot of big companies do this. It’s almost a must.
  9. For the team overseas, its important to spend your valuable time together in the beginning to ask lots of questions and understand the requirements as much as possible, in case there is a task that you run into questions, then leave it and work on something else.

Hamid, Axosoft CEO claims that Outsourcing is for Dummies. I think this isn’t true in all cases, as I have been able to apply outsourcing successfully on some small projects. However, it all depends on the case, and for building complicated software with a (geographically) fragmented team, you may just end up proving his point.

Server security and PHP Safe mode

July 4th, 2008 by Sameer | No Comments | Filed in Hosting

Last weekend was a bit of a disaster.  One of the servers I was maintaining was hacked, big time.  How did the (not so nice word) guys do it?  Well, first of all, I learned hackers think they are doing good deeds.  They did me a favor by hacking my server and by not "deleting all the files".  They only defaced some 30 something sites and caused me lots of misery and site cleanup.  Why do I say this?  Based on the hacker’s signatory message – "Owned by nEtDeViL .. Just testing your Security .. Peace ! .. net_devil@…….com"

So Mr. hacker dude, if you really want to just "test" my security, why don’t you send me a kind email stating that you found some security holes and how to fix them?  That would be a real gem of a good deed :)

Anyway, there is always light at the end of the tunnel, good always comes from bad, if you are patient and learn from your mistakes.

Here is what I learned – TURN ON PHP SAFE MODE!  The hacker exploited some old postNuke script in the albums folder uploaded some old Russian hack script called r57shell.php .  This script allowed him to install some rootkits which basically log everything you do on the server and all sorts of crap.  Which caused me to have to get a new server, yada yada.. :(

Now the first reason they managed to achieve this, is I didn’t have php safe mode on.  I didn’t want to inconvenience my buddies on the server (ya right, dumb move.)  So even if they managed to upload it, they can’t do much with PHP safe mode on.  But with PHP safe mode off, well sorry buddy, even your own pals on the server can use this script to take over the server if you didn’t give your friends full rights to run stuff on it and they get mad at you (you know what they say…. keep your friends close and your enemies ….)

Second thing, I went all out and installed Suhosin (grown out of what was known as PHP Hardening Patch).  I don’t know how much this will help me, but at the least it didn’t break anything on the server, so I’m leaving it there for good measure.

There is also Mod_Security for Apache but that’s a bit difficult cuz it will slow down your server by checking every single request plus it will break a bunch of scripts so you will have to keep tweaking the regular expressions to get it to work nicely especially if you have tons of apps on the server.

Related reading – Forum Post: Tightening your PHP Security (just a few easy tips on how to tighten your security)

PS.. this server is running Microsoft Windows so don’t even bother trying to hack it ;) — okay don’t laugh

Updating Your Web.Config From Each Build with CruiseControl

June 17th, 2008 by Sameer | No Comments | Filed in .NET articles, Software Engineering
Let’s say you have CruiseControl.NET all set up nice and hunky dory.  Now you love the fact that it labels your each build, and you want to somehow show that from your project.  Here is how you can get your CruiseControl.NET project build number into your Web.Config.  This concept can be applied to update any file.
It’s super easy. You will need to add an exec block to your ccnet.config
<exec>
<!-- Auto increment web.config build number -->
<executable>E:\Userdata\CruiseControl\Tools\MergeWebConfigValues.exe (my custom tool)</executable>
<buildArgs>"E:\Program Files (x86)\CruiseControl.NET\server\Main.state" e:\userdata\cruisecontrol\Dev_Main\Web.config</buildArgs>
<baseDirectory>e:\userdata\cruisecontrol\Dev_Main</baseDirectory>
<buildTimeoutSeconds>15</buildTimeoutSeconds>
</exec>
 Now all you need to do is write the MergeWebConfigValues.exe
What does it do?
1. It reads the CCNET state file (provided by argument 1) and grabs the last label from there. (The state file is an XML file)
2. It then goes and writes to your Web.Config and updates the build number in there. (or writes to any specified file you like)
Lastly, update your code to read this value by adding some version or about page to read your Web.Config
You now instantly know what version your code is.

Regular Expression Designer

June 17th, 2008 by Sameer | No Comments | Filed in Updates

If you are doing frequent work with regular expressions, check out this free tool – Regular Expression Designer by Rad Tools.  It’s very nice and helps you with debugging those pesky statements with different input.

And just 2 reminders regarding naming of variables:

1. Short acronyms should be uppercase
http://msdn.microsoft.com/en-us/library/ms182256(VS.80).aspx

2. Identifiers should be cased correctly
 
http://msdn.microsoft.com/en-us/library/ms182240(VS.80).aspx

Hopefully I’ll post some more stuff soon, been busy last week with personal stuff (selling my car, etc.)

Unit Testing on Your Database

May 22nd, 2008 by Sameer | 2 Comments | Filed in .NET articles, Software Engineering

When unit testing on your database, you will run into a common problem.

Rolling back.

So you want to do some unit tests, and then you want to reset your database back to the nice squeaky clean version that doesn’t have half failed unit tests.

So how can you do this?

There are many ways to achieve this.

The best way I found (requires Win XP SP2 or Windows Server 2003) is to use Roy’s Unit Testing Rollback Attribute.  Simply inherit his class, add a "DataRollback" attribute, and you are good to go.  Using some complicated Interception logic and Enterprise Services (COM+) it rolls back all the database work that was done.  It’s super easy to implement.  Here is some sample code that shows you just how easy it is.  You just have to download XtUnit (an extension to NUnit) to do this. (Full source code available)

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using TeamAgile.ApplicationBlocks.Interception.UnitTestExtensions;
using NUnit.Framework;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

namespace DBTest
{
    ///<summary>
    /// Test roll back functionality.
    ///</summary>
    [TestFixture]
    public class RollbackTest : ExtensibleFixture
    {
        [Test, DataRollBack]
        [Category("Database")]
        public void TestInsert()
        {
            //this method will be performed inside a COM+ transaction
            //this requires windows XP SP2 or better
            //Windows Server 2003 works as well.

            string strCnn = "your_conn_string";
            Guid random = Guid.NewGuid();
            string sqlI = string.Format(@"insert into log4net (message,date,thread,level,logger) values ('{0}',getdate(),'{1}','Debug','Test')", random.ToString(), System.Threading.Thread.CurrentThread.GetHashCode());
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.Text, sqlI);

            string sqlS = string.Format(@"select count(*) from log4net where message='{0}'", random.ToString());
            int rowcount = (int)SqlHelper.ExecuteScalar(strCnn, CommandType.Text, sqlS);
            Assert.That(rowcount > 0, "Cannot find {0}", random.ToString());
        }
    }
}
This test passes successfully.  What does that mean? The insert and select worked perfectly fine.  After that, I did a query and found the database to be clean.  So the rollback worked too.
There are also other ways to skin this cat (i.e. to achieve this goal).  One is to use Spring Framework and extend their Unit Testing class (AbstractTransactionalSpringContextTests), and they will handle rolling back everything.  Here is an article on this topic, but unfortunately I was not able to make it work for me due to some odd reason.  Here’s hoping you have better luck.  If you don’t have any transactions, and your code is wired to use Spring, it’s still also very easy, you just need to call TransactionManager.Rollback.
You can also try to achieve this using Nested Transactions if you have existing transactions implemented via Spring.  But then you have to set up checkpoints and stuff like that. 
I have some other ideas on how to achieve this that I will post later, God willing.