From: <gc...@us...> - 2003-04-07 00:44:01
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Framework/Xml/XPath In directory sc8-pr-cvs1:/tmp/cvs-serv23859/DotNetMock.Framework/Xml/XPath Added Files: MockXPathDocument.cs MockXPathNavigator.cs MockXPathNodeIterator.cs Log Message: Added Mock Objects for System.Xml.XPath namespace: XPathDocument, XPathNavigator, XPathNodeIterator Added MockObject & NUnitTest wizards Added nunit.framework.dll to distribution Fixed Master build install of VisualStudioTemplates Added various comments and XML documentation to various classes --- NEW FILE: MockXPathDocument.cs --- /* * ============================================================================ * The Apache Software License, Version 1.1 * ============================================================================ * * Copyright (C) 1999 The Apache Software Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. The end-user documentation included with the redistribution, if any, must * include the following acknowledgment: "This product includes software * developed by the Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, if * and wherever such third-party acknowledgments normally appear. * * 4. The names "log4j" and "Apache Software Foundation" must not be used to * endorse or promote products derived from this software without prior * written permission. For written permission, please contact * ap...@ap.... * * 5. Products derived from this software may not be called "Apache", nor may * "Apache" appear in their name, without prior written permission of the * Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many individuals * on behalf of the Apache Software Foundation. For more information on the * Apache Software Foundation, please see <http://www.apache.org/>. * */ using System; using System.Xml; using System.Xml.XPath; using DotNetMock; namespace DotNetMock.Framework.Xml.XPath { /// <summary> /// Mock Object implementing extending the XPathDocument class /// </summary> public class MockXPathDocument : XPathDocument, IMockObject { private string name = ""; /// <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> /// Default Constructor. /// </summary> public MockXPathDocument( ) : base("../DotNetMock.Master.build") { this.name = "MockXPathDocument"; } #region Mock Methods /// <summary> /// Sets exception to throw on CreateNavigator() calls /// </summary> /// <param name="expected">Excepiton to throw</param> public void SetExpectedCreateException( Exception expected ) { _expectedException = expected; } /// <summary> /// Sets number of CreateNavigator() calls to expect /// </summary> /// <param name="count">Calls to expect</param> public void SetExpectedCreateCalls( 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="MockXPathNavigator">MockXPathNavigator</seealso> is returned /// </summary> /// <returns></returns> public new System.Xml.XPath.XPathNavigator CreateNavigator() { _createNavigatorCalls.Inc(); if ( _expectedException != null ) { throw _expectedException; } if ( _expectedNavigator != null ) { return _expectedNavigator; } else { return (XPathNavigator) new MockXPathNavigator(); } } #endregion #region Implementation of IMockObject public void NotImplemented(string methodName) { throw new NotImplementedException(methodName + " is currently not implemented."); } public string MockName { get { return name; } set { name = value; } } #endregion #region Implementation of IVerifiable public void Verify() { Verifier.Verify( this ); } #endregion } } --- NEW FILE: MockXPathNavigator.cs --- using System; using System.Xml.XPath; using DotNetMock; namespace DotNetMock.Framework.Xml.XPath { public class MockXPathNavigator : XPathNavigator, IMockObject { /// <summary> /// Mock Object name /// </summary> private string name = ""; /// <summary> /// Expected number of Select*() calls /// </summary> private ExpectationCounter _selectCalls = new ExpectationCounter("MockXPathNavigator.SelectCalls"); /// <summary> /// Expected Exception to be thrown for Select*() calls /// </summary> private Exception _expectedException = null; /// <summary> /// Expected MockXPathNodeIterator to return /// </summary> private MockXPathNodeIterator _iterator = new MockXPathNodeIterator(); public MockXPathNavigator() { this.name = "MockXPathNavigator"; } #region Mock Methods public void SetExpectedIterator( MockXPathNodeIterator iterator ) { _iterator = iterator; } public void SetExpectedSelectCalls( int selectCalls ) { _selectCalls.Expected = selectCalls; } public void SetExpectedException( Exception exception ) { _expectedException = exception; } #endregion #region Overrides of XPathNavigator public override string BaseURI { get { NotImplemented("MockXPathNavigator.BaseURI"); return null; } } public override System.Xml.XPath.XPathNavigator Clone() { NotImplemented("MockXPathNavigator.Clone"); return null; } public override string GetAttribute(string localName, string namespaceURI) { NotImplemented("MockXPathNavigator.GetAttribute"); return null; } public override string GetNamespace(string name) { NotImplemented("MockXPathNavigator.GetNamespace"); return null; } public override bool HasAttributes { get { NotImplemented("MockXPathNavigator.HasAttributes"); return false; } } public override bool HasChildren { get { NotImplemented("MockXPathNavigator.HasChildren"); return false; } } public override bool IsEmptyElement { get { NotImplemented("MockXPathNavigator.IsEmptyElement"); return false; } } public override bool IsSamePosition(System.Xml.XPath.XPathNavigator other) { NotImplemented("MockXPathNavigator.IsSamePosition"); return false; } public override string LocalName { get { NotImplemented("MockXPathNavigator.LocalName"); return null; } } public override bool MoveTo(System.Xml.XPath.XPathNavigator other) { NotImplemented("MockXPathNavigator.MoveTo"); return false; } public override bool MoveToAttribute(string localName, string namespaceURI) { NotImplemented("MockXPathNavigator.MoveToAttribute"); return false; } public override bool MoveToFirst() { NotImplemented("MockXPathNavigator.MoveToFirst"); return false; } public override bool MoveToFirstAttribute() { NotImplemented("MockXPathNavigator.MoveToFirstAttribute"); return false; } public override bool MoveToFirstChild() { NotImplemented("MockXPathNavigator.MoveToFirstChild"); return false; } public override bool MoveToFirstNamespace(System.Xml.XPath.XPathNamespaceScope namespaceScope) { NotImplemented("MockXPathNavigator.MoveToFirstNamespace"); return false; } public override bool MoveToId(string id) { NotImplemented("MockXPathNavigator.MoveToId"); return false; } public override bool MoveToNamespace(string name) { NotImplemented("MockXPathNavigator.MoveToNamespace"); return false; } public override bool MoveToNext() { NotImplemented("MockXPathNavigator.MoveToNext"); return false; } public override bool MoveToNextAttribute() { NotImplemented("MockXPathNavigator.MoveToNextAttribute"); return false; } public override bool MoveToNextNamespace(System.Xml.XPath.XPathNamespaceScope namespaceScope) { NotImplemented("MockXPathNavigator.MoveToNextNamespace"); return false; } public override bool MoveToParent() { NotImplemented("MockXPathNavigator.MoveToParent"); return false; } public override void MoveToRoot() { NotImplemented("MockXPathNavigator.MoveToRoot"); } public override string Name { get { NotImplemented("MockXPathNavigator.Name"); return null; } } public override string NamespaceURI { get { NotImplemented("MockXPathNavigator.NamespaceURI"); return null; } } public override System.Xml.XmlNameTable NameTable { get { NotImplemented("MockXPathNavigator.NameTable"); return null; } } public override System.Xml.XPath.XPathNodeType NodeType { get { NotImplemented("MockXPathNavigator.NodeType"); return XPathNodeType.All; } } public override string Prefix { get { NotImplemented("MockXPathNavigator.Prefix"); return null; } } public override string Value { get { NotImplemented("MockXPathNavigator.Value"); return null; } } public override string XmlLang { get { NotImplemented("MockXPathNavigator.XmlLang"); return null; } } public override bool MoveToPrevious() { NotImplemented("MockXPathNavigator.MoveToPrevious"); return false; } public override System.Xml.XPath.XPathNodeIterator Select(string xpath) { innerExecute(); return _iterator; } public override System.Xml.XPath.XPathNodeIterator Select(System.Xml.XPath.XPathExpression expr) { innerExecute(); return _iterator; } public override System.Xml.XPath.XPathNodeIterator SelectAncestors(string name, string namespaceURI, bool matchSelf) { innerExecute(); return _iterator; } public override System.Xml.XPath.XPathNodeIterator SelectAncestors(System.Xml.XPath.XPathNodeType type, bool matchSelf) { innerExecute(); return _iterator; } public override System.Xml.XPath.XPathNodeIterator SelectChildren(string name, string namespaceURI) { innerExecute(); return _iterator; } public override System.Xml.XPath.XPathNodeIterator SelectChildren(System.Xml.XPath.XPathNodeType type) { innerExecute(); return _iterator; } public override System.Xml.XPath.XPathNodeIterator SelectDescendants(string name, string namespaceURI, bool matchSelf) { innerExecute(); return _iterator; } public override System.Xml.XPath.XPathNodeIterator SelectDescendants(System.Xml.XPath.XPathNodeType type, bool matchSelf) { innerExecute(); return _iterator; } private void innerExecute() { _selectCalls.Inc(); if (_expectedException != null) { throw _expectedException; } } #endregion #region Implementation of IMockObject public void NotImplemented(string methodName) { throw new NotImplementedException(methodName + " is currently not implemented."); } public string MockName { get { return name; } set { name = value; } } #endregion #region Implementation of IVerifiable public void Verify() { Verifier.Verify(this); } #endregion } } --- NEW FILE: MockXPathNodeIterator.cs --- using System; using System.Collections; using System.Xml.XPath; using DotNetMock; namespace DotNetMock.Framework.Xml.XPath { /// <summary> /// MockObject that extends the XPathNodeIterator class and implements the IMockObject interface /// </summary> public class MockXPathNodeIterator : XPathNodeIterator, IMockObject { private ExpectationCounter _moveNextCalls = new ExpectationCounter("MockXPathNodeIterator.MoveNextCalls"); private ArrayList _currentData = null; private int _currentPosition = 0; private string name = ""; /// <summary> /// Default Constructor. Sets the name of the object to "MockXPathNodeIterator" /// </summary> public MockXPathNodeIterator() { name = "MockXPathNodeIterator"; _currentData = new ArrayList(); } #region Mock Methods /// <summary> /// Sets the number of MoveNext() calls to expect /// </summary> /// <param name="count">Number of calls</param> public void SetExpectedMoveNextCalls( int count ) { _moveNextCalls.Expected = count; } /// <summary> /// Sets the collection of data to iterate over; /// </summary> /// <param name="data">Data to use</param> public void SetExpectedData( ArrayList data ) { _currentData = data; } #endregion #region Implementation of IMockObject /// <summary> /// Throws NotImplementedException() /// </summary> /// <param name="className">Method name that is not implemented</param> public void NotImplemented(string methodName) { throw new NotImplementedException(methodName + " is currently not implemented."); } /// <summary> /// Gets/Sets the Mock's name /// </summary> public string MockName { get { return name; } set { name = value; } } /// <summary> /// Verify the MockObject /// </summary> public void Verify() { Verifier.Verify( this ); } #endregion #region Overrides of XPathNodeIterator /// <summary> /// Clones the current XPathNodeIterator. Currently not implemented. /// </summary> /// <returns>Clone of the current XPathNodeIterator</returns> public override System.Xml.XPath.XPathNodeIterator Clone() { NotImplemented("MockXPathNodeIterator.Clone"); return null; } /// <summary> /// Moves to the next node in the selected set. /// </summary> /// <returns>True/False if there this is a valid move</returns> public override bool MoveNext() { _moveNextCalls.Inc(); if (_currentPosition < _currentData.Count) { _currentPosition++; return true; } else { return false; } } /// <summary> /// Gets the index of the alst node in the selected set of nodes. /// </summary> public override int Count { get { return _currentData.Count; } } /// <summary> /// Gets the Navigator position on the current node. /// </summary> public override System.Xml.XPath.XPathNavigator Current { get { return (XPathNavigator)_currentData[_currentPosition - 1]; } } /// <summary> /// Gets the index of the current position in the selected set of nodes. /// </summary> public override int CurrentPosition { get { return _currentPosition; } } #endregion } } |