|
From: Jim A. <JA...@th...> - 2004-12-16 18:55:31
|
<FONT face=3D"Default Sans Serif,Verdana,Arial,Helvetica,sans-serif" size=
=3D2><DIV>Yes, there is a bug, but I'm a little confused by your test. =
; NMock will only verify the value of a parameter, not the actual refe=
rence. In your test, you assign the variable 'refStringArr' to null, =
then pass it to your mock. This will fail (assuming the bug has been =
fixed) because NMock is expecting the original value assigned to strArr, wh=
ich was {"a", "b"}. Even if NMock could have compared the reference r=
efStringArr with strArr, however, it still would have failed, because they =
are different references. So I'm not sure what you expect the behavio=
r to be.</DIV><DIV> </DIV><DIV>Anyway, I have fixed the bug, and it sh=
ould make its way onto SourceForge in the next day or so.</DIV><DIV> <=
/DIV><DIV>Jim</DIV><DIV> </DIV><DIV>ThoughtWorks<BR></DIV><FONT color=
=3D#990099>-----nmo...@li... wrote: -----<BR><=
BR></FONT><blockquote style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGI=
N-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">To: nmock-g=
en...@li...<BR>From: "web11p1" <in...@ro...><BR>S=
ent by: nmo...@li...<BR>Date: 12/16/2004 05:19=
PM<BR>Subject: [Nmock-general] Problem with 'ref string[]' parameter<BR><BR=
><FONT face=3Dmonospace size=3D2>Hello<BR><BR>I've got a problem with creat=
ing a DynmicMock for a Interface with<BR>a Function that takes a 'ref strin=
g[] foo' parameter. (see example below).<BR><BR>The function is defined as =
<BR>bool ByRefFunction(ref string[] strArray);<BR><BR>the problem is that t=
he ExpectAndReturn function of nMock didn't find the <BR>method signature (=
so it tells in the exception).<BR><BR>Since some messages on the list archi=
ves showed a equal problem, i've got<BR>the latest nmock.dll from <A href=
=3D"http://ccnetlive.thoughtworks.com/NMock-builds/131/" target=3Dblank >h=
ttp://ccnetlive.thoughtworks.com/NMock-builds/131/</A><BR>(was mentoind in =
a list message).<BR><BR>Please find a example below!<BR><BR>The ByRefFuncti=
on is suposed to cange to given array to { "a", "b" }, so the<BR>nunit test=
s should conform.<BR><BR>Did i miss something or is it a bug?<BR><BR>kind r=
egards<BR>Dominik<BR><BR><BR><BR><BR><BR>using System;<BR>using NUnit.Frame=
work;<BR>using NMock;<BR>namespace Test<BR>{<BR><SPAN style=3D"VISIBILITY: =
hidden"> </SPAN>public interface IFoo<BR><SPAN style=
=3D"VISIBILITY: hidden"> </SPAN>{<BR><SPAN style=3D"=
VISIBILITY: hidden"> </SPAN><SPAN style=3D"VISIBILIT=
Y: hidden"> </SPAN>bool ByRefFunction(ref string[] s=
trArray);<BR><SPAN style=3D"VISIBILITY: hidden"> </S=
PAN><SPAN style=3D"VISIBILITY: hidden"> </SPAN>bool =
Function(string[] strArray);<BR><SPAN style=3D"VISIBILITY: hidden"> &n=
bsp; </SPAN>}<BR><BR><SPAN style=3D"VISIBILITY: hidden"> &n=
bsp; </SPAN>[TestFixture]<BR><SPAN style=3D"VISIBILITY: hidden">=
</SPAN>public class FooTester<BR><SPAN style=3D"VIS=
IBILITY: hidden"> </SPAN>{<BR><BR><SPAN style=3D"VIS=
IBILITY: hidden"> </SPAN><SPAN style=3D"VISIBILITY: =
hidden"> </SPAN>[Test]<BR><SPAN style=3D"VISIBILITY:=
hidden"> </SPAN><SPAN style=3D"VISIBILITY: hidden">=
</SPAN>public void TestFunction()<BR><SPAN style=3D=
"VISIBILITY: hidden"> </SPAN><SPAN style=3D"VISIBILI=
TY: hidden"> </SPAN>{<BR><SPAN style=3D"VISIBILITY: =
hidden"> </SPAN><SPAN style=3D"VISIBILITY: hidden">&=
nbsp; </SPAN><SPAN style=3D"VISIBILITY: hidden"> &nbs=
p; </SPAN>string[] strArr =3D new string[] {"a", "b"};<BR><SPAN =
style=3D"VISIBILITY: hidden"> </SPAN><SPAN style=3D"=
VISIBILITY: hidden"> </SPAN><SPAN style=3D"VISIBILIT=
Y: hidden"> </SPAN>Mock fooMock =3D new DynamicMock(=
typeof(IFoo));<BR><BR><SPAN style=3D"VISIBILITY: hidden"> =
</SPAN><SPAN style=3D"VISIBILITY: hidden"> </S=
PAN><SPAN style=3D"VISIBILITY: hidden"> </SPAN>fooMo=
ck.ExpectAndReturn("Function", true, (object)strArr);<BR><BR><SPAN style=3D=
"VISIBILITY: hidden"> </SPAN><SPAN style=3D"VISIBILI=
TY: hidden"> </SPAN><SPAN style=3D"VISIBILITY: hidde=
n"> </SPAN>IFoo foo =3D (IFoo)fooMock.MockInstance=
;<BR><SPAN style=3D"VISIBILITY: hidden"> </SPAN><SPA=
N style=3D"VISIBILITY: hidden"> </SPAN><SPAN style=
=3D"VISIBILITY: hidden"> </SPAN>bool bar =3D foo.F=
unction(strArr);<BR><BR><SPAN style=3D"VISIBILITY: hidden"> &nbs=
p; </SPAN><SPAN style=3D"VISIBILITY: hidden"> <=
/SPAN><SPAN style=3D"VISIBILITY: hidden"> </SPAN>Ass=
ert.IsTrue(bar);<BR><BR><SPAN style=3D"VISIBILITY: hidden"> &nbs=
p; </SPAN><SPAN style=3D"VISIBILITY: hidden"> <=
/SPAN><SPAN style=3D"VISIBILITY: hidden"> </SPAN>foo=
Mock.Verify();<BR><SPAN style=3D"VISIBILITY: hidden"> &nbs=
p;</SPAN><SPAN style=3D"VISIBILITY: hidden"> </SPAN>=
}<BR><BR><SPAN style=3D"VISIBILITY: hidden"> </SPAN>=
<SPAN style=3D"VISIBILITY: hidden"> </SPAN>[Test]<BR=
><SPAN style=3D"VISIBILITY: hidden"> </SPAN><SPAN st=
yle=3D"VISIBILITY: hidden"> </SPAN>public void TestB=
yRefFunction()<BR><SPAN style=3D"VISIBILITY: hidden"> &nbs=
p;</SPAN><SPAN style=3D"VISIBILITY: hidden"> </SPAN>=
{<BR><SPAN style=3D"VISIBILITY: hidden"> </SPAN><SPA=
N style=3D"VISIBILITY: hidden"> </SPAN><SPAN style=
=3D"VISIBILITY: hidden"> </SPAN>string[] strArr =3D =
new string[] { "a", "b"};<BR><SPAN style=3D"VISIBILITY: hidden">  =
; </SPAN><SPAN style=3D"VISIBILITY: hidden"> &n=
bsp;</SPAN><SPAN style=3D"VISIBILITY: hidden"> </SPA=
N>Mock fooMock =3D new DynamicMock(typeof(IFoo));<BR><BR><SPAN style=3D"VIS=
IBILITY: hidden"> </SPAN><SPAN style=3D"VISIBILITY: =
hidden"> </SPAN><SPAN style=3D"VISIBILITY: hidden">&=
nbsp; </SPAN>fooMock.ExpectAndReturn("ByRefFunction", true=
, (object)strArr);<BR><BR><SPAN style=3D"VISIBILITY: hidden"> &n=
bsp; </SPAN><SPAN style=3D"VISIBILITY: hidden">  =
;</SPAN><SPAN style=3D"VISIBILITY: hidden"> </SPAN>s=
tring[] refStringArr =3D null;<BR><BR><SPAN style=3D"VISIBILITY: hidden">=
</SPAN><SPAN style=3D"VISIBILITY: hidden"> &nb=
sp; </SPAN><SPAN style=3D"VISIBILITY: hidden"> =
</SPAN>IFoo foo =3D (IFoo)fooMock.MockInstance;<BR><SPAN style=3D"V=
ISIBILITY: hidden"> </SPAN><SPAN style=3D"VISIBILITY=
: hidden"> </SPAN><SPAN style=3D"VISIBILITY: hidden"=
> </SPAN>bool bar =3D foo.ByRefFunction(ref refStr=
ingArr);<BR><BR><SPAN style=3D"VISIBILITY: hidden"> =
</SPAN><SPAN style=3D"VISIBILITY: hidden"> </SPAN><S=
PAN style=3D"VISIBILITY: hidden"> </SPAN>Assert.AreE=
qual("a", refStringArr[0]);<BR><SPAN style=3D"VISIBILITY: hidden"> &nb=
sp; </SPAN><SPAN style=3D"VISIBILITY: hidden"> =
</SPAN><SPAN style=3D"VISIBILITY: hidden"> </S=
PAN>Assert.AreEqual("b", refStringArr[1]);<BR><SPAN style=3D"VISIBILITY: hi=
dden"> </SPAN><SPAN style=3D"VISIBILITY: hidden">&nb=
sp; </SPAN><SPAN style=3D"VISIBILITY: hidden"> =
</SPAN>Assert.IsTrue(bar);<BR><BR><SPAN style=3D"VISIBILITY: hi=
dden"> </SPAN><SPAN style=3D"VISIBILITY: hidden">&nb=
sp; </SPAN><SPAN style=3D"VISIBILITY: hidden"> =
</SPAN>fooMock.Verify();<BR><SPAN style=3D"VISIBILITY: hidden">=
</SPAN><SPAN style=3D"VISIBILITY: hidden"> &nb=
sp; </SPAN>}<BR><BR><SPAN style=3D"VISIBILITY: hidden"> &nb=
sp; </SPAN>}<BR><BR>}<BR><BR><BR><BR>---------------------------=
----------------------------<BR>SF email is sponsored by - The IT Product G=
uide<BR>Read honest & candid reviews on hundreds of IT Products from re=
al users.<BR>Discover which products truly live up to the hype. Start readi=
ng now. <BR><A href=3D"http://productguide.itmanagersjournal.com/" target=
=3Dblank >http://productguide.itmanagersjournal.com/</A><BR>=5F=5F=5F=5F=
=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=
=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F<BR>Nmock-general mai=
ling list<BR>Nmo...@li...<BR><A href=3D"https://list=
s.sourceforge.net/lists/listinfo/nmock-general" target=3Dblank >https://lis=
ts.sourceforge.net/lists/listinfo/nmock-general</A><BR></FONT></blockquote>=
<br></FONT>=
|