Friday, May 31, 2013

LayoutIt!: A drag & drop interface builder for Bootstrap

Bootstrap is a great framework for building good looking and powerful websites. However in the hands of developers, most Bootstrap sites end up looking the same.

Enter LayoutIt!, a drag & drop interface builder that let you easily design your own sites by using the Bootstrap functionality.

image

It allows you to drag & drop your template together and download the required HTML, CSS, LESS and JavaScript afterwards.

image

Thursday, May 30, 2013

Microsoft Code Digger

Microsoft Research released their first extension for Visual Studio 2012: Code Digger.

Code Digger analyzes possible execution paths through your .NET code. The result is a table where each row shows a unique behavior of your code. The table helps you understand the behavior of the code, and it may also uncover hidden bugs.

Through the new context menu item "Generate Inputs / Outputs Table" in the Visual Studio editor, you can invoke Code Digger to analyze your code. Code Digger computes and displays input-output pairs. Code Digger systematically hunts for bugs, exceptions, and assertion failures.

You can also try the functionality online through Pex4Fun.

Remark: At the moment Code Digger only works on public .NET code that resides in Portable Class Libraries. This limits its usefulness at the moment.

Wednesday, May 29, 2013

Reporting Services error: Unable to load client print control

Last week, our users send us a bug report mentioning that they cannot print a reporting services report from the web browser.

image

We discovered that printing from the ASP.NET Report Viewer control requires a separate ActiveX to be installed. If you don’t have this ActiveX control installed and the users don’t have the rights to install the ActiveX control themselves, they end up with the following error message:

“Unable to load client print control”

image

The browser will ask you to install the required ActiveX control to solve this problem:

image

Remark: Because the printing is using an ActiveX control, you can only print Reporting Services reports from Internet Explorer. If you open the ASP.NET reportviewer in FireFox or Chrome, the print button will not be available.

Tuesday, May 28, 2013

Get rid of the ‘Missing XML comment for publicly visible type or member’ warning

For a long time, I had the (good?) habit to document all my public API’s. But keeping the documentation up-to-date has always been a long and boring task.

After a discussion with my fellow developers, I decided to stop adding documentation. Most developers said they don’t look at the documentation but just read the code or  have a look at my unit tests to understand what’s going on.

After removing all the documentation, I’m left with a long list of warnings inside my application complaining about ‘Missing XML comment for publicly visible type or member’

How to remove these warnings?

There are 2 ways to remove these warnings:

  • Turn off the comment generation:
    • Go to the Project properties(Right click on your project and choose Properties from the context menu)
    • Go to the Build tab
    • Uncheck the XML documentation file checkbox

image

    • Repeat this for every project in your solution
  • Disable the warning:
    • Go to the Project properties(Right click on your project and choose Properties from the context menu)
    • Go to the Build tab
    • Add 1591 to the Suppress warnings textbox

image

    • Repeat this for every project in your solution

Monday, May 27, 2013

Setting up sliding sessions in Windows Identity Foundation(WIF) 4.5

I talked about sliding sessions before. With the release of WIF 4.5, a lot of changes were introduced.

So to get sliding sessions working in .NET 4.5, replace the old implementation of the SessionSecurityTokenReceived method with the following:

Friday, May 24, 2013

PostMan: an easy-to-use REST client to test all your Web API’s

image

 

PostMan is a REST client available as a  Chrome application. It’s a very easy-to-use and developer friendly tool to test and try your Web API’s. You have lots of options to manipulate the request and it has integrated support for multiple authentication mechanisms. 

Download it here.

 
 
Features
  • Create requests quickly
    • Compact layout
    • HTTP requests with file upload support
    • Formatted API responses for JSON and XML
    • Open responses as an HTML file in a new window
    • HATEOAS support
    • Image previews
    • Request history
    • Basic and OAuth 1.0 helpers
    • Autocomplete for URL and header values
    • Key/value editors for adding parameters or header values. Works for URL parameters too.
    • Use environment variables to easily shift between settings. Great for testing production, staging or local setups.
    • Use Global variables for values which are common throughout APIs
    • Use the quick look feature to preview variables and their values before you use them
    • Keyboard shortcuts to maximize your productivity
  • Document and share APIs
    • Use collections to organize requests and share them quickly using URLs.
    • Document requests inside collections. You can even store entire HTML notes. Postman uses Bootstrap so you can use it too to style your notes.
    • Download and share collections with your team of developers.
  • Collections
    • Collections can be any group of requests. You can save any kind of request by clicking the 'Add to collection' button. While saving the request you can also add a name and a note. There is no limit on the size of the notes so it can be as detailed as possible. Collections can be downloaded and shared as a file.

