# Tag Archive for 'Tutorials'

September 27, 2011

### Running unit tests in Visual Studio 2011 and Windows 8 (WinRT)

This is a quick tip, because it confused me at first. But thanks to the always excellent Tim Heuer and Peter Provost (from the Visual Studio team), here is the answer:

Usual disclaimer: This is for XAML/C#. I am not sure how this works for the other programming stacks.

## Creating unit tests for your WinRT application/library

• Start Visual Studio 2011.
• Create a new project.
• From the Add New Project dialog, select Unit Test Library (In the Visual C#/Windows Metro Style category). Give a name to the project and press OK.
• Either open the unit test class that was created, or create a new class. No need to select a fancy template, just create a new empty class.
• Decorate the class with a [TestClass] attribute.
• Create a public method with no parameters, and decorate it with a [TestMethod] attribute.
• Right click on the unit test project and select Add Reference from the context menu.
• In the Reference Manager, select Solution and then the project you want to write tests for. Then press Add and then Close.

You can now write your tests, using the usual Assert syntax. Here is a simple example.

01.[TestClass]
02.public class UnitTest1
03.{
04.    [TestMethod]
05.    public void TestAlwaysPass()
06.    {
07.        const string expected = "Any text";
08.        var myClass = new ClassLibrary1.Class1(expected);
09.
10.        Assert.AreEqual(expected, myClass.Parameter);
11.    }
12.
13.    [TestMethod]
14.    public void TestAlwaysFail()
15.    {
16.        const string expected = "Any text";
17.        var myClass = new ClassLibrary1.Class1(expected);
18.
19.        const string notExpected = "Another text";
20.        Assert.AreEqual(notExpected, myClass.Parameter);
21.    }
22.}

## Running the unit tests

To run the unit tests you just wrote, follow the steps:

• Select the menu View / Other Windows / Unit Test Explorer.

Build your application. You should now see the unit tests you wrote in the explorer window.

Press Run All to run all the unit tests.

Hopefully this quick tip will be helpful!

Cheers

Laurent

August 3, 2011

### Simple Tips: Application Image Processing

A lot of people are familiar with the WriteableBitmapEx project on Codeplex. I got an opportunity to use it in a recent project of mine, and although many of its functions are very helpful, I noticed a couple common image processing functions it was missing. It supports resizable blits (with bilinear filtering), flips, and rotates, which are nice. More impressively, it supports arbitrary convolutions, which are very powerful and versatile in the image processing world. What it was missing, however, was the ability to perform a linear colorspace transform, and apply a color ramp lookup table.

Linear transforms in an image’s color space (RGB in the case of this implementation) can perform a variety of functions. They work by treating each pixel as a vector of color components, <R, G, B, A>. That vector is transformed by a 4×4 matrix, and the output vector represents the new color. To use this function, call

WriteableBitmapColorExtensions.TransformColors(Matrix3D matrix);

The matrix you supply determines how the color is transformed.  The alpha component in most images is usually 1, making the matrix usually affine, though the method does not give it special treatment, so you may get some… interesting… behavior with translucent images, depending on how you put your matrix together.

The WriteableBitmapColorExtensions class defines a few common ones:

NegativeTransform – Produces an image’s film negative

$latex \left( \begin{matrix}1&0&0&-1 \\ 0&1&0&-1 \\ 0&0&1&-1 \\ 0&0&0&1 \end{matrix} \right)$

BlackAndWhiteTransform – Transforms the image into black and white

$latex \left( \begin{matrix}0.30&0.30&0.30&0 \\ 0.59&0.59&0.59&0 \\ 0.11&0.11&0.11&0 \\ 0&0&0&1 \end{matrix} \right)$

SepiaTransform – Transform an image into sepia

$latex \left( \begin{matrix}0.393&0.349&0.272&0 \\ 0.769&0.686&0.534&0 \\ 0.189&0.168&0.131&0 \\ 0&0&0&1 \end{matrix} \right)$

What else can you do with it? You can try brightness changes:

$latex Brightness(B) = \left( \begin{matrix}B&0&0&0 \\ 0&B&0&0 \\ 0&0&B&0 \\ 0&0&0&1 \end{matrix} \right)$

Note you can vary the brightness of independent color components, if you like.

You can also desaturate an image by interpolating between the identity matrix and the black and white matrix. If your saturation level goes from 0 (black and white) to 1 (normal):

$latex Saturation(S)= Brightness(S) + BlackAndWhiteTransform * (1 – S)$

You can even do a hue shift. A hue shift basically rotates a color vector around the <1, 1, 1> axis:

HueShift(Degrees) = Matrix3D.Identity.Rotate(Degrees, new Vector3D(1,1,1))

The purists among us will note that this isn’t exactly right… to do a true hue shift you need to normalize the brightness of the color components first (you can use the Brightness(S) function above), but this gets the idea across. The sample image here uses a subtle rotation of 15 degrees.

Those are the ‘ordinary’ functions that a color transform can do, but you can stylize things as well.  For example, you can swap around or even turn off color components:

There are other interesting things you can do with TransformColors as well, such as skewing colors or projecting them onto a plane (or a line, creating a nice two-tone effect—this is essentially what the black and white matrix does). And remember the most powerful feature of linear transformations: you can take any or all of these effects, combine them into a single matrix, and apply all of them to an image at once without any additional performance hit.

The other function introduced into the library, which I will elaborate more on in my next post, is WriteableBitmapColorExtensions. RampColors. This method replaces all the colors in an image using a lookup table. This is useful for nonlinear things like gamma correction.  In fact, gamma correction is by far the most common application of this function, so I included a special method just for it, WriteableBitmapColorExtensions.AdjustGamma.

May 25, 2011

### @lbugnion Brings you Mango from the Trenches via galasoft

We’ve already posted some details about our Mango updates to the IMDb application, which were unveiled at MIX11.  Our own beloved Integrator, @lbugnion, dives into the steps that were taken to add a new Live Tile on Windows Phone 7 on his personal blog. You owe it to yourself to check out his insights if you are a software developer working with Windows Phone 7.

Here’s a taste:

Very important: The pictures used for the live tile must be 173×173 pixels PNG or JPG, and added to the project with the Build Action set to Content. To change this, select the images in the Solution Explorer, press F4 to display the Properties and then change the Build Action to Content, and the “Copy to Output Directory” property to “Copy if Newer”.

Visit Laurent’s blog to get the full story! If you’ve had a chance to work with the new Mango features and would like to share your story on the IdentityMine blog, let us know in the comments.

May 15, 2011

### Silverlight TV – Windows Phone Tips

Ever wonder how a list of images loads and scrolls in your Windows Phone application? Our Director of UX technology, Jobi Joy, joins John Papa on Silverlight TV to discuss how to handle image scenarios, as wells as how he gains extra performance in his applications. Jobi also has a blog post that explains exactly how this optimization works. Check out the video below

Did you find this post useful? Questions or Comments? We would love to hear from you!

April 13, 2011

### Deep Dive MVVM at #MIX11

IdentityMine Integrator and Microsoft MVP, Laurent Bugnion (@lbugnion) presented Deep Dive MVVM at MIX11 yesterday to a packed house.  The session was a follow up to Laurent’s MVVM presentation at MIX10 and was intended to answer some of the more common questions that Laurent received over the past year.

Laurent’s posted code samples from his presentation on his blog here.  Check it out and make a social application of your very own!

You can also see Laurent in an interview with Channel 9 today at 1:45pt.

Laurent Bugnion dives into MVVM

#ms_mix_e