Skip to content
This repository was archived by the owner on Sep 25, 2024. It is now read-only.

Commit 20394cf

Browse files
author
Eric Maupin
committed
[core] CreateInstance should bail on null returned type
1 parent f4273f4 commit 20394cf

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

Xamarin.PropertyEditing.Tests/ObjectPropertyViewModelTests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,41 @@ public async Task MultiValueTypesNull ()
256256
Assert.That (vm.ValueType, Is.Null);
257257
}
258258

259+
[Test]
260+
public void ReturnedNullTypeCancels ()
261+
{
262+
object value = new object ();
263+
var p = CreatePropertyMock ("prop");
264+
var childsubInfo = GetTypeInfo (typeof (SubChildClass));
265+
var editor = new MockObjectEditor (new[] { p.Object }, new Dictionary<IPropertyInfo, IReadOnlyList<ITypeInfo>> {
266+
{
267+
p.Object,
268+
new[] {
269+
GetTypeInfo (typeof(ChildClass)),
270+
childsubInfo
271+
}
272+
}
273+
});
274+
275+
var providerMock = CreateProviderMock (value, new MockObjectEditor { Target = value });
276+
var vm = new ObjectPropertyViewModel (new TargetPlatform (providerMock.Object), p.Object, new[] { editor });
277+
278+
var tcs = new TaskCompletionSource<ITypeInfo> ();
279+
bool requested = false;
280+
vm.TypeRequested += (sender, args) => {
281+
requested = true;
282+
args.SelectedType = tcs.Task;
283+
};
284+
285+
Assume.That (vm.CreateInstanceCommand.CanExecute (childsubInfo), Is.True);
286+
vm.CreateInstanceCommand.Execute (null);
287+
Assume.That (requested, Is.True);
288+
289+
tcs.SetResult (null);
290+
291+
providerMock.Verify (ep => ep.CreateObjectAsync (null), Times.Never);
292+
}
293+
259294
private TestContext syncContext;
260295

261296
private Mock<IEditorProvider> CreateProviderMock (object value, IObjectEditor editor)

Xamarin.PropertyEditing/ViewModels/ObjectPropertyViewModel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ private async void CreateInstance ()
164164

165165
try {
166166
selectedType = await args.SelectedType;
167-
} catch (OperationCanceledException) {
167+
if (selectedType == null)
168+
return;
169+
} catch (OperationCanceledException) {
168170
return;
169171
}
170172
}

0 commit comments

Comments
 (0)