Thursday, May 23, 2013

UnitTestIsolationException when using ReSharper

In a previous post I introduced the Microsoft Fakes framework. However when I tried to use this framework inside my tests, they always failed with the following message:

Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationException: UnitTestIsolation instrumentation failed to initialize. Please restart Visual Studio and rerun this test


 clip_image002

I discovered that it failed because I was running my tests through the ReSharper test plugin. When I used the Visual Studio Test runner instead, everything worked fine…

Anyone who knows how I can get this working using ReSharper?

Wednesday, May 22, 2013

Visual Studio 2012: Testing the untestable using Microsoft Fakes

Testing the untestable

To test your code in isolation, Mocking frameworks like RhinoMocks or Moq are an important tool in your toolbox. By using an isolation(mocking) tool, you can replace an existing object by a ‘fake’ implementation. Unfortunately these tools cannot help you solve everything. If your system is not designed with testing in mind, it can be very hard or even impossible to replace an existing implementation with a mock object. Let’s for example take DateTime.Now.  This is a static property on a static class, how are you going to replace this?

Let’s have a look how Microsoft Fakes, the isolation framework that Microsoft introduced in Visual Studio 2012.

Microsoft Fakes

Microsoft Fakes help you isolate the code you are testing by replacing other parts of the application with stubs or shims.

  • A stub replaces another class with a small substitute that implements the same interface. To use stubs, you have to design your application so that each component depends only on interfaces, and not on other components.So this is similar to the functionality that most other mocking frameworks offer.

  • A shim modifies the compiled code of your application at run time so that instead of making a specified method call, it runs the shim code that your test provides. Shims can be used to replace calls to assemblies that you cannot modify, such as .NET assemblies.(It is using the Moles Isolation Framework behind the scenes)

Fakes replace other components

So what does this mean? By using the ‘shims’ we can isolate any kind of functionality inside our .NET application, including non-virtual and static methods in sealed types. No longer we are limited to to interfaces or virtual methods to replace dependencies.

Remark: Using Shims has a performance impact on your tests because it will rewrite your code at run time.

How to use Microsoft Fakes?

Let’s walk through an example. In this sample I want to test the SmtpClient, preferably without sending real emails. Below you’ll find the MailService class I want to test. This class has a direct dependency on the SmtpClient making it hard to test:

The SmtpClient class lives in the System assembly. To create a shim for this class,  go to the Test Project, right-click on the System assembly in the references for the project, and choose “Add Fakes Assembly”:

image

This creates a System.fakes file within the project:

image

It also creates a Fakes folder containing a .fakes file for every fakes assembly we created:

image

Inside the System.fakes file, we can specify for which types a shim should be created(for some types, this is done by default):

Let’s now write our test. Start by creating the test method and specifying the ‘arrange’ part:

Now we continue by adding the ‘act’ and ‘assert’ part of our tests. Because we want to use shims, we’ll have to wrap our calls into a special ShimsContext. The Microsoft Fakes framework created a ShimSmtpClient in the System.Net.Mail.Fakes namespace. On this ShimSmtpClient, we can overwrite the SendMailMessage method of all SmtpClient implementations through the Action<SmtpClient,MailMessage> property available on the AllInstances property:

This naming convention is used for all shims you create in your test application.

Tuesday, May 21, 2013

Xamarin Objective Sharpie: a binding definition generator for third party Objective C libraries

Xamarin iOS allows you to consume a third-party Objective-C library. Before you had to use Xamarin.iOS's Binding Projects to create a C# binding to the native Objective-C libraries. Inside this Binding project you’ll find two files: ApiDefinition.cs and StructsAndEnums.cs.

The ApiDefinition.cs is where you will define the API contract, this is the file that describes how the underlying Objective-C API is projected into C#. The StructsAndEnums.cs file is the file where you will enter any definitions that are required by the interfaces and delegates.

To bind your library you will have to create C# interfaces and annotate these interfaces with attributes to map the C# interface to the corresponding Objective-C class. Although it’s not too hard to do this, expect a lot of work for a moderate size  Objective-C library.

To make this job easier, Xamarin introduced a new tool: Objective Sharpie, a very powerful binding definition generator for third party Objective C libraries to help provide APIs matching the .NET idioms.

“Objective Sharpie takes much of the manual work of translating Objective C APIs into binding definitions that are consumed by Xamarin’s binding tools. Download your third party library, point Objective Sharpie to its header files, and off you go.”

Monday, May 20, 2013

Nice quote

“There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies.”

- C.A.R. Hoare

Friday, May 17, 2013

