Wednesday, February 10, 2010

Visual Studio 2010 RC public download available now!

Visual Studio 2010 RC public download available now!


Visual Studio 2010 RC public download available now!

Posted: 10 Feb 2010 09:16 AM PST

It's finally here.  Visual Studio 2010 and .Net 4.0 release candidate is available for everyone to download now. To download the public RC of Visual Studio 2010 go the RC landing page :  Since the beta we've been focused on performance improvements, reducing memory requirements, increasing stability and fixing customer reported bugs. Here are just a few of the tweets flying around about the RC: @CanadianJames #vs2010 is fast like ambulances flying through a school zone at 120 mph being chased by ninjas. and the ninjas are on fire! @ddotterer Trying out VS2010 RC: Snappier UI, much faster intellisense, significant build time reduction, etc. Overall: AWESOME JOB! #vs2010 #vs2010RC @alazlasse Testing #VS2010 RC performance: loading solution...(read more)

Trapping Intentional Cross Site Scripting (XSS) Attempts in ASP.NET

Posted: 10 Feb 2010 12:38 PM PST

So I'm building an ASP.NET application to host Podcasts and in the post submission logic I want folks to be able to submit markup, but not JavaScript. ASP.NET automatically traps suspicious posts to the server, but the results have to unfortunate defines. First is the ugly resulting page. We've all seen them. And the second is that I may want to be able to add some SPECIFIC logic to handling that Security exception because it probably means someone is intentionally trying to hack my web site. It turns out that this is another that ASP.NET makes easy to solve. First, add a Global.asax file to your solution and code the global Application_Error event handler as follows. 1: protected void Application_Error( object sender, EventArgs...(read more)

Visual Studio 2010 Release Candidate is Here

Posted: 10 Feb 2010 11:10 AM PST

Visual Studio 2010 and .NET Framework 4 mark the next generation of developer tools from Microsoft. Be sure to download the Release Candidate and let us know what you think.

This posting includes an audio/video/photo media file: Download Now

U.S. MSDN Premium Subscribers: Test and Develop at No Cost on Windows Azure

Posted: 08 Feb 2010 05:43 PM PST

As an MSDN Premium Subscriber, you can leverage your MSDN subscription to obtain over 700 hours of compute time on Windows Azure to test and develop your latest cloud applications. U.S. developers can also benefit from no-cost phone and e-mail technical support to help fast-track your cloud application development by using Front Runner for Windows Azure.

Using Silverlight Media Framework for simple playback

Posted: 10 Feb 2010 10:09 AM PST

If you aren't aware of the Silverlight Media Framework , you should take a look. This is a media playback framework for Silverlight that is based off of a lot of best practices from such implementations as the NBC Olympics, Sunday Night Football and others...( read more )...(read more)

The Misfit Geek Podcast on Zune Social

Posted: 10 Feb 2010 08:58 AM PST

Yes, the MisfitGeek Podcast still lives. I've recovered from a catastrophic audio hardware failure and learned how to record podcast interviews over Skype. I've got several scheduled and they should start appearing here soon. In the meantime I thought I'd share that that the Podcast is now listed on Zune Social. YOU can check it out on Zune Social [ HERE ]  If you have show suggestions for me PLEASE send them to me [ HERE ] Read More......(read more)

Silverlight Cream for February 10, 2010 -- #795

Posted: 10 Feb 2010 08:15 AM PST

In this Issue: Bruce Abernethy ( 2 ), Laurent Bugnion , and Jesse Liberty . Shoutouts: Robby Ingebretsen blogged Kaxaml Update + Downloads + A Request Shawn Wildermuth is getting ready to write a Silverlight book and is asking all of us to Help Me Figure...( read more )...(read more)

WCF and netTCP Binding in Silverlight 4

Posted: 10 Feb 2010 06:45 AM PST

Tomek has a fantastic post over here about the netTCP binding in Silverlight 4. I'm linking it so that I never lose it! :-)...( read more )...( read more )...(read more)

Silverlight & MEF Talk from the London Silverlight User Group

Posted: 10 Feb 2010 01:44 AM PST

Just a quick plug for a talk I gave last week at the London Silverlight User Group on the Managed Extensibility Framework in Silverlight 4. Ian Smith kindly recorded this with great skill and speed and has the video available if you click the picture...( read more )...(read more)

Building an interactive spider in Silverlight

Posted: 10 Feb 2010 01:29 AM PST

Introduction In this article we'll look at building a spider, which can load web pages and extract links. It will then allow the user to select which links it wants to retrieve, which adds more links to the list. It will look something like this: Building...( read more )...(read more)

Silverlight Test Driven Development – Part II

Posted: 09 Feb 2010 07:42 PM PST

        At the end of Test Driven Body Snatchers I promised to follow up with a walkthrough of real-world Test Driven Development. What gets into me?  Well, a promise is a promise.  Walking Through Test Driven Development...( read more )...(read more)

How to extend target file to include registry settings for web project package

Posted: 09 Feb 2010 05:13 PM PST

Web project package and deployment targets files are written with extensibility in mind.  User can easily extend a property to include more functionalities in their package by using msbuild targets and properties.  If we check the Microsoft.Web.Publishing.targets file under "%Program Files%\MSBuild\Microsoft\VisualStudio\v10.0\Web\", we can see the following, which means if file $(WebPublishPipelineProjectName).wpp.targets exists in the project directory, we'll import it automatically when build package or publish. <!-- *************************************************************** --> <!-- To allow the Team build to have custom setting for the Web Application project without change the project file --> <!-- by default...(read more)

Silverlight Test Driven Development – Part II

Posted: 09 Feb 2010 07:42 PM PST

MiniTutorialLogo

 

 

 

 

At the end of Test Driven Body Snatchers I promised to follow up with a walkthrough of real-world Test Driven Development. What gets into me? 

Well, a promise is a promise. 

Walking Through Test Driven Development

Waybackmachine3[1] The set up is this: We've designed the  Silverlight HyperVideo Platform using the MVVM pattern

We're going to take a trip in the way-back machine, and design  the ItemsViewModel class (the VM in MVVM)  using Test-Driven Development. 

 

Begin At The Beginning…

We start out by examining the existing ItemsView class (the V in MVVM ) which is implemented in ItemsView.xaml (and its code-behind):

<UserControl x:Class="SilverlightHVP.View.ItemsView"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"              mc:Ignorable="d"            d:DesignHeight="300"              d:DesignWidth="400">    <Grid x:Name="LayoutRoot" Background="White">       <ListBox Name="ItemsList"                Background="Beige"                Width="200"                Height="250"                HorizontalAlignment="Center"                VerticalAlignment="Top"                ItemsSource="{Binding Items}"                SelectedItem="{Binding CurrentItem, Mode=TwoWay}"                DisplayMemberPath="TextToDisplay">       </ListBox>     </Grid> </UserControl>

Designing the View Model

We are now ready to create the ItemsViewModel, which will serve as the data-context for the binding shown in the ListBox.

iStock_BoyWithBrainXSmall And here the world turns upside down. 

In the absence of test-driven development, I'd think about this a lot and make all sorts of decisions before writing a line of code. I'd decide, no doubt that the ItemsViewModel needs to provide a collection of Item objects to serve as the ItemsSource, and thus the Items property of the class would be a collection of Item objects. 

Since CurrentItem is bound to the SelectedItem, I'd try to figure out if that is a property with its backing value held in the ItemsViewModel or in, for example, the state object that is shared by all the ViewModel classes.

You can do all that, and you can make unit tests for it, but test-driven development works differently.  In TDD you make much smaller design decisions, write much smaller bits of code, and create a rapid cycle of three steps:

  1. Determine one key thing  you believe the ItemsViewModel class must provide and write a test asserting that it does provide that. Run that test. It will fail.
  2. Write just enough code in ItemsViewModel to make the test pass. No stop, just enough, no more. Good. Run the test again, it should pass.
  3. Repeat*
* Old joke: a programmer  was stuck in the shower because the shampoo bottle said "apply, lather, rinse, repeat."

 

The Discipline of TDD

Yes, it is infuriating to write the simplest thing when you believe you already know more. But a funny thing happens… you find that you are never lost, confused, befuddled or even in need of a debugger. You only did a little bit and the test either passes or it fails. If it fails, it is trivial to figure out what is wrong; after all you probably only wrote a couple lines of code.

Creating The Test in Visual Studio

HVPTests To get started, I'll add a project to the SilverlightHVP solution of type Test Project and I'll name it SilverlightHVP.Tests.

Visual Studio will add the project, add a file UnitTest1.cs and add two new files to the solution: Local.testsettings and TraceAndTestImpact.testsettings. It also adds a reference to Microsoft.VisualStudio.Quality.

Tools.UnitTestFramework. Once the project is added to the solution, I can right click on the new project and choose Add->NewTest, bringing up the Add New Test dialog box.  I recommend experimenting with each of the tests offered, but for now, I'll just  AddNewTest choose Basic Unit Test and name it ItemsViewModelUnitTests. 

Visual Studio will create the class and a first test method, and adorn each with the appropriate attributes.  Delete TestMethod1 and it is time to write (and name!) our first test method.

The First Test

So; what is the very least we think the ItemsViewModel must do? Let's return to the ViewModel and note that the ListBox.ItemsSource property is binding to a ItemsViewModel property named Items. 

A quick look at the Silverlight documentation reveals that the ListBox.ItemsSource property is of type IEnumerable. That is, a collection. We don't yet know what is in the collection, but we do know that the ItemsViewModel must have a property Items that returns an IEnumerable of something. Let's create a test for that.

So what is the test actually testing for? The minimum is that the Items property, an IEnumerable<object> (that is, an enumerable list of something) is not null.

Our naming convention is to identify the thing we are testing and what should be true. The name, therefore, is ItemsProperty_ShouldNotBeNull.

 [TestMethod]  public void ItemsProperty_ShouldNotBeNull()  {  }

Creating the body of the test requires testing the property of an ItemsViewModel instance; so the first line of the test will create the beast. 

CreateInstanceOfIVM

When we attempt to make an instance, we immediately get the feedback that something is amiss; no surprise; the class doesn't exist yet. Visual Studio is ever-helpful, however, and it offers to generate the classs for you. Let's have it do  that.  Hey! Presto! a new file ItemsViewModel.cs is generated in the test project. That's not where we'll want it, but for now it is just fine.

Our first test line no longer shows an error, and oh, by the way, creating this line was a forcing function on the design: we needed a class of type ItemsViewModel.   ItemsProperty Similarly, we now will attempt to retrieve the Items property as an enumerable, which of courses will generate both an error (no such property) and an offer to create the property for you.  Once again we'll let Visual Studio generate the needed stub.  With that, we can test that Items is not null:

TestFailed

Place your cursor on the name of the test method and press Control-R, T; this will run this one test and display the results in a window, as shown.

Our dreams and ambitions are fulfilled; the test failed as we expected it to!  Great.

(click on images for full size)

Making The Code Pass The Test

Now we write just enough code for the test to pass. Watch it! Just enough and no more.

 class ItemsViewModel  {     public IEnumerable<object> Items      {        get { return new List<Object>(); }        set { }     }  }  

Since I can't instantiate an interface, I chose a very simple class that implements IEnumerable. Notice that I've not populated the list; all I've done is write enough code to satisfy the test. This is pedantic, rigid, annoying and incredibly useful. The design emerges based on the needs, the needs are expressed by the tests, and the code never goes beyond the (thought through and tested) requirements. 

A real though not driving benefit is that the tests become both insurance and documentation; and unlike other documentation, as long as you "rigidly" make sure you run all the tests every time you make any change, the documentation never goes out of date.

The Second Test

At this point we know that we want more than for the property to be non-null; we want it to have items. Let's test for that:

 

      [TestMethod]       public void ItemsProperty_ShouldNotBeNull()       {          var itemsViewModel = new ItemsViewModel();          IEnumerable<object> items = itemsViewModel.Items;          Assert.IsNotNull( items );       }        [TestMethod]       public void ItemsProperty_ShouldReturnListOfObjects()       {          var itemsViewModel = new ItemsViewModel();          IEnumerable<object> items = itemsViewModel.Items;          Assert.AreNotEqual<int>( 0, items.Count<object>() );       }

Running Two Tests

You can run the second test just as you ran the first, but we really want to make sure that it is wicked easy to run all the tests every time. Click in the class, but not on either test, and press Ctrl-R, T.  This causes both tests to be run, and sure enough the first test (ShouldNotBeNull) passes, but the new test fails.

Once again, we write just enough code to make this pass.

 class ItemsViewModel  {     public IEnumerable<object> Items      {        get { return new List<Object>() { new Object() }; }        set { }     }  }

And running the tests again, both pass. And so it goes. Step by tiny step. 

Factor Out Common Code In Tests?

Most of you are probably starting to itch terribly, as you look at the two tests and note that the first two (of three!) lines are identical.  Yikes! Somebody factor that out, quick!

And we will, but before we do, let me note that this is not a given; in fact doing so is somewhat controversial.  First, how to do it, then the controversy.

[TestClass] public class ItemsViewModelTests {    private IEnumerable<object> items;    [TestInitialize]    public void ItemsProperty_SetUp()    {       var itemsViewModel = new ItemsViewModel();       items = itemsViewModel.Items;    }     [TestMethod]    public void ItemsProperty_ShouldNotBeNull()    {       Assert.IsNotNull( items );    }     [TestMethod]    public void ItemsProperty_ShouldReturnListOfObjects()    {       Assert.AreNotEqual<int>( 0, items.Count<object>() );    }     [TestCleanup]    public void ItemsProperty_CleanUp()    {       items = null;    } }

The trick here is that the testing framework will run each test in the following sequence:

  • If there is a method marked [TestInitialize] run that first
  • Run the test method
  • If there is a method marked [TestCleanup] run that last

The controversy is this: you do not want any dependencies between tests. It can never be allowed that running one test affects another. That is, for example, ShouldReturnListOfObjects should return the same results if it is run before or after ShouldNotBeNull or even if ShouldNotBeNull is not run at all.

One way to protect yourself is to have each test be fully self-contained. A second way is to ensure that CleanUp eliminates any side-effects. 

Or Not…

James Newkirk, one of the brighter lights in the field, author of nUnit and xUnit, explains in some detail why he opposes using Setup and Cleanup (TearDown) methods.

I've taken the liberty® of quoting one of the key paragraphs:

The problem that I have with SetUp in this case is twofold. The first and primary complaint is that when I am reading each test I have to glance up to BeforeTest() to see the values that are being used in the test. Worse yet if there was a TearDown method I would need to look in 3 methods. The second issue is that BeforeTest() initializes member variables for all 3 tests which complicates BeforeTest() and makes it violate the single responsibility pattern. 

Brad Wilson, Newkirk's partner in crime, elucidates four objections to the use of setup and teardown, which I summarize here,

  • You can't tell what the test is doing without looking at the setup, which can be far away in the file when you have a number of tests
  • If the setup or teardown throws an exception it can be very confusing as to what is wrong
  • There is only one setup and teardown per set of tests, and that presumes every test needs the same setup; a dangerous and misleading assumption that makes the test harder to understand.
  • It is too easy to have the setup code change the environment for tests run later in the series; breaking the rule that tests are independent.

==========

I am incredibly grateful to Abby Fichtner for helping me past the initial hurdles in Test Driven Development (though she may argue I'm not yet past them!). 

She recommended to me, and I recommend to you this excellent tutorial by Jason Olson from Channel 9 (where you can now watch Silverlight TV)

 

jessesig

This work is licensed under a Creative Commons license.

Visual Studio 2010 RC Feedback Channel for Web Tools

Posted: 09 Feb 2010 12:19 PM PST

As you probably heard the Visual Studio 2010 RC is currently available for MSDN subscribers! You can download it from here http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx . General public release is slated for Wed. The Web Development Tools Team has setup a DL that we would like you to use to send us direct feedback on anything web development related for this RC. The DL is: vsweb@microsoft.com Once you have had a chance to use the product please send us feedback on your overall experience with our product. The more details you can provide the better. Also, feel free to shoot us a mail if: You encounter a bug or issue. You have general feedback, suggestions or ideas on our web tools product. If you do encounter a bug please send us a clear...(read more)

Windows7 and Visual C++ Developer Resources

Posted: 09 Feb 2010 02:09 PM PST

Hi, I am Sridhar Madhugiri a Developer on the WinC++ team. I have worked in different areas of Visual C++ including Libraries, Code Gen and most recently on the IDE. In this blog entry, I will highlight development resources for new features in Windows 7. Integrating these features in your application can light up your application when run on Windows 7.

 

Application Experience. You can enhance the Application experience through the new features in Windows 7 by adding new input capabilities, new UI elements and animations, or using some of the new features in Taskbar and shell integration that improves discoverability and usability. MFC with VS2010 automatically allows your application to add some of these new features easily.

 

Direct 2D: Allows you to render your 2D graphics with higher visual quality and better performance.

Native Sensor API: Windows 7 exposes a native API for Sensors so you can easily integrate these devices into your native application.

 

Windows Web services API: Windows 7 exposes a native API for working with web services. These APIs allow integrating data from Web Services in native apps as well as writing web services in native code.

 

Above is a summary of the features. The following are good starting points to explore these and other APIs that are new to Windows 7.

 

1.       Windows Developer Center: As I started using MSDN to find information, the first place that seemed to come up often was the Windows Developer Center (http://msdn.microsoft.com/en-us/windows/dd433113.aspx). This is a good starting point to get a summary of the new features and trying to decide which features make sense to add to one's application. It has links to more detailed documentation for each of the features.

2.       Windows 7 for developers Blog: The next location I found very useful is this blog. A number of new features and their API's are discussed on this blog. http://windowsteamblog.com/blogs/developers/default.aspx

3.       Windows developers is now on Facebook: Become a fan and stay abreast of the latest news on the Windows platform. http://www.facebook.com/pages/Windows-Developers/275596740826

4.       Windows 7 Developer guide: http://code.msdn.microsoft.com/Win7DeveloperGuide

5.       MSDN: http://msdn.microsoft.com/en-us/default.aspx

6.       Visual C++ Development Center: Another useful resource to find out what is happening with VC++. http://msdn.microsoft.com/en-us/visualc/default.aspx

 

Of course you need the new SDK to get these new API's. VS 2010 should ship with the latest SDK but in the meantime you can get the latest version from http://msdn.microsoft.com/en-us/windows/bb980924.aspx. In addition to the SDK you can find a number of samples that illustrate using the new features.

 

I am looking forward to more and more apps that light up on Windows 7! If there is a specific area you need more information or details, feel free to post and I can research more information on the specific area and get back to you. Or we can address some of these topics in later blog posts.

Visual Studio 2010 and .NET Framework 4 Release Candidate available

Posted: 09 Feb 2010 01:35 PM PST

Some useful links: MSDN Download links ScottGu's blog post Quick FAQ on Visual Studio 2010 RC Release (February 2010) and Silverlight development by Tim Heuer Enjoy!...( read more )...(read more)

The Weekly Source Code 49 - SmallBasic is Fun, Simple, Powerful Programming for Kids and Adults

Posted: 09 Feb 2010 01:18 PM PST

While the boys are only 2 and 4, I'm always keeping an eye out on new ways to teach them programming. Certainly I hope they'll be more well-rounded and I and spend more time outside, but a even a basic background in programming and logic, I think, produces...( read more )...(read more)

No comments:

Post a Comment