Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TestContext.cs « Xamarin.PropertyEditing.Tests - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0f4f01829723efa6d352f173ad7673bd2752e052 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.Runtime.ExceptionServices;
using System.Threading;

namespace Xamarin.PropertyEditing.Tests
{
	internal class TestContext
		: SynchronizationContext
	{
		public override void Post (SendOrPostCallback d, object state)
		{
			try {
				d (state);
			} catch (Exception ex) {
				var info = ExceptionDispatchInfo.Capture (ex);
				this.exceptions.Add (info);

				// If we throw exceptions here we will crash out the test runner process when
				// running tests from VSM.
				//
				// As part of our `Teardown` method we manually rethrow the exceptions so they
				// propagate to NUnit and cause the test to fail.

				//throw;
			}
		}

		public override void Send (SendOrPostCallback d, object state)
		{
			try {
				d (state);
			} catch (Exception ex) {
				var info = ExceptionDispatchInfo.Capture (ex);
				this.exceptions.Add (info);

				// If we throw exceptions here we will crash out the test runner process when
				// running tests from VSM.
				//
				// As part of our `Teardown` method we manually rethrow the exceptions so they
				// propagate to NUnit and cause the test to fail.

				//throw;
			}
		}

		public void ThrowPendingExceptions ()
		{
			if (this.exceptions.Count > 0)
				this.exceptions[0].Throw();
		}

		private readonly List<ExceptionDispatchInfo> exceptions = new List<ExceptionDispatchInfo> ();
	}
}