TestBase.cs 1.5 KB

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