示例#1
0
        public void should_consume_extended_event_in_the_classic_way()
        {
            var sut = new WiFiScanner();

            var networks = new List <Info>();
            ExtendedNetworkFoundHandler sutOnExtendedNetworkFound = (ssid, strength) =>
            {
                networks.Add(new Info {
                    Ssid = ssid, Strength = strength
                });
            };

            sut.ExtendedNetworkFound += sutOnExtendedNetworkFound;

            sut.FindExtendedNetwork("one", 1);
            sut.FindExtendedNetwork("two", 2);

            networks[0].ShouldBeEquivalentTo(new Info {
                Ssid = "one", Strength = 1
            });
            networks[1].ShouldBeEquivalentTo(new Info {
                Ssid = "two", Strength = 2
            });

            sut.ExtendedNetworkFound -= sutOnExtendedNetworkFound;
        }
示例#2
0
        public void should_create_an_extended_observable_using_FromEvent()
        {
            var sut = new WiFiScanner();

            var networks = Observable.FromEvent <ExtendedNetworkFoundHandler, Info>(
                handler => ((ssid, strength) => handler(new Info()
            {
                Ssid = ssid, Strength = strength
            })),
                handler => { sut.ExtendedNetworkFound += handler; },
                handler => { sut.ExtendedNetworkFound -= handler; });

            var sb = new List <string>();

            using (networks
                   .Select(n => $"{n.Ssid} ({n.Strength})")
                   .Subscribe(new StringObserver <string>(sb)))
            {
                sut.FindExtendedNetwork("one", 1);
                sut.FindExtendedNetwork("two", 2);
            }

            sb[0].Should().Be("OnNext(one (1))");
            sb[1].Should().Be("OnNext(two (2))");
        }