But it works on my PC!

The random thoughts of Richard Fennell on technology and software development

Nice introduction to the new features of VS2012

If you are looking for a nice introduction to the new features of Visual Studio 2012, I can heartily recommend Richard Banks 'Visual Studio 2012 Cookbook'.

This book covers a wide range of subjects including the IDE, .NET 4.5 features, Windows 8 development, Web development, C++, debugging, async and TFS 2012. This is all done in a easy to read format that will get you going with the key concepts, providing sample and links to further reading. A great starting off point.

There is stuff in the book for people new to any of the subjects as well as nuggets for the more expererienced users. I particularly like the sections on what is not in 2012 but was in previous versions, and what to do about it. This type of information too oftan left out of new product books.

So a book that is well worth a look, and has it has been published by Packt there are no shortage of formats to choose from.

Weekend trip to see family – 1 OS upgrade, 1 network printer installed and 3 machines de-virused

I have been away over the weekend seeing family, and as anyone who is in IT (or is a medical doctor I suspect) would expect I had the standard experience – everyone wanted me to show me something they were worried about that turned to be virus related. This trip I did one operating system upgrade, one network printer installation and de-virused three PCs. So nothing out of ordinary.

The one thing I would mention was how useful I found the contents of Mark Russinovich’s TechEd Session ‘Malware Hunting with the Sysinterals Tools’. This saved me the complete machine rebuild I had feared for one PC which had got infected with a bit of poor quality ransomware  that turns out to only be a splash screen that I could easily spot with Autoruns from the Sysinternals Suite. The video is well worth a watch for all of us in the family IT support game.

At last my Nokia Lumia 800 gets its firmware upgrade to allow tethering

At last my Nokia Lumia 800 gets its firmware upgrade to allow tethering. The 8773 update seems to be made up of three updates, two operating system ones (which I managed to force down in the usual way), but this Nokia firmware one has taken weeks to get to me, forcing did not help. I had to wait.

I don’t think I am alone in not being too impressed with the update process. The throttling/delaying update process is probably Ok for the man in the street, who just wants a working phone, but there should be an easier way to get updates if you want/need them ASAP for development purposes or are trying to run consistent versions for all phones in an organisation.

Skydrive pushes me over my broadband usage

I got back from a trip away to find an unexpected bill for broadband  through the letterbox. I have paid about the same each quarter for broadband for a good while now, I don’t see much variation as I rarely use my home phone, then again who does?

This bill was nearly double, why?

I think it was mostly due to setting up Skydrive to mirror my family photos and video as a backup, though this can’t explain it all, but then again my son as found Roblox. In each month I went over my usage it was costing me £5 a 5Gb block. It adds up fast.

On calling BT I found I could upgrade my package to a larger allowance and it worked out less than £1 more. The most irritating thing was they had been emailing me about my usage on my BT provided email address, an address I have never used.

So the top tip is make sure your usage notifications go to an address you actually get .

Thoughts on my Channel9 post

After hearing my TEE video on Channel9 mentioned on Radio TFS I thought I should watch it through, I had only found time to do a quick look previously. This is all part of my on-going self review process, a form of self torture.

It seems the issues I mentioned last time are still there, I still have too many err’s. The thing that stood out the most was I looked like a very shifty newsreader. My movement behind the table and losing eye contact with the camera were too noticeable to me.

This said I am happy with how it came out. It was great working with a professional crew and you can see how good they can make the video look with good lights, camera and  editing.

On the whole I am very happy with it, just need to ‘love the camera’ bit more.

Thoughts on the new Skydrive

I have swapped to the new version of Microsoft Skydrive, replacing my old Mesh setup. It is a nice slick experience, allowing easy viewing of files on Skydrive from Windows and WP7. However, I do have couple of issues

  1. I used Mesh to sync photos from my Window 7 Media Center up to cloud storage as a backup, don’t want to loose all the family photos due to a disk failure. This was simple with Mesh, just set up a sync. This is not so easy with the new Skydrive, which appears only as a folder in your user area. The only solution I can spot is to copy my photos into this folder e.g. xcopy d:\photos c:\users\richard\skydrive\photos. Once the copy is done this will be synced up to the cloud. With mesh if I added a file to my PC it sync’d without me doing anything, now I need to remember the xcopy (or whatever sync copy tool I am using), or have the copy being run on a regular basis via a timer.
  2. Letting Skydrive start automatically on a laptop Windows PC is dangerous. I was on site today using my Mifi and in about 10 minutes used a whole days credit. So I would recommend changing your tool tray setting to make sure you can see the Skydrive icon all the time, so you have a chance see when it is syncing and can stop it when on a connection that cost you money.

