Monday, March 29, 2010

Unit Testing in Visual Studio 2010 and converting from NUnit

Previously I had a project in VB.NET 2005 that was developed using a Test Driven Development approach. My test framework of choice was NUnit .
The screen shot Left should an example of the NUnit user interface in action. In this case with failing and interrupted tests.

In this case the tests are failing but in a sucess case the progress bar would be green and the unit test would have green buttons instead of red ones as in the image below.

One thing to notice is that NUnit gui automatically groups the tests according to the dll it is in and the class that it belong to.


 Now, the code is pretty simple, you can add a class, import the reference to the NUnit Framework and add the attribute to the class and a attribute to method that implements the test as shown in the code sample below.


<TestTixture()>
Public Class TestLookup

Private mLk As New Lookup

<Test()>
Public Sub TestNewLookup()

Dim lk As New Lookup
Assert.IsNotNull(lk)
End Sub

End Class


When converting to Visual Studio 2010 release candidate I found that it was most convenient to recreate the project files in Visual Studio and copy the code files in to the appropiate folder and then add them to the projects. In my case it also helped clean up the project structure that had become a little disorganised over the project cycle. So I cannot comment on the ability of Visual Studio to convert from the earlier format. I also choose this route as I wanted to use the built in unit testing rather than NUnit. Visual Studio holds unit test is a specific project type and I have not found any obvious way of converting a code library to a test project. I suppose I could go around editing the project files but at this stage that was not a route I wanted to take.




The Visual Studio Test Editor window is seen above and the test list on the left is manually organised by creating test list that correspond to the classes. The tests themselves are included automatically when you convert the NUnit attributes to their Visual Studio equivalents.

The following code shows a class originally created in NUnit now in VS test format

Imports Techrete.MasterListData
Imports Techrete.SharedLibrary
Imports System.Data.SqlClient
Imports Microsoft.VisualStudio.TestTools.UnitTesting

<testclass()> _

Public Class TestManageIndices


    Private mObject As String

    Private mPrefix As String

    Private mDoReset As Boolean = False

    Private mResetIndexValue As Integer


<testcleanup()> _
Public Sub Cleanup()

       Dim cn As SqlConnection = TestComponentsData.GetDataConnection

        Dim cmd As New SqlCommand("Update csm_ManageUserIndexes Set LastIndex = " & mResetIndexValue.ToString _
 " Where [Object] = '" & mObject & "' and Prefix = '" & mPrefix & "'", cn)

        If mDoReset Then

            Try
                cn.Open()

                cmd.ExecuteNonQuery()

            Finally

                cn.Close()

            End Try

        End If

    End Sub

    <testmethod()> _
    Public Sub TestAssemblyIndex()

        Dim lastIndex As Integer

        Dim currentIndex As Integer

        Dim prefix As String = "F"

        'Now obtain the last index and increment by 1

        'then save it - that should succeed and save it again - that should fail.

        Dim sql As String = "Select LastIndex from csm_ManageUserIndexes Where Object = 'Assembly'"

        Dim cn As SqlConnection = TestComponentsData.GetDataConnection

        Dim cmd As New SqlCommand(sql, cn)
        Try

            cn.Open()
            lastIndex = CInt(cmd.ExecuteScalar)
        Finally

            cn.Close()

        End Try

        currentIndex = IndexData.GetLastIndex("Assembly", prefix)

        Assert.AreEqual(lastIndex, currentIndex)

    End Sub
 End Class

One big difference is that in the current release of Visual Studio the Assert.AreEquals does not appear to work as in NUnit. In that you can have two object of the same type and with the same property values and in NUnit they will pass but in Visual Studio they will be considered not equal. It appears that at the moment Visual Studio only accept that two object that have the same address in memory are equal and there is no functional difference between Assert.AreEquals and Assert.AreSame.

Thursday, March 4, 2010

Windows 7 Networking

So the last time I posted about Windows 7 my desktop machine failed to boot. For a long while I ignored it as it was not all that important to anything I was doing.

