This list is closed, nobody may subscribe to it.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(99) |
Feb
(163) |
Mar
(3) |
Apr
(33) |
May
(8) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2006 |
Jan
|
Feb
|
Mar
(10) |
Apr
|
May
|
Jun
(16) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Choy R. <ch...@us...> - 2005-02-20 09:26:59
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Predicates In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15950/DotNetMock/Dynamic/Predicates Modified Files: AndPredicate.cs IsAnything.cs IsCloseTo.cs IsEqual.cs IsEqualIgnoreCase.cs IsEqualIgnoreWhiteSpace.cs IsIn.cs IsMatch.cs IsNull.cs IsTypeOf.cs NotEqual.cs NotIn.cs NotNull.cs NotPredicate.cs OrPredicate.cs Predicate.cs Added Files: AbstractPredicate.cs Log Message: Make sure all Predicates support the ability to describe their evaluation expression through the ExpressionAsText(name) method. The name parameter is so that in the future we can include the name of the parameter that didn't satisfy the predicate in our assertion failure messages. Index: AndPredicate.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Predicates/AndPredicate.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AndPredicate.cs 1 Jan 2005 21:13:54 -0000 1.4 --- AndPredicate.cs 20 Feb 2005 09:26:49 -0000 1.5 *************** *** 1,29 **** namespace DotNetMock.Dynamic.Predicates { /// <summary> ! /// Represets a <see cref="IPredicate"/> that expects a value to satisfy two predicates. /// </summary> ! public class AndPredicate : IPredicate { ! private IPredicate p1, p2; /// <summary> /// Default Constructor /// </summary> ! /// <param name="p1">first <see cref="IPredicate"/></param> ! /// <param name="p2">first <see cref="IPredicate"/></param> ! public AndPredicate(IPredicate p1, IPredicate p2) { ! this.p1 = p1; ! this.p2 = p2; } /// <summary> /// Evaluates the input value against both <see cref="IPredicate"/>s /// </summary> ! /// <param name="currentValue">Value to evaluate</param> /// <returns>True if the input value satisfies both <see cref="IPredicate"/> instances</returns> ! public bool Eval(object currentValue) { ! return p1.Eval(currentValue) && p2.Eval(currentValue); } } } --- 1,49 ---- + #region License + // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. + #endregion + #region Imports + using System; + #endregion + namespace DotNetMock.Dynamic.Predicates { /// <summary> ! /// A <see cref="IPredicate"/> that expects a value to satisfy two predicates. /// </summary> ! public class AndPredicate : AbstractPredicate { ! private IPredicate _lhs, _rhs; /// <summary> /// Default Constructor /// </summary> ! /// <param name="_lhs">first <see cref="IPredicate"/></param> ! /// <param name="_rhs">first <see cref="IPredicate"/></param> ! public AndPredicate(IPredicate _lhs, IPredicate _rhs) { ! this._lhs = _lhs; ! this._rhs = _rhs; } /// <summary> /// Evaluates the input value against both <see cref="IPredicate"/>s /// </summary> ! /// <param name="inputValue">Value to evaluate</param> /// <returns>True if the input value satisfies both <see cref="IPredicate"/> instances</returns> ! public override bool Eval(object inputValue) { ! return _lhs.Eval(inputValue) && _rhs.Eval(inputValue); } + /// <summary> + /// Text representation of what is evaluated by the + /// <see cref="Eval"/> method. + /// </summary> + public override string ExpressionAsText(string name) + { + return String.Format( + "({0}) and ({1})", + _lhs.ExpressionAsText(name), + _rhs.ExpressionAsText(name) + ); + } + } } Index: IsTypeOf.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Predicates/IsTypeOf.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** IsTypeOf.cs 1 Jan 2005 21:13:54 -0000 1.3 --- IsTypeOf.cs 20 Feb 2005 09:26:49 -0000 1.4 *************** *** 1,3 **** --- 1,8 ---- + #region License + // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. + #endregion + #region Imports using System; + #endregion namespace DotNetMock.Dynamic.Predicates *************** *** 6,10 **** /// <see cref="IPredicate"/> that evaluates the input value against the expected <see cref="Type"/> /// </summary> ! public class IsTypeOf : IPredicate { private Type _type; --- 11,15 ---- /// <see cref="IPredicate"/> that evaluates the input value against the expected <see cref="Type"/> /// </summary> ! public class IsTypeOf : AbstractPredicate { private Type _type; *************** *** 22,29 **** /// <param name="currentValue">input value</param> /// <returns>True if the original type is assignable from the input value, false otherwise.</returns> ! public bool Eval(object currentValue) { return currentValue == null ? false : _type.IsAssignableFrom(currentValue.GetType()); } } } --- 27,46 ---- /// <param name="currentValue">input value</param> /// <returns>True if the original type is assignable from the input value, false otherwise.</returns> ! public override bool Eval(object currentValue) { return currentValue == null ? false : _type.IsAssignableFrom(currentValue.GetType()); } + /// <summary> + /// Text representation of what is evaluated by the + /// <see cref="Eval"/> method. + /// </summary> + public override string ExpressionAsText(string name) + { + return String.Format( + "{0} is a {1}", + name, + _type.FullName + ); + } } } --- NEW FILE: AbstractPredicate.cs --- #region License // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. #endregion #region Imports using System; using System.Collections; #endregion namespace DotNetMock.Dynamic.Predicates { /// <summary> /// Abstract base class for all predicates. /// </summary> public abstract class AbstractPredicate : IPredicate { /// <summary> /// Evaluates whether input value satisfies this predicate. /// </summary> /// <param name="inputValue">input value</param> /// <returns>true if the predicate was satisfied</returns> public abstract bool Eval(object inputValue); /// <summary> /// Text representation of what is evaluated by the /// <see cref="Eval"/> method. /// </summary> /// <param name="name"> /// name of value/variable to use in the expression text /// </param> /// <returns>text representation of this predicate</returns> public virtual string ExpressionAsText(string name) { return "(N/A)"; } /// <summary> /// Returns a <see cref="String"/> that represents the /// expression evaluated by this <see cref="IPredicate"/>. /// </summary> /// <returns> /// Expression evaluated by this predicate. /// </returns> public override string ToString() { return ExpressionAsText("value"); } } } Index: IsIn.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Predicates/IsIn.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** IsIn.cs 1 Jan 2005 21:13:54 -0000 1.3 --- IsIn.cs 20 Feb 2005 09:26:49 -0000 1.4 *************** *** 1,4 **** --- 1,11 ---- + #region License + // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. + #endregion + #region Imports using System; + using DotNetMock.Util; + #endregion + namespace DotNetMock.Dynamic.Predicates { *************** *** 6,10 **** /// <see cref="IPredicate"/> that looks for an input value in an array of values. /// </summary> ! public class IsIn : IPredicate { private object[] _inList; --- 13,17 ---- /// <see cref="IPredicate"/> that looks for an input value in an array of values. /// </summary> ! public class IsIn : AbstractPredicate { private object[] _inList; *************** *** 31,35 **** /// <param name="inputValue">input value to look for</param> /// <returns>True if the input value is found, false otherwise.</returns> ! public bool Eval(object inputValue) { foreach (object o in _inList) --- 38,42 ---- /// <param name="inputValue">input value to look for</param> /// <returns>True if the input value is found, false otherwise.</returns> ! public override bool Eval(object inputValue) { foreach (object o in _inList) *************** *** 42,45 **** --- 49,64 ---- return false; } + /// <summary> + /// Text representation of what is evaluated by the + /// <see cref="Eval"/> method. + /// </summary> + public override string ExpressionAsText(string name) + { + return String.Format( + "{0} is in [{1}]", + name, + StringUtils.FormatArray(_inList) + ); + } } } Index: IsMatch.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Predicates/IsMatch.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** IsMatch.cs 1 Jan 2005 21:13:54 -0000 1.3 --- IsMatch.cs 20 Feb 2005 09:26:49 -0000 1.4 *************** *** 1,4 **** --- 1,9 ---- + #region License + // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. + #endregion + #region Imports using System; using System.Text.RegularExpressions; + #endregion namespace DotNetMock.Dynamic.Predicates *************** *** 7,11 **** /// <see cref="IPredicate"/> that compares the input value against an regular expression pattern. /// </summary> ! public class IsMatch : IPredicate { private Regex _regex; --- 12,16 ---- /// <see cref="IPredicate"/> that compares the input value against an regular expression pattern. /// </summary> ! public class IsMatch : AbstractPredicate { private Regex _regex; *************** *** 34,41 **** /// <param name="inputValue">input value</param> /// <returns>True if the regular expression matches the input value, flase otherwise.</returns> ! public bool Eval(object inputValue) { return inputValue == null ? false : _regex.IsMatch(inputValue.ToString()); } } } --- 39,58 ---- /// <param name="inputValue">input value</param> /// <returns>True if the regular expression matches the input value, flase otherwise.</returns> ! public override bool Eval(object inputValue) { return inputValue == null ? false : _regex.IsMatch(inputValue.ToString()); } + /// <summary> + /// Text representation of what is evaluated by the + /// <see cref="Eval"/> method. + /// </summary> + public override string ExpressionAsText(string name) + { + return String.Format( + "{0} matches /{1}/", + name, + _regex + ); + } } } Index: NotEqual.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Predicates/NotEqual.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NotEqual.cs 1 Jan 2005 21:13:54 -0000 1.3 --- NotEqual.cs 20 Feb 2005 09:26:49 -0000 1.4 *************** *** 1,2 **** --- 1,11 ---- + #region License + // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. + #endregion + #region Imports + using System; + + using DotNetMock.Util; + #endregion + namespace DotNetMock.Dynamic.Predicates { *************** *** 4,10 **** /// <see cref="IPredicate"/> that verifies the input value is not equal to the original value. /// </summary> ! public class NotEqual : IPredicate { private IPredicate p; /// <summary> /// Default Constructor --- 13,20 ---- /// <see cref="IPredicate"/> that verifies the input value is not equal to the original value. /// </summary> ! public class NotEqual : AbstractPredicate { private IPredicate p; + object _rhs; /// <summary> /// Default Constructor *************** *** 13,16 **** --- 23,27 ---- public NotEqual(object compare) { + _rhs = compare; p = new NotPredicate(new IsEqual(compare)); } *************** *** 20,27 **** /// <param name="inputValue">input value</param> /// <returns>True if the input value does not equal the original value, false otherwise.</returns> ! public bool Eval(object inputValue) { return p.Eval(inputValue); } } } --- 31,50 ---- /// <param name="inputValue">input value</param> /// <returns>True if the input value does not equal the original value, false otherwise.</returns> ! public override bool Eval(object inputValue) { return p.Eval(inputValue); } + /// <summary> + /// Text representation of what is evaluated by the + /// <see cref="Eval"/> method. + /// </summary> + public override string ExpressionAsText(string name) + { + return String.Format( + "{0} is not equal to {1}", + name, + StringUtils.FormatScalar(_rhs) + ); + } } } Index: IsEqual.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Predicates/IsEqual.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** IsEqual.cs 16 Feb 2005 10:39:26 -0000 1.6 --- IsEqual.cs 20 Feb 2005 09:26:49 -0000 1.7 *************** *** 1,4 **** --- 1,11 ---- + #region License + // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. + #endregion + #region Imports using System; + using DotNetMock.Util; + #endregion + namespace DotNetMock.Dynamic.Predicates { *************** *** 6,10 **** /// <see cref="IPredicate"/> comparing two values /// </summary> ! public class IsEqual : IPredicate { private object _compare; --- 13,17 ---- /// <see cref="IPredicate"/> comparing two values /// </summary> ! public class IsEqual : AbstractPredicate { private object _compare; *************** *** 17,30 **** _compare = compare; } - - /// <summary> - /// The condition this evaluates as text. - /// </summary> - /// <returns>"value equals (xxx)"</returns> - public override string ToString() - { - return String.Format("value equals ({0})", _compare); - } - /// <summary> /// Evaluates input value against original value for equality --- 24,27 ---- *************** *** 32,36 **** /// <param name="inputValue">input value</param> /// <returns>True if input value equals original value, false otherwise.</returns> ! public bool Eval(object inputValue) { if ( ( inputValue == null ) & ( _compare != null ) ) --- 29,33 ---- /// <param name="inputValue">input value</param> /// <returns>True if input value equals original value, false otherwise.</returns> ! public override bool Eval(object inputValue) { if ( ( inputValue == null ) & ( _compare != null ) ) *************** *** 72,75 **** --- 69,85 ---- } } + /// <summary> + /// Text representation of what is evaluated by the + /// <see cref="Eval"/> method. + /// </summary> + public override string ExpressionAsText(string name) + { + return String.Format( + "{0} equals {1}", + name, + StringUtils.FormatScalar(_compare) + ); + } + } } Index: IsEqualIgnoreCase.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Predicates/IsEqualIgnoreCase.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** IsEqualIgnoreCase.cs 1 Jan 2005 21:13:54 -0000 1.3 --- IsEqualIgnoreCase.cs 20 Feb 2005 09:26:49 -0000 1.4 *************** *** 1,3 **** --- 1,9 ---- + #region License + // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. + #endregion + #region Imports + using System; using System.Globalization; + #endregion namespace DotNetMock.Dynamic.Predicates *************** *** 6,12 **** /// <see cref="IPredicate"/> comparing strings while ignoring case /// </summary> ! public class IsEqualIgnoreCase : IPredicate { ! private IPredicate _originalPredicate; /// <summary> /// Default Constructor --- 12,18 ---- /// <see cref="IPredicate"/> comparing strings while ignoring case /// </summary> ! public class IsEqualIgnoreCase : AbstractPredicate { ! private IsEqual _isEqual; /// <summary> /// Default Constructor *************** *** 15,19 **** public IsEqualIgnoreCase(object compare) { ! _originalPredicate = new IsEqual(compare.ToString().ToLower(CultureInfo.CurrentCulture)); } /// <summary> --- 21,25 ---- public IsEqualIgnoreCase(object compare) { ! _isEqual = new IsEqual(compare.ToString().ToLower(CultureInfo.CurrentCulture)); } /// <summary> *************** *** 22,28 **** /// <param name="inputValue">Input value</param> /// <returns>True if input value equals original value</returns> ! public bool Eval(object inputValue) { ! return _originalPredicate.Eval(inputValue.ToString().ToLower(CultureInfo.CurrentCulture)); } } --- 28,45 ---- /// <param name="inputValue">Input value</param> /// <returns>True if input value equals original value</returns> ! public override bool Eval(object inputValue) { ! return _isEqual.Eval(inputValue.ToString().ToLower(CultureInfo.CurrentCulture)); ! } ! /// <summary> ! /// Text representation of what is evaluated by the ! /// <see cref="Eval"/> method. ! /// </summary> ! public override string ExpressionAsText(string name) ! { ! return String.Format( ! "{0} (ignore case)", ! _isEqual.ExpressionAsText(name) ! ); } } Index: NotNull.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Predicates/NotNull.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NotNull.cs 1 Jan 2005 21:13:54 -0000 1.3 --- NotNull.cs 20 Feb 2005 09:26:49 -0000 1.4 *************** *** 1,2 **** --- 1,9 ---- + #region License + // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. + #endregion + #region Imports + using System; + #endregion + namespace DotNetMock.Dynamic.Predicates { *************** *** 4,8 **** /// <see cref="IPredicate"/> that verifies that the input value is null. Opposite of <see cref="IsNull"/>. /// </summary> ! public class NotNull : IPredicate { /// <summary> --- 11,15 ---- /// <see cref="IPredicate"/> that verifies that the input value is null. Opposite of <see cref="IsNull"/>. /// </summary> ! public class NotNull : AbstractPredicate { /// <summary> *************** *** 11,18 **** /// <param name="inputValue">input value</param> /// <returns>True if the input value is not null, false otherwise.</returns> ! public bool Eval(object inputValue) { return inputValue != null; } } } --- 18,36 ---- /// <param name="inputValue">input value</param> /// <returns>True if the input value is not null, false otherwise.</returns> ! public override bool Eval(object inputValue) { return inputValue != null; } + /// <summary> + /// Text representation of what is evaluated by the + /// <see cref="Eval"/> method. + /// </summary> + public override string ExpressionAsText(string name) + { + return String.Format( + "{0} is not null", + name + ); + } } } Index: Predicate.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Predicates/Predicate.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Predicate.cs 1 Jan 2005 21:13:54 -0000 1.3 --- Predicate.cs 20 Feb 2005 09:26:49 -0000 1.4 *************** *** 4,8 **** /// <see cref="IPredicate"/> that accepts a reference to the a delegate instance that performs the evaluation. /// </summary> ! public class Predicate : IPredicate { /// <summary> --- 4,8 ---- /// <see cref="IPredicate"/> that accepts a reference to the a delegate instance that performs the evaluation. /// </summary> ! public class Predicate : AbstractPredicate { /// <summary> *************** *** 25,29 **** /// <param name="currentValue">input value</param> /// <returns>The results of the delegation methods evaluation</returns> ! public bool Eval(object currentValue) { return _evaluationMethod(currentValue); --- 25,29 ---- /// <param name="currentValue">input value</param> /// <returns>The results of the delegation methods evaluation</returns> ! public override bool Eval(object currentValue) { return _evaluationMethod(currentValue); Index: NotPredicate.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Predicates/NotPredicate.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NotPredicate.cs 1 Jan 2005 21:13:54 -0000 1.3 --- NotPredicate.cs 20 Feb 2005 09:26:49 -0000 1.4 *************** *** 1,2 **** --- 1,9 ---- + #region License + // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. + #endregion + #region Imports + using System; + #endregion + namespace DotNetMock.Dynamic.Predicates { *************** *** 4,8 **** /// <see cref="IPredicate"/> that is used to wrap other <see cref="IPredicate"/> objects, and invert their results. /// </summary> ! public class NotPredicate : IPredicate { private IPredicate _wrappedPredicate; --- 11,15 ---- /// <see cref="IPredicate"/> that is used to wrap other <see cref="IPredicate"/> objects, and invert their results. /// </summary> ! public class NotPredicate : AbstractPredicate { private IPredicate _wrappedPredicate; *************** *** 20,27 **** /// <param name="inputValue">input value</param> /// <returns>The opposite ( ! ) of the original <see cref="IPredicate"/>s evaluation.</returns> ! public bool Eval(object inputValue) { return !_wrappedPredicate.Eval(inputValue); } } } --- 27,45 ---- /// <param name="inputValue">input value</param> /// <returns>The opposite ( ! ) of the original <see cref="IPredicate"/>s evaluation.</returns> ! public override bool Eval(object inputValue) { return !_wrappedPredicate.Eval(inputValue); } + /// <summary> + /// Text representation of what is evaluated by the + /// <see cref="Eval"/> method. + /// </summary> + public override string ExpressionAsText(string name) + { + return String.Format( + "not ({0})", + _wrappedPredicate.ExpressionAsText(name) + ); + } } } Index: IsCloseTo.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Predicates/IsCloseTo.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** IsCloseTo.cs 1 Jan 2005 21:13:54 -0000 1.4 --- IsCloseTo.cs 20 Feb 2005 09:26:49 -0000 1.5 *************** *** 1,4 **** --- 1,9 ---- + #region License + // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. + #endregion + #region Imports using System; using System.Globalization; + #endregion namespace DotNetMock.Dynamic.Predicates *************** *** 7,11 **** /// <see cref="IPredicate"/> representing a expected value, but also an acceptable delta for the input value /// </summary> ! public class IsCloseTo : IPredicate { private double _expected; --- 12,16 ---- /// <see cref="IPredicate"/> representing a expected value, but also an acceptable delta for the input value /// </summary> ! public class IsCloseTo : AbstractPredicate { private double _expected; *************** *** 26,30 **** /// <param name="currentValue">Input value to evaluate</param> /// <returns>True if the input value is within acceptable range.</returns> ! public bool Eval(object currentValue) { try --- 31,35 ---- /// <param name="currentValue">Input value to evaluate</param> /// <returns>True if the input value is within acceptable range.</returns> ! public override bool Eval(object currentValue) { try *************** *** 38,41 **** --- 43,59 ---- } } + /// <summary> + /// Text representation of what is evaluated by the + /// <see cref="Eval"/> method. + /// </summary> + public override string ExpressionAsText(string name) + { + return String.Format( + "{0} is within {1} of {2}", + name, + _error, + _expected + ); + } } } Index: IsAnything.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Predicates/IsAnything.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** IsAnything.cs 1 Jan 2005 21:13:54 -0000 1.4 --- IsAnything.cs 20 Feb 2005 09:26:49 -0000 1.5 *************** *** 1,2 **** --- 1,5 ---- + #region License + // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. + #endregion using System; *************** *** 6,10 **** /// <see cref="IPredicate"/> representing any value /// </summary> ! public class IsAnything : IPredicate { /// <summary> --- 9,13 ---- /// <see cref="IPredicate"/> representing any value /// </summary> ! public class IsAnything : AbstractPredicate { /// <summary> *************** *** 13,20 **** /// <param name="currentValue">INput value to evaluate</param> /// <returns>True</returns> ! public bool Eval(object currentValue) { return true; } } } --- 16,31 ---- /// <param name="currentValue">INput value to evaluate</param> /// <returns>True</returns> ! public override bool Eval(object currentValue) { return true; } + /// <summary> + /// Text representation of what is evaluated by the + /// <see cref="Eval"/> method. + /// </summary> + public override string ExpressionAsText(string name) + { + return String.Format("{0} is anything", name); + } } } Index: IsNull.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Predicates/IsNull.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** IsNull.cs 16 Feb 2005 10:39:26 -0000 1.4 --- IsNull.cs 20 Feb 2005 09:26:49 -0000 1.5 *************** *** 1,2 **** --- 1,9 ---- + #region License + // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. + #endregion + #region Imports + using System; + #endregion + namespace DotNetMock.Dynamic.Predicates { *************** *** 4,27 **** /// <see cref="IPredicate"/> that indicates that the input value should be null. /// </summary> ! public class IsNull : IPredicate { /// <summary> - /// The condition this evaluates as text. - /// </summary> - /// <returns>"value is null"</returns> - public override string ToString() - { - return "value is null"; - } - - /// <summary> /// Evaluates the input value against null /// </summary> /// <param name="inputValue">input value</param> /// <returns>True if the input value is null, false otherwise.</returns> ! public bool Eval(object inputValue) { return inputValue == null; } } } --- 11,36 ---- /// <see cref="IPredicate"/> that indicates that the input value should be null. /// </summary> ! public class IsNull : AbstractPredicate { /// <summary> /// Evaluates the input value against null /// </summary> /// <param name="inputValue">input value</param> /// <returns>True if the input value is null, false otherwise.</returns> ! public override bool Eval(object inputValue) { return inputValue == null; } + /// <summary> + /// Text representation of what is evaluated by the + /// <see cref="Eval"/> method. + /// </summary> + public override string ExpressionAsText(string name) + { + return String.Format( + "{0} is null", + name + ); + } } } Index: IsEqualIgnoreWhiteSpace.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Predicates/IsEqualIgnoreWhiteSpace.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** IsEqualIgnoreWhiteSpace.cs 1 Jan 2005 21:13:54 -0000 1.3 --- IsEqualIgnoreWhiteSpace.cs 20 Feb 2005 09:26:49 -0000 1.4 *************** *** 1,5 **** --- 1,12 ---- + #region License + // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. + #endregion + #region Imports using System; using System.Text; + using DotNetMock.Util; + #endregion + namespace DotNetMock.Dynamic.Predicates { *************** *** 7,13 **** /// <see cref="IPredicate"/> comparing string values that ignore whitespace. /// </summary> ! public class IsEqualIgnoreWhiteSpace : IPredicate { private IPredicate _originalPredicate; /// <summary> /// Default Constructor --- 14,21 ---- /// <see cref="IPredicate"/> comparing string values that ignore whitespace. /// </summary> ! public class IsEqualIgnoreWhiteSpace : AbstractPredicate { private IPredicate _originalPredicate; + private string _compare; /// <summary> /// Default Constructor *************** *** 16,19 **** --- 24,28 ---- public IsEqualIgnoreWhiteSpace(object compare) { + _compare = compare.ToString(); _originalPredicate = new IsEqual(StripSpace(compare.ToString())); } *************** *** 23,27 **** /// <param name="inputValue">input value to compare</param> /// <returns>True if the input value equals the original value, false otherwise</returns> ! public bool Eval(object inputValue) { return _originalPredicate.Eval(StripSpace(inputValue.ToString())); --- 32,36 ---- /// <param name="inputValue">input value to compare</param> /// <returns>True if the input value equals the original value, false otherwise</returns> ! public override bool Eval(object inputValue) { return _originalPredicate.Eval(StripSpace(inputValue.ToString())); *************** *** 54,57 **** --- 63,78 ---- return result.ToString().Trim(); } + /// <summary> + /// Text representation of what is evaluated by the + /// <see cref="Eval"/> method. + /// </summary> + public override string ExpressionAsText(string name) + { + return String.Format( + "{0} equals {1} (ignore whitespace)", + name, + StringUtils.FormatScalar(_compare) + ); + } } } Index: NotIn.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Predicates/NotIn.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NotIn.cs 1 Jan 2005 21:13:54 -0000 1.3 --- NotIn.cs 20 Feb 2005 09:26:49 -0000 1.4 *************** *** 1,2 **** --- 1,11 ---- + #region License + // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. + #endregion + #region Imports + using System; + + using DotNetMock.Util; + #endregion + namespace DotNetMock.Dynamic.Predicates { *************** *** 4,10 **** /// <see cref="IPredicate"/> to verify that the input value is not in the original list of values. Opposite of <see cref="IsIn"/>. /// </summary> ! public class NotIn : IPredicate { private IPredicate p; /// <summary> /// Default Constructor --- 13,20 ---- /// <see cref="IPredicate"/> to verify that the input value is not in the original list of values. Opposite of <see cref="IsIn"/>. /// </summary> ! public class NotIn : AbstractPredicate { private IPredicate p; + private object[] _inList; /// <summary> /// Default Constructor *************** *** 13,16 **** --- 23,27 ---- public NotIn(params object[] inList) { + _inList = inList; p = new NotPredicate(new IsIn(inList)); } *************** *** 20,27 **** /// <param name="inputValue">input value</param> /// <returns>True if the input value is not in the original array of values, false otherwise.</returns> ! public bool Eval(object inputValue) { return p.Eval(inputValue); } } } --- 31,50 ---- /// <param name="inputValue">input value</param> /// <returns>True if the input value is not in the original array of values, false otherwise.</returns> ! public override bool Eval(object inputValue) { return p.Eval(inputValue); } + /// <summary> + /// Text representation of what is evaluated by the + /// <see cref="Eval"/> method. + /// </summary> + public override string ExpressionAsText(string name) + { + return String.Format( + "{0} is not in [{1}]", + name, + StringUtils.FormatArray(_inList) + ); + } } } Index: OrPredicate.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Predicates/OrPredicate.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** OrPredicate.cs 1 Jan 2005 21:13:54 -0000 1.3 --- OrPredicate.cs 20 Feb 2005 09:26:49 -0000 1.4 *************** *** 1,2 **** --- 1,9 ---- + #region License + // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. + #endregion + #region Imports + using System; + #endregion + namespace DotNetMock.Dynamic.Predicates { *************** *** 4,8 **** /// <see cref="IPredicate"/> that compares the input value against two <see cref="IPredicate"/> instances. /// </summary> ! public class OrPredicate : IPredicate { private IPredicate _originalPredicate1; --- 11,15 ---- /// <see cref="IPredicate"/> that compares the input value against two <see cref="IPredicate"/> instances. /// </summary> ! public class OrPredicate : AbstractPredicate { private IPredicate _originalPredicate1; *************** *** 23,30 **** /// <param name="inputValue">input value</param> /// <returns>True if the input value satisfies either of the original <see cref="IPredicate"/> objects, false otherwise.</returns> ! public bool Eval(object inputValue) { return _originalPredicate1.Eval(inputValue) || _originalPredicate2.Eval(inputValue); } } } --- 30,49 ---- /// <param name="inputValue">input value</param> /// <returns>True if the input value satisfies either of the original <see cref="IPredicate"/> objects, false otherwise.</returns> ! public override bool Eval(object inputValue) { return _originalPredicate1.Eval(inputValue) || _originalPredicate2.Eval(inputValue); } + /// <summary> + /// Text representation of what is evaluated by the + /// <see cref="Eval"/> method. + /// </summary> + public override string ExpressionAsText(string name) + { + return String.Format( + "({0}) or ({1})", + _originalPredicate1.ExpressionAsText(name), + _originalPredicate2.ExpressionAsText(name) + ); + } } } |
From: Choy R. <ch...@us...> - 2005-02-20 09:26:58
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15950/DotNetMock.Tests/Util Added Files: StringUtilsTests.cs Log Message: Make sure all Predicates support the ability to describe their evaluation expression through the ExpressionAsText(name) method. The name parameter is so that in the future we can include the name of the parameter that didn't satisfy the predicate in our assertion failure messages. --- NEW FILE: StringUtilsTests.cs --- #region License // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. #endregion #region Imports using System; using System.Collections; using NUnit.Framework; using DotNetMock.Util; #endregion namespace DotNetMock.Tests.Util { [TestFixture] public class StringUtilsTests { [Test] public void FormatScalar() { Assert.AreEqual( "'two'", StringUtils.FormatScalar("two") ); Assert.AreEqual( "1", StringUtils.FormatScalar(1) ); Assert.AreEqual( "3.4", StringUtils.FormatScalar(3.4) ); Assert.AreEqual( "[1, 'two', 3.4]", StringUtils.FormatScalar(new object[] { 1, "two", 3.4 }) ); } [Test] public void FormatArray() { Assert.AreEqual( "1, 'two', 3.4", StringUtils.FormatArray(1, "two", 3.4) ); } [Test] public void FormatDictionary() { Hashtable hash = new Hashtable(); hash["a"]=1; hash["b"]="two"; hash["c"]=3.4; Assert.AreEqual( "a=1, b='two', c=3.4", StringUtils.FormatCollection(hash) ); } [Test] public void FormatCollection() { ArrayList list = new ArrayList(); list.Add(1); list.Add("two"); list.Add(3.4); Assert.AreEqual( "1, 'two', 3.4", StringUtils.FormatCollection(list) ); } } } |
From: Choy R. <ch...@us...> - 2005-02-20 09:26:58
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15950/DotNetMock/Util Added Files: StringUtils.cs Log Message: Make sure all Predicates support the ability to describe their evaluation expression through the ExpressionAsText(name) method. The name parameter is so that in the future we can include the name of the parameter that didn't satisfy the predicate in our assertion failure messages. --- NEW FILE: StringUtils.cs --- #region License // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. #endregion #region Imports using System; using System.Collections; #endregion namespace DotNetMock.Util { /// <summary> /// Perl-like utility functions. /// </summary> public class StringUtils { /// <summary> /// Format an object. /// </summary> /// <param name="scalar">object to format</param> /// <returns>string representation of an object value</returns> public static string FormatScalar(object scalar) { return mapElement(scalar).ToString(); } /// <summary> /// Format an array. /// </summary> /// <param name="args">array to format</param> /// <returns>string representation of array</returns> public static string FormatArray(params object[] args) { return FormatCollection(args, DefaultElementMapper); } /// <summary> /// Format a collection.. /// </summary> /// <param name="collection">collection to format</param> /// <returns>string representation of collection</returns> public static string FormatCollection(ICollection collection) { return FormatCollection(collection, DefaultElementMapper); } #region Private Static /// <summary> /// Delegate for mapping/transforming objects. /// </summary> private delegate object Mapper(object element); /// <summary> /// Default <see cref="Mapper"/> for displaying objects. /// </summary> private static readonly Mapper DefaultElementMapper = new Mapper(mapElement); private static string FormatCollection(ICollection collection, Mapper mapper) { return String.Join(", ", mapToString(mapCollection( mapper, collection ))); } private static object mapElement(object arg) { if ( arg is string ) { return "'"+arg as string+"'"; } else if ( arg is DictionaryEntry ) { DictionaryEntry entry = (DictionaryEntry) arg; return String.Format( "{0}={1}", entry.Key, mapElement(entry.Value) ); } else if ( arg is ICollection ) { return "["+FormatCollection( (ICollection) arg, new Mapper(mapElement) )+"]"; } else { return arg; } } private static object[] mapCollection(Mapper mapper, ICollection collection) { object[] result = new object[collection.Count]; int i = 0; foreach (object element in collection) { result[i++] = mapper(element); } return result; } private static string[] mapToString(params object[] array) { string[] result = new string[array.Length]; for (int i = 0; i<array.Length; ++i) { result[i] = array[i].ToString(); } return result; } #endregion } } |
From: Choy R. <ch...@us...> - 2005-02-20 09:26:58
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15950/DotNetMock/Dynamic Modified Files: AbstractArgumentMutator.cs IPredicate.cs Log Message: Make sure all Predicates support the ability to describe their evaluation expression through the ExpressionAsText(name) method. The name parameter is so that in the future we can include the name of the parameter that didn't satisfy the predicate in our assertion failure messages. Index: IPredicate.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/IPredicate.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** IPredicate.cs 1 Jan 2005 22:58:07 -0000 1.6 --- IPredicate.cs 20 Feb 2005 09:26:49 -0000 1.7 *************** *** 13,16 **** --- 13,25 ---- /// <returns>True/False if the current value equals the input value </returns> bool Eval(object inputValue); + /// <summary> + /// Text representation of what is evaluated by the + /// <see cref="Eval"/> method. + /// </summary> + /// <param name="name"> + /// name of value/variable to use in the expression text + /// </param> + /// <returns>text representation of this predicate</returns> + string ExpressionAsText(string name); } } Index: AbstractArgumentMutator.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/AbstractArgumentMutator.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AbstractArgumentMutator.cs 5 Jan 2005 00:29:34 -0000 1.3 --- AbstractArgumentMutator.cs 20 Feb 2005 09:26:49 -0000 1.4 *************** *** 35,47 **** } /// <summary> ! /// Evaluates the input value according to the contained predicate. /// </summary> - /// <param name="inputValue">Value to evaluate</param> - /// <returns>Result of the predicate evaluation</returns> public virtual bool Eval(object inputValue) { return _predicate.Eval(inputValue); } ! } } --- 35,51 ---- } /// <summary> ! /// <seealso cref="IPredicate.Eval"/> /// </summary> public virtual bool Eval(object inputValue) { return _predicate.Eval(inputValue); } ! /// <summary> ! /// <seealso cref="IPredicate.ExpressionAsText"/> ! /// </summary> ! public virtual string ExpressionAsText(string name) ! { ! return _predicate.ExpressionAsText(name); ! } } } |
From: Choy R. <ch...@us...> - 2005-02-20 09:26:57
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15950/DotNetMock Modified Files: DotNetMock.csproj Log Message: Make sure all Predicates support the ability to describe their evaluation expression through the ExpressionAsText(name) method. The name parameter is so that in the future we can include the name of the parameter that didn't satisfy the predicate in our assertion failure messages. Index: DotNetMock.csproj =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/DotNetMock.csproj,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** DotNetMock.csproj 18 Feb 2005 06:37:35 -0000 1.35 --- DotNetMock.csproj 20 Feb 2005 09:26:49 -0000 1.36 *************** *** 270,273 **** --- 270,278 ---- /> <File + RelPath = "Dynamic\Predicates\AbstractPredicate.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Dynamic\Predicates\AndPredicate.cs" SubType = "Code" *************** *** 399,402 **** --- 404,412 ---- BuildAction = "Compile" /> + <File + RelPath = "Util\StringUtils.cs" + SubType = "Code" + BuildAction = "Compile" + /> </Include> </Files> |
From: Choy R. <ch...@us...> - 2005-02-20 09:26:57
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15950/DotNetMock.Tests/Dynamic Modified Files: ExpectationMethodTests.cs PredicateTests.cs Log Message: Make sure all Predicates support the ability to describe their evaluation expression through the ExpressionAsText(name) method. The name parameter is so that in the future we can include the name of the parameter that didn't satisfy the predicate in our assertion failure messages. Index: ExpectationMethodTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/ExpectationMethodTests.cs,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** ExpectationMethodTests.cs 19 Feb 2005 09:06:24 -0000 1.12 --- ExpectationMethodTests.cs 20 Feb 2005 09:26:48 -0000 1.13 *************** *** 9,12 **** --- 9,13 ---- using DotNetMock.Dynamic; + using DotNetMock.Dynamic.Predicates; #endregion *************** *** 59,63 **** [ExpectedException( typeof(AssertionException), ! "Failed to satisfy 'value equals (1)' on argument[0] of method call Method2(x=3, y=2, z=1)" )] public void DecentErrorMessageWhenPredicateFails() --- 60,83 ---- [ExpectedException( typeof(AssertionException), ! "Failed to satisfy '(value is a System.Double) and (value is within 0.1 of 1)' on argument[0] of method call Method2(x=3, y=2, z=1)" ! )] ! public void ErrorMessageWhenComplexPredicateFails() ! { ! IPredicate complexPredicate = new AndPredicate( ! new IsTypeOf(typeof(double)), ! new IsCloseTo(1, 0.1) ! ); ! methodCallExpectation = new ExpectationMethod( ! method2.Name, ! null, ! new object[] { complexPredicate, 2, 3 } ! ); ! methodCallExpectation.ActualMethodCall = new MethodCall(method2, 3, 2, 1); ! methodCallExpectation.Verify(); ! } ! [Test] ! [ExpectedException( ! typeof(AssertionException), ! "Failed to satisfy 'value equals 1' on argument[0] of method call Method2(x=3, y=2, z=1)" )] public void DecentErrorMessageWhenPredicateFails() *************** *** 70,74 **** [ExpectedException( typeof(AssertionException), ! "Failed to satisfy 'value equals (2)' on argument[1] of method call Method2(x=1, y=3, z=2)" )] public void DecentErrorMessageWhenPredicateFailsOnSecondArgument() --- 90,94 ---- [ExpectedException( typeof(AssertionException), ! "Failed to satisfy 'value equals 2' on argument[1] of method call Method2(x=1, y=3, z=2)" )] public void DecentErrorMessageWhenPredicateFailsOnSecondArgument() Index: PredicateTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/PredicateTests.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** PredicateTests.cs 16 Feb 2005 10:39:25 -0000 1.13 --- PredicateTests.cs 20 Feb 2005 09:26:48 -0000 1.14 *************** *** 12,23 **** private IPredicate p; [Test] public void IsNullToString() { Assert.AreEqual("value is null", new IsNull().ToString()); } ! [Test] public void IsEqualToString() { ! Assert.AreEqual("value equals (3)", new IsEqual(3).ToString()); ! Assert.AreEqual("value equals (whatever it is)", new IsEqual("whatever it is").ToString()); } [Test] --- 12,130 ---- private IPredicate p; + [Test] public void AndToString() + { + Assert.AreEqual( + "(value is anything) and (value is anything)", + new AndPredicate( + new IsAnything(), new IsAnything() + ).ToString() + ); + } + [Test] public void IsAnythingToString() + { + Assert.AreEqual("value is anything", new IsAnything().ToString()); + } + [Test] public void IsCloseToToString() + { + Assert.AreEqual( + "value is within 0.1 of 1", + new IsCloseTo(1, 0.1).ToString() + ); + } + [Test] public void IsEqualToString() + { + Assert.AreEqual( + "value equals 3", + new IsEqual(3).ToString() + ); + Assert.AreEqual( + "value equals 'whatever it is'", + new IsEqual("whatever it is").ToString() + ); + } + [Test] public void IsEqualIgnoreCaseToString() + { + Assert.AreEqual( + "value equals 'abc' (ignore case)", + new IsEqualIgnoreCase("abc").ToString() + ); + Assert.AreEqual( + "value equals 'whatever' (ignore case)", + new IsEqualIgnoreCase("whatever").ToString() + ); + } + [Test] public void IsEqualIgnoreWhiteSpaceToString() + { + Assert.AreEqual( + "value equals 'a b c' (ignore whitespace)", + new IsEqualIgnoreWhiteSpace("a b c").ToString() + ); + Assert.AreEqual( + "value equals 'what ever' (ignore whitespace)", + new IsEqualIgnoreWhiteSpace("what ever").ToString() + ); + } + [Test] public void IsInToString() + { + Assert.AreEqual( + "value is in [1, 'two', 3.4]", + new IsIn(1, "two", 3.4).ToString() + ); + } + [Test] public void IsMatchToString() + { + Assert.AreEqual( + "value matches /^abc$/", + new IsMatch("^abc$").ToString() + ); + } [Test] public void IsNullToString() { Assert.AreEqual("value is null", new IsNull().ToString()); } ! [Test] public void IsTypeOfToString() { ! Assert.AreEqual( ! "value is a System.Object", ! new IsTypeOf(typeof(object)).ToString() ! ); ! } ! [Test] public void NotEqualToString() ! { ! Assert.AreEqual( ! "value is not equal to 3", ! new NotEqual(3).ToString() ! ); ! Assert.AreEqual( ! "value is not equal to 'whatever it is'", ! new NotEqual("whatever it is").ToString() ! ); ! } ! [Test] public void NotInToString() ! { ! Assert.AreEqual( ! "value is not in [1, 'two', 3.4]", ! new NotIn(1, "two", 3.4).ToString() ! ); ! } ! [Test] public void NotNullToString() ! { ! Assert.AreEqual("value is not null", new NotNull().ToString()); ! } ! [Test] public void NotToString() ! { ! Assert.AreEqual( ! "not (value is anything)", ! new NotPredicate(new IsAnything()).ToString() ! ); ! } ! [Test] public void OrToString() ! { ! Assert.AreEqual( ! "(value is anything) or (value is anything)", ! new OrPredicate( ! new IsAnything(), new IsAnything() ! ).ToString() ! ); } [Test] *************** *** 268,274 **** } ! class True : IPredicate { ! public bool Eval(object val) { return true; --- 375,381 ---- } ! class True : AbstractPredicate { ! public override bool Eval(object val) { return true; *************** *** 276,282 **** } ! class False : IPredicate { ! public bool Eval(object val) { return false; --- 383,389 ---- } ! class False : AbstractPredicate { ! public override bool Eval(object val) { return false; |
From: Choy R. <ch...@us...> - 2005-02-20 09:26:57
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15950/DotNetMock.Tests Modified Files: DotNetMock.Tests.csproj Log Message: Make sure all Predicates support the ability to describe their evaluation expression through the ExpressionAsText(name) method. The name parameter is so that in the future we can include the name of the parameter that didn't satisfy the predicate in our assertion failure messages. Index: DotNetMock.Tests.csproj =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/DotNetMock.Tests.csproj,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** DotNetMock.Tests.csproj 18 Feb 2005 06:37:34 -0000 1.18 --- DotNetMock.Tests.csproj 20 Feb 2005 09:26:48 -0000 1.19 *************** *** 210,213 **** --- 210,218 ---- BuildAction = "Compile" /> + <File + RelPath = "Util\StringUtilsTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> </Include> </Files> |
From: Choy R. <ch...@us...> - 2005-02-20 09:19:23
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14272/Util Log Message: Directory /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Util added to the repository |
From: Choy R. <ch...@us...> - 2005-02-20 09:19:15
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14245/Util Log Message: Directory /cvsroot/dotnetmock/dotnetmock/DotNetMock/Util added to the repository |
From: Choy R. <ch...@us...> - 2005-02-19 22:14:38
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10674/DotNetMock/Dynamic Modified Files: DynamicMock.cs DynamicOrderedMock.cs Log Message: fixed up nextExpectation so that it can be used by DynamicOrderedMock and got rid of some redundant code. Index: DynamicOrderedMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicOrderedMock.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** DynamicOrderedMock.cs 19 Feb 2005 21:47:56 -0000 1.10 --- DynamicOrderedMock.cs 19 Feb 2005 22:14:28 -0000 1.11 *************** *** 44,60 **** } /// <summary> ! /// Uses the given method to verify expectations for the method. Also verifies method call order. /// </summary> ! /// <param name="mi">mathod called</param> ! /// <param name="args">arguments to the method</param> ! /// <returns>Return value, if any, from method call.</returns> ! public override object Call(MethodInfo mi, params object[] args) { - MethodCall methodCall = new MethodCall(mi, args); - string methodName = methodCall.MethodName; - if (values.Contains(methodName)) - { - return values[methodName]; - } if (expectations.Count == 0) { --- 44,68 ---- } /// <summary> ! /// Adds a <see cref="ExpectationMethod"/> to the list of expectations of the mock object. /// </summary> ! /// <param name="e">Expectation to add</param> ! protected override void addExpectation(ExpectationMethod e) ! { ! expectations.Add(e); ! } ! /// <summary> ! /// Retrieve next expectation and remove from FIFO. ! /// </summary> ! /// <param name="methodCall"> ! /// <see cref="MethodCall"/> to get expectation for ! /// </param> ! /// <returns>next <see cref="ExpectationMethod"/></returns> ! /// <remarks> ! /// This is a state mutating method. It removes the expectation from ! /// a list. Not a big deal since we don't ever recover from any ! /// exceptions. ! /// </remarks> ! protected override ExpectationMethod nextExpectation(MethodCall methodCall) { if (expectations.Count == 0) { *************** *** 66,80 **** ExpectationMethod e = (ExpectationMethod)expectations[0]; expectations.RemoveAt(0); ! e.ActualMethodCall = methodCall; ! e.Verify(); ! return e.ReturnValue; ! } ! /// <summary> ! /// Adds a <see cref="ExpectationMethod"/> to the list of expectations of the mock object. ! /// </summary> ! /// <param name="e">Expectation to add</param> ! protected override void addExpectation(ExpectationMethod e) ! { ! expectations.Add(e); } } --- 74,78 ---- ExpectationMethod e = (ExpectationMethod)expectations[0]; expectations.RemoveAt(0); ! return e; } } Index: DynamicMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicMock.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** DynamicMock.cs 19 Feb 2005 22:05:56 -0000 1.18 --- DynamicMock.cs 19 Feb 2005 22:14:28 -0000 1.19 *************** *** 190,194 **** return values[methodName]; } ! ExpectationMethod e = nextExpectation(methodName); e.ActualMethodCall = methodCall; e.Verify(); --- 190,194 ---- return values[methodName]; } ! ExpectationMethod e = nextExpectation(methodCall); e.ActualMethodCall = methodCall; e.Verify(); *************** *** 212,217 **** /// Retrieve next expectation and remove from FIFO. /// </summary> ! /// <param name="methodName"> ! /// name of method to get expectation for /// </param> /// <returns>next <see cref="ExpectationMethod"/></returns> --- 212,217 ---- /// Retrieve next expectation and remove from FIFO. /// </summary> ! /// <param name="methodCall"> ! /// <see cref="MethodCall"/> to get expectation for /// </param> /// <returns>next <see cref="ExpectationMethod"/></returns> *************** *** 221,226 **** /// exceptions. /// </remarks> ! protected virtual ExpectationMethod nextExpectation(string methodName) { IList list = (IList) expectations[methodName]; if (list == null) --- 221,227 ---- /// exceptions. /// </remarks> ! protected virtual ExpectationMethod nextExpectation(MethodCall methodCall) { + string methodName = methodCall.MethodName; IList list = (IList) expectations[methodName]; if (list == null) |
From: Choy R. <ch...@us...> - 2005-02-19 22:06:06
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7971/DotNetMock/Dynamic Modified Files: DynamicMock.cs Log Message: refactor extract method: factored out retrieving the next expectation for more OOAO (or DRY) Index: DynamicMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicMock.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** DynamicMock.cs 19 Feb 2005 21:34:39 -0000 1.17 --- DynamicMock.cs 19 Feb 2005 22:05:56 -0000 1.18 *************** *** 190,209 **** return values[methodName]; } ! ! IList list = (IList) expectations[methodName]; ! if (list == null) ! { ! if ( strict ) ! { ! throw new VerifyException(methodName + "() called too many times"); ! } ! return null; ! } ! if (list.Count == 0) ! { ! Assertion.Fail(methodName + "() called too many times"); ! } ! ExpectationMethod e = (ExpectationMethod)list[0]; ! list.RemoveAt(0); e.ActualMethodCall = methodCall; e.Verify(); --- 190,194 ---- return values[methodName]; } ! ExpectationMethod e = nextExpectation(methodName); e.ActualMethodCall = methodCall; e.Verify(); *************** *** 224,227 **** --- 209,243 ---- list.Add(e); } + /// <summary> + /// Retrieve next expectation and remove from FIFO. + /// </summary> + /// <param name="methodName"> + /// name of method to get expectation for + /// </param> + /// <returns>next <see cref="ExpectationMethod"/></returns> + /// <remarks> + /// This is a state mutating method. It removes the expectation from + /// a list. Not a big deal since we don't ever recover from any + /// exceptions. + /// </remarks> + protected virtual ExpectationMethod nextExpectation(string methodName) + { + IList list = (IList) expectations[methodName]; + if (list == null) + { + if ( strict ) + { + throw new VerifyException(methodName + "() called too many times"); + } + return null; + } + if (list.Count == 0) + { + Assertion.Fail(methodName + "() called too many times"); + } + ExpectationMethod e = (ExpectationMethod) list[0]; + list.RemoveAt(0); + return e; + } private void generate() |
From: Choy R. <ch...@us...> - 2005-02-19 21:48:05
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3899/DotNetMock.Tests/Dynamic Modified Files: DynamicOrderedMockTests.cs Log Message: Replace argsToString with MethodCall stringification. Index: DynamicOrderedMockTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/DynamicOrderedMockTests.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DynamicOrderedMockTests.cs 12 Feb 2005 18:10:36 -0000 1.7 --- DynamicOrderedMockTests.cs 19 Feb 2005 21:47:56 -0000 1.8 *************** *** 29,32 **** --- 29,47 ---- [Test] + [ExpectedException( + typeof(AssertionException), + "Unexpected call myMethod3()" + )] + public void CallMoreMethodsThanExpected() + { + mock.Expect("myMethod1"); + mock.Expect("myMethod2"); + mock.Call(myMethod1); + mock.Call(myMethod2); + mock.Call(myMethod3); + mock.Verify(); + } + + [Test] [ExpectedException(typeof(AssertionException))] public void CallMultipleMethodsInWrongOrder() |
From: Choy R. <ch...@us...> - 2005-02-19 21:48:05
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3899/DotNetMock/Dynamic Modified Files: DynamicOrderedMock.cs Log Message: Replace argsToString with MethodCall stringification. Index: DynamicOrderedMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicOrderedMock.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** DynamicOrderedMock.cs 19 Feb 2005 21:34:39 -0000 1.9 --- DynamicOrderedMock.cs 19 Feb 2005 21:47:56 -0000 1.10 *************** *** 59,63 **** if (expectations.Count == 0) { ! Assertion.Fail( "Unexpected call to method " + methodName + "(" + argsToString(args) + ")"); } ExpectationMethod e = (ExpectationMethod)expectations[0]; --- 59,66 ---- if (expectations.Count == 0) { ! Assertion.Fail(String.Format( ! "Unexpected call {0}", ! methodCall ! )); } ExpectationMethod e = (ExpectationMethod)expectations[0]; *************** *** 67,82 **** return e.ReturnValue; } - private string argsToString( object[] args ) { - if ( args.Length > 0 ) - { - string argStr = ""; - foreach( object o in args ) - { - argStr = argStr + ", \"" + o.ToString() + "\""; - } - return argStr.Substring(2); - } - return String.Empty; - } /// <summary> /// Adds a <see cref="ExpectationMethod"/> to the list of expectations of the mock object. --- 70,73 ---- |
From: Choy R. <ch...@us...> - 2005-02-19 21:34:48
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1357/DotNetMock/Dynamic Modified Files: DynamicMock.cs DynamicOrderedMock.cs ExpectationMethod.cs Log Message: Continuing with the OOAO with regard to the logic for method names of properties. Index: DynamicOrderedMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicOrderedMock.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** DynamicOrderedMock.cs 19 Feb 2005 09:06:26 -0000 1.8 --- DynamicOrderedMock.cs 19 Feb 2005 21:34:39 -0000 1.9 *************** *** 51,55 **** public override object Call(MethodInfo mi, params object[] args) { ! string methodName = getMethodName(mi); if (values.Contains(methodName)) { --- 51,56 ---- public override object Call(MethodInfo mi, params object[] args) { ! MethodCall methodCall = new MethodCall(mi, args); ! string methodName = methodCall.MethodName; if (values.Contains(methodName)) { *************** *** 62,66 **** ExpectationMethod e = (ExpectationMethod)expectations[0]; expectations.RemoveAt(0); ! e.ActualMethodCall = new MethodCall(mi, args); e.Verify(); return e.ReturnValue; --- 63,67 ---- ExpectationMethod e = (ExpectationMethod)expectations[0]; expectations.RemoveAt(0); ! e.ActualMethodCall = methodCall; e.Verify(); return e.ReturnValue; Index: DynamicMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicMock.cs,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** DynamicMock.cs 19 Feb 2005 09:06:26 -0000 1.16 --- DynamicMock.cs 19 Feb 2005 21:34:39 -0000 1.17 *************** *** 184,188 **** public virtual object Call(MethodInfo mi, params object[] args) { ! string methodName = getMethodName(mi); if (values.Contains(methodName)) { --- 184,189 ---- public virtual object Call(MethodInfo mi, params object[] args) { ! MethodCall methodCall = new MethodCall(mi, args); ! string methodName = methodCall.MethodName; if (values.Contains(methodName)) { *************** *** 205,209 **** ExpectationMethod e = (ExpectationMethod)list[0]; list.RemoveAt(0); ! e.ActualMethodCall = new MethodCall(mi, args); e.Verify(); return e.ReturnValue; --- 206,210 ---- ExpectationMethod e = (ExpectationMethod)list[0]; list.RemoveAt(0); ! e.ActualMethodCall = methodCall; e.Verify(); return e.ReturnValue; *************** *** 223,240 **** list.Add(e); } - /// <summary> - /// Returns the method name for the input <see cref="MethodInfo"/>. Accounts for property get and set methods. - /// </summary> - /// <param name="mi">method to get name from</param> - /// <returns>methond name for input method.</returns> - protected static string getMethodName( MethodInfo mi ) - { - string methodName = mi.Name; - if (methodName.StartsWith("get_") || methodName.StartsWith("set_")) - { - methodName = methodName.Substring(4); - } - return methodName; - } private void generate() --- 224,227 ---- Index: ExpectationMethod.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/ExpectationMethod.cs,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** ExpectationMethod.cs 19 Feb 2005 09:19:42 -0000 1.19 --- ExpectationMethod.cs 19 Feb 2005 21:34:39 -0000 1.20 *************** *** 113,124 **** public string ActualMethodName { ! get { ! string name = ActualMethod.Name; ! if ( name.StartsWith("get_") || name.StartsWith("set_") ) ! { ! name = name.Substring(4); ! } ! return name; ! } } /// <summary> --- 113,117 ---- public string ActualMethodName { ! get { return ActualMethodCall.MethodName; } } /// <summary> |
From: Choy R. <ch...@us...> - 2005-02-19 21:25:45
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32197/DotNetMock.Tests/Dynamic Modified Files: MethodCallTests.cs Log Message: Put "get_" and "set_" stripping logic for properties in MethodCall.MethodName. So that we can comply with the OOAO edict. Index: MethodCallTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/MethodCallTests.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MethodCallTests.cs 19 Feb 2005 07:48:17 -0000 1.2 --- MethodCallTests.cs 19 Feb 2005 21:25:37 -0000 1.3 *************** *** 24,27 **** --- 24,29 ---- void Method4(); void Method4(int a); + + int Property0 { get; set; } } interface IMethodsA *************** *** 38,41 **** --- 40,53 ---- new Type[] { typeof(int) } ); + static readonly MethodInfo property0_get = typeof(IMethods).GetMethod("get_Property0"); + static readonly MethodInfo property0_set = typeof(IMethods).GetMethod("set_Property0"); + + [Test] public void MethodNameStripsPrefixOnProperties() + { + MethodCall gc = new MethodCall(property0_get); + Assert.AreEqual("Property0", gc.MethodName); + MethodCall sc = new MethodCall(property0_set, 1); + Assert.AreEqual("Property0", sc.MethodName); + } [Test] public void MethodCallToString() |
From: Choy R. <ch...@us...> - 2005-02-19 21:25:45
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32197/DotNetMock/Dynamic Modified Files: MethodCall.cs Log Message: Put "get_" and "set_" stripping logic for properties in MethodCall.MethodName. So that we can comply with the OOAO edict. Index: MethodCall.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/MethodCall.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MethodCall.cs 18 Feb 2005 06:37:35 -0000 1.1 --- MethodCall.cs 19 Feb 2005 21:25:37 -0000 1.2 *************** *** 42,46 **** _arguments = arguments; } ! /// <summary> /// Check if given and this object represent the same method call. --- 42,64 ---- _arguments = arguments; } ! /// <summary> ! /// Name of method or property. ! /// </summary> ! /// <remarks> ! /// In the case of a property, we strip the "get_" or "set_" ! /// prefix. ! /// </remarks> ! public string MethodName ! { ! get ! { ! string name = _method.Name; ! if ( name.StartsWith("get_") || name.StartsWith("set_") ) ! { ! name = name.Substring(4); ! } ! return name; ! } ! } /// <summary> /// Check if given and this object represent the same method call. |
From: Choy R. <ch...@us...> - 2005-02-19 09:19:51
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29530/DotNetMock/Dynamic Modified Files: ExpectationMethod.cs Log Message: Clarify by renaming variables named expected argument to argument expectations, meaning that we specify abstract expectations on each argument and not the argument itself. Index: ExpectationMethod.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/ExpectationMethod.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** ExpectationMethod.cs 19 Feb 2005 09:06:26 -0000 1.18 --- ExpectationMethod.cs 19 Feb 2005 09:19:42 -0000 1.19 *************** *** 21,27 **** private string _expectedMethodName; /// <summary> ! /// Any expected arguments for the expected method call /// </summary> ! private object[] _expectedMethodArguments; /// <summary> /// Expected return value for this method call if any. --- 21,27 ---- private string _expectedMethodName; /// <summary> ! /// Expectations on the arguments of the expected method call. /// </summary> ! private object[] _argumentExpectations; /// <summary> /// Expected return value for this method call if any. *************** *** 52,57 **** /// <param name="methodName">Method name to expect</param> /// <param name="returnValue">return value when expectation is called</param> ! /// <param name="expectedArguments">Arguments to expect when called.</param> ! public ExpectationMethod( string methodName, object returnValue, object[] expectedArguments ) : this( methodName, returnValue, expectedArguments, null ){} /// <summary> /// Default Constructor --- 52,57 ---- /// <param name="methodName">Method name to expect</param> /// <param name="returnValue">return value when expectation is called</param> ! /// <param name="argumentExpectations">Expectations on the arguments</param> ! public ExpectationMethod( string methodName, object returnValue, object[] argumentExpectations ) : this( methodName, returnValue, argumentExpectations, null ){} /// <summary> /// Default Constructor *************** *** 59,74 **** /// <param name="methodName">Method name to expect</param> /// <param name="returnValue">return value when expectation is called</param> ! /// <param name="expectedArguments">Arguments to expect when called.</param> /// <param name="expectedException">Exception to throw when called.</param> ! public ExpectationMethod( string methodName, object returnValue, object[] expectedArguments, Exception expectedException) { _expectedMethodName = methodName; ! if (expectedArguments == null) { ! _expectedMethodArguments = new object[0]; } else { ! _expectedMethodArguments = expectedArguments; } --- 59,74 ---- /// <param name="methodName">Method name to expect</param> /// <param name="returnValue">return value when expectation is called</param> ! /// <param name="argumentExpectations">Expectations on the arguments</param> /// <param name="expectedException">Exception to throw when called.</param> ! public ExpectationMethod( string methodName, object returnValue, object[] argumentExpectations, Exception expectedException) { _expectedMethodName = methodName; ! if (argumentExpectations == null) { ! _argumentExpectations = new object[0]; } else { ! _argumentExpectations = argumentExpectations; } *************** *** 192,196 **** "{0}({1}) expected but never called.", ExpectedMethodName, ! argsToString(_expectedMethodArguments) )); } --- 192,196 ---- "{0}({1}) expected but never called.", ExpectedMethodName, ! argsToString(_argumentExpectations) )); } *************** *** 199,203 **** Assertion.Fail(String.Format( "{0}({1}) expected, but {2} called.", ! ExpectedMethodName, argsToString(_expectedMethodArguments), ActualMethodCall )); --- 199,203 ---- Assertion.Fail(String.Format( "{0}({1}) expected, but {2} called.", ! ExpectedMethodName, argsToString(_argumentExpectations), ActualMethodCall )); *************** *** 205,214 **** object[] actualArguments = ActualMethodCall.Arguments; // actual arguments must be greater than or equal to expectations ! if ( actualArguments.Length<_expectedMethodArguments.Length) { Assertion.Fail(String.Format( "Expected {0} arguments but received {1} "+ "in method call {2}.", ! _expectedMethodArguments.Length, actualArguments.Length, ActualMethodCall --- 205,214 ---- object[] actualArguments = ActualMethodCall.Arguments; // actual arguments must be greater than or equal to expectations ! if ( actualArguments.Length<_argumentExpectations.Length) { Assertion.Fail(String.Format( "Expected {0} arguments but received {1} "+ "in method call {2}.", ! _argumentExpectations.Length, actualArguments.Length, ActualMethodCall *************** *** 217,223 **** // assert that each passed in arg is validated by the appropriate predicate. ! for (int i = 0; i < _expectedMethodArguments.Length; i++) { ! object argumentExpectation = _expectedMethodArguments[i]; object actualArgument = actualArguments[i]; --- 217,223 ---- // assert that each passed in arg is validated by the appropriate predicate. ! for (int i = 0; i < _argumentExpectations.Length; i++) { ! object argumentExpectation = _argumentExpectations[i]; object actualArgument = actualArguments[i]; |
From: Choy R. <ch...@us...> - 2005-02-19 09:06:34
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26509/DotNetMock/Dynamic Modified Files: DynamicMock.cs DynamicOrderedMock.cs ExpectationMethod.cs Log Message: Now you assign the actual method call to the ActualMethodCall property of ExpectationMethod. So that it is like other expectations. sort of. Index: DynamicOrderedMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicOrderedMock.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DynamicOrderedMock.cs 17 Feb 2005 05:29:38 -0000 1.7 --- DynamicOrderedMock.cs 19 Feb 2005 09:06:26 -0000 1.8 *************** *** 62,66 **** ExpectationMethod e = (ExpectationMethod)expectations[0]; expectations.RemoveAt(0); ! e.SetActualMethodCall(mi, args); e.Verify(); return e.ReturnValue; --- 62,66 ---- ExpectationMethod e = (ExpectationMethod)expectations[0]; expectations.RemoveAt(0); ! e.ActualMethodCall = new MethodCall(mi, args); e.Verify(); return e.ReturnValue; Index: DynamicMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicMock.cs,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** DynamicMock.cs 17 Feb 2005 05:29:38 -0000 1.15 --- DynamicMock.cs 19 Feb 2005 09:06:26 -0000 1.16 *************** *** 205,209 **** ExpectationMethod e = (ExpectationMethod)list[0]; list.RemoveAt(0); ! e.SetActualMethodCall(mi, args); e.Verify(); return e.ReturnValue; --- 205,209 ---- ExpectationMethod e = (ExpectationMethod)list[0]; list.RemoveAt(0); ! e.ActualMethodCall = new MethodCall(mi, args); e.Verify(); return e.ReturnValue; Index: ExpectationMethod.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/ExpectationMethod.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** ExpectationMethod.cs 19 Feb 2005 08:39:20 -0000 1.17 --- ExpectationMethod.cs 19 Feb 2005 09:06:26 -0000 1.18 *************** *** 92,96 **** /// <summary> /// True if actual method call was set. ! /// <seealso cref="SetActualMethodCall"/> /// </summary> public bool ActualMethodCallWasSet --- 92,96 ---- /// <summary> /// True if actual method call was set. ! /// <seealso cref="ActualMethodCall"/> /// </summary> public bool ActualMethodCallWasSet *************** *** 156,168 **** } } - /// <summary> - /// Set actual method call <see cref="MethodInfo"/> and arguments. - /// </summary> - /// <param name="actualMethod">actual method</param> - /// <param name="actualArguments">actual arguments</param> - public void SetActualMethodCall( MethodInfo actualMethod, params object[] actualArguments ) - { - ActualMethodCall = new MethodCall(actualMethod, actualArguments); - } //TODO: Refactor methods private string argsToString( object[] args ) --- 156,159 ---- |
From: Choy R. <ch...@us...> - 2005-02-19 09:06:34
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26509/DotNetMock.Tests/Dynamic Modified Files: ExpectationMethodTests.cs Log Message: Now you assign the actual method call to the ActualMethodCall property of ExpectationMethod. So that it is like other expectations. sort of. Index: ExpectationMethodTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/ExpectationMethodTests.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** ExpectationMethodTests.cs 19 Feb 2005 08:39:19 -0000 1.11 --- ExpectationMethodTests.cs 19 Feb 2005 09:06:24 -0000 1.12 *************** *** 38,42 **** { methodCallExpectation = new ExpectationMethod(method1.Name); ! methodCallExpectation.SetActualMethodCall(method1); methodCallExpectation.Verify(); } --- 38,42 ---- { methodCallExpectation = new ExpectationMethod(method1.Name); ! methodCallExpectation.ActualMethodCall = new MethodCall(method1); methodCallExpectation.Verify(); } *************** *** 52,56 **** { methodCallExpectation = new ExpectationMethod(method1.Name, true ); ! methodCallExpectation.SetActualMethodCall(method1); Assert.IsTrue((bool)methodCallExpectation.ReturnValue); methodCallExpectation.Verify(); --- 52,56 ---- { methodCallExpectation = new ExpectationMethod(method1.Name, true ); ! methodCallExpectation.ActualMethodCall = new MethodCall(method1); Assert.IsTrue((bool)methodCallExpectation.ReturnValue); methodCallExpectation.Verify(); *************** *** 64,68 **** { methodCallExpectation = new ExpectationMethod(method2.Name, null, new object[] { 1, 2, 3 }); ! methodCallExpectation.SetActualMethodCall(method2, 3, 2, 1); methodCallExpectation.Verify(); } --- 64,68 ---- { methodCallExpectation = new ExpectationMethod(method2.Name, null, new object[] { 1, 2, 3 }); ! methodCallExpectation.ActualMethodCall = new MethodCall(method2, 3, 2, 1); methodCallExpectation.Verify(); } *************** *** 75,79 **** { methodCallExpectation = new ExpectationMethod(method2.Name, null, new object[] { 1, 2, 3 }); ! methodCallExpectation.SetActualMethodCall(method2, 1, 3, 2); methodCallExpectation.Verify(); } --- 75,79 ---- { methodCallExpectation = new ExpectationMethod(method2.Name, null, new object[] { 1, 2, 3 }); ! methodCallExpectation.ActualMethodCall = new MethodCall(method2, 1, 3, 2); methodCallExpectation.Verify(); } *************** *** 90,94 **** { methodCallExpectation = new ExpectationMethod(method1.Name); ! methodCallExpectation.SetActualMethodCall(method3); methodCallExpectation.Verify(); } --- 90,94 ---- { methodCallExpectation = new ExpectationMethod(method1.Name); ! methodCallExpectation.ActualMethodCall = new MethodCall(method3); methodCallExpectation.Verify(); } *************** *** 101,105 **** { methodCallExpectation = new ExpectationMethod(method2.Name, null, new object[] { 1, 2, 3 }); ! methodCallExpectation.SetActualMethodCall(method2, 1, 3); methodCallExpectation.Verify(); } --- 101,105 ---- { methodCallExpectation = new ExpectationMethod(method2.Name, null, new object[] { 1, 2, 3 }); ! methodCallExpectation.ActualMethodCall = new MethodCall(method2, 1, 3); methodCallExpectation.Verify(); } *************** *** 116,120 **** new object[] { 1, 2, 3, 4 } ); ! methodCallExpectation.SetActualMethodCall(method2, 1, 2, 3); methodCallExpectation.Verify(); } --- 116,120 ---- new object[] { 1, 2, 3, 4 } ); ! methodCallExpectation.ActualMethodCall = new MethodCall(method2, 1, 2, 3); methodCallExpectation.Verify(); } |
From: Choy R. <ch...@us...> - 2005-02-19 08:39:29
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22599/DotNetMock/Dynamic Modified Files: ExpectationMethod.cs Log Message: Incorporated MethodCall into ExpectationMethod Index: ExpectationMethod.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/ExpectationMethod.cs,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** ExpectationMethod.cs 18 Feb 2005 02:16:08 -0000 1.16 --- ExpectationMethod.cs 19 Feb 2005 08:39:20 -0000 1.17 *************** *** 25,32 **** private object[] _expectedMethodArguments; /// <summary> - /// Arguments to the method that was called - /// </summary> - private object[] _actualMethodArguments; - /// <summary> /// Expected return value for this method call if any. /// </summary> --- 25,28 ---- *************** *** 37,43 **** private Exception _expectedException; /// <summary> ! /// <see cref="MethodInfo"/> of actual method call. /// </summary> ! private MethodInfo _actualMethod = null; /// <summary> /// Default Constructor --- 33,39 ---- private Exception _expectedException; /// <summary> ! /// Actual <see cref="MethodCall"/>. /// </summary> ! private MethodCall _actualMethodCall = null; /// <summary> /// Default Constructor *************** *** 100,104 **** public bool ActualMethodCallWasSet { ! get { return _actualMethod!=null; } } /// <summary> --- 96,100 ---- public bool ActualMethodCallWasSet { ! get { return _actualMethodCall!=null; } } /// <summary> *************** *** 109,120 **** get { ! if ( ! ActualMethodCallWasSet ) ! { ! throw new InvalidOperationException( ! "Cannot access ActualMethod property "+ ! "before SetActualMethodCall" ! ); ! } ! return _actualMethod; } } --- 105,109 ---- get { ! return ActualMethodCall.Method; } } *************** *** 134,137 **** --- 123,160 ---- } /// <summary> + /// Actual method call. + /// </summary> + public MethodCall ActualMethodCall + { + get + { + if ( ! ActualMethodCallWasSet ) + { + throw new InvalidOperationException( + "Cannot get property ActualMethodCall "+ + "before setting it." + ); + } + return _actualMethodCall; + } + set + { + if ( value==null ) + { + throw new ArgumentNullException( + "Cannot set ActualMethodCall property to null" + ); + } + if ( ActualMethodCallWasSet ) + { + throw new InvalidOperationException( + "Cannot set property ActualMethodCall "+ + "more than once." + ); + } + _actualMethodCall = value; + } + } + /// <summary> /// Set actual method call <see cref="MethodInfo"/> and arguments. /// </summary> *************** *** 140,145 **** public void SetActualMethodCall( MethodInfo actualMethod, params object[] actualArguments ) { ! _actualMethod = actualMethod; ! _actualMethodArguments = actualArguments; } //TODO: Refactor methods --- 163,167 ---- public void SetActualMethodCall( MethodInfo actualMethod, params object[] actualArguments ) { ! ActualMethodCall = new MethodCall(actualMethod, actualArguments); } //TODO: Refactor methods *************** *** 185,218 **** { Assertion.Fail(String.Format( ! "{0}({1}) expected, but {2}({3}) called.", ExpectedMethodName, argsToString(_expectedMethodArguments), ! ActualMethodName, argsToString(_actualMethodArguments) ! )); ! } ! // check if the actual argument count is correct ! // TODO: ideally this would be done in the constructor if possible ! ParameterInfo[] pis = ActualMethod.GetParameters(); ! if ( pis.Length!=_actualMethodArguments.Length ) ! { ! throw new InvalidOperationException(String.Format( ! "Method {0} takes {1} arguments but received {2}.", ! ActualMethodName, ! pis.Length, ! _actualMethodArguments.Length )); } ! /* cannot check that actual args size matches expected ! * because we want to be able to expect using just method name ! if ( _actualMethodArguments.Length!=_expectedMethodArguments.Length) { Assertion.Fail(String.Format( "Expected {0} arguments but received {1} "+ ! "in method call {2}({3}).", _expectedMethodArguments.Length, ! _actualMethodArguments.Length, ! ActualMethodName, argsToString(_actualMethodArguments) )); } - */ // assert that each passed in arg is validated by the appropriate predicate. --- 207,227 ---- { Assertion.Fail(String.Format( ! "{0}({1}) expected, but {2} called.", ExpectedMethodName, argsToString(_expectedMethodArguments), ! ActualMethodCall )); } ! object[] actualArguments = ActualMethodCall.Arguments; ! // actual arguments must be greater than or equal to expectations ! if ( actualArguments.Length<_expectedMethodArguments.Length) { Assertion.Fail(String.Format( "Expected {0} arguments but received {1} "+ ! "in method call {2}.", _expectedMethodArguments.Length, ! actualArguments.Length, ! ActualMethodCall )); } // assert that each passed in arg is validated by the appropriate predicate. *************** *** 220,224 **** { object argumentExpectation = _expectedMethodArguments[i]; ! object actualArgument = _actualMethodArguments[i]; // evaluate whether input expectations have been met --- 229,233 ---- { object argumentExpectation = _expectedMethodArguments[i]; ! object actualArgument = actualArguments[i]; // evaluate whether input expectations have been met *************** *** 229,241 **** if ( ! isPredicateSatisfied ) { - ParameterInfo pi = pis[i]; Assertion.Fail(String.Format( ! "Failed to satisfy '{0}' on argument {2} ({1}) "+ ! "of method call {3}({4})", predicate, - pi.Name, i, ! ExpectedMethodName, ! argsToString(_actualMethodArguments) )); } --- 238,247 ---- if ( ! isPredicateSatisfied ) { Assertion.Fail(String.Format( ! "Failed to satisfy '{0}' on argument[{1}] "+ ! "of method call {2}", predicate, i, ! ActualMethodCall )); } *************** *** 245,249 **** if ( mutator!=null ) { ! mutator.Mutate(ref _actualMethodArguments[i]); } } --- 251,255 ---- if ( mutator!=null ) { ! mutator.Mutate(ref actualArguments[i]); } } |
From: Choy R. <ch...@us...> - 2005-02-19 08:39:28
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22599/DotNetMock.Tests/Dynamic Modified Files: ExpectationMethodTests.cs Log Message: Incorporated MethodCall into ExpectationMethod Index: ExpectationMethodTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/ExpectationMethodTests.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** ExpectationMethodTests.cs 18 Feb 2005 02:16:08 -0000 1.10 --- ExpectationMethodTests.cs 19 Feb 2005 08:39:19 -0000 1.11 *************** *** 16,20 **** public class ExpectationMethodTests { ! private ExpectationMethod _expectedMethod = null; private interface IMethods --- 16,20 ---- public class ExpectationMethodTests { ! private ExpectationMethod methodCallExpectation = null; private interface IMethods *************** *** 22,41 **** void Method1(); void Method2(int x, int y, int z); } static readonly MethodInfo method1 = typeof(IMethods).GetMethod("Method1"); static readonly MethodInfo method2 = typeof(IMethods).GetMethod("Method2"); [TearDown] public void Destroy() { ! _expectedMethod = null; } [Test] public void ExpectationMethodVoid() { ! _expectedMethod = new ExpectationMethod(method1.Name); ! _expectedMethod.SetActualMethodCall(method1); ! _expectedMethod.Verify(); } [Test] --- 22,43 ---- void Method1(); void Method2(int x, int y, int z); + void Method3(); } static readonly MethodInfo method1 = typeof(IMethods).GetMethod("Method1"); static readonly MethodInfo method2 = typeof(IMethods).GetMethod("Method2"); + static readonly MethodInfo method3 = typeof(IMethods).GetMethod("Method3"); [TearDown] public void Destroy() { ! methodCallExpectation = null; } [Test] public void ExpectationMethodVoid() { ! methodCallExpectation = new ExpectationMethod(method1.Name); ! methodCallExpectation.SetActualMethodCall(method1); ! methodCallExpectation.Verify(); } [Test] *************** *** 43,72 **** public void ExpectationMethodVoidNoCall() { ! _expectedMethod = new ExpectationMethod(method1.Name); ! _expectedMethod.Verify(); } [Test] public void ExpectedMethodReturnValue() { ! _expectedMethod = new ExpectationMethod(method1.Name, true ); ! _expectedMethod.SetActualMethodCall(method1); ! Assert.IsTrue((bool)_expectedMethod.ReturnValue); ! _expectedMethod.Verify(); } [Test] ! [ExpectedException(typeof(AssertionException), "Failed to satisfy 'value equals (1)' on argument 0 (x) of method call Method2(3, 2, 1)")] public void DecentErrorMessageWhenPredicateFails() { ! _expectedMethod = new ExpectationMethod(method2.Name, null, new object[] { 1, 2, 3 }); ! _expectedMethod.SetActualMethodCall(method2, 3, 2, 1); ! _expectedMethod.Verify(); } [Test] ! [ExpectedException(typeof(AssertionException), "Failed to satisfy 'value equals (2)' on argument 1 (y) of method call Method2(1, 3, 2)")] public void DecentErrorMessageWhenPredicateFailsOnSecondArgument() { ! _expectedMethod = new ExpectationMethod(method2.Name, null, new object[] { 1, 2, 3 }); ! _expectedMethod.SetActualMethodCall(method2, 1, 3, 2); ! _expectedMethod.Verify(); } [Test] --- 45,80 ---- public void ExpectationMethodVoidNoCall() { ! methodCallExpectation = new ExpectationMethod(method1.Name); ! methodCallExpectation.Verify(); } [Test] public void ExpectedMethodReturnValue() { ! methodCallExpectation = new ExpectationMethod(method1.Name, true ); ! methodCallExpectation.SetActualMethodCall(method1); ! Assert.IsTrue((bool)methodCallExpectation.ReturnValue); ! methodCallExpectation.Verify(); } [Test] ! [ExpectedException( ! typeof(AssertionException), ! "Failed to satisfy 'value equals (1)' on argument[0] of method call Method2(x=3, y=2, z=1)" ! )] public void DecentErrorMessageWhenPredicateFails() { ! methodCallExpectation = new ExpectationMethod(method2.Name, null, new object[] { 1, 2, 3 }); ! methodCallExpectation.SetActualMethodCall(method2, 3, 2, 1); ! methodCallExpectation.Verify(); } [Test] ! [ExpectedException( ! typeof(AssertionException), ! "Failed to satisfy 'value equals (2)' on argument[1] of method call Method2(x=1, y=3, z=2)" ! )] public void DecentErrorMessageWhenPredicateFailsOnSecondArgument() { ! methodCallExpectation = new ExpectationMethod(method2.Name, null, new object[] { 1, 2, 3 }); ! methodCallExpectation.SetActualMethodCall(method2, 1, 3, 2); ! methodCallExpectation.Verify(); } [Test] *************** *** 74,87 **** public void AccessingActualMethodPropertyBeforeSetting() { ! _expectedMethod = new ExpectationMethod(method1.Name); ! MethodInfo mi = _expectedMethod.ActualMethod; } [Test] ! [ExpectedException(typeof(AssertionException), "Method1() expected, but Method2() called.")] public void WrongMethodCalled() { ! _expectedMethod = new ExpectationMethod(method1.Name); ! _expectedMethod.SetActualMethodCall(method2); ! _expectedMethod.Verify(); } [Test] --- 82,95 ---- public void AccessingActualMethodPropertyBeforeSetting() { ! methodCallExpectation = new ExpectationMethod(method1.Name); ! MethodInfo mi = methodCallExpectation.ActualMethod; } [Test] ! [ExpectedException(typeof(AssertionException), "Method1() expected, but Method3() called.")] public void WrongMethodCalled() { ! methodCallExpectation = new ExpectationMethod(method1.Name); ! methodCallExpectation.SetActualMethodCall(method3); ! methodCallExpectation.Verify(); } [Test] *************** *** 92,112 **** public void ArgumentCountontMatchMethodSignature() { ! _expectedMethod = new ExpectationMethod(method2.Name, null, new object[] { 1, 2, 3 }); ! _expectedMethod.SetActualMethodCall(method2, 1, 3); ! _expectedMethod.Verify(); } - /* [Test] [ExpectedException( typeof(AssertionException), ! "Expected 2 arguments but received 3 in method call Method2(1, 2, 3)." )] ! public void ActualArgumentLengthDoesntMatchExpected() { ! _expectedMethod = new ExpectationMethod(method2.Name, null, new object[] { 1, 2 }); ! _expectedMethod.SetActualMethodCall(method2, 1, 2, 3); ! _expectedMethod.Verify(); } - */ } } --- 100,122 ---- public void ArgumentCountontMatchMethodSignature() { ! methodCallExpectation = new ExpectationMethod(method2.Name, null, new object[] { 1, 2, 3 }); ! methodCallExpectation.SetActualMethodCall(method2, 1, 3); ! methodCallExpectation.Verify(); } [Test] [ExpectedException( typeof(AssertionException), ! "Expected 4 arguments but received 3 in method call Method2(x=1, y=2, z=3)." )] ! public void MoreExpectationsThanArguments() { ! methodCallExpectation = new ExpectationMethod( ! method2.Name, ! null, ! new object[] { 1, 2, 3, 4 } ! ); ! methodCallExpectation.SetActualMethodCall(method2, 1, 2, 3); ! methodCallExpectation.Verify(); } } } |
From: Choy R. <ch...@us...> - 2005-02-19 07:48:28
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12357/DotNetMock.Tests/Dynamic Modified Files: MethodCallTests.cs Log Message: added test to check that overloaded methods don't match. Index: MethodCallTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/MethodCallTests.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MethodCallTests.cs 18 Feb 2005 06:37:35 -0000 1.1 --- MethodCallTests.cs 19 Feb 2005 07:48:17 -0000 1.2 *************** *** 23,26 **** --- 23,27 ---- void Method3(int x, string y, double z); void Method4(); + void Method4(int a); } interface IMethodsA *************** *** 30,35 **** static readonly MethodInfo method3 = typeof(IMethods).GetMethod("Method3"); ! static readonly MethodInfo method4 = typeof(IMethods).GetMethod("Method4"); static readonly MethodInfo methodA3 = typeof(IMethodsA).GetMethod("Method3"); [Test] public void MethodCallToString() --- 31,41 ---- static readonly MethodInfo method3 = typeof(IMethods).GetMethod("Method3"); ! static readonly MethodInfo method4 = typeof(IMethods).GetMethod("Method4", new Type[0]); static readonly MethodInfo methodA3 = typeof(IMethodsA).GetMethod("Method3"); + static readonly MethodInfo method4a = + typeof(IMethods).GetMethod( + "Method4", + new Type[] { typeof(int) } + ); [Test] public void MethodCallToString() *************** *** 47,50 **** --- 53,57 ---- MethodCall mc4 = new MethodCall(method4); MethodCall mc5 = new MethodCall(methodA3, 1, "two", 3.4); + MethodCall mc6 = new MethodCall(method4a, 1); Assert.AreEqual(mc1, mc2); *************** *** 52,57 **** Assert.IsFalse(mc1.Equals(mc4)); Assert.IsFalse(mc1.Equals(mc5)); ! Assert.IsFalse(mc1.Equals(null)); ! Assert.IsFalse(mc1.Equals("text")); } [ExpectedException( --- 59,65 ---- Assert.IsFalse(mc1.Equals(mc4)); Assert.IsFalse(mc1.Equals(mc5)); ! Assert.IsFalse(mc1.Equals(null), "MethodCall not equal to null"); ! Assert.IsFalse(mc1.Equals("text"), "MethodCall not equal to string"); ! Assert.IsFalse(mc4.Equals(mc6), "overloaded methods don't match"); } [ExpectedException( |
From: Choy R. <ch...@us...> - 2005-02-18 06:37:44
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13400/DotNetMock/Dynamic Added Files: MethodCall.cs Log Message: Started adding one of Roman's ideas to the codebase. A modified version of his MethodCall class that doesn't use MethodSignature (yet). Unclear whether we'll need MethodSignature. --- NEW FILE: MethodCall.cs --- #region License // Copyright (c) 2004 Griffin Caprio, Roman V. Gavrilov & Choy Rim. All rights reserved. #endregion #region Imports using System; using System.Reflection; #endregion namespace DotNetMock.Dynamic { /// <summary> /// Method call. /// </summary> /// <author>Roman V. Gavrilov</author> /// <author>Choy Rim</author> public class MethodCall { /// <summary> /// Create new method call instance. /// </summary> /// <param name="method"> /// <see cref="MethodInfo"/> of method called /// </param> /// <param name="arguments">Arguments of the method call.</param> public MethodCall(MethodInfo method, params object[] arguments) { if (arguments == null) { arguments = new object[0]; } int expectedArgumentCount = method.GetParameters().Length; if (expectedArgumentCount != arguments.Length) { throw new InvalidOperationException(String.Format( "Method {0} takes {1} arguments but received {2}.", method.Name, expectedArgumentCount, arguments.Length )); } _method = method; _arguments = arguments; } /// <summary> /// Check if given and this object represent the same method call. /// </summary> public override bool Equals(object obj) { MethodCall that = obj as MethodCall; if ( object.ReferenceEquals(that, null) ) { return false; } if ( that.Method!=this.Method ) { return false; } if (that.Arguments.Length != this.Arguments.Length) { return false; } for (int i = 0; i < that.Arguments.Length; ++i) { if (!that.Arguments[i].Equals(this.Arguments[i])) return false; } return true; } /// <summary> /// Get object's hash code. /// </summary> /// <returns>Object's hash code.</returns> public override int GetHashCode() { int hashCode = Method.GetHashCode(); foreach (object argument in Arguments) { hashCode ^= argument.GetHashCode(); } return hashCode; } /// <summary> /// String representation of method call. /// </summary> /// <returns> /// String of the form: /// <i>method-name</i>(<i>argument-name</i>=<i>argument-value</i>, ...) /// </returns> public override string ToString() { ParameterInfo[] pis = Method.GetParameters(); string[] argumentTexts = new string[Arguments.Length]; for ( int i = 0; i<Arguments.Length; ++i ) { object argument = Arguments[i]; string argumentName = pis[i].Name; string argumentValue; if ( object.ReferenceEquals(argument, null) ) { argumentValue = "null"; } else if( argument is string ) { argumentValue = "\""+argument.ToString()+"\""; } else { argumentValue = argument.ToString(); } argumentTexts[i] = String.Format( "{0}={1}", argumentName, argumentValue ); } return String.Format( "{0}({1})", Method.Name, String.Join(", ", argumentTexts) ); } /// <summary> /// <see cref="MethodInfo"/> of method in method call. /// </summary> public MethodInfo Method { get { return _method; } } /// <summary> /// Array of all argument values for method call. /// </summary> public object[] Arguments { get { return _arguments; } } #region Private Instance Fields private MethodInfo _method; private object[] _arguments; #endregion } } |
From: Choy R. <ch...@us...> - 2005-02-18 06:37:43
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13400/DotNetMock.Tests/Dynamic Added Files: MethodCallTests.cs Log Message: Started adding one of Roman's ideas to the codebase. A modified version of his MethodCall class that doesn't use MethodSignature (yet). Unclear whether we'll need MethodSignature. --- NEW FILE: MethodCallTests.cs --- #region License // Copyright (c) 2004 Griffin Caprio, Roman V. Gavrilov & Choy Rim. All rights reserved. #endregion #region Imports using System; using System.Reflection; using NUnit.Framework; using DotNetMock.Dynamic; #endregion namespace DotNetMock.Tests.Dynamic { /// <summary> /// Unit tests for <see cref="MethodCall"/>. /// </summary> [TestFixture] public class MethodCallTests { interface IMethods { void Method3(int x, string y, double z); void Method4(); } interface IMethodsA { void Method3(int x, string y, double z); } static readonly MethodInfo method3 = typeof(IMethods).GetMethod("Method3"); static readonly MethodInfo method4 = typeof(IMethods).GetMethod("Method4"); static readonly MethodInfo methodA3 = typeof(IMethodsA).GetMethod("Method3"); [Test] public void MethodCallToString() { MethodCall mc = new MethodCall(method3, 1, "two", 3.4); Assert.AreEqual("Method3(x=1, y=\"two\", z=3.4)", mc.ToString()); mc = new MethodCall(method4); Assert.AreEqual("Method4()", mc.ToString()); } [Test] public void MethodCallEqualsMethodCall() { MethodCall mc1 = new MethodCall(method3, 1, "two", 3.4); MethodCall mc2 = new MethodCall(method3, 1, "two", 3.4); MethodCall mc3 = new MethodCall(method3, 1, "2", 3.4); MethodCall mc4 = new MethodCall(method4); MethodCall mc5 = new MethodCall(methodA3, 1, "two", 3.4); Assert.AreEqual(mc1, mc2); Assert.IsFalse(mc1.Equals(mc3)); Assert.IsFalse(mc1.Equals(mc4)); Assert.IsFalse(mc1.Equals(mc5)); Assert.IsFalse(mc1.Equals(null)); Assert.IsFalse(mc1.Equals("text")); } [ExpectedException( typeof(InvalidOperationException), "Method Method4 takes 0 arguments but received 1." )] [Test] public void TooManyArguments() { MethodCall mc = new MethodCall(method4, 1); } [ExpectedException( typeof(InvalidOperationException), "Method Method3 takes 3 arguments but received 1." )] [Test] public void TooFewArguments() { MethodCall mc = new MethodCall(method3, 1); } } } |
From: Choy R. <ch...@us...> - 2005-02-18 06:37:43
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13400/DotNetMock Modified Files: DotNetMock.csproj Log Message: Started adding one of Roman's ideas to the codebase. A modified version of his MethodCall class that doesn't use MethodSignature (yet). Unclear whether we'll need MethodSignature. Index: DotNetMock.csproj =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/DotNetMock.csproj,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** DotNetMock.csproj 12 Feb 2005 09:07:57 -0000 1.34 --- DotNetMock.csproj 18 Feb 2005 06:37:35 -0000 1.35 *************** *** 245,248 **** --- 245,253 ---- /> <File + RelPath = "Dynamic\MethodCall.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Dynamic\PredicateUtils.cs" SubType = "Code" |