private void RunTests() { this.Title = "Unit Tests for " + new AssemblyName(this.GetType().Assembly.FullName).Name; if (TestRunner == null) { try { OnTestRunStarted(); } catch (Exception e) { MethodInfo method = GetType().GetMethod("OnTestRunStarted", BindingFlags.NonPublic | BindingFlags.Instance); this.m_headerOutcome = new MethodOutcome(method); this.m_headerOutcome.SetOutcome(e); this.m_headerView.SetHtml(TestClassResultActivity.GetHTMLDescriptionFor(this.m_headerOutcome)); this.m_headerView.Visibility = ViewStates.Visible; this.ResultBar.SetColorByState(TestState.Failed); Toast.MakeText(this, "OnTestRunStarted() notification failed.", ToastLength.Long).Show(); return; } this.m_headerView.Visibility = ViewStates.Gone; this.ResultBar.SetColorByState(TestState.Running); AsyncTestRunner.Run(this, this.CreateTestRunner, this.OnTestRunFinished); } }
public void InvokingAsyncVoidWhichThrowsIsObservedAndRethrown() { var methodInfo = typeof(WhenStepScannerFactoryAsyncMethods).GetMethod("AsyncTaskMethod", BindingFlags.Instance | BindingFlags.NonPublic); var stepAction = StepActionFactory.GetStepAction(methodInfo, new object[] { new SomeScenario() }); Should.Throw <ArgumentException>(() => AsyncTestRunner.Run(() => stepAction(this))); }
[Ignore] // https://github.com/nventive/Uno.Core/issues/48 public async Task TestUnlockReleaseNextSynchronously() { Console.WriteLine($"Running on thread {Thread.CurrentThread.ManagedThreadId}"); var sut = new FastAsyncLock(); var thread1ExitingThread = -1; var thread2LockingTask = default(Task <IDisposable>); var thread1 = new AsyncTestRunner(Thread1); var thread2 = new AsyncTestRunner(); thread2.Run(Thread2); using (thread1) using (thread2) { // Acquire the lock on thread 1 await thread1.AdvanceTo(1); // Wait for the thread 2 to be stuck to acquire the lock var thread2Locking = thread2.AdvanceTo(1); while (thread2LockingTask == null) { await Task.Yield(); } // Make sure that the thread 2 is really awaiting the thread2LockingTask before requesting thread1 to continue await Task.Delay(100); Assert.AreEqual(TaskStatus.WaitingForActivation, thread2LockingTask.Status); // Relase the thread 1 and make sure that the thread 2 is able to acquire the lock var thread1Release = thread1.AdvanceTo(2); await thread2Locking; } async Task Thread1(CancellationToken ct, AsyncTestRunner r) { Console.WriteLine($"Thread 1: {Thread.CurrentThread.ManagedThreadId}"); var ctx = AsyncTestContext.Current; using (await sut.LockAsync(ct)) { Console.WriteLine($"Acquired lock for Thread1 on thread: {Thread.CurrentThread.ManagedThreadId}"); ctx.Validate(); await Task.Yield(); r.Sync(position: 1); thread1ExitingThread = Thread.CurrentThread.ManagedThreadId; Console.WriteLine($"Releasing lock from Thread1 on thread: {Thread.CurrentThread.ManagedThreadId}"); } Console.WriteLine($"Released lock from Thread1 on thread: {Thread.CurrentThread.ManagedThreadId}"); // This must have run synchronously when lock got released (disposed). Assert.AreEqual(TaskStatus.RanToCompletion, thread2LockingTask.Status); r.Sync(position: 2); } async Task Thread2(CancellationToken ct, AsyncTestRunner r) { Console.WriteLine($"Thread 2: {Thread.CurrentThread.ManagedThreadId}"); var ctx = AsyncTestContext.Current; thread2LockingTask = sut.LockAsync(ct); // Validate that we are running on thread 2 Assert.AreEqual(thread2.ThreadId, Thread.CurrentThread.ManagedThreadId); Console.WriteLine("Thread 2 is waiting for lock"); using (await thread2LockingTask) { Console.WriteLine($"Acquired lock for Thread2 on thread: {Thread.CurrentThread.ManagedThreadId}"); // Here we should run on the thread 1 since the lock is released synchronously from thread 1 Assert.AreEqual(thread1ExitingThread, Thread.CurrentThread.ManagedThreadId); // But we should have kept the ExecutionContext from the thread 2 ctx.Validate(); await Task.Yield(); r.Sync(position: 1); Console.WriteLine($"Releasing lock from Thread2 on thread: {Thread.CurrentThread.ManagedThreadId}"); } Console.WriteLine($"Released lock from Thread2 on thread: {Thread.CurrentThread.ManagedThreadId}"); r.Sync(position: 2); } }
public void CallingAsyncVoidWhichThrowsIsObservedAndRethrown() { var stepAction = StepActionFactory.GetStepAction <SomeScenario>(s => AsyncVoidMethod(s)); Should.Throw <ArgumentException>(() => AsyncTestRunner.Run(() => stepAction(new SomeScenario()))); }
public void CallingAsyncTaskWhichThrowsIsObservedAndRethrown() { var stepAction = StepActionFactory.GetStepAction <SomeScenario>(o => AsyncTaskMethod(o)); Assert.Throws <ArgumentException>(() => AsyncTestRunner.Run(() => stepAction(new SomeScenario()))); }