BM-Bloggers

The blogs of Black Marble staff

Why Typemock Isolator does not work on TFS 2012 Build and what you can do about it

Update 4/Aug/2012: See post on my implementation of a 2012 version of this activity

If you are using Typemock Isolator in your unit testing then you be wanting to include then in your automated build process. Unlike other mocking frameworks you have to do a bit of work to achieve this with Isolator, this is because to enable its advanced features of mocking items like sealed private classes you have to start the interceptor that does the magic prior to running the tests and the switch it off afterwards.

In the past I posted on how you could use a build activity I wrote to wrapper MStest in a TFS 2010 build using TMockRunner. Since I wrote this Typemock released a set of build activities to do the starting and stopping of the inceptor as separate activities, a much more flexible solution which I would always recommend for TFS.

However when you try to use either with TFS 2012 you get a problem, the activities fail to load. This is a problem we saw on the TFS Extensions Codeplex project; you have to build you activities against either the 2010 TFS API or the 2012 TFS API. You don’t need to alter the code in your activities, but you do need to make a specific build.

So at this time there is no solution, one or both of these activities need to be rebuilt. For the MSTest wrapper I wrote the source is available so you can do it yourself if you want to, but the way Typemock have implemented their activities is a better solution. This is because it is not reliant on TMockRunner and MStest, it can wrapper any activities. This is important as to be able to use the new ‘any framework’ unit testing features in VS2012 you want to use Microsoft’s new test running activities and not just the old MSTest activity.

I understand that Typemock are looking at releasing a TFS2010 version of their activities soon, but I know of no release date as yet. If you want an immediate solution you will need to do a bit of work.

  • You could rebuild my MSTest based activity
  • You could use the standard InvokeMethod activity and put the contents of my MStest activity’s generated command line into this
  • But the one I favour is to use a dissembler such as Telerik JustDecompile to get the code from the Typemock.TFS2010.DLL and build a new activity.

However, it must be said I see this as just a temporary measure until the official Typemock 2012 activity is released. I am not sure I will get around to doing this before the Typemock release, we shall see.

Windows Azure Training Kit–June 2012 Release

The Windows Azure Training Kit June 2012 release is out now with the following features:

  • 12 new hands-on labs for Windows Azure Virtual Machines
  • 11 new hands-on labs for Windows Azure Web Sites
  • 2 new hands-on labs demonstrating Windows Azure with Windows 8 Metro-style applications
  • Several new hands-on labs for Node.js and PHP using Mac OS X
  • Updated content for the latest Windows Azure SDKs, tools, and new Windows Azure Management Portal
  • New and updated presentations designed to support individual sessions to a full 3 day training workshops

Adding DHCP Option 119 (Domain Search List) to Windows Server 2008 R2

If you’ve seen my recent blog post on making Android work in Hyper-V you will have seen my problems around DNS resolution when in the office. That turned out to be down to the DHCP options being handed back by our Server 2008 R2 box. Or rather, it was what wasn’t being handed back to the client that was the problem.

Linux (and Apple OSX, as it turns out) both want a response to option 119, which defines the domain suffix search order. Windows does not request this option and the windows DHCP server does not offer the option at all.

There are a few locations on the web that talk around this but none properly document the process of adding the custom option to your DHCP server and more importantly, exactly how to encode the response (thanks go to Matt for describing that one in enough detail!).

What option 119 looks like

Option 119 hands back a byte array that encodes the domain suffix. The trouble is, it’s not a simple matter of turning text into ascii hex values. There is a structure to it.

Our domain is blackmarble.co.uk. I found a handy web site that sped up the process of getting the hex of that.

b l a c k m a r b l e . c o . u k
0x62 0x6c 0x61 0x63 0x6b 0x6d 0x61 0x72 0x62 0x6c 0x65 0x2e 0x63 0x6f 0x2e 0x75 0x6b

The client expects the full domain to be split (get rid of the separating periods), with each section prefixed by it’s length (e.g. 11 blackmarble 2 co 2 uk) and then the whole string is null terminated.

  b l a c k m a r b l e   c o   u k  
0x0b 0x62 0x6c 0x61 0x63 0x6b 0x6d 0x61 0x72 0x62 0x6c 0x65 0x02 0x63 0x6f 0x02 0x75 0x6b 0x00

