If a unit test connects to a database, interacts with the file system, reads a configuration file value, requests some data from a web service, it isn’t a unit test.
September 30, 2011
by admin
0 comments
September 30, 2011
by admin
0 comments
If a unit test connects to a database, interacts with the file system, reads a configuration file value, requests some data from a web service, it isn’t a unit test.
February 28, 2011
by shane
0 comments
If you’ve developed a .NET application, chances are you’ve used private methods in your design. Their inclusion brings about several advantages, but unit testing them isn’t immediately obvious. In fact, whether to unit test private methods at all is frequently debated, with opponents citing that they shouldn’t be considered because only a public interface is used in a real-world scenario.
I feel that private methods should be tested, because a core idea of unit testing is to test small units of functional code, which by definition, includes private methods.
Without question, private methods are trickier to unit test than public methods; at first glance, it isn’t obvious at all. Unit testing code is client code after all, and by definition, private methods aren’t visible. However, there are ways, and I present three of them here.
InternalsVisibleTo attributePrivateObject classJanuary 31, 2011
by shane
0 comments
A screenr screencast demonstrating the use of Optional and Named Parameters in C# 4.0 and Visual Studio 2010.
December 8, 2010
by shane
0 comments
In this screencast, I talk through the process of creating a simple custom debug visualizer to view a System.Drawing.Image image.
Essentially, the visualizer is a class library that references the Microsoft.VisualStudio.DebuggerVisualizers and System.Windows.Forms assemblies. The project has a class, ImageVisualizer, that inherits the .NET framework DialogDebuggerVisualizer class, and overrides its Show method:
class ImageVisualizer : DialogDebuggerVisualizer
{
protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
{
Image image = (Image)objectProvider.GetObject();
ImageForm form = new ImageForm { DebugImage = image };
windowService.ShowDialog(form);
}
}
This converts the variable that’s being debugged to an Image type using the objectProvider parameter’s GetObject method call. This is then assigned to the dialog’s DebugImage property, and the dialog is shown using the windowService parameter’s ShowDialog method.
The actual dialog is very simple indeed, comprising of just a PictureBox to show the image, and a close button to, well, close the dialog.
public Image DebugImage
{
set
{
this.pictureBoxImage.Image = value;
this.pictureBoxImage.SizeMode = PictureBoxSizeMode.Zoom;
}
get
{
return this.pictureBoxImage.Image;
}
}
The dialog class’ DebugImage property simply assigns the picture box’s Image property and zooms. I kept things simple for the screencast, but there’s no reason why the dialog couldn’t be extended to show other image properties such as image location, image type, and dimensions.
To use the visualizer, simply build the project and copy the dll to the Visualizers directory, which on my machine is:
C:Program Files (x86)Microsoft Visual Studio 10.0Common7PackagesDebuggerVisualizers
This particular path relates specifically to my machine, since I’m running 64 bit windows, and Visual Studio 10. Once the dll has been copied, it can be used on the next debug session. In the screencast, I use a simple console program example that loads an image from file. Clicking on the magnifying glass opens up the visualizer’s dialog, and the image can be seen.
March 31, 2009
by shane
0 comments
Since its release in early 2002, Microsoft’s ASP.NET platform has gone from strength to strength. Despite its strong uptake from Microsoft-centric software houses, there may be a few people who have hesitated in adopting ASP.NET for their web development platform. Here I present some things you might not know about ASP.NET. Perhaps it’ll encourage you to take a look at it.
There once was a time when the standard IDE for developing ASP.NET apps, Visual Studio, was prohibitively expensive for the average Joe. In late 2007, Microsoft released its first versions of ‘Express’ software, aimed at students and hobbyists. Though Express incarnations have fewer features than their full version cousins, they do offer the possibility of exploring ASP.NET. The Microsoft website offers a download page for Visual Web Developer 2008 Express Edition. An express version of SQL Server is also available, and can be downloaded from the SQL Server 2008 download page.
The MVC pattern is an established and well-recognised way of building web applications, and is familiar to RoR, Java and PHP developers. For many years, MVC was not available as a standard approach to developing ASP.NET websites, but Microsoft has recognised the deficiency and have (at the time of writing) released version 1.0 Release Candidate of ASP.NET MVC. The release has had a mixed response from the ASP.NET community, many of whom are used to the traditional code-behind model. Despite the inevitable squabbles as to which way is best, many have welcomed the MVC approach for its separation of concerns and finer control over JavaScript and markup. To find out more about the release candidate, head over to Scott Guthrie’s blog post.
A big advantage for anybody learning a new technology is the wealth of learning material that is available. Although you can rely on a large number of books, the ASP.NET learn website contains many videos on both traditional and MVC ASP.NET as well as data access.
The lightweight open source JavaScript library that’s taken the web by storm is now fully supported by Microsoft. As well as full intellisense support in Visual Studio, Microsoft will be using the library as-is, without forking or changing the code from the main jQuery branch. What’s more, Microsoft will be using jQuery as a basis for future ASP.NET and ASP.NET AJAX features. I feel this counters the argument of Microsoft not supporting open-source software.
Microsoft’s ubiquity means that learning ASP.NET and supporting technologies will do no harm to your career prospects. .NET skills are ranked as some of the most in-demand in the UK. Continue reading