You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.7 KiB

  1. using System.Collections.Generic;
  2. using NUnit.Framework;
  3. using UnityEditor.Experimental.UIElements;
  4. using UnityEngine;
  5. using UnityEngine.Experimental.UIElements;
  6. namespace UnityEditor.PackageManager.UI.Tests
  7. {
  8. internal abstract class UITests<TWindow> where TWindow : EditorWindow
  9. {
  10. private TWindow Window { get; set; }
  11. protected VisualElement Container { get { return Window.GetRootVisualContainer(); } }
  12. protected MockOperationFactory Factory { get; private set; }
  13. [OneTimeSetUp]
  14. protected void OneTimeSetUp()
  15. {
  16. Factory = new MockOperationFactory();
  17. OperationFactory.Instance = Factory;
  18. Window = EditorWindow.GetWindow<TWindow>();
  19. Window.Show();
  20. }
  21. [OneTimeTearDown]
  22. protected void OneTimeTearDown()
  23. {
  24. OperationFactory.Reset();
  25. Window = null;
  26. if (TestContext.CurrentContext.Result.FailCount <= 0)
  27. {
  28. PackageCollection.Instance.UpdatePackageCollection(true);
  29. }
  30. }
  31. protected void SetSearchPackages(IEnumerable<PackageInfo> packages)
  32. {
  33. Factory.SearchOperation = new MockSearchOperation(Factory, packages);
  34. PackageCollection.Instance.FetchSearchCache(true);
  35. }
  36. protected void SetListPackages(IEnumerable<PackageInfo> packages)
  37. {
  38. Factory.Packages = packages;
  39. PackageCollection.Instance.FetchListCache(true);
  40. }
  41. protected static Error MakeError(ErrorCode code, string message)
  42. {
  43. var error = "{\"errorCode\" : " + (uint)code + ", \"message\" : \"" + message + "\"}";
  44. return JsonUtility.FromJson<Error>(error);
  45. }
  46. }
  47. }