Here’s a photo I’ve uploaded taken with this lens to Flickr (Click on the image to see it on Flickr):
Tuesday, 25 August 2009
Sunday, 14 June 2009
Today I discovered how I can return the input on a Moq Mock object as the output. Let’s imagine we have an abstract class called (oddly) EchoInput:
public abstract class EchoInput
public abstract string SayIt(string input);
We wish to create a Mock object for this abstract class that returns the value of the input as the return value for the method SayIt. To do that we simply use an overload of the Moq Return’s method that allows us to specify a Func<> delegate that simply matches the signature of the method:
var testDouble = new Mock<EchoInput>();
testDouble.Setup(mock => (mock.SayIt(Moq.It.IsAny<string>()))).Returns((string input) => input);
If you don’t match up the parameters in the call to return you will simply get a “System.Reflection.TargetParameterCountException” at runtime. This would happen if you used the example below (deliberately incorrect code):
testDouble.Setup(mock => (mock.SayIt(Moq.It.IsAny<string>())))
.Returns((string input, int x) => input);
It is worth noting that the number of parameters need to match the method’s signature. It doesn’t matter what you call the parameters but for readability it is worth giving them the same names as the original parameters.
Monday, 25 May 2009
After reading lots about Windows 7 and how good it is supposed to be on laptops, I decided to take the plunge and upgrade my Thinkpad Z60m to Windows 7. Previously I had been running Windows XP on the laptop, as I don’t think it is that suitable for running Vista. Though Windows 7 has yet to be released, I had a copy of Windows 7 RC Ultimate and decided my laptop would be a good candidate for installing Microsoft’s latest desktop operating system.
As I don’t do anything overly important on my laptop I decided the upgrade wouldn’t be that much of a risk (I can always go back to XP if needed). To start off I decided to upgrade the machine from the base specification, by upgrading the memory to 2 GB of RAM from Crucial (the maximum RAM allowed in a Z60m) and upgrading the standard 100GB 5400 RPM hard drive to a better spec 7200 RPM, 320GB Seagate drive.
After installing the new RAM and hard drive, I proceeded to install Windows 7 from DVD. The installation was very quick and painless. Once installed I discovered the wireless wasn’t working out of the box and the screen resolution wasn’t right. After plugging in a CAT-5 cable, I downloaded the latest Microsoft updates, installed them and rebooted.
Once I had installed the updates the screen was displaying the correct resolution, and I could now use the wireless. I then decided to benchmark the system to get a performance score:
My overall score was 3.7, not bad considering the Z60m is now an old laptop (bear in mind these scores need to taken with a pinch of salt). It seems the new hard drive has a good performance score of 5.9, with the lowest scores being achieved from the Processor (Pentium M 2.0 GHz) and the graphics (ATI Mobility Radeon X600)- both with a score of 3.7.
Since installing Windows 7 it seems to be very stable for a RC. The only other software I have installed so far is MSN Messenger and Windows Live Writer. This blog post has been written using Windows Live Writer in Windows 7. With the ease of installation and strong hardware support following Windows Update, my first impressions of Windows 7 are resoundingly positive- I now just need to install some more software on the laptop.
Wednesday, 20 May 2009
Today my copy of Pro ASP.NET MVC Framework arrived from Amazon. I’m hoping this book will teach me how to become an expert at ASP.NET MVC. So far I’ve read the first introductory chapter and I must say I am very impressed.
It looks like you can view a sample chapter in PDF format for free from the Apress Web site.
Sunday, 17 May 2009
Several years ago (maybe 5 now) when I was studying for my MCSD.NET, I stumbled upon a site for MS 70-316, which contains lots of links to help study for the Microsoft 70-316 exam. Back then you had a lot of excellent books for these exams, like Amit Kalani’s study guides, which I thought were the best around at the time.
Roll on several years later I find myself studying for Microsoft 70-568. Currently there are no specific books for this exam. I’m not a fan of doing courses- I prefer reading and experimenting. So this post is my own lists of links and recommended books that a test candidate may find useful.
It turns out that the upgrade exams are a combination of 3 separate MCTS/MCPD exams (Scroll down to Gerry's comment on the prep guides).
Before starting your study for the upgrade exam, I recommend you do some background reading on what is new in .NET 3.5 for ADO.NET, Windows Forms and ASP.NET. Here are some links to get you started:
- What’s new in .NET Framework Version 3.5.
- What’s new in ASP.NET 3.5.
- What’s new in ASP.NET 3.5 (includes SP 1).
- What’s new in Data (LINQ etc).
- What’s new in Windows Forms for .NET framework 3.5.
This roughly ties up with the skills measured page (as of 17th May 2009) on the MS site (the tabs don’t seem to work in the version of Firefox I use, so it is probably best to use IE to visit this page). The majority of the links point to MSDN, with a few linking to some excellent articles that I found. Of course this information is not 100% complete and subject to my own interpretation of the requirements. You should supplement the missing sections with your own Google search/book reading.
- Configuring and Deploying Web Applications
- Providers (I love the provider model, hence why there are so many links):
- Provider Model Design Pattern and Specification, Part 1 (old but detailed).
- The ASP.NET 2.0 Provider Model. 136 pages- a tomb of Provider Model information.
- ProviderBase- the base class for all provider implementations.
- Don’t forget to add <clear/> when adding providers.
- Configuring Providers.
- Using the ASP.NET provider functionality in Windows based apps.
- Implementing a Membership Provider.
- Implementing a Role Provider.
- Examining Membership, Roles and Profile.
- SiteMap- can use the Site-Map Provider.
- Creating a custom site map provider.
- Profiles in ASP.NET.
- Implementing a Profile Provider.
- Creating a custom DB profile provider.
- Session State Providers.
- Implementing a Session-State Store Provider.
- Authentication etc
- I just read books for this section
- Session State and Session-State modes.
- Providers (I love the provider model, hence why there are so many links):
- Consuming and Creating Server Controls
- A great general comparison of controls.
- QuickStarts- data (.NET 2.0 but still handy as a refresher).
- QuickStarts- standard. (.NET 2.0 but still handy as a refresher).
- ListView- my personal favourite ASP.NET control.
- DataList- https://aspalliance.com/1007_Building_and_Using_a_LINQ_for_SQL_Class_Library_with_ASPNET_20.6
- TreeView- http://msdn.microsoft.com/en-us/library/e8z5184w.aspx
- @Register- http://msdn.microsoft.com/en-us/library/c76dd5k1.aspx
- Templated ASP.NET user control
- CompareValidator and here.
- Radio Button.
- MultiView and here.
- Working with data and services.
- Troubleshooting and debugging Web Applications.
- customErrors element.
- <compilation debug=”true”>.
- Compilation Element.
- ASP.NET AJAX debugging- scroll to section 2.4.6.
- Debugging and Tracing AJAX Applications overview.
- Health monitoring overview.
- How to send email for health monitoring notifications.
- Health monitoring in ASP.NET 2.0.
- Implementing health monitoring (Video).
- Simple health monitoring email example.
- Web events.
- How to use health monitoring in ASP.NET 2.0.
- Performance counters.
- Using perfmon.
- Working with ASP.NET AJAX and Client-Side Scripting
- The ScriptManager control.
- Web Services in ASP.NET AJAX.
- Client side Web service calls with AJAX extensions.
- Consuming Web Services from Client Script.
- Page methods and here.
- UpdateProgress and here.
- Timer Control.
- AJAX Client lifecycle events.
- Targeting mobile devices (odd choice considering VS.NET 2008 doesn’t have templates installed for it).
- Programming Web Applications
- Request- HttpRequest class
- HttpRequest Members
- Server- HttpServerUtility
- Application- HttpApplicationState
- Session- HttpSessionState
- Response- HttpResponse
- Accessibility improvements in ASP.NET 2.0
- Session State
- Application State
- Page Events
- Control Events
- Application Events:
- Session Events
- Cross Page Posting
- Creating a UI for a Windows Forms Application by Using Standard Controls
- Integrating Data in a Windows Forms Application
- DataGridView- replaces the functionality of the DataGrid in .NET 2.0+
- Databinding and Windows Forms
- Navigating data (binding source)
- DataConnector- assumes they mean BindingSource
- Transaction Class
- Relationships in Datasets
- Merging DataSet Contents
- Typed DataSets
- Using XML in a DataSet
- Loading a DataSet from XML
- Writing DataSet contents as XML data
- CommandBuilder- also see Weaning developers from the CommandBuilder
- DataAdapter Events
- Performing batch operations using DataAdapters
- Implementing Printing and Reporting Functionality in a Windows Forms Application
- Enhancing Usability
- Globalizing Windows Forms
- CultureInfo class
- MDI applications and menu merging for MDI applications
- Help systems in Windows Forms applications
- HelpProvider Class
- Tooltip component
- Popup Help
- PropertyGrid Class
- Which timer class to use
- Threading Timer
- Windows Forms Timer- single threaded, accuracy of 55ms
- Implementing Asynchronous Programming Techniques
- Deploying Windows Forms Controls
- Configuring and Deploying Applications
- ClickOnce Deployment for Windows Forms Applications
- System.Deployment.Application namespace
- Trusted Application Deployment Overview- using certificates instead of prompting users for elevation
- How to check for updates programmatically
- ClickOnce deployments on Vista
- Add icons during setup
- Set Conditional Installation Based on Operating System Versions
- Codes for the various OS versions
- Launch conditions
- Custom Action walkthrough
- Error Handling in Custom Actions
- Using caspol to modify the security policy
- Selecting and Querying Data
The official books
You might want to get the official MS Press books to help you study for this exam. I didn’t, as I choose to read non MS books instead- for that reason I don’t have an opinion of them. For completeness, these are what I believe to be the official MS Press books for the components that make up the exam:
- MCTS Self Paced Training Kit (Exam 70-562 – ASP.NET).
- MCTS Self-Paced Training Kit(Exam 70-505 - Windows Forms).
- MCTS Self-Paced Training Kit(Exam 70-561 - ADO.NET).
Unfortunately I can’t find any sample chapters for these books- from the reviews it looks like they may be useful for exam, particularly for candidates with little experience.
The books I used/think are useful
I read a lot of tech books in order to try and stay up-to-date with technology, so I didn’t read all of these books just to pass the exam. Also if like me you have access to O’Reilly Safari, then you can read some of these books on there.
- ASP.NET AJAX in action (this is a .NET 2.0 book but still mostly relevant). A very good book, but unfortunately out of date. I still found it very useful both for the exam and using ASP.NET AJAX. You also might want to consider Professional ASP.NET 3.5 AJAX, as this targets ASP.NET 3.5- I didn’t buy it, but if I was looking for a book now I would probably favour this one over the “in action” range, simple because it is out of date.
- Professional ASP.NET 3.5. This is a nice easy to read book on ASP.NET 3.5. It would probably be most useful for people who haven’t done much ASP.NET, but have some .NET experience.
- Essential ASP.NET 2.0. Brilliant chapter on Health Monitoring and Web events- the chapter is called Diagnostics. This book looks like it aimed at more experienced ASP.NET developers. I only read the chapter on diagnostics, but the rest of it looks interesting.
- Programming Microsoft ASP.NET 3.5. Good coverage of authorization and authentication.
- Programming ASP.NET 3.5, 4th edition. Another book with good coverage of authentication and impersonation.
- Pro LINQ: Language Integrated Query in C# 2008. This book got me up-to-speed with LINQ and was very useful for both the exam and my daily development tasks.
I didn’t use a Windows forms book to study for the exam, but I can recommend this one:
- Windows Forms 2.0 Programming (2nd Edition). There doesn’t seem to be any alternative to the MS-Press study books for Windows Forms 3.5- maybe authors are targeting WPF instead.
I didn’t buy any specific books on ADO.NET. However I know this framework exceptionally well, as it use it on virtually every project I work on. A book I found useful when upgrading to .NET 2.0 was:
A book that looks like it could be very good is “Professional ADO.NET 3.5”, though I’ve not read it myself.
- CLR via C#. This is the one book I recommend to any .NET programmer. For the exam it has an excellent chapter on performing asynchronous operations.
Of course you don’t have to use books at all (or you might not have the budget to buy books), in that case the next section is the most useful.
You don’t need to this stuff for the exam, but I stumbled across it whilst revising.
Completely off topic, but I found it interesting- distributed caching:
- MemCached. See Memcached Session State and Cache Providers for ASP.NET- I haven’t it but it looks interesting.
- Microsoft Velocity and Microsoft Project Code Name “Velocity”.
Other interesting stuff:
- Using health monitoring with log4net.
- Session wrapper- makes it more testable- designed for ASP.NET MVC:
Finally there is lots of useful programming information on Stackoverflow.
Tuesday, 21 April 2009
Sorry to disappoint- a non technical post!
Today the Top Gear team were in Canary Wharf and I managed to take some poor quality photos on my mobile- if only I had my SLR! Luckily I managed to make them a little better by using Photoshop Elements.
Clarkson inspecting a car:
Hammond and May inspecting a car:
The trio looking at the assembled crowd:
Clarkson asking the crowd if anyone is a banker:
It was amazing how many people “worked” for the FSA when Clarkson asked them this question!
Looks like someone else beat me to it putting pictures on the Internet.
Monday, 20 April 2009
Today a former co-worker asked me “what was that attribute we used to mark something as deprecated?” After a little pause for thought I remembered it was the ObsoleteAttribute- It’s a shame Microsoft hadn’t named this DeprecatedAttribute instead- this is what the annotation is called in Java.
I had previously used this attribute whilst in the middle of a large refactoring exercise on a project, where other developers were working on existing classes. It served as a useful reminder to start calling the new method, without breaking the build/their code/unit tests (we had a team culture where we would address warnings as soon as we noticed them). After all the consumer classes had been modified to use the new code, I searched for “Obsolete” in the code and discovered that the previous development team (the project was initially outsourced) had been using comments to mark code as deprecated- so perhaps not many people know about this useful attributes existence?
By default the attribute generates a compiler warning when a program element is referred to in a consumer class. This is the way I had used the attribute previously with a textual description describing how to correct the warning. Indeed a first glance at the documentation for the class (see here in the C# language specification, and here in the MSDN library) suggests this is all this attribute can do:
static void Main(string args)
[Obsolete("Use the BetterMethod instead")]
public static void ObsoleteOne()
Console.WriteLine("This is a bad method");
public static void BetterMethod()
Console.WriteLine("This is a better method");
Used in this manner, the attribute will caused a warning to be generated like so:
In our discussion on using the attribute my former co-worker pointed out that the attribute can also be used to create a compiler error, simply by changing the code to (notice the 2nd boolean parameter):
[Obsolete("Use the BetterMethod instead", true)]
public static void ObsoleteOne()
Console.WriteLine("This is a bad method");
This will result in a compiler error as follows:
In my project I didn’t use this- when references to the old code were removed, I simply removed the obsolete methods. In an API which you distribute to multiple consumers, you obviously don’t have that luxury, and I can see this overload being useful. It is important to remember that this attribute is useful for classes, structs, enums, constructors, properties, fields, events, interfaces or delegates as well as methods.
When deprecating it is important to suggest how developers using your code should fix the issue. For example if you use the deprecated class System.Web.Mail.MailMessage, you will receive the following useful compiler warning:
This tells the consumer that the method is obsolete, what the recommended alternative is and where to go to find further help- which unfortunately in this case seems to redirect to a generic .NET Framework page (woops)! I’m sure any competent developer can quickly work out that they should use System.Net.Mail.MailMessage instead though!