// Tests timeout on an event that is never set. private static bool RunManualResetEventSlimTest3_ConstructorTests() { bool passed = true; TestHarness.TestLog("* RunManualResetEventSlimTest3_ConstructorTests()"); passed &= TestHarnessAssert.EnsureExceptionThrown( () => new ManualResetEventSlim(false, 2048), //max value is 2047. typeof(ArgumentOutOfRangeException), "The max value for spin count is 2047. An ArgumentException should be thrown."); passed &= TestHarnessAssert.EnsureExceptionThrown( () => new ManualResetEventSlim(false, -1), typeof(ArgumentOutOfRangeException), "The min value for spin count is 0. An ArgumentException should be thrown."); return(passed); }
private static bool RunThreadLocalTest5_Dispose() { TestHarness.TestLog("* RunThreadLocalTest5_Dispose()"); ThreadLocal <string> tl = new ThreadLocal <string>(() => "dispose test"); string value = tl.Value; tl.Dispose(); if (!TestHarnessAssert.EnsureExceptionThrown(() => { string tmp = tl.Value; }, typeof(ObjectDisposedException), "The Value property of the disposed ThreadLocal object should throw ODE")) { return(false); } if (!TestHarnessAssert.EnsureExceptionThrown(() => { bool tmp = tl.IsValueCreated; }, typeof(ObjectDisposedException), "The IsValueCreated property of the disposed ThreadLocal object should throw ODE")) { return(false); } if (!TestHarnessAssert.EnsureExceptionThrown(() => { string tmp = tl.ToString(); }, typeof(ObjectDisposedException), "The ToString method of the disposed ThreadLocal object should throw ODE")) { return(false); } // test recycling the combination index; tl = new ThreadLocal <string>(() => null); if (tl.IsValueCreated) { TestHarness.TestLog("* Filed, reusing the same index kept the old value and didn't use the new value."); return(false); } if (tl.Value != null) { TestHarness.TestLog("* Filed, reusing the same index kept the old value and didn't use the new value."); return(false); } return(true); }
private static bool RunManualResetEventSlimTest5_Dispose() { bool passed = true; TestHarness.TestLog("* RunManualResetEventSlimTest5_Dispose()"); ManualResetEventSlim mres = new ManualResetEventSlim(false); mres.Dispose(); passed &= TestHarnessAssert.EnsureExceptionThrown( () => mres.Reset(), typeof(ObjectDisposedException), "The object has been disposed, should throw ObjectDisposedException."); passed &= TestHarnessAssert.EnsureExceptionThrown( () => mres.Wait(0), typeof(ObjectDisposedException), "The object has been disposed, should throw ObjectDisposedException."); passed &= TestHarnessAssert.EnsureExceptionThrown( () => { WaitHandle handle = mres.WaitHandle; }, typeof(ObjectDisposedException), "The object has been disposed, should throw ObjectDisposedException."); mres = new ManualResetEventSlim(false);; ManualResetEvent mre = (ManualResetEvent)mres.WaitHandle; mres.Dispose(); passed &= TestHarnessAssert.EnsureExceptionThrown( () => mre.WaitOne(0, false), typeof(ObjectDisposedException), "The underlying event object has been disposed, should throw ObjectDisposedException."); return(passed); }
private static bool Bug599487_MoveNextAfterQueryOpeningFailsIsIllegal() { TestHarness.TestLog("* MoveNextAfterQueryOpeningFailsIsIllegal()"); bool success = true; var query = Enumerable.Range(0, 10) .AsParallel() .Select <int, int>(x => { throw new ApplicationException(); }) .OrderBy(x => x); IEnumerator <int> enumerator = query.GetEnumerator(); //moveNext will cause queryOpening to fail (no element generated) success &= TestHarnessAssert.EnsureExceptionThrown( () => enumerator.MoveNext(), typeof(AggregateException), "An AggregateException(containing ApplicationException) should be thrown"); //moveNext after queryOpening failed success &= TestHarnessAssert.EnsureExceptionThrown( () => enumerator.MoveNext(), typeof(InvalidOperationException), "A second attempt to enumerate should cause InvalidOperationException"); return(success); }
/// <summary>Tests for the Value factory throws an exception.</summary> /// <returns>True if the tests succeeds, false otherwise.</returns> private static bool RunLazyTest9_Exceptions() { TestHarness.TestLog("* RunLazyTest9_Exceptions()"); int counter = m_exceptionCounter; Lazy <string> l = new Lazy <string>(() => { m_exceptionCounter++; int zero = 0; int x = 1 / zero; return(""); }, true); string s; if (!TestHarnessAssert.EnsureExceptionThrown(() => s = l.Value, typeof(DivideByZeroException), "Expected DivideByZeroException")) { TestHarness.TestLog("failed"); return(false); } if (!TestHarnessAssert.EnsureExceptionThrown(() => s = l.Value, typeof(DivideByZeroException), "Expected DivideByZeroException")) { TestHarness.TestLog("failed"); return(false); } if (!TestHarnessAssert.AreEqual <int>(counter + 1, m_exceptionCounter, "value factory has been called twise and it should be called only once.")) { TestHarness.TestLog("failed"); return(false); } if (l.IsValueCreated) { TestHarness.TestLog("failed* IsValueCreated should return false."); return(false); } return(true); }