public static void IsTrue(bool condition, string format, params object[] args) { if (!condition) { Thrower.Throw(format, args); } }
public void ThrowTest() { var exceptions = new List <Exception>(); try { Thrower.Throw("Inner {0}", true); } catch (Exception ex) { exceptions.Add(ex); } try { Thrower.Throw(new Exception("Inner"), "Outer {0}", true); } catch (Exception ex) { exceptions.Add(ex); } Assert.AreEqual(2, exceptions.Count); Assert.AreEqual("Inner True", exceptions[0].Message); Assert.AreEqual("Outer True", exceptions[1].Message); Assert.NotNull(exceptions[1].InnerException); Assert.AreEqual("Inner", exceptions[1].InnerException.Message); }
public static TcpClient ConnectWithTimeout(string ip, int port, int timeout) { var client = new TcpClient(); var result = client.BeginConnect(ip, port, null, null); if (!result.AsyncWaitHandle.WaitOne(timeout, true)) { Disposer.Dispose(client); Thrower.Throw("Timeout connecting to {0}:{1}", ip, port); } client.EndConnect(result); return(client); }