|
From: Joe R. <joe...@gm...> - 2006-02-22 17:47:14
|
I've done all of the due diligence I could think of before asking this question. It seems obvious and I found some references to it on a JMock forum but nothing with regards to NMock. I did most of my searching with regards to ArrayLists as I figured there would be more posts about .NET 1.x than 2.x. So anyway, the question is: I have an interface that exposes a property of type List<T>. I've worked my way through the NMock2 source and discovered that when calling the setter, an NMock2.Matchers.EqualMatcher is used to determine if the value passed to the setter matches the expectation. EqualMatcher checks if it's an array by using "is Array" (it is not technically an array) so then it does an equals. At this point it's basically comparing the addresses that each reference is pointing two. The addresses are different so it fails. I need a more complex check than this for this collection. I thought I could create a custom Matcher but it appears that the ArgumentsMatcher is called before ExtraMatchersMatch. Is there a way to override which ArgumentsMatcher is used? Again, I apologize if this question has been covered before. I searched Google and this mailing list. I made my way through the source code. I don't really know of a good source of NMock2 documentation (I have that cheat sheet PDF which is nice) besides the source code and tests. Thanks for any assistance to an NMock2 newcomer, -joe |
|
From: Joe R. <joe...@gm...> - 2006-02-22 18:28:37
|
I believe you can disregard this question. Since sending the email I've discovered that I can pass a Matcher to the "To" method in addition to a value. This seems to accomplish what I'm after. I was trying to do .To (value).Matching (myMatcher) which I now know to be incorrect. If there's a better way to do this, I'd still like to hear any advice. Thanks! -joe On 2/22/06, Joe Ross <joe...@gm...> wrote: > I've done all of the due diligence I could think of before asking this > question. It seems obvious and I found some references to it on a > JMock forum but nothing with regards to NMock. I did most of my > searching with regards to ArrayLists as I figured there would be more > posts about .NET 1.x than 2.x. > > So anyway, the question is: I have an interface that exposes a > property of type List<T>. I've worked my way through the NMock2 > source and discovered that when calling the setter, an > NMock2.Matchers.EqualMatcher is used to determine if the value passed > to the setter matches the expectation. EqualMatcher checks if it's an > array by using "is Array" (it is not technically an array) so then it > does an equals. At this point it's basically comparing the addresses > that each reference is pointing two. The addresses are different so > it fails. > > I need a more complex check than this for this collection. I thought > I could create a custom Matcher but it appears that the > ArgumentsMatcher is called before ExtraMatchersMatch. Is there a way > to override which ArgumentsMatcher is used? > > Again, I apologize if this question has been covered before. I > searched Google and this mailing list. I made my way through the > source code. I don't really know of a good source of NMock2 > documentation (I have that cheat sheet PDF which is nice) besides the > source code and tests. > > Thanks for any assistance to an NMock2 newcomer, > -joe > |
|
From: Nat P. <nat...@gm...> - 2006-02-23 12:52:43
|
You need to pass a custom matcher to the With method, since you want
to match on a single argument.
E.g. create a EqualListsMatcher that checks if two lists are equal.=20
Write a convenient factory function to create it, then use it in an
expectation like:
On(mock).Method("Foo").With(ListEqualTo(someList)).Will(Return.Value(10=
));
--Nat.
On 2/22/06, Joe Ross <joe...@gm...> wrote:
> I believe you can disregard this question. Since sending the email
> I've discovered that I can pass a Matcher to the "To" method in
> addition to a value. This seems to accomplish what I'm after. I was
> trying to do .To (value).Matching (myMatcher) which I now know to be
> incorrect.
>
> If there's a better way to do this, I'd still like to hear any advice.
>
> Thanks!
> -joe
>
> On 2/22/06, Joe Ross <joe...@gm...> wrote:
> > I've done all of the due diligence I could think of before asking this
> > question. It seems obvious and I found some references to it on a
> > JMock forum but nothing with regards to NMock. I did most of my
> > searching with regards to ArrayLists as I figured there would be more
> > posts about .NET 1.x than 2.x.
> >
> > So anyway, the question is: I have an interface that exposes a
> > property of type List<T>. I've worked my way through the NMock2
> > source and discovered that when calling the setter, an
> > NMock2.Matchers.EqualMatcher is used to determine if the value passed
> > to the setter matches the expectation. EqualMatcher checks if it's an
> > array by using "is Array" (it is not technically an array) so then it
> > does an equals. At this point it's basically comparing the addresses
> > that each reference is pointing two. The addresses are different so
> > it fails.
> >
> > I need a more complex check than this for this collection. I thought
> > I could create a custom Matcher but it appears that the
> > ArgumentsMatcher is called before ExtraMatchersMatch. Is there a way
> > to override which ArgumentsMatcher is used?
> >
> > Again, I apologize if this question has been covered before. I
> > searched Google and this mailing list. I made my way through the
> > source code. I don't really know of a good source of NMock2
> > documentation (I have that cheat sheet PDF which is nice) besides the
> > source code and tests.
> >
> > Thanks for any assistance to an NMock2 newcomer,
> > -joe
> >
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log fi=
les
> for problems? Stop! Download the new AJAX search engine that makes
> searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
> http://sel.as-us.falkag.net/sel?cmdlnk&kid=103432&bid#0486&dat=121642
> _______________________________________________
> NMock-two-dev mailing list
> NMo...@li...
> https://lists.sourceforge.net/lists/listinfo/nmock-two-dev
>
|
|
From: Mike M. <mik...@gm...> - 2006-03-01 16:54:40
|
On 2/23/06, Nat Pryce <nat...@gm...> wrote:
>
> You need to pass a custom matcher to the With method, since you want
> to match on a single argument.
>
> E.g. create a EqualListsMatcher that checks if two lists are equal.
> Write a convenient factory function to create it, then use it in an
> expectation like:
>
> On(mock).Method("Foo").With(ListEqualTo(someList)).Will(Return.Value
> (10));
>
We had the same problem on our projects and I created a ComparableList<T>
class that overrode equals and did the right thing, but the matcher looks
much more like it's the right thing to do.
Is this something we should implement directly in NMock2 instead of
requiring folks to implement their own ListEqualTo() matcher?
Cheers,
Mike.
|
|
From: Joe R. <joe...@gm...> - 2006-03-01 19:14:59
|
Mike-
I'm not involved in the development of NMock2 obviously, but the
question I raise is whether or not everyone's definition of two lists
being equal is the same. My definition for my purpose was that each
list contained the same items in the same order. Someone else might
only care about the same items being in each list but not necessarily
the same order. I realize there is also a SortedList<T> in .NET 2.0,
but I want to use List<T> and add the objects in the correct order
based on business logic
Are there other complexities to two lists being equal that I'm not
considering? My implementation was is simple as a null check, a count
check, then an object comparison across the lists.
-joe
On 3/1/06, Mike Mason <mik...@gm...> wrote:
> On 2/23/06, Nat Pryce <nat...@gm...> wrote:
> > You need to pass a custom matcher to the With method, since you want
> > to match on a single argument.
> >
> > E.g. create a EqualListsMatcher that checks if two lists are equal.
> > Write a convenient factory function to create it, then use it in an
> > expectation like:
> >
> >
> On(mock).Method("Foo").With(ListEqualTo(someList)).Will(Return.Value(10))=
;
> >
>
> We had the same problem on our projects and I created a ComparableList<T>
> class that overrode equals and did the right thing, but the matcher looks
> much more like it's the right thing to do.
>
> Is this something we should implement directly in NMock2 instead of
> requiring folks to implement their own ListEqualTo() matcher?
>
> Cheers,
> Mike.
>
|
|
From: Mike M. <mik...@gm...> - 2006-03-01 22:19:32
|
On 3/1/06, Joe Ross <joe...@gm...> wrote: > > I'm not involved in the development of NMock2 obviously, but the > question I raise is whether or not everyone's definition of two lists > being equal is the same. My definition for my purpose was that each > list contained the same items in the same order. Someone else might > only care about the same items being in each list but not necessarily > the same order. I realize there is also a SortedList<T> in .NET 2.0, > but I want to use List<T> and add the objects in the correct order > based on business logic Well to me, if I'm using a List I would say I did care about order of items= . If I didn't care, I'd use a Set or a Bag. Problem is neither of those are built-in types for .NET (which is an entirely different rant ;-) ). I was just thinking that "check lists are not null, same size, and each object in turn .Equals() the corresponding object in the other list" is a piece of code most people are gonna end up writing, so maybe we should provide it. Cheers, Mike. |
|
From: Joe P. <joe...@gm...> - 2006-03-02 02:04:40
|
i agree with mike on the definition of two lists being equal. as i imagine this is the most common definition, i'd find it convenient if = a built-in ListMatcher (perhaps like the one mike has in the tutorial) was th= e default matcher used by nmock2 when comparing two lists. and in the scenario where order doesn't matter, bring on the custom matcher. - joe On 3/1/06, Mike Mason <mik...@gm...> wrote: > > On 3/1/06, Joe Ross <joe...@gm...> wrote: > > > I'm not involved in the development of NMock2 obviously, but the > > question I raise is whether or not everyone's definition of two lists > > being equal is the same. My definition for my purpose was that each > > list contained the same items in the same order. Someone else might > > only care about the same items being in each list but not necessarily > > the same order. I realize there is also a SortedList<T> in .NET 2.0, > > but I want to use List<T> and add the objects in the correct order > > based on business logic > > > Well to me, if I'm using a List I would say I did care about order of > items. If I didn't care, I'd use a Set or a Bag. Problem is neither of th= ose > are built-in types for .NET (which is an entirely different rant ;-) ). > > I was just thinking that "check lists are not null, same size, and each > object in turn .Equals() the corresponding object in the other list" is a > piece of code most people are gonna end up writing, so maybe we should > provide it. > > Cheers, > Mike. > |
|
From: Nat P. <nat...@gm...> - 2006-03-02 11:16:50
|
I agree that this should be part of the standard set of constraints.=20 Perhaps there should be constraints for dictionaries too. I merged a patch into jMock recently that contributed useful constraints for collections and dictionaries, so you can specify that a parameter is an element of a list, or is a key of a dictionary, etc. Very useful for keeping tests flexible. --Nat. On 3/2/06, Joe Poon <joe...@gm...> wrote: > i agree with mike on the definition of two lists being equal. > > as i imagine this is the most common definition, i'd find it convenient i= f a > built-in ListMatcher (perhaps like the one mike has in the tutorial) was = the > default matcher used by nmock2 when comparing two lists. and in the > scenario where order doesn't matter, bring on the custom matcher. > > - joe > > > On 3/1/06, Mike Mason <mik...@gm...> wrote: > > > > On 3/1/06, Joe Ross <joe...@gm... > wrote: > > > > > > > > > I'm not involved in the development of NMock2 obviously, but the > > > question I raise is whether or not everyone's definition of two lists > > > being equal is the same. My definition for my purpose was that each > > > list contained the same items in the same order. Someone else might > > > only care about the same items being in each list but not necessarily > > > the same order. I realize there is also a SortedList<T> in .NET 2.0, > > > but I want to use List<T> and add the objects in the correct order > > > based on business logic > > > > > > > > Well to me, if I'm using a List I would say I did care about order of > items. If I didn't care, I'd use a Set or a Bag. Problem is neither of th= ose > are built-in types for .NET (which is an entirely different rant ;-) ). > > > > I was just thinking that "check lists are not null, same size, and each > object in turn .Equals() the corresponding object in the other list" is a > piece of code most people are gonna end up writing, so maybe we should > provide it. > > Cheers, > > > > Mike. > > > > |
|
From: Mike M. <mik...@gm...> - 2006-03-02 17:01:52
|
I've started logging feature requests in the SF tracker to try and get a handle on all the stuff we think we'd like to do for a 2.0 release. http://sourceforge.net/tracker/?group_id=3D66591&atid=3D515020 God, that SF tracker is awful. *sigh* Cheers, Mike. |
|
From: Owen R. <exo...@gm...> - 2006-03-03 05:55:26
|
On 02/03/06, Mike Mason <mik...@gm...> wrote: > I've started logging feature requests in the SF tracker to try and get a > handle on all the stuff we think we'd like to do for a 2.0 release. > > http://sourceforge.net/tracker/?group_id=3D66591&atid=3D515020 > > God, that SF tracker is awful. *sigh* we should be able to set up an extra project for you on the public tw jira, if you would prefer. o. -- Owen Rogers | http://dotnetjunkies.com/weblog/exortech | CruiseControl.NET - http://ccnet.thoughtworks.com |