UITests.cs
1.74 KB
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.Collections.Generic;
using NUnit.Framework;
using UnityEditor.Experimental.UIElements;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.PackageManager.UI.Tests
{
internal abstract class UITests<TWindow> where TWindow : EditorWindow
{
private TWindow Window { get; set; }
protected VisualElement Container { get { return Window.GetRootVisualContainer(); } }
protected MockOperationFactory Factory { get; private set; }
[OneTimeSetUp]
protected void OneTimeSetUp()
{
Factory = new MockOperationFactory();
OperationFactory.Instance = Factory;
Window = EditorWindow.GetWindow<TWindow>();
Window.Show();
}
[OneTimeTearDown]
protected void OneTimeTearDown()
{
OperationFactory.Reset();
Window = null;
if (TestContext.CurrentContext.Result.FailCount <= 0)
{
PackageCollection.Instance.UpdatePackageCollection(true);
}
}
protected void SetSearchPackages(IEnumerable<PackageInfo> packages)
{
Factory.SearchOperation = new MockSearchOperation(Factory, packages);
PackageCollection.Instance.FetchSearchCache(true);
}
protected void SetListPackages(IEnumerable<PackageInfo> packages)
{
Factory.Packages = packages;
PackageCollection.Instance.FetchListCache(true);
}
protected static Error MakeError(ErrorCode code, string message)
{
var error = "{\"errorCode\" : " + (uint)code + ", \"message\" : \"" + message + "\"}";
return JsonUtility.FromJson<Error>(error);
}
}
}