Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Catel - Part 4 of n: Unit testing with Catel

, 28 Jan 2011 CPOL
This article explains how to write unit tests for MVVM using Catel.
Catel-04_01-unittesting.zip
src
Catel.Articles.04 - Unit testing
Models
Properties
Settings.settings
Resources
Images
add.png
delete.png
edit.png
group.png
UI
Data
Converters
ViewModels
Windows
Catel.Articles.04 - Unit testing.Test
Models
Properties
UI
ViewModels
Catel.Articles.Base
Data
Attributes
Properties
Settings.settings
Resources
Images
CatenaLogic.png
Preview.png
Run.png
ShowCode.png
UI
Controls
Helpers
ViewModels
Windows
Catel.Core
Attributes
ClassDiagrams
DataObjectBase.cd
SavableDataObjectBase.cd
Collections
Helpers
ComponentModel
Data
Attributes
Exceptions
Interfaces
Diagnostics
Extensions
Helpers
Exceptions
Helpers
IO
Exceptions
IoC
LLBLGen
Log4net
Appender
Extensions
Helpers
MVVM
Commands
Interfaces
Exceptions
Services
EventArgs
Exceptions
Interfaces
ViewModels
Attributes
Interfaces
Properties
Reflection
Exceptions
Extensions
Helpers
Runtime
Serialization
Attributes
Helpers
Security
Cryptography
Helpers
Catel.Examples.Models
Properties
Catel.Examples.PersonApplication
Properties
Settings.settings
Resources
Images
add.png
delete.png
edit.png
group.png
UI
Data
Converters
ViewModels
Windows
Catel.Examples.Silverlight
Properties
Resources
Images
add.png
delete.png
edit.png
group.png
UI
Data
Converters
Pages
ViewModels
Windows
Catel.Examples.Silverlight.Web
Catel.Examples.Silverlight.Web.csproj.user
ClientBin
Properties
Catel.FxCop
Catel.Silverlight
Diagnostics
log4net
Core
MVVM
Commands
Services
ViewModels
Properties
Catel.Core
Catel.Windows
Reflection
Themes
Generic
Assets
Old
Windows
Controls
Data
Converters
Helpers
Helpers
Catel.Silverlight.Test
Properties
Catel.Silverlight.Test.Web
Catel.Silverlight.Test.Web.csproj.user
ClientBin
Properties
Catel.snk
Catel.Templates.WpfApplication
Properties
Settings.settings
UI
Controls
ViewModels
Windows
Catel.Templates.WpfItemTemplates
Properties
UI
Controls
ViewModels
Windows
Catel.Test
Collections
Convert
Data
Helpers
IO
MVVM
UI
ViewModels
Properties
Reflection
Runtime
Serialization
Security
Cryptography
Test References
Catel.Windows.accessor
Windows
Data
Converters
Catel.vsmdi
Catel.Windows
ClassDiagrams
ViewModelBase.cd
Collections
Extensions
Helpers
MVVM
Commands
Services
Test
UI
ViewModels
Properties
Settings.settings
Resources
Images
Add.png
ClearOutput.png
Edit.png
Error.png
Loading.gif
Preview.png
Remove.png
Save.png
TipOfTheDay.png
Warning.png
Themes
Aero
ExpressionDark
Assets
Generic
Assets
Controls
Jetpack
Assets
background.png
Old
SunnyOrange
Assets
Windows
Controls
Extensions
LinkLabel
StackGrid
Data
Converters
Helpers
Documents
Extensions
Extensions
Helpers
Input
Markup
Media
Effects
EmptyEffect
EmptyEffect.fx
EmptyEffect.ps
EmptyEffect.fx
GrayscaleEffect
GrayscaleEffect.fx
GrayscaleEffect.ps
Extensions
Imaging
Extensions
Windows
DataWindow
TipOfTheDay
Local.testsettings
Settings.StyleCop
TraceAndTestImpact.testsettings
<?xml version="1.0" encoding="utf-8"?>
<root>
  <!-- 
    Microsoft ResX Schema 
    
    Version 2.0
    
    The primary goals of this format is to allow a simple XML format 
    that is mostly human readable. The generation and parsing of the 
    various data types are done through the TypeConverter classes 
    associated with the data types.
    
    Example:
    
    ... ado.net/XML headers & schema ...
    <resheader name="resmimetype">text/microsoft-resx</resheader>
    <resheader name="version">2.0</resheader>
    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
        <value>[base64 mime encoded serialized .NET Framework object]</value>
    </data>
    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
        <comment>This is a comment</comment>
    </data>
                
    There are any number of "resheader" rows that contain simple 
    name/value pairs.
    
    Each data row contains a name, and value. The row also contains a 
    type or mimetype. Type corresponds to a .NET class that support 
    text/value conversion through the TypeConverter architecture. 
    Classes that don't support this are serialized and stored with the 
    mimetype set.
    
    The mimetype is used for serialized objects, and tells the 
    ResXResourceReader how to depersist the object. This is currently not 
    extensible. For a given mimetype the value must be set accordingly:
    
    Note - application/x-microsoft.net.object.binary.base64 is the format 
    that the ResXResourceWriter will generate, however the reader can 
    read any of the formats listed below.
    
    mimetype: application/x-microsoft.net.object.binary.base64
    value   : The object must be serialized with 
            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
            : and then encoded with base64 encoding.
    
    mimetype: application/x-microsoft.net.object.soap.base64
    value   : The object must be serialized with 
            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
            : and then encoded with base64 encoding.

    mimetype: application/x-microsoft.net.object.bytearray.base64
    value   : The object must be serialized into a byte array 
            : using a System.ComponentModel.TypeConverter
            : and then encoded with base64 encoding.
    -->
  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
    <xsd:element name="root" msdata:IsDataSet="true">
      <xsd:complexType>
        <xsd:choice maxOccurs="unbounded">
          <xsd:element name="metadata">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0" />
              </xsd:sequence>
              <xsd:attribute name="name" use="required" type="xsd:string" />
              <xsd:attribute name="type" type="xsd:string" />
              <xsd:attribute name="mimetype" type="xsd:string" />
              <xsd:attribute ref="xml:space" />
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="assembly">
            <xsd:complexType>
              <xsd:attribute name="alias" type="xsd:string" />
              <xsd:attribute name="name" type="xsd:string" />
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="data">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
              </xsd:sequence>
              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
              <xsd:attribute ref="xml:space" />
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="resheader">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
              </xsd:sequence>
              <xsd:attribute name="name" type="xsd:string" use="required" />
            </xsd:complexType>
          </xsd:element>
        </xsd:choice>
      </xsd:complexType>
    </xsd:element>
  </xsd:schema>
  <resheader name="resmimetype">
    <value>text/microsoft-resx</value>
  </resheader>
  <resheader name="version">
    <value>2.0</value>
  </resheader>
  <resheader name="reader">
    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </resheader>
  <resheader name="writer">
    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </resheader>
  <data name="FailedToDeserializeDataForBackupTryingWithRedirects" xml:space="preserve">
    <value>Failed to deserialize the data for backup, which is weird. Trying with redirects enabled.</value>
  </data>
  <data name="FailedToSubscribeToEventsInOnDeserializedMethod" xml:space="preserve">
    <value>Failed to subscribe to events in the OnDeserialized method</value>
  </data>
  <data name="ObjectNotDisposedCorrectly" xml:space="preserve">
    <value>object '{0}' is not disposed correctly, so object is not fully cleaned up and could not unsubscribe from event handlers. Call the Dispose() method after using this class.</value>
    <comment>{0} = object name</comment>
  </data>
  <data name="LoadingObject" xml:space="preserve">
    <value>Loading object '{0}' as '{1}'</value>
    <comment>{0} = object name
{1} = type name</comment>
  </data>
  <data name="FailedToDeserializeBinaryObject" xml:space="preserve">
    <value>Failed to deserialize the binary object</value>
  </data>
  <data name="ErrorDeserializingObject" xml:space="preserve">
    <value>An error occurred while deserializing object '{0}'</value>
    <comment>{0} = object name</comment>
  </data>
  <data name="FailedToCallOnDeserializationForChildObjects" xml:space="preserve">
    <value>Failed to call IDeserializationCallback.OnDeserialization for child objects</value>
  </data>
  <data name="FailedToDeserializeProperty" xml:space="preserve">
    <value>Failed to deserialize property '{0}' stored as '{1}', using default value</value>
    <comment>{0} = property name
{1} = xml name</comment>
  </data>
  <data name="SavingObject" xml:space="preserve">
    <value>Saving object '{0}' as '{1}'</value>
    <comment>{0} = type name
{1} = mode</comment>
  </data>
  <data name="CannotFindProperty" xml:space="preserve">
    <value>GetPropertyInfo cannot find the PropertyInfo for '{0}'</value>
    <comment>{0} = property name</comment>
  </data>
  <data name="RedirectAlreadyAdded" xml:space="preserve">
    <value>A redirect for type '{0}' is already added to '{1}'. The redirect to '{2}' will not be added.</value>
    <comment>{0} = original type
{1} = existing type to load
{2} = type to load</comment>
  </data>
  <data name="FailedToLoadType" xml:space="preserve">
    <value>Failed to load type '{0}'</value>
    <comment>{0} = type</comment>
  </data>
  <data name="FailedToRetrieveInnerTypes" xml:space="preserve">
    <value>Failed to retrieve inner types</value>
  </data>
  <data name="FailedToDeserializeObject" xml:space="preserve">
    <value>Failed to deserialize object</value>
  </data>
  <data name="FailedToSerializeObject" xml:space="preserve">
    <value>Failed to serialize object</value>
  </data>
  <data name="PropertyNotDisposedSinceItIsInIgnoreList" xml:space="preserve">
    <value>Property '{0}' of type '{1}' is not disposed since it is in the ignore list</value>
    <comment>{0} = property name
{1} = property type</comment>
  </data>
  <data name="PropertyNotFoundOnObjectProbablyInvalidMapping" xml:space="preserve">
    <value>Property '{0}' is not found on the object '{1}', probably the wrong field is being mapped</value>
    <comment>{0} = property name
{1} = object type</comment>
  </data>
  <data name="PropertyNotSerializableSoExcludedFromSerialization" xml:space="preserve">
    <value>Property '{0}' is not serializable, so will be excluded from the serialization</value>
    <comment>{0} = property name</comment>
  </data>
  <data name="PropertyFlaggedToBeExcludedFromSerialization" xml:space="preserve">
    <value>Property '{0}' is flagged to be excluded from serialization</value>
    <comment>{0} = property name</comment>
  </data>
  <data name="AddingPropertyToListOfObjectsToSerialize" xml:space="preserve">
    <value>Adding property '{0}' to list of objects to serialize</value>
    <comment>{0} = property name</comment>
  </data>
  <data name="CannotSetPropertyObjectIsReadonly" xml:space="preserve">
    <value>Cannot set property '{0}', object is currently read-only</value>
    <comment>{0} = property name</comment>
  </data>
  <data name="MethodNotFound" xml:space="preserve">
    <value>Method '{0}' does not exist for object '{1}'</value>
    <comment>{0} = Method name
{1} = object type name</comment>
  </data>
  <data name="MethodResultIsNull" xml:space="preserve">
    <value>Method '{0}' of object '{1}' returned null</value>
    <comment>{0} = Method name
{1} = object type name</comment>
  </data>
  <data name="PropertyNotFound" xml:space="preserve">
    <value>Property '{0}' does not exist for '{1}'</value>
    <comment>{0} = Property name
{1} = object type name</comment>
  </data>
  <data name="PropertyResultIsNull" xml:space="preserve">
    <value>Property '{0}' of object '{1}' returned null</value>
    <comment>{0} = Property name
{1} = object type name</comment>
  </data>
  <data name="RelationsFound" xml:space="preserve">
    <value>Found {0} relations for object '{1}'</value>
    <comment>{0} = Number of relations found
{1} = object type name</comment>
  </data>
  <data name="FoundRelationForFieldOnType" xml:space="preserve">
    <value>Found relation for field '{0}' on type '{1}'</value>
    <comment>{0} = field name
{1} = type name</comment>
  </data>
  <data name="FieldNotFound" xml:space="preserve">
    <value>Field '{0}' does not exist for '{1}'</value>
    <comment>{0} = Field name
{1} = object type name</comment>
  </data>
  <data name="FailedToRefetchRelationForField" xml:space="preserve">
    <value>Failed to refetch relation mapped on field '{0}'</value>
    <comment>
			{0} = mapped field name
		</comment>
  </data>
  <data name="FailedToGetTypesOfAssembly" xml:space="preserve">
    <value>Failed to get the types of assembly '{0}'</value>
    <comment>{0} = assembly name</comment>
  </data>
  <data name="CannotReadProperty" xml:space="preserve">
    <value>Cannot read property {0}.'{1}'</value>
    <comment>{0} = type name
{1} = property name</comment>
  </data>
  <data name="CannotWriteProperty" xml:space="preserve">
    <value>Cannot write property {0}.'{1}'</value>
    <comment>{0} = type name
{1} = property name</comment>
  </data>
  <data name="CreatingBinarySerializer" xml:space="preserve">
    <value>Creating binary serializer</value>
  </data>
  <data name="CreatedBinarySerializer" xml:space="preserve">
    <value>Created binary serializer</value>
  </data>
  <data name="InitializingRedirectDeserializationBinder" xml:space="preserve">
    <value>Initializing redirect deserialization binder</value>
  </data>
  <data name="InitializedRedirectDeserializationBinder" xml:space="preserve">
    <value>Initialized redirect deserialization binder</value>
  </data>
  <data name="CreatingRedirectDeserializationBindinger" xml:space="preserve">
    <value>Creating redirect deserialization binder</value>
  </data>
  <data name="CreatedRedirectDeserializationBindinger" xml:space="preserve">
    <value>Created redirect deserialization binder</value>
  </data>
  <data name="AddingRedirectFromTypeToType" xml:space="preserve">
    <value>Adding redirect from '{0}' to '{1}'</value>
    <comment>{0} = original type name
{1} = new type name</comment>
  </data>
  <data name="ResettedStreamPositionToZero" xml:space="preserve">
    <value>Resetted stream position to 0</value>
  </data>
  <data name="ResettingStreamPositionToZero" xml:space="preserve">
    <value>Resetting stream position to 0</value>
  </data>
  <data name="DeserializingBinaryStream" xml:space="preserve">
    <value>Deserializing binary stream for type '{0}'</value>
    <comment>{0} = type name</comment>
  </data>
  <data name="DeserializedBinaryStream" xml:space="preserve">
    <value>Deserialized binary stream</value>
  </data>
  <data name="ReceivedOnDeserialization" xml:space="preserve">
    <value>Received OnDeserialization event for '{0}'</value>
    <comment>{0} = type name</comment>
  </data>
  <data name="ReceivedOnDeserialized" xml:space="preserve">
    <value>Received OnDeserialized event for '{0}'</value>
    <comment>{0} = type name</comment>
  </data>
  <data name="FailedToDeserializeDataForBackup" xml:space="preserve">
    <value>Failed to deserialize the data for backup, which is weird. However, for Silverlight there is no other option.</value>
  </data>
  <data name="AddedInterestedViewModel" xml:space="preserve">
    <value>Added interested view model of type '{0}' for type '{1}', currently containing {2} interested view model(s)</value>
    <comment>{0} = interested view model type
{1} = view model type
{2} = number of interested view models</comment>
  </data>
  <data name="AddedViewModelInstance" xml:space="preserve">
    <value>Added view model instance, currently containing '{0}' instances of type '{1}'</value>
    <comment>{0} = number of current instances
{1} = view model type</comment>
  </data>
  <data name="CanceledViewModel" xml:space="preserve">
    <value>Canceled view model '{0}'</value>
    <comment>
			{0} = view model type
		</comment>
  </data>
  <data name="CannotMapFromViewModelToModelBecauseModelIsNull" xml:space="preserve">
    <value>Value for model property '{0}' is null, cannot map properties from view model to model</value>
    <comment>{0} = model property</comment>
  </data>
  <data name="ClosedViewModel" xml:space="preserve">
    <value>Closed view model '{0}'</value>
    <comment>
			{0} = view model type
		</comment>
  </data>
  <data name="FailedToCancelEditOfModel" xml:space="preserve">
    <value>Failed to cancel the edit of object for model '{0}'</value>
    <comment>{0} = model name</comment>
  </data>
  <data name="FailedToEndEditOfModel" xml:space="preserve">
    <value>Failed to end the edit of object for model '{0}'</value>
    <comment>
			{0} = model property name
		</comment>
  </data>
  <data name="FailedToInformInterestedViewModelOfAViewModelChange" xml:space="preserve">
    <value>Failed to let an interested view model know that a view model has changed. Probably the view model is not correctly cleaned up</value>
  </data>
  <data name="FailedToSaveViewModel" xml:space="preserve">
    <value>Failed to save view model '{0}'</value>
    <comment>
			{0} = view model type
		</comment>
  </data>
  <data name="InstantiatedViewModelManager" xml:space="preserve">
    <value>ViewModelManager instantiated</value>
  </data>
  <data name="InterestingViewModelCallPropertyChanged" xml:space="preserve">
    <value>A view model ('{0}') the current view model ('{1}') is interested in has changed a property ('{2}')</value>
    <comment>{0} = view model type
{1} = current view model type
{2} = property name</comment>
  </data>
  <data name="ModelNotRegistered" xml:space="preserve">
    <value>There is no model '{0}' registered with the model attribute, so the ViewModelToModel attribute on property '{1}' is invalid</value>
    <comment>{0} = model name
{1} = property that points to the model</comment>
  </data>
  <data name="PropertyNotFoundInModel" xml:space="preserve">
    <value>Mapped viewmodel property '{0}' to model property '{1}' is invalid because property '{1}' is not found on the model '{2}'</value>
    <comment>{0} = view model property name
{1} = model property name
{2} = model name</comment>
  </data>
  <data name="RemovedInterestedViewModel" xml:space="preserve">
    <value>Removed interested view model of type '{0}' for type '{1}', currently containing {2} interested view model(s)</value>
    <comment>{0} = interested view model type
{1} = view model type
{2} = number of interested view models</comment>
  </data>
  <data name="RemovedViewModelInstance" xml:space="preserve">
    <value>Removed view model instance, currently containing '{0}' instances of type '{1}'</value>
    <comment>{0} = number of current instances
{1} = view model type</comment>
  </data>
  <data name="SavedViewModel" xml:space="preserve">
    <value>Saved view model '{0}'</value>
    <comment>
			{0} = view model type
		</comment>
  </data>
  <data name="ViewModelImplementsMoreThanOneModelWarning" xml:space="preserve">
    <value>The view model {0} implements {1} models.

Normally, a view model only implements 1 model so make sure you are using the Model attribute correctly. If the Model attribute is used correctly (on models only), this warning can be ignored by using a constructor overload.</value>
    <comment>{0} = View model name
{1} = Number of actual models</comment>
  </data>
  <data name="WrongViewModelPropertyType" xml:space="preserve">
    <value>Property '{0}' mapped on model property '{1}' is of the wrong type ('{2}'), should be '{3}'</value>
    <comment>{0} = view model property name
{1} = model property name
{2} = view model property type
{3} = model property type</comment>
  </data>
  <data name="FoundCommandOnViewModel" xml:space="preserve">
    <value>Found command '{0}' on view model '{1}'</value>
    <comment>{0} = command property name
{1} = view model type name</comment>
  </data>
  <data name="FinishedDeserializationOfObject" xml:space="preserve">
    <value>Finished deserialization of '{0}'</value>
    <comment>{0} = type name</comment>
  </data>
  <data name="GettingDataFromSerializationInfo" xml:space="preserve">
    <value>Getting data from serialization info</value>
  </data>
  <data name="SerializationInfoIsNull" xml:space="preserve">
    <value>Serialization info is null, no data to retrieve</value>
  </data>
  <data name="ObjectAlreadyDeserialized" xml:space="preserve">
    <value>Object '{0}' is already deserialized</value>
    <comment>{0} = type name</comment>
  </data>
  <data name="GettingKnownTypesForXmlSerialization" xml:space="preserve">
    <value>Getting known types for xml serialization of '{0}'</value>
    <comment>{0} = type name of object to serialize</comment>
  </data>
  <data name="FoundKnownTypesForXmlSerialization" xml:space="preserve">
    <value>Found '{0}' known types for xml serialization</value>
    <comment>
			{0} = number of known types found
		</comment>
  </data>
	<data name="FailedToGetFieldValue">
		<value><![CDATA[Failed to get value for field '{0}' of type '{1}']]></value>
		<comment><![CDATA[{0} = field name
{1} = type name]]></comment>
	</data>
	<data name="FailedToGetPropertyValue">
		<value><![CDATA[Failed to get value for property '{0}' of type '{1}']]></value>
		<comment><![CDATA[{0} = property name
{1} = type name]]></comment>
	</data>
</root>

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)

Share

About the Author

Geert van Horrik
Software Developer CatenaLogic
Netherlands 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.
 
To download (or buy) applications I have written, visit my website: http://www.catenalogic.com
Follow on   Twitter

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141030.1 | Last Updated 28 Jan 2011
Article Copyright 2011 by Geert van Horrik
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid