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); } } } |