RemoteTestResultDataFactory.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using NUnit.Framework.Interfaces;
  4. using UnityEngine.TestRunner.NUnitExtensions.Runner;
  5. namespace UnityEngine.TestRunner.TestLaunchers
  6. {
  7. internal class RemoteTestResultDataFactory : IRemoteTestResultDataFactory
  8. {
  9. public RemoteTestResultDataWithTestData CreateFromTestResult(ITestResult result)
  10. {
  11. var tests = CreateTestDataList(result.Test);
  12. tests.First().testCaseTimeout = UnityTestExecutionContext.CurrentContext.TestCaseTimeout;
  13. return new RemoteTestResultDataWithTestData()
  14. {
  15. results = CreateTestResultDataList(result),
  16. tests = tests
  17. };
  18. }
  19. public RemoteTestResultDataWithTestData CreateFromTest(ITest test)
  20. {
  21. var tests = CreateTestDataList(test);
  22. if (UnityTestExecutionContext.CurrentContext != null)
  23. {
  24. tests.First().testCaseTimeout = UnityTestExecutionContext.CurrentContext.TestCaseTimeout;
  25. }
  26. return new RemoteTestResultDataWithTestData()
  27. {
  28. tests = tests
  29. };
  30. }
  31. private RemoteTestData[] CreateTestDataList(ITest test)
  32. {
  33. var list = new List<RemoteTestData>();
  34. list.Add(new RemoteTestData(test));
  35. list.AddRange(test.Tests.SelectMany(CreateTestDataList));
  36. return list.ToArray();
  37. }
  38. private static RemoteTestResultData[] CreateTestResultDataList(ITestResult result)
  39. {
  40. var list = new List<RemoteTestResultData>();
  41. list.Add(new RemoteTestResultData(result));
  42. list.AddRange(result.Children.SelectMany(CreateTestResultDataList));
  43. return list.ToArray();
  44. }
  45. }
  46. }