Re: Is.Serializable
"Simone Busoli" <[email protected]> Thu, 14 Aug 2008 20:15:13 +0200
| Newsgroups | gmane.comp.windows.dotnet.nunit.user |
|---|---|
| Message-ID | <[email protected]> |
> > > To check just for the attribute or the interface > Is.Serializable() OR > Is.Serializable > > To check by trying to do it > Is.Serializable(formatter) OR > Is.Serializable.Using(formatter) > I think that making Is.Serializable check for the presence of the attribute on the class might be misleading, because its presence doesn't mean it's serializable, and its absence doesn't mean it isn't. I think that Is.Serializable should be used to check that an object is really serializable, together with its references. That is, Is.Serializable should come in two flavours, one that checks if it is serializable in binary format, and another for xml. I'll come to this later. About checking for the presence of the attribute, as you mentioned in a comment to Fabio's feature request, I think it could be generalized with Has.Attribute<> or Has.Attribute(Type). So, given that the presence of an attribute is checked with a generic Has.Attribute, the way I would tackle the true ability of an object graph to serialize is either using Is.XmlSerializable and Is.BinarySerializable or something equivalent. I don't get how you could pass in an instance of a formatter; I guess you proposed it because you might want to be able to use the assertion for other types of formatters not built into the .net fx s well, but then how would you call their methods? Via reflection? > > The aternatives above are between using a method and using a property. It > would be > cool to use the property for te first example and the method for the > second, but > that's not possible. > > Most of our syntactic elements use a property format when there is no > argument. > When an element has an optional argument, then we are forced to use method > syntax, which may look a bit odd. For example, we have to use Is.Ordered() > rather than Is.Ordered - That example should be familiar to you :-) > > I lean toward "Using" or "With" or some other keyword. > > What do folks think? > I'm fine with anything you choose. I don't think it's so important if it's a property or a method, just let's try to be consistent :) > > Charlie > > ------------------------------ > *From:* Simone Busoli [mailto:[email protected]] > *Sent:* Thursday, August 14, 2008 12:16 AM > *To:* Charlie Poole > *Subject:* Re: [Nunit-users] Is.Serializable > > Hmm, I just realized that what I'm doing is not enough for the object to > be serializable. I noticed that the prerequisites for it to be serializable > are quite different according to whether you want to serialize it to xml or > to binary. For example, the binary serialization doesn't require classes to > be public, while xml does. xml serialization doesn't require the > serializable attribute, while the binary does. So I'm wondering if it could > be the case to split the assertion in IsBinarySerializable and > IsXmlSerializable, or check that it is both binary and xml serializable in > the same assertion. Thoughts? > > On Thu, Aug 14, 2008 at 2:02 AM, Charlie Poole < > [email protected]> wrote: > >> Hi Simone, >> >> This looks good to me. Would you like to synch up and fix it so it works >> with the latest code? My major >> changes to Constraint, ConstraintBuilder, etc. are done and it would give >> you a good way for you >> to get familiar with those changes. Once it's done, you can either send me >> a new patch or - if >> you would like - I'll make you a commiter so you can add it yourself. If >> you agree, I'll explain more >> to you about review of code etc. >> >> Charlie >> >> ------------------------------ >> *From:* [email protected] [mailto: >> [email protected]] *On Behalf Of *Simone Busoli >> *Sent:* Monday, August 11, 2008 7:11 AM >> *To:* [email protected] >> *Subject:* [Nunit-users] Is.Serializable >> >> With regards to: >> http://sourceforge.net/tracker/index.php?func=detail&aid=2028517&group_id=10749&atid=360749 >> >> I have implemented a SerializableConstraint accessible via >> Is.Serializable. The match is true if serialization to and deserialization >> from a memory stream via a BinaryFormatter both succeed and the deserialized >> object is not null. Otherwise the match returns false. >> >> > ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Nunit-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nunit-users