示例#1
0
        private static void DoTest(ClientTesting.Behaviour behaviour)
        {
            var stuff = ClientTesting.CreateClient(behaviour);
            //
            var cli = stuff.DutClient;

            cli.SetPin(Pin1234);
            stuff.Mockery.VerifyAllExpectationsHaveBeenMet();
            //
            Expect.Once.On(stuff.MockedSecurityApi)
            .Method("SetPin")
            .With(ClientTesting.Addr1, Pin1234)
            .Will(Return.Value(true));
            ClientTesting.ExpectOpen(stuff);
            ClientTesting.DoOpen(stuff, new Action(delegate {
                Expect.Once.On(stuff.MockedSecurityApi)
                .Method("RevokePin")
                .With(ClientTesting.Addr1)
                .Will(Return.Value(true));
            }));
            stuff.Mockery.VerifyAllExpectationsHaveBeenMet();
            //
            if (behaviour.EndConnectSuccess)
            {
                ClientTesting.RaiseRemoteClose(stuff);
            }
            else
            {
                Expect.Once.On(stuff.MockedApi).Method("SPP_Close_Port")
                .With(stuff.StackId, stuff.DutConn.Testing_GetPortId())
                .Will(Return.Value(BluetopiaError.OK));
            }
            stuff.DutClient.Dispose();
            stuff.Mockery.VerifyAllExpectationsHaveBeenMet();
        }
示例#2
0
        void NextGetPortFails(Action <CommonBluetoothListener> doConstruct)
        {
            var mockP = new Mock <MyCommonRfcommStream>();
            var p     = mockP.Object;
            var ports = new MyCommonRfcommStream[] {
                p
            };
            //--
            var svr = CreateLsnr(ports, MockBehavior.Loose);

            doConstruct(svr); // ****
            //
            svr.Start();      // ****
            var ar  = svr.BeginAcceptBluetoothClient(null, null);
            var ar2 = svr.BeginAcceptBluetoothClient(null, null);

            Assert.IsFalse(ar.IsCompleted, "isc0");
            //--
            p.HandleCONNECTED("Weeeee"); // ****
            ClientTesting.SafeWait(ar);
            Assert.IsTrue(ar.IsCompleted, "isc1");
            svr.EndAcceptBluetoothClient(ar);
            try {
                svr.EndAcceptBluetoothClient(ar2);
                Assert.Fail("should have thrown!");
            } catch (Exception ex) {
            }
            //
            try {
                var ar3 = svr.BeginAcceptBluetoothClient(null, null);
                Assert.Fail("should have thrown!");
                //svr.EndAcceptBluetoothClient(ar3);
            } catch (Exception ex) {
            }
        }
示例#3
0
        public void ErrorOpenNoCallback()
        {
            var stuff = BluetopiaTesting.InitMockery_Client(new ClientTestingBluetopia.Behaviour());
            //
            const int hConn = 99;
            //
            var cli  = stuff.CreateBluetoothClient();
            var cli2 = (BluetopiaClient)cli;
            var conn = (BluetopiaRfcommStream)cli2.Testing_GetConn();

            //
            Expect.Once.On(stuff.MockedApi).Method("SPP_Open_Remote_Port")
            .With(stuff.StackId, ClientTesting.Addr1Long, ClientTesting.Port5Uint,
                  (InTheHand.Net.Bluetooth.StonestreetOne.NativeMethods.SPP_Event_Callback)
                  conn.HandleSPP_Event_Callback, (uint)0)
            .Will(Return.Value(hConn));
            //
            var remote = new BluetoothEndPoint(ClientTesting.Addr1, BluetoothService.Empty, ClientTesting.Port5);
            var ar     = cli.BeginConnect(remote, null, null);

            stuff.Mockery_VerifyAllExpectationsHaveBeenMet();
            ClientTesting.Assert_IsConnected(
                ClientTesting.IsConnectedState.Closed,
                conn, cli, "after");
            Assert.IsFalse(ar.IsCompleted, "ar.IsCompleted after");
            //
            Expect.Once.On(stuff.MockedApi).Method("SPP_Close_Port")
            .With(stuff.StackId, conn.Testing_GetPortId())
            .Will(Return.Value(BluetopiaError.OK));
            cli.Dispose();
            stuff.Mockery_VerifyAllExpectationsHaveBeenMet();
        }
示例#4
0
        void _HandleCONNECTED(Action <CommonBluetoothListener> doConstruct)
        {
            var mockP = new Mock <MyCommonRfcommStream>();
            var p     = mockP.Object;
            //
            var ports = new MyCommonRfcommStream[] {
                p,
                new Mock <MyCommonRfcommStream>().Object
            };
            //--
            var svr = CreateLsnr(ports, MockBehavior.Loose);

            doConstruct(svr); // ****
            //
            svr.Start();      // ****
            var ar = svr.BeginAcceptBluetoothClient(null, null);

            Assert.IsFalse(ar.IsCompleted, "isc0");
            //--
            p.HandleCONNECTED("Weeeee"); // ****
            ClientTesting.SafeWait(ar);
            Assert.IsTrue(ar.IsCompleted, "isc1");
            svr.EndAcceptBluetoothClient(ar);
        }
示例#5
0
        public void HandleCONNECTERR()
        {
            var mockP = new Mock <MyCommonRfcommStream>();
            var p     = mockP.Object;
            var ports = new MyCommonRfcommStream[] { p };
            //---------------------
            var svr = CreateLsnr(ports, MockBehavior.Loose);

            svr.Construct(BluetoothService.CordlessTelephony); // ****
            svr.Start();                                       // ****
            var ar = svr.BeginAcceptBluetoothClient(null, null);

            Assert.IsFalse(ar.IsCompleted, "isc0");
            //--
            p.HandleCONNECT_ERR("Weeeee", null); // ****
            ClientTesting.SafeWait(ar);
            Assert.IsTrue(ar.IsCompleted, "isc1");
            try {
                svr.EndAcceptBluetoothClient(ar);
                Assert.Fail("should have thrown!");
            } catch (SocketException ex) {
                Assert.IsInstanceOfType(typeof(SocketException), ex);
            }
        }