I picked up this month’s MSDN magazine and came across an interesting article. The article described a way to test .NET Classes though the command line!!! Who would have thought of that - obviously Microsoft did and is achieved through a free downloaded program called Window PowerShell. This excited me due to its potential of Unit testing objects. Here is the link to the article http://msdn.microsoft.com/msdnmag/issues/07/05/TestRun/default.aspx
Here is what I did first
- Downloaded Windows PowerShell for XP from http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx
- Open Windows PowerShell through your Start Menu. The first things I tried to do was type in old DOS command like dir etc. and they worked. In fact the tool gave me more information on the files e.g. was the file in the listing read-only etc.
- The first programming I try to do is to write a program\profile that executes on start up – here is how I got it working
- The article mentions that you can view your profile file (startup script file) when you type notepad.exe $profile. But that does not quite work since it seems the file does not exist by default.
- Type $profile in the command line. This will show you the path of the startup script file
- Create the directory and file physically in the path show e.g. My Document\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
- Now go back to the power shell prompt and type notepad $profile – this opens up the profile file correctly now
- In the profile file type in the text below and save. Open power shell the script should execute…
- C:
- C:\
- write-host "My first windows power shell script"
- Well it won’t execute by default. Power shell disables script execution by default for security reasons – to enable scripts to execute, I executed the command
- set-executionpolicy unrestricted
- Re open the Windows PowerShell program, you will now see the message “My first windows power shell script” and notice that your default directory is C:\
- !!SUCCESS!!!
More to follow tomorrow\this week – this is exciting cannot wait to start unit testing….