image

So any comments, or better ways to do the sync?

More thoughts on Typemock Isolator, Microsoft Fakes and Sharepoint

I posted yesterday on using Typemock and Microsoft Fakes with SharePoint. After a bit more thought I realised the key thing in using Typemock I found easier was the construction of my SPListItem dataset. Typemock allowed me to fake SPListItems and put them in a generic List<SPListItem> then just make this the return value for the Item collection using the magic .WillReturnCollectionValuesOf() method that converts my List to the required collection type. With the Microsoft Fakes I had think about a delegate that constructed my test data at runtime. This is not a problem, just a different way of working.

A side effect of using the Typemock .WillReturnCollectionValuesOf() method is that if I check the number of SPListItems in the return SPListColection I have a real collection so I can use the collection’s own .Count method, I don’t have fake it out. With the Microsoft Fakes as there is no collection returned so I must Fake its return value.

This is a trend common across Typemock Isolator, it does much  of the work for you. Microsoft Fakes, like Moles, required you to do the work. In Moles this was addressed by the use of behaviour packs to get you started with standard items you need in SharePoint.

I would say again that there may be other ways of using the Microsoft Fakes library, so there maybe ways to address these initial comments of mine, I am keen to see if this is the case

Now that VS11 has a fake library do I still need Typemock Isolator to fake out SharePoint?

Updated 5 May 2012 Also see my follow up post, this corrects some of the information of faking SharePoint 

I have done posts in the past about how you can use Typemock Isolator to fake out SharePoint to speed design and testing. The  reason you need special tooling, beyond standard mocking frameworks like Rhino or MOQ, is that SharePoint has many sealed private classes with no public constructors. So in the past you only had two options: Typemock Isolator and Moles from Microsoft research.

With the release of the Visual Studio 11 beta we now have a means to fake out ‘non mockable classes’ (shim) classes that is shipped in the box. This tooling I understand has it roots in Moles, but is all new. So with the advent of fakes in VS11 you have to ask ‘do I still need Typemock isolator?”

To answer this question I have tried to perform the same basic mocking exercise as I did in my previous posts. Create a fake SharePoint list and make sure I can access the faked out content in test asserts.

In Typemock Isolator

To perform the test in Isolator, assuming Isolated is installed on your PC, is add a reference to Typemock.dll and Typemock.ArrangeActAssert.dll and use the following code

[TestMethod]
        public void FakeSharePointWithIsolator()
        {

            // Arrange // build the dataset var fakeItemList = new List<SPListItem>();
            for (int i = 0; i < 3; i++)
            {
                var fakeItem = Isolate.Fake.Instance<SPListItem>();
                Isolate.WhenCalled(() => fakeItem.Title).WillReturn(String.Format("The Title {0}", i));
                Isolate.WhenCalled(() => fakeItem["Email"]).WillReturn(String.Format("email{0}@fake.url", i));

                fakeItemList.Add(fakeItem);
            }

            // fake the SPWeb and attach the data var fakeWeb = Isolate.Fake.Instance<SPWeb>();
            Isolate.WhenCalled(() => fakeWeb.Url).WillReturn("http://fake.url");
            Isolate.WhenCalled(() => fakeWeb.Lists["fakelistname"].Items).WillReturnCollectionValuesOf(fakeItemList);


            // act // not actually doing an operation // assert Assert.AreEqual("http://fake.url", fakeWeb.Url);
            Assert.AreEqual(3, fakeWeb.Lists["fakelistname"].Items.Count); 
            Assert.AreEqual("The Title 0", fakeWeb.Lists["fakelistname"].Items[0].Title);
            Assert.AreEqual("email0@fake.url", fakeWeb.Lists["fakelistname"].Items[0]["Email"]);
            Assert.AreEqual("The Title 1", fakeWeb.Lists["fakelistname"].Items[1].Title);
            Assert.AreEqual("email1@fake.url", fakeWeb.Lists["fakelistname"].Items[1]["Email"]);
            
        }

Using Microsoft Faking

Adding the Fake

The process to added a fake in VS11 is to right click on an assembly reference (in our case Microsoft.SharePoint) and select the ‘add fake assembly’ option.

