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 
12 namespace ConsoleApp45_NoPlatformServices
13 {
14     static class Program
15     {
Main(string[] args)16         static void Main(string[] args)
17         {
18             var tests = typeof(Program).GetMethods(BindingFlags.Static | BindingFlags.NonPublic).Where(m => m.IsDefined(typeof(TestAttribute), false));
19 
20             foreach (var t in tests)
21             {
22                 Console.WriteLine(t.Name);
23 
24                 var e = new ManualResetEvent(false);
25 
26                 var res = false;
27                 var done = new Action<bool>(b =>
28                 {
29                     res = b;
30                     e.Set();
31                 });
32 
33                 t.Invoke(null, new[] { done });
34 
35                 e.WaitOne();
36 
37                 Console.WriteLine(res ? "Succeeded!" : "Failed!");
38                 Console.WriteLine();
39             }
40         }
41 
42         [Test]
Clock(Action<bool> done)43         static void Clock(Action<bool> done)
44         {
45             var clock = Observable.Interval(TimeSpan.FromSeconds(1)).Select(_ => DateTime.Now);
46 
47             var res = clock.Take(5);
48 
49             res.Subscribe(now => { Console.WriteLine(now); }, () => done(true));
50         }
51 
52         [Test]
Portable(Action<bool> done)53         static void Portable(Action<bool> done)
54         {
55             var clock = MyExtensions.GetClock();
56 
57             var res = clock.Take(5);
58 
59             res.Subscribe(now => { Console.WriteLine(now); }, () => done(true));
60         }
61 
62         [Test]
Providers(Action<bool> done)63         static void Providers(Action<bool> done)
64         {
65             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);
66 
67             res.Subscribe(done);
68         }
69 
70         [Test]
Remoting(Action<bool> done)71         static void Remoting(Action<bool> done)
72         {
73             var d = AppDomain.CreateDomain("RemotingTest");
74 
75             var xs = Observable.Range(0, 10, Scheduler.Default).Remotable();
76             var dn = new Done(done);
77 
78             d.SetData("xs", xs);
79             d.SetData("dn", dn);
80 
81             d.DoCallBack(() =>
82             {
83                 var ys = (IObservable<int>)AppDomain.CurrentDomain.GetData("xs");
84 
85                 var res = ys.ToArray().Wait();
86 
87                 var b = res.SequenceEqual(Enumerable.Range(0, 10));
88 
89                 ((Done)AppDomain.CurrentDomain.GetData("dn")).Set(b);
90             });
91         }
92 
93         class Done : MarshalByRefObject
94         {
95             private readonly Action<bool> _done;
96 
Done(Action<bool> done)97             public Done(Action<bool> done)
98             {
99                 _done = done;
100             }
101 
Set(bool result)102             public void Set(bool result)
103             {
104                 _done(result);
105             }
106 
InitializeLifetimeService()107             public override object InitializeLifetimeService()
108             {
109                 return null;
110             }
111         }
112     }
113 
114     [AttributeUsage(AttributeTargets.Method)]
115     class TestAttribute : Attribute
116     {
117     }
118 }
119