Many people have installed the beta or release candidate releases of Windows 7. Now that Windows 7 RTM is out they want to upgrade these installations. They will found out that it is not possible. The installer will complain that you have in stalled a version of Windows 7 that cannot be upgraded. It that it? Must you do a clean install and loose all the stuff from the other installs? No, see the steps underneath to upgrade the per-RTM Windows 7 installations.

How to Upgrade Windows 7 RC/Beta to Windows 7 RTM

1. Mount Windows 7 RTM Build 7600 ISO and Extract content to any folder or USB drive.
2. Now go to Sources folder of Windows 7 and open “cversion.ini” file in notepad.
3. Modify the “MinClient” build number to a value lower than your installed Windows 7 Build. For example, change 7233 to 7000 if you have Windows 7 Beta Build installed.

[HostBuild]
MinClient=7000.0
MinServer=7100.0

4. Save the updated file to the same location and then run setup.exe to start Windows 7 RC upgrade process.

That’s it, Now follow on Screen instructions and choose Upgrade option.

I want to write some blogpost about RhinoMocks. I made a TestProject in Visual Studio.Net 2008 to make some examples. The first thing I did was to add a reference to the RhinoMocks assembly. I made a test and it would not excute. This is all I got at first:

I did not understand why. I looked up more information about the testrun. This is what I found: The location of the file or directory ‘c:\users\<<user>>\documents\visual studio 2008\projects\rhinomocksdemos\rhinomocksdemos\bin\debug\Rhino.Mocks.dll’ is not trusted. Not trusted?! Its my computer. I downloaded it. I trust it. Windows is being stubborn (again). How can I solve this? Why does this happen?

As it turns out Windows (XP SP2 and above) is just being carefull. It adds a marker to a file downloaded from internet indicating that it may not be safe to execute it. Normally Windows will show a ‘Are you sure?’ dialog when you try to use the file. In my case it showed nothing obvious and left me in the dark. It would have been nice if Windows showed this error and the solution. It is a missed chance but then again I would not have anything to do if the world was perfect. The solution is simple: go to the properties of the file and click the unblock button on the General tab. Look at the screenshot below. Next click on the Apply button and then on the Ok button. The problem is solved. Testing and mocking can start.

 

 References:

http://social.msdn.microsoft.com/forums/en-US/vststest/thread/0d8d89d1-e373-4a29-9325-febf748a771c/ 

Ever have this error when you were building a master-detail view with the ASP.Net DetailsView and the GridView?

Server Error in ‘/’ Application.


Object must implement IConvertible.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Object must implement IConvertible.

 

I had. You know why? I will explain. It occurs when you use ObjectDataSources to create the master-detail view<< Er moet tussen dat de objectdatasource een methode als selectmethode gebruikt die een string verwacht en daardoor een IConvertible verwcaht>>. When you make the master-detail view the GridView DataKeyNames array contains the primary key fields of the table it displays. The DataKeyNames array is used the fill the SelectedValue property with the primary key value belonging to the row that is selected. The SelectedValue property is used as a parameter of the selectquery of the DetailsView’s ObjectDataSource. This way the GridView and the DetailsView are synchronized. The SelectedValue’s datatype must implement the IConvertible interface. I was using a Guid as the primary key field. A Guid does not implement the IConvertible interface. So the application blows up.

How can we use a Guid field as a primary key? 

Solution 1: use a guid as a parameter.

Solution 2: use the string but convert the guid to a string. 

What is T4? Has it something to do with C4?

Visual Studio.Net has a little known code generation feature called T4 templates since version 2005. It was introduced to facilitate Domain Specific Languages (DSL’s). With it you can make code generation templates like the ones CodeSmith has but without the GUI. A free GUI can be downloaded here.

You can find more information about T4 here and here.

TypeMock Isolator is a mocking framework for .Net. It uses the .Net profiling API to do its work. This makes it possible for TypeMock to mock parts of your code that other frameworks cannot. TypeMock makes it easy to write unit tests. TypeMock provides three ways to fake dependencies:

  • Relective Mocks. Reflective mocks uses reflection and a string based API,
  • Natural Mocks. It is a Record-Replay but strongly typed API,
  • Arrange-Act-Assert (AAA) API.

In this post I want to show you how to mock the AppSettings property of the ConfigurationManager class using the Reflective and Natural Mocks patterns.

the Reflective Mocks way

reflectivemocks

Notice the ClearMocks attribute (line 16) on the testclass. It tells TypeMock to cleanup its mock administration before a test is run. Also notice the VerifyMocks attribute (line 20) on the testmethod. This attribute cause TypeMock to verify the mocks in the test. These attributes are used by Natural Mocks also.

MockManager.Mock (line 29) is used to get fake of the ConfigurationManager. With the fake you can tell TypeMock that the AppSettings property returns a NameValueCollection. You can use either ExpectGet or ExpectGetAlways. I used the latter because TypeMock will always return the value you setup. ExpectGet will only return the value once. Every next call to AppSettings will throw an exception.

As you can see in the example above I created a NameValueCollection and added the key-value pair “ApplicationName”- “TypeMockDemo”. With ExpectGetAlways (line 30) I make sure the my collection is always returned. Just the way I like it.

This is all you have to do to setup ConfigurationManager.AppSettings. Now you can call the code you want to test like you always did. Look at the picture below for the implementation of the ApplicationContext class.

appContext

The Natural Mocks way

Next the same example as above but now implemented with Natural Mocks. The picture below shows the code:

naturalmocks

The setup of the fake is done in the using block. A recorder is created by RecorderManager.StartRecording. The recorder let you setup expectations. In this case I told TypeMock that I expect a call to the  ConfigurationManager.AppSettings.Get method. See line 45. After setting up the expectation I told the recorder to return “TypeMockDemo” for this expectation. After the setup you can call the code you want to test like you always did.

I do not like line 45 because it is not natural. I want to setup the expectation like this: ConfigurationManager.AppSettings[“ApplicationName”] = “TypeMockDemo“;. I could not get that to work. Maybe someone else knows how to do that. Someone?

Finishing up

I am going to show more examples of how to mock using TypeMock. Also I am going to rewrite the examples with RhinoMocks and Moq mocking frameworks.

Updated: The pictures were wrong. I copy-pasted the pictures. If you do that Live Writer gives them the same name. My blog shows the same image for all images. I corrected that.