CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

ServerDisconnects No Unhandeled Exception

122 Views
Copy Code Show/Hide Line Numbers
[Test]
public void Idle_ServerDisconnects_NoUnhandeledException()
{
    bool unhandeledException = false;
    UnhandledExceptionEventHandler fail = (sender, args) => unhandeledException = true;
 
    try
    {
        AppDomain.CurrentDomain.UnhandledException += fail;
        WithLogin(client =>
                      {
                          client.SelectInbox();
                          new Thread(() =>
                                         {
                                             ServerException ex = Assert.Throws<ServerException>(() => client.Idle());
                                             StringAssert.Contains("An existing connection was forcibly closed by the remote host.", ex.Message);
                                         }).Start();
                          new HMailServer().Stop();
                      });
    }
    finally
    {
        AppDomain.CurrentDomain.UnhandledException -= fail;
        new HMailServer().Start();
    }
    Assert.IsFalse(unhandeledException);
}
by lesnikowski
  August 31, 2010 @ 7:40am

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate