public void TryDoOnObjectWithExceptionImplicitArrayFails() { try { var source = new { Property = (string)null }; var result = source.TryDo(s => s.Property.ToString(), typeof(OutOfMemoryException), typeof(ArgumentException)); Assert.Fail("Exception must be thrown."); } catch (NullReferenceException) { } }
public void TryDoOnObjectWithException() { var source = new { Property = (string)null }; var r = String.Empty; var result = source.TryDo(s => r = s.Property.ToString()); Assert.AreEqual(String.Empty, r); Assert.AreEqual(source, result.Item1); Assert.IsInstanceOfType(result.Item2, typeof(NullReferenceException)); }
public void TryDoOnObjectWithExceptionImplicitArray() { var source = new { Property = (string)null }; var result = source.TryDo(s => s.Property.ToString(), typeof(NullReferenceException), typeof(ArgumentException)); Assert.AreEqual(source, result.Item1); Assert.IsInstanceOfType(result.Item2, typeof(NullReferenceException)); }
public void TryDoOnObjectWithNullNoException() { var source = new { Property = "Some value" }; source = null; var r = String.Empty; var result = source.TryDo(s => r = s.Property); Assert.AreEqual(String.Empty, r); Assert.AreEqual(null, result.Item1); Assert.AreEqual(null, result.Item2); }