Monthly Archives: April 2011

Pluralsight Webcast: Agile Environments

On the 5th May, in collaboration with our partners Pluralsight, we will be doing a webcast on Agile environments:

– What exactly is an Agile environment

- Best practices for setting up environments with TeamCity, YouTrack and an OSS stack

This webcast is completely free and open to all. Please check out Pluralsight’s website for more information and registration information.

TechDays Belgium and The Netherlands

We’ve only just come back from Mix 11 and are already preparing things for the next great .NET events taking place in Europe: TechDays Belgium and DevDays The Netherlands.

 image image

With over 3.000 delegates registered, it’s cut out to be a blast. JetBrains will be at both events, which slightly overlap.

We will be giving away our Dead Code T-Shirts as well as some other surprise swag we have to give away. Please make sure you stop by our booths to chat.

I’ll be doing a session at each event, a Deep Dive into MVC 3 at TechDays Belgium and Real World Architectures with MVC at DevDays in The Netherlands. I’ll also be giving a short 30 minute talk at the Speaker Corner in the Expo area on the 27th of April at 12:30 on using ReSharper to be more productive with Web Development.

See you there!

Using dotCover to Cover Applications, with or without ReSharper

One of the main benefits of Code Coverage is that it allows us to detect certain areas, branches or lines of code that are not covered during a test run, which could lead to potential issues in production. We often write some code to find to our surprise that certain parts are never actually executed.

dotCover’s integration with ReSharper’s test runners, allows us to easily monitor what parts of our code are covered with tests. What happens though if we do not have tests? Whether we like it or not, there is a reality out there, and it’s mostly composed of legacy applications that have little to no knowledge of what a test is, let alone a unit test.

Although the ideal solution is to gradually add tests to existing code until we build up a good percentage of coverage, this is a process that takes time and is not accomplished overnight.

Covering Execution Paths

What dotCover allows us to do, independently of whether we have tests or not, is to execute an application and run an analysis report on what code paths of the application have actually been hit during the run. This often helps us track down not only potential issues (“I really thought that code was being executed”) but also resolve bugs (“Ah. So that’s why it’s not working”). Running Coverage of applications is a very simple process and does not even require ReSharper to be installed.

dotCover allows us to cover either an application that is currently open in a Visual Studio Project and selected as the Startup Application

 

image 

 

or alternatively launch a non-executing Application:

 

SNAGHTMLb0d87fd

 

And as we can see, it covers a wide variety of application types.

Covering an MVC Application

The example below outlines an execution path of the MVC Music Store application. We open the project and select Cover Startup Application from the dotCover menu. This immediately launches the application allowing us to execute a certain scenario. In our case, we will select some items and drop them in the cart.

 

image

 

When starting coverage, dotCover also launches the Controller Panel, which allows us to grab a snapshot of the execution at any point we are happy with it.

 

SNAGHTMLb47486f

 

On clicking on Get Snapshot, the execution ends and we are returned to Visual Studio, were dotCover analyses the results and displays the Coverage Results Browser window

 

SNAGHTMLb49c05c

 

From here on, the possibilities of what we can do with these results are pretty much inline with that of running Code Coverage on our tests. We can examine coverage of projects, namespaces, classes and members. Navigate to a specific member as well as see in-place code coverage in the editor:

 

image

 

Exporting Results

New to dotCover 1.1 is the ability to export results to different formats, including XML, HTML, JSON and XML for NDepend. To export to HTML for instance, we select the Export icon from the Coverage Browser Window

SNAGHTMLb4f1afa

 

and select a destination to save the output too.

image

 

Summary

Although the more common usage of dotCover and in general all coverage tools are examining coverage of our code by tests, it is also useful at time to be able to run coverage of an application during a specific scenario, for testing or diagnosis reasons. Whether or not we have ReSharper, dotCover allows us to do that easily. Also remember that dotCover ships with a Console application which does permit you to run coverage of your Unit Tests from the command line and open up the results in Visual Studio.

ReSharper 6 Enhances Razor Support

Previous posts introducing ReSharper 6:

 

Razor is the new View Engine introduced by Microsoft in ASP.NET MVC 3. If you have worked with ASPX View Engine, the default one up to version 2 of MVC, you’ll certainly appreciate the simplicity and ease of use of Razor. It makes the flow of HTML vs Code much easier to the eyes and to work with. In ReSharper 6, we are enhancing Razor support in Visual Studio by adding a series of features that will make it even better to work with.

 

 

Importing Namespaces

ReSharper 6 now automatically imports the specific namespace for your model:

 

Hitting Alt+Enter (QuickFix) will add the using statement

image

If you prefer to have a fully qualified name, that is:

image

you can change the setting under the Namespace Imports for C# under ReSharper Options (we are looking at the possibility of making this setting independent from general C# settings).

 

Creating from Usage

If a specific Model does not exist, ReSharper now allows you to create it from usage:

image

placing the Model automatically in the Models folder:

image

 

Helping with Sections

Razor has support for Sections. ReSharper enhances this support by providing Code Completion for Sections. The following shows a section defined in the _layout.cshtml file

image

We now get Code Completion for this section in any child page by typing @section

image

This provides us not only with Intellisense, but prevents us from making. If we were to type Footeer instead of Footer, ReSharper would highlight this error

image

Refactoring

Razor files are made up of code and HTML. As such, you also have Refactoring options that are applicable to both languages. For instance, the picture below depicts a refactoring of an HTML tag:

image

whereas the following is a Refactoring of some C# code

image

 

In fact, for ReSharper it doesn’t matter where your C# code starts and where your HTML ends. Just like Razor, ReSharper is capable of providing the correct contextual menus. The following is displayed when prompting the Refactor This menu (Shift+Ctrl+R) on the @text variable

image

 

ReSharper also knows how to handle situations where certain Razor constructs are required based on the outcome of a Refactoring option. Take the following code:

image

if we are to apply the Invert if refactoring, we would obtain:

image

where ReSharper conveniently places the @: which allows mixing of code and plain text.

 

Refactoring Helpers

Razor provides support for two types of Helpers, the classic Extension Methods that were available in the ASPX View Engine and Declarative Helpers, which are new to Razor. Declarative helpers are placed in the same file usually and avoid having to define an extension method or pre-post conversions. Given the following code:

image

 

we can invoke the Refactor This menu (by selecting the input tag line) and select Extract Helper:

 

image

ReSharper prompts us with the following dialog box:

 

image

 

resulting in the following refactoring

 

image

 

Currently Helpers are placed inline in the same Razor file, although we are looking at providing common helpers in App_Code folder as well as Extension Methods.

 

Navigation and Selection

Razor also now supports all the goodness of Navigation and other features of ReSharper such as Extend Selection (Ctrl+W). We can now navigate to and from Razor Views, go to Actions, Controllers:

 

image

as well as User Controls:

image

 

ReSharper Intellisense

We now get the full benefits of ReSharper Intellisense in Razor

image

with Razor-specific entries which allow for easy completion for constructs such as defining Models, Using or Flow statements. Similar to ASPX View Engine, we also get Intellisense for Actions, Controllers and User Controls:

image

and just like ASPX, we can also do Create From Usage:

image

 

On the Controller Side, ReSharper 6 now supports the built-in Scaffolding dialog for creating Views:

 

image

 

which allows us to have the QuickFix of Alt+Enter and take advantage of Visual Studio’s Scaffolding support.

 

Analysis

Last but not least, ReSharper wouldn’t be ReSharper without its in-depth analysis of source code. And Razor support wouldn’t be complete without it either. In ReSharper 6 we provide full analysis of Razor files, providing you with insight on errors, hints, warnings along with their associated QuickFixes:

 

image

along with full right-margin analysis of the file:

image

 

 

Summary

As you can see, Razor support in ReSharper 6 is pretty extensive, although it’s not entirely complete yet. We are still in Early Access Program and would love to hear your feedback, whether they are bug reports or suggestions on how to even make it better. Please download the EAP and play with it and report any issues you find on YouTrack

[IMPORTANT: Please note that some code snippets shown are neither endorsed or recommended. They are merely for demonstration purposes. Code in Views should usually be restricted to View Logic and Rendering]

Mix…Here we come!

We are going to MIX! image

As one of the premier Microsoft conferences focused on Web Technology, MIX is all about Web, and we are going to be there to show what we have in stock for Web Developers.

With the upcoming release of ReSharper 6, which adds support for JavaScript, CSS and HTML, as well as Razor View Engine, and of course our slew of Web Development IDE’s including WebStorm, PyCharm, PHPStorm and RubyMine, you can be pretty certain that there is something that suites you!

Stop by our booth. We’d love to meet you in person!

And as always, our Spending time with you program is open, so if you’d like to meet up at your offices, ping me

Webinar: Working with TeamCity, YouTrack and an OSS Stack

On Tuesday, 5th April 2011, I’ll be giving a webinar (in Spanish) on how to setup an environment with TeamCity, YouTrack and your favorite OSS tools and frameworks.

Things we’ll see:

  • TeamCity: Overview and benefits
  • YouTrack: Mouseless Web Issue Tracking
  • Introduction to Distributed Version Control Systems and benefits over Centralized
  • Creating Continuous Integration Processes with TeamCity and OSS stacks
  • Integration with Visual Studio and other IDE’s

The webinar will be roughly 2 hours and it will be mostly demo-centric.

It is a completely free event. If you’d like to attend, please register here