public void GetObjectData_SerializationInfo_Null () { SmtpException se = new SmtpException (); try { se.GetObjectData ((SerializationInfo) null, new StreamingContext ()); Assert.Fail ("#1"); } catch (ArgumentNullException ex) { Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2"); Assert.IsNull (ex.InnerException, "#3"); Assert.IsNotNull (ex.Message, "#4"); Assert.AreEqual ("info", ex.ParamName, "#5"); } }
public void GetObjectData () { string msg = "MESSAGE"; Exception inner = new ArgumentException ("whatever"); SerializationInfo si; SmtpException se; se = new SmtpException (msg, inner); si = new SerializationInfo (typeof (SmtpException), new FormatterConverter ()); se.GetObjectData (si, new StreamingContext ()); Assert.AreEqual (12, si.MemberCount, "#A1"); Assert.AreEqual (typeof (SmtpException).FullName, si.GetString ("ClassName"), "#A2"); Assert.IsNull (si.GetValue ("Data", typeof (IDictionary)), "#A3"); Assert.AreSame (msg, si.GetString ("Message"), "#A4"); Assert.AreSame (inner, si.GetValue ("InnerException", typeof (Exception)), "#A5"); Assert.AreSame (se.HelpLink, si.GetString ("HelpURL"), "#A6"); Assert.IsNull (si.GetString ("StackTraceString"), "#A7"); Assert.IsNull (si.GetString ("RemoteStackTraceString"), "#A8"); Assert.AreEqual (0, si.GetInt32 ("RemoteStackIndex"), "#A9"); Assert.AreEqual (-2146233088, si.GetInt32 ("HResult"), "#A10"); Assert.IsNull (si.GetString ("Source"), "#A11"); Assert.IsNull (si.GetString ("ExceptionMethod"), "#A12"); Assert.AreEqual ((int) SmtpStatusCode.GeneralFailure, si.GetInt32 ("Status"), "#A13"); // attempt initialization of lazy init members Assert.IsNotNull (se.Data); Assert.IsNull (se.Source); Assert.IsNull (se.StackTrace); si = new SerializationInfo (typeof (SmtpException), new FormatterConverter ()); se.GetObjectData (si, new StreamingContext ()); Assert.AreEqual (12, si.MemberCount, "#B1"); Assert.AreEqual (typeof (SmtpException).FullName, si.GetString ("ClassName"), "#B2"); Assert.AreSame (se.Data, si.GetValue ("Data", typeof (IDictionary)), "#B3"); Assert.AreSame (msg, si.GetString ("Message"), "#B4"); Assert.AreSame (inner, si.GetValue ("InnerException", typeof (Exception)), "#B5"); Assert.AreSame (se.HelpLink, si.GetString ("HelpURL"), "#B6"); Assert.IsNull (si.GetString ("StackTraceString"), "#B7"); Assert.IsNull (si.GetString ("RemoteStackTraceString"), "#B8"); Assert.AreEqual (0, si.GetInt32 ("RemoteStackIndex"), "#B9"); Assert.AreEqual (-2146233088, si.GetInt32 ("HResult"), "#B10"); Assert.IsNull (si.GetString ("Source"), "#B11"); Assert.IsNull (si.GetString ("ExceptionMethod"), "#B12"); Assert.AreEqual ((int) SmtpStatusCode.GeneralFailure, si.GetInt32 ("Status"), "#B13"); try { throw new SmtpException (msg, inner); } catch (SmtpException ex) { si = new SerializationInfo (typeof (SmtpException), new FormatterConverter ()); ex.GetObjectData (si, new StreamingContext ()); Assert.AreEqual (12, si.MemberCount, "#C1"); Assert.AreEqual (typeof (SmtpException).FullName, si.GetString ("ClassName"), "#C2"); Assert.IsNull (si.GetValue ("Data", typeof (IDictionary)), "#C3"); Assert.AreSame (msg, si.GetString ("Message"), "#C4"); Assert.AreSame (inner, si.GetValue ("InnerException", typeof (Exception)), "#C5"); Assert.AreSame (se.HelpLink, si.GetString ("HelpURL"), "#C6"); Assert.IsNotNull (si.GetString ("StackTraceString"), "#C7"); Assert.IsNull (si.GetString ("RemoteStackTraceString"), "#C8"); Assert.AreEqual (0, si.GetInt32 ("RemoteStackIndex"), "#C9"); Assert.AreEqual (-2146233088, si.GetInt32 ("HResult"), "#C10"); Assert.IsNotNull (si.GetString ("Source"), "#C11"); //Assert.IsNotNull (si.GetString ("ExceptionMethod"), "#C12"); Assert.AreEqual ((int) SmtpStatusCode.GeneralFailure, si.GetInt32 ("Status"), "#C13"); } try { throw new SmtpException (msg, inner); } catch (SmtpException ex) { // force initialization of lazy init members Assert.IsNotNull (ex.Data); Assert.IsNotNull (ex.StackTrace); si = new SerializationInfo (typeof (SmtpException), new FormatterConverter ()); ex.GetObjectData (si, new StreamingContext ()); Assert.AreEqual (12, si.MemberCount, "#D1"); Assert.AreEqual (typeof (SmtpException).FullName, si.GetString ("ClassName"), "#D2"); Assert.AreSame (ex.Data, si.GetValue ("Data", typeof (IDictionary)), "#D3"); Assert.AreSame (msg, si.GetString ("Message"), "#D4"); Assert.AreSame (inner, si.GetValue ("InnerException", typeof (Exception)), "#D5"); Assert.AreSame (ex.HelpLink, si.GetString ("HelpURL"), "#D6"); Assert.IsNotNull (si.GetString ("StackTraceString"), "#D7"); Assert.IsNull (si.GetString ("RemoteStackTraceString"), "#D8"); Assert.AreEqual (0, si.GetInt32 ("RemoteStackIndex"), "#D9"); Assert.AreEqual (-2146233088, si.GetInt32 ("HResult"), "#D10"); Assert.AreEqual (typeof (SmtpExceptionTest).Assembly.GetName ().Name, si.GetString ("Source"), "#D11"); //Assert.IsNotNull (si.GetString ("ExceptionMethod"), "#D12"); Assert.AreEqual ((int) SmtpStatusCode.GeneralFailure, si.GetInt32 ("Status"), "#D13"); } }