Click here to Skip to main content
15,891,657 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.1K   572   11  
This article explains how to write unit tests for MVVM using Catel.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>9.0.30729</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{6D7F75BD-14E7-4F6D-B599-AF434FB371B0}</ProjectGuid>
    <ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>Catel.Silverlight.Test</RootNamespace>
    <AssemblyName>Catel.Silverlight.Test</AssemblyName>
    <TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
    <SilverlightApplication>true</SilverlightApplication>
    <SupportedCultures />
    <XapOutputs>true</XapOutputs>
    <GenerateSilverlightManifest>true</GenerateSilverlightManifest>
    <XapFilename>Catel.Silverlight.Test.xap</XapFilename>
    <SilverlightManifestTemplate>Properties\AppManifest.xml</SilverlightManifestTemplate>
    <SilverlightAppEntry>Catel.Silverlight.Test.App</SilverlightAppEntry>
    <TestPageFileName>TestPage.html</TestPageFileName>
    <CreateTestPage>true</CreateTestPage>
    <ValidateXaml>true</ValidateXaml>
    <EnableOutOfBrowser>false</EnableOutOfBrowser>
    <OutOfBrowserSettingsFile>Properties\OutOfBrowserSettings.xml</OutOfBrowserSettingsFile>
    <UsePlatformExtensions>false</UsePlatformExtensions>
    <ThrowErrorsInValidation>true</ThrowErrorsInValidation>
    <LinkedServerProject />
  </PropertyGroup>
  <!--
  //
  // Silverlight Code Coverage Instrumentation
  // List any libraries or assemblies that you would like to instrument during
  // a code coverage pass. An example, for ClassLibrary1, is provided, and
  // commented out below as a starting point:
  //
  -->
  <!--
  <ItemGroup>
    <InstrumentSilverlightAssemblies Include="SilverlightClassLibrary1">
      <Visible>false</Visible>
    </InstrumentSilverlightAssemblies>
  </ItemGroup>
  -->
  <!-- This property group is only here to support building this project using the 
       MSBuild 3.5 toolset. In order to work correctly with this older toolset, it needs 
       to set the TargetFrameworkVersion to v3.5 -->
  <PropertyGroup Condition="'$(MSBuildToolsVersion)' == '3.5'">
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>..\..\output\Release\Test\</OutputPath>
    <DefineConstants>DEBUG;TRACE;SILVERLIGHT</DefineConstants>
    <NoStdLib>true</NoStdLib>
    <NoConfig>true</NoConfig>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>..\..\output\Release\Test\</OutputPath>
    <DefineConstants>TRACE;SILVERLIGHT</DefineConstants>
    <NoStdLib>true</NoStdLib>
    <NoConfig>true</NoConfig>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>..\..\output\Release\Test\</OutputPath>
    <DefineConstants>DEBUG;TRACE;SILVERLIGHT</DefineConstants>
    <NoStdLib>true</NoStdLib>
    <DebugType>full</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
    <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
    <OutputPath>..\..\output\Release\Test\</OutputPath>
    <DefineConstants>TRACE;SILVERLIGHT</DefineConstants>
    <Optimize>true</Optimize>
    <NoStdLib>true</NoStdLib>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
    <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>..\..\output\Release\Test\</OutputPath>
    <DefineConstants>DEBUG;TRACE;SILVERLIGHT</DefineConstants>
    <NoStdLib>true</NoStdLib>
    <DebugType>full</DebugType>
    <PlatformTarget>x86</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
    <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
    <OutputPath>..\..\output\Release\Test\</OutputPath>
    <DefineConstants>TRACE;SILVERLIGHT</DefineConstants>
    <Optimize>true</Optimize>
    <NoStdLib>true</NoStdLib>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>x86</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
    <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="Castle.Core">
      <HintPath>..\..\lib\Silverlight\Moq\Castle.Core.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Practices.Unity.Silverlight, Version=2.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
    <Reference Include="Microsoft.Silverlight.Testing">
      <HintPath>$(MSBuildExtensionsPath)\..\Microsoft SDKs\Silverlight\v4.0\Toolkit\Apr10\Testing\Microsoft.Silverlight.Testing.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight">
      <HintPath>$(MSBuildExtensionsPath)\..\Microsoft SDKs\Silverlight\v4.0\Toolkit\Apr10\Testing\Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight.dll</HintPath>
    </Reference>
    <Reference Include="Moq.Silverlight">
      <HintPath>..\..\lib\Silverlight\Moq\Moq.Silverlight.dll</HintPath>
    </Reference>
    <Reference Include="System.Runtime.Serialization" />
    <Reference Include="System.Windows" />
    <Reference Include="mscorlib" />
    <Reference Include="system" />
    <Reference Include="System.Core" />
    <Reference Include="System.Net" />
    <Reference Include="System.Windows.Controls, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
    <Reference Include="System.Windows.Controls.Toolkit, Version=4.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
    <Reference Include="System.Xml" />
    <Reference Include="System.Windows.Browser" />
    <Reference Include="System.Xml.Linq, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="..\Catel.Test\Collections\CollectionHelperTest.cs">
      <Link>Collections\CollectionHelperTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Collections\ObservableCollectionExtensionsTest.cs">
      <Link>Collections\ObservableCollectionExtensionsTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Data\DataObjectBaseTest.cs">
      <Link>Data\DataObjectBaseTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Data\DataObjectBaseTestHelper.cs">
      <Link>Data\DataObjectBaseTestHelper.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Data\PropertyDataManagerTest.cs">
      <Link>Data\PropertyDataManagerTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Data\PropertyDataTest.cs">
      <Link>Data\PropertyDataTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Data\SavableDataObjectBaseTest.cs">
      <Link>Data\SavableDataObjectBaseTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\EnumTest.cs">
      <Link>EnumTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Helpers\AttributeHelperTest.cs">
      <Link>Helpers\AttributeHelperTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Helpers\FilesHelper.cs">
      <Link>Helpers\FilesHelper.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Helpers\LLBLGenHelperTest.cs">
      <Link>Helpers\LLBLGenHelperTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Helpers\TypeHelperTest.cs">
      <Link>Helpers\TypeHelperTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Helpers\WindowHelper.cs">
      <Link>Helpers\WindowHelper.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\MVVM\UI\ControlToViewModelAttributeTest.cs">
      <Link>MVVM\UI\ControlToViewModelAttributeTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\MVVM\UI\ControlToViewModelMappingContainerTest.cs">
      <Link>MVVM\UI\ControlToViewModelMappingContainerTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\MVVM\UI\ControlToViewModelMappingHelperTest.cs">
      <Link>MVVM\UI\ControlToViewModelMappingHelperTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\MVVM\UI\ControlToViewModelMappingTest.cs">
      <Link>MVVM\UI\ControlToViewModelMappingTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\MVVM\ViewModels\ViewModelBaseTest.cs">
      <Link>MVVM\ViewModels\ViewModelBaseTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Reflection\AppDomainExtensionsTest.cs">
      <Link>Reflection\AppDomainExtensionsTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Reflection\AssemblyExtensionsTest.cs">
      <Link>Reflection\AssemblyExtensionsTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Reflection\PropertyHelperTest.cs">
      <Link>Reflection\PropertyHelperTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Reflection\ReflectionExtensionsTest.cs">
      <Link>Reflection\ReflectionExtensionsTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\RetrySafetyCounterTest.cs">
      <Link>RetrySafetyCounterTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Windows\Data\Converters\BooleanToGrayscaleConverterTest.cs">
      <Link>Windows\Data\Converters\BooleanToGrayscaleConverterTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Windows\Data\Converters\BooleanToOppositeBooleanConverterTest.cs">
      <Link>Windows\Data\Converters\BooleanToOppositeBooleanConverterTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Windows\Data\Converters\BooleanToTextConverterTest.cs">
      <Link>Windows\Data\Converters\BooleanToTextConverterTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Windows\Data\Converters\BooleanToVisibilityConverterTest.cs">
      <Link>Windows\Data\Converters\BooleanToVisibilityConverterTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Windows\Data\Converters\ColorToBrushConverterTest.cs">
      <Link>Windows\Data\Converters\ColorToBrushConverterTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Windows\Data\Converters\ContainsItemsConverterTest.cs">
      <Link>Windows\Data\Converters\ContainsItemsConverterTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Windows\Data\Converters\CountVisibilityConverterTest.cs">
      <Link>Windows\Data\Converters\CountVisibilityConverterTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Windows\Data\Converters\EmptyStringToVisibilityConverterTest.cs">
      <Link>Windows\Data\Converters\EmptyStringToVisibilityConverterTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Windows\Data\Converters\FormattingConverterTest.cs">
      <Link>Windows\Data\Converters\FormattingConverterTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Windows\Data\Converters\GetFirstValidationErrorConverterTest.cs">
      <Link>Windows\Data\Converters\GetFirstValidationErrorConverterTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Windows\Data\Converters\IsSelectedConverterTest.cs">
      <Link>Windows\Data\Converters\IsSelectedConverterTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Windows\Data\Converters\IsSelectedValueConverterTest.cs">
      <Link>Windows\Data\Converters\IsSelectedValueConverterTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Windows\Data\Converters\MethodToValueConverterTest.cs">
      <Link>Windows\Data\Converters\MethodToValueConverterTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Windows\Data\Converters\MultiplyConverterTest.cs">
      <Link>Windows\Data\Converters\MultiplyConverterTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Windows\Data\Converters\ReferenceToBooleanConverterTest.cs">
      <Link>Windows\Data\Converters\ReferenceToBooleanConverterTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Windows\Data\Converters\ReferenceToCollapsingVisibilityConverterTest.cs">
      <Link>Windows\Data\Converters\ReferenceToCollapsingVisibilityConverterTest.cs</Link>
    </Compile>
    <Compile Include="..\Catel.Test\Windows\Data\Converters\ShortDateFormattingConverterTest.cs">
      <Link>Windows\Data\Converters\ShortDateFormattingConverterTest.cs</Link>
    </Compile>
    <Compile Include="App.xaml.cs">
      <DependentUpon>App.xaml</DependentUpon>
    </Compile>
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <ApplicationDefinition Include="App.xaml">
      <SubType>Designer</SubType>
      <Generator>MSBuild:Compile</Generator>
    </ApplicationDefinition>
  </ItemGroup>
  <ItemGroup>
    <None Include="Properties\AppManifest.xml" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\Catel.Silverlight\Catel.Silverlight.csproj">
      <Project>{31E5FE50-0F17-497A-857E-73D5476B3C2D}</Project>
      <Name>Catel.Silverlight</Name>
    </ProjectReference>
  </ItemGroup>
  <ItemGroup />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" />
  <Import Condition="$(SilverlightVersion)=='v3.0'" Project="$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SilverlightToolkit\Tools\v3.0)Microsoft.Silverlight.Toolkit.Build.targets" />
  <Import Condition="$(SilverlightVersion)=='v4.0'" Project="$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SilverlightToolkit\Tools\v4.0)Microsoft.Silverlight.Toolkit.Build.targets" />
  <ProjectExtensions>
    <VisualStudio>
      <FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
        <SilverlightProjectProperties />
      </FlavorProperties>
    </VisualStudio>
  </ProjectExtensions>
</Project>

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