Anyway recently I was passing the machine and I pressed the power button and what do you know it booted. It had to run some repair routines but it booted. So I ran a virus scan and did get some report of a virus. Also an external drive had some hidden files that I could not access. So I removed the virus and reformatted the drive.

Then I went back to installing the shared printer. The routine was the same as I described in the previous post but again no documents would print. So I found a tip (cannot remember where right now) but simply install the printer as local (after installing the networked printer) and add a local port that maps to:


\\server\pinterShareName

I then has to install the same printer on my nephews mac notebook. So from this thread I followed the steps listed, which I will repeat here.
On the Windows 7 PC:

  1. Open Control panel
  2. Select 'Programs and Features' pane
  3. Click 'Turn Windows Features on or off'
  4. Check on the LDP protocol
  5. Make sure that the printer is shared and that the shared name is short and all one word with no spaces


On the Mac:

  1. Start/Applications/Unitities/Printer Setup Utility
  2. Hold down the option key and click the 'More Printers' button
  3. From the top menu select 'Advanced'
  4. From the Device field select 'LDP/LPR Host or Printer'
  5. In the 'Device url:' field type 'lpd://PCName/PrinterShareName'
  6. Click the Add Button

Friday, February 12, 2010

eReaders

Just some thoughts on eReaders, I downloaded Stanza last week for my iPhone and have read 2 books on it since.
The books were 'Alice in Wonderland' which came with the eReader app and 'On Basilik Station' which is available on the Baen Free Library. The interesting thing is that I read both books in about a week which is unusual for me these days. I have a lot of distractions (usually the net ) and I tend to be slow reading books unless the book really grips me and I was wondering about that. It occurred to me as I was reading books on the iPhone that I had returned to a reading pattern that I had as a teenager when I always had a paperback in my pocket and I took it out and read it whenever I had a quite moment alone. In this fashion I got through quite a few books. 
My reading rate did not really diminish until I left college and most dramatically when I left fulltime farming and entered the computer industry as a developer. At that time the commutes were longer, I was reading more technical books in my spare time and paperback were no longer in a size that one could put in a pocket.
I also developed an addiction to fanfiction and D&D forums, that did not help either but the size of the books was a big issue. Now the books sit in my room and occasionally I read the book but when it is put down it could stay there for a couple of days.
Now as to reading on an iPhone, well what is it like? I hear you say (maybe not, not sure if anyone really reads this :)) I was somewhat surprised, it was not bad. 'Alice in Wonderland' lost something as the drawings were really too small on the iPhone screen to have any real impact but 'On Basilisk Station' was fine.
I could see me reading a lot more on the iPhone, though I will be sticking to free stuff for the while. 
I have not tried reading in the iPhone outdoors but so far it works pretty well in all indoors conditions that I tried it out in.
 So overall verdict, I could see myself doing most of my reading on the iPhone only buying hardcopy for books I really like and want to permanently add to my collection. I could also see me buying books and reading the electronic versions. I would like a larger screen but I have a feeling that the iPad is possibly a bit too large. I really want something about the size of a paperback.

Thursday, February 4, 2010

iPhone Rave

Treated myself to an iPhone over the Christmas and decided to post a few comments on it. Well it is a wonderful gadget. The UI is pretty slick and the touch interface is very good. It is a good music player and a pretty good video player. I have even watched some movies on it. Calendar, email,  messages are all pretty slick and easier to use than on a regular phone, though one with a keyboard may or may not be better to use.

All in all it is a pretty good PDA and a pretty good phone. As a phone voice quality is generally pertty good though it looses connection and reports poorer connections than the Nokias I was using before I got an iPhone.
Battery life is fairly good and depends on what you are doing. Bluetooth chews up battery like nothing else and is my biggest source of complaint. I have trouble detecting other bluetooth devices and really dislike that I cannot have bluetooth enabled in a hidden mode. After that the working alot with data is the next biggest draw on battery. Normal usage, now I get perhaps 36 hours or so between recharges.

