Program.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reactive.Concurrency;
  5. using System.Reactive.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using PortableLibraryProfile78_NuGet;
  11. namespace ConsoleApp45_NoPlatformServices
  12. {
  13. static class Program
  14. {
  15. static void Main(string[] args)
  16. {
  17. var tests = typeof(Program).GetMethods(BindingFlags.Static | BindingFlags.NonPublic).Where(m => m.IsDefined(typeof(TestAttribute), false));
  18. foreach (var t in tests)
  19. {
  20. Console.WriteLine(t.Name);
  21. var e = new ManualResetEvent(false);
  22. var res = false;
  23. var done = new Action<bool>(b =>
  24. {
  25. res = b;
  26. e.Set();
  27. });
  28. t.Invoke(null, new[] { done });
  29. e.WaitOne();
  30. Console.WriteLine(res ? "Succeeded!" : "Failed!");
  31. Console.WriteLine();
  32. }
  33. }
  34. [Test]
  35. static void Clock(Action<bool> done)
  36. {
  37. var clock = Observable.Interval(TimeSpan.FromSeconds(1)).Select(_ => DateTime.Now);
  38. var res = clock.Take(5);
  39. res.Subscribe(now => { Console.WriteLine(now); }, () => done(true));
  40. }
  41. [Test]
  42. static void Portable(Action<bool> done)
  43. {
  44. var clock = MyExtensions.GetClock();
  45. var res = clock.Take(5);
  46. res.Subscribe(now => { Console.WriteLine(now); }, () => done(true));
  47. }
  48. [Test]
  49. static void Providers(Action<bool> done)
  50. {
  51. var res = Qbservable.Range(Qbservable.Provider, 0, 10, Scheduler.Default).Zip(Observable.Range(0, 10, Scheduler.Default).AsQbservable().Where(_ => true).AsObservable(), (x, y) => x - y).All(d => d == 0);
  52. res.Subscribe(done);
  53. }
  54. [Test]
  55. static void Remoting(Action<bool> done)
  56. {
  57. var d = AppDomain.CreateDomain("RemotingTest");
  58. var xs = Observable.Range(0, 10, Scheduler.Default).Remotable();
  59. var dn = new Done(done);
  60. d.SetData("xs", xs);
  61. d.SetData("dn", dn);
  62. d.DoCallBack(() =>
  63. {
  64. var ys = (IObservable<int>)AppDomain.CurrentDomain.GetData("xs");
  65. var res = ys.ToArray().Wait();
  66. var b = res.SequenceEqual(Enumerable.Range(0, 10));
  67. ((Done)AppDomain.CurrentDomain.GetData("dn")).Set(b);
  68. });
  69. }
  70. class Done : MarshalByRefObject
  71. {
  72. private readonly Action<bool> _done;
  73. public Done(Action<bool> done)
  74. {
  75. _done = done;
  76. }
  77. public void Set(bool result)
  78. {
  79. _done(result);
  80. }
  81. public override object InitializeLifetimeService()
  82. {
  83. return null;
  84. }
  85. }
  86. }
  87. [AttributeUsage(AttributeTargets.Method)]
  88. class TestAttribute : Attribute
  89. {
  90. }
  91. }