Sunday 25 March 2012

The best of VS11 (Talk from Dev11 Launch)–Demos

Continuing on from my previous post on the best bits of Visual Studio 11, these are the demos that I showed as part of that talk.

Testing integration

As part of the new test runners integration, this demo shows how to run different testing frameworks easily within the same project. To show the testing frameworks in  Unit Test Manager windows, you will need to install the test runner and the nUnit test adapter via the Extension Manager or from the Visual Studio Gallery. br />Once these are installed when you build the application you will see the 3 different unit testing frameworks appearing in the Unit Test Manager pane.
Download the demo project.

OAuth and OpenID providers

One of the new features that appeared with WebMatrix 2 Beta Refresh  (now with added Unicorn sauce) and Web Pages 2 Beta are the OpenID and OAuth providers which allow you to build applications that support these systems such as Facebook, Twitter and Google logins.
Currently these are only available in ASP.NET WebPages but as part of the whole one ASP.NET concept these features will be released for ASP.NET MVC and WebForms later.
This project comes from the WebMatrix starter site. It shows how to use the Google, Twitter and Facebook logins.

Using Google OpenID

Google OpenID is one of the simplest providers to implement. In the _AppStart.cshtml file add the following after the WebSecurity.InitializeDatabaseConnection

In the Account/login.cshtml you can modify the social login section to look like
<section class="social" id="socialLoginForm">
<form method="post">
<h2>Use another service to log in.</h2>
<legend>Log in using another service</legend>
<input type="submit" name="provider" id="google" value="Google" title="Log in your Google account" />

Using Yahoo for OpenID is the same procedure

Using Twitter OAuth

Twitter OAuth requires you to create a Twitter application first because the Oauth provider requires a consumerKey and consumerSecret tokens.

Head over to the Twitter developers site and create a new app. If you are developing on localhost, Twitter may not accept this as a valid domain name so you can use the loopback address instead for the WebSite field in the new application creation.

Once you have your Twitter application setup just take note of the Consumer Key and Consumer Secret values.

Back to _AppStart.cshtml add the following
consumerKey: "",
consumerSecret: "");

Insert you own consumerKey and Secret and then add the new input in your socialLoginForm and viola Twitter login integration!

Download the sample

Maps Helper

The final demo of the day is using the new Maps feature. This one also comes with WebMatrix 2 Beta Refresh but you can use it in MVC or WebForms right now. You need the new v2 of Microsoft.Web.Helpers assembly. You can get this assembly from the Bakery starter site in WebMatrix 2 Beta or from conveniently from here

To add a Google map to your website is as simple as the following lines of code.
<section id="map">
<div style="margin-bottom: 5px; font-weight: bold;">UiS Stavanger</div>
@Maps.GetGoogleHtml("Kjell Arholmsgt. 41, 4036 Stavanger", zoom: 15)

The map types that are supported right now are Google, Bing, Yahoo and MapQuest.

Download the sample.

Some handy information

You can get more on the new features of Web Pages 2 Beta here. Some of the new features that are in Web Pages now, will appear in the other parts of ASP.NET in line with the one ASP.NET vision.

No comments: