Ejemplo n.º 1
0
        public void Should_expect_never_observable()
        {
            var scheduler = new MarbleScheduler();

            scheduler.ExpectObservable(Observable.Never <string>()).ToBe("-", new { });
            scheduler.ExpectObservable(Observable.Never <string>()).ToBe("---", new { });
            scheduler.Flush();
        }
Ejemplo n.º 2
0
        public void Should_expect_empty_observable()
        {
            var scheduler = new MarbleScheduler();

            scheduler.ExpectObservable(Observable.Empty <string>()).ToBe("|", new { });
            scheduler.Flush();
        }
Ejemplo n.º 3
0
        public void Should_expect_one_value_observable()
        {
            var scheduler = new MarbleScheduler();

            scheduler.ExpectObservable(Observable.Return("hello")).ToBe("(h|)", new { h = "hello" });
            scheduler.Flush();
        }
 public void ExpectObservable_should_work_for_observable_return()
 {
     using (var s = new MarbleScheduler())
     {
         s.ExpectObservable(Observable.Return('a', s)).ToBe("(a|)");
     }
 }
 public void ExpectObservable_should_work_for_observable_throw()
 {
     using (var s = new MarbleScheduler())
     {
         s.ExpectObservable(Observable.Throw <char>(new Exception(), s)).ToBe("#");
     }
 }
 public void ExpectObservable_should_work_for_observable_empty()
 {
     using (var s = new MarbleScheduler())
     {
         s.ExpectObservable(Observable.Empty <int>(s)).ToBe("|", Dict.Empty <int>());
     }
 }
Ejemplo n.º 7
0
        public void Should_expect_observable_on_error()
        {
            var scheduler = new MarbleScheduler();

            var source = scheduler.CreateColdObservable <Unit>("---#", null, new Exception());

            scheduler.ExpectObservable(source).ToBe("---#", null, new Exception());
            scheduler.Flush();
        }
Ejemplo n.º 8
0
        public void Should_use_unsubscription_diagram()
        {
            var scheduler   = new MarbleScheduler();
            var source      = scheduler.CreateHotObservable("---^-a-b-|");
            var unsubscribe = "---!";
            var expected    = "--a";

            scheduler.ExpectObservable(source, unsubscribe).ToBe(expected);
            scheduler.Flush();
        }
Ejemplo n.º 9
0
        public void Should_fail_when_event_values_differ()
        {
            var scheduler = new MarbleScheduler();

            Check.ThatCode(() =>
            {
                scheduler.ExpectObservable(Observable.Return("hello")).ToBe("h", new { h = "bye" });
                scheduler.Flush();
            }).ThrowsAny();
        }
 public void ExpectObservable_should_accept_unsubscription_marble_diagram()
 {
     using (var s = new MarbleScheduler())
     {
         var source      = s.Hot("---^-a-b-|");
         var unsubscribe = "---!";
         var expected    = "--a";
         s.ExpectObservable(source, unsubscribe).ToBe(expected);
     }
 }
Ejemplo n.º 11
0
 public void Markers()
 {
     using (var s = new MarbleScheduler())
     {
         var e1       = s.Hot("-a");
         var e2       = s.Hot("--b");
         var expected = "-ab";
         s.ExpectObservable(e1.Merge(e2)).ToBe(expected);
     }
 }
Ejemplo n.º 12
0
 public void Ensure()
 {
     using (var s = new MarbleScheduler())
     {
         var e1       = s.Hot("----a--^--b-------c--|");
         var e2       = s.Hot("---d-^--e---------f-----|");
         var expected = "---(be)----c-f-----|";
         s.ExpectObservable(e1.Merge(e2)).ToBe(expected);
     }
 }
Ejemplo n.º 13
0
        public void Should_demo_with_a_simple_operator()
        {
            var scheduler    = new MarbleScheduler();
            var sourceEvents = scheduler.CreateColdObservable("a-b-c-|");

            var upperEvents = sourceEvents.Select(s => s.ToUpper());

            scheduler.ExpectObservable(upperEvents).ToBe("A-B-C-|");
            scheduler.Flush();
        }
