Click here to Skip to main content
15,881,687 members
Articles / Desktop Programming / WPF

Catel - Part 4 of n: Unit testing with Catel

Rate me:
Please Sign up or sign in to vote.
4.55/5 (10 votes)
28 Jan 2011CPOL11 min read 48.8K   572   11  
This article explains how to write unit tests for MVVM using Catel.
<Windows:DataWindow x:Class="Catel.Windows.MultipleChoiceWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:Controls="clr-namespace:Catel.Windows.Controls"
    xmlns:Windows="clr-namespace:Catel.Windows"
    MinWidth="400">

	<!-- Content -->
	<StackPanel DataContext="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}}">
		<!-- Show choices -->
		<ListBox ItemsSource="{DynamicResource ChoiceCollection}" SelectedItem="{Binding SelectedChoice}"
				 BorderThickness="0" Margin="0">
			<ListBox.Resources>
				<Style x:Key="{x:Type ListBoxItem}" TargetType="{x:Type ListBoxItem}">
					<Setter Property="Template">
						<Setter.Value>
							<ControlTemplate>
								<Border Background="Transparent">
									<RadioButton Content="{Binding Header}"  
										IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}"/>
								</Border>
							</ControlTemplate>
						</Setter.Value>
					</Setter>
				</Style>
			</ListBox.Resources>
		</ListBox>

		<!-- Reason text -->
		<Controls:MultiLineInput Text="{Binding Choice}" IsEnabled="{Binding SelectedChoice.AllowCustomization}"/>
	</StackPanel>
</Windows:DataWindow>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Netherlands Netherlands
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions