static Stream DoStream(TestState state, bool?canRead, bool?canWrite) { var sMock = new Mock <Stream>(MockBehavior.Strict); state.AddMock(sMock); if (canRead.HasValue) { sMock.Setup(x => x.CanRead).Returns(canRead.Value); } if (canWrite.HasValue) { sMock.Setup(x => x.CanWrite).Returns(canWrite.Value); } return(sMock.Object); }
internal static TestState Init(Options options) { var state = new TestState(); // var aMock = new Mock <Android.Bluetooth.BluetoothAdapter>(MockBehavior.Strict); state.AddMock(aMock); //-- var dMock = new Mock <Android.Bluetooth.BluetoothDevice>(MockBehavior.Strict); state.AddMock(dMock); //-- // Socket Func <BluetoothSocket> setupSocketConnectStop = delegate() { var sMock = new Mock <BluetoothSocket>(MockBehavior.Strict); state.AddMock(sMock); if (GetValueOrReport(() => options.Connect)) { sMock.Setup(x => x.Connect()) ; //.Callback(doConnect); if (true) { bool gs = GetValueOrReport(() => options.GetStream1); //bool? gs = gsV ? true : (bool?)null; sMock.Setup(x => x.InputStream).Returns(DoInputStream(state, gs)); sMock.Setup(x => x.OutputStream).Returns(DoOutputStream(state, gs)); } } if (GetValueOrReport(() => options.ClientDispose)) { sMock.Setup(x => x.Close()).Callback(() => { }); } return(sMock.Object); }; // CreateSocket Moq.Language.Flow.ISetup <BluetoothDevice, BluetoothSocket> setupDeviceCreateSocket; if (GetValueOrReport(() => options.CreateSocket)) { if (GetValueOrReport(() => options.Insecure)) { setupDeviceCreateSocket = dMock.Setup(x => x.CreateInsecureRfcommSocketToServiceRecord( It.IsAny <UUID>())); // TODO ! } else { setupDeviceCreateSocket = dMock.Setup(x => x.CreateRfcommSocketToServiceRecord( It.IsAny <UUID>())); // TODO ! } setupDeviceCreateSocket.Returns(setupSocketConnectStop); } // BluetoothClass Func <BluetoothClass> setupDeviceGetClass = delegate { var cMock = new Mock <BluetoothClass>(); return(cMock.Object); }; // GetRemoteDevice //-Func<BluetoothDevice> setupAdapterGetDevice= delegate // Func <UUID> doUUID = () => { var uMock = new Mock <UUID>(Guid.Empty); return(uMock.Object); }; //---- // // Radio init aMock.Setup(x => x.Address).Returns("0000000000aa"); if (GetValueOrReport(() => options.GetRemoteDevice)) { // Device Init // TODO Have AndroidBtCli not need BondState/Class dMock.Setup(x => x.Address).Returns("0000000000dd"); //dMock.Setup(x => x.BondState).Returns((Bond)999); //dMock.Setup(x => x.BluetoothClass).Returns(setupDeviceGetClass); // Adapter init aMock.Setup(x => x.GetRemoteDevice( It.IsAny <string>())) //TODO .Returns(dMock.Object); } // var a = aMock.Object; //var f = new FooAndroidBthFactory(a); var fMock = new Mock <AndroidBthFactoryBase>(MockBehavior.Loose, a) { CallBase = true, }; fMock.Setup(x => x.ToJavaUuid(options.ExpectedSvcClass)) .Returns(doUUID); fMock.Setup(x => x.ToJavaUuid(It.IsAny <Guid>())) #if true .Throws(new AssertionException("Expected Service Class Guid not found."));