Fwd: How to test an Exception marked with SerializableAttribute
"Simon Garratt" <[email protected]>
| Newsgroups | gmane.comp.windows.dotnet.nunit.user |
|---|---|
| Message-ID | <[email protected]> |
Apologies for the earlier, rather lame "Please help me mail". I'd been up
since 3.20am after the darling daughter let go a startled "Daddy!" Needless
to say, she was back asleep 30 seconds later and I was still awake come 5.20
!
Serialization is not an area I'm particularly familiar with. I've come up
with a plan and would appreciate feedback. I'm looking to avoid a 'Fragile
Test' so please do chip in with any comments. Basically, I'm serializing a
new instance of the exception into a MemoryStream, resetting the position
and then immediately deserializing it. Then I perform the Asserts on the
deserialized object.
[Test]
public void BaseException_Serialization()
{
BaseException baseException = new BaseException("Test message", new
ArgumentNullException("NullParam"));
BaseException deserBaseEx;
BinaryFormatter binaryFormatter = new BinaryFormatter();
using (MemoryStream memoryStream = new MemoryStream())
{
binaryFormatter.Serialize(memoryStream, baseException);
baseException = null;
memoryStream.Position = 0;
deserBaseEx = (BaseException)binaryFormatter.Deserialize(memoryStream);
}
Assert.That(deserBaseEx.Message, Is.EqualTo("Test message"));
Assert.That(deserBaseEx.InnerException, Is.InstanceOfType(typeof(
ArgumentNullException)));
Assert.That(((ArgumentNullException)deserBaseEx.InnerException).ParamName,
Is.EqualTo("NullParam"));
Assert.That(deserBaseEx.ComputerName, Is.EqualTo(System.Environment
.MachineName));
}
---------- Forwarded message ----------
I'm building a base exception class and I want to test it but I can't think
how. The bit I'm having trouble with is the fourth required constructor -
the serializable one. What's the best way to serialize and deserialize it
within a test?
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Nunit-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nunit-users