private NoSuchObjectDefinitionException Serialize(NoSuchObjectDefinitionException inputException) { NoSuchObjectDefinitionException deserializedException = null; string tempDir = Environment.GetEnvironmentVariable("TEMP"); string tempFilename = tempDir + @"\foo.dat"; FileInfo file = new FileInfo(tempFilename); try { Stream outstream = file.OpenWrite(); new BinaryFormatter().Serialize(outstream, inputException); outstream.Flush(); outstream.Close(); Stream instream = file.OpenRead(); deserializedException = new BinaryFormatter().Deserialize(instream) as NoSuchObjectDefinitionException; instream.Close(); } finally { try { file.Delete(); } catch { } } return(deserializedException); }
public void SerializesObjectTypeFieldCorrectly() { NoSuchObjectDefinitionException ex = new NoSuchObjectDefinitionException(NotFoundObjectDefinitionType, null); NoSuchObjectDefinitionException deserializedException = Serialize(ex); Assert.IsNotNull(deserializedException); Assert.AreEqual(NotFoundObjectDefinitionType, deserializedException.ObjectType, "'ObjectType' property was not serialized correctly."); }
public void SerializesObjectNameFieldCorrectly() { NoSuchObjectDefinitionException ex = new NoSuchObjectDefinitionException(NotFoundObjectDefinitionName, "Cannot dynamically build object key..."); NoSuchObjectDefinitionException deserializedException = Serialize(ex); Assert.IsNotNull(deserializedException); Assert.AreEqual(NotFoundObjectDefinitionName, deserializedException.ObjectName, "'ObjectName' property was not serialized correctly."); }