13,897,185 members

#### Stats

37.8K views
11 bookmarked
Posted 11 Jan 2011
Licenced CPOL

# Catel - Part 4 of n: Unit testing with Catel

, 28 Jan 2011
This article explains how to write unit tests for MVVM using Catel.
 ```﻿// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2008 - 2011 Catel development team. All rights reserved. // // // Calculate the product of given value and factor in parameter. // // -------------------------------------------------------------------------------------------------------------------- using System; using System.Windows.Data; namespace Catel.Windows.Data.Converters { /// /// Calculate the product of given value and factor in parameter. /// #if !SILVERLIGHT [ValueConversion(typeof(int), typeof(int))] #endif public class MultiplyConverter : IValueConverter { /// /// Calulate the product of given value and factor in parameter. /// /// Base value. /// Not used, supports now int and double. /// Factor used for multiply (always double). /// Not used. /// Product of specified values. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { // Get typed value double typedValue = 0d; // Check input if (value is int) { typedValue = System.Convert.ToDouble((int)value); } else if (value is double) { typedValue = (double)value; } // Check value if (typedValue == 0d) { return 0d; } // Get factor double factor; if (!double.TryParse(parameter as string, out factor)) { return 0d; } // Multiply return typedValue * factor; } /// /// Calculate value back. /// /// Base value. /// Not used, supports now int and double. /// Factor used for multiply (always double). /// Not used. /// Original value. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { // Get typed value double typedValue = 0d; // Check input if (value is int) { typedValue = System.Convert.ToDouble((int)value); } else if (value is double) { typedValue = (double)value; } // Check value if (typedValue == 0d) { return 0d; } // Get factor double factor; if (!double.TryParse(parameter as string, out factor)) { return 0d; } // Divide return typedValue / factor; } } } ```

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

## Share

 Software Developer CatenaLogic Netherlands
I am Geert van Horrik, and I have studied Computer Science in the Netherlands.

I love to write software using .NET (especially the combination of WPF and C#). I am also the lead developer of Catel, an open-source application development framework for WPF, Silverlight, WP7 and WinRT with the focus on MVVM.

I have my own company since January 1st 2007, called CatenaLogic. This company develops commercial and non-commercial software.