Using Serialization with Mock Objects

1,992 views
Skip to first unread message

OAbrivard

unread,
Sep 20, 2006, 4:00:47 AM9/20/06
to Rhino.Mocks
Hi,

I tried to use .Net binary serialization and my program raised the
following exception (in french) :
System.Runtime.Serialization.SerializationException: Le type
'Rhino.Mocks.Impl.RhinoInterceptor' dans l'assembly 'Rhino.Mocks,
Version=2.9.1.10183, Culture=neutral, PublicKeyToken=0b3305902db7183f'
n'est pas marqué comme sérialisable

It seems that 'Rhino.Mocks.Impl.RhinoInterceptor' isn't serializable.
Do you have any idea on how I can overcome this problem ?

A similar problem arises when I try to use a JSON serializer
(Newtonsoft.Json). Here the program raises the following exception :
Newtonsoft.Json.JsonSerializationException: Self referencing loop

It seems that there's a loop in objects references (maybe between the
dynamic proxy and the proxied object). Can you confirm that point ?

Anyway, thanks for your work, it's really a helpful tool !

Best regards,
Olivier

Ayende Rahien

unread,
Sep 20, 2006, 6:38:28 PM9/20/06
to Rhino...@googlegroups.com
Get the code, put [Serializable] on the interceptor, and see if it works :-)
Send me a patch if it does.

OAbrivard

unread,
Sep 26, 2006, 9:46:17 AM9/26/06
to Rhino.Mocks
Hi,

I tried to put [Serializable] on the interceptor and finally ended up
putting [Serializable] on half the project's class.
Once finished, I had no problem using .Net binary serialisation.
But it did not solve my XML serialization or JSon serialization issues.
I still have the same problem with JSon serializer and I get the
following error with XML serializer :
"System.InvalidOperationException: Impossible de sérialiser
CProxyTypeNServMon_CommonCollectionOccurrenceCommon_Rhino_Mocks_InterfacesIMockedObject_System_Runtime_SerializationISerializable2,
car il n'a pas de constructeur sans paramètres" which can be
translated to "no defaut (parameterless) constructor".

I guess I'll stick with actual limitations and not use mock objects
with serialization.

Best regards,
Olivier

Ayende Rahien

unread,
Sep 26, 2006, 11:13:31 AM9/26/06
to Rhino...@googlegroups.com
That is probably for the best.
Why are you trying to do mock object serialization.

> > Version= 2.9.1.10183, Culture=neutral, PublicKeyToken=0b3305902db7183f'

Jeff Brown

unread,
Sep 26, 2006, 5:30:40 PM9/26/06
to Rhino...@googlegroups.com
I think the serialization problem for Xml can be remedied with judicious application of [XmlIgnore] attributes to hide any internal Rhino Mocks data structures.  Atlas's JSON serializer also respects XmlIgnore, perhaps NewtonSoft's does too.  I'm not familiar with it.
 
Of course Xml and JSON deserialization will never work since it depends on being able to create an instance of the type, which doesn't make much sense for mocks because they have a dynamic type anyways.
 
Jeff.


From: Rhino...@googlegroups.com [mailto:Rhino...@googlegroups.com] On Behalf Of Ayende Rahien
Sent: Tuesday, September 26, 2006 8:14 AM
To: Rhino...@googlegroups.com
Subject: Re: Using Serialization with Mock Objects

OAbrivard

unread,
Sep 27, 2006, 4:48:47 AM9/27/06
to Rhino.Mocks
Hi,


Thanks for your answers.

Ayende, I serialize mocks objects when I write a unit test for my "File
Store" class. This class basically writes the serialized state of a
set of business objects (binary serialization, XML serialization and
JSon serialization). To test my "FileStore.Store()" method, I choosed
to use a mocked business object. I'm not sure if it is a good idea
anyway.

Jeff, I'm not sure that [XmlIgnore] will help in my case since once of
the problem is the lack of parameterless constructor in mock objects. I
think [XmlIgnore] will help with circular references problem.

As i'm not inclined to modify deeply a framework that I don't control,
I prefer forget about serialization of my mock objets. Especially when
it's not an unavoidable feature.

Best regards,
Olivier

Ayende Rahien

unread,
Sep 27, 2006, 2:25:11 PM9/27/06
to Rhino...@googlegroups.com
Serializing mock objects doesn't make sense, really.
You can't get a mock object back out of the deserialization process.
Binary serialization is of some value, because it aids in remoting
scenarios, but that is about it, I think.

> -----Original Message-----
> From: Rhino...@googlegroups.com [mailto:Rhino...@googlegroups.com]
> On Behalf Of OAbrivard
> Sent: Wednesday, September 27, 2006 10:49 AM
> To: Rhino.Mocks
> Subject: Re: Using Serialization with Mock Objects
>
>

João Paulo Duque Vieira

unread,
Sep 28, 2006, 7:26:33 AM9/28/06
to Rhino...@googlegroups.com
Hello. :)

Is there a way to set that a certain call is not expected (using Dynamic ofcourse)?

Best regards.

Ayende Rahien

unread,
Sep 28, 2006, 7:23:43 AM9/28/06
to Rhino...@googlegroups.com
LastCall.Repeat.Never()
Reply all
Reply to author
Forward
0 new messages