Click here to Skip to main content
15,885,896 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.9K   572   11  
This article explains how to write unit tests for MVVM using Catel.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace Ricciolo.StylesExplorer.MarkupReflection
{
    internal class XmlBamlElement : XmlBamlNode
    {
        private ArrayList _arguments = new ArrayList();
        private XmlNamespaceCollection _namespaces = new XmlNamespaceCollection();
        private TypeDeclaration _typeDeclaration;
        private KeysResourcesCollection _keysResources = new KeysResourcesCollection();
        private long _position;

        public XmlBamlElement()
        {
        }


        public XmlBamlElement(XmlBamlElement parent)
        {
            this.Namespaces.AddRange(parent.Namespaces);
        }

        public XmlNamespaceCollection Namespaces
        {
            get { return _namespaces; }
        }

        public TypeDeclaration TypeDeclaration
        {
            get
            {
                return this._typeDeclaration;
            }
            set
            {
                this._typeDeclaration = value;
            }
        }

        public override XmlNodeType NodeType
        {
            get
            {
                return XmlNodeType.Element;
            }
        }

        public long Position
        {
            get { return _position; }
            set { _position = value; }
        }

        public override string ToString()
        {
            return String.Format("Element: {0}", TypeDeclaration.Name);
        }
    }

    internal class XmlBamlEndElement : XmlBamlElement
    {
        public XmlBamlEndElement(XmlBamlElement start)
        {
            this.TypeDeclaration = start.TypeDeclaration;
            this.Namespaces.AddRange(start.Namespaces);
        }

        public override XmlNodeType NodeType
        {
            get
            {
                return XmlNodeType.EndElement;
            }
        }

        public override string ToString()
        {
            return String.Format("EndElement: {0}", TypeDeclaration.Name);
        }
    }

    internal class KeyMapping
    {
        private string _key;
        private TypeDeclaration _declaration;
        private string _trueKey;

        public KeyMapping(string key, TypeDeclaration declaration, string trueKey)
        {
            _key = key;
            _declaration = declaration;
            _trueKey = trueKey;
        }

        public string Key
        {
            get { return _key; }
        }

        public TypeDeclaration Declaration
        {
            get { return _declaration; }
        }

        public string TrueKey
        {
            get { return _trueKey; }
        }

        public override string ToString()
        {
            return String.Format("{0} - {1} - {2}", Key, Declaration, TrueKey);
        }
    }

    internal class KeysResourcesCollection : List<KeysResource>
    {
        public KeysResource Last
        {
            get
            {
                if (this.Count == 0)
                    return null;
                return this[this.Count - 1];
            }
        }

        public KeysResource First
        {
            get
            {
                if (this.Count == 0)
                    return null;
                return this[0];
            }
        }
    }

    internal class KeysResource
    {
        private KeysTable _keys = new KeysTable();
        private ArrayList _staticResources = new ArrayList();

        public KeysTable Keys
        {
            get { return _keys; }
        }

        public ArrayList StaticResources
        {
            get { return _staticResources; }
        }
    }

    internal class KeysTable
    {
        private Hashtable table = new Hashtable();

        public String this[long position]
        {
            get
            {
                return (string)this.table[position];
            }
            set
            {
                this.table[position] = value;
            }
        }

        public int Count
        {
            get { return this.table.Count; }
        }

        public void Remove(long position)
        {
            this.table.Remove(position);
        }

        public bool HasKey(long position)
        {
            return this.table.ContainsKey(position);
        }
    }
}

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