Adding the option to Server 2008 R2

To add the DHCP option to Windows Server 2008 R2 you need to add a new option to the IPV4 section. Select ‘Set Predefined Options’ from the context menu on the IPV4 heading beneath the name of the server in the DHCP console.

dhcp option menu

In the dialog that appears, click the Add button.

dhcp options add

Enter the name for new option. It needs to be of type Byte and make sure you check the array option; the Code is 119 and you can add a description if you want to.

dhcp add new option

Once you’ve defined the option you can add it either to the main Server Options section, a scope or an individual address reservation.

119 server options

Each of the hex values you worked out (see my examples) needs to be added in turn to create the full byte array.

Hopefully this pulls all the necessary information into one handy reference and it saves somebody else the confusion I experienced.

A Virtual Ice Cream Sandwich: Android 4 x86 in a Hyper-V VM

More and more of our projects include a stipulation from the client that any web sites must work on the tablet devices of senior management. Up until recently that was exclusively iPads, but we are now seeing more Android devices out there. I wanted to find a straightforward way for us to test on such devices, preferably without needing to build up a collection of expensive physical kit.

I read with interest Ben Armstrong’s post about running Android 2.2 (Froyo) in a VM using a build from the Android x86 project. I started my journey by replicating his steps, so I won’t document any of that here, other than to note that the generic x86 build you need is now a deprecated one, so I had to hunt a little to find what I needed.

Creating the VM was a doddle. However, once I’d got things up and running I hit a snag: The sites I needed to test were hosted on SharePoint and required authentication. The web browser on the Android 2.2 build steadfastly refused to present a logon dialog for any sites. I could rework my test sites with anonymous access or forms-authentication but that didn’t fill me with enthusiasm. I wondered, then, if a later Android version might be my salvation.

That in itself led to a long time spent digging around the corners of the internet: The Android x86 project has a number of Ice Cream Sandwich builds but all are targetted at various types of hardware device and whilst all had support for wifi, none had support for ethernet. Since I can’t present a wifi device within the Hyper-V VM I had to look elsewhere.

The build I finally used was one I found at tabletsx86.org – an Android 4 build with experimental ethernet support.

I ran through a number of installations as I edged my way through the different options each time I found that a choice I’d made prevented me from making some essential tweak. To save you all the effort, I’ve documented the steps here. Since I was a complete Android novice I’ve taken the approach of showing screenshots of every step for other novices like myself.

Step 1: Getting things installed

The Virtual Machine we need to create doesn’t have to be powerful. However, we are running an OS that is not Hyper-V aware, so we can’t just go with the defaults.

I created a machine with 512Mb of RAM and a single processor. I started with a 16Gb virtual disk as the hard drive but after a few passes I increased that to 32 to give me some headroom should I want to install apps later. The important step, however, is that you need to add a Legacy Network Adapter and remove the standard virtual adapter that Hyper-V will add.

hyper-v settings

Once you’ve got your VM built, insert the ISO for the Android 4 build into the DVD drive and boot the machine.

Select the option to install Android to the hard disk of the machine.

screen1

On the next screen choose Create/Modify partitions

screen2

In the partition editor, left and right cursor keys will move between the menu items; enter will select. Choose New to create a new partition.

screen3

You want to create a new primary partition

screen4

The utility defaults to the full size of the disk. Simply hit enter to confirm that.

screen5

Now we have our partition we need to mark it as bootable.

screen6

And finally we need to write the changes out to disk.

screen7

Now we have our partition we can exit the utility to continue the installation.

screen8

The installer will now show our new partition and allow us to select it as the target for the installation.

screen9

We then need to choose what format to use for the installation. I used ext3. I did try NTFS once, thinking that I could easily transfer files onto the system, but when I attached the VHD windows failed to recognise the file system, so I went back to Ext3, figuring I’d simply transfer stuff over the network.

screen10

Unsurprisingly, the installer asks for confirmation of the format.

screen11

Then it shows progress as it formats.

screen12

Next you need to install the Grub bootloader. Honestly, I’ve not tried without this, but I modify the bootloader options later so unless you want to plough your own furrow, install Grub.

screen13

The default option at the next step is to install the system directory as read only. I discovered very quickly that some of the things I might need to fiddle with are in that system directory so I’ve chosen to make it writable.

screen14

Now the installation occurs.

screen15

Once the installation is complete you should choose to create a fake SD card. I learned the hard way that if you don’t, saving stuff in your Android web browser won’t work.

screen16

Sadly the largest size we can create is 2Gb, which conveniently is the default.

screen17

Once again we get a progress bar whilst the SD card image is created.

screen18

Now we’re all done and we get the option to reboot. Note that you can’t eject the installation media yet – it’s locked, so you’ll have to reboot.

screen19

When the VM reboots you’ll be back at the first screen, allowing to choose to install or run the live CD. Turn the VM off so you can eject the media.

At this point the installation is done. You have a shiny new Android VM running Ice Cream Sandwich.

Step 2: The Android wizard

This isn’t difficult at all, other then you need to remember that when you click on the VM to capture the mouse, it’s really emulating your finger. That means that you need to click and drag in drop down menus. I also discovered that the right mouse button seems to act as the hardware back button. Clicking the mouse is equivalent to tapping with your finger.

I set the language to UK English as my first step.

screen21

Then the wizard will burble for a little while.

screen22

I chose to automatically set the time. Think grey outlines of check boxes are hard to see when they are on a black background!

screen23

The next step allows you to use your Google account to keep settings an stuff. I’m building a VM that will be generic and used by lots of people so I skip this one.

screen24

I am happy to use location services though – we want to use this thing for testing, after all.

screen25

Again, because this is a build for lots of users I’ve put the company in as the owner name. Note that even though we chose United Kingdom as the location, the keyboard setting is for a US keyboard.

screen26

Next we get an obligatory screen where we agree to stuff…

screen27

…and we’re done.

screen28

The system helps you through how to use it. The import bits are the icons at the bottom. The upward pointing outline of an arrow in the middle brings you back to the home screen.

screen29

A handy tip

This thing feels a lot like Linux to me. Conveniently, pressing alt+f1 will switch to a console screen. Alt+left arrow and alt+right arrow will switch between consoles and the graphical UI.

Inside the console you can use familiar tools like ping and nslookup. It’s not a full-fat linux box, mind you. The two commands I find myself using most in the console are reboot and halt. Odd that there’s no way to cleanly shutdown – no shutdown command or even an old school init 0!

A couple of minor hiccups

Having got my VM up and running and gone through the startup wizard in Android there were a few things not quite right. First of all the screen resolution was too low at only 800x600. Step forward my very rusty Linux experience and my much less rusty internet research expertise!

More worryingly, when I boot the machine it doesn’t always pick up the correct DNS settings.  Research showed that to be much more interesting. Strangely, things worked at home but not in the office. Research showed that it was to do with the DHCP responses being different on the two networks: The office network was not responding to the request for DHCP option 119 – domain suffix search order. Fixing that solved the problem (but that’s another can of worms and I’ll write up a separate post about that one!).

Step 3: Setting the screen resolution

This one turned out to be quite easy, although it involves using Vi, which is a text editor whose arcane commands I have very limited knowledge of.

The first thing we need to do is find information about what display modes are available. To do this we boot the VM and use the options available to modify the boot parameters. Be aware that when you boot the VM the Grub screen only shows for a few seconds before the first option is booted automatically. When you see the screen below, hit the ‘a’ key to easily append options to the boot command.

screen30

When you hit ‘a’ you will be presented with the boot command to edit. Options on the command line are separated by spaces. Add a new one: vga=screen31

Hit the enter key and the OS will boot. You will see a black screen with a number of options on it. Hit enter again at this screen in order to view the display modes available to us.

screen32

From the list of available modes, choose the one you want to use. The system is waiting for you to type in the three character hex code for the mode you wish to use. For 1024x768 at 32 bit, for example, enter 318

screen33

Assuming all works correctly  you will see Android running in your chosen resolution. Sadly, it’s not permanent yet. I’ve also become paranoid enough that before I edit the bootloader options permanently I like to try what I’m going to do first.

Reboot the system and hit ‘a’ to append boot options. This time we want to specify the display option we want to use. Just to bend your head a little, the boot option needs the decimal equivalent of the hex value that the display modes screen showed us. For Our 1024x768x32, the hex was 318. The decimal is 792, so we append vga=792 to the boot options.

screen34

When Android boots, you should see it in 1024x768 once more:

screen35

Now we need to make the change permanent. To do that we need to edit the configuration file that the Grub bootloader uses.

To do that we need to reboot the system in debug mode.

Boot the system and use the cursor keys to select the second option on the boot menu.

screen36

The system will boot to a command shell:

screen37

Once you’re in the command prompt, typing clear will clear the screen and get rid of the boot messages. Then you need to enter the following commands:

cd /

mount –o remount,rw /mnt

cd /mnt/grub

vi menu.lst

What does that lot do? The part of the filesystem that stores the bootloader is attached as read-only. The mount command effectively detaches and reattaches that part of the filesystem so we can modify it. The files we want are in the grub folder within mnt. Finally, we open the text editor Vi to change the file.

Vi is a bit arcane, although extremely powerful. For help with the commands look at online tutorials, like the one hosted by Washington University.

Once we’re in the config file we are going to add the vga=792 option to the end of the default boot command. I’ll tell you what Vi commands I use to get the job done – note that they are not necessarily the best ones, they just work for me. I know about half a dozen Vi commands and they allow me to get by. If I want to do something clever I have to look it up!

screen38

In Vi, the cursor keys allow you to move around the file. Pressing escape tells Vi to listen for commands. Move down to the start of the first line of the first boot section (the first occurrence of ‘kernel’). Press Esc then ‘o’. That should give you a new line after kernel.

screen39

Now use the cursor keys to navigate to the end of that first ‘kernel…’ line and you should be able to type ‘ vga=792’

screen40

Now we want to get rid of that extra line. Move the cursor to the start of it and hit Esc then dd (escape then hit ‘d’ twice).

Finally we save the file. Esc+:wq is the command to write out the file and quit.

screen41

You should now find yourself back at the command prompt. Type reboot –f to reboot the system.

You should now find that by default your Android VM boots into your chosen resolution.

A quick side note

If you don’t have control over your own DHCP server you can use the following command to poke the dns into life:

setprop net.dns1 x.x.x.x where x.x.x.x is the IP address of your DNS. You can also add a second with net.dns2.

You can also give the VM more memory with no issues – mine now runs with 1024Mb. I’ve also added a second CPU core as an experiment which works but I’m not sure it’s any quicker.

Where did my Visual Studio 2010 link go from my Windows 8 desktop after I installed SSDT?

I have been finding the ‘hit the windows key and type’ means to launch desktop applications in Windows 8 quite nice. It means I get used to the same behaviour in Windows or Ubuntu to launch things, no need to remember menu locations just type a name, all very slickrun . However, I hit a problem today, I hit the windows key, typed Visual and expected to see Visual Studio 2012 and 2010, but I only saw Visual Studio 2012

image

But both were there yesterday!

The issue was I had install SSDT (SQL Server Data Tools), this is hosted within the Visual Studio 2010 shell and had renamed my Metro desktop Visual Studio 2010 App to Microsoft SQL Server Data Tools. If I typed this the app was found and it launched Visual Studio 2010. I then could choose whether to use SSDT or Ultimate features as you would expect. This is the same behaviour as on Windows 7, it is just on Windows 7 you would have two menu items, one for SSDT and one for VS2010 both pointing to the same place.

Now I am a creature of habit, even if it is a newly formed one, and I like to just type Vis, so this is how I got the link back into the Metro desktop, might be other ways but this is the one that worked for me

  1. Found the Visual Studio 2010 devenv.exe file in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE
  2. Right click and create a shortcut on the desktop
  3. Rename the new desktop shortcut to ‘Visual Studio 2010’
  4. Right clicked on the renamed shortcut and selected ‘pin to start’
  5. Deleted the desktop shortcut, it is no longer needed as it has been copied, yes I found this a bit strange too, but I do like a clean desktop so delete it I did. You don’t have to delete it if you want a desktop shortcut.

I can now press the Windows key, type Vis and I can see both Vs 2010 and 2012, and I can still type SQL and get to SSDT

image