One thing that I have tried that really does not work is the voice recognition, it does not understand me at all and there does not appear to be anyway to train it. Not that I have tried to hard to find out. Overall I am pertty pleased, now if only iTunes would behave itself and not lock up every so often.

Monday, November 9, 2009

Windows 7 My experience so far

So, At the end of September I went to the Windows 7 launch presentation in Cork. It was well attended and pretty well presented and I was pretty impressed. I was also impressed by the copies of Windows 7 Ultimate we were given to try out.

So I informed the nephews of my intention to put Windows 7 on the desktop system at home and gave the, a couple of weeks to backup any stuff they really wanted to keep since I would not guarantee that anything would survive the transition from Windows XP to Windows 7.

I ended up giving them a bit more time than I originally intended before I got around to putting Windows 7 on that machine. I used the used the Windows Easy Transfer tool to migrate their existing user profiles to an external hard drive and the, since I decided to go with Windows 7 64bit on that machine I rebooted the machine and installed the new OS. It all went as advertised and the installation ran unattended by me. I came back later to find it completely installed and then used the Easy Migration tool to restore the profiles from the hard drive.

I had a brief play about with the new OS and though it looked really pretty and left the young 'uns at it for about a week or so. After that interval, I got no complaints and I decided to reinstall the printer and get it shared to my laptop still running XP. Since i use this for development I decided to wait for my MSDN Windows 7 release to upgrade the laptop, though I was still unsure. I have a few apps in mid development and I am always wary about changing OS in mid development.

However, I find that I am spending more time taking care of my mother and less in development these days. Though I will find the time to get in some more development work as soon as I get some things sorted out.

Anyway, back to Windows 7, printer sharing was not too bad with the help of a useful article from HowtoGeek. The only problem was that the share on the windows 7 machine was not sharing out the correct printer drivers. I solved that by installing the printer drivers on the laptop and every thing worked fine.

After a couple of weeks I was starting to get really cheesed off on the boot times of the laptop as compared to the Windows 7 machine, and more particularly the time after the desktop comes up but Windows is still loading services and what not and you have activated FireFox or Outlook but they do not become usable for another 10 minutes as distinct to near instantly on Windows 7.

So my MSDN disks arrive and I decided to take the plunge and install Windows 7 on my laptop. Since I am not working for any boss at the moment and my development efforts are for fun and to keep me in the game I decided to live on the edge and see what happened. So same as before, I migrated my profile using the Windows Easy Transfer Tool and installed Windows 7 and Microsoft Security Essentials.

Every thing ran smoothly and no hiccups until I tried to connect to the shared printer on the desktop, it picked up the printer but would not print.

I reckon the problem is that the desktop machine was sharing out the 64 bit drivers while I had installed the 32 bit version of Windows 7 on the laptop. So I tried the automated troubleshooting software and in the middle the desktop machine rebooted to get something working and failed to boot.

It posted but hung in the boot. So I thought it is not with the new version that long and I had not created a recovery disk so I would simply reboot the machine with the Windows DVD and reinstall but now the installer does not recognise the hard drive.

Not to worry I though, it is not too mission critical to me, though it may bother the nephews so I will just complete installing stuff on the laptop, and sort out the desktop machine later.. So on with Office and Firefox and then horrors of horrors Civilization 4 does not run properly.

Now its serious :-)

The error was quite weird, the game basically ran but the Audio Settings were not visible and the graph had some internal programming constant names instead on the constant string values and I could not launch a revolution to change civics. Some of the dialogues were also messed up with constant programming names appearing instead of the underlying string values.

The solution, un-install the applications, including manually removing both the application files and the game profiles. Reinstall Civ 4 core game and then manually download and install the latest patch, I got it from here because I kept getting errors on the official page. Then go find the actual file

Right click on the selected exe file and select the "Troubleshoot Compatibility" option and then follow the wizard. So Civ ran as intended then install the expansion, in my case the "Beyond the Sword" expansion. Repeat the compatibility steps with the expansion. This is now running normally. At least a quick few turns with the Romans indicate that all seem normal at the moment.

