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

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan McGovern <alan@xamarin.com>2018-09-26 13:53:41 +0300
committerDominique Louis <dominique@Dominiques-MacBook-Pro-2.local>2018-10-09 18:39:12 +0300
commite0d21548fa0349b37431ea7fe652b38d009f66b6 (patch)
treec0854824917b93d76fca4b3880727374e8855fb0 /Xamarin.PropertyEditing.Tests
parent73bbf32dbc2021262fb8c56de325886010fe2d0e (diff)
[Tests] Ensure async void exceptions propagate correctly
This should ensure that exceptions thrown inside async void methods do get rethrown as part of the Teardown of a given test. This removes the eventhandlers on AppDomain.UnhandledException and also removes the second SyncContext implementation which did not capture/propagate the exceptions.
Diffstat (limited to 'Xamarin.PropertyEditing.Tests')
-rw-r--r--Xamarin.PropertyEditing.Tests/AddValueConverterViewModelTests.cs6
-rw-r--r--Xamarin.PropertyEditing.Tests/AsyncSynchronizationContext.cs17
-rw-r--r--Xamarin.PropertyEditing.Tests/CollectionPropertyViewModelTests.cs6
-rw-r--r--Xamarin.PropertyEditing.Tests/CreateBindingViewModelTests.cs22
-rw-r--r--Xamarin.PropertyEditing.Tests/ObjectPropertyViewModelTests.cs6
-rw-r--r--Xamarin.PropertyEditing.Tests/PanelViewModelTests.cs7
-rw-r--r--Xamarin.PropertyEditing.Tests/PropertiesViewModelTests.cs22
-rw-r--r--Xamarin.PropertyEditing.Tests/PropertyViewModelTests.cs6
-rw-r--r--Xamarin.PropertyEditing.Tests/Xamarin.PropertyEditing.Tests.csproj1
9 files changed, 22 insertions, 71 deletions
diff --git a/Xamarin.PropertyEditing.Tests/AddValueConverterViewModelTests.cs b/Xamarin.PropertyEditing.Tests/AddValueConverterViewModelTests.cs
index c323cc2..e107c19 100644
--- a/Xamarin.PropertyEditing.Tests/AddValueConverterViewModelTests.cs
+++ b/Xamarin.PropertyEditing.Tests/AddValueConverterViewModelTests.cs
@@ -14,15 +14,15 @@ namespace Xamarin.PropertyEditing.Tests
[SetUp]
public void Setup ()
{
- this.syncContext = new AsyncSynchronizationContext ();
+ this.syncContext = new TestContext ();
SynchronizationContext.SetSynchronizationContext (this.syncContext);
}
[TearDown]
public void TearDown ()
{
- this.syncContext.WaitForPendingOperationsToComplete ();
SynchronizationContext.SetSynchronizationContext (null);
+ this.syncContext.ThrowPendingExceptions ();
}
[Test]
@@ -75,6 +75,6 @@ namespace Xamarin.PropertyEditing.Tests
Assert.That (vm.ConverterName, Is.EqualTo (type.Name));
}
- private AsyncSynchronizationContext syncContext;
+ private TestContext syncContext;
}
}
diff --git a/Xamarin.PropertyEditing.Tests/AsyncSynchronizationContext.cs b/Xamarin.PropertyEditing.Tests/AsyncSynchronizationContext.cs
deleted file mode 100644
index 34a7086..0000000
--- a/Xamarin.PropertyEditing.Tests/AsyncSynchronizationContext.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-using System.Threading;
-
-namespace Xamarin.PropertyEditing.Tests
-{
- internal class AsyncSynchronizationContext
- : SynchronizationContext
- {
- public override void Post (SendOrPostCallback d, object state)
- {
- d (state);
- }
-
- public void WaitForPendingOperationsToComplete ()
- {
- }
- }
-} \ No newline at end of file
diff --git a/Xamarin.PropertyEditing.Tests/CollectionPropertyViewModelTests.cs b/Xamarin.PropertyEditing.Tests/CollectionPropertyViewModelTests.cs
index 7f87448..daaa32d 100644
--- a/Xamarin.PropertyEditing.Tests/CollectionPropertyViewModelTests.cs
+++ b/Xamarin.PropertyEditing.Tests/CollectionPropertyViewModelTests.cs
@@ -16,20 +16,20 @@ namespace Xamarin.PropertyEditing.Tests
[TestFixture]
internal class CollectionPropertyViewModelTests
{
- private AsyncSynchronizationContext syncContext;
+ private TestContext syncContext;
[SetUp]
public void Setup ()
{
- this.syncContext = new AsyncSynchronizationContext ();
+ this.syncContext = new TestContext ();
SynchronizationContext.SetSynchronizationContext (this.syncContext);
}
[TearDown]
public void TearDown ()
{
- this.syncContext.WaitForPendingOperationsToComplete ();
SynchronizationContext.SetSynchronizationContext (null);
+ this.syncContext.ThrowPendingExceptions ();
}
[Test]
diff --git a/Xamarin.PropertyEditing.Tests/CreateBindingViewModelTests.cs b/Xamarin.PropertyEditing.Tests/CreateBindingViewModelTests.cs
index 2cf707b..0c3b16b 100644
--- a/Xamarin.PropertyEditing.Tests/CreateBindingViewModelTests.cs
+++ b/Xamarin.PropertyEditing.Tests/CreateBindingViewModelTests.cs
@@ -22,31 +22,15 @@ namespace Xamarin.PropertyEditing.Tests
[SetUp]
public void Setup ()
{
- AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
- this.syncContext = new AsyncSynchronizationContext ();
+ this.syncContext = new TestContext ();
SynchronizationContext.SetSynchronizationContext (this.syncContext);
}
- private Exception unhandled;
-
- private void CurrentDomainOnUnhandledException (object sender, UnhandledExceptionEventArgs e)
- {
- this.unhandled = e.ExceptionObject as Exception;
- }
-
[TearDown]
public void TearDown ()
{
- this.syncContext.WaitForPendingOperationsToComplete ();
SynchronizationContext.SetSynchronizationContext (null);
-
- AppDomain.CurrentDomain.UnhandledException -= CurrentDomainOnUnhandledException;
-
- if (this.unhandled != null) {
- var ex = this.unhandled;
- this.unhandled = null;
- Assert.Fail ("Unhandled exception: {0}", ex);
- }
+ this.syncContext.ThrowPendingExceptions ();
}
[Test]
@@ -630,7 +614,7 @@ namespace Xamarin.PropertyEditing.Tests
vm.BindingProperties.Cast<PropertyViewModel> ().Select (pvm => pvm.Property));
}
- private AsyncSynchronizationContext syncContext;
+ private TestContext syncContext;
private static readonly ResourceSource[] DefaultResourceSources = new[] { MockResourceProvider.SystemResourcesSource, MockResourceProvider.ApplicationResourcesSource };
private Mock<IPropertyInfo> GetBasicProperty (string name = "propertyName")
diff --git a/Xamarin.PropertyEditing.Tests/ObjectPropertyViewModelTests.cs b/Xamarin.PropertyEditing.Tests/ObjectPropertyViewModelTests.cs
index 426cdd7..193bc09 100644
--- a/Xamarin.PropertyEditing.Tests/ObjectPropertyViewModelTests.cs
+++ b/Xamarin.PropertyEditing.Tests/ObjectPropertyViewModelTests.cs
@@ -17,15 +17,15 @@ namespace Xamarin.PropertyEditing.Tests
[SetUp]
public void Setup ()
{
- this.syncContext = new AsyncSynchronizationContext();
+ this.syncContext = new TestContext ();
SynchronizationContext.SetSynchronizationContext (this.syncContext);
}
[TearDown]
public void TearDown ()
{
- this.syncContext.WaitForPendingOperationsToComplete ();
SynchronizationContext.SetSynchronizationContext (null);
+ syncContext.ThrowPendingExceptions ();
}
[Test]
@@ -255,7 +255,7 @@ namespace Xamarin.PropertyEditing.Tests
Assert.That (vm.ValueType, Is.Null);
}
- private AsyncSynchronizationContext syncContext;
+ private TestContext syncContext;
private Mock<IEditorProvider> CreateProviderMock (object value, IObjectEditor editor)
{
diff --git a/Xamarin.PropertyEditing.Tests/PanelViewModelTests.cs b/Xamarin.PropertyEditing.Tests/PanelViewModelTests.cs
index 7b51e8f..723d86f 100644
--- a/Xamarin.PropertyEditing.Tests/PanelViewModelTests.cs
+++ b/Xamarin.PropertyEditing.Tests/PanelViewModelTests.cs
@@ -17,13 +17,6 @@ namespace Xamarin.PropertyEditing.Tests
internal class PanelViewModelTests
: PropertiesViewModelTests<PanelViewModel>
{
- [SetUp]
- public override void Setup ()
- {
- base.Setup ();
- SynchronizationContext.SetSynchronizationContext (this.context = new TestContext ());
- }
-
[Test]
[Description ("We must be sure that if the selected objects list changes while the provider is still retrieving that we end up with the right result")]
public async Task InteruptedEditorRetrievalResolvesCorrectlyItemAdded ()
diff --git a/Xamarin.PropertyEditing.Tests/PropertiesViewModelTests.cs b/Xamarin.PropertyEditing.Tests/PropertiesViewModelTests.cs
index a7e98a9..6560aa9 100644
--- a/Xamarin.PropertyEditing.Tests/PropertiesViewModelTests.cs
+++ b/Xamarin.PropertyEditing.Tests/PropertiesViewModelTests.cs
@@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Reflection;
+using System.Threading;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
@@ -35,28 +36,19 @@ namespace Xamarin.PropertyEditing.Tests
}
}
- private Exception unhandled;
+ private TestContext syncContext;
[SetUp]
- public virtual void Setup ()
+ public void Setup ()
{
- AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
+ this.syncContext = new TestContext ();
+ SynchronizationContext.SetSynchronizationContext (this.syncContext);
}
[TearDown]
public void TearDown ()
{
- AppDomain.CurrentDomain.UnhandledException -= CurrentDomainOnUnhandledException;
-
- if (this.unhandled != null) {
- var ex = this.unhandled;
- this.unhandled = null;
- Assert.Fail ("Unhandled exception: {0}", ex);
- }
- }
-
- private void CurrentDomainOnUnhandledException (object sender, UnhandledExceptionEventArgs e)
- {
- this.unhandled = e.ExceptionObject as Exception;
+ SynchronizationContext.SetSynchronizationContext (null);
+ this.syncContext.ThrowPendingExceptions ();
}
[Test]
diff --git a/Xamarin.PropertyEditing.Tests/PropertyViewModelTests.cs b/Xamarin.PropertyEditing.Tests/PropertyViewModelTests.cs
index bb719e8..2c49a80 100644
--- a/Xamarin.PropertyEditing.Tests/PropertyViewModelTests.cs
+++ b/Xamarin.PropertyEditing.Tests/PropertyViewModelTests.cs
@@ -24,15 +24,15 @@ namespace Xamarin.PropertyEditing.Tests
[SetUp]
public void Setup ()
{
- this.syncContext = new AsyncSynchronizationContext();
+ this.syncContext = new TestContext ();
SynchronizationContext.SetSynchronizationContext (this.syncContext);
}
[TearDown]
public void TearDown ()
{
- this.syncContext.WaitForPendingOperationsToComplete ();
SynchronizationContext.SetSynchronizationContext (null);
+ this.syncContext.ThrowPendingExceptions ();
}
[Test]
@@ -1467,6 +1467,6 @@ namespace Xamarin.PropertyEditing.Tests
}
private readonly Random rand = new Random (42);
- private AsyncSynchronizationContext syncContext;
+ private TestContext syncContext;
}
} \ No newline at end of file
diff --git a/Xamarin.PropertyEditing.Tests/Xamarin.PropertyEditing.Tests.csproj b/Xamarin.PropertyEditing.Tests/Xamarin.PropertyEditing.Tests.csproj
index c5419cd..1e0355f 100644
--- a/Xamarin.PropertyEditing.Tests/Xamarin.PropertyEditing.Tests.csproj
+++ b/Xamarin.PropertyEditing.Tests/Xamarin.PropertyEditing.Tests.csproj
@@ -58,7 +58,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AddValueConverterViewModelTests.cs" />
- <Compile Include="AsyncSynchronizationContext.cs" />
<Compile Include="AsyncValueTests.cs" />
<Compile Include="AsyncWorkQueueTests.cs" />
<Compile Include="BoolViewModelTests.cs" />