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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Tests
{
[TestFixture]
public class AddValueConverterViewModelTests
{
[SetUp]
public void Setup ()
{
this.syncContext = new TestContext ();
SynchronizationContext.SetSynchronizationContext (this.syncContext);
}
[TearDown]
public void TearDown ()
{
SynchronizationContext.SetSynchronizationContext (null);
this.syncContext.ThrowPendingExceptions ();
}
[Test]
public void ConverterNameSuggestedWithProvider ()
{
object target = new object();
var editorProvider = new Mock<IEditorProvider> ();
var type = new TypeInfo (new AssemblyInfo ("Assembly", false), "Namespace", "Name");
const string suggested = "SuggestedName";
var resourcesProvider = new Mock<IResourceProvider> ();
resourcesProvider.Setup (rp => rp.SuggestResourceNameAsync (It.IsAny<IReadOnlyCollection<object>> (), type))
.ReturnsAsync (suggested);
var types = new AssignableTypesResult (new [] { type });
var vm = new AddValueConverterViewModel (
new TargetPlatform (editorProvider.Object, resourcesProvider.Object), target,
new AsyncValue<IReadOnlyDictionary<IAssemblyInfo, ILookup<string, ITypeInfo>>> (
Task.FromResult (types.GetTypeTree ())));
Assume.That (vm.ConverterName, Is.Null);
vm.SelectedType = type;
Assert.That (vm.ConverterName, Is.EqualTo (suggested));
}
[Test]
public void ConverterNameSuggestedWithoutProvider ()
{
object target = new object ();
var editorProvider = new Mock<IEditorProvider> ();
var type = new TypeInfo (new AssemblyInfo ("Assembly", false), "Namespace", "Name");
var types = new AssignableTypesResult (new[] { type });
var vm = new AddValueConverterViewModel (
new TargetPlatform (editorProvider.Object), target,
new AsyncValue<IReadOnlyDictionary<IAssemblyInfo, ILookup<string, ITypeInfo>>> (
Task.FromResult (types.GetTypeTree ())));
Assume.That (vm.ConverterName, Is.Null);
vm.SelectedType = type;
Assert.That (vm.ConverterName, Is.EqualTo (type.Name));
}
private TestContext syncContext;
}
}
|