Ejemplo n.º 14
0
        public void Should_fail_when_observables_end_with_different_error_types()
        {
            var scheduler = new MarbleScheduler();

            Check.ThatCode(() =>
            {
                var source = _scheduler.CreateColdObservable <Unit>("---#", null, new ArgumentException());
                scheduler.ExpectObservable(source).ToBe("---#", null, new Exception());
                scheduler.Flush();
            }).ThrowsAny();
        }
 public void ExpectObservable_should_support_testing_metastreams()
 {
     using (var s = new MarbleScheduler())
     {
         var x            = s.Cold("-a-b|");
         var y            = s.Cold("-c-d|");
         var myObservable = s.Hot("---x---y----|", Dict.Map('x', x, 'y', y));
         var expected     = "---x---y----|";
         s.ExpectObservable(myObservable).ToBe(expected, Dict.Map('x', x, 'y', y));
     }
 }
Ejemplo n.º 16
0
        public void Should_fail_when_event_timing_differs()
        {
            var scheduler = new MarbleScheduler();

            Action timingDiffer = () =>
            {
                scheduler.ExpectObservable(Observable.Return("hello")).ToBe("--h", new { h = "hello" });
                scheduler.Flush();
            };

            Check.ThatCode(timingDiffer).ThrowsAny();
        }
        public void ExpectObservable_should_materialize_inner_observables()
        {
            var s = new MarbleScheduler();

            var x1 = s.Cold("---a---b---|");
            var x2 = s.Cold("---a---b---|");
            var y  = s.Hot("---x---", Dict.Map('x', x1));

            s.ExpectObservable(y).ToBe("---x---", Dict.Map('x', x2), comparer: new ObservableEqualityComparer <char>());

            s.Start();
        }
 public void EqualityComparer_can_be_provided_in_ToBe()
 {
     using (var s = new MarbleScheduler())
     {
         var veryCuriousEqualityComparer =
             new LambdaEqualityComparer <int>((a, b) => Math.Abs(a - b) == 1, x => 0);
         s.ExpectObservable(Observable.Return(1)).ToBe(
             "(x|)",
             Dict.Map('x', 2),
             comparer: veryCuriousEqualityComparer);
     }
 }
 public void ExpectObservable_should_work_for_zipped_observable()
 {
     using (var s = new MarbleScheduler())
     {
         var dict = Enumerable.Range(0, 10)
                    .Zip(Enumerable.Range('0' + 0, 10).Select(p => (char)p), Tuple.Create)
                    .ToDictionary(k => k.Item2, v => v.Item1);
         var e1       = s.Hot("----1--^--2--3-----0--|", dict);
         var e2       = s.Hot("---2-^--1---2--1----9--|", dict);
         var expected = "---3---5----1--|";
         s.ExpectObservable(e1.Zip(e2, (a, b) => a + b)).ToBe(expected, dict);
     }
 }
Ejemplo n.º 20
0
        public async Task should_stop_stream_after_10_seconds()
        {
            // given
            var scheduler   = new MarbleScheduler();
            var quoteSource = Observable.Never <string>();

            // when
            var server = CreateServer(quoteSource, scheduler);
            var stream = await server.GetEvents();

            // then
            scheduler.ExpectObservable(stream).ToBe("----------|");
            scheduler.Flush();
        }
Ejemplo n.º 21
0
        public void Should_support_testing_metastreams()
        {
            var scheduler = new MarbleScheduler();
            var x         = scheduler.CreateColdObservable("-a-b|");
            var y         = scheduler.CreateColdObservable("-c-d|");

            var myObservable = scheduler.CreateHotObservable <IObservable <string> >("---x---y----|", new { x = x, y = y });
            var expected     = "---x---y----|";
            var expectedx    = scheduler.CreateColdObservable("-a-b|");
            var expectedy    = scheduler.CreateColdObservable("-c-d|");

            scheduler.ExpectObservable(myObservable).ToBe(expected, new { x = expectedx, y = expectedy });
            scheduler.Flush();
        }
Ejemplo n.º 22
0
        public async Task should_forward_forex_data()
        {
            // given
            var scheduler   = new MarbleScheduler();
            var forexSource = scheduler.CreateHotObservable <string>("--f--", new { f = new Quote("EUR/USD", 1.4).ToJson() });

            // when
            var forexStream = await Create(forexSource).GetEvents();

            // then
            scheduler.ExpectObservable(forexStream.Take(1))
            .ToBe("--(v|)", new { v = 1.4 });

            scheduler.Flush();
        }
