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: Jim A. <JA...@th...> - 2004-01-19 17:43:59
|
Yes, currently NMock allows you to mock classes with empty constructors. You get back a subclass with a real class as its base. What I'm proposing is to remove the limitation on empty constructors by either *not* calling any constructor on the base, or by allowing the user to pass parameters into GetMockInstance() which would be used to construct the base with. Jim |---------+-----------------------------------------> | | "Mike Bresnahan" | | | <mbr...@vi...> | | | Sent by: | | | nmo...@li...| | | ceforge.net | | | | | | | | | 19/01/2004 16:33 | | | | |---------+-----------------------------------------> >------------------------------------------------------------------------------------------------------------------------------| | | | To: <JA...@th...> | | cc: <nmo...@li...> | | Subject: RE: [Nmock-general] Mocking types with constructors | >------------------------------------------------------------------------------------------------------------------------------| I'm still confused. Does the current Nmock allow classes to be mocked? Wouldn't a mock of a class have a mock as a base as well? Are you saying that the mocked class would have the real class as its base? Mike P.S. A cc'ed list under the assumption that you forgot to. > -----Original Message----- > From: Jim Arnold [mailto:JA...@th...] > Sent: Monday, January 19, 2004 4:11 AM > To: mbr...@vi... > Subject: RE: [Nmock-general] Mocking types with constructors > > > > > > > The point is that sometimes the class you're mocking has > non-virtual methods which the class under test needs to call > (or perhaps you've used Ignore on some methods), and if you > don't have a fully constructed base those methods can fail. > It may not be a big deal, but I've run into it before and > thought it was worth discussing. > > Jim ------------------------------------------------------- The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. http://www.eclipsecon.org/osdn _______________________________________________ Nmock-general mailing list Nmo...@li... https://lists.sourceforge.net/lists/listinfo/nmock-general |
|
From: Mike B. <mbr...@vi...> - 2004-01-19 16:34:07
|
I'm still confused. Does the current Nmock allow classes to be mocked? Wouldn't a mock of a class have a mock as a base as well? Are you saying that the mocked class would have the real class as its base? Mike P.S. A cc'ed list under the assumption that you forgot to. > -----Original Message----- > From: Jim Arnold [mailto:JA...@th...] > Sent: Monday, January 19, 2004 4:11 AM > To: mbr...@vi... > Subject: RE: [Nmock-general] Mocking types with constructors > > > > > > > The point is that sometimes the class you're mocking has > non-virtual methods which the class under test needs to call > (or perhaps you've used Ignore on some methods), and if you > don't have a fully constructed base those methods can fail. > It may not be a big deal, but I've run into it before and > thought it was worth discussing. > > Jim |
|
From: Mike B. <mbr...@vi...> - 2004-01-18 22:41:40
|
I wasn't aware that DynamicMock could be used on any classes. I thought it
only worked on interfaces. Being able to create dynamic mocks of classes
would be super cool. Its annoying to have to create separate interface for
every single class in the application, especially when working with existing
code that did not use mock objects. I don't see the need for calling
constructors though. I would think that a dynamic mock object created from
a class would only have the public methods and properties just as if the
class were an interface. What would a constructor do for us?
Mike Bresnahan
-----Original Message-----
From: nmo...@li...
[mailto:nmo...@li...]On Behalf Of Jim Arnold
Sent: Sunday, January 18, 2004 3:47 PM
To: nmo...@li...
Subject: [Nmock-general] Mocking types with constructors
You're probably all aware of NMock's inability to mock types without default
(empty) constructors. It's been bothering me for a while, given that this
trendy Inversion Of Control lark is driving us to create classes with fatter
constructors, so I decided to do something about it. I am aware that one of
the more important goals of mocking is to drive an interface/implementation
seperated design and that, arguably, expanding the range of classes that we
can mock subverts that goal. However, I don't think many of us would argue
that *every* concrete type should be matched by an interface just for the
sake of it, and we all work with pre-defined classes that are not always
described by interfaces. Furthermore, creating an interface purely to mock
a class is Evil. It is a code smell (a tool smell, really, if you'll pardon
the expression).
The code to allow NMock to support constructors turns out to be trivial, but
it does force the user to choose whether they want to pass parameters
through to the base class or not (yes, even though C# forces you to call a
base constructor, the CLR does not, so you would end up with a
non-initialised base). An example might describe it better. Given the
following class:
public class ClassWithFatConstructor
{
public int Foo;
public string Bar;
public ClassWithFatConstructor(int foo, string bar)
{
Foo = foo;
Bar = bar;
}
}
the following code would create a mock instance without calling the base
constructor:
IMock mock = new DynamicMock(typeof(ClassWithFatConstructor));
ClassWithFatConstructor instance =
(ClassWithFatConstructor)mock.GetInstance(false); //false indicates we don't
want to initialise the base class
We end up with a subclass of ClassWithFatConstructor, with all public
virtual methods mocked as usual, but with all fields in the base class
remaining in an uninitialised, or default state. This means that Foo == 0
and Bar == null, and that calls to unmocked methods which rely on that state
can potentially fail. The next snippet creates a mock instance and ensures
that it calls through to the base:
IMock mock = new DynamicMock(typeof(ClassWithFatConstructor));
ClassWithFatConstructor instance =
(ClassWithFatConstructor)mock.GetInstance(true, 123, "abc");
We now get a properly initialised base. There is one thing that still
bother me about the API though. There's no point passing parameters in if
we *don't* want to call the base constructor - we can just create a default
constructor on the mock and call that instead. So I'd appreciate some
feedback on how this would look.
Anyway, if you got this far, you probably have an opinion on whether this
should be in NMock or not, so let me know what you think and I'll either
post the code or shut up.
Cheers,
Jim
|
|
From: Jim A. <JA...@th...> - 2004-01-18 21:47:05
|
You're probably all aware of NMock's inability to mock types without
default (empty) constructors. It's been bothering me for a while, given
that this trendy Inversion Of Control lark is driving us to create classes
with fatter constructors, so I decided to do something about it. I am
aware that one of the more important goals of mocking is to drive an
interface/implementation seperated design and that, arguably, expanding
the range of classes that we can mock subverts that goal. However, I
don't think many of us would argue that *every* concrete type should be
matched by an interface just for the sake of it, and we all work with
pre-defined classes that are not always described by interfaces.
Furthermore, creating an interface purely to mock a class is Evil. It is
a code smell (a tool smell, really, if you'll pardon the expression).
The code to allow NMock to support constructors turns out to be trivial,
but it does force the user to choose whether they want to pass parameters
through to the base class or not (yes, even though C# forces you to call a
base constructor, the CLR does not, so you would end up with a
non-initialised base). An example might describe it better. Given the
following class:
public class ClassWithFatConstructor
{
public int Foo;
public string Bar;
public ClassWithFatConstructor(int foo, string bar)
{
Foo = foo;
Bar = bar;
}
}
the following code would create a mock instance without calling the base
constructor:
IMock mock = new DynamicMock(typeof(ClassWithFatConstructor));
ClassWithFatConstructor instance =
(ClassWithFatConstructor)mock.GetInstance(false); //false indicates we
don't want to initialise the base class
We end up with a subclass of ClassWithFatConstructor, with all public
virtual methods mocked as usual, but with all fields in the base class
remaining in an uninitialised, or default state. This means that Foo == 0
and Bar == null, and that calls to unmocked methods which rely on that
state can potentially fail. The next snippet creates a mock instance and
ensures that it calls through to the base:
IMock mock = new DynamicMock(typeof(ClassWithFatConstructor));
ClassWithFatConstructor instance =
(ClassWithFatConstructor)mock.GetInstance(true, 123, "abc");
We now get a properly initialised base. There is one thing that still
bother me about the API though. There's no point passing parameters in if
we *don't* want to call the base constructor - we can just create a
default constructor on the mock and call that instead. So I'd appreciate
some feedback on how this would look.
Anyway, if you got this far, you probably have an opinion on whether this
should be in NMock or not, so let me know what you think and I'll either
post the code or shut up.
Cheers,
Jim |
|
From: Mike R. <mik...@th...> - 2004-01-18 17:37:00
|
NMock's linked from an article on the new .NET version of The Server Side. http://www.theserverside.net/articles/article.aspx?l=UnitTesting (near the bottom) The article's a pretty thorough intro to using NUnit to boot. Mike -- Mike Roberts http://mikeroberts.thoughtworks.net/ |
|
From: Mike R. <mik...@th...> - 2004-01-18 13:57:06
|
Hi, The nmock build is currently broken on CCNetLive. I think this is because NAnt 0.8.4 doesn't seem to be happy on machines that just have .NET 1.1 installed (we've seen the same kind of problem on the CCNet project.) If anyone checks in a build update to fix this then this will require a manual CVS update on CCNetLive - just let me know and I'll do it. -- part of error message from http://ccnetlive.thoughtworks.com/nmock/log/log20040118075846.xml -- compile: init: compile.core: [csc] Compiling 21 files to d:\sourceforge\nmock\build\nmock.dll. BUILD FAILED d:\sourceforge\nmock\nmock.build(15,4): [csc] C:\WINNT\Microsoft.NET\Framework\v1.0.3705\csc.exe failed to start. The system cannot find the file specified Total time: 0.4 seconds. -- Mike -- Mike Roberts http://mikeroberts.thoughtworks.net/ |
|
From: <mik...@us...> - 2004-01-18 13:52:02
|
Update of /cvsroot/nmock/nmock In directory sc8-pr-cvs1:/tmp/cvs-serv28328 Modified Files: build.bat Log Message: prodding build (Mike Roberts doing CCNet stuff) Index: build.bat =================================================================== RCS file: /cvsroot/nmock/nmock/build.bat,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** build.bat 30 Jul 2003 15:51:45 -0000 1.2 --- build.bat 18 Jan 2004 13:51:59 -0000 1.3 *************** *** 1,2 **** --- 1,3 ---- @echo off tools\NAnt.exe -buildfile:nmock.build %* + |
|
From: <exo...@us...> - 2004-01-15 01:00:12
|
Update of /cvsroot/nmock/nmock/lib In directory sc8-pr-cvs1:/tmp/cvs-serv19833/lib Modified Files: nunit.framework.dll Removed Files: nunit-console.exe nunit-console.exe.config Log Message: upgraded nmock to NUnit 2.1.4 and to NAnt 0.8.4 Index: nunit.framework.dll =================================================================== RCS file: /cvsroot/nmock/nmock/lib/nunit.framework.dll,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 Binary files /tmp/cvsQhXNYj and /tmp/cvsg1Bvlu differ --- nunit-console.exe DELETED --- --- nunit-console.exe.config DELETED --- |
Update of /cvsroot/nmock/nmock/tools
In directory sc8-pr-cvs1:/tmp/cvs-serv19833/tools
Modified Files:
NAnt.Core.dll NAnt.DotNetTasks.dll NAnt.NUnit.dll
NAnt.NUnit2Tasks.dll NAnt.exe.config NDoc.Core.dll nant.exe
nunit.framework.dll
Added Files:
ICSharpCode.SharpCvsLib.dll ICSharpCode.SharpZipLib.dll
NAnt.NUnit1Tasks.dll NAnt.SourceControlTasks.dll
NAnt.VSNetTasks.dll NAnt.VisualCppTasks.dll
NAnt.Win32Tasks.dll NAnt.ZipTasks.dll NDoc.Documenter.Msdn.dll
NDoc.Documenter.NAnt.dll log4net.dll
Log Message:
upgraded nmock to NUnit 2.1.4 and to NAnt 0.8.4
--- NEW FILE: ICSharpCode.SharpCvsLib.dll ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: ICSharpCode.SharpZipLib.dll ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: NAnt.SourceControlTasks.dll ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: NAnt.VSNetTasks.dll ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: NAnt.VisualCppTasks.dll ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: NAnt.Win32Tasks.dll ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: NAnt.ZipTasks.dll ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: NDoc.Documenter.Msdn.dll ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: NDoc.Documenter.NAnt.dll ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: log4net.dll ---
(This appears to be a binary file; contents omitted.)
Index: NAnt.Core.dll
===================================================================
RCS file: /cvsroot/nmock/nmock/tools/NAnt.Core.dll,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
Binary files /tmp/cvsRcyEfX and /tmp/cvsuJ2RCK differ
Index: NAnt.DotNetTasks.dll
===================================================================
RCS file: /cvsroot/nmock/nmock/tools/NAnt.DotNetTasks.dll,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
Binary files /tmp/cvswtFrK1 and /tmp/cvsoF0NyR differ
Index: NAnt.NUnit.dll
===================================================================
RCS file: /cvsroot/nmock/nmock/tools/NAnt.NUnit.dll,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
Binary files /tmp/cvs9MrUE3 and /tmp/cvs8PCuhX differ
Index: NAnt.NUnit2Tasks.dll
===================================================================
RCS file: /cvsroot/nmock/nmock/tools/NAnt.NUnit2Tasks.dll,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
Binary files /tmp/cvsujygP2 and /tmp/cvsYv3MJV differ
Index: NAnt.exe.config
===================================================================
RCS file: /cvsroot/nmock/nmock/tools/NAnt.exe.config,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NAnt.exe.config 8 Nov 2003 00:01:22 -0000 1.1
--- NAnt.exe.config 15 Jan 2004 00:59:39 -0000 1.2
***************
*** 3,7 ****
<!-- Leave this alone. Sets up configsectionhandler section -->
<configSections>
! <section name="nantsettings" type="NAnt.Core.ConfigurationSection, NAnt.Core" />
<section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
</configSections>
--- 3,7 ----
<!-- Leave this alone. Sets up configsectionhandler section -->
<configSections>
! <section name="nant" type="NAnt.Core.ConfigurationSection, NAnt.Core" />
<section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
</configSections>
***************
*** 17,74 ****
</appSettings>
<!-- nant config settings -->
! <nantsettings
! defaultframework="net-1.1"
! taskpath=".\optional">
<frameworks>
! <frameworkinfo name="net-1.0" description="Microsoft .Net Framework 1.0" version="1.0.3705" runtimeengine=""
! csharpcompilername="csc" basiccompilername="vbc" jsharpcompilername="vjc" jscriptcompilername="jsc"
! resgenname="resgen">
! <sdkdirectory useregistry="true" regkey="Software\Microsoft\.NetFramework" regvalue="sdkInstallRoot" />
! <frameworkdirectory useregistry="true" regkey="Software\Microsoft\.NetFramework" regvalue="InstallRoot" />
! <frameworkassemblydirectory useregistry="true" regkey="Software\Microsoft\.NetFramework" regvalue="InstallRoot" />
! </frameworkinfo>
! <frameworkinfo name="net-1.1" description="Microsoft .Net Framework 1.1" version="1.1.4322" runtimeengine=""
! csharpcompilername="csc" basiccompilername="vbc" jsharpcompilername="vjc" jscriptcompilername="jsc"
! resgenname="resgen">
! <sdkdirectory useregistry="true" regkey="Software\Microsoft\.NetFramework" regvalue="sdkInstallRootv1.1" />
! <frameworkdirectory useregistry="true" regkey="Software\Microsoft\.NetFramework" regvalue="InstallRoot" />
! <frameworkassemblydirectory useregistry="true" regkey="Software\Microsoft\.NetFramework" regvalue="InstallRoot" />
! </frameworkinfo>
! <frameworkinfo name="netcf-1.0" description="Microsoft .Net Compact Framework Framework 1.0" version="1.1.4322"
! runtimeengine="" csharpcompilername="csc" basiccompilername="vbc" jsharpcompilername="" jscriptcompilername=""
! resgenname="cfresgen">
! <sdkdirectory dir="C:\Program Files\Microsoft Visual Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\bin" />
! <frameworkdirectory useregistry="true" regkey="Software\Microsoft\.NetFramework" regvalue="InstallRoot" />
! <frameworkassemblydirectory dir="C:\Program Files\Microsoft Visual Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows CE" />
! </frameworkinfo>
! <frameworkinfo name="mono-1.0" description="gnome projects port of the .Net Framework" version="0.25"
! runtimeengine="mono.exe" csharpcompilername="mcs" basiccompilername="mbas" jsharpcompilername=""
! jscriptcompilername="" resgenname="monoresgen">
! <sdkdirectory dir="C:\Program Files\Mono-0.25\bin" />
! <frameworkdirectory dir="C:\Program Files\Mono-0.25\bin" />
! <frameworkassemblydirectory dir="C:\Program Files\Mono-0.25\lib" />
! </frameworkinfo>
! <!-- shared source implementation -->
! <frameworkinfo name="sscli-1.0" description="Microsoft Shared Source CLI 1.0" version="1.0.0000"
! runtimeengine="clix.exe" csharpcompilername="csc" basiccompilername="" jsharpcompilername=""
! jscriptcompilername="jsc" resgenname="resgen">
! <sdkdirectory dir="C:\sscli\build\v1.x86fstchk.rotor\sdk\bin" />
! <frameworkdirectory dir="C:\sscli\build\v1.x86fstchk.rotor" />
! <frameworkassemblydirectory dir="C:\sscli\build\v1.x86fstchk.rotor" />
! </frameworkinfo>
</frameworks>
<!-- Default properties -->
<properties>
! <!-- add global properties here in th following format-->
<!-- <property name="foo" value = "bar" readonly="false" /> -->
</properties>
! <tasks>
! <!-- setting for individual tasks -->
! <task name="csctask">
! <!-- not used yet --></task>
! <task name="resgentask">
! <!-- not used yet --></task>
! </tasks>
! </nantsettings>
<!--
This section contains the log4net configuration settings.
--- 17,272 ----
</appSettings>
<!-- nant config settings -->
! <nant defaultframework="net-1.1" taskpath=".\optional">
<frameworks>
! <platform name="win32" default="net-1.0">
! <framework name="net-1.0" description="Microsoft .NET Framework 1.0" version="${version}" runtimeengine=""
! sdkdirectory="${sdkInstallRoot}bin" frameworkdirectory="${installRoot}v${version}" frameworkassemblydirectory="${installRoot}v${version}">
! <properties>
! <property name="version" value="1.0.3705" />
! <property name="sdkInstallRoot" useregistry="true" regkey="SOFTWARE\Microsoft\.NETFramework"
! regvalue="sdkInstallRoot" />
! <property name="installRoot" useregistry="true" regkey="SOFTWARE\Microsoft\.NETFramework"
! regvalue="InstallRoot" />
! </properties>
! <tasks>
! <task name="csc">
! <attribute name="exename">csc</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="vbc">
! <attribute name="exename">vbc</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="jsc">
! <attribute name="exename">jsc</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="vjc">
! <attribute name="exename">vjc</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="resgen">
! <attribute name="exename">resgen</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="al">
! <attribute name="exename">al</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! </tasks>
! </framework>
! <framework name="net-1.1" description="Microsoft .NET Framework 1.1" version="${version}" runtimeengine=""
! sdkdirectory="${sdkInstallRoot}bin" frameworkdirectory="${installRoot}v${version}" frameworkassemblydirectory="${installRoot}v${version}">
! <properties>
! <property name="version" value="1.1.4322" />
! <property name="sdkInstallRoot" useregistry="true" regkey="SOFTWARE\Microsoft\.NETFramework"
! regvalue="sdkInstallRootv1.1" />
! <property name="installRoot" useregistry="true" regkey="SOFTWARE\Microsoft\.NETFramework"
! regvalue="InstallRoot" />
! </properties>
! <tasks>
! <task name="csc">
! <attribute name="exename">csc</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="vbc">
! <attribute name="exename">vbc</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="jsc">
! <attribute name="exename">jsc</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="vjc">
! <attribute name="exename">vjc</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="resgen">
! <attribute name="exename">resgen</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="al">
! <attribute name="exename">al</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! </tasks>
! </framework>
! <framework name="net-1.2" description="Microsoft .NET Framework 1.2" version="${version}" runtimeengine=""
! sdkdirectory="${sdkInstallRoot}bin" frameworkdirectory="${installRoot}v${version}" frameworkassemblydirectory="${installRoot}v${version}">
! <properties>
! <property name="version" value="1.2.30703" />
! <property name="sdkInstallRoot" useregistry="true" regkey="SOFTWARE\Microsoft\.NETFramework"
! regvalue="sdkInstallRootv1.2" />
! <property name="installRoot" useregistry="true" regkey="SOFTWARE\Microsoft\.NETFramework"
! regvalue="InstallRoot" />
! </properties>
! <tasks>
! <task name="csc">
! <attribute name="exename">csc</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="vbc">
! <attribute name="exename">vbc</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="jsc">
! <attribute name="exename">jsc</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="vjc">
! <attribute name="exename">vjc</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="resgen">
! <attribute name="exename">resgen</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="al">
! <attribute name="exename">al</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! </tasks>
! </framework>
! <framework name="netcf-1.0" description="Microsoft .Net Compact Framework Framework 1.0" version="${version}"
! runtimeengine="" sdkdirectory="${sdkInstallRoot}v${version}\bin" frameworkdirectory="${installRoot}v1.1.4322"
! frameworkassemblydirectory="${sdkInstallRoot}v${version}\Windows CE">
! <properties>
! <property name="version" value="1.0.5000" />
! <property name="sdkInstallRoot" useregistry="true" regkey="SOFTWARE\Microsoft\.NETCompactFramework"
! regvalue="sdkInstallRoot" />
! <property name="installRoot" useregistry="true" regkey="SOFTWARE\Microsoft\.NETFramework"
! regvalue="InstallRoot" />
! </properties>
! <tasks>
! <task name="csc">
! <attribute name="exename">csc</attribute>
! <attribute name="noconfig">true</attribute>
! <attribute name="nostdlib">true</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="vbc">
! <attribute name="exename">vbc</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="resgen">
! <attribute name="exename">cfresgen</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="al">
! <attribute name="exename">al</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="delay-sign">
! <attribute name="exename">sn</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! </tasks>
! </framework>
! <framework name="mono-1.0" description="GNOME projects port of the .NET Framework" version="${version}"
! runtimeengine="mono.exe" sdkdirectory="${sdkInstallRoot}\bin" frameworkdirectory="${sdkInstallRoot}\bin"
! frameworkassemblydirectory="${frameworkAssemblyDirectory}">
! <properties>
! <property name="version" value="0.28" />
! <property name="sdkInstallRoot" useregistry="true" regkey="SOFTWARE\Mono\${version}" regvalue="SdkInstallRoot" />
! <property name="frameworkAssemblyDirectory" useregistry="true" regkey="SOFTWARE\Mono\${version}" regvalue="FrameworkAssemblyDirectory" />
! <property name="configDir" useregistry="true" regkey="SOFTWARE\Mono\${version}" regvalue="MonoConfigDir" />
! </properties>
! <environment>
! <env name="PATH" path="${frameworkAssemblyDirectory};%PATH%" />
! <env name="MONO_BASEPATH" path="${sdkInstallRoot};%MONO_BASEPATH%" />
! <env name="MONO_PATH" path="${frameworkAssemblyDirectory};%MONO_PATH%" />
! <env name="MONO_CFG_DIR" path="${configDir};%MONO_CFG_DIR%" />
! </environment>
! <tasks>
! <task name="csc">
! <attribute name="exename">mcs</attribute>
! <attribute name="useruntimeengine">true</attribute>
! </task>
! <task name="vbc">
! <attribute name="exename">mbas</attribute>
! <attribute name="useruntimeengine">true</attribute>
! </task>
! <task name="resgen">
! <attribute name="exename">monoresgen</attribute>
! <attribute name="useruntimeengine">true</attribute>
! </task>
! <task name="delay-sign">
! <attribute name="exename">monosn</attribute>
! <attribute name="useruntimeengine">true</attribute>
! </task>
! </tasks>
! </framework>
! <framework name="sscli-1.0" description="Microsoft Shared Source CLI 1.0" version="${version}"
! runtimeengine="clix.exe" sdkdirectory="C:\sscli\build\v1.x86fstchk.rotor\sdk\bin" frameworkdirectory="C:\sscli\build\v1.x86fstchk.rotor"
! frameworkassemblydirectory="C:\sscli\build\v1.x86fstchk.rotor">
! <properties>
! <property name="version" value="1.0.0000" />
! </properties>
! <tasks>
! <task name="csc">
! <attribute name="exename">csc</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="jsc">
! <attribute name="exename">jsc</attribute>
! <attribute name="useruntimeengine">true</attribute>
! </task>
! <task name="resgen">
! <attribute name="exename">resgen</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="al">
! <attribute name="exename">al</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! <task name="delay-sign">
! <attribute name="exename">sn</attribute>
! <attribute name="useruntimeengine">false</attribute>
! </task>
! </tasks>
! </framework>
! </platform>
! <platform name="unix" default="mono-1.0">
! <framework name="mono-1.0" description="GNOME projects port of the .NET Framework" version="${version}"
! runtimeengine="mono" sdkdirectory="/usr/local/bin" frameworkdirectory="/usr/local/bin"
! frameworkassemblydirectory="/usr/local/lib">
! <properties>
! <property name="version" value="0.28" />
! </properties>
! <tasks>
! <task name="csc">
! <attribute name="exename">mcs</attribute>
! <attribute name="useruntimeengine">true</attribute>
! </task>
! <task name="vbc">
! <attribute name="exename">mbas</attribute>
! <attribute name="useruntimeengine">true</attribute>
! </task>
! <task name="resgen">
! <attribute name="exename">monoresgen</attribute>
! <attribute name="useruntimeengine">true</attribute>
! </task>
! <task name="delay-sign">
! <attribute name="exename">monosn</attribute>
! <attribute name="useruntimeengine">true</attribute>
! </task>
! </tasks>
! </framework>
! </platform>
! <!-- Framework-neutral properties -->
! <properties>
! <!-- <property name="foo" value = "bar" /> -->
! </properties>
! <!-- Framework-neutral task configuration defaults -->
! <tasks>
! <!-- settings for individual tasks -->
! </tasks>
</frameworks>
<!-- Default properties -->
<properties>
! <!-- add global properties here in the following format-->
<!-- <property name="foo" value = "bar" readonly="false" /> -->
</properties>
! </nant>
<!--
This section contains the log4net configuration settings.
***************
*** 119,124 ****
</log4net>
<startup>
<supportedRuntime version="v1.0.3705" />
- <supportedRuntime version="v1.1.4322" />
</startup>
</configuration>
--- 317,322 ----
</log4net>
<startup>
+ <supportedRuntime version="v1.1.4322" />
<supportedRuntime version="v1.0.3705" />
</startup>
</configuration>
Index: NDoc.Core.dll
===================================================================
RCS file: /cvsroot/nmock/nmock/tools/NDoc.Core.dll,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
Binary files /tmp/cvso9xGj8 and /tmp/cvsCaPe64 differ
Index: nant.exe
===================================================================
RCS file: /cvsroot/nmock/nmock/tools/nant.exe,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
Binary files /tmp/cvsd50uGa and /tmp/cvs0VpOjb differ
Index: nunit.framework.dll
===================================================================
RCS file: /cvsroot/nmock/nmock/tools/nunit.framework.dll,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
Binary files /tmp/cvsg0orP9 and /tmp/cvsEFhOmc differ
|
|
From: <exo...@us...> - 2004-01-15 00:59:50
|
Update of /cvsroot/nmock/nmock
In directory sc8-pr-cvs1:/tmp/cvs-serv19833
Modified Files:
nmock.build
Log Message:
upgraded nmock to NUnit 2.1.4 and to NAnt 0.8.4
Index: nmock.build
===================================================================
RCS file: /cvsroot/nmock/nmock/nmock.build,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** nmock.build 30 Jul 2003 17:10:33 -0000 1.4
--- nmock.build 15 Jan 2004 00:59:38 -0000 1.5
***************
*** 37,40 ****
--- 37,41 ----
<target name="test" depends="compile" description="Run unit tests">
<nunit2>
+ <formatter type="Plain" />
<test assemblyname="build\nmock.test.dll" fork="true" type="${nunit.output}"/>
</nunit2>
|
|
From: Mike B. <mbr...@vi...> - 2004-01-11 17:12:59
|
It makes sense to me. There are many times when I don't really care that a
certain method is called or that it is called more than once. Putting in
expectXXX() calls just clutters my test code and makes it sensitive to
implementation level changes to the real code.
Mike
> -----Original Message-----
> From: nmo...@li...
> [mailto:nmo...@li...]On Behalf Of Nat Pryce
> Sent: Thursday, January 08, 2004 5:56 AM
> To: jmo...@li...; Steve Freeman
> Cc: nmo...@li...
> Subject: Re: [jmock-dev] RE: [Nmock-general] Strict vs Lenient mode for
> mock objects
>
>
> Here's what we are envisaging.
>
> A Mock* has a set of invocation mockers and a default stub that is used to
> provide behaviour for an invocation that doesn't match against any
> invocation mocker.
>
> By default the default stub signals a test failure.
>
> The user will be able to set the default stub to change the default
> behaviour of the mock.
>
> If they change it to a DefaultResultStub then they will get a
> lenient mode.
> They can set up the DefaultResultStub to handle their own classes
> and share
> a single DefaultResultStub among multiple mock objects so that
> they all have
> the same default behaviour.
>
> Code would look like:
>
> public void setUp() {
> DefaultResultStub defaults = new DefaultResultStub();
> defaults.addDefaultResult( Date.class, new Date(-1L) );
> defaults.addDefaultResult( Point.class, new Point(0,0) );
>
> mock = new Mock( MockedInterface.class );
> mock.setDefaultStub( defaults );
> }
>
> What do people think?
> https://lists.sourceforge.net/lists/listinfo/nmock-general
|
|
From: Jim A. <JA...@th...> - 2004-01-08 18:09:33
|
>I would like to suggest an alternative (d) though which is quite like >option (a) as follows: if you call GetInstance() with no arguments, then >any constructor is used on the class being mocked; null or zero values >are passed in as relevant and any exceptions are caught and swallowed. There is a problem with this, though: there is no way to stop the base constructor executing. And, if the base doesn't like the default parameters you pass in, the construction process fails. I started off thinking that a constructor is just another method, but it really isn't, and has different semantics. I did think about screwing with the IL in the mock's constructor so that it wraps calls to base::.ctor in a try...catch, but I've no idea what the runtime would say to such heresy. It *should* reject it as invalid, because it would leave the mock with a null base class, but you never know... Having said all this, there's no reason why constructors with parameters should be any less dependable than those without, but I guess there's a tendency to "do stuff" with things that get passed to you, whereas well-behaved, parameter-less constructors don't have much to do anything with. Maybe there's a mini anti-pattern there: should constructors call methods on their parameters? Jim |---------+-----------------------------------------> | | Mike Roberts | | | <mik...@th...| | | > | | | Sent by: | | | nmo...@li...| | | ceforge.net | | | | | | | | | 08/01/2004 13:40 | | | | |---------+-----------------------------------------> >------------------------------------------------------------------------------------------------------------------------------| | | | To: nmo...@li... | | cc: | | Subject: [Nmock-general] Mocking classes without an empty constructor | >------------------------------------------------------------------------------------------------------------------------------| Hi all, Say you have the following: class Foo { public Foo(int x) { .. } public Sheep calculateSheep() { .. } } class Bar { public Bar(Foo foo) { .. } } class BarTest { [Test] public void DoesSomethingWithFoo() { DynamicMock mockFoo = new DynamicMock(typeof(Foo)); Foo aFoo = (Foo) mockFoo.MockInstance; Bar aBar = new Bar(aFoo); } } As NMock stands right now though, this won't work because Foo doesn't have an empty constructor. The answer to this so far has been to either: (a) Interface/Impl separate Foo (b) Add an empty constructor to Foo With (a), we would therefore get: interface IFoo { Sheep calculateSheep() { .. } } class Foo : IFoo { .. } class Bar { public Bar(IFoo foo) { .. } } I/I separation fans like this because it means a lot of I/I separation happens. People that don't like introducing interfaces when there's only one implementation have a big problem with it though. With (b), we end up with a bunch of constructors in our project that only exist for testing. This is a bad thing if you're using IoC(3) principles. So, Jim Arnold made a change the other day to our internal version of NMock so that you can do the following (call this option (c) ) class BarTest { [Test] public void DoesSomethingWithFoo() { DynamicMock mockFoo = new DynamicMock(typeof(Foo)); Foo aFoo = (Foo) mockFoo.GetInstance(2); /// Note the new method on DynamicMock Bar aBar = new Bar(aFoo); } } In other words, you can mock classes with non-empty constructors by passing in some constructor values, and constructor matching happens against the class being mocked. I would like to suggest an alternative (d) though which is quite like option (a) as follows: if you call GetInstance() with no arguments, then any constructor is used on the class being mocked; null or zero values are passed in as relevant and any exceptions are caught and swallowed. With such a mock instance it is invalid to pass calls to the mock instance through to the parent class. Why? Because this would allow us to use the signature of the class, without having to worry about any state in the mocked class. Effectively it does automatically exactly what we would do manually by extracting an interface. Any thoughts? Mike ------------------------------------------------------- This SF.net email is sponsored by: Perforce Software. Perforce is the Fast Software Configuration Management System offering advanced branching capabilities and atomic changes on 50+ platforms. Free Eval! http://www.perforce.com/perforce/loadprog.html _______________________________________________ Nmock-general mailing list Nmo...@li... https://lists.sourceforge.net/lists/listinfo/nmock-general |
|
From: Mike R. <mik...@th...> - 2004-01-08 13:40:22
|
Hi all,
Say you have the following:
class Foo
{
public Foo(int x) { .. }
public Sheep calculateSheep() { .. }
}
class Bar
{
public Bar(Foo foo) { .. }
}
class BarTest
{
[Test]
public void DoesSomethingWithFoo()
{
DynamicMock mockFoo = new DynamicMock(typeof(Foo));
Foo aFoo = (Foo) mockFoo.MockInstance;
Bar aBar = new Bar(aFoo);
}
}
As NMock stands right now though, this won't work because Foo doesn't
have an empty constructor. The answer to this so far has been to either:
(a) Interface/Impl separate Foo
(b) Add an empty constructor to Foo
With (a), we would therefore get:
interface IFoo
{
Sheep calculateSheep() { .. }
}
class Foo : IFoo { .. }
class Bar
{
public Bar(IFoo foo) { .. }
}
I/I separation fans like this because it means a lot of I/I separation
happens. People that don't like introducing interfaces when there's only
one implementation have a big problem with it though.
With (b), we end up with a bunch of constructors in our project that
only exist for testing. This is a bad thing if you're using IoC(3)
principles.
So, Jim Arnold made a change the other day to our internal version of
NMock so that you can do the following (call this option (c) )
class BarTest
{
[Test]
public void DoesSomethingWithFoo()
{
DynamicMock mockFoo = new DynamicMock(typeof(Foo));
Foo aFoo = (Foo) mockFoo.GetInstance(2); /// Note the new method
on DynamicMock
Bar aBar = new Bar(aFoo);
}
}
In other words, you can mock classes with non-empty constructors by
passing in some constructor values, and constructor matching happens
against the class being mocked.
I would like to suggest an alternative (d) though which is quite like
option (a) as follows: if you call GetInstance() with no arguments, then
any constructor is used on the class being mocked; null or zero values
are passed in as relevant and any exceptions are caught and swallowed.
With such a mock instance it is invalid to pass calls to the mock
instance through to the parent class.
Why? Because this would allow us to use the signature of the class,
without having to worry about any state in the mocked class. Effectively
it does automatically exactly what we would do manually by extracting an
interface.
Any thoughts?
Mike
|
|
From: Nat P. <nat...@b1...> - 2004-01-08 12:03:06
|
Here's what we are envisaging.
A Mock* has a set of invocation mockers and a default stub that is used to
provide behaviour for an invocation that doesn't match against any
invocation mocker.
By default the default stub signals a test failure.
The user will be able to set the default stub to change the default
behaviour of the mock.
If they change it to a DefaultResultStub then they will get a lenient mode.
They can set up the DefaultResultStub to handle their own classes and share
a single DefaultResultStub among multiple mock objects so that they all have
the same default behaviour.
Code would look like:
public void setUp() {
DefaultResultStub defaults = new DefaultResultStub();
defaults.addDefaultResult( Date.class, new Date(-1L) );
defaults.addDefaultResult( Point.class, new Point(0,0) );
mock = new Mock( MockedInterface.class );
mock.setDefaultStub( defaults );
}
What do people think?
--------
* Actually the InvocationDispatcher inside the mock, but that's an
implementation detail.
_______________________
Dr. Nathaniel Pryce
B13media Ltd.
http://www.b13media.com
+44 (0)7712 526 661
----- Original Message -----
From: "Nick Robinson" <nic...@ya...>
To: "Steve Freeman" <st...@m3...>; "JMock Dev"
<jmo...@li...>
Cc: <nmo...@li...>
Sent: Thursday, January 08, 2004 7:38 AM
Subject: [jmock-dev] RE: [Nmock-general] Strict vs Lenient mode for mock
objects
> I personally can see the benefit of the lenient mode, but IMO it should
have
> to be "switched on", and be in switched off mode by default. This is
> similar to my comments about the Strict property. However, if there was
> documentation with NMock, which was accompanied with a few use scenarios
> (showing the use of Strict), such problems I witnessed may not have
> happened.
>
> Thanks,
>
> nick.robinson
> site : www.fromconcept.co.uk
> blog : www.fromconcept.co.uk/weblog.aspx
>
> > -----Original Message-----
> > From: nmo...@li...
> > [mailto:nmo...@li...]On Behalf Of Steve
> > Freeman
> > Sent: 07 January 2004 23:13
> > To: JMock Dev
> > Cc: nmo...@li...
> > Subject: [Nmock-general] Strict vs Lenient mode for mock objects
> >
> >
> > Hello mockistas. We (Steve & Nat) have just spent a semi-productive
> > session designing an API for "lenient mode" mock objects. In lenient
> > mode a mock will return default values from unexpected invocations
> > instead of throwing a test failure.
> >
> > But then we decided that it was a bad idea and deleted all the code.
> >
> > Lenient mode can mask errors and make errors fail slow instead of fast.
> > In fact, Nick Robinson has just complained about this on the nmock list.
> > There is some mechanism underneath to support default values for people
> > who want to pop in their own default stub, but this is not yet exposed
> > properly.
> >
> > What do people think about lenient mode?
> >
> > Cheers,
> > Nat & Steve.
> >
> >
> > -------------------------------------------------------
> > This SF.net email is sponsored by: Perforce Software.
> > Perforce is the Fast Software Configuration Management System offering
> > advanced branching capabilities and atomic changes on 50+ platforms.
> > Free Eval! http://www.perforce.com/perforce/loadprog.html
> > _______________________________________________
> > Nmock-general mailing list
> > Nmo...@li...
> > https://lists.sourceforge.net/lists/listinfo/nmock-general
> >
>
> _______________________________________________
> jmock-dev mailing list
> jmo...@li...
> http://lists.codehaus.org/mailman/listinfo/jmock-dev
|
|
From: Nick R. <nic...@ya...> - 2004-01-08 07:38:42
|
I personally can see the benefit of the lenient mode, but IMO it should have to be "switched on", and be in switched off mode by default. This is similar to my comments about the Strict property. However, if there was documentation with NMock, which was accompanied with a few use scenarios (showing the use of Strict), such problems I witnessed may not have happened. Thanks, nick.robinson site : www.fromconcept.co.uk blog : www.fromconcept.co.uk/weblog.aspx > -----Original Message----- > From: nmo...@li... > [mailto:nmo...@li...]On Behalf Of Steve > Freeman > Sent: 07 January 2004 23:13 > To: JMock Dev > Cc: nmo...@li... > Subject: [Nmock-general] Strict vs Lenient mode for mock objects > > > Hello mockistas. We (Steve & Nat) have just spent a semi-productive > session designing an API for "lenient mode" mock objects. In lenient > mode a mock will return default values from unexpected invocations > instead of throwing a test failure. > > But then we decided that it was a bad idea and deleted all the code. > > Lenient mode can mask errors and make errors fail slow instead of fast. > In fact, Nick Robinson has just complained about this on the nmock list. > There is some mechanism underneath to support default values for people > who want to pop in their own default stub, but this is not yet exposed > properly. > > What do people think about lenient mode? > > Cheers, > Nat & Steve. > > > ------------------------------------------------------- > This SF.net email is sponsored by: Perforce Software. > Perforce is the Fast Software Configuration Management System offering > advanced branching capabilities and atomic changes on 50+ platforms. > Free Eval! http://www.perforce.com/perforce/loadprog.html > _______________________________________________ > Nmock-general mailing list > Nmo...@li... > https://lists.sourceforge.net/lists/listinfo/nmock-general > |
|
From: Steve F. <st...@m3...> - 2004-01-07 23:11:37
|
Hello mockistas. We (Steve & Nat) have just spent a semi-productive session designing an API for "lenient mode" mock objects. In lenient mode a mock will return default values from unexpected invocations instead of throwing a test failure. But then we decided that it was a bad idea and deleted all the code. Lenient mode can mask errors and make errors fail slow instead of fast. In fact, Nick Robinson has just complained about this on the nmock list. There is some mechanism underneath to support default values for people who want to pop in their own default stub, but this is not yet exposed properly. What do people think about lenient mode? Cheers, Nat & Steve. |
|
From: Steve F. <st...@m3...> - 2004-01-06 11:10:18
|
Your mileage may vary. My instincts are more "discpline and bondage" than some of the others, so I would have preferred to have Strict as the default setting, but others prefer a little slack. Don't forget, you can also check that a method is /not/ called, if that's what you're interested in. S. Nick Robinson wrote: > I am sure there is a really good reason for the Strict property being > defaulted to false, but what do people think about this defaulting to > true? Through human error, we have missed things when building the > mocks. I have been sat with a colleague today, and we expected the > abscence of a method call in the Expect calls, to result in a failure > when the method is actually called. So we looked at it and so the > Strict property, set it to true and ran. Hey presto, we found that > not only was the problem highlighted by setting this to true, but we > had overlooked a call to a certain method in a certain way. Setting > it to true picks this up, because it shows we didnt do a > Mock.ExpectXXX(). > > I can see that maybe having to put all calls in, would couple the > code to the behaviour of the class that uses the mock. But I think > thats what we are doing anyway, and it reads better by making the > mock behaviour more explicit in the test cases, by having to define > the calls. If strict is false, then ignore seems to be redundant? > > Just wondered what peoples thoughts are. |
|
From: Nick R. <nic...@fr...> - 2004-01-05 16:02:00
|
I am sure there is a really good reason for the Strict property being defaulted to false, but what do people think about this defaulting to true? Through human error, we have missed things when building the mocks. I have been sat with a colleague today, and we expected the abscence of a method call in the Expect calls, to result in a failure when the method is actually called. So we looked at it and so the Strict property, set it to true and ran. Hey presto, we found that not only was the problem highlighted by setting this to true, but we had overlooked a call to a certain method in a certain way. Setting it to true picks this up, because it shows we didnt do a Mock.ExpectXXX(). I can see that maybe having to put all calls in, would couple the code to the behaviour of the class that uses the mock. But I think thats what we are doing anyway, and it reads better by making the mock behaviour more explicit in the test cases, by having to define the calls. If strict is false, then ignore seems to be redundant? Just wondered what peoples thoughts are. nick robinson site : http://www.fromconcept.co.uk weblog : http://www.fromconcept.co.uk/weblog.aspx |
|
From: <sm...@us...> - 2003-11-29 17:26:28
|
Update of /cvsroot/nmock/nmock/src
In directory sc8-pr-cvs1:/tmp/cvs-serv23622/src
Modified Files:
NMock.csproj
Log Message:
ascii/binary
Index: NMock.csproj
===================================================================
RCS file: /cvsroot/nmock/nmock/src/NMock.csproj,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NMock.csproj 24 Jul 2003 23:08:55 -0000 1.1
--- NMock.csproj 29 Nov 2003 17:26:21 -0000 1.2
***************
*** 1,168 ****
! <VisualStudioProject>
! <CSHARP
! ProjectType = "Local"
! ProductVersion = "7.10.3077"
! SchemaVersion = "2.0"
! ProjectGuid = "{4859B9E5-3F65-4517-878C-AFC58B9D0035}"
! SccProjectName = "Perforce Project"
! SccLocalPath = "."
! SccProvider = "MSSCCI:Perforce SCM"
! >
! <Build>
! <Settings
! ApplicationIcon = ""
! AssemblyKeyContainerName = ""
! AssemblyName = "NMock"
! AssemblyOriginatorKeyFile = ""
! DefaultClientScript = "JScript"
! DefaultHTMLPageLayout = "Grid"
! DefaultTargetSchema = "IE50"
! DelaySign = "false"
! OutputType = "Library"
! PreBuildEvent = ""
! PostBuildEvent = ""
! RootNamespace = "NMock"
! RunPostBuildEvent = "OnBuildSuccess"
! StartupObject = ""
! >
! <Config
! Name = "Debug"
! AllowUnsafeBlocks = "false"
! BaseAddress = "285212672"
! CheckForOverflowUnderflow = "false"
! ConfigurationOverrideFile = ""
! DefineConstants = "DEBUG;TRACE"
! DocumentationFile = ""
! DebugSymbols = "true"
! FileAlignment = "4096"
! IncrementalBuild = "true"
! NoStdLib = "false"
! NoWarn = ""
! Optimize = "false"
! OutputPath = "bin\Debug\"
! RegisterForComInterop = "false"
! RemoveIntegerChecks = "false"
! TreatWarningsAsErrors = "false"
! WarningLevel = "4"
! />
! <Config
! Name = "Release"
! AllowUnsafeBlocks = "false"
! BaseAddress = "285212672"
! CheckForOverflowUnderflow = "false"
! ConfigurationOverrideFile = ""
! DefineConstants = "TRACE"
! DocumentationFile = ""
! DebugSymbols = "false"
! FileAlignment = "4096"
! IncrementalBuild = "false"
! NoStdLib = "false"
! NoWarn = ""
! Optimize = "true"
! OutputPath = "bin\Release\"
! RegisterForComInterop = "false"
! RemoveIntegerChecks = "false"
! TreatWarningsAsErrors = "false"
! WarningLevel = "4"
! />
! </Settings>
! <References>
! <Reference
! Name = "System"
! AssemblyName = "System"
! HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.0.3705\System.dll"
! />
! <Reference
! Name = "System.Data"
! AssemblyName = "System.Data"
! HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.0.3705\System.Data.dll"
! />
! <Reference
! Name = "System.XML"
! AssemblyName = "System.Xml"
! HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.0.3705\System.XML.dll"
! />
! </References>
! </Build>
! <Files>
! <Include>
! <File
! RelPath = "AssemblyInfo.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\CallMethodWithoutExpectation.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\DynamicMock.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\IMethod.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\IMock.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\IVerifiable.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\Method.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\Mock.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\MockCall.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\SingleMethod.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\VerifyException.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\Constraints\Constraints.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\Constraints\IConstraint.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\Dynamic\ClassGenerator.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\Dynamic\InterfaceLister.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! </Include>
! </Files>
! </CSHARP>
! </VisualStudioProject>
!
--- 1,168 ----
! <VisualStudioProject>
! <CSHARP
! ProjectType = "Local"
! ProductVersion = "7.10.3077"
! SchemaVersion = "2.0"
! ProjectGuid = "{4859B9E5-3F65-4517-878C-AFC58B9D0035}"
! SccProjectName = "Perforce Project"
! SccLocalPath = "."
! SccProvider = "MSSCCI:Perforce SCM"
! >
! <Build>
! <Settings
! ApplicationIcon = ""
! AssemblyKeyContainerName = ""
! AssemblyName = "NMock"
! AssemblyOriginatorKeyFile = ""
! DefaultClientScript = "JScript"
! DefaultHTMLPageLayout = "Grid"
! DefaultTargetSchema = "IE50"
! DelaySign = "false"
! OutputType = "Library"
! PreBuildEvent = ""
! PostBuildEvent = ""
! RootNamespace = "NMock"
! RunPostBuildEvent = "OnBuildSuccess"
! StartupObject = ""
! >
! <Config
! Name = "Debug"
! AllowUnsafeBlocks = "false"
! BaseAddress = "285212672"
! CheckForOverflowUnderflow = "false"
! ConfigurationOverrideFile = ""
! DefineConstants = "DEBUG;TRACE"
! DocumentationFile = ""
! DebugSymbols = "true"
! FileAlignment = "4096"
! IncrementalBuild = "true"
! NoStdLib = "false"
! NoWarn = ""
! Optimize = "false"
! OutputPath = "bin\Debug\"
! RegisterForComInterop = "false"
! RemoveIntegerChecks = "false"
! TreatWarningsAsErrors = "false"
! WarningLevel = "4"
! />
! <Config
! Name = "Release"
! AllowUnsafeBlocks = "false"
! BaseAddress = "285212672"
! CheckForOverflowUnderflow = "false"
! ConfigurationOverrideFile = ""
! DefineConstants = "TRACE"
! DocumentationFile = ""
! DebugSymbols = "false"
! FileAlignment = "4096"
! IncrementalBuild = "false"
! NoStdLib = "false"
! NoWarn = ""
! Optimize = "true"
! OutputPath = "bin\Release\"
! RegisterForComInterop = "false"
! RemoveIntegerChecks = "false"
! TreatWarningsAsErrors = "false"
! WarningLevel = "4"
! />
! </Settings>
! <References>
! <Reference
! Name = "System"
! AssemblyName = "System"
! HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.0.3705\System.dll"
! />
! <Reference
! Name = "System.Data"
! AssemblyName = "System.Data"
! HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.0.3705\System.Data.dll"
! />
! <Reference
! Name = "System.XML"
! AssemblyName = "System.Xml"
! HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.0.3705\System.XML.dll"
! />
! </References>
! </Build>
! <Files>
! <Include>
! <File
! RelPath = "AssemblyInfo.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\CallMethodWithoutExpectation.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\DynamicMock.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\IMethod.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\IMock.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\IVerifiable.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\Method.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\Mock.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\MockCall.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\SingleMethod.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\VerifyException.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\Constraints\Constraints.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\Constraints\IConstraint.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\Dynamic\ClassGenerator.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! <File
! RelPath = "NMock\Dynamic\InterfaceLister.cs"
! SubType = "Code"
! BuildAction = "Compile"
! />
! </Include>
! </Files>
! </CSHARP>
! </VisualStudioProject>
!
|
|
From: <sm...@us...> - 2003-11-29 17:25:32
|
Update of /cvsroot/nmock/nmock
In directory sc8-pr-cvs1:/tmp/cvs-serv23477
Modified Files:
continuousintegration.build
Log Message:
*** keyword substitution change ***
Index: continuousintegration.build
===================================================================
RCS file: /cvsroot/nmock/nmock/continuousintegration.build,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** continuousintegration.build 30 Jul 2003 15:49:22 -0000 1.1
--- continuousintegration.build 29 Nov 2003 17:25:28 -0000 1.2
***************
*** 1,24 ****
! <project name="ccnetlaunch" default="go">
! <target name="go" depends="update,build"/>
!
! <target name="update">
! <ifnot propertyexists="cvs.executable">
! <fail message="cvs.executable property not set, so can't update" />
! </ifnot>
! <echo message="CVS Executable at [${cvs.executable}]" />
! <exec
! basedir="."
! program="${cvs.executable}"
! commandline="-q update -P -d"
! />
! </target>
!
! <target name="build">
! <nant
! buildfile="nmock.build"
! target="cruise"
! inheritall="true"
! />
! </target>
!
</project>
--- 1,24 ----
! <project name="ccnetlaunch" default="go">
! <target name="go" depends="update,build"/>
!
! <target name="update">
! <ifnot propertyexists="cvs.executable">
! <fail message="cvs.executable property not set, so can't update" />
! </ifnot>
! <echo message="CVS Executable at [${cvs.executable}]" />
! <exec
! basedir="."
! program="${cvs.executable}"
! commandline="-q update -P -d"
! />
! </target>
!
! <target name="build">
! <nant
! buildfile="nmock.build"
! target="cruise"
! inheritall="true"
! />
! </target>
!
</project>
|
|
From: <sm...@us...> - 2003-11-29 17:19:18
|
Update of /cvsroot/nmock/nmock/test/NMock
In directory sc8-pr-cvs1:/tmp/cvs-serv22336/test/NMock
Modified Files:
MockTest.cs
Log Message:
Added better diagnostics for rejected constraint
Index: MockTest.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/test/NMock/MockTest.cs,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** MockTest.cs 13 Aug 2003 21:19:58 -0000 1.11
--- MockTest.cs 29 Nov 2003 17:19:13 -0000 1.12
***************
*** 231,235 ****
}
- // , Ignore("NoCall does not currently work, but requires a biggish overhaul to fix. No time right now to do it")]
[Test] public void ExpectNoCall_WithNoCall()
{
--- 231,234 ----
***************
*** 391,401 ****
[Test] public void IncorrectParameterConstraintMessage()
{
try
{
! IMock Constraint = new DynamicMock(typeof(IConstraint));
! Constraint.SetupResult("Message", "wee woo");
! Constraint.SetupResult("Eval", false, typeof(object));
! mock.Expect("x", new IsAnything(), (IConstraint)Constraint.MockInstance);
mock.Invoke("x", "hello", "world");
Assertion.Fail("Expected VerifyException");
--- 390,402 ----
[Test] public void IncorrectParameterConstraintMessage()
{
+ IMock mockConstraint = new DynamicMock(typeof(IConstraint));
try
{
! mockConstraint.SetupResult("Message", "wee woo");
! mockConstraint.SetupResult("Eval", false, typeof(object));
! mockConstraint.ExpectAndReturn("ExtractActualValue", "actual value", "world");
!
! mock.Expect("x", new IsAnything(), (IConstraint)mockConstraint.MockInstance);
mock.Invoke("x", "hello", "world");
Assertion.Fail("Expected VerifyException");
***************
*** 405,410 ****
Assertion.AssertEquals("x() called with incorrect parameter (2)", e.Reason);
Assertion.AssertEquals("wee woo", e.Expected);
! Assertion.AssertEquals("world", e.Actual);
}
}
--- 406,413 ----
Assertion.AssertEquals("x() called with incorrect parameter (2)", e.Reason);
Assertion.AssertEquals("wee woo", e.Expected);
! Assertion.AssertEquals("actual value", e.Actual);
}
+
+ mockConstraint.Verify();
}
|
|
From: <sm...@us...> - 2003-11-29 17:19:18
|
Update of /cvsroot/nmock/nmock/src/NMock
In directory sc8-pr-cvs1:/tmp/cvs-serv22336/src/NMock
Modified Files:
MockCall.cs
Log Message:
Added better diagnostics for rejected constraint
Index: MockCall.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/src/NMock/MockCall.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** MockCall.cs 16 Oct 2003 13:49:13 -0000 1.5
--- MockCall.cs 29 Nov 2003 17:19:13 -0000 1.6
***************
*** 83,87 ****
String messageFormat = "{0}() called with incorrect parameter ({1})";
String message = String.Format(messageFormat, methodName, index + 1);
! throw new VerifyException(message, expected.Message, actual);
}
}
--- 83,87 ----
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));
}
}
|
|
From: <sm...@us...> - 2003-11-29 17:04:50
|
Update of /cvsroot/nmock/nmock/src/NMock
In directory sc8-pr-cvs1:/tmp/cvs-serv19354/src/NMock
Modified Files:
Mock.cs DynamicMock.cs
Log Message:
Allow SetupResult to return conformant types, rather than exact match
Bit more refactoring
Index: Mock.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/src/NMock/Mock.cs,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** Mock.cs 13 Aug 2003 21:19:58 -0000 1.12
--- Mock.cs 29 Nov 2003 17:04:46 -0000 1.13
***************
*** 73,83 ****
public virtual void SetupResult(string methodName, object returnVal, params Type[] argTypes)
{
! IMethod method = getMethod(new MethodSignature(Name, methodName, argTypes));
if (method == null)
{
! method = new CallMethodWithoutExpectation(methodName);
! methods[methodName] = method;
}
! method.SetExpectation(new MockCall(new MethodSignature(Name, methodName, argTypes), returnVal, null, null));
}
--- 73,88 ----
public virtual void SetupResult(string methodName, object returnVal, params Type[] argTypes)
{
! SetupResult(new MethodSignature(Name, methodName, argTypes), returnVal);
! }
!
! protected void SetupResult(MethodSignature signature, object returnVal)
! {
! IMethod method = getMethod(signature);
if (method == null)
{
! method = new CallMethodWithoutExpectation(signature.methodName);
! methods[signature.methodName] = method;
}
! method.SetExpectation(new MockCall(signature, returnVal, null, null));
}
Index: DynamicMock.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/src/NMock/DynamicMock.cs,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** DynamicMock.cs 28 Nov 2003 17:31:22 -0000 1.18
--- DynamicMock.cs 29 Nov 2003 17:04:46 -0000 1.19
***************
*** 7,111 ****
namespace NMock
{
! public class DynamicMock : Mock
! {
! private object mockInstance;
! private Type type;
! private IList ignoredMethodNames;
! private readonly Type superclassIfTypeIsInterface;
! public DynamicMock(Type type) : this(type, "Mock" + type.Name) {}
! 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;
! }
! public override object MockInstance
! {
! get
! {
! if (mockInstance == null)
! {
! mockInstance = CreateClassGenerator().Generate();
! }
! return mockInstance;
! }
! }
! /// <summary>
! /// Don't generate mock method for suppied methodName.
! /// </summary>
! public virtual void Ignore(string methodName)
! {
! ignoredMethodNames.Add(methodName);
! }
! 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);
! checkMethodIsValidIfNoConstraints(signature);
! checkReturnTypeIsValid(methodName, returnVal);
! base.SetupResult(methodName, returnVal, argTypes);
! }
! void checkReturnTypeIsValid(string methodName, object returnVal)
! {
! if (returnVal == null)
! {
! return;
! }
! MethodInfo method = type.GetMethod(methodName, ClassGenerator.ALL_INSTANCE_METHODS);
! Type realReturnVal;
! if(method == null)
! {
! realReturnVal = type.GetProperty(methodName, ClassGenerator.ALL_INSTANCE_METHODS).PropertyType;
! }
! else
! {
! realReturnVal = method.ReturnType;
! }
! if (realReturnVal == null)
! {
! realReturnVal = type.GetProperty(methodName, ClassGenerator.ALL_INSTANCE_METHODS).PropertyType;
! }
!
! if(realReturnVal != returnVal.GetType())
! {
! throw new ArgumentException(String.Format("method <{0}> returns a {1}", methodName, realReturnVal));
! }
! }
!
! void checkMethodIsValidIfNoConstraints(MethodSignature signature)
! {
! if (signature.HasAConstraintArgument)
! return;
! foreach (Type t in new InterfaceLister().List(type))
! {
! if (signature.IsPropertyOn(t) || signature.HasMatchingMethodIn(t))
! return;
! }
! throw new MissingMethodException(String.Format("method <{0}> not defined", signature.methodName));
! }
! }
}
--- 7,101 ----
namespace NMock
{
! public class DynamicMock : Mock
! {
! private object mockInstance;
! private Type type;
! private IList ignoredMethodNames;
! private readonly Type superclassIfTypeIsInterface;
! public DynamicMock(Type type) : this(type, "Mock" + type.Name) {}
! 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;
! }
! public override object MockInstance
! {
! get
! {
! if (mockInstance == null)
! {
! mockInstance = CreateClassGenerator().Generate();
! }
! return mockInstance;
! }
! }
! /// <summary>
! /// Don't generate mock method for suppied methodName.
! /// </summary>
! public virtual void Ignore(string methodName)
! {
! ignoredMethodNames.Add(methodName);
! }
! 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);
! CheckMethodIsValidIfNoConstraints(signature);
! CheckReturnTypeIsValid(methodName, returnVal);
! SetupResult(signature, returnVal);
! }
! void CheckReturnTypeIsValid(string methodName, object returnVal)
! {
! if (returnVal == null)
! return;
! Type realReturnType = ReturnTypeForMethodName(methodName);
! if(! realReturnType.IsAssignableFrom(returnVal.GetType()))
! {
! throw new ArgumentException(String.Format("method <{0}> should return a {1}", methodName, realReturnType));
! }
! }
! private void CheckMethodIsValidIfNoConstraints(MethodSignature signature)
! {
! if (signature.HasAConstraintArgument)
! return;
! foreach (Type t in new InterfaceLister().List(type))
! {
! if (signature.IsPropertyOn(t) || signature.HasMatchingMethodIn(t))
! return;
! }
! throw new MissingMethodException(String.Format("method <{0}> not defined", signature.methodName));
! }
! private Type ReturnTypeForMethodName(string methodName)
! {
! MethodInfo method = type.GetMethod(methodName, ClassGenerator.ALL_INSTANCE_METHODS);
! return (method == null)
! ? type.GetProperty(methodName, ClassGenerator.ALL_INSTANCE_METHODS).PropertyType
! : method.ReturnType;
! }
! }
}
|
|
From: <sm...@us...> - 2003-11-29 17:04:50
|
Update of /cvsroot/nmock/nmock/test/NMock
In directory sc8-pr-cvs1:/tmp/cvs-serv19354/test/NMock
Modified Files:
FastErrorHandlingTest.cs DynamicMockTest.cs
Log Message:
Allow SetupResult to return conformant types, rather than exact match
Bit more refactoring
Index: FastErrorHandlingTest.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/test/NMock/FastErrorHandlingTest.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** FastErrorHandlingTest.cs 24 Jul 2003 23:09:05 -0000 1.3
--- FastErrorHandlingTest.cs 29 Nov 2003 17:04:47 -0000 1.4
***************
*** 72,76 ****
catch (ArgumentException e)
{
! AssertEquals("method <Foo> returns a System.String", e.Message);
}
}
--- 72,76 ----
catch (ArgumentException e)
{
! AssertEquals("method <Foo> should return a System.String", e.Message);
}
}
Index: DynamicMockTest.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/test/NMock/DynamicMockTest.cs,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** DynamicMockTest.cs 7 Nov 2003 23:28:39 -0000 1.17
--- DynamicMockTest.cs 29 Nov 2003 17:04:47 -0000 1.18
***************
*** 78,81 ****
--- 78,86 ----
void SomeParametersMethod(string p1, string p2);
}
+
+ interface WithMethodThatReturnsAMock
+ {
+ Mock ReturnIt();
+ }
#endregion
***************
*** 136,139 ****
--- 141,152 ----
}
+ [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()
{
|
|
From: <sm...@us...> - 2003-11-28 17:31:26
|
Update of /cvsroot/nmock/nmock/src/NMock
In directory sc8-pr-cvs1:/tmp/cvs-serv24047/src/NMock
Modified Files:
MethodSignature.cs DynamicMock.cs
Log Message:
Refactoring, moved some method lookup behaviour into MethodSignature
Index: MethodSignature.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/src/NMock/MethodSignature.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** MethodSignature.cs 8 Aug 2003 00:05:03 -0000 1.1
--- MethodSignature.cs 28 Nov 2003 17:31:22 -0000 1.2
***************
*** 1,3 ****
--- 1,7 ----
using System;
+ using System.Reflection;
+
+ using NMock.Constraints;
+ using NMock.Dynamic;
namespace NMock
***************
*** 20,23 ****
--- 24,84 ----
return typeName + "." + methodName + "()";
}
+
+ public bool HasAConstraintArgument
+ {
+ get
+ {
+ foreach(Type argType in argumentTypes)
+ {
+ if(typeof(IConstraint).IsAssignableFrom(argType))
+ return true;
+ }
+ return false;
+ }
+ }
+
+ 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 && parameters[pi].GetType().IsAssignableFrom(argumentType) )
+ return false;
+ }
+ return true;
+ }
}
}
Index: DynamicMock.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/src/NMock/DynamicMock.cs,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** DynamicMock.cs 16 Oct 2003 13:49:13 -0000 1.17
--- DynamicMock.cs 28 Nov 2003 17:31:22 -0000 1.18
***************
*** 7,166 ****
namespace NMock
{
! public class DynamicMock : Mock
! {
! private object mockInstance;
! private Type type;
! private IList ignoredMethodNames;
! private readonly Type superclassIfTypeIsInterface;
! public DynamicMock(Type type) : this(type, "Mock" + type.Name) {}
! 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;
! }
! public override object MockInstance
! {
! get
! {
! if (mockInstance == null)
! {
! mockInstance = CreateClassGenerator().Generate();
! }
! return mockInstance;
! }
! }
! /// <summary>
! /// Don't generate mock method for suppied methodName.
! /// </summary>
! public virtual void Ignore(string methodName)
! {
! ignoredMethodNames.Add(methodName);
! }
! 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);
! checkMethodIsValidIfNoConstraints(signature);
! checkReturnTypeIsValid(methodName, returnVal);
! base.SetupResult(methodName, returnVal, argTypes);
! }
! void checkReturnTypeIsValid(string methodName, object returnVal)
! {
! if (returnVal == null)
! {
! return;
! }
! MethodInfo method = type.GetMethod(methodName, ClassGenerator.ALL_INSTANCE_METHODS);
! Type realReturnVal;
! if(method == null)
! {
! realReturnVal = type.GetProperty(methodName, ClassGenerator.ALL_INSTANCE_METHODS).PropertyType;
! }
! else
! {
! realReturnVal = method.ReturnType;
! }
! if (realReturnVal == null)
! {
! realReturnVal = type.GetProperty(methodName, ClassGenerator.ALL_INSTANCE_METHODS).PropertyType;
! }
! if(realReturnVal != returnVal.GetType())
! {
! throw new ArgumentException(String.Format("method <{0}> returns a {1}", methodName, realReturnVal));
! }
! }
! void checkMethodIsValidIfNoConstraints(MethodSignature signature)
! {
! foreach(Type argType in signature.argumentTypes)
! {
! if(typeof(IConstraint).IsAssignableFrom(argType)) return;
! }
!
! Type[] allTypes = new InterfaceLister().List(type);
!
! //find method with argumentTypes
! foreach (Type t in allTypes)
! {
! PropertyInfo property = t.GetProperty(signature.methodName, ClassGenerator.ALL_INSTANCE_METHODS);
! if (property != null)
! {
! return;
! }
!
! MethodInfo method = FindBestMatchingMethod(t, signature);
! if(method != null)
! {
! if(!method.IsVirtual)
! {
! throw new ArgumentException(String.Format("method <{0}> is not virtual", signature.methodName));
! }
! return;
! }
!
! }
!
! throw new MissingMethodException(String.Format("method <{0}> not defined", signature.methodName));
! }
!
!
! public MethodInfo FindBestMatchingMethod(Type t, MethodSignature signature)
! {
! //find any methods that match all non-null argument types
! MethodInfo[] methods = t.GetMethods(ClassGenerator.ALL_INSTANCE_METHODS);
! foreach (MethodInfo m in methods)
! {
! if (!m.Name.Equals(signature.methodName))
! continue;
!
! ParameterInfo[] parameters = m.GetParameters();
! if ( parameters.Length!=signature.argumentTypes.Length )
! continue;
!
! bool match = true;
! for ( int pi=0; pi<parameters.Length; pi++ )
! {
! if ( signature.argumentTypes[pi]==null )
! continue;
!
! if ( parameters[pi].GetType().IsAssignableFrom(signature.argumentTypes[pi]) )
! {
! match = false;
! break;
! }
! }
! if (match)
! {
! return m;
! }
! }
! return null;
! }
! }
}
--- 7,111 ----
namespace NMock
{
! public class DynamicMock : Mock
! {
! private object mockInstance;
! private Type type;
! private IList ignoredMethodNames;
! private readonly Type superclassIfTypeIsInterface;
! public DynamicMock(Type type) : this(type, "Mock" + type.Name) {}
! 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;
! }
! public override object MockInstance
! {
! get
! {
! if (mockInstance == null)
! {
! mockInstance = CreateClassGenerator().Generate();
! }
! return mockInstance;
! }
! }
! /// <summary>
! /// Don't generate mock method for suppied methodName.
! /// </summary>
! public virtual void Ignore(string methodName)
! {
! ignoredMethodNames.Add(methodName);
! }
! 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);
! checkMethodIsValidIfNoConstraints(signature);
! checkReturnTypeIsValid(methodName, returnVal);
! base.SetupResult(methodName, returnVal, argTypes);
! }
! void checkReturnTypeIsValid(string methodName, object returnVal)
! {
! if (returnVal == null)
! {
! return;
! }
! MethodInfo method = type.GetMethod(methodName, ClassGenerator.ALL_INSTANCE_METHODS);
! Type realReturnVal;
! if(method == null)
! {
! realReturnVal = type.GetProperty(methodName, ClassGenerator.ALL_INSTANCE_METHODS).PropertyType;
! }
! else
! {
! realReturnVal = method.ReturnType;
! }
! if (realReturnVal == null)
! {
! realReturnVal = type.GetProperty(methodName, ClassGenerator.ALL_INSTANCE_METHODS).PropertyType;
! }
! if(realReturnVal != returnVal.GetType())
! {
! throw new ArgumentException(String.Format("method <{0}> returns a {1}", methodName, realReturnVal));
! }
! }
! void checkMethodIsValidIfNoConstraints(MethodSignature signature)
! {
! if (signature.HasAConstraintArgument)
! return;
! foreach (Type t in new InterfaceLister().List(type))
! {
! if (signature.IsPropertyOn(t) || signature.HasMatchingMethodIn(t))
! return;
! }
! throw new MissingMethodException(String.Format("method <{0}> not defined", signature.methodName));
! }
! }
}
|