I will blog more here as my adventures unfold. My next trick is to continue my experiment to play all civs in the game and see how I do. I am going to use this to test windows 7 before i start installing my development applications like Visual Studio and SQL Server and so forth.

I am also going to have a look at the backup and recovery stuff and see if I can resurrect the desktop machine.

So final thoughts, Well it looks good and it boots quickly and it seems as stable as XP so far, apart from the issue of what ever happened to the desk top machine.

Monday, July 13, 2009

Configuring a firewall

One of my hobbies is gaming, wargames (used to be mostly historical hex games) but now more often Euro style games and role playing games, mostly D&D, though in the past Palladium, MERP and Warhammer Fantasy Roleplaying Game also featured.
A few years ago a couple of friends and I tried out online gaming, initially Neverwinter Nights modules, Guild Wars, Civilisation 4, D&D Online and recently there is talk of Lord of the Rings Online, though I am not that keen on the latter. There is also the matter of cost and the fact that I am currently one of the great unemployed.
Now, over the last year or so I have been running a campaign of 4th edition D&D, now I really love this version of the game. The campaign is based loosely on the published modules beginning with Keep on the Shadowfell.
I can feel that the campaign is going to veer of course but that is another matter. However, I have also been running the Scales of War campaign from Dungeon for my older game friends when we meet a couple of times of year. The problem with that is that at 2 to 3 sessions a year it is not likely to finish withing my lifetime. So a possible solution is online game on a virtual table. This was one of the promised features of D&D 4th edition but it may never be delivered at the moment. So what are the alternatives? From my lurking on ENWorld, I tried out a couple and decided that Maptools is the one for me. It very easy to create maps and counters for and looked promising. The problem, is connecting over the Internet.
What is the issue, no real idea but I suspect that something is blocking the relevant ports. So to determine the issue, I tired getting a session running over the LAN, no joy. So it is my local firewalls that are causing the problem.
I am using Kaspersky Internet Security 2009 and it is pretty complex with regard to rules for access to applications. It appears to set up the rules per application. My problems, well I am not sure how the open particular ports in Kaspersky for a particular application and not at all sure how to accomplish this for a application like Maptools that is a .jar file.
Before I go an start mucking about with the ports on the local machine I decided to secure the LAN router.
Not as easy as it appeared. I use a Sweex LW050v2 router and when I set the firewall to deny all and started to create rules to allow standard net traffic no traffic was being allowed through.
So what appears to be the case is when, setting ip address filtering one needs to not specify LAN ports, just the WAN ports one wants open to allow the normal traffic. For quick reference mail used 25 (smtp) and 110 (pop), 80 (http) , 443 (https), 53 (DNS) ,FTP(20,21). The rest are based on what applications one wishes to work and I will refer you to the port forwarding page for that.
There is a major problem with the router though and that is it only takes 8 rules, so as a packet filterign firewall it leaves something to be desired.
I got maptools working in the LAN but had use the direct ip options. I must try to run the application on a pc connected directly to the cable modem as it appears that the cable modem is connected to hte internet through a NAT router. If it works driectly on the cable modem then ok, otherwisw I would have to use Hamachi or some other vpn software. I have already run it using Hamachi and it is very slow.

Rad With Access

Well, been a while since I posted here, got 7 days to build a small app for a company, initially they were thinking of Excel but that was they were used to hammers so all problems are nails. So I offered to do it in Access with the caveat that it was about 14 years or so since I worked with Access last.
So I got it done, just about, there a few things I did not get around to and there have been no complaints since and they were happy with it as it stood.
The code was less than elegant in places because I worked with what I could remember and DAO I could remember but not ADO. It took a while for Access SQL and using parameter queries to come back to me so there are areas that could usefully be revisited in the application to change from using DAO recordsets to using parameter queries.
The remarkable thing is how little Access has really changed over the years, at least for basic applications of that type.

CiV VII The first 100 hours

First Impressions   I purchased Civ VII from Steam earlier this summer when it was on sale and almost immediately pulled an all-night sessio...