From: <gc...@us...> - 2003-03-11 20:30:58
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Framework/Xml/XPath In directory sc8-pr-cvs1:/tmp/cvs-serv20785/DotNetMock.Framework/Xml/XPath Added Files: MockXPathNavigable.cs Log Message: --- NEW FILE: MockXPathNavigable.cs --- using System; using System.Xml; using System.Xml.XPath; using DotNetMock; namespace DotNetMock.Xml.XPath { /// <summary> /// Mock Object implementing IXPathNavigable interface /// </summary> public class MockXPathNavigable : MockObject, IXPathNavigable { /// <summary> /// Number of CreateNavigator() calls to expect /// </summary> private ExpectationCounter _createNavigatorCalls = new ExpectationCounter("MockXPathNavigable.CreateNavigatorCount"); /// <summary> /// Exception to throw on CreateNavigator() call /// </summary> private Exception _expectedException = null; /// <summary> /// XPathNavigator to be returned by a CreateNavigator() call /// </summary> private XPathNavigator _expectedNavigator = null; /// <summary> /// Private, internal class that provides empty implementation of the XPathNavigator abstract /// class. If no XPathNavigator is supplied to be returned, then a empty instance of /// DummyXPathNavigator will be returned /// </summary> private class DummyXPathNavigator : XPathNavigator { public override string BaseURI { get { return null; } } public override System.Xml.XPath.XPathNavigator Clone() { return null; } public override string GetAttribute(string localName, string namespaceURI) { return null; } public override string GetNamespace(string name) { return null; } public override bool HasAttributes { get { return true; } } public override bool HasChildren { get { return true; } } public override bool IsEmptyElement { get { return true; } } public override bool IsSamePosition(System.Xml.XPath.XPathNavigator other) { return true; } public override string LocalName { get { return null; } } public override bool MoveTo(System.Xml.XPath.XPathNavigator other) { return true; } public override bool MoveToAttribute(string localName, string namespaceURI) { return true; } public override bool MoveToFirst() { return true; } public override bool MoveToFirstAttribute() { return true; } public override bool MoveToFirstChild() { return true; } public override bool MoveToFirstNamespace(System.Xml.XPath.XPathNamespaceScope namespaceScope) { return true; } public override bool MoveToId(string id) { return true; } public override bool MoveToNamespace(string name) { return true; } public override bool MoveToNext() { return true; } public override bool MoveToNextAttribute() { return true; } public override bool MoveToNextNamespace(System.Xml.XPath.XPathNamespaceScope namespaceScope) { return true; } public override bool MoveToParent() { return true; } public override void MoveToRoot() { } public override string Name { get { return null; } } public override string NamespaceURI { get { return null; } } public override System.Xml.XmlNameTable NameTable { get { return null; } } public override System.Xml.XPath.XPathNodeType NodeType { get { return new System.Xml.XPath.XPathNodeType(); } } public override string Prefix { get { return null; } } public override string Value { get { return null; } } public override string XmlLang { get { return null; } } public override bool MoveToPrevious() { return true; } } /// <summary> /// Default Constructor. /// </summary> public MockXPathNavigable() { this.name = "MockXPathNavigable"; } #region Mock Methods /// <summary> /// Sets exception to throw on CreateNavigator() calls /// </summary> /// <param name="expected">Excepiton to throw</param> public void SetCreateException( Exception expected ) { _expectedException = expected; } /// <summary> /// Sets number of CreateNavigator() calls to expect /// </summary> /// <param name="count">Calls to expect</param> public void SetExpectedCreateCount( int count ) { _createNavigatorCalls.Expected = count; } /// <summary> /// Sets instance of an XPathNavigator subclass to return on CreateNavigator() calls /// </summary> /// <param name="navigator">XPathNavigator subclass to return</param> public void SetExpectedNavigator( XPathNavigator navigator ) { _expectedNavigator = navigator; } #endregion #region Implementation of IXPathNavigable /// <summary> /// 1) Increments the number of CreateNavigator() calls /// 2) If there is an exception to throw, it is thrown /// 3) If there is an expected XPathNavigator to return, it is returned /// 4) Otherwise, a default empty <seealso cref="DummyXPathNavigator">DummyXPathNavigator</seealso> is returned /// </summary> /// <returns></returns> public System.Xml.XPath.XPathNavigator CreateNavigator() { _createNavigatorCalls.Inc(); if ( _expectedException != null ) { throw _expectedException; } if ( _expectedNavigator != null ) { return _expectedNavigator; } else { return (XPathNavigator) new DummyXPathNavigator(); } } #endregion } } |