Example #1
0
        private static void ShimAllConnections()
        {
            //shim connections to avoid network connections...
            ShimConnection.ConstructorIPAddressClusterInt32 = (conn, address, conf, nr) =>
            {
                //wrap the new connection in a shim
                var connection = new ShimConnection(conn);
                int connLoad   = 0;
                EventHandler <LoadChangeEvent> nodeHandler = null;

                //replace any IO inducing methods
                connection.OpenAsyncLogger =
                    (log) => Task.FromResult(true);

                connection.SendRequestAsyncFrameLoggerInt32Boolean
                    =
                        (frame, log, load, connecting) =>
                    {
                    //update connection load
                    connLoad += load;
                    //call load change event handler
                    if (nodeHandler != null)
                    {
                        nodeHandler(connection,
                                    new LoadChangeEvent {
                            LoadDelta = load
                        });
                    }
                    //done
                    return
                        (Task.FromResult(
                             (Frame)
                             new ResultFrame {
                        Stream = frame.Stream
                    }));
                    };

                //intercept load changed handlers
                connection.
                OnLoadChangeAddEventHandlerOfLoadChangeEvent
                    = (handler) => { nodeHandler += handler; };

                //return proper load values
                connection.LoadGet = () => connLoad;

                //set some default properties
                connection.IsConnectedGet = () => true;
                connection.IsIdleGet      = () => false;
            };
        }
        public void testing()
        {
            var cut = new Mock <IConnectionProvider>();

            cut.Setup(x => x.GetConnection).Returns(() =>
            {
                var x           = new ShimConnection();
                x.GetSecret     = () => "fake";
                x.GetSettings   = () => "fake";
                x.PublicPropGet = () => "fake";
                return(x);
            });

            using (ShimsContext.Create())
            {
                var a = new A(cut.Object.GetConnection);
                Assert.AreEqual(a.GetAll().Length, 2);
                Assert.AreEqual(a.GetAll()[0], "fake");
                Assert.AreEqual(a.GetAll()[1], "fake");
            }
        }
        private static void ShimAllConnections()
        {
            //shim connections to avoid network connections...
            ShimConnection.ConstructorNodeInt32 = (conn, node, nr) =>
            {
                //wrap the new connection in a shim
                var connection = new ShimConnection(conn);
                int connLoad = 0;
                EventHandler<LoadChangeEvent> nodeHandler = null;

                //replace any IO inducing methods
                connection.OpenAsyncLogger =
                    log => Task.FromResult(true);


                // ReSharper disable AccessToModifiedClosure
                connection.
                    SendRequestAsyncFrameLoggerInt32CancellationToken
                    =
                    (frame, log, load, token) =>
                    {
                        //update connection load
                        connLoad += load;
                        //call load change event handler
                        if(nodeHandler != null)
                        {
                            nodeHandler(connection,
                                        new LoadChangeEvent
                                        {LoadDelta = load});
                        }
                        //done
                        return
                            Task.FromResult(
                                (Frame)
                                    new ResultFrame {Stream = frame.Stream});
                    };
                // ReSharper restore AccessToModifiedClosure

                //intercept load changed handlers
                connection.
                    OnLoadChangeAddEventHandlerOfLoadChangeEvent
                    = handler => { nodeHandler += handler; };

                //return proper load values
                connection.LoadGet = () => connLoad;

                //set some default properties
                connection.IsAvailableGet = () => true;
                connection.IsIdleGet = () => false;
            };
        }
        private static void ShimAllConnections()
        {
            //shim connections to avoid network connections...
            ShimConnection.ConstructorIPAddressClusterInt32 = (conn, address, conf, nr) =>
                                                                  {
                                                                      //wrap the new connection in a shim
                                                                      var connection = new ShimConnection(conn);
                                                                      int connLoad = 0;
                                                                      EventHandler<LoadChangeEvent> nodeHandler = null;

                                                                      //replace any IO inducing methods
                                                                      connection.OpenAsyncLogger =
                                                                          (log) => Task.FromResult(true);

                                                                      connection.SendRequestAsyncFrameLoggerInt32Boolean
                                                                          =
                                                                          (frame, log, load, connecting) =>
                                                                          {
                                                                              //update connection load
                                                                              connLoad += load;
                                                                              //call load change event handler
                                                                              if (nodeHandler != null)
                                                                                  nodeHandler(connection,
                                                                                           new LoadChangeEvent { LoadDelta = load });
                                                                              //done
                                                                              return
                                                                                  Task.FromResult(
                                                                                      (Frame)
                                                                                      new ResultFrame { Stream = frame.Stream });
                                                                          };

                                                                      //intercept load changed handlers
                                                                      connection.
                                                                          OnLoadChangeAddEventHandlerOfLoadChangeEvent
                                                                          = (handler) => { nodeHandler += handler; };

                                                                      //return proper load values
                                                                      connection.LoadGet = () => connLoad;

                                                                      //set some default properties
                                                                      connection.IsConnectedGet = () => true;
                                                                      connection.IsIdleGet = () => false;
                                                                  };
        }