TestBase.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading;
  9. namespace ReactiveTests
  10. {
  11. #if SILVERLIGHT && !SILVERLIGHTM7
  12. public class TestBase : Microsoft.Silverlight.Testing.SilverlightTest
  13. {
  14. public void RunAsync(Action<Waiter> a)
  15. {
  16. EnqueueCallback(() =>
  17. {
  18. var w = new Waiter(TestComplete);
  19. a(w);
  20. w.Wait();
  21. });
  22. }
  23. public void CompleteAsync()
  24. {
  25. EnqueueTestComplete();
  26. }
  27. }
  28. public class Waiter
  29. {
  30. private Action _complete;
  31. public Waiter(Action complete)
  32. {
  33. _complete = complete;
  34. }
  35. public void Set()
  36. {
  37. _complete();
  38. }
  39. public void Wait()
  40. {
  41. }
  42. }
  43. #else
  44. public class TestBase
  45. {
  46. public void RunAsync(Action<Waiter> a)
  47. {
  48. var w = new Waiter();
  49. a(w);
  50. w.Wait();
  51. }
  52. }
  53. public class Waiter
  54. {
  55. private ManualResetEvent _evt = new ManualResetEvent(false);
  56. public void Set()
  57. {
  58. _evt.Set();
  59. }
  60. public void Wait()
  61. {
  62. _evt.WaitOne();
  63. }
  64. }
  65. [AttributeUsage(AttributeTargets.Method)]
  66. public class AsynchronousAttribute : Attribute
  67. {
  68. }
  69. #endif
  70. }