You can subscribe to this list here.
| 2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(31) |
Dec
(26) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2003 |
Jan
(8) |
Feb
(27) |
Mar
(15) |
Apr
|
May
(2) |
Jun
(13) |
Jul
(59) |
Aug
(48) |
Sep
(9) |
Oct
(4) |
Nov
(24) |
Dec
|
| 2004 |
Jan
(24) |
Feb
(2) |
Mar
(12) |
Apr
(9) |
May
(4) |
Jun
(26) |
Jul
(20) |
Aug
(23) |
Sep
(13) |
Oct
(31) |
Nov
(23) |
Dec
(11) |
| 2005 |
Jan
|
Feb
|
Mar
|
Apr
(19) |
May
(64) |
Jun
(7) |
Jul
(20) |
Aug
(1) |
Sep
(6) |
Oct
|
Nov
(3) |
Dec
|
| 2006 |
Jan
|
Feb
(69) |
Mar
(18) |
Apr
(1) |
May
(4) |
Jun
(3) |
Jul
(27) |
Aug
(19) |
Sep
(12) |
Oct
(3) |
Nov
(13) |
Dec
(6) |
| 2007 |
Jan
(20) |
Feb
(17) |
Mar
(1) |
Apr
(3) |
May
(4) |
Jun
(11) |
Jul
(10) |
Aug
(24) |
Sep
(19) |
Oct
(13) |
Nov
(8) |
Dec
(7) |
| 2008 |
Jan
(54) |
Feb
(24) |
Mar
(11) |
Apr
(35) |
May
(13) |
Jun
(10) |
Jul
(30) |
Aug
(18) |
Sep
(21) |
Oct
(18) |
Nov
(40) |
Dec
(76) |
| 2009 |
Jan
(64) |
Feb
(23) |
Mar
(15) |
Apr
(23) |
May
(46) |
Jun
(25) |
Jul
(31) |
Aug
(7) |
Sep
(7) |
Oct
(6) |
Nov
(15) |
Dec
(19) |
| 2010 |
Jan
(13) |
Feb
(8) |
Mar
(6) |
Apr
(4) |
May
(8) |
Jun
(7) |
Jul
(3) |
Aug
(9) |
Sep
(6) |
Oct
(15) |
Nov
(3) |
Dec
(5) |
| 2011 |
Jan
(1) |
Feb
|
Mar
(4) |
Apr
(5) |
May
(2) |
Jun
|
Jul
(2) |
Aug
(2) |
Sep
(2) |
Oct
(4) |
Nov
(2) |
Dec
(3) |
| 2012 |
Jan
(6) |
Feb
(2) |
Mar
(3) |
Apr
(3) |
May
(3) |
Jun
(1) |
Jul
|
Aug
|
Sep
(2) |
Oct
(2) |
Nov
|
Dec
(1) |
| 2013 |
Jan
(3) |
Feb
(1) |
Mar
|
Apr
|
May
(1) |
Jun
(1) |
Jul
|
Aug
(5) |
Sep
|
Oct
(1) |
Nov
(2) |
Dec
|
| 2014 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
(1) |
Jul
(1) |
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
(1) |
| 2015 |
Jan
|
Feb
(19) |
Mar
(115) |
Apr
(23) |
May
(41) |
Jun
(48) |
Jul
(59) |
Aug
(29) |
Sep
(40) |
Oct
(78) |
Nov
(58) |
Dec
(47) |
| 2016 |
Jan
(25) |
Feb
(30) |
Mar
(29) |
Apr
(10) |
May
(17) |
Jun
(1) |
Jul
(1) |
Aug
(6) |
Sep
(2) |
Oct
(1) |
Nov
(3) |
Dec
(2) |
| 2017 |
Jan
(5) |
Feb
(2) |
Mar
(7) |
Apr
(1) |
May
(7) |
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2018 |
Jan
|
Feb
|
Mar
(5) |
Apr
|
May
(1) |
Jun
|
Jul
(3) |
Aug
|
Sep
|
Oct
|
Nov
(2) |
Dec
|
| 2019 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
(3) |
| 2020 |
Jan
|
Feb
|
Mar
|
Apr
(6) |
May
|
Jun
|
Jul
(29) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2021 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(5) |
Dec
(3) |
| 2022 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(5) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2023 |
Jan
|
Feb
|
Mar
|
Apr
(3) |
May
|
Jun
(7) |
Jul
(1) |
Aug
|
Sep
(6) |
Oct
(4) |
Nov
(1) |
Dec
(4) |
| 2024 |
Jan
(2) |
Feb
(5) |
Mar
|
Apr
|
May
(8) |
Jun
(159) |
Jul
(90) |
Aug
(22) |
Sep
|
Oct
(6) |
Nov
(8) |
Dec
(1) |
| 2025 |
Jan
(20) |
Feb
(6) |
Mar
(2) |
Apr
(4) |
May
(29) |
Jun
(63) |
Jul
(62) |
Aug
(70) |
Sep
(120) |
Oct
(46) |
Nov
(33) |
Dec
(25) |
| 2026 |
Jan
(37) |
Feb
(56) |
Mar
(62) |
Apr
(24) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Steve F. <st...@m3...> - 2004-08-26 21:00:57
|
So why are you hiding ParameterClass? If it's only accessible via Main,
then the whole thing is packaged up in one and there's no point in being
picky. If UnderTest is callable elsewhere then ParameterClass has to be
visible anyway. If I wanted to be more controlled, I'd make
ParameterClass an interface and publish that.
S.
Alexey Kalinichenko wrote:
> Let me make sure I understand you. So if I have something like:
>
> //--------------------------------------------------------------
>
> class ParameterClass
>
> {
>
> public void DoSomething();
>
> }
>
> class UnderTest
>
> {
>
> public UnderTest(ParameterClass pc)
>
> {
>
> this.pc = pc;
>
> }
>
>
>
> public void UseIt()
>
> {
>
> pc.DoSomething();
>
> }
>
> }
>
> public class App
>
> {
>
> public static Main()
>
> {
>
> ClassUnderTest cut = new ClassUnderTest(new ParameterClass());
>
> cut.UseIt();
>
> }
>
> }
>
> //-------------------------------------------------------------------------------
>
> And I want to test ClassUnderTest in isolation, what do I do? Make
> ParameterClass public? I don't see it is a good idea to change it to public just
> for the testing purposes... Or did you mean something else?
>
> Thanks,
>
> Alexey
>
> >From: Steve Freeman <st...@m3...>
> >To: Alexey Kalinichenko <ak...@ho...>
> >Subject: Re: [Nmock-general] NMock and private/internal classes
> >Date: Thu, 26 Aug 2004 11:44:35 +0100
> >
> >Sorry to be facetious, but the short answer is not to test private
> >features, but to break things up so that you can test smaller public
> >components. I've become a lot less protective than I used to be
> >since moving to TDD.
> >
> >S.
> >
> >Alexey Kalinichenko wrote:
> >>I am new to NMock and have a basic question. Is mocking
> >>private/internal class supported by NMock? It doesn't work for me,
> >>I get MemberAccessException for the class ctor. I looked at the
> >>code and as far as I understand the mock class is created in a
> >>dynamic assembly and derived from the specified class. So in order
> >>for this to work the mocked class needs to be public.
> >> Is there any way around it? What is the preferred method of
> >>mocking private classes using NMock?
> >
|
|
From: Jim A. <JA...@th...> - 2004-08-26 11:59:12
|
As far as I know this can't be done with the current framework. The problem is that internal types don't have visibility outside their enclosing type or assembly, and as NMock creates a new assembly for its dynamic mocks we can't inherit from them. Jim "Alexey Kalinichenko" <ak...@ho...> Sent by: nmo...@li... 26/08/2004 02:41 To nmo...@li... cc Subject [Nmock-general] NMock and private/internal classes Hi All, I am new to NMock and have a basic question. Is mocking private/internal class supported by NMock? It doesn't work for me, I get MemberAccessException for the class ctor. I looked at the code and as far as I understand the mock class is created in a dynamic assembly and derived from the specified class. So in order for this to work the mocked class needs to be public. Is there any way around it? What is the preferred method of mocking private classes using NMock? Thanks, Alexey ------------------------------------------------------- SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift. http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285 _______________________________________________ Nmock-general mailing list Nmo...@li... https://lists.sourceforge.net/lists/listinfo/nmock-general |
|
From: Owen R. <exo...@us...> - 2004-08-26 10:19:20
|
Update of /cvsroot/nmock/nmock/src/NMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32254/src/NMock Modified Files: Mock.cs Log Message: Index: Mock.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/Mock.cs,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Mock.cs 24 Aug 2004 21:15:28 -0000 1.16 --- Mock.cs 26 Aug 2004 10:19:11 -0000 1.17 *************** *** 11,15 **** private object instance; private bool strict; ! private IDictionary methods; public Mock(string name) --- 11,15 ---- private object instance; private bool strict; ! protected IDictionary methods; public Mock(string name) |
|
From: Alexey K. <ak...@ho...> - 2004-08-26 01:41:20
|
<html><div style='background-color:'><DIV class=RTE> <DIV class=RTE>Hi All,</DIV> <DIV class=RTE> </DIV> <DIV class=RTE>I am new to NMock and have a basic question. Is mocking private/internal class supported by NMock? It doesn't work for me, I get MemberAccessException for the class ctor. I looked at the code and as far as I understand the mock class is created in a dynamic assembly and derived from the specified class. So in order for this to work the mocked class needs to be public.</DIV> <DIV class=RTE> </DIV> <DIV class=RTE>Is there any way around it? What is the preferred method of mocking private classes using NMock?</DIV> <DIV class=RTE> </DIV> <DIV class=RTE>Thanks,</DIV> <DIV class=RTE>Alexey</DIV></DIV></div></html> |
|
From: Levi K. <lkh...@us...> - 2004-08-24 21:19:17
|
Update of /cvsroot/nmock/nmock/src/NMock/Proxy In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26154/src/NMock/Proxy Modified Files: MockRealProxy.cs Log Message: removing debug print statement left in by mistake Index: MockRealProxy.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/Proxy/MockRealProxy.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MockRealProxy.cs 24 Aug 2004 21:15:29 -0000 1.1 --- MockRealProxy.cs 24 Aug 2004 21:19:03 -0000 1.2 *************** *** 41,45 **** if (method.ReturnType.IsValueType) { - Console.WriteLine(method.ReturnType.FullName); result = Activator.CreateInstance(method.ReturnType); } --- 41,44 ---- |
|
From: Levi K. <lkh...@us...> - 2004-08-24 21:16:16
|
Update of /cvsroot/nmock/nmock/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25016/src Modified Files: src.csproj Log Message: Added ProxyMock: can mock interface and MarshalByRefObjects, can mock sealed classes/non-empty contructor and nonvirtual members; related refactoring; some MethodSignature methods moved to a new class Index: src.csproj =================================================================== RCS file: /cvsroot/nmock/nmock/src/src.csproj,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** src.csproj 23 Jun 2004 04:44:53 -0000 1.11 --- src.csproj 24 Aug 2004 21:15:28 -0000 1.12 *************** *** 150,153 **** --- 150,158 ---- /> <File + RelPath = "NMock\ProxyMock.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "NMock\SingleMethod.cs" SubType = "Code" *************** *** 155,158 **** --- 160,168 ---- /> <File + RelPath = "NMock\TypeCheckedMock.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "NMock\VerifyException.cs" SubType = "Code" *************** *** 205,208 **** --- 215,223 ---- /> <File + RelPath = "NMock\Proxy\MockRealProxy.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "NMock\Remoting\MockServer.cs" SubType = "Code" |
|
From: Levi K. <lkh...@us...> - 2004-08-24 21:15:54
|
Update of /cvsroot/nmock/nmock/test/NMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25016/test/NMock Modified Files: DynamicMockTest.cs Added Files: ProxyMockTest.cs TypeCheckedMockTest.cs Log Message: Added ProxyMock: can mock interface and MarshalByRefObjects, can mock sealed classes/non-empty contructor and nonvirtual members; related refactoring; some MethodSignature methods moved to a new class --- NEW FILE: TypeCheckedMockTest.cs --- using System; using System.Collections; using System.Reflection; using NMock.Constraints; using NUnit.Framework; namespace NMock { public abstract class TypeCheckedMockTest : Assertion { #region types public interface IBaseBlah { string GetSuperString(); } public interface IBlah : IBaseBlah { object DoStuff(string name); } public class SameClass : MarshalByRefObject { public virtual string A() { return c() ? b() : "Default"; } protected virtual string b() { throw new Exception("Should not have called b()"); } protected virtual bool c() { return true; } } public interface IValueType { ArrayList Query(string symbol, DateTime arg2); } public class Thingy : MarshalByRefObject { public void X() {} } public interface IOverloadedMethods { void DoStuff(string one, int two); void DoStuff(string one); } public interface TwoMethods { void Foo(String a); int Bar(String a); } public interface IWithParams { void WithLeadingParameter(int i, params object[] args); void WithoutLeadingParameter(params object[] args); } public class WithNonEmptyConstructor : MarshalByRefObject { public WithNonEmptyConstructor(string unused) { } } public interface IWithProperty { string Name { get; set; } } public class WithNonVirtualMethod : MarshalByRefObject { public void NonVirtualMethod() { } } public interface WithDifferentTypesOfParameters { void SomeParametersMethod(string p1, string p2); } public interface WithMethodThatReturnsAMock { Mock ReturnIt(); } #endregion protected abstract IMock CreateMock(Type type); [Test] public void HasADefaultNameBasedOnMockedType() { IMock mock = CreateMock(typeof(IBlah)); Assertion.AssertEquals("MockIBlah", mock.Name); } [Test] public void DynamicallyImplementsAnInterface() { IMock mock = CreateMock(typeof(IBlah)); mock.ExpectAndReturn("DoStuff", "world", "hello"); IBlah blah = (IBlah)mock.MockInstance; Assertion.AssertEquals("world", blah.DoStuff("hello")); mock.Verify(); } [Test] public void SetupResultCanReturnAssignableTypesAsWellAsTheSameType() { IMock mock = CreateMock(typeof(WithMethodThatReturnsAMock)); mock.SetupResult("ReturnIt", CreateMock(typeof(MarshalByRefObject))); ((WithMethodThatReturnsAMock)mock.MockInstance).ReturnIt(); } [Test] public void InvocationFailsIfParamaterValueIsIncorrect() { IMock m1 = CreateMock(typeof(Thingy)); Thingy thingy = (Thingy)m1.MockInstance; IMock m2 = new Mock("x"); m2.Expect("y", thingy); try { m2.Invoke("y", "something else"); } catch (VerifyException) { return; } Fail("Should have thrown VerifyException"); } [Test] public void CanExpectMultipleInputsAndReturnAValue() { IMock mock = CreateMock(typeof(IValueType)); ArrayList ret = new ArrayList(); DateTime date = DateTime.Now; mock.ExpectAndReturn("Query", ret, "hello", date); IValueType blah = (IValueType)mock.MockInstance; Assertion.AssertEquals(ret, blah.Query("hello", date)); mock.Verify(); } [Test] public void CanExpectFromMembersInheritedFromBaseInterfaces() { IMock mock = CreateMock(typeof(IBlah)); mock.ExpectAndReturn("GetSuperString", "some string"); IBlah b = (IBlah) mock.MockInstance; Assertion.AssertEquals("some string", b.GetSuperString()); mock.Verify(); } [Test] public void CanSetupResultForMembersInheritedFromBaseInterfaces() { IMock mock = CreateMock(typeof(IBlah)); mock.SetupResult("GetSuperString", "some string"); IBlah b = (IBlah) mock.MockInstance; Assertion.AssertEquals("some string", b.GetSuperString()); mock.Verify(); } [Test] public void CanMockMembersWithAParamsArgument() { IMock mock = CreateMock(typeof(IWithParams)); mock.Expect("WithLeadingParameter", 1, new Object[] {1, 2, 3}); IWithParams p = (IWithParams)mock.MockInstance; p.WithLeadingParameter(1, 1, 2, 3); mock.Verify(); } [Test] public void CannotYetMockMembersWithOnlyAParamsArgument() { IMock mock = CreateMock(typeof(IWithParams)); try { mock.Expect("WithoutLeadingParameter", new Object[] {1, 2, 3}); Fail("Should have thrown MissingMethodException"); } catch (MissingMethodException) {} } [Test] public void CanMockOverloadedMethods() { IMock mock = CreateMock(typeof(IOverloadedMethods)); mock.Expect("DoStuff", "one", 2); mock.ExpectNoCall("DoStuff", typeof(string)); IOverloadedMethods instance = (IOverloadedMethods)mock.MockInstance; instance.DoStuff("one", 2); mock.Verify(); } [Test] public void CanMockMethodWithConstraint() { IMock mock = CreateMock(typeof(TwoMethods)); mock.Expect("Foo", new StartsWith("Hello")); mock.ExpectAndReturn("Bar", 5, new NotNull()); TwoMethods instance = (TwoMethods)mock.MockInstance; instance.Foo("Hello World"); Assertion.AssertEquals("Should get a result", 5, instance.Bar("not null")); mock.Verify(); } [Test] public void CanSetAndGetPropertiesOnAMockedInterface() { IMock mock = CreateMock(typeof(IWithProperty)); IWithProperty withProperty = (IWithProperty)mock.MockInstance; mock.ExpectAndReturn("Name", "fred"); mock.Expect("Name", "joe"); AssertEquals("Should be property Name", "fred", withProperty.Name); withProperty.Name = "joe"; mock.Verify(); } [Test] public void SetAndGetPropertiesDoesNotWorkWithSetupReturn() { IMock mock = CreateMock(typeof(IWithProperty)); IWithProperty withProperty = (IWithProperty)mock.MockInstance; mock.SetupResult("Name", "fred"); mock.Expect("Name", "jim"); try { AssertEquals("Should be property Name", "fred", withProperty.Name); withProperty.Name = "jim"; mock.Verify(); } catch (VerifyException) { return; } Fail("Should have thrown VerifyException"); } [Test] public void TestNullParameterCanStillResolveCorrectMethod() { IMock mock = CreateMock(typeof(WithDifferentTypesOfParameters)); WithDifferentTypesOfParameters instance = (WithDifferentTypesOfParameters)mock.MockInstance; //works mock.Expect("SomeParametersMethod", "foo", "foo"); instance.SomeParametersMethod("foo", "foo"); //fails mock.Expect("SomeParametersMethod", "foo", null); instance.SomeParametersMethod("foo", null); mock.Verify(); } [Test] public void TestNullConstraintsCanStillResolveCorrectMethod() { IMock mock = CreateMock(typeof(WithDifferentTypesOfParameters)); WithDifferentTypesOfParameters instance = (WithDifferentTypesOfParameters)mock.MockInstance; //works mock.Expect("SomeParametersMethod", "foo", "foo"); instance.SomeParametersMethod("foo", "foo"); //bug - cannot resolve this mock.Expect("SomeParametersMethod", "foo", new IsNull()); instance.SomeParametersMethod("foo", null); mock.Verify(); } } } --- NEW FILE: ProxyMockTest.cs --- using System; using NUnit.Framework; namespace NMock { [TestFixture] public class ProxyMockTest : TypeCheckedMockTest { #region types public class CustomMock : ProxyMock { public CustomMock(Type t) : base(t) {} public override object Invoke(string name, params object[] args) { return "CUSTOM"; } } public class NonMarshalByRef { } public sealed class SealedThingy : MarshalByRefObject { } #endregion protected override IMock CreateMock(Type type) { return new ProxyMock(type); } [Test] public void CanBeExplicitlyNamed() { IMock mock = new ProxyMock(typeof(IBlah), "XBlah"); Assertion.AssertEquals("XBlah", mock.Name); } [Test] public void CannotSetStubsAndExpectationsOnMethodsInTheSameClass() { ProxyMock mock = new ProxyMock(typeof(SameClass)); SameClass sc = (SameClass)mock.MockInstance; mock.ExpectAndReturn("c", true); mock.SetupResult("b", "hello"); AssertEquals("Should not have overriden B()", null, sc.A()); } [Test] public void CanBeCustomisedByOverridingCallMethod() { IMock mock = new CustomMock(typeof(IBlah)); IBlah blah = (IBlah)mock.MockInstance; Assertion.AssertEquals("CUSTOM", blah.DoStuff("hello")); mock.Verify(); } [Test] public void NamedProxyMockImplementsAnInterface() { IMock mock = new ProxyMock(typeof(IBlah), "XBlah"); mock.ExpectAndReturn("DoStuff", "world", "hello"); IBlah blah = (IBlah)mock.MockInstance; Assertion.AssertEquals("world", blah.DoStuff("hello")); mock.Verify(); } [Test] public void StubbedMethodsCannotBeCalledByOtherMethodsWithinObject() { ProxyMock mock = new ProxyMock(typeof(SameClass)); SameClass sc = (SameClass)mock.MockInstance; mock.SetupResult("b", "hello"); Assertion.AssertEquals(null, sc.A()); } [Test] public void MockInstanceCanBeUsedAsValueInAnExpectation() { IMock mockThingy = new ProxyMock(typeof(Thingy)); Thingy thingy = (Thingy)mockThingy.MockInstance; mockThingy.SetupResult("Equals", true, typeof(object)); IMock m2 = new Mock("x"); m2.Expect("y", thingy); m2.Invoke("y", thingy); m2.Verify(); } [Test] public void CanMockNonVirtualMethodsOfAClass() { IMock mock = new ProxyMock(typeof(WithNonVirtualMethod)); mock.Expect("NonVirtualMethod"); } [Test] public void CanCreateMockInstanceWithNonEmptyConstructor() { IMock mock = new ProxyMock(typeof(WithNonEmptyConstructor)); WithNonEmptyConstructor nonEmpty = (WithNonEmptyConstructor)mock.MockInstance; } [ExpectedExceptionAttribute(typeof(ArgumentException))] [Test] public void CannotMockNonMarshalByRefClass() { new ProxyMock(typeof(NonMarshalByRef)); } [Test] public void CanMockSealedClass() { new ProxyMock(typeof(SealedThingy)); } } } Index: DynamicMockTest.cs =================================================================== RCS file: /cvsroot/nmock/nmock/test/NMock/DynamicMockTest.cs,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** DynamicMockTest.cs 24 Aug 2004 16:00:24 -0000 1.23 --- DynamicMockTest.cs 24 Aug 2004 21:15:30 -0000 1.24 *************** *** 1,25 **** - using NUnit.Framework; using System; - using System.Collections; using System.Reflection; ! using NMock.Constraints; namespace NMock { ! [TestFixture] public class DynamicMockTest : Assertion { #region types ! interface IBaseBlah ! { ! string GetSuperString(); ! } ! ! interface IBlah : IBaseBlah ! { ! object DoStuff(string name); ! } ! ! private class CustomMock : DynamicMock { public CustomMock(Type t) : base(t) {} --- 1,14 ---- using System; using System.Reflection; ! ! using NUnit.Framework; namespace NMock { ! [TestFixture] public class DynamicMockTest : TypeCheckedMockTest { #region types ! public class CustomMock : DynamicMock { public CustomMock(Type t) : base(t) {} *************** *** 30,99 **** } } - public class SameClass - { - public virtual string A() { return c() ? b() : "Default"; } - protected virtual string b() { throw new Exception("Should not have called b()"); } - protected virtual bool c() { return true; } - } - - interface IValueType - { - ArrayList Query(string symbol, DateTime arg2); - } - - public class Thingy - { - public void X() {} - } - interface IOverloadedMethods - { - void DoStuff(string one, int two); - void DoStuff(string one); - } - interface TwoMethods - { - void Foo(String a); - int Bar(String a); - } - interface IWithParams - { - void WithLeadingParameter(int i, params object[] args); - void WithoutLeadingParameter(params object[] args); - } - class WithNonEmptyConstructor - { - public WithNonEmptyConstructor(string unused) - { - } - } - interface IWithProperty - { - string Name { get; set; } - } - class WithNonVirtualMethod - { - public void NonVirtualMethod() { } - } - interface WithDifferentTypesOfParameters - { - void SomeParametersMethod(string p1, string p2); - } - - interface WithMethodThatReturnsAMock - { - Mock ReturnIt(); - } public class DisposableThingy : Thingy { } #endregion ! [Test] public void HasADefaultNameBasedOnMockedType() { ! IMock mock = new DynamicMock(typeof(IBlah)); ! Assertion.AssertEquals("MockIBlah", mock.Name); } [Test] public void CanBeExplicitlyNamed() { --- 19,35 ---- } } public class DisposableThingy : Thingy { } + #endregion ! protected override IMock CreateMock(Type type) { ! return new DynamicMock(type); } + [Test] public void CanBeExplicitlyNamed() { *************** *** 102,114 **** } ! [Test] public void DynamicallyImplementsAnInterface() { ! IMock mock = new DynamicMock(typeof(IBlah)); ! ! mock.ExpectAndReturn("DoStuff", "world", "hello"); ! IBlah blah = (IBlah)mock.MockInstance; ! Assertion.AssertEquals("world", blah.DoStuff("hello")); ! mock.Verify(); } --- 38,60 ---- } ! [Test] public void CanSetStubsAndExpectationsOnMethodsInTheSameClass() { ! DynamicMock mock = new DynamicMock(typeof(SameClass)); ! mock.Ignore("A"); ! SameClass sc = (SameClass)mock.MockInstance; ! ! mock.ExpectAndReturn("c", true); ! mock.SetupResult("b", "hello"); ! ! AssertEquals("Should have overriden B()", "hello", sc.A()); ! ! mock.Verify(); ! } ! ! [Test] public void CanBeCustomisedByOverridingCallMethod() ! { ! IMock mock = new CustomMock(typeof(IBlah)); IBlah blah = (IBlah)mock.MockInstance; ! Assertion.AssertEquals("CUSTOM", blah.DoStuff("hello")); mock.Verify(); } *************** *** 126,137 **** } - [Test] public void CanBeCustomisedByOverridingCallMethod() - { - IMock mock = new CustomMock(typeof(IBlah)); - IBlah blah = (IBlah)mock.MockInstance; - Assertion.AssertEquals("CUSTOM", blah.DoStuff("hello")); - mock.Verify(); - } - [Test] public void StubbedMethodsCanBeCalledByOtherMethodsWithinObject() { --- 72,75 ---- *************** *** 146,176 **** } - [Test] public void SetupResultCanReturnAssignableTypesAsWellAsTheSameType() - { - DynamicMock mock = new DynamicMock(typeof(WithMethodThatReturnsAMock)); - - mock.SetupResult("ReturnIt", new DynamicMock(typeof(object))); - - ((WithMethodThatReturnsAMock)mock.MockInstance).ReturnIt(); - } - [Test] public void CanSetStubsAndExpectationsOnMethodsInTheSameClass() - { - DynamicMock mock = new DynamicMock(typeof(SameClass)); - mock.Ignore("A"); - SameClass sc = (SameClass)mock.MockInstance; - - mock.ExpectAndReturn("c", true); - mock.SetupResult("b", "hello"); - - AssertEquals("Should have overriden B()", "hello", sc.A()); - - mock.Verify(); - } - [Test] public void MockInstanceCanBeUsedAsValueInAnExpectation() { ! DynamicMock mockThingy = new DynamicMock(typeof(Thingy)); Thingy thingy = (Thingy)mockThingy.MockInstance; ! Mock m2 = new Mock("x"); m2.Expect("y", thingy); --- 84,92 ---- } [Test] public void MockInstanceCanBeUsedAsValueInAnExpectation() { ! IMock mockThingy = new DynamicMock(typeof(Thingy)); Thingy thingy = (Thingy)mockThingy.MockInstance; ! IMock m2 = new Mock("x"); m2.Expect("y", thingy); *************** *** 179,258 **** } ! [Test] public void InvocationFailsIfParamaterValueIsIncorrect() ! { ! DynamicMock m1 = new DynamicMock(typeof(Thingy)); ! Thingy thingy = (Thingy)m1.MockInstance; ! Mock m2 = new Mock("x"); ! ! m2.Expect("y", thingy); ! try ! { ! m2.Invoke("y", "something else"); ! } ! catch (VerifyException) ! { ! return; ! } ! Fail("Should have thrown VerifyException"); ! } ! ! [Test] public void CanExpectMultipleInputsAndReturnAValue() ! { ! IMock mock = new DynamicMock(typeof(IValueType)); ! ArrayList ret = new ArrayList(); ! DateTime date = DateTime.Now; ! mock.ExpectAndReturn("Query", ret, "hello", date); ! ! IValueType blah = (IValueType)mock.MockInstance; ! Assertion.AssertEquals(ret, blah.Query("hello", date)); ! ! mock.Verify(); ! } ! ! [Test] public void CanExpectFromMembersInheritedFromBaseInterfaces() ! { ! IMock mock = new DynamicMock(typeof(IBlah)); ! mock.ExpectAndReturn("GetSuperString", "some string"); ! ! IBlah b = (IBlah) mock.MockInstance; ! ! Assertion.AssertEquals("some string", b.GetSuperString()); ! mock.Verify(); ! } ! ! [Test] public void CanSetupResultForMembersInheritedFromBaseInterfaces() ! { ! IMock mock = new DynamicMock(typeof(IBlah)); ! mock.SetupResult("GetSuperString", "some string"); ! ! IBlah b = (IBlah) mock.MockInstance; ! ! Assertion.AssertEquals("some string", b.GetSuperString()); ! mock.Verify(); ! } ! ! [Test] public void CanMockMembersWithAParamsArgument() ! { ! IMock mock = new DynamicMock(typeof(IWithParams)); ! mock.Expect("WithLeadingParameter", 1, new Object[] {1, 2, 3}); ! ! IWithParams p = (IWithParams)mock.MockInstance; ! p.WithLeadingParameter(1, 1, 2, 3); ! mock.Verify(); ! } ! ! [Test] public void CannotYetMockMembersWithOnlyAParamsArgument() ! { ! IMock mock = new DynamicMock(typeof(IWithParams)); ! try ! { ! mock.Expect("WithoutLeadingParameter", new Object[] {1, 2, 3}); ! Fail("Should have thrown MissingMethodException"); ! } ! catch (MissingMethodException) ! {} ! } ! ! [Test] public void CannotMockNonVirtualMethodsOfAClass() { IMock mock = new DynamicMock(typeof(WithNonVirtualMethod)); --- 95,99 ---- } ! [Test] public void CannotMockNonVirtualMethodsOfAClass() { IMock mock = new DynamicMock(typeof(WithNonVirtualMethod)); *************** *** 266,297 **** } ! [Test] public void CanMockOverloadedMethods() ! { ! IMock mock = new DynamicMock(typeof(IOverloadedMethods)); ! mock.Expect("DoStuff", "one", 2); ! mock.ExpectNoCall("DoStuff", typeof(string)); ! ! IOverloadedMethods instance = (IOverloadedMethods)mock.MockInstance; ! instance.DoStuff("one", 2); ! ! mock.Verify(); ! } ! ! [Test] public void CanMockMethodWithConstraint() ! { ! IMock mock = new DynamicMock(typeof(TwoMethods)); ! mock.Expect("Foo", new StartsWith("Hello")); ! mock.ExpectAndReturn("Bar", 5, new NotNull()); ! ! TwoMethods instance = (TwoMethods)mock.MockInstance; ! instance.Foo("Hello World"); ! Assertion.AssertEquals("Should get a result", 5, instance.Bar("not null")); ! ! mock.Verify(); ! } ! ! [Test] public void CannotCreateMockInstanceWithNonEmptyConstructor() { ! IMock mock = new DynamicMock(typeof(WithNonEmptyConstructor)); try { --- 107,113 ---- } ! [Test] public void CannotCreateMockInstanceWithNonEmptyConstructor() { ! IMock mock = CreateMock(typeof(WithNonEmptyConstructor)); try { *************** *** 301,372 **** catch (NotSupportedException) {} } - - [Test] public void CanSetAndGetPropertiesOnAMockedInterface() - { - DynamicMock mock = new DynamicMock(typeof(IWithProperty)); - IWithProperty withProperty = (IWithProperty)mock.MockInstance; - - mock.ExpectAndReturn("Name", "fred"); - mock.Expect("Name", "joe"); - - AssertEquals("Should be property Name", "fred", withProperty.Name); - withProperty.Name = "joe"; - - mock.Verify(); - } - - [Test] public void SetAndGetPropertiesDoesNotWorkWithSetupReturn() - { - DynamicMock mock = new DynamicMock(typeof(IWithProperty)); - IWithProperty withProperty = (IWithProperty)mock.MockInstance; - - mock.SetupResult("Name", "fred"); - mock.Expect("Name", "jim"); - - try - { - AssertEquals("Should be property Name", "fred", withProperty.Name); - withProperty.Name = "jim"; - mock.Verify(); - } - catch (VerifyException) - { - return; - } - - Fail("Should have thrown VerifyException"); - } - - [Test] public void TestNullParameterCanStillResolveCorrectMethod() - { - DynamicMock mock = new DynamicMock(typeof(WithDifferentTypesOfParameters)); - WithDifferentTypesOfParameters instance = (WithDifferentTypesOfParameters)mock.MockInstance; - - //works - mock.Expect("SomeParametersMethod", "foo", "foo"); - instance.SomeParametersMethod("foo", "foo"); - - //fails - mock.Expect("SomeParametersMethod", "foo", null); - instance.SomeParametersMethod("foo", null); - - mock.Verify(); - } - - [Test] public void TestNullConstraintsCanStillResolveCorrectMethod() - { - DynamicMock mock = new DynamicMock(typeof(WithDifferentTypesOfParameters)); - WithDifferentTypesOfParameters instance = (WithDifferentTypesOfParameters)mock.MockInstance; - - //works - mock.Expect("SomeParametersMethod", "foo", "foo"); - instance.SomeParametersMethod("foo", "foo"); - - //bug - cannot resolve this - mock.Expect("SomeParametersMethod", "foo", new IsNull()); - instance.SomeParametersMethod("foo", null); - - mock.Verify(); - } [Test] public void VerifyThatFinalizeIsNotOverriddenInMockSubClass() --- 117,120 ---- *************** *** 381,385 **** IMock mock = new DynamicMock(typeof(DisposableThingy)); mock.Strict = true; ! return (DisposableThingy) mock.MockInstance; } } --- 129,133 ---- IMock mock = new DynamicMock(typeof(DisposableThingy)); mock.Strict = true; ! return (DisposableThingy)mock.MockInstance; } } |
Update of /cvsroot/nmock/nmock/src/NMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25016/src/NMock Modified Files: DynamicMock.cs Method.cs MethodSignature.cs Mock.cs MockCall.cs SingleMethod.cs Added Files: ProxyMock.cs TypeCheckedMock.cs Log Message: Added ProxyMock: can mock interface and MarshalByRefObjects, can mock sealed classes/non-empty contructor and nonvirtual members; related refactoring; some MethodSignature methods moved to a new class Index: Method.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/Method.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Method.cs 24 Aug 2004 16:00:24 -0000 1.6 --- Method.cs 24 Aug 2004 21:15:28 -0000 1.7 *************** *** 20,24 **** public virtual string Name { ! get { return signature.methodName; } } --- 20,24 ---- public virtual string Name { ! get { return signature.MethodName; } } *************** *** 37,41 **** MockCall mockCall = expectations[timesCalled]; timesCalled++; ! return mockCall.Call(signature.methodName, parameters); } --- 37,41 ---- MockCall mockCall = expectations[timesCalled]; timesCalled++; ! return mockCall.Call(signature.MethodName, parameters); } Index: MethodSignature.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/MethodSignature.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MethodSignature.cs 24 Aug 2004 16:00:24 -0000 1.5 --- MethodSignature.cs 24 Aug 2004 21:15:28 -0000 1.6 *************** *** 10,22 **** public class MethodSignature { ! public readonly string typeName; ! public readonly string methodName; ! public readonly Type[] argumentTypes; public MethodSignature(string typeName, string methodName, params Type[] argumentTypes) { ! this.typeName = typeName; ! this.methodName = methodName; ! this.argumentTypes = argumentTypes; } --- 10,22 ---- public class MethodSignature { ! public readonly string TypeName; ! public readonly string MethodName; ! public readonly Type[] ArgumentTypes; public MethodSignature(string typeName, string methodName, params Type[] argumentTypes) { ! TypeName = typeName; ! MethodName = methodName; ! ArgumentTypes = argumentTypes; } *************** *** 24,28 **** { StringBuilder argumentList = new StringBuilder(); ! foreach (Type type in argumentTypes) { if (argumentList.Length > 0) argumentList.Append(", "); --- 24,28 ---- { StringBuilder argumentList = new StringBuilder(); ! foreach (Type type in ArgumentTypes) { if (argumentList.Length > 0) argumentList.Append(", "); *************** *** 37,41 **** } } ! return string.Format("{0}.{1}({2})", typeName, methodName, argumentList); } --- 37,41 ---- } } ! return string.Format("{0}.{1}({2})", TypeName, MethodName, argumentList); } *************** *** 44,48 **** get { ! foreach(Type argType in argumentTypes) { if(typeof(IConstraint).IsAssignableFrom(argType)) --- 44,48 ---- get { ! foreach(Type argType in ArgumentTypes) { if(typeof(IConstraint).IsAssignableFrom(argType)) *************** *** 52,123 **** } } - - public PropertyInfo FindMatchingPropertyOn(Type type) - { - return type.GetProperty( - methodName, ClassGenerator.ALL_INSTANCE_METHODS); - } - - public MethodInfo FindMatchingMethodIn(Type type) - { - foreach (MethodInfo methodInfo in type.GetMethods(ClassGenerator.ALL_INSTANCE_METHODS)) - { - if (MatchesNameAndAllNonNullArguments(methodInfo)) - { - return methodInfo; - } - } - return null; - } - - public bool IsPropertyOn(Type type) - { - return type.GetProperty(methodName, ClassGenerator.ALL_INSTANCE_METHODS) != null; - } - - public bool HasMatchingMethodIn(Type type) - { - foreach (MethodInfo methodInfo in type.GetMethods(ClassGenerator.ALL_INSTANCE_METHODS)) - { - if (MatchesNameAndAllNonNullArguments(methodInfo)) - { - return true; - } - } - return false; - } - - private bool MatchesNameAndAllNonNullArguments(MethodInfo methodInfo) - { - if (!methodName.Equals(methodInfo.Name)) - return false; - - if (! MatchNonNullArguments(methodInfo.GetParameters())) - return false; - - if(!methodInfo.IsVirtual) - throw new ArgumentException(String.Format("method <{0}> is not virtual", methodName)); - - return true; - } - - - private bool MatchNonNullArguments(ParameterInfo[] parameters) - { - if ( argumentTypes.Length != parameters.Length ) - return false; - - for ( int pi=0; pi<parameters.Length; pi++ ) - { - Type argumentType = argumentTypes[pi]; - if (argumentType == null) - continue; - - Type parameterType = parameters[pi].ParameterType; - if (!parameterType.IsAssignableFrom(argumentType)) - return false; - } - return true; - } } } --- 52,55 ---- Index: DynamicMock.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/DynamicMock.cs,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** DynamicMock.cs 18 Aug 2004 14:59:24 -0000 1.22 --- DynamicMock.cs 24 Aug 2004 21:15:28 -0000 1.23 *************** *** 2,14 **** using System.Collections; using System.Reflection; using NMock.Dynamic; - using NMock.Constraints; namespace NMock { ! public class DynamicMock : Mock { private object mockInstance; - private Type type; private IList ignoredMethodNames; private readonly Type superclassIfTypeIsInterface; --- 2,13 ---- using System.Collections; using System.Reflection; + using NMock.Dynamic; namespace NMock { ! public class DynamicMock : TypeCheckedMock { private object mockInstance; private IList ignoredMethodNames; private readonly Type superclassIfTypeIsInterface; *************** *** 18,25 **** public DynamicMock(Type type, string name) : this (type, name, null) {} ! public DynamicMock(Type type, string name, Type superclassIfTypeIsInterface) : base(name) { this.ignoredMethodNames = new ArrayList(); - this.type = type; this.superclassIfTypeIsInterface = superclassIfTypeIsInterface; } --- 17,23 ---- public DynamicMock(Type type, string name) : this (type, name, null) {} ! public DynamicMock(Type type, string name, Type superclassIfTypeIsInterface) : base(type, name) { this.ignoredMethodNames = new ArrayList(); this.superclassIfTypeIsInterface = superclassIfTypeIsInterface; } *************** *** 45,107 **** } ! private ClassGenerator CreateClassGenerator() ! { ! return new ClassGenerator(type, this, ignoredMethodNames, superclassIfTypeIsInterface); ! } ! ! protected override IMethod getMethod(MethodSignature signature) ! { ! CheckMethodIsValidIfNoConstraints(signature); ! return base.getMethod(signature); ! } ! ! public override void SetupResult(string methodName, object returnVal, params Type[] argTypes) ! { ! MethodSignature signature = new MethodSignature(Name, methodName, argTypes); ! CheckReturnTypeIsValid(signature, returnVal); ! SetupResult(signature, returnVal); ! } ! ! private void CheckReturnTypeIsValid(MethodSignature signature, object returnVal) { ! if (returnVal == null) ! return; ! ! if (signature.HasAConstraintArgument) ! return; ! ! Type realReturnType = GetReturnTypeForSignature(signature); ! if (!realReturnType.IsAssignableFrom(returnVal.GetType())) ! { throw new ArgumentException( ! string.Format("method <{0}> should return a {1}", ! signature, realReturnType)); ! } } ! private void CheckMethodIsValidIfNoConstraints(MethodSignature signature) { ! if (signature.HasAConstraintArgument) ! return; ! ! GetReturnTypeForSignature(signature); } - - private Type GetReturnTypeForSignature(MethodSignature signature) - { - foreach (Type t in new InterfaceLister().List(type)) - { - MethodInfo method = signature.FindMatchingMethodIn(t); - if (method != null) - return method.ReturnType; - - PropertyInfo property = signature.FindMatchingPropertyOn(t); - if (property != null) - return property.PropertyType; - } - - throw new MissingMethodException( - string.Format("method <{0}> not defined", signature)); - } } } --- 43,57 ---- } ! protected override void ValidateMethodInfo(MethodInfo methodInfo) { ! if(!methodInfo.IsVirtual) throw new ArgumentException( ! string.Format("method <{0}> is not virtual", methodInfo.Name)); } ! private ClassGenerator CreateClassGenerator() { ! return new ClassGenerator(MockedType, this, ignoredMethodNames, superclassIfTypeIsInterface); } } } --- NEW FILE: ProxyMock.cs --- using System; using NMock.Proxy; namespace NMock { public class ProxyMock : TypeCheckedMock { private readonly MockRealProxy proxy; public ProxyMock(Type type) : this(type, "Mock" + type.Name) { } public ProxyMock(Type type, string name) : base(type, name) { proxy = new MockRealProxy(this, type); } public override object MockInstance { get { return proxy.GetTransparentProxy(); } } } } --- NEW FILE: TypeCheckedMock.cs --- using System; using System.Reflection; using NMock.Dynamic; namespace NMock { public abstract class TypeCheckedMock : Mock { private Type type; public TypeCheckedMock(Type type, string name) : base(name) { this.type = type; } public Type MockedType { get { return type; } } public override void SetupResult(string methodName, object returnVal, params Type[] argTypes) { MethodSignature signature = new MethodSignature(Name, methodName, argTypes); CheckReturnTypeIsValid(signature, returnVal); SetupResult(signature, returnVal); } protected override IMethod getMethod(MethodSignature signature) { CheckMethodIsValidIfNoConstraints(signature); return base.getMethod(signature); } protected void CheckReturnTypeIsValid(MethodSignature signature, object returnVal) { if (returnVal == null) return; if (signature.HasAConstraintArgument) return; Type realReturnType = GetReturnTypeForSignature(signature); if (!realReturnType.IsAssignableFrom(returnVal.GetType())) { throw new ArgumentException( string.Format("method <{0}> should return a {1}", signature, realReturnType)); } } protected void CheckMethodIsValidIfNoConstraints(MethodSignature signature) { if (signature.HasAConstraintArgument) return; GetReturnTypeForSignature(signature); } protected Type GetReturnTypeForSignature(MethodSignature signature) { foreach (Type t in new InterfaceLister().List(MockedType)) { MethodInfo method = FindMatchingMethodIn(signature, t); if (method != null) return method.ReturnType; PropertyInfo property = FindMatchingPropertyOn(signature, t); if (property != null) return property.PropertyType; } throw new MissingMethodException( string.Format("method <{0}> not defined", signature)); } internal static string StripGetSetPrefix(string methodName) { if (methodName.StartsWith("get_") || methodName.StartsWith("set_")) { methodName = methodName.Substring(4); } return methodName; } private PropertyInfo FindMatchingPropertyOn(MethodSignature signature, Type type) { return type.GetProperty( signature.MethodName, ClassGenerator.ALL_INSTANCE_METHODS); } private MethodInfo FindMatchingMethodIn(MethodSignature signature, Type type) { foreach (MethodInfo methodInfo in type.GetMethods(ClassGenerator.ALL_INSTANCE_METHODS)) { if (MatchesNameAndAllNonNullArguments(signature, methodInfo)) { return methodInfo; } } return null; } private bool IsPropertyOn(MethodSignature signature, Type type) { return type.GetProperty(signature.MethodName, ClassGenerator.ALL_INSTANCE_METHODS) != null; } private bool HasMatchingMethodIn(MethodSignature signature, Type type) { foreach (MethodInfo methodInfo in type.GetMethods(ClassGenerator.ALL_INSTANCE_METHODS)) { if (MatchesNameAndAllNonNullArguments(signature, methodInfo)) { return true; } } return false; } private bool MatchesNameAndAllNonNullArguments(MethodSignature signature, MethodInfo methodInfo) { if (!signature.MethodName.Equals(methodInfo.Name)) return false; if (! MatchNonNullArguments(signature, methodInfo.GetParameters())) return false; ValidateMethodInfo(methodInfo); return true; } private bool MatchNonNullArguments(MethodSignature signature, ParameterInfo[] parameters) { if ( signature.ArgumentTypes.Length != parameters.Length ) return false; for ( int pi=0; pi<parameters.Length; pi++ ) { Type argumentType = signature.ArgumentTypes[pi]; if (argumentType == null) continue; Type parameterType = parameters[pi].ParameterType; if (!parameterType.IsAssignableFrom(argumentType)) return false; } return true; } protected virtual void ValidateMethodInfo(MethodInfo methodInfo) { } } } Index: SingleMethod.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/SingleMethod.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SingleMethod.cs 24 Aug 2004 16:00:24 -0000 1.3 --- SingleMethod.cs 24 Aug 2004 21:15:28 -0000 1.4 *************** *** 17,21 **** public string Name { ! get { return signature.methodName; } } --- 17,21 ---- public string Name { ! get { return signature.MethodName; } } *************** *** 27,31 **** public virtual object Call(params object[] parameters) { ! object obj = expectation.Call(signature.methodName, parameters); timesCalled++; return obj; --- 27,31 ---- public virtual object Call(params object[] parameters) { ! object obj = expectation.Call(signature.MethodName, parameters); timesCalled++; return obj; Index: MockCall.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/MockCall.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** MockCall.cs 24 Aug 2004 16:00:24 -0000 1.8 --- MockCall.cs 24 Aug 2004 21:15:28 -0000 1.9 *************** *** 24,28 **** } ! public Type[] ArgTypes { get {return signature.argumentTypes; } } private IConstraint[] argsAsConstraints(object[] args) --- 24,28 ---- } ! public Type[] ArgTypes { get {return signature.ArgumentTypes; } } private IConstraint[] argsAsConstraints(object[] args) Index: Mock.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/Mock.cs,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Mock.cs 24 Aug 2004 16:00:24 -0000 1.15 --- Mock.cs 24 Aug 2004 21:15:28 -0000 1.16 *************** *** 81,86 **** if (method == null) { ! method = new CallMethodWithoutExpectation(signature.methodName); ! methods[signature.methodName] = method; } method.SetExpectation(new MockCall(signature, returnVal, null, null)); --- 81,86 ---- if (method == null) { ! method = new CallMethodWithoutExpectation(signature.MethodName); ! methods[signature.MethodName] = method; } method.SetExpectation(new MockCall(signature, returnVal, null, null)); *************** *** 112,116 **** protected virtual IMethod getMethod(MethodSignature signature) { ! return (IMethod)methods[signature.methodName]; } --- 112,116 ---- protected virtual IMethod getMethod(MethodSignature signature) { ! return (IMethod)methods[signature.MethodName]; } |
|
From: Levi K. <lkh...@us...> - 2004-08-24 21:15:54
|
Update of /cvsroot/nmock/nmock/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25016/test Modified Files: test.csproj Log Message: Added ProxyMock: can mock interface and MarshalByRefObjects, can mock sealed classes/non-empty contructor and nonvirtual members; related refactoring; some MethodSignature methods moved to a new class Index: test.csproj =================================================================== RCS file: /cvsroot/nmock/nmock/test/test.csproj,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** test.csproj 23 Jun 2004 04:44:53 -0000 1.10 --- test.csproj 24 Aug 2004 21:15:30 -0000 1.11 *************** *** 125,128 **** --- 125,138 ---- /> <File + RelPath = "NMock\ProxyMockTest.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "NMock\TypeCheckedMockTest.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "NMock\VerifyExceptionTest.cs" SubType = "Code" |
|
From: Levi K. <lkh...@us...> - 2004-08-24 21:15:53
|
Update of /cvsroot/nmock/nmock/src/NMock/Proxy In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25016/src/NMock/Proxy Added Files: MockRealProxy.cs Log Message: Added ProxyMock: can mock interface and MarshalByRefObjects, can mock sealed classes/non-empty contructor and nonvirtual members; related refactoring; some MethodSignature methods moved to a new class --- NEW FILE: MockRealProxy.cs --- using System; using System.Reflection; using System.Runtime.Remoting; using System.Runtime.Remoting.Proxies; using System.Runtime.Remoting.Messaging; namespace NMock.Proxy { public class MockRealProxy : RealProxy { private readonly IMock mock; private readonly Type type; public MockRealProxy(IMock mock, Type type) : base(type) { this.mock = mock; this.type = type; } public override IMessage Invoke(IMessage msg) { IMethodCallMessage call = msg as IMethodCallMessage; if (call == null) { throw new NotSupportedException("Unsupported call type " + msg.GetType()); } if (call.MethodName == "GetType" && call.InArgCount == 0) { return new ReturnMessage(type, null, 0, null, call); } return new ReturnMessage(ExecuteCall(call), null, 0, null, call); } private object ExecuteCall(IMethodCallMessage call) { string methodName = TypeCheckedMock.StripGetSetPrefix(call.MethodName); object result = mock.Invoke(methodName, call.InArgs); if (result == null) { MethodInfo method = type.GetMethod(call.MethodName, (Type[])call.MethodSignature); if (method.ReturnType.IsValueType) { Console.WriteLine(method.ReturnType.FullName); result = Activator.CreateInstance(method.ReturnType); } } return result; } } } |
|
From: Levi K. <lkh...@us...> - 2004-08-24 21:15:50
|
Update of /cvsroot/nmock/nmock/src/NMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25016/src/NMock/Dynamic Modified Files: MethodImplementor.cs Log Message: Added ProxyMock: can mock interface and MarshalByRefObjects, can mock sealed classes/non-empty contructor and nonvirtual members; related refactoring; some MethodSignature methods moved to a new class Index: MethodImplementor.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/Dynamic/MethodImplementor.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MethodImplementor.cs 17 Jun 2004 05:13:38 -0000 1.1 --- MethodImplementor.cs 24 Aug 2004 21:15:29 -0000 1.2 *************** *** 24,28 **** MSILStack stack = new MSILStack(methodBuilder.GetILGenerator()); ! CallInvocationHandler(stack, parameters, StripGetSetPrefix(method.Name)); ReturnFromMethod(stack, method.ReturnType); --- 24,28 ---- MSILStack stack = new MSILStack(methodBuilder.GetILGenerator()); ! CallInvocationHandler(stack, parameters, TypeCheckedMock.StripGetSetPrefix(method.Name)); ReturnFromMethod(stack, method.ReturnType); *************** *** 69,82 **** } - private string StripGetSetPrefix(string methodName) - { - if (methodName.StartsWith("get_") || methodName.StartsWith("set_")) - { - methodName = methodName.Substring(4); - } - - return methodName; - } - private Type[] ExtractParameterTypes(MethodInfo method) { --- 69,72 ---- |
|
From: Levi K. <lkh...@us...> - 2004-08-24 21:09:33
|
Update of /cvsroot/nmock/nmock/src/NMock/Proxy In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23279/Proxy Log Message: Directory /cvsroot/nmock/nmock/src/NMock/Proxy added to the repository |
|
From: Levi K. <lkh...@us...> - 2004-08-24 16:00:38
|
Update of /cvsroot/nmock/nmock/src/NMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18881/src/NMock Modified Files: Method.cs MethodSignature.cs Mock.cs MockCall.cs SingleMethod.cs VerifyException.cs Log Message: VerifyException message overhaul, now all messages include full expected method signature; helps to locate errors in tests Index: Method.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/Method.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Method.cs 8 Aug 2003 00:05:03 -0000 1.5 --- Method.cs 24 Aug 2004 16:00:24 -0000 1.6 *************** *** 15,19 **** { this.signature = signature; ! expectations = new CallSequence(signature.methodName); } --- 15,19 ---- { this.signature = signature; ! expectations = new CallSequence(signature); } *************** *** 42,52 **** public virtual void Verify() { ! Mock.Assertion.AssertEquals(signature + " " + CallCountErrorMessage(), ! expectations.CountExpectedCalls, timesCalled); ! } ! ! private string CallCountErrorMessage() ! { ! return (timesCalled == 0 ? "never called" : "not called enough times"); } --- 42,50 ---- public virtual void Verify() { ! if (expectations.CountExpectedCalls > timesCalled) ! { ! throw VerifyException.NotEnoughCalls( ! signature, expectations.CountExpectedCalls, timesCalled); ! } } *************** *** 56,65 **** public class CallSequence { ! private string name; private ArrayList sequence = new ArrayList(); ! public CallSequence(string aName) { ! name = aName; } public MockCall this[int timesCalled] --- 54,63 ---- public class CallSequence { ! private MethodSignature signature; private ArrayList sequence = new ArrayList(); ! public CallSequence(MethodSignature signature) { ! this.signature = signature; } public MockCall this[int timesCalled] *************** *** 67,73 **** get { ! if (sequence.Count <= timesCalled) { ! throw new VerifyException(name + "() called too many times", sequence.Count, timesCalled + 1); } return (MockCall)sequence[timesCalled]; --- 65,71 ---- get { ! if (sequence.Count <= timesCalled) { ! throw VerifyException.TooManyCalls(signature, sequence.Count, timesCalled + 1); } return (MockCall)sequence[timesCalled]; Index: MethodSignature.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/MethodSignature.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MethodSignature.cs 18 Aug 2004 14:59:24 -0000 1.4 --- MethodSignature.cs 24 Aug 2004 16:00:24 -0000 1.5 *************** *** 14,18 **** public readonly Type[] argumentTypes; ! public MethodSignature(string typeName, string methodName, Type[] argumentTypes) { this.typeName = typeName; --- 14,18 ---- public readonly Type[] argumentTypes; ! public MethodSignature(string typeName, string methodName, params Type[] argumentTypes) { this.typeName = typeName; *************** *** 28,32 **** if (argumentList.Length > 0) argumentList.Append(", "); ! argumentList.Append(type.FullName); } return string.Format("{0}.{1}({2})", typeName, methodName, argumentList); --- 28,39 ---- if (argumentList.Length > 0) argumentList.Append(", "); ! if (typeof(IConstraint).IsAssignableFrom(type)) ! { ! argumentList.Append("<constraint>"); ! } ! else ! { ! argumentList.Append(type.FullName); ! } } return string.Format("{0}.{1}({2})", typeName, methodName, argumentList); Index: VerifyException.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/VerifyException.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** VerifyException.cs 15 Nov 2002 22:31:09 -0000 1.2 --- VerifyException.cs 24 Aug 2004 16:00:24 -0000 1.3 *************** *** 1,3 **** --- 1,5 ---- using System; + using System.Text; + using NMock.Constraints; namespace NMock *************** *** 7,22 **** private string reason; private object actual; - private object expected; ! private const string format = "{0}\nexpected:{1}\n but was:<{2}>"; ! ! public VerifyException(string reason, object expected, object actual) : base(reason) { ! this.reason = reason; ! this.expected = expected; this.actual = actual; } public string Reason { --- 9,60 ---- private string reason; + private string expected; private object actual; ! ! public VerifyException(MethodSignature signature, string reason) { ! this.reason = signature + " " + reason; ! } ! ! public VerifyException(MethodSignature signature, string reason, ! object expected, object actual) : this(signature, reason) ! { ! this.expected = "<" + expected + ">"; this.actual = actual; } + public VerifyException(MethodSignature signature, + IConstraint constraint, object actual, int index) + { + reason = string.Format("{0} called with incorrect parameter ({1})", signature, index + 1); + this.expected = constraint.Message; + this.actual = constraint.ExtractActualValue(actual); + } + + + public static VerifyException TooManyCalls(MethodSignature signature, + int expected, int actual) + { + if (expected >= actual) + { + throw new ArgumentException("expected >= actual"); + } + return new VerifyException( + signature, "called too many times", expected, actual); + } + + public static VerifyException NotEnoughCalls(MethodSignature signature, + int expected, int actual) + { + if (expected <= actual) + { + throw new ArgumentException("expected <= actual"); + } + string message = (actual == 0)? "never called" : "not called enough times"; + return new VerifyException(signature, message, expected, actual); + } + + public string Reason { *************** *** 24,28 **** } ! public object Expected { get { return expected; } --- 62,66 ---- } ! public object Expected { get { return expected; } *************** *** 38,42 **** get { ! return String.Format(format, reason, expected, actual); } } --- 76,87 ---- get { ! StringBuilder message = new StringBuilder(); ! message.AppendFormat("\n\t{0}", reason); ! ! if (expected != null || actual != null) ! { ! message.AppendFormat("\n\n\texpected:{0}\n\t but was:<{1}>", expected, actual); ! } ! return message.ToString(); } } Index: SingleMethod.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/SingleMethod.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SingleMethod.cs 24 Jul 2003 23:08:42 -0000 1.2 --- SingleMethod.cs 24 Aug 2004 16:00:24 -0000 1.3 *************** *** 6,21 **** public class SingleMethod : IMethod { ! private string name; private MockCall expectation; private int timesCalled = 0; ! public SingleMethod(string name) { ! this.name = name; } public string Name { ! get { return name; } } --- 6,21 ---- public class SingleMethod : IMethod { ! private MethodSignature signature; private MockCall expectation; private int timesCalled = 0; ! public SingleMethod(MethodSignature signature) { ! this.signature = signature; } public string Name { ! get { return signature.methodName; } } *************** *** 27,31 **** public virtual object Call(params object[] parameters) { ! object obj = expectation.Call(name, parameters); timesCalled++; return obj; --- 27,31 ---- public virtual object Call(params object[] parameters) { ! object obj = expectation.Call(signature.methodName, parameters); timesCalled++; return obj; *************** *** 34,38 **** public virtual void Verify() { ! Mock.Assertion.Assert(name + "() never called.", timesCalled > 1); } } --- 34,38 ---- public virtual void Verify() { ! Mock.Assertion.Assert(signature, "never called", timesCalled > 1); } } Index: MockCall.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/MockCall.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** MockCall.cs 19 Aug 2004 06:12:37 -0000 1.7 --- MockCall.cs 24 Aug 2004 16:00:24 -0000 1.8 *************** *** 67,71 **** if ( HasExpectations ) { ! Mock.Assertion.AssertEquals(methodName + "() called with incorrect number of parameters", expectedArgs.Length, actualArgs.Length); --- 67,71 ---- if ( HasExpectations ) { ! Mock.Assertion.AssertEquals(signature, "called with incorrect number of parameters", expectedArgs.Length, actualArgs.Length); *************** *** 81,87 **** if (!expected.Eval(actual)) { ! String messageFormat = "{0}() called with incorrect parameter ({1})"; ! String message = String.Format(messageFormat, methodName, index + 1); ! throw new VerifyException(message, expected.Message, expected.ExtractActualValue(actual)); } } --- 81,85 ---- if (!expected.Eval(actual)) { ! throw new VerifyException(signature, expected, actual, index); } } *************** *** 119,123 **** public override object Call(string methodName, object[] actualArgs) { ! throw new VerifyException(signature.ToString() + " called too many times", 0, 1); } } --- 117,121 ---- public override object Call(string methodName, object[] actualArgs) { ! throw VerifyException.TooManyCalls(signature, 0, 1); } } Index: Mock.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/Mock.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Mock.cs 19 Aug 2004 06:12:37 -0000 1.14 --- Mock.cs 24 Aug 2004 16:00:24 -0000 1.15 *************** *** 95,99 **** if (strict) { ! throw new VerifyException(signature.ToString() + " called too many times", 0, 1); } return null; --- 95,99 ---- if (strict) { ! throw VerifyException.TooManyCalls(signature, 0, 1); } return null; *************** *** 117,133 **** public class Assertion { ! public static void Assert(string message, bool expression) { if (!expression) { ! throw new VerifyException(message, null, null); } } ! public static void AssertEquals(string message, object expected, object actual) { if (!expected.Equals(actual)) { ! throw new VerifyException(message, expected, actual); } } --- 117,134 ---- public class Assertion { ! public static void Assert(MethodSignature signature, string message, bool expression) { if (!expression) { ! throw new VerifyException(signature, message); } } ! public static void AssertEquals(MethodSignature signature, string message, ! object expected, object actual) { if (!expected.Equals(actual)) { ! throw new VerifyException(signature, message, expected, actual); } } |
|
From: Levi K. <lkh...@us...> - 2004-08-24 16:00:37
|
Update of /cvsroot/nmock/nmock/test/NMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18881/test/NMock Modified Files: DynamicMockTest.cs MockTest.cs VerifyExceptionTest.cs Log Message: VerifyException message overhaul, now all messages include full expected method signature; helps to locate errors in tests Index: MockTest.cs =================================================================== RCS file: /cvsroot/nmock/nmock/test/NMock/MockTest.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** MockTest.cs 19 Aug 2004 06:12:37 -0000 1.13 --- MockTest.cs 24 Aug 2004 16:00:24 -0000 1.14 *************** *** 258,262 **** { Assertion.AssertEquals("mymock.x(System.String) called too many times", e.Reason); ! Assertion.AssertEquals(0, e.Expected); Assertion.AssertEquals(1, e.Actual); } --- 258,262 ---- { Assertion.AssertEquals("mymock.x(System.String) called too many times", e.Reason); ! Assertion.AssertEquals("<0>", e.Expected); Assertion.AssertEquals(1, e.Actual); } *************** *** 274,278 **** { Assertion.AssertEquals("mymock.x(System.String) called too many times", e.Reason); ! Assertion.AssertEquals(0, e.Expected); Assertion.AssertEquals(1, e.Actual); } --- 274,278 ---- { Assertion.AssertEquals("mymock.x(System.String) called too many times", e.Reason); ! Assertion.AssertEquals("<0>", e.Expected); Assertion.AssertEquals(1, e.Actual); } *************** *** 290,294 **** { Assertion.AssertEquals("mymock.x() never called", e.Reason); ! Assertion.AssertEquals(1, e.Expected); Assertion.AssertEquals(0, e.Actual); } --- 290,294 ---- { Assertion.AssertEquals("mymock.x() never called", e.Reason); ! Assertion.AssertEquals("<1>", e.Expected); Assertion.AssertEquals(0, e.Actual); } *************** *** 307,312 **** catch (VerifyException e) { ! Assertion.AssertEquals("x() called too many times", e.Reason); ! Assertion.AssertEquals(1, e.Expected); Assertion.AssertEquals(2, e.Actual); } --- 307,312 ---- catch (VerifyException e) { ! Assertion.AssertEquals("mymock.x() called too many times", e.Reason); ! Assertion.AssertEquals("<1>", e.Expected); Assertion.AssertEquals(2, e.Actual); } *************** *** 325,329 **** { AssertEquals("mymock.x() never called", e.Reason); ! AssertEquals(2, e.Expected); AssertEquals(0, e.Actual); } --- 325,329 ---- { AssertEquals("mymock.x() never called", e.Reason); ! AssertEquals("<2>", e.Expected); AssertEquals(0, e.Actual); } *************** *** 343,347 **** { Assertion.AssertEquals("mymock.x() not called enough times", e.Reason); ! Assertion.AssertEquals(2, e.Expected); Assertion.AssertEquals(1, e.Actual); } --- 343,347 ---- { Assertion.AssertEquals("mymock.x() not called enough times", e.Reason); ! Assertion.AssertEquals("<2>", e.Expected); Assertion.AssertEquals(1, e.Actual); } *************** *** 362,367 **** catch (VerifyException e) { ! Assertion.AssertEquals("x() called too many times", e.Reason); ! Assertion.AssertEquals(2, e.Expected); Assertion.AssertEquals(3, e.Actual); } --- 362,367 ---- catch (VerifyException e) { ! Assertion.AssertEquals("mymock.x() called too many times", e.Reason); ! Assertion.AssertEquals("<2>", e.Expected); Assertion.AssertEquals(3, e.Actual); } *************** *** 382,386 **** catch (VerifyException e) { ! Assertion.AssertEquals(3, e.Expected); Assertion.AssertEquals(2, e.Actual); Assertion.AssertEquals("mymock.x() not called enough times", e.Reason); --- 382,386 ---- catch (VerifyException e) { ! Assertion.AssertEquals("<3>", e.Expected); Assertion.AssertEquals(2, e.Actual); Assertion.AssertEquals("mymock.x() not called enough times", e.Reason); *************** *** 398,403 **** catch (VerifyException e) { ! Assertion.AssertEquals("x() called with incorrect number of parameters", e.Reason); ! Assertion.AssertEquals(3, e.Expected); Assertion.AssertEquals(2, e.Actual); } --- 398,404 ---- catch (VerifyException e) { ! Assertion.AssertEquals("mymock.x(System.Int32, System.Int32, System.Int32)" + ! " called with incorrect number of parameters", e.Reason); ! Assertion.AssertEquals("<3>", e.Expected); Assertion.AssertEquals(2, e.Actual); } *************** *** 420,424 **** catch (VerifyException e) { ! Assertion.AssertEquals("x() called with incorrect parameter (2)", e.Reason); Assertion.AssertEquals("wee woo", e.Expected); Assertion.AssertEquals("actual value", e.Actual); --- 421,426 ---- catch (VerifyException e) { ! Assertion.AssertEquals("mymock.x(<constraint>, <constraint>)" + ! " called with incorrect parameter (2)", e.Reason); Assertion.AssertEquals("wee woo", e.Expected); Assertion.AssertEquals("actual value", e.Actual); Index: VerifyExceptionTest.cs =================================================================== RCS file: /cvsroot/nmock/nmock/test/NMock/VerifyExceptionTest.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** VerifyExceptionTest.cs 15 Nov 2002 22:48:20 -0000 1.1 --- VerifyExceptionTest.cs 24 Aug 2004 16:00:25 -0000 1.2 *************** *** 1,4 **** --- 1,5 ---- using System; using NUnit.Framework; + using NMock.Constraints; namespace NMock *************** *** 8,22 **** public class VerifyExceptionTest { ! [Test] ! public void Message() { ! VerifyException e = new VerifyException("Boo", "<Wee>", 44); ! Assertion.AssertEquals("Boo\nexpected:<Wee>\n but was:<44>", e.Message); ! Assertion.AssertEquals("Boo", e.Reason); ! Assertion.AssertEquals("<Wee>", e.Expected); ! Assertion.AssertEquals(44, e.Actual); } } --- 9,105 ---- public class VerifyExceptionTest { ! private readonly MethodSignature signature = new MethodSignature("Foo", "Bar"); ! [Test] ! public void SimpleMessage() { ! VerifyException e = new VerifyException(signature, "Boo"); ! Assertion.AssertEquals("\n\tFoo.Bar() Boo", e.Message); ! Assertion.AssertEquals("Foo.Bar() Boo", e.Reason); ! Assertion.AssertEquals(null, e.Expected); ! Assertion.AssertEquals(null, e.Actual); } + [Test] + public void MessageWithExpectedActual() + { + VerifyException e = new VerifyException(signature, "Boo", "Wee", 44); + Assertion.AssertEquals("\n\tFoo.Bar() Boo\n\n\texpected:<Wee>\n\t but was:<44>", e.Message); + Assertion.AssertEquals("Foo.Bar() Boo", e.Reason); + Assertion.AssertEquals("<Wee>", e.Expected); + Assertion.AssertEquals(44, e.Actual); + } + + [Test] + public void MessageFromContraint() + { + IMock constraint = new DynamicMock(typeof(IConstraint)); + constraint.SetupResult("Message", "<wee woo>"); + constraint.SetupResult("Eval", false, typeof(object)); + + constraint.ExpectAndReturn("ExtractActualValue", "actual value", "world"); + + VerifyException e = new VerifyException(signature, + (IConstraint)constraint.MockInstance, "world", 0); + + Assertion.AssertEquals( + "\n\tFoo.Bar() called with incorrect parameter (1)\n\n" + + "\texpected:<wee woo>\n\t but was:<actual value>", e.Message); + + Assertion.AssertEquals("Foo.Bar() called with incorrect parameter (1)", e.Reason); + Assertion.AssertEquals("<wee woo>", e.Expected); + Assertion.AssertEquals("actual value", e.Actual); + } + + [Test] + public void TooManyCalls() + { + VerifyException e = VerifyException.TooManyCalls(signature, 1, 2); + Assertion.AssertEquals("Foo.Bar() called too many times", e.Reason); + Assertion.AssertEquals("<1>", e.Expected); + Assertion.AssertEquals(2, e.Actual); + } + + [Test, ExpectedException(typeof(ArgumentException))] + public void TooManyCalls_EqualArguments() + { + VerifyException.TooManyCalls(signature, 1, 1); + } + + [Test, ExpectedException(typeof(ArgumentException))] + public void TooManyCalls_WrongArguments() + { + VerifyException.TooManyCalls(signature, 2, 1); + } + + [Test] + public void NotEnoughCalls() + { + VerifyException e = VerifyException.NotEnoughCalls(signature, 2, 1); + Assertion.AssertEquals("Foo.Bar() not called enough times", e.Reason); + Assertion.AssertEquals("<2>", e.Expected); + Assertion.AssertEquals(1, e.Actual); + } + + [Test] + public void NotEnoughCalls_Never() + { + VerifyException e = VerifyException.NotEnoughCalls(signature, 1, 0); + Assertion.AssertEquals("Foo.Bar() never called", e.Reason); + Assertion.AssertEquals("<1>", e.Expected); + Assertion.AssertEquals(0, e.Actual); + } + + [Test, ExpectedException(typeof(ArgumentException))] + public void NotEnoughCalls_EqualArguments() + { + VerifyException.NotEnoughCalls(signature, 1, 1); + } + + [Test, ExpectedException(typeof(ArgumentException))] + public void NotEnoughCalls_WrongArguments() + { + VerifyException.NotEnoughCalls(signature, 1, 2); + } } Index: DynamicMockTest.cs =================================================================== RCS file: /cvsroot/nmock/nmock/test/NMock/DynamicMockTest.cs,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** DynamicMockTest.cs 15 Jun 2004 17:32:53 -0000 1.22 --- DynamicMockTest.cs 24 Aug 2004 16:00:24 -0000 1.23 *************** *** 221,225 **** } ! [Test] public void CanSetupResultForMembersInheritedFromBaseInterfaces() { IMock mock = new DynamicMock(typeof(IBlah)); --- 221,225 ---- } ! [Test] public void CanSetupResultForMembersInheritedFromBaseInterfaces() { IMock mock = new DynamicMock(typeof(IBlah)); |
|
From: Levi K. <lkh...@us...> - 2004-08-19 06:12:48
|
Update of /cvsroot/nmock/nmock/test/NMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30546/test/NMock Modified Files: MockTest.cs Log Message: Unexpected call exception messages made consistent Index: MockTest.cs =================================================================== RCS file: /cvsroot/nmock/nmock/test/NMock/MockTest.cs,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** MockTest.cs 29 Nov 2003 17:19:13 -0000 1.12 --- MockTest.cs 19 Aug 2004 06:12:37 -0000 1.13 *************** *** 251,261 **** try { ! mock.ExpectNoCall("x"); ! mock.Invoke("x"); Fail("Expected VerifyException"); } catch (VerifyException e) { ! Assertion.AssertEquals("mymock.x() called", e.Reason); Assertion.AssertEquals(0, e.Expected); Assertion.AssertEquals(1, e.Actual); --- 251,277 ---- try { ! mock.ExpectNoCall("x", typeof(string)); ! mock.Invoke("x", "foo"); Fail("Expected VerifyException"); } catch (VerifyException e) { ! Assertion.AssertEquals("mymock.x(System.String) called too many times", e.Reason); ! Assertion.AssertEquals(0, e.Expected); ! Assertion.AssertEquals(1, e.Actual); ! } ! } ! ! [Test] public void StrictVerifyExceptionMessage() ! { ! try ! { ! mock.Strict = true; ! mock.Invoke("x", "foo"); ! Fail("Expected VerifyException"); ! } ! catch (VerifyException e) ! { ! Assertion.AssertEquals("mymock.x(System.String) called too many times", e.Reason); Assertion.AssertEquals(0, e.Expected); Assertion.AssertEquals(1, e.Actual); |
|
From: Levi K. <lkh...@us...> - 2004-08-19 06:12:48
|
Update of /cvsroot/nmock/nmock/src/NMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30546/src/NMock Modified Files: Mock.cs MockCall.cs Log Message: Unexpected call exception messages made consistent Index: MockCall.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/MockCall.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** MockCall.cs 29 Nov 2003 17:19:13 -0000 1.6 --- MockCall.cs 19 Aug 2004 06:12:37 -0000 1.7 *************** *** 119,123 **** public override object Call(string methodName, object[] actualArgs) { ! throw new VerifyException(signature.ToString() + " called", 0, 1); } } --- 119,123 ---- public override object Call(string methodName, object[] actualArgs) { ! throw new VerifyException(signature.ToString() + " called too many times", 0, 1); } } Index: Mock.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/Mock.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Mock.cs 29 Nov 2003 17:04:46 -0000 1.13 --- Mock.cs 19 Aug 2004 06:12:37 -0000 1.14 *************** *** 95,99 **** if (strict) { ! throw new VerifyException(methodName + "() called too many times", 0, 1); } return null; --- 95,99 ---- if (strict) { ! throw new VerifyException(signature.ToString() + " called too many times", 0, 1); } return null; |
|
From: Levi K. <lkh...@us...> - 2004-08-18 14:59:33
|
Update of /cvsroot/nmock/nmock/src/NMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29194/src/NMock Modified Files: DynamicMock.cs MethodSignature.cs Log Message: whitespace/formatting Index: MethodSignature.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/MethodSignature.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** MethodSignature.cs 8 Apr 2004 03:47:39 -0000 1.3 --- MethodSignature.cs 18 Aug 2004 14:59:24 -0000 1.4 *************** *** 113,116 **** return true; } ! } } --- 113,116 ---- return true; } ! } } Index: DynamicMock.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/DynamicMock.cs,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** DynamicMock.cs 8 Apr 2004 03:47:38 -0000 1.21 --- DynamicMock.cs 18 Aug 2004 14:59:24 -0000 1.22 *************** *** 72,76 **** Type realReturnType = GetReturnTypeForSignature(signature); ! if(! realReturnType.IsAssignableFrom(returnVal.GetType())) { throw new ArgumentException( --- 72,76 ---- Type realReturnType = GetReturnTypeForSignature(signature); ! if (!realReturnType.IsAssignableFrom(returnVal.GetType())) { throw new ArgumentException( |
|
From: Steve M. <Ste...@mp...> - 2004-08-12 13:25:34
|
Thanks for the quick response.
-----Original Message-----
From: Jim Arnold [mailto:JA...@th...]
Sent: Thursday, August 12, 2004 4:28 AM
To: Steve Mitcham
Cc: nmo...@li...; =
nmo...@li...
Subject: Re: [Nmock-general] ExecutionEngine exception
Yes, this is a bug (well, a limitation). I'll try and fix it today if I =
get a minute.=20
Jim=20
ThoughtWorks=20
"Steve Mitcham" <Ste...@mp...>=20
Sent by: nmo...@li...=20
12/08/2004 03:35=20
To
<nmo...@li...>=20
cc
Subject
[Nmock-general] ExecutionEngine exception
=09
I am getting an ExecutionEngine exception when attempting to execute a =
method off a mock instance with a ref parameter.
The simplest case I can show is:
public interface IFoo
{
void DoSomething(ref string s);
}
[Test]
public void TestSomething()
{
DynamicMock mock =3D new DynamicMock(typeof(IFoo));
IFoo foo =3D (IFoo)mock.MockInstance;
string testString =3D "";
foo.DoSomething(ref testString);
}
Now, am I doing something wrong, or is this simply not supported? I've =
looked at the code, and frankly I'm just not well versed enough with the =
IL code to even know where to start.
When stepping through the code in the debugger, it seems that the =
generator is not being called, yet the mockInstance is still being set =
to a System.Object instance somehow.
-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
_______________________________________________
Nmock-general mailing list
Nmo...@li...
https://lists.sourceforge.net/lists/listinfo/nmock-general
|
|
From: Jim A. <JA...@th...> - 2004-08-12 09:27:27
|
Yes, this is a bug (well, a limitation). I'll try and fix it today if I
get a minute.
Jim
ThoughtWorks
"Steve Mitcham" <Ste...@mp...>
Sent by: nmo...@li...
12/08/2004 03:35
To
<nmo...@li...>
cc
Subject
[Nmock-general] ExecutionEngine exception
I am getting an ExecutionEngine exception when attempting to execute a
method off a mock instance with a ref parameter.
The simplest case I can show is:
public interface IFoo
{
void DoSomething(ref string s);
}
[Test]
public void TestSomething()
{
DynamicMock mock = new DynamicMock(typeof(IFoo));
IFoo foo = (IFoo)mock.MockInstance;
string testString = "";
foo.DoSomething(ref testString);
}
Now, am I doing something wrong, or is this simply not supported? I've
looked at the code, and frankly I'm just not well versed enough with the
IL code to even know where to start.
When stepping through the code in the debugger, it seems that the
generator is not being called, yet the mockInstance is still being set to
a System.Object instance somehow.
-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
_______________________________________________
Nmock-general mailing list
Nmo...@li...
https://lists.sourceforge.net/lists/listinfo/nmock-general
|
|
From: Steve M. <Ste...@mp...> - 2004-08-12 02:39:08
|
I am getting an ExecutionEngine exception when attempting to execute a =
method off a mock instance with a ref parameter.
The simplest case I can show is:
public interface IFoo
{
void DoSomething(ref string s);
}
[Test]
public void TestSomething()
{
DynamicMock mock =3D new DynamicMock(typeof(IFoo));
IFoo foo =3D (IFoo)mock.MockInstance;
string testString =3D "";
foo.DoSomething(ref testString);
}
Now, am I doing something wrong, or is this simply not supported? I've =
looked at the code, and frankly I'm just not well versed enough with the =
IL code to even know where to start.
When stepping through the code in the debugger, it seems that the =
generator is not being called, yet the mockInstance is still being set =
to a System.Object instance somehow.
|
|
From: Mei X. <mx...@ya...> - 2004-08-07 01:00:06
|
Jim, thanks for your reply. But the same code works in
.Net 1.1. Any idea?
--- Jim Arnold <JA...@th...> wrote:
> Without trying to pass the buck, that looks like a
> problem with csUnit
> rather than NMock. It's trying to get the CodeBase
> property of the
> dynamic assembly created by NMock, which is not
> allowed. Can you file a
> bug report with the csUnit developers and ask them
> to catch
> NotSupportedException in their OnAssemblyLoaded
> handler?
>
> (By the way, that should fail in .Net 1.1 as well).
>
>
> Jim
>
>
>
>
> Mei Xiu <mx...@ya...>
> Sent by: nmo...@li...
> 05/08/2004 22:00
>
> To
> nmo...@li...
> cc
>
> Subject
> [Nmock-general] (no subject)
>
>
>
>
>
>
> Hi there,
>
> I would like to use NMock with .net framework v2.0.
> but having problem as showing in the callstack
> below.
>
> Has anyone successfully used NMock on .net v2.0? any
> suggestion is appreciated. Thanks!
>
> Summary
> Tests run: 1
> Errors: 1
> **************************************
> **************************************
> Detailed errors
>
> Test Name: test1.HelloTest.testExpect
> Error Reason: System.NotSupportedException: The
> invoked member is not supported in a dynamic module.
>
> at
>
System.Reflection.Emit.AssemblyBuilder.get_CodeBase()
>
> at
> csUnit.Core.RemoteLoader.OnAssemblyLoaded(Object
> sender, AssemblyLoadEventArgs args)
> at System.AppDomain.OnAssemblyLoadEvent(Assembly
> LoadedAssembly)
> at
> System.AppDomain.nCreateDynamicAssembly(AssemblyName
> name, Evidence identity, StackCrawlMark& stackMark,
> PermissionSet requiredPermissions, PermissionSet
> optionalPermissions, PermissionSet
> refusedPermissions,
> AssemblyBuilderAccess access)
>
> at
>
System.AppDomain.InternalDefineDynamicAssembly(AssemblyName
> name, AssemblyBuilderAccess access, String dir,
> Evidence evidence, PermissionSet
> requiredPermissions,
> PermissionSet optionalPermissions, PermissionSet
> refusedPermissions, StackCrawlMark& stackMark)
>
> at
> System.AppDomain.DefineDynamicAssembly(AssemblyName
> name, AssemblyBuilderAccess access)
> at
> NMock.Dynamic.ClassGenerator.CreateTypeBuilder()
> in
>
d:\nexus\nmock\nmocksource\1.01\nmock\nmock\dynamic\classgenerator.cs:line
> 54
>
> at NMock.Dynamic.ClassGenerator.Generate() in
>
d:\nexus\nmock\nmocksource\1.01\nmock\nmock\dynamic\classgenerator.cs:line
> 41
>
> at NMock.DynamicMock.get_MockInstance() in
>
d:\nexus\nmock\nmocksource\1.01\nmock\nmock\dynamicmock.cs:line
> 34
> at test1.HelloTest.testExpect() in
>
d:\nexus\nmock\testproject\test1\test1\test1\program.cs:line
> 88
> -----------------------
> Failures: 0
> **************************************
>
> Here is my source file:
>
> using System;
> using System.Collections.Generic;
> using System.Collections;
> using NMock;
> using System.Text;
> using com.siebel.nexus.test;
>
> namespace test1
> {
> public class HelloTest : NexusTestCase
> //NexusTestCase is extended from csUnit
> {
> public HelloTest(String name) : base (name)
> {
> }
> public void testExpect()
> {
> // mock the dependency
> IMock person = new
> DynamicMock(typeof(IPerson));
> // setting up values
> person.ExpectAndReturn("Name", "John Doe");
> Hello hello = new
> Hello((IPerson)person.MockInstance);
> assertEquals("Hello John Doe",
> hello.Greet());
>
> // Verify that Name property is only
> accessed
> once
> person.Verify();
> }
> }
> public interface Iperson
> {
> string Name { get; }
> }
>
> public class Hello
> {
> IPerson person;
> public Hello(IPerson person)
> {
> this.person = person;
> }
>
> public String Greet()
> {
> return "Hello " + person.Name;
> }
> }
> }
>
>
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail is new and improved - Check it out!
> http://promotions.yahoo.com/new_mail
>
>
>
-------------------------------------------------------
> This SF.Net email is sponsored by OSTG. Have you
> noticed the changes on
> Linux.com, ITManagersJournal and NewsForge in the
> past few weeks? Now,
> one more big change to announce. We are now OSTG-
> Open Source Technology
> Group. Come see the changes on the new OSTG site.
> www.ostg.com
> _______________________________________________
> Nmock-general mailing list
> Nmo...@li...
>
https://lists.sourceforge.net/lists/listinfo/nmock-general
>
>
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail
|
|
From: Jim A. <JA...@th...> - 2004-08-06 14:11:12
|
Without trying to pass the buck, that looks like a problem with csUnit
rather than NMock. It's trying to get the CodeBase property of the
dynamic assembly created by NMock, which is not allowed. Can you file a
bug report with the csUnit developers and ask them to catch
NotSupportedException in their OnAssemblyLoaded handler?
(By the way, that should fail in .Net 1.1 as well).
Jim
Mei Xiu <mx...@ya...>
Sent by: nmo...@li...
05/08/2004 22:00
To
nmo...@li...
cc
Subject
[Nmock-general] (no subject)
Hi there,
I would like to use NMock with .net framework v2.0.
but having problem as showing in the callstack below.
Has anyone successfully used NMock on .net v2.0? any
suggestion is appreciated. Thanks!
Summary
Tests run: 1
Errors: 1
**************************************
**************************************
Detailed errors
Test Name: test1.HelloTest.testExpect
Error Reason: System.NotSupportedException: The
invoked member is not supported in a dynamic module.
at
System.Reflection.Emit.AssemblyBuilder.get_CodeBase()
at csUnit.Core.RemoteLoader.OnAssemblyLoaded(Object
sender, AssemblyLoadEventArgs args)
at System.AppDomain.OnAssemblyLoadEvent(Assembly
LoadedAssembly)
at
System.AppDomain.nCreateDynamicAssembly(AssemblyName
name, Evidence identity, StackCrawlMark& stackMark,
PermissionSet requiredPermissions, PermissionSet
optionalPermissions, PermissionSet refusedPermissions,
AssemblyBuilderAccess access)
at
System.AppDomain.InternalDefineDynamicAssembly(AssemblyName
name, AssemblyBuilderAccess access, String dir,
Evidence evidence, PermissionSet requiredPermissions,
PermissionSet optionalPermissions, PermissionSet
refusedPermissions, StackCrawlMark& stackMark)
at
System.AppDomain.DefineDynamicAssembly(AssemblyName
name, AssemblyBuilderAccess access)
at NMock.Dynamic.ClassGenerator.CreateTypeBuilder()
in
d:\nexus\nmock\nmocksource\1.01\nmock\nmock\dynamic\classgenerator.cs:line
54
at NMock.Dynamic.ClassGenerator.Generate() in
d:\nexus\nmock\nmocksource\1.01\nmock\nmock\dynamic\classgenerator.cs:line
41
at NMock.DynamicMock.get_MockInstance() in
d:\nexus\nmock\nmocksource\1.01\nmock\nmock\dynamicmock.cs:line
34
at test1.HelloTest.testExpect() in
d:\nexus\nmock\testproject\test1\test1\test1\program.cs:line
88
-----------------------
Failures: 0
**************************************
Here is my source file:
using System;
using System.Collections.Generic;
using System.Collections;
using NMock;
using System.Text;
using com.siebel.nexus.test;
namespace test1
{
public class HelloTest : NexusTestCase
//NexusTestCase is extended from csUnit
{
public HelloTest(String name) : base (name)
{
}
public void testExpect()
{
// mock the dependency
IMock person = new
DynamicMock(typeof(IPerson));
// setting up values
person.ExpectAndReturn("Name", "John Doe");
Hello hello = new
Hello((IPerson)person.MockInstance);
assertEquals("Hello John Doe", hello.Greet());
// Verify that Name property is only accessed
once
person.Verify();
}
}
public interface Iperson
{
string Name { get; }
}
public class Hello
{
IPerson person;
public Hello(IPerson person)
{
this.person = person;
}
public String Greet()
{
return "Hello " + person.Name;
}
}
}
__________________________________
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
http://promotions.yahoo.com/new_mail
-------------------------------------------------------
This SF.Net email is sponsored by OSTG. Have you noticed the changes on
Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
one more big change to announce. We are now OSTG- Open Source Technology
Group. Come see the changes on the new OSTG site. www.ostg.com
_______________________________________________
Nmock-general mailing list
Nmo...@li...
https://lists.sourceforge.net/lists/listinfo/nmock-general
|
|
From: Mei X. <mx...@ya...> - 2004-08-05 21:01:05
|
Hi there,
I would like to use NMock with .net framework v2.0.
but having problem as showing in the callstack below.
Has anyone successfully used NMock on .net v2.0? any
suggestion is appreciated. Thanks!
Summary
Tests run: 1
Errors: 1
**************************************
**************************************
Detailed errors
Test Name: test1.HelloTest.testExpect
Error Reason: System.NotSupportedException: The
invoked member is not supported in a dynamic module.
at
System.Reflection.Emit.AssemblyBuilder.get_CodeBase()
at csUnit.Core.RemoteLoader.OnAssemblyLoaded(Object
sender, AssemblyLoadEventArgs args)
at System.AppDomain.OnAssemblyLoadEvent(Assembly
LoadedAssembly)
at
System.AppDomain.nCreateDynamicAssembly(AssemblyName
name, Evidence identity, StackCrawlMark& stackMark,
PermissionSet requiredPermissions, PermissionSet
optionalPermissions, PermissionSet refusedPermissions,
AssemblyBuilderAccess access)
at
System.AppDomain.InternalDefineDynamicAssembly(AssemblyName
name, AssemblyBuilderAccess access, String dir,
Evidence evidence, PermissionSet requiredPermissions,
PermissionSet optionalPermissions, PermissionSet
refusedPermissions, StackCrawlMark& stackMark)
at
System.AppDomain.DefineDynamicAssembly(AssemblyName
name, AssemblyBuilderAccess access)
at NMock.Dynamic.ClassGenerator.CreateTypeBuilder()
in
d:\nexus\nmock\nmocksource\1.01\nmock\nmock\dynamic\classgenerator.cs:line
54
at NMock.Dynamic.ClassGenerator.Generate() in
d:\nexus\nmock\nmocksource\1.01\nmock\nmock\dynamic\classgenerator.cs:line
41
at NMock.DynamicMock.get_MockInstance() in
d:\nexus\nmock\nmocksource\1.01\nmock\nmock\dynamicmock.cs:line
34
at test1.HelloTest.testExpect() in
d:\nexus\nmock\testproject\test1\test1\test1\program.cs:line
88
-----------------------
Failures: 0
**************************************
Here is my source file:
using System;
using System.Collections.Generic;
using System.Collections;
using NMock;
using System.Text;
using com.siebel.nexus.test;
namespace test1
{
public class HelloTest : NexusTestCase
//NexusTestCase is extended from csUnit
{
public HelloTest(String name) : base (name)
{
}
public void testExpect()
{
// mock the dependency
IMock person = new
DynamicMock(typeof(IPerson));
// setting up values
person.ExpectAndReturn("Name", "John Doe");
Hello hello = new
Hello((IPerson)person.MockInstance);
assertEquals("Hello John Doe", hello.Greet());
// Verify that Name property is only accessed
once
person.Verify();
}
}
public interface Iperson
{
string Name { get; }
}
public class Hello
{
IPerson person;
public Hello(IPerson person)
{
this.person = person;
}
public String Greet()
{
return "Hello " + person.Name;
}
}
}
__________________________________
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
http://promotions.yahoo.com/new_mail
|
|
From: Steve F. <st...@m3...> - 2004-07-28 19:43:11
|
Ouch. Well one option might be to create another interface that extends
both and mock that. I can't try it on my current setup so you'll have to
experiment. You /sure/ you can't change the type structure?
S.
Nick Robinson wrote:
> I am mocking an interface, and inside the client class I need to do a query
> for a different type:
>
> Client(ISomeInterface someInterface)
> {
> INewInterface interface = someInterface as IAnotherInterface;
> if(interface != null)
> {
> ...
> }
> }
>
> someInterface is a mock. The only way I know how to work with this is to
> stub the interface rather than mock it - I cannot move away from the
> downcast. Is it possible to do this on a mock? I get the feeling I would
> need to do something like:
>
> DynamicMock someInterfaceMock = new DynamicMock(typeof(ISomeInterface));
> someInterfaceMock.Supports(typeof(IAnotherInterface));
|
|
From: Nick R. <nic...@fr...> - 2004-07-28 19:20:51
|
Hi,
I am mocking an interface, and inside the client class I need to do a query
for a different type:
Client(ISomeInterface someInterface)
{
INewInterface interface = someInterface as IAnotherInterface;
if(interface != null)
{
...
}
}
someInterface is a mock. The only way I know how to work with this is to
stub the interface rather than mock it - I cannot move away from the
downcast. Is it possible to do this on a mock? I get the feeling I would
need to do something like:
DynamicMock someInterfaceMock = new DynamicMock(typeof(ISomeInterface));
someInterfaceMock.Supports(typeof(IAnotherInterface));
Or something like that....
nick.robinson
site : www.fromconcept.co.uk
blog : www.fromconcept.co.uk/weblog.aspx
draco : www.sourceforge.net/projects/draconet
|