|
From: Owen R. <OR...@th...> - 2004-07-27 04:10:34
|
hi nick,
this is where constraints come in. constraints allow you to set up fuzzy
validation on the parameters that are passed into and verified by the
mock.
for example, if you really don't card about what gets passed to
DoSomething, you could use:
- interfaceMock.ExpectAndReturn("DoSomething", true, new IsAnything());
if you want to verify it is at least instantiated, you could use:
- interfaceMock.ExpectAndReturn("DoSomething", true, new NotNull());
or you could verify the type of someObject with:
- interfaceMock.ExpectAndReturn("DoSomething", true, new IsTypeOf());
if you really want to verify that SomeObject is passed and instantiated
correctly, you could override the Equals() method on someObject and then
write something like this:
Test
{
SomeObject expectedSomeObject = new SomeObject(the same params
that are used in the object under test);
interfaceMock.ExpectAndReturn("DoSomething", true,
expectedSomeObject);
}
if you want to be explicit using constraints, you could use this instead:
interfaceMock.ExpectAndReturn("DoSomething", true,
IsEqual(expectedSomeObject));
check out the other constraints in the constraints namespace for more
examples.
cheers,
owen.
---
R. Owen Rogers
ThoughtWorks Technologies (India) Pvt Ltd.
ThoughtWorks - Deliver with passion!
ThoughtWorks is always looking for talented people who are passionate
about technology. To find out more about a career at ThoughtWorks go to
http://www.thoughtworks.com/career/.
"Nick Robinson" <nic...@fr...>
Sent by: nmo...@li...
27/07/2004 03:39
To: <nmo...@li...>
cc: (bcc: Owen Rogers/Canada/ThoughtWorks)
Subject: [Nmock-general] ExpectAndReturn too strict
I have a situation, where I want to return a value from a method call of
an
interface, but between the outer object and the interface, a creation
occurs
which I am not aware of which is passed into the interface:
outer object.Dosomething(some params)
{
SomeObject someObject = new SomeObject(some of the
params);
if(_interface.DoSomething(someObject))
{
...
}
}
I want _interface to return false, but I obviously dont have access to the
someObject instance in my test:
Test
{
interfaceMock.ExpectAndReturn("DoSomething", true, ???);
}
I seem to have the option of introducing an interfaced factory or a stub
that replaces the mock. Do people just ignore this by creating one of
these
items and moving on, or do you have a different technique to get around
this
situation?
Cheers,
nick.robinson
site : www.fromconcept.co.uk
blog : www.fromconcept.co.uk/weblog.aspx
draco : www.sourceforge.net/projects/draconet
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
_______________________________________________
Nmock-general mailing list
Nmo...@li...
https://lists.sourceforge.net/lists/listinfo/nmock-general
|