image

You should see a Fake reference created and an entry in the fakes folder

image

Gotcha Warning ‘Can’t generate the fake reference’ – When I tried to generate a fake for the Microsoft.SharePoint assembly within a classlibrary project that had a reference to only the Microsoft.Sharepoint assembly (and the default assemblies references added for any classlibrary project) the entry is made in the Fakes folder but no .Fakes assembly is created. After a delay (30 seconds?)  you see an error message in the Visual Studio output window. This tells you a reference cannot be resolved, if you delete the entry in the Fakes folder, add the missing reference listed in the output windows and repeat the process you get the same problem but another assembly is named as missing, add this and repeat this process. Eventually the .Fakes assembly is created.

In the case of this SharePoint sample I had to manually add Microsoft.SharePoint.Dsp, Microsoft.SharePoint.Library, Microsoft.SharePoint.Search, System.Web, System.Web.ApplicationServices. Remember these entries are ONLY required to allow the fake creation/registration, they are not needed for your assembly to work in production or for Typemock.  [5 May 2012 See my follow up post

You should now have a generated assembly that you can use to create your fakes shims

Writing the fakes logic

The logic to create the fake behaviour is as follows. Now there might be easier ways to do this, but this does work and is reasonably readable

 [TestMethod] public void FakeSharePointWithShims() 
{
using (ShimsContext.Create()) // required to tidy up the shim system
{
// arrange
var fakeWebShim = new Microsoft.SharePoint.Fakes.ShimSPWeb()
{
UrlGet = () =>
http://fake.url,
ListsGet = () =>
new Microsoft.SharePoint.Fakes.ShimSPListCollection()
{
ItemGetString = (listname) =>
new Microsoft.SharePoint.Fakes.ShimSPList()
{
ItemsGet = () =>
new Microsoft.SharePoint.Fakes.ShimSPListItemCollection()
{
// we have to fake the count, as we not returning a list SPListCollection
CountGet = () => 3,
ItemGetInt32 = (index) =>
new Microsoft.SharePoint.Fakes.ShimSPListItem()
{
TitleGet = () =>
string.Format("The Title {0}", index),
ItemGetString = (fieldname) =>
string.Format("email{0}@fake.url", index)
// note we don't check the field name
}
}
}
}
};

// act
// not actually doing an operation
// assert
var fakeWeb = fakeWebShim.Instance;
Assert.AreEqual("http://fake.url", fakeWeb.Url);
Assert.AreEqual(3, fakeWeb.Lists["fakelistname"].Items.Count);
Assert.AreEqual("The Title 0", fakeWeb.Lists["fakelistname"].Items[0].Title);
Assert.AreEqual("email0@fake.url", fakeWeb.Lists["fakelistname"].Items[0]["Email"]);
Assert.AreEqual("The Title 1", fakeWeb.Lists["fakelistname"].Items[1].Title);
Assert.AreEqual("email1@fake.url", fakeWeb.Lists["fakelistname"].Items[1]["Email"]); }

 

Comments

Which which do you find the most readable?

I guess it is down to familiarity really. You can see I end up using the same test asserts, so the logic I am testing is the same.

I do think the Typemock remains the easier to use. There is the gotcha I found with having to add extra references to allow the fakes to be create in the VS11 faking system, and just the simple fact of having to manually create the fakes in Visual Studio, as opposed to it just being handled behind the scenes by Typemock. There is also the issue of having to refer to the ShimSPWeb class and using the .Instance property as opposed to just using the SPWeb in Typemock.

The down side of Typemock is the cost and the need to have it installed on any development and build machines, neither an issue for the Microsoft fake system, the tests just being standard .NET code that can be wrappered in any unit testing fame work (and remember VS11’s Unit Test Explorer and TFS11 build allow you to use any testing framework not just MStest.

So which tool am I going to use? I think for now I will be staying with Typemock, but the VS11 faking system is well worth keeping an eye on.

[Updates 24 March 12 - More comments added in a second post]

Changed my phone to a Nokia

I swapped to a Nokia Lumia 800 yesterday from my LG E900, all very quick an easy after my experience last month.

My first impressions

  1. the on/off/volume buttons were better placed for a left hander on the LG, but I expect I will get used to that.
  2. the poor reception in my house was not the LGs fault – just a bad reception area
  3. the Nokia does seem faster