示例#1
0
        public void TestReachability()
        {
            try {
                var status = NetworkReachabilityStatus.Unknown;
                var e      = new NetworkReachabilityChangeEventArgs(status);
                NetworkReachabilityStatus s = NetworkReachabilityStatus.Unknown;

                var _reachability = new Reachability();

                _reachability.StatusChanged += (sender, args) => s = args.Status;
                _reachability.Start();

                e.Status.Should().Be(s);

                var method = ReachabilityType.GetMethod("InvokeNetworkChangeEvent", BindingFlags.NonPublic | BindingFlags.Instance);
                var res    = method.Invoke(_reachability, new object[1] {
                    s
                });

                NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
                method = ReachabilityType.GetMethod("IsInterfaceValid", BindingFlags.NonPublic | BindingFlags.Static);
                foreach (var n in nics)
                {
                    res = method.Invoke(null, new object[1] {
                        n
                    });
                }

                var asender = new object();
                method = ReachabilityType.GetMethod("OnNetworkChange", BindingFlags.NonPublic | BindingFlags.Instance);
                res    = method.Invoke(_reachability, new object[2] {
                    asender, e
                });

                var ReplicatorType = typeof(Replicator);
                var targetEndpoint = new URLEndpoint(new Uri("ws://192.168.0.11:4984/app"));
                var config         = new ReplicatorConfiguration(Db, targetEndpoint);
                using (Replicator replicator = new Replicator(config)) {
                    method = ReplicatorType.GetMethod("ReachabilityChanged", BindingFlags.NonPublic | BindingFlags.Instance);
                    res    = method.Invoke(replicator, new object[2] {
                        asender, e
                    });
                }
            }
            catch { }
        }