private static BlueSoleilSerialPortNetworkStream CreateConnectedStream(out BsTestNullApi api) { api = new BsTestNullApi(); api.SetIsOpen(); var fcty = new BluesoleilFactory(api); TestSerialPortWrapper port = new TestSerialPortWrapper(); UInt32 hConn = 0; var cli = (BluesoleilClient)fcty.DoGetBluetoothClient(); var conn = new BlueSoleilSerialPortNetworkStream(port, hConn, cli, fcty); return(conn); }
//-------- private static void Create_BtCli(out Mockery mkry, out IBluesoleilApi api, out BluesoleilFactory fcty, out IBluetoothClient cli) { mkry = new Mockery(); api = mkry.NewMock <IBluesoleilApi>(); // Expect.Exactly(2).On(api).Method("Btsdk_IsSDKInitialized") .WithAnyArguments() .Will(Return.Value(false)); Expect.Once.On(api).Method("Btsdk_IsServerConnected") .WithAnyArguments() .Will(Return.Value(false)); // Expect.AtLeastOnce.On(api).Method("Btsdk_Init") .WithAnyArguments() .Will(Return.Value(BtSdkError.OK)); // //Expect.AtLeastOnce.On(api).Method("Btsdk_IsBluetoothReady") // .WithAnyArguments() // .Will(Return.Value(true)); Expect.Once.On(api).Method("Btsdk_IsServerConnected") .WithAnyArguments() .Will(Return.Value(true)); Expect.Once.On(api).Method("Btsdk_IsBluetoothHardwareExisted") .WithAnyArguments() .Will(Return.Value(true)); Expect.AtLeastOnce.On(api).Method("Btsdk_IsSDKInitialized") .WithAnyArguments() .Will(Return.Value(true)); Expect.AtLeastOnce.On(api).Method("Btsdk_IsServerConnected") .WithAnyArguments() .Will(Return.Value(true)); // Expect.Once.On(api).Method("Btsdk_GetLocalDeviceAddress") .WithAnyArguments() .Will(Return.Value(BtSdkError.OK)); Expect.Once.On(api).Method("Btsdk_GetLocalName") .WithAnyArguments() .Will(Return.Value(BtSdkError.OK)); Expect.Once.On(api).Method("Btsdk_GetLocalDeviceClass") .With(Is.Out) .Will(Return.Value(BtSdkError.OK), new NMock2.Actions.SetIndexedParameterAction(0, (uint)0)); Expect.Once.On(api).Method("Btsdk_GetLocalLMPInfo") .WithAnyArguments() .Will(Return.Value(BtSdkError.OK)); // fcty = new BluesoleilFactory(api); mkry.VerifyAllExpectationsHaveBeenMet(); cli = fcty.DoGetBluetoothClient(); mkry.VerifyAllExpectationsHaveBeenMet(); }
void HackVerifyShutdown(Mockery mkry, IBluesoleilApi api, BluesoleilFactory fcty) { GC.KeepAlive(fcty); Expect.Once.On(api).Method("Btsdk_Disconnect") .WithAnyArguments() .Will(Return.Value(BtSdkError.OK)); #if true Expect.AtLeast(0).On(api).Method("Btsdk_Done") .WithAnyArguments() .Will(Return.Value(BtSdkError.OK)); // #else fcty = null; cli = null; Expect.Once.On(api).Method("Btsdk_Done") .WithAnyArguments() .Will(Return.Value(BtSdkError.OK)); WaitForFinalizers(); WaitForFinalizers(); mkry.VerifyAllExpectationsHaveBeenMet(); #endif }
private void ExpectNewWay(bool doMockSerialPort, out Mockery mkry, out IBluesoleilApi api, out BluesoleilFactory fcty, out IBluetoothClient cli, out UInt32 comSerialNum, out byte comPort8) { Create_BtCli(out mkry, out api, out fcty, out cli); if (doMockSerialPort) { ((BluesoleilClient)cli).CreateSerialPortMethod = delegate() { //var sp = mkry.NewMock<ISerialPortWrapper>(); var sp = new InTheHand.Net.Tests.BlueSoleil.TestSerialPortWrapper(); return(sp); }; } // ExpectConnectSetup(api); // UInt32 hDev = 0x123; ExpectGetDeviceInfo(api, hDev); //-- comSerialNum = 0x1000; UInt32 comPort = 250; comPort8 = checked ((byte)comPort); UInt32 hConn = 0x1000000; // Expect.Once.On(api).Method("Btsdk_GetASerialNum") .WithNoArguments() .Will(Return.Value(comSerialNum)); Expect.Once.On(api).Method("Btsdk_PlugInVComm") .WithAnyArguments() .Will(Return.Value(true), new NMock2.Actions.SetIndexedParameterAction(1, comPort)); Expect.Once.On(api).Method("Btsdk_InitCommObj") .WithAnyArguments() .Will(Return.Value(BtSdkError.OK)); Expect.Once.On(api).Method("Btsdk_ConnectEx") .WithAnyArguments() .Will(Return.Value(BtSdkError.OK), new NMock2.Actions.SetIndexedParameterAction(3, hConn) ); }