Ejemplo n.º 23
0
        public async Task should_send_a_stock_message_when_receiving_a_quote()
        {
            // given
            var scheduler   = new MarbleScheduler();
            var quoteSource = scheduler.CreateHotObservable <string>("--q--", new { q = new Quote("GOOGL", 705.8673).ToJson() });

            // when
            var server = CreateServer(quoteSource, scheduler);
            var stream = await server.GetEvents();

            // then
            scheduler.ExpectObservable(stream.Select(s => s.CompanyName).Concat(Observable.Never <string>()))
            .ToBe("--s--", new { s = "Alphabet Inc" });

            scheduler.Flush();
        }
 public void ExpectObservable_should_work_for_combine_latest_observable()
 {
     using (var s = new MarbleScheduler())
     {
         var e1       = s.Cold("---a--b----|");
         var e2       = s.Cold("--c----d----|");
         var expected = "---x--yz----|";
         var dict     = new Dictionary <char, string>
         {
             { 'x', "ac" },
             { 'y', "bc" },
             { 'z', "bd" }
         };
         s.ExpectObservable(e1.CombineLatest(e2, (a, b) => a.ToString() + b.ToString()))
         .ToBe(expected, dict);
     }
 }
 public void ExpectObservable_should_handle_inner_observables()
 {
     using (var s = new MarbleScheduler())
     {
         var x                = s.Cold("--a--b--c--d--e--|           ");
         var xsubs            = "         ^         !                  ";
         var y                = s.Cold("---f---g---h---i--|");
         var ysubs            = "                   ^                 !";
         var e1               = s.Hot("---------x---------y---------|        ");
         var e1subs           = "^                            !        ";
         var expected         = "-----------a--b--c----f---g---h---i--|";
         var observableLookup = Dict.Map('x', x, 'y', y);
         var result           = e1.Select(p => observableLookup[p]).Switch();
         s.ExpectObservable(result).ToBe(expected);
         s.ExpectSubscriptions(x.Subscriptions).ToBe(xsubs);
         s.ExpectSubscriptions(y.Subscriptions).ToBe(ysubs);
         s.ExpectSubscriptions(e1.Subscriptions).ToBe(e1subs);
     }
 }
Ejemplo n.º 26
0
        public void Should_demo_metastreams_with_windows()
        {
            var scheduler    = new MarbleScheduler();
            var input        = "a---b---c---d-|";
            var myObservable = scheduler.CreateColdObservable(input);

            var result = myObservable.Window(2, 1);

            var aWindow = scheduler.CreateColdObservable("a---(b|)");
            var bWindow = scheduler.CreateColdObservable("----b---(c|)");
            var cWindow = scheduler.CreateColdObservable("----c---(d|)");
            var dWindow = scheduler.CreateColdObservable("----d-|");
            var eWindow = scheduler.CreateColdObservable("--|");

            var expected = "(ab)c---d---e-|";

            scheduler.ExpectObservable(result).ToBe(expected, new { a = aWindow, b = bWindow, c = cWindow, d = dWindow, e = eWindow });
            scheduler.Flush();
        }
Ejemplo n.º 27
0
        public async Task should_send_a_stock_message_only_once_when_receiving_two_quotes_for_the_same_stock()
        {
            // given
            var scheduler   = new MarbleScheduler();
            var quoteSource = scheduler.CreateHotObservable <string>("--f-s-t--", new
            {
                f = new Quote("GOOGL", 705.8673).ToJson(),
                s = new Quote("GOOGL", 705.8912).ToJson(),
                t = new Quote("IBM", 106.344).ToJson()
            });

            // when
            var server = CreateServer(quoteSource, scheduler);
            var stream = await server.GetEvents();

            // then
            scheduler.ExpectObservable(stream.Select(s => s.CompanyName).Concat(Observable.Never <string>()))
            .ToBe("--g---i--", new
            {
                g = "Alphabet Inc",
                i = "International Business Machines Corp."
            });
            scheduler.Flush();
        }