Exemplo n.º 1
0
        public void FromEventPattern()
        {
            var tester = new EventTester();

            {
                var list = new List <int>();
                var d    = Observable.FromEventPattern <EventHandler <MyEventArgs>, MyEventArgs>((h) => h.Invoke, h => tester.genericEventHandler += h, h => tester.genericEventHandler -= h)
                           .Subscribe(xx =>
                {
                    list.Add(xx.EventArgs.MyProperty);
                    Observable.Return(xx.EventArgs.MyProperty)
                    .Do(x => { if (x == 1)
                               {
                                   throw new Exception();
                               }
                        })
                    .Subscribe(x => list.Add(x));
                });

                try { tester.Fire(5); } catch { }
                try { tester.Fire(1); } catch { }
                try { tester.Fire(10); } catch { }

                list.IsCollection(5, 5, 1, 10, 10);
                d.Dispose();
                tester.Fire(1000);
                list.Count.Is(5);
            }
        }
Exemplo n.º 2
0
        public void FromEventPattern()
        {
            var tester = new EventTester();

            {
                var list = new List<int>();
                var d = Observable.FromEventPattern<EventHandler<MyEventArgs>, MyEventArgs>((h) => h.Invoke, h => tester.genericEventHandler += h, h => tester.genericEventHandler -= h)
                    .Subscribe(xx =>
                    {
                        list.Add(xx.EventArgs.MyProperty);
                        Observable.Return(xx.EventArgs.MyProperty)
                            .Do(x => { if (x == 1) throw new Exception(); })
                            .Subscribe(x => list.Add(x));
                    });

                try { tester.Fire(5); } catch { }
                try { tester.Fire(1); } catch { }
                try { tester.Fire(10); } catch { }

                list.IsCollection(5, 5, 1, 10, 10);
                d.Dispose();
                tester.Fire(1000);
                list.Count.Is(5);
            }
        }
Exemplo n.º 3
0
        public void FromEventUnityLike()
        {
            var tester = new EventTester();

            {
                var list = new List <int>();
                var d    = Observable.FromEvent <LikeUnityAction <int>, int>(h => new LikeUnityAction <int>(h), h => tester.intUnityAction += h, h => tester.intUnityAction -= h)
                           .Subscribe(xx =>
                {
                    list.Add(xx);
                    Observable.Return(xx)
                    .Do(x => { if (x == 1)
                               {
                                   throw new Exception();
                               }
                        })
                    .Subscribe(x => list.Add(x));
                });

                try { tester.Fire(5); } catch { }
                try { tester.Fire(1); } catch { }
                try { tester.Fire(10); } catch { }

                list.IsCollection(5, 5, 1, 10, 10);
                d.Dispose();
                tester.Fire(1000);
                list.Count.Is(5);
            }

            {
                var i    = 0;
                var list = new List <int>();
                var d    = Observable.FromEvent <LikeUnityAction>(h => new LikeUnityAction(h), h => tester.unityAction += h, h => tester.unityAction -= h)
                           .Subscribe(xx =>
                {
                    list.Add(i);
                    Observable.Return(i)
                    .Do(x => { if (x == 1)
                               {
                                   throw new Exception();
                               }
                        })
                    .Subscribe(x => list.Add(i));
                });

                try { i = 5; tester.Fire(5); } catch { }
                try { i = 1; tester.Fire(1); } catch { }
                try { i = 10; tester.Fire(10); } catch { }

                list.IsCollection(5, 5, 1, 10, 10);
                d.Dispose();
                tester.Fire(1000);
                list.Count.Is(5);
            }
        }
Exemplo n.º 4
0
        public void FromEventUnityLike()
        {
            var tester = new EventTester();

            {
                var list = new List<int>();
                var d = Observable.FromEvent<LikeUnityAction<int>, int>(h => new LikeUnityAction<int>(h), h => tester.intUnityAction += h, h => tester.intUnityAction -= h)
                    .Subscribe(xx =>
                    {
                        list.Add(xx);
                        Observable.Return(xx)
                            .Do(x => { if (x == 1) throw new Exception(); })
                            .Subscribe(x => list.Add(x));
                    });

                try { tester.Fire(5); } catch { }
                try { tester.Fire(1); } catch { }
                try { tester.Fire(10); } catch { }

                list.IsCollection(5, 5, 1, 10, 10);
                d.Dispose();
                tester.Fire(1000);
                list.Count.Is(5);
            }

            {
                var i = 0;
                var list = new List<int>();
                var d = Observable.FromEvent<LikeUnityAction>(h => new LikeUnityAction(h), h => tester.unityAction += h, h => tester.unityAction -= h)
                    .Subscribe(xx =>
                    {
                        list.Add(i);
                        Observable.Return(i)
                            .Do(x => { if (x == 1) throw new Exception(); })
                            .Subscribe(x => list.Add(i));
                    });

                try { i = 5; tester.Fire(5); } catch { }
                try { i = 1; tester.Fire(1); } catch { }
                try { i = 10; tester.Fire(10); } catch { }

                list.IsCollection(5, 5, 1, 10, 10);
                d.Dispose();
                tester.Fire(1000);
                list.Count.Is(5);
            }
        }
Exemplo n.º 5
0
 public void FromEventUnity()
 {
     SetScehdulerForImport();
     var tester = new EventTester();
     {
         var list = new List<int>();
         var d = Observable.FromEvent<int>(h => tester.intAction += h, h => tester.intAction -= h)
             .Subscribe(xx =>
             {
                 list.Add(xx);
                 Observable.Return(xx)
                     .Do(x => { if (x == 1) throw new Exception(); })
                     .Subscribe(x => list.Add(x));
             });
         try { tester.Fire(5); } catch { }
         try { tester.Fire(1); } catch { }
         try { tester.Fire(10); } catch { }
         list.IsCollection(5, 5, 1, 10, 10);
         d.Dispose();
         tester.Fire(1000);
         list.Count.Is(5);
     }
     {
         var i = 0;
         var list = new List<int>();
         var d = Observable.FromEvent(h => tester.unitAction += h, h => tester.unitAction -= h)
             .Subscribe(xx =>
             {
                 list.Add(i);
                 Observable.Return(i)
                     .Do(x => { if (x == 1) throw new Exception(); })
                     .Subscribe(x => list.Add(i));
             });
         try { i = 5; tester.Fire(5); } catch { }
         try { i = 1; tester.Fire(1); } catch { }
         try { i = 10; tester.Fire(10); } catch { }
         list.IsCollection(5, 5, 1, 10, 10);
         d.Dispose();
         tester.Fire(1000);
         list.Count.Is(5);
     }
     UniRx.Scheduler.SetDefaultForUnity();
 }