Specify a CDN fallback when using ASP.NET Web Optimizations

One of the recommendations to improve your web application performance is to use a CDN(Content Delivery Network). This allows you to load common files(like for example jQuery) from the CDN server instead of your own. Extra advantage is that if the user already loaded the same script for another site, it’s still available in the browser cache.

But what if the CDN you’re using goes down? To fix this you can use a CDN fallback. For more details I recommend reading Scott Hanselmans post on the subject.

The ASP.NET team added a CDN fallback feature to the latest (prerelease) version of the ASP.NET Web Optimizations library. To use it, specify a CdnFallBackExpression.  This expression will be checked and if the expression fails, the fallback URL will be used(a local reference to jQuery in this sample):

Thursday, May 16, 2013

Team Foundation Server 2012: create a direct link to a work item

Team Foundation Server always allowed you to directly browse to a specific work item by calling a very specific URL. In Team Foundation Server 2012, this URL has changed to

http://tfsservername:8080/tfs/web/wi.aspx?pcguid={collectionguid}&id={workitemid}

Replace the {workitemid} part by the id of the work item and the {collectionguid} part by the GUID of your TFS collection.

How to get this collection GUID?

The easiest way to know the collection GUID(without querying the TFS configuration database directly) is to follow the steps below:

  • Open Team Explorer
  • Connect to the TFS collection you want to use
  • Open a work item in this collection(doesn’t matter which one)
  • Right click on the work item and choose Copy Full Path

image 

  • Paste the path into notepad and you’ll find the correct GUID

image

Wednesday, May 15, 2013

Entity Framework: Explicit Loading

One of the features that Entity Framework offers is Explicit Loading. This allows you to lazily load related entities, even with lazy loading disabled. The only difference is that you need a explicit call to do it(by using the Load method on the related entity’s entry):

But what if you want to filter the child results you get back. For example, imagine that you only want to know the female students in your class(no idea why you would want to know this Glimlach

Let’s try to change our code to do this:

However if we look at the results we get back, it still contains all students. To enable filtering when using explicit loading, you’ll have to make sure that LazyLoading is disabled. If we change the code to incorporate this, it will work as expected:

Tuesday, May 14, 2013

SQL Server: see which users are connected to your database

There are multiple ways to see which users are connected to your SQL Server database. Probably the easiest way is to use the built in stored procedure called sp_who2.

To use it, execute the following steps:

  • Open SQL Server Management Studio
  • Connect to the database server you want to monitor
  • Click on the New Query button to open the SQL editor
  • Paste the sp_who2 command in the SQL Editor

image

  • Click Execute

image

  • In the results window you’ll find a list of logins, database names, status, command, program name, CPU time, Login time and so on.

image

Monday, May 13, 2013

Team Foundation Server 2012: Work item link type end '' does not exist

After upgrading a customers TFS environment to Team Foundation Server 2012(Update 2), some minor issues were found. One of the more interesting issues was the following one:

When opening the Team Foundation Server Web Access, a specific work item query always failed with the following JavaScript error:

Work item link type end '' does not exist.TFS.WorkItemTracking.LinkTypeEndDoesNotExistException: Work item link type end '' does not exist.
   at findLinkTypeEnd (
http://servername:8080/tfs/_static/tfs/11/_scripts/TFS/TFS.WorkItemTracking.min.js?__loc=en-US:4:28677)
   at getColumnValue (http://servername:8080/tfs/_static/tfs/11/_scripts/TFS/TFS.WorkItemTracking.Controls.Query.min.js?__loc=en-US:4:30154)
   at getColumnText (http://servername:8080/tfs/_static/tfs/11/_scripts/TFS/TFS.UI.Controls.Grids.min.js?__loc=en-US:4:12128)
   at _drawCell (http://servername:8080/tfs/_static/tfs/11/_scripts/TFS/TFS.UI.Controls.Grids.min.js?__loc=en-US:4:10896)
   at _updateRow (http://servername:8080/tfs/_static/tfs/11/_scripts/TFS/TFS.UI.Controls.Grids.min.js?__loc=en-US:4:10331)
   at _updateRow (http://servername:8080/tfs/_static/tfs/11/_scripts/TFS/TFS.WorkItemTracking.Controls.Query.min.js?__loc=en-US:4:40857)
   at _drawRows (http://servername:8080/tfs/_static/tfs/11/_scripts/TFS/TFS.UI.Controls.Grids.min.js?__loc=en-US:4:8529)
   at _updateViewport (http://servername:8080/tfs/_static/tfs/11/_scripts/TFS/TFS.UI.Controls.Grids.min.js?__loc=en-US:4:30553)
   at _redraw (http://servername:8080/tfs/_static/tfs/11/_scripts/TFS/TFS.UI.Controls.Grids.min.js?__loc=en-US:4:32717)
   at redraw (http://servername:8080/tfs/_static/tfs/11/_scripts/TFS/TFS.UI.Controls.Grids.min.js?__loc=en-US:4:11986)

After this happens, everything else on the webpage starts to fail too and the only way to solve this is by doing a full page refresh.

The strange thing was that when opening the same work item query using Team Explorer, it just worked. This set me in the wrong direction because it made me think that the issue was related to the web access and not to the work item query itself.

But in the end I found it, the work item query was using the LinkType column which is not available in TFS 2012. To remove this column, execute the following steps:

  • Open the work item query
  • Go to Column Options
  • Select the column you want to remove from the Selected Columns list and click on the ‘<’ button to remove it.
  • Click OK to apply the changes

Friday, May 10, 2013

Useful PowerShell scripts for SharePoint

While converting and merging some SharePoint sites, I created some PowerShell scripts to speed up the process.

In case I’ll ever need them again, I post them here:

Script 1: Mount a Content database using PowerShell
Script 2: Generate a sub site using PowerShell
Script 3: Generate a Document Library using PowerShell
Script 4: Remove a site collection(without asking for confirmation) using PowerShell

Thursday, May 9, 2013

Generate SQL script from Entity Framework Migrations

By default when using Entity Framework Migrations, the Update-Database PowerShell script will immediately apply your changes to your target databases. But what if you just want to generate a SQL script (to give it to your DBA for example)?

To do this run the Update-Database command in the Package Manager Console but this time specify the –Script flag so that changes are written to a script rather than applied. Also specify a source and target migration to generate the script for.

Update-Database -Script -SourceMigration: $InitialDatabase 

Some remarks:

  • If you don’t specify a target migration, Migrations will use the latest migration as the target.
  • If you don't specify a source migrations, Migrations will use the current state of the database.
  • If you want to create a script from the initial state to the latest migration, use $InitialDatabase as the SourceMigration value.

Code First Migrations will run the migration pipeline but instead of actually applying the changes it will write them out to a .sql file for you. Once the script is generated, it is opened for you in Visual Studio:

image

Wednesday, May 8, 2013

SharePoint 2013: “You may be trying to access this site from a secured browser on the server. Please enable scripts and reload this page.”

When I tried to open a Microsoft SharePoint Server 2013 site, not much happened. Instead I got the following error message:

“You may be trying to access this site from a secured browser on the server. Please enable scripts and reload this page.”

To resolve this problem, enable the JavaScript feature in Internet Explorer. To do this, follow these steps:

  1. Open Internet Explorer, go to the SharePoint Server 2013 site, press Alt to reveal the Menu bar, click Tools, and then click Internet Options.
  2. On the Security tab, click Custom level.
  3. Scroll down to the Active scripting section, and then select Enable.

More details at http://support.microsoft.com/kb/2752584

Tuesday, May 7, 2013

Users can’t login after migrating to SharePoint 2013

After migrating our TFS SharePoint Portal to SharePoint 2013, our users started to complain that they couldn’t login. However when I took a look at the different site permissions, everything looked fine. All users were there as expected…

Why can’t users login?

This is caused by the new Claims based model in SharePoint 2013. In SharePoint 2010 you still had the choice between claims and the classic security model. in SharePoint 2013 this is no longer the case and therefore  you have to upgrade your users to their claims alternative. As long as you don’t do this, users will not be able to access your sites.

To fix this, open the SharePoint PowerShell command line and execute the following script:

Monday, May 6, 2013

Enterprise Library 6 finally arrived

After a long silence, Microsoft Patterns & Practices finally released Enterprise Library 6.

Main goals of the team for this release were:

  • Simplifying the library all around
  • Embracing semantic logging
  • Increasing resiliency to errors
  • Enhancing Unity type registration
  • Supporting Windows Store apps (Unity, Topaz)
  • Streamlining programmatic configuration of all blocks
  • Integrating with other technologies (ASP.NET MVC and ASP.NET Web API)
  • Improving ease of learning, ease of experimentation (fast start), and ease of use

This release introduces one new application block: the Semantic Logging Application Block. It also contains some updates for the other application blocks and introduces a new programmatic configuration model(in case you don’t like large XML configuration files).

This release also means the end of some of the existing application blocks:

  • Caching Application Block
  • Cryptography Application Block
  • Security Application Block

Here is a nice diagram showing all application blocks and their dependencies:

EntLib6

Go download it through NuGet or use  the self-extractable zip packages via Microsoft Download Center.