Friday, June 28, 2013

[Visual C#] How to test your applications using the Fakes Framework (1/3)

As already mentioned on my blog multiple times, one of the ways of having good quality code is to use the Test Driven Development (TDD) approach. I have shown you how to apply the TDD using Visual Studio 2012 in a tutorial on my blog here.

When talking about TDD we have to talk about unit tests. Testing your code correctly can be very complicated sometimes and even nearly impossible to achieve. This is especially true for legacy code, which might not adhere to best practices such as loosely coupling and abstraction.

To help you with these kind of problems, Microsoft has created the Fakes Framework. It will aid you to create good unit tests for new code that you write (via Stubs) but also for legacy code (via Shims).

This blog series aims at presenting you the benefits of using the Fakes Framework. It can also be used as tutorial to start using it in your daily work.

What is a good unit test ? How to handle coupling to external sources ?

One of the main problems when writing unit tests is the dependency on external sources such as databases, external components, web services and even method calls within the same class.

For example, if you write a unit test that queries a database, how to handle data inconsistencies or database unavailability ? The unit test will fail in these cases, even if the code is implemented in an efficient and correct way ! This is due to the fact that the unit tests does not test the code in an atomic way, but instead it tests the code as well as all of its external dependencies. But conceiving and implementing atomic unit tests absolutely necessary to assure consistent and correct test results.

So how do we create unit tests that are independent from external sources ? We apply mocking ! This means replacing the real external sources by fake sources (also called Shims or Mocks) within your code. You do connect to the database anymore during your unit tests, for example. You substitute and mock the data objects (such as POCO, DataSet, DataTable, etc…) containing the database query results and your unit tests become decoupled.

We have solved one important problem, but we have added another since we need now to be able to create mock objects easily and quickly. Your unit tests will have better quality but if mock creation takes too much time it will have a negative impact on developer efficiency. The Fakes Framework allows for the automatic creation of mock objects, thus eliminating the cited problem.

What is the Fakes Framework ?

The Fakes Framework is the next generation of the Moles & Stubs project, which was created by Microsoft Research. Please note that the Moles & Stubs project is not supported in Visual Studio 2012 anymore, but you may very well use it in Visual Studio 2010 of course. The Fakes Framework is only included in Visual Studio 2012 Ultimate and you have to modify your existing Moles & Stubs code since it is not compatible out of the box. The basic functionalities are the same but nonetheless much has been improved and modified. The Moles are now called Shims for example !

By using the Fakes Framework development teams can create quickly and efficiently unit tests. Two different approaches are provided: Stubs and Shims.

Stubs are substitute objects that help to isolate the code that needs to be tested. To be able to use them correctly, you have to have loosely coupled classes in your code. This can be achieved by using interfaces for example. Stubs are very well adapted to new code.

Shims are very different, because they allow the interception of method calls during runtime. This allows mocking objects and function calls , which could normally not be done. Shims are very well adapted to legacy code.

Here is a comparison between Stubs and Shims and their provided functionalities:

Functionality

Stubs

Shims

Interception Mechanism

Virtual Methods

Runtime Instrumentation

Static Methods / Sealed

No

Yes

Internal Types

Yes

No

Private Methods

No

Yes

Static Constructor / Finalizers

No

Yes

Performance

Good

Low

Deployment

Xcopy

Installation

Abstract Methods

Yes

No


Share/Save/Bookmark

Thursday, June 27, 2013

[.NET 4.5.1 - C#] New features in the .NET 4.5.1 and Visual Studio 2013 Preview

The next version of the .NET Framework is .NET 4.5.1. It has been published as Preview version as announced yesterday during the BUILD conference. This blog posts aims to present what has been added, modified and improved in this new Framework version.

The .NET Framework 4.5.1 Preview is the first update of .NET Framework 4.5. It contains critical fixes, improvements, and opt-in features and is part of the Visual Studio 2013 and Windows 8.1 Previews. But it is also available as direct download without the requirement of having an existing .NET Framework 4.5 installation.

Visual Studio 2013 and .NET 4.5.1 language based improvements

The following language based improvements that have been added to the Visual Studio 2013 and .NET 4.5.1 Previews :

  • X64 edit and continue is now possible (with some restrictions, but now X86 and X64 are nearly handled the same, which is good news)
  • Async/Await debugging has been added (such as support in the Call Stack window, Tasks window, etc…)
  • Managed return value inspection has been added (in the Autos and Watch windows it allows for easier return value debugging)
  • Windows Store application development improvements (compatibility with Windows 8.1, Win RT improvements, etc…)
  • ADO.NET idle connection resiliency has been added (rebuild broken idle connections with SQL databases automatically and transparently)
  • ASP.NET application suspension has been added (Idle sites are suspended from CPU activity and are paged to disk)
  • On-demand large object heap compaction (instruct the Garbage Collector to compact the large object heap, as part of the natural GC or a forced GC)
  • Multi-core JIT improvements (support for dynamically loaded assemblies)
  • Consistent performance after .NET Framework updates (application startup performance will be more consistent after a .NET Framework update)

Installation of Visual Studio 2013 and .NET 4.5.1

The installation of the .NET 4.5.1 Preview can be done by installing the Visual Studio 2013 Preview in which case it will be automatically installed with the Visual Studio components. Note that it will replace existing .NET 4.5 installations since it is an in-place upgrade.

  • Download the ISO for Visual Studio 2013 Ultimate Preview from here (you may also install any of the other version available if needed).

image

  • After downloading the ISO, you may now start the installation. The installation will require a high amount of empty hard disk space (in my example 14GB !!).

Install VS 2013    Install VS 2013 2

You may also just install the in-place upgrade directly on your test server without the full Visual Studio development environment. You can download it from here.

You are now ready to start you evaluation of the new features within Visual Studio 2013 Preview and .NET 4.5.1 Preview !

Future language upgrades now also possible via NuGet

Future language updates will be shipped via upgrades and service packs as it is already done today. They will also be available via component specific NuGet packages. This allows for a maximum of flexibility concerning your upgrade strategy. If you do not want to wait until language upgrades are fully available, you may partially upgrade your language components via NuGet packages depending on your specific customer needs.

Furthermore, you can now retrieve NuGet packages for the .NET Framework 4.5.1 and above on Windows Update (it will not work for earlier versions of the .NET Framework). This provides are very easy and efficient way of getting the latest upgrades for the packages that you use. Note that upgrades will only be serviced for NuGet packages that are actually used by your applications.

Conclusion

The .NET 4.5.1 Preview Framework update provides some fixes and multiple  performance enhancements. There are no major language features, but nonetheless those upgrades become very handy and will allow for a more seamless and productive software development experience. I think that the next big language features that we can expect will be around Roslyn, when it will finally be finished and shipped as RTM version. But we will see !


Share/Save/Bookmark

[VS2013 - .NET 4.5.1] Preview of VS2013, TFS 2013, .NET 4.5.1 and Windows 8.1 annouced during Microsoft's BUILD conference

Yesterday during the BUILD conference in San Francisco one of the main major news was the announcement of multiple new product versions for you preferred development platform and operation system (Visual Studio 2013, Team Foundation Server 2013, .NET 4.5.1 and Windows 8.1). 

They are in Preview state and you can download them from here:

Those are preview version, which means that there is no support and that the final version could still be modified. In the past we have already seen that APIs have been changed and new functionalities been added to final versions.So you should use them for educational purpose only.

I have installed those versions in a VM to be able to test them and to give you some feedback on my blog. I am going to show you some of the new features in action in the next days/weeks. So stay tuned if you are interested in this topic.


Share/Save/Bookmark

Friday, May 17, 2013

[WinRT - Prism] Prism for Windows Runtime goes live !

This Friday 17th of Mai “Prism for Windows Runtime” is going live. This project is also known under the code name “Kona” by the patterns & practices team. It provides guidance on how to develop Windows Store Business Applications (basically Windows 8 applications).

It contains information on how to build loosely coupled, maintainable and testable applications based on the MVVM pattern for Windows Runtime (WinRT) with a focus on Line of Business (LoB) and Business to Consumer (BtC) applications.

Prism for Windows Runtime contents

  • A sample application “AdventureWorks Shopper” representing a real Windows Store application that you might find in the Windows Store. It has gone through the same approval processes all Windows Store applications have to go through.
  • This sample application demonstrates all the aspects of what Prism for Windows Runtime contains and how to apply them to your applications.
  • The Microsoft.Practices.Prism.StoreApps library, which contains code for implementing the MVVM pattern on WinRT. This means base classes, pages, ViewModels, a ViewModelLocator, application state management, validation, search and settings charms, etc...
  • The Microsoft.Practices.Prism.PubSubEvents library, which is basically the Prism 4.0 CompositePresentationEvent pub/sub events code moved to a Portable Class Library (PCL).
  • Quickstart examples and a thorough documentation

I was working on it together with Microsoft and the other members of the Developer Guidance Council in the lasts months, so I am happy to announce that it is available for the public now.

The release announcement on the blog can be found here:
http://blogs.msdn.com/b/blaine/archive/2013/05/18/just-released-prism-for-windows-runtime.aspx

The final resources (code, documentation, examples, etc…) can be found here:
http://code.msdn.microsoft.com/windowsapps/Prism-for-the-Windows-86b8fb72
http://msdn.microsoft.com/en-us/library/windows/apps/xx130643.aspx
http://www.microsoft.com/en-us/download/details.aspx?id=39042

The official CodePlex site can be found here :
https://prismwindowsruntime.codeplex.com

You can also find a Channel 9 webcast on the subject :
http://channel9.msdn.com/Shows/Visual-Studio-Toolbox/Prism-for-Windows-Store-Apps

There is also a Pluralsight course "Building Windows Store Business Apps with Prism" by Brian Noyes available here :
http://pluralsight.com/training/Courses/TableOfContents/building-windows-store-business-applications-prism

I will show you some examples in the next weeks if I get the time to prepare them for you. But if you can’t wait, just download the guidance from CodePlex and play with it. It is really easy to use and should give you all information necessary to build effective and robust Windows Store applications.


Share/Save/Bookmark

Monday, April 15, 2013

[C# and Win8] How to develop your first Modern UI application Part 3: Function declarations & Windows Store Deployment

In the last part we saw how to develop our first Windows 8 Modern UI application. I showed you how to create a very basic Image Viewer application. This part will show how to use system features (such as access to system resources or external devices) and how to deploy your applications via the Windows Store.

Application Manifest for Windows 8 Modern UI Applications

By default Modern UI applications do not have any access rights to system resources or external devices. You have to specifically allow and authorize those operations within the Application Manifest. In our example we had to edit the Package.appxmanifest file, as explained in the last blog post.

This declaration is especially important if you want to add your applications to the Windows Store. In fact, during the acceptance process, Microsoft verifies that the available functionalities are fully mentioned in your application description.

This is done to assure that everything is coherent, because Users need to know what access rights are required, if they want to install your applications from the Windows Store. Then they are able to decide if they want to download and buy your applications.

There are mainly two types of functionalities, for which access rights can be declared in the Application Manifest :

  • General functionalities : Media Files, Pictures Library, Removable Storage, Microphone, Webcam, Localization, Internet Connection, etc...

image

  • Advances functionalities : My Documents, Enterprise Authentication, Certificates, Share Targets, Background Tasks, etc...

image

You have to know that if you provide access to the advanced functionalities, then Microsoft will analyze your application in more details before your it can be made available on the Windows Store.

Windows Store Deployment

The Windows Store is the centralized and unique software distribution platform for Windows 8 applications. Customers find all sorts of Modern UI applications in the store. You can get more information here: http://www.windowsstore.com.

As already mentioned, applications are validated before they can be distributed via the store. This allows a high quality and controlled security access for all applications present on the store. There is a whole acceptance process, that each application has to comply on before it can be put on the Windows Store. It assures that applications work correctly, that they use only the accesses that are declared in the application description and that they comply to certain Modern UI design rules.

The validation is done by specialized Microsoft teams. It includes a thorough technical review, which aims at prohibiting malwares and viruses as well as unnecessary security accesses. Thus, a Windows Store customer may be confident to buy anything from the store without any risks of bad impact on his system.

Before you can distribute you applications on the store, you have to create a user account within the Dev Center for Windows Store Apps :  
http://msdn.microsoft.com/en-us/windows/apps.

The are two types of user accounts: individual accounts and enterprise accounts. You have to know that only enterprise accounts can submit applications using advanced functionalities.

After the account creation you are now able to submit your first application to the Windows Store via the the “Submit an App” button. Choose a name for you application, enter a meaningful description and apply for the technical review.

After Microsoft has validated and tested your application it will be available on the Windows Store. That’s it you are now ready to build you own Windows 8 Modern UI application and distribute on the Windows Store.


Share/Save/Bookmark

Monday, April 8, 2013

[MVP Nomination] Third year as MVP Visual C# !!!

I am proud to inform you that I was awarded Microsoft MVP Visual C# again 2013. This is the third year as MVP, but I am still very excited, happy and honored for being selected MVP !!!

image

I want to take some time and thank my MVP Lead for having me nominated.

Also a big thank you to Microsoft for putting their trust in me. I will do my best and continue sharing my knowledge with the community. So be prepared for many new blog posts and articles in the technical press on Software Architecture & Design, Visual C# and Windows Azure, which are my main interests. I will also continue concentrating on speaking at conferences so I would be glad to see you at any Microsoft events (TechDays, MS Days, etc…). This year I am also working on several books !

Stay tuned and continue following me if you like this Blog !


Share/Save/Bookmark

Tuesday, March 12, 2013

[Guide] Visual Studio Test Tooling Guidance
Better Unit Testing with Microsoft Fakes

The ALM Rangers have recently published a guide on their page “Visual Studio Test Tooling Guidance” with best practice on Unit Testing and the Microsoft Fakes Framework with thorough examples and Hands-On Labs called “v1.0 - Better Unit Testing with Microsoft Fakes”.

image

I really recommend looking into the guide since it contains a rich set of information on how to start using the Fakes Framework as well as how to use it in advanced scenarios.

And if you are already reviewing guides, please also take a look at all the other guides that are available on the site such as :

image

Happy reading and feel free to add comments with other guides that you find useful around software testing and especially the Microsoft Fakes Framework.

If you don’t know what the Microsoft Fakes Framework is, please stay tuned, since I am going to give you a first overview of its features and some examples in a future blog post series on this subject in the next weeks.


Share/Save/Bookmark

Friday, February 1, 2013

[Publication] Article in French Programmez Magazine on Fakes Framework with Visual Studio 2012

You can find an article of 4 pages on how use the Fakes Framework with Visual Studio 2012 in the French Programmez magazine No.160 written by Fathi Bellahcene and me.

First Page and Second Page (low resolution)

Third Page and Fourth Page (low resolution)

The article is written in French but as always I will write some English articles on my Blog in the next weeks. So stay tuned if you are interested in getting to know how the Fakes Framework can help you when you need to test your code (especially if you are keen on TDD).


Share/Save/Bookmark

Wednesday, January 23, 2013

[C# and Win8] How to develop your first Modern UI application
Part 2: Source Code & Development

In the last part we discussed how to create your first Modern UI project and all the prerequisites for being able to start its development. In this part you will actually see, what developing this type of application really means.

Development of the Image Viewer application

For this tutorial we are going to create an Image Viewer application. The goal of this example application will be to display all the images in your local Pictures Library. You may reuse the skeleton project, that we have created at the end of the last blog post and apply the following steps to it.

Add some code that gets data from your local Pictures Library and execute your application. A best practice in Modern UI applications is to always use an asynchronous approach, which is why we use the GetFilesAync() method and the await keyword in the following example :

CodePicturesLibrary

You will see that there is an exception of type “System.UnauthorizedAccessException” :

Exception

Modern UI application do not have any access rights by default, which is why you get an error message, when trying to access your local Pictures Library.

So as first step you have to allow access to your Pictures Library. To do this you just have to double-click on the “Package.appxmanifest” file in the Solution Explorer. Then go to the Capabilities section and enable the checkbox “Pictures Library”. Save your modifications and there should not be any error message anymore, when you execute your application.

Capabilities

In the next step, add a new class ImageItem to the solution and implement the following code :

ImageItem

This class will be instantiated for each picture in your local Pictures Library. It contains the picture itself, the picture name and a short description.

Add a GridView to the “MainPage.xaml” file, that is going to be used for displaying the pictures from the local Pictures Library :

GridView

Here is an example implementation of the whole code that could be implemented for the Image Viewer application in the “MainPage.xaml.cs” file :

Example

When executing the application, you will get a display of all the pictures that are currently stored in your local Pictures Library :

Fig9_Image_Viewer

If there are no pictures you will get a message that there were no pictures found :

NoPictures

This concludes this part. I am going to show you how to further configure your applications in more detail, as well as how to publish them in the next parts of the series.


Share/Save/Bookmark

[C# and Win8] How to develop your first Modern UI application
Part 1: Prerequisits & Project Creation

This tutorial is going to show you how to develop Modern UI applications (also called Metro-style applications). You will see the different steps such as creation and configuration of the project, the development using Visual Studio 2012 and its deployment on the Windows Store.

Modern UI applications can be developed using multiples languages. So if you are experienced in web development (HTML5/CSS3), .NET application development (XAML/C#, VB, or C++) or DirectX application development (C++), you already have the necessary skills to develop your first application.

Fig1_Presentation_Modern_UI

There are multiple display modes for Modern UI applications. You should know that by default they are border-less and full-screen (but you may change that).

Modern UI applications may currently only run on the Windows 8 and Windows 2012 operation systems. But they are running on all devices that are compatible with those operation systems (Desktop PCs, Laptops, Tablets, etc…).

Prerequisites for Modern UI applications

To be able to develop you first Modern UI application you have to have some prerequisites in place. Here are the technical requirements :

  • Windows 8 (Professional or Enterprise) / Windows Server 2012
  • Visual Studio 2012 (Professional or Ultimate)
  • Developer License (see below)

That is all ! After installation of those products you are now able to create your first Modern UI application project.

Project Creation

Start Visual Studio 2012, make sure that .NET Framework 4.5 is selected and click on “New Project” (you may also do this from the menu by clicking on “File” / “New” / “Project”). Create a new project of type “Blank App (XAML)”, which you may find under the “Windows Store” section.

Fig3_Creation_Nouveau_Projet

If this is the first time you have ever created a Modern UI application, you will not have a valid developer license for Windows 8. But this is really no problem, since you may ask for one for free.

You now have to connect yourself with a valid Windows Live account, then the system will present you with the following dialog. Just click on “I Agree” and the developer license will be downloaded to your system.

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDCTTWFYja5NvLW5iozWrjMqv_F6vB-wJuCP3y9PO6ThnGfaqLzqVrPq4uQCGmRhpkRutBbfGH7Xz5Ift053pPwwklb68XilLsJ0hmfAxutR14lxHH93NOUq-KEL80BDJKZE8TaepGsWolmKo/?imgmax=800

If you already had a license but it is not valid anymore (licenses are currently only valid during 1 month), then you have to renew it. For being able to develop Modern UI applications you have to have a valid developer license all the time.

The skeleton of your new application gets now generated. In the next parts of the series we will continue with the actual development of the application and see how to debug and in the end deploy it.


Share/Save/Bookmark

Wednesday, January 16, 2013

[Publication] New ".Net Framework 4.5 Expert Programming Cookbook" Book is now available in English

I am happy to announce, that the English book “.Net Framework 4.5 Expert Programming Cookbook”, which I have technically reviewed, is now available in the Packt Publishing online store. You may buy it as eBook and paper book.

If you are interested in .NET 4.5, this book is for you since it contains everything necessary for you to master this technology quickly. Examples and explications provide thorough information on all new features. I personally have reviewed all of the examples and I hope they will give you all insights you expect.

.Net Framework 4.5 Expert Programming Cookbook

Here is the table of contents (look under the “Table of Contents” tab):

Preface
Chapter 1: Core .NET Recipes
Chapter 2: Application Events and Windows Forms
Chapter 3: Threading and Parallel Programming
Chapter 4: ASP.NET Recipes – I
Chapter 5: ADO.NET Recipes
Chapter 6: WCF Recipes
Chapter 7: WPF Recipes
Chapter 8: ASP.NET Recipes – II
Chapter 9: Silverlight Recipes
Chapter 10: Entity Framework Recipes
Index

If you have bought and read it, please let me know what you think.


Share/Save/Bookmark

Tuesday, January 15, 2013

[Publication] New "WCF 4.5 Multi-Layer Services Development with Entity Framework" Book is now available in English

I am happy to announce, that the English book “WCF 4.5 Multi-Layer Services Development with Entity Framework”, which I have technically reviewed, is now available in the Packt Publishing online store. You may buy it as eBook and paper book.

If you are interested in .NET 4.5 and WCF 4.5, this book is for you since it contains everything necessary for you to master those technologies quickly. Examples and explications provide thorough information on all new features. I personally have reviewed all of the examples and I hope they will give you all insights you expect.

WCF 4.5 Multi-Layer Services Development with Entity Framework

Here is the table of contents (look under the “Table of Contents” tab):

Preface
Chapter 1: Web Services and Windows Communication Foundation
Chapter 2: Implementing a Basic HelloWorld WCF Service
Chapter 3: Hosting and Debugging the HelloWorld WCF Service
Chapter 4: Implementing a WCF Service in the Real World
Chapter 5: Adding Database Support and Exception Handling
Chapter 6: LINQ: Language Integrated Query
Chapter 7: LINQ to Entities: Basic Concepts and Features
Chapter 8: LINQ to Entities: Advanced Concepts and Features
Chapter 9: Applying LINQ to Entities to a WCF Service
Chapter 10: Distributed Transaction Support of WCF
Chapter 11: WCF Security
Chapter 12: Extending WCF Services
Index

If you have bought and read it, please let me know what you think.


Share/Save/Bookmark

Wednesday, January 9, 2013

[TechDays 2013] Cellenza will be animating some sessions during the next Techdays in Paris

The biggest and most important Microsoft event of the year in Europe is not far away ! TechDays 2013, planned for mid-February in Paris, will provide thorough information on all current and upcoming Microsoft technologies. Many new technology trends will be presented. A must for everyone who is working in the software development sector. And the best of all : It is for free !

Microsoft TechDays - 12, 13, 14 février 2013 au Palais des Congrès de Paris

Cellenza has the honor to present some sessions during this glorious event. Here are the sessions that we are currently preparing :

I will act as ATE (Ask The Expert) and will be happy to respond to any questions you might have concerning Microsoft products during the breaks in between the different sessions.

You will find me at one of the stands wearing a special shirt and I will be happy to exchange with you on any technical subject you might have.

Don't hesitate, inscribe yourself quickly. See you at TechDays 2013 !!!


Share/Save/Bookmark

[Webcast] Cellenza in MS France Visual Studio BonApp Show

Cellenza has published a very interesting French Webcast on the Microsoft France BonApp Website. The speakers are Michel Perfetti (Cellenza) and Olivier Conq (Mediapost) and the subject is around Visual Studio 2012, TFS 2012, Agility and Software Development.

They explain how Visual Studio 2012 and TFS 2012 can aid you to apply Agility in your projects by sharing their own real life experiences.

The Webcast is called “Visual Studio 2012, enfin !” and you can find it here (or just view it below) :

http://www.microsoft.com/france/visual-studio/bonapp/hub-emission.aspx?Uuid=e804d5a6-d3cb-4886-95a6-2fc6a34b4fe5

 


Share/Save/Bookmark

Sunday, December 2, 2012

[Event] Initiation of new Agile DotNet Association in France

We recently created a new association with the goal to promote Agile methods in the Microsoft environment in France. It is a non-profit association open to anyone who is interested in this absorbing subject. I am one of the founders and an active member of the association.

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVBKv8BJZhAtPgbnaiBPzHGrcQykdKAxCb8DgH8VRl1JWze8AGNXgsvx2xQMHrI-n9ykkve5FUGj8DeJ_Fm5e-A_z_wFar8XY_Cmqw3y9u0hdNouhzm42lfSU7k4R-QGN9t6Gwcy9swFk/s259/agiledotnetfrance.png

Next Monday 3rd of December 2012 will be a the initiation of this new association with the help of our first sponsors (Microsoft, Axones, Ineat Conseil, D-Cube, Cellenza). I am sure that other sponsors will join us soon !

The initiation will take place at the Microsoft Conference Center in France in Paris. Jeff Sutherland, Creator of Scrum and sponsor of the association, has accepted to come and to help us in promoting the association. He will honor us with his presence and he will be available for questions during the evening !!!

The agenda will be as follows:

18:30:
Reception and Welcome

18:45:
Presentation of the Agile DotNetFrance association by its president Arnaud Hego (Cellenza)

19:00:
Presentation of the Agile & Microsoft ecosystem by Benoit Launay (Microsoft)

19:15:
Keynote by Jeff Sutherland, Creator of Scrum and sponsor of the Agile DotNet France association

20:15:
Cocktail

So if you live around Paris and are able to come, I hope to see you see there. We already have more than 250 registered visitors, so I think that this will be a quite interesting event !


Share/Save/Bookmark

Wednesday, November 14, 2012

[Information] New adventure begins ! Cellenza here I come !

Just a quick note to inform you that I am leaving Capgemini Sogeti to work for Cellenza as CTO. This is going to be quite an adventure and I thank Cellenza in trusting me with this high responsibility.

logo-cellenza

You will see much activity around Cellenza in the next weeks. I am glad to announce that there are some very bright and intelligent people that I am going to work with. Also we are hiring so please contact me if you are interested in joining us !


Share/Save/Bookmark

Monday, November 5, 2012

[Publication] Article in French Programmez Magazine on Portable Class Library with Visual Studio 2012

You can find an article of 3 pages on how to use the Portable Class Library (PCL) with Visual Studio 2012 in the French Programmez magazine No.157 written by me and Fathi Bellahcene.

00001

First Page and Second Page (low resolution)

Third Page (low resolution)

The article is written in French, but this time I have already written a blog post in English on how to use the PCL with Visual Studio 2012 on my blog, which you can find here.


Share/Save/Bookmark

Thursday, October 25, 2012

[Tutorial] Test Driven Development with Visual Studio 2012
Part4: Full cycle of TDD using Visual Studio 2012

The last blog post in the series introduced some of the new features within Visual Studio 2012, applicable to Test Driven Development (TDD). This blog post is going to show you how to practically use all of those new features and apply them to Test Driven Development. You are going to see a full cycle of TDD using Visual Studio 2012, during the implementation of a simple calculator example!

Phase 1: Write a unit test for a new functionality  

Respecting the Test Driven Development approach, you have to create your unit tests before starting with any implementations. In our example we have to write some unit tests for the methods “Addition” and “Multiplication”. But first of all, we have to add a project of type “Unit Test Project” to our solution (if you do not already have one).

Fig8_UniTestProject

You may now add the necessary unit tests.Here is an example of the unit tests you could add based on the unit test framework NUnit:

Tdd_Code

Please note that the “Calculator” class and its methods “Addition” and “Multiplication” do not exist at this stage yet.

Visual Studio 2012 provides the possibility to generate the missing code in an automatic way. For that you just have to right-click on the “new Calculator” definition in the unit test project and choose to generate the class via the “Generate/New Type“ option in the menu.

Fig9_GenerateType

A wizard opens and you are now able to configure multiple options such as the type (classe, struct, interface, enum), the access (public, internal), the destination project and the file name for the generation of the missing class.

Fig10_NewType

The next step, after having auto-generated the “Calculator” class, consists of auto-generating the missing methods within this class. This can be achieved in almost the same way as it was done for the missing class. You do a right-click on the method calls "calculator.Addition(…)” and “calculator.Multiplication(…)” in the unit test project and you generate them via the “Generate/Method Stub” option in the menu.

Here is the auto-generated source code of those two methods:

Autogenerated

In the last step of this phase you have to open the “Test Explorer” window where you may now execute all your unit tests. This can be done by clicking on the “RunAll” button or by using the already explained “Post Build Test Runs” option (see the previous blog post in the series).

As expected your unit tests will fail, since the corresponding source code has not been implemented yet. We will see how to do that in the next phase.

Fig11_FailedTests

Phase 2: Implement the minimum code necessary to pass the test

Now in this phase, the only thing that needs to be done, is to implement the expected functionalities. The idea is to develop the minimum code necessary, which responds to the functional requirements. Everything that concerns optimization and amelioration must not be addressed since it will be treated later in the next phase (refactoring).

Modified

Following the implementation you may now restart your unit tests by clicking on the “RunAll” button or by using the already explained “Post Build Test Runs” option (see the previous blog post in the series). Your should see that you unit tests have been terminated successfully. If this is not the case you have to review your code and iterate until all of your unit tests pass successfully.

Fig12_PassedTests

At this stage the source code corresponds exactly to the functional needs and it provides the expected behavior. The final project structure includes a unit test project as well as an application implementation project.

Fig13_SolutionExplorer

But the source code might not be optimized. Its quality might not adhere to your quality standards, so it has to be ameliorate. The refactoring can be done without any problems since the unit test assure that there are no regressions. Moreover, regressions can be detected very quickly and thus can be handled as soon as possible. This is going to be explained in the next phase.

Phase 3: Refactor and optimize the source code

The process of improving your source code after the initial implementation phase (Phase 2)  is called “Refactoring”. The source code structure is modified internally without any modifications to the external behavior (very important!!). A source code that just “works” is now transformed into a source code that works in an optimal way. Most of the time, the resulting source code is executing with better performance, using less memory and/or with a better software design.

The refactoring consists of the following steps (non-exhaustive list):

  • Detect and eliminate all code duplication
  • Limit complexity and the number of classes
  • Simplify and optimize method algorithms
  • Relocate, rename and harmonize methods
  • Improve code readability
  • Remove not used code (also called “dead code”)
  • Add comments to complex code sections

In our simple example there is nothing to be refactored, since there are neither enough methods nor enough classes. But this last step has to be done in bigger developments at the end of each cycle. Afterwards, a new development cycle starts with  new functionalities from Phase1 on.


Share/Save/Bookmark

Wednesday, October 24, 2012

[Tutorial] Test Driven Development with Visual Studio 2012
Part3: New features in Visual Studio 2012 (2/2)

The last blog post in the series introduced some of the new features within Visual Studio 2012, applicable to Test Driven Development (TDD). This blog post is going to continue to further present some more features of Visual Studio 2012 in this domain.

Management of unit tests via Test Explorer

The first impression when opening the “Test Explorer” window is a very positive one. Here are the principal changes when compared to Visual Studio 2010:

  • The “Test View” and “Test Results” windows have been deleted and consolidated into the “Test Explorer” window. This is going to streamline the interaction between development (the code) and tests.
  • The interface is simple but efficient: all information is accessible via a simple mouse click in a very intuitive way.
  • Unit tests are grouped by their status (failed, passed,…), failed tests are shown on top, a double mouse click allows for accessing the code source of a test (no need to open an external window anymore).
  • It is now much easier to execute a code coverage analysis. In previous versions this was not handled in a very intuitive way, since you had to create a configuration file, start the analysis via the Visual Studio menu and then open the adequate results window. In Visual Studio 2012 everything was consolidated and is now integrated in the “Test Explorer” interface.

Post Build Test Runs

A best practice when adhering to TDD principles is to execute unit tests as soon and as much as possible for being able to identify bugs, misbehaviors and regressions. There is a new feature, called “Post Build Test Runs”, in Visual Studio 2012, which allows for automatically unit test execution after each compilation. The feature can either be activated via the menu under “Test/Test Settings” or directly from within the “Test Explorer” window. When using this features, unit test are executed on a separated and dedicated thread, so there is no impact on developer efficiency.

Fig7_RunTestsAfterBuild

Migration of unit tests from Visual Studio 2010 to Visual Studio 2012

As you might know, there a multiple difficulties and bugs, when migrating unit tests from Visual Studio 2008 to Visual Studio 2010, because the migration is not very transparent and sometimes even somewhat complex. In some cases you even have to migrate to the .NET 4.0 Framework to make everything work correctly!

I can assure you that there are no such migration problems, when trying to migrate from Visual Studio 2010 to Visual Studio 2012. This is partly due to the fact that most of the unit test components are the same between those two versions of Visual Studio. The library is still Microsoft.VisualStudio.QualityTools.unitTestFramework.dll in its version 10.0.0.0, which is still based on .NET runtime v2.0.50727.

Fakes Framework (Stubs and Shims)

The “Fakes Framework” based on the  “Moles” project, created by the Microsoft Research team, is now exclusively integrated into the “Ultimate” version of Visual Studio 2012 (and sadly only in this version!).

The goal of this framework is to aid development teams in producing unit tests rapidly and easily. For this, the “Fakes Framework” adds 2 notions:

  • Stubs: they provide automatic mock implementations of interfaces or abstract classes, that can be used in unit tests for being able to isolate parts that need to be unit tested.
  • Shims: they allow for runtime interception and redirection of method calls to specific objects. For example , they may be used to mock objects, which normally can’t be mocked due to access restrictions in the .NET framework. By using Shims it is possible to redirect calls to these objects with calls to objects that provide your own implementations.

There are however some restrictions. One restriction is that classes included in the “mscorlib” namespace cannot have any “Fake Assemblies”. Unfortunately, you cannot create any Shims for the “System.Configuration.ConfigurationManager” class for example.

The “Fakes Framework” provides some real advantages, when compared to existing mock testing frameworks such as RhinoMock, because developers do not need to modify their functional code for being able to execute unit tests.

In my next blog post I am going to show you how to practically use all of those new features and apply them to Test Driven Development. You are going to see a full cycle of TDD using Visual Studio 2012 !


Share/Save/Bookmark

Wednesday, October 17, 2012

[Tutorial] Test Driven Development with Visual Studio 2012
Part2: New features in Visual Studio 2012 (1/2)

The last blog post in the series introduced Test Driven Development (TDD). This blog post is going to talk about some of the new features in Visual Studio 2012, that allow you to successfully apply the TDD approach in your daily work.

Visual Studio 2012 external test framework support

The previous version Visual Studio 2010 already provides the possibility of using external test frameworks. But unfortunately with multiple limitations such as:

  • Dependency on third party applications for being able to execute unit tests. For example Gallio needs Icarus Runner if you want to run your unit tests.
  • Code coverage analysis does not work natively, only by using third party products (such as NCover for example).
  • Execution of unit tests is specific to certain plugins : for example there is a difference if you run your MSTest unit tests from within Visual Studio 2008 or by using Resharper, which may result in problems when trying to apply continuous integration processes.

As you can see, you have to multiply plugins and tools, that might not always be compatible with each other, when using Visual Studio 2010 with external test frameworks. Really not an optimal situation, when you want to benefit from specialized external test frameworks and their advanced functionalities !

One of the major updates of Visual Studio 2012 is the support of several external unit test frameworks for multiple languages without any of the limitations mentioned above.

Here are some of the unit test frameworks that you can now use easily:

For .NET :

For Javascript/HTML :

For C++ :

How to use NUnit as external test unit framework 

Lets see how to use NUnit as external test unit framework. First you have to install NUnit (currently as Prerelease) via NuGet.

Fig2_NUnit

Then you have to install the test adapter plugin for NUnit (currently as Beta) via the Extension Manager, which you can now find under “Tools/Extensions and Updates…”. Note that all test adapters are free of charge and that the functionality to search and download those adapters is fully integrated in Visual Studio 2012.

Fig4_Menu

Fig3_Extensions

After installing the NUnit test adapter plugin, you are able to use all Visual Studio 2012 unit test functionalities together with NUnit. You may for example execute your NUnit unit tests directly from within the Visual Studio 2012 IDE, display the test results in the standard view “Test Explorer” and run a code coverage analysis on your code.

Fig5_CodeCoverage

Support for C++ in native MSTest

Another big feature of Visual Studio 2012 is that it now supports native MSTest unit tests for C++ applications. Good news for C++ developers, who may now also apply Test Driven Development using native MSTest as unit test framework.

Fig6_NativeUnitTestProject

Following is an example implementation of a unit test in Visual C++ using the native MSTest unit test framework:

image

Support for async and await in VS 2012 and its unit test framework

Windows 8 and .NET 4.5 introduce a major feature that will have a high impact on software development as we know it: Asynchronous Programming. Visual Studio 2012 and its unit test framework support this new approach perfectly. The async and await keywords, available in .NET 4.5, may now be used for creating unit tests of asynchronous methods.

Lets say that you want to create a unit test for the following asynchronous example method:

16-Oct-12 16-49-01

The corresponding NUnit test method could be:

16-Oct-12 17-09-08

In my next blog post I am going to further show you other new features of Visual Studio 2012, which will make your life easier when trying to apply Test Driven Development.


Share/Save/Bookmark