Click here to Skip to main content
15,894,106 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 49.2K   572   11  
This article explains how to write unit tests for MVVM using Catel.
<Window x:Class="Catel.Windows.TipOfTheDayWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Input="clr-namespace:Catel.Windows.Input;assembly=Catel.Windows"
        Title="Tip of the Day" ShowInTaskbar="False" ResizeMode="NoResize" SizeToContent="WidthAndHeight"
        WindowStartupLocation="CenterOwner">

    <!-- Resources -->

    <!-- Content -->
    <Grid DataContext="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}}">
        <DockPanel>
            <!-- Bottom -->
            <Grid DockPanel.Dock="Bottom">
                <!-- Column definitions -->
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <!-- Do not show again -->
                <CheckBox Grid.Column="0" Content="Do not show again" IsChecked="{Binding DoNotShowAgain}" />

                <!-- Close button -->
                <Button Grid.Column="1" Command="Close" IsCancel="True" Style="{DynamicResource FixedSizeButtonStyle}" />
            </Grid>

            <!-- Splitter -->
            <Rectangle DockPanel.Dock="Bottom" Fill="Gray" Margin="8" Height="1" />

            <!-- Right side buttons -->
            <StackPanel DockPanel.Dock="Right" VerticalAlignment="Bottom">
                <Button Command="Input:TipOfTheDayCommands.ShowNextTip" Style="{DynamicResource FixedSizeButtonStyle}" />
            </StackPanel>

            <!-- Actual tip -->
            <GroupBox Header="Tip of the day" DataContext="{Binding ActiveTipOfTheDay}">
                <Grid>
                    <!-- Rounded border that will serve as the mask -->
                    <Border Name="mask" BorderThickness="1" BorderBrush="Gray" CornerRadius="3" >
                        <Border.Background>
                            <RadialGradientBrush RadiusX="1" RadiusY="1" GradientOrigin="1,0" Center="0.9,0.1">
                                <GradientStop Color="White" Offset="0"/>
                                <GradientStop Color="Gray" Offset="1"/>
                            </RadialGradientBrush>
                        </Border.Background>
                    </Border>

                    <!-- Grid that will clip to the border -->
                    <Grid Height="180" Width="360" HorizontalAlignment="Left">
                        <Grid.OpacityMask>
                            <VisualBrush Visual="{Binding ElementName=mask}" />
                        </Grid.OpacityMask>

                        <!-- Row definitions -->
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>

                        <!-- Column definitions -->
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <!-- Lamp -->
                        <Image Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" Source="/Catel.Windows;component/Resources/Images/TipOfTheDay.png" Stretch="UniformToFill"
                               Height="72" VerticalAlignment="Top" Margin="0,10,0,0"/>

                        <!-- Title -->
                        <Label Grid.Row="0" Grid.Column="1">
                            <TextBlock Text="{Binding Title}" Style="{DynamicResource CaptionTextBlockStyle}" />
                        </Label>
                        
                        <!-- Description -->
                        <Label Grid.Row="1" Grid.Column="1">
                            <TextBlock Text="{Binding Description}" TextWrapping="Wrap" />
                        </Label>
                    </Grid>
                </Grid>
            </GroupBox>
        </DockPanel>
    </Grid>
</Window>

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