diff options
author | Eric Maupin <ermaup@microsoft.com> | 2018-08-23 22:01:22 +0300 |
---|---|---|
committer | Eric Maupin <ermaup@microsoft.com> | 2018-08-23 22:01:24 +0300 |
commit | 96044ed481d24cb834dd27cb3ee489b5df9e94ab (patch) | |
tree | f371f2f3ac50098ddaaadbba65d072c554193180 /Xamarin.PropertyEditing.Tests | |
parent | 76d63916d293bc917e43d134fcecefb560543b26 (diff) |
[Win] Fix canceled Add Type result
Also fixes Add not having a restriction.
Fixes #367
Diffstat (limited to 'Xamarin.PropertyEditing.Tests')
-rw-r--r-- | Xamarin.PropertyEditing.Tests/CollectionPropertyViewModelTests.cs | 83 |
1 files changed, 79 insertions, 4 deletions
diff --git a/Xamarin.PropertyEditing.Tests/CollectionPropertyViewModelTests.cs b/Xamarin.PropertyEditing.Tests/CollectionPropertyViewModelTests.cs index c8e8cde..0139aad 100644 --- a/Xamarin.PropertyEditing.Tests/CollectionPropertyViewModelTests.cs +++ b/Xamarin.PropertyEditing.Tests/CollectionPropertyViewModelTests.cs @@ -2,9 +2,11 @@ using System; using System.Collections; using System.Collections.Specialized; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Moq; using NUnit.Framework; +using Xamarin.PropertyEditing.Properties; using Xamarin.PropertyEditing.Reflection; using Xamarin.PropertyEditing.Tests.MockControls; using Xamarin.PropertyEditing.ViewModels; @@ -14,8 +16,24 @@ namespace Xamarin.PropertyEditing.Tests [TestFixture] internal class CollectionPropertyViewModelTests { + private AsyncSynchronizationContext syncContext; + + [SetUp] + public void Setup () + { + this.syncContext = new AsyncSynchronizationContext (); + SynchronizationContext.SetSynchronizationContext (this.syncContext); + } + + [TearDown] + public void TearDown () + { + this.syncContext.WaitForPendingOperationsToComplete (); + SynchronizationContext.SetSynchronizationContext (null); + } + [Test] - public async Task AddType () + public void AddType () { TargetPlatform platform = new TargetPlatform (new MockEditorProvider()); var obj = new { @@ -30,14 +48,14 @@ namespace Xamarin.PropertyEditing.Tests e.SelectedType = buttonType; }; - await vm.AssignableTypes.Task; + vm.AssignableTypes.Task.Wait(); vm.SelectedType = vm.SuggestedTypes.First (); Assert.That (vm.SuggestedTypes, Contains.Item (buttonType)); } [Test] - public async Task AddTarget () + public void AddTarget () { TargetPlatform platform = new TargetPlatform (new MockEditorProvider()); @@ -48,7 +66,7 @@ namespace Xamarin.PropertyEditing.Tests var editor = new ReflectionObjectEditor (obj); var vm = new CollectionPropertyViewModel (platform, editor.Properties.First(), new[] { editor }); - await vm.AssignableTypes.Task; + vm.AssignableTypes.Task.Wait(); vm.SelectedType = GetTypeInfo (typeof(MockWpfButton)); vm.AddTargetCommand.Execute (null); @@ -58,6 +76,63 @@ namespace Xamarin.PropertyEditing.Tests } [Test] + public async Task AddTargetCanAdd () + { + TargetPlatform platform = new TargetPlatform (new MockEditorProvider ()); + + var obj = new { + Collection = new ArrayList () + }; + + var editor = new ReflectionObjectEditor (obj); + + var vm = new CollectionPropertyViewModel (platform, editor.Properties.First (), new[] { editor }); + await vm.AssignableTypes.Task; + + Assume.That (vm.SelectedType, Is.Null); + Assert.That (vm.AddTargetCommand.CanExecute (null), Is.False); + + bool changed = false; + vm.AddTargetCommand.CanExecuteChanged += (o, e) => { changed = true; }; + vm.SelectedType = GetTypeInfo (typeof (MockWpfButton)); + Assert.That (vm.AddTargetCommand.CanExecute (null), Is.True); + Assert.That (changed, Is.True, "CanExecuteChanged did not fire"); + + changed = false; + vm.SelectedType = null; + Assert.That (vm.AddTargetCommand.CanExecute (null), Is.False); + Assert.That (changed, Is.True, "CanExecuteChanged did not fire"); + } + + [Test] + [Description ("When selecting a new type, if it's canceled the suggested type should return to something else")] + public void AddTypeCanceled () + { + TargetPlatform platform = new TargetPlatform (new MockEditorProvider ()); + + var obj = new { + Collection = new ArrayList () + }; + + var editor = new ReflectionObjectEditor (obj); + + var vm = new CollectionPropertyViewModel (platform, editor.Properties.First (), new[] { editor }); + vm.AssignableTypes.Task.Wait(); + + var buttonType = GetTypeInfo (typeof (MockWpfButton)); + vm.TypeRequested += (o, e) => { + e.SelectedType = buttonType; + }; + + vm.SelectedType = vm.SuggestedTypes.Last (); + Assume.That (vm.SuggestedTypes, Contains.Item (buttonType)); + + buttonType = null; + vm.SelectedType = vm.SuggestedTypes.Last (); + Assert.That (vm.SelectedType, Is.EqualTo (vm.SuggestedTypes.First ())); + } + + [Test] public async Task RemoveTarget () { TargetPlatform platform = new TargetPlatform (new MockEditorProvider()); |