Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock
In directory usw-pr-cvs1:/tmp/cvs-serv8794/DotNetMock
Modified Files:
DotNetMock.csproj ExpectationArrayList.cs
ExpectationCollection.cs
Added Files:
AbstractExpectationCollection.cs
Log Message:
Added AbstractExpectationCollection class
COmpleted ExpectationCollection interface
Refactored EcpectationArrayList class to utilize new abstract class
--- NEW FILE: AbstractExpectationCollection.cs ---
using System;
using System.Collections;
using NUnit.Framework;
namespace DotNetMock
{
/// <summary>
/// Summary description for AbstractExpectationCollection.
/// </summary>
public abstract class AbstractExpectationCollection : AbstractExpectation, ExpectationCollection
{
public AbstractExpectationCollection(string name) : base(name) {}
abstract protected void CheckImmediateValues(object actual);
abstract protected IList GetActualCollection();
abstract protected IList GetExpectedCollection();
public void AddActual(object actual)
{
GetActualCollection().Add(actual);
if (ShouldCheckImmediate)
{
CheckImmediateValues(actual);
}
}
public void AddActualMany(object[] actualMany)
{
for (int i = 0; i < actualMany.Length; i++)
{
AddActual(actualMany[i]);
}
}
public void AddActualMany(IEnumerable actualMany)
{
IEnumerator enumerator = actualMany.GetEnumerator();
while (enumerator.MoveNext())
{
AddActual(enumerator.Current);
}
}
public void AddActualMany(IList actualMany)
{
for (int i = 0; i < actualMany.Count; i++)
{
AddActual(actualMany[i]);
}
}
public void AddExpected(object expected)
{
GetExpectedCollection().Add(expected);
this.HasExpectations = true;
}
public void AddExpectedMany(object[] expectedMany)
{
for (int i = 0; i < expectedMany.Length; i++)
{
AddExpected(expectedMany[i]);
}
}
public void AddExpectedMany(IEnumerable expectedMany)
{
IEnumerator enumerator = expectedMany.GetEnumerator();
while (enumerator.MoveNext())
{
AddExpected(enumerator.Current);
}
}
public void AddExpectedMany(IList expectedMany)
{
for (int i = 0; i < expectedMany.Count; i++)
{
AddExpected(expectedMany[i]);
}
}
public override void ClearActual()
{
GetActualCollection().Clear();
}
public override void ClearExpected()
{
GetExpectedCollection().Clear();
}
public override void ExpectNothing()
{
ClearExpected();
this.HasExpectations = true;
}
public override void Verify()
{
for (int i = 0; i < GetActualCollection().Count; i++)
{
NUnit.Framework.Assertion.AssertEquals("Collection items not equal.", GetExpectedCollection()[i], GetActualCollection()[i]);
}
}
}
}
Index: DotNetMock.csproj
===================================================================
RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/DotNetMock.csproj,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** DotNetMock.csproj 21 Sep 2002 06:28:15 -0000 1.5
--- DotNetMock.csproj 25 Sep 2002 00:12:21 -0000 1.6
***************
*** 88,91 ****
--- 88,96 ----
/>
<File
+ RelPath = "AbstractExpectationCollection.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
RelPath = "AssemblyInfo.cs"
SubType = "Code"
***************
*** 129,132 ****
--- 134,142 ----
<File
RelPath = "Null.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "ReturnValue.cs"
SubType = "Code"
BuildAction = "Compile"
Index: ExpectationArrayList.cs
===================================================================
RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/ExpectationArrayList.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** ExpectationArrayList.cs 21 Sep 2002 06:19:18 -0000 1.4
--- ExpectationArrayList.cs 25 Sep 2002 00:12:21 -0000 1.5
***************
*** 6,105 ****
/// Summary description for ArrayList Expectation.
/// </summary>
! public class ExpectationArrayList : AbstractExpectation
{
private ArrayList _actualArrayList = null;
private ArrayList _expectedArrayList = null;
! public ExpectationArrayList(string name) : base(name) {}
! /// <summary>
! /// Gets/Sets actual array list.
! /// </summary>
! public ArrayList Actual
! {
! get { return this._actualArrayList; }
! set
! {
! CheckActual();
! foreach (Object obj in value)
! {
! this._actualArrayList.Add(obj);
! }
! }
}
! /// <summary>
! /// Gets/Sets expected array list.
! /// </summary>
! public ArrayList Expected
{
! get{ return this._expectedArrayList;}
! set
! {
! CheckExpected();
! foreach (Object obj in value)
! {
! this._expectedArrayList.Add(obj);
! }
!
! this.HasExpectations = true;
! }
! }
! /// <summary>
! /// Clears Actual array list.
! /// </summary>
! public override void ClearActual() {
! this._actualArrayList = null;
! }
! /// <summary>
! /// Clears Expected array list.
! /// </summary>
! public override void ClearExpected() {
! this._expectedArrayList = null;
! }
! /// <summary>
! /// Verifies Object.
! /// </summary>
! public override void Verify() {
!
! NUnit.Framework.Assertion.AssertEquals("Different lengths", this._expectedArrayList.Count, this._actualArrayList.Count);
! for (int i = 0; i < _expectedArrayList.Count; i++)
! {
! NUnit.Framework.Assertion.AssertEquals(this._expectedArrayList[i], this._actualArrayList[i]);
! }
! }
! /// <summary>
! /// Adds object to actual array list.
! /// </summary>
! /// <param name="actualObject">Object to add.</param>
! public void AddActual(Object actualObject) {
! CheckActual();
! this._actualArrayList.Add(actualObject);
! }
! /// <summary>
! /// Adds object to expected array list.
! /// </summary>
! /// <param name="expectedObject">Object to add.</param>
! public void AddExpected(Object expectedObject) {
! CheckExpected();
! this._expectedArrayList.Add(expectedObject);
}
! /// <summary>
! /// Checks if actual arraylist exists yet.
! /// </summary>
! private void CheckActual()
{
! if (this._actualArrayList == null)
! {
! this._actualArrayList = new ArrayList();
! }
}
! /// <summary>
! /// Checks if expected arraylist exists yet.
! /// </summary>
! private void CheckExpected()
{
! if (this._expectedArrayList == null)
! {
! this._expectedArrayList = new ArrayList();
! }
}
}
--- 6,32 ----
/// Summary description for ArrayList Expectation.
/// </summary>
! public class ExpectationArrayList : AbstractExpectationCollection
{
private ArrayList _actualArrayList = null;
private ArrayList _expectedArrayList = null;
! public ExpectationArrayList(string name) : base(name) {
! _actualArrayList = new ArrayList();
! _expectedArrayList = new ArrayList();
}
!
! protected override IList GetActualCollection()
{
! return _actualArrayList;
}
! protected override IList GetExpectedCollection()
{
! return _expectedArrayList;
}
! protected override void CheckImmediateValues(object actual)
{
! int size = _actualArrayList.Count;
! NUnit.Framework.Assertion.Assert(_expectedArrayList.Count >= size);
! NUnit.Framework.Assertion.AssertEquals(_expectedArrayList[size -1], actual);
}
}
Index: ExpectationCollection.cs
===================================================================
RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/ExpectationCollection.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ExpectationCollection.cs 23 Sep 2002 20:13:26 -0000 1.3
--- ExpectationCollection.cs 25 Sep 2002 00:12:21 -0000 1.4
***************
*** 13,21 ****
--- 13,51 ----
/// <param name="actual">object to add</param>
void AddActual(object actual);
+ /// <summary>
+ /// Adds an array of objects to actual collection
+ /// </summary>
+ /// <param name="actualMany">array of objects to add</param>
void AddActualMany(object[] actualMany);
+ /// <summary>
+ /// Adds a Collection that implements the IEnumerable interface to actual collection
+ /// </summary>
+ /// <param name="actualMany"></param>
+ void AddActualMany(IEnumerable actualMany);
+ /// <summary>
+ /// Adds the elements of an object that implements IList to the actual collection
+ /// </summary>
+ /// <param name="actualMany"></param>
void AddActualMany(IList actualMany);
+ /// <summary>
+ /// Adds object to expected collection
+ /// </summary>
+ /// <param name="expected"></param>
void AddExpected(object expected);
+ /// <summary>
+ /// Adds an array of objects to expected collection
+ /// </summary>
+ /// <param name="expectedMany"></param>
void AddExpectedMany(object[] expectedMany);
+ /// <summary>
+ /// Adds a Collection that implements the IEnumerable interface to expected collection
+ /// </summary>
+ /// <param name="expectedMany"></param>
+ void AddExpectedMany(IEnumerable expectedMany);
+ /// <summary>
+ /// Adds the elements of an object that implements IList to the expected collection
+ /// </summary>
+ /// <param name="expectedMany"></param>
void AddExpectedMany(IList expectedMany);
}
|