コード例 #1
0
        public async Task <IButtplugDevice> CreateDevice(IButtplugLogManager aLogManager, IButtplugDeviceImpl aDevice)
        {
            var device = new ButtplugDevice(aLogManager, _protocolType, aDevice);
            // Run initialization now, just to make sure we're ready to go when we hand the device back.
            // TODO should probably find a better cancellation token for this. Or like, any at all.
            await device.InitializeAsync(CancellationToken.None).ConfigureAwait(false);

            return(device);
        }
コード例 #2
0
        public async Task TestBaseDevice()
        {
            var logMgr  = new ButtplugLogManager();
            var devImpl = new TestDeviceImpl(logMgr, "Device");
            var dev     = new ButtplugDevice(logMgr, new TestProtocol(logMgr, devImpl), devImpl)
            {
                Index = 2,
            };

            await dev.InitializeAsync(default(CancellationToken));

            (await dev.ParseMessageAsync(new StopDeviceCmd(2), default(CancellationToken))).Should().BeOfType <Ok>();

            dev.Awaiting(async aDevice => await dev.ParseMessageAsync(new RotateCmd(2, new List <RotateCmd.RotateSubcommand>()), default(CancellationToken))).Should().Throw <ButtplugDeviceException>();

            dev.Disconnect();
            dev.Awaiting(async aDevice => await aDevice.ParseMessageAsync(new StopDeviceCmd(2), default(CancellationToken))).Should().Throw <ButtplugDeviceException>();
        }