当前位置: 首页>>代码示例>>C#>>正文


C# CommandProcessor.ExecuteBuiltinCommandAsync方法代码示例

本文整理汇总了C#中CommandProcessor.ExecuteBuiltinCommandAsync方法的典型用法代码示例。如果您正苦于以下问题:C# CommandProcessor.ExecuteBuiltinCommandAsync方法的具体用法?C# CommandProcessor.ExecuteBuiltinCommandAsync怎么用?C# CommandProcessor.ExecuteBuiltinCommandAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CommandProcessor的用法示例。


在下文中一共展示了CommandProcessor.ExecuteBuiltinCommandAsync方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecuteBuiltinCommandAsyncSceneTest

        public async Task ExecuteBuiltinCommandAsyncSceneTest()
        {
            //Arrange 
            var dbConnection = new UnitTestDbConnection();
            Database.SetInitializer(new CreateFreshDbInitializer());

            var deviceCommandIds = new List<int>();
            var adapterManager = new StubIAdapterManager
            {
                FindZvsAdapterGuid = adapterGuid => new StubZvsAdapter
                {
                    IsEnabled = true,
                    ProcessDeviceCommandAsyncDeviceDeviceCommandStringString = async (adapterDevice, command, argument, argument2) => deviceCommandIds.Add(command.Id)
                }
            };
            var log = new StubIFeedback<LogEntry>
            {
                ReportAsyncT0CancellationToken = (e, c) =>
                {
                    Console.WriteLine(e);
                    return Task.FromResult(0);
                }
            };

            var cts = new CancellationTokenSource();
            var commmandProcessor = new CommandProcessor(adapterManager, dbConnection, log);

            var device = UnitTesting.CreateFakeDevice();
            using (var context = new ZvsContext(dbConnection))
            {
                var deviceCommand = new DeviceCommand
                {
                    Name = "Turn On"
                };
                device.Commands.Add(deviceCommand);
                context.Devices.Add(device);

                var scene = new Scene
                {
                    Name = "Test Scene"
                };
                scene.Commands.Add(new SceneStoredCommand
                {
                    Command = deviceCommand,
                    Argument = "0"
                });
                context.Scenes.Add(scene);

                var builtinCommand = new BuiltinCommand
                {
                    Name = "Activate Scene",
                    UniqueIdentifier = "RUN_SCENE"
                };
                context.Commands.Add(builtinCommand);
                await context.SaveChangesAsync(new CancellationToken());

                //Act
                var result = await commmandProcessor.ExecuteBuiltinCommandAsync(builtinCommand, scene.Id.ToString(CultureInfo.InvariantCulture), "", cts.Token);
                Console.WriteLine(result.Message);

                //Assert
                Assert.IsFalse(result.HasError);
                Assert.IsTrue(deviceCommandIds.Count == 1, "Process did not run the correct amount of commands.");
                Assert.IsTrue(deviceCommand.Id == deviceCommandIds[0], "Ran the wrong scene!");
            }
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:66,代码来源:CommandProcessorTests.cs

示例2: ExecuteBuiltinCommandAsyncUnknownCommandTest

        public async Task ExecuteBuiltinCommandAsyncUnknownCommandTest()
        {
            //Arrange 
            var dbConnection = new UnitTestDbConnection();
            Database.SetInitializer(new CreateFreshDbInitializer());

            var deviceCommandIds = new List<int>();
            var adapterManager = new StubIAdapterManager();
            var log = new StubIFeedback<LogEntry>();

            var cts = new CancellationTokenSource();
            var commmandProcessor = new CommandProcessor(adapterManager, dbConnection, log);

            using (var context = new ZvsContext(dbConnection))
            {
                var builtinCommand = new BuiltinCommand
                {
                    Name = "Unknown Built-in Command",
                    UniqueIdentifier = "UNKNOWN_COMMAND_TYPE"
                };
                context.Commands.Add(builtinCommand);
                await context.SaveChangesAsync(new CancellationToken());

                //Act
                var result = await commmandProcessor.ExecuteBuiltinCommandAsync(builtinCommand, "", "", cts.Token);
                Console.WriteLine(result.Message);

                //Assert
                Assert.IsTrue(result.HasError);
                Assert.IsTrue(deviceCommandIds.Count == 0, "Process did not run the correct amount of commands.");
            }
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:32,代码来源:CommandProcessorTests.cs

示例3: ExecuteBuiltinCommandAsyncGroupOnNoDevicesTest

        public async Task ExecuteBuiltinCommandAsyncGroupOnNoDevicesTest()
        {
            //Arrange 
            var dbConnection = new UnitTestDbConnection();
            Database.SetInitializer(new CreateFreshDbInitializer());

            var groupOnIdsRequestSentToAdapter = new List<Group>();
            var adapterManager = new StubIAdapterManager
            {
                FindZvsAdapterGuid = adapterGuid => new StubZvsAdapter
                {
                    IsEnabled = true,
                    ActivateGroupAsyncGroup = async g => groupOnIdsRequestSentToAdapter.Add(g)
                }
            };
            var log = new StubIFeedback<LogEntry>();
            var cts = new CancellationTokenSource();
            var commmandProcessor = new CommandProcessor(adapterManager, dbConnection, log);

            using (var context = new ZvsContext(dbConnection))
            {
                var group = new Group
                {
                    Name = "Test Group"
                };
                context.Groups.Add(group);

                var builtinCommand = new BuiltinCommand
                {
                    Name = "Turn on a Group",
                    UniqueIdentifier = "GROUP_ON"
                };
                context.Commands.Add(builtinCommand);
                await context.SaveChangesAsync(new CancellationToken());

                //Act
                var result =
                    await
                        commmandProcessor.ExecuteBuiltinCommandAsync(builtinCommand,
                            group.Id.ToString(CultureInfo.InvariantCulture), "", cts.Token);
                Console.WriteLine(result.Message);

                //Assert
                Assert.IsTrue(result.HasError);
                Assert.IsTrue(result.Message.Contains("no devices found "), "Expected to see 'no devices found' in log when executed group with no devices");
            }
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:47,代码来源:CommandProcessorTests.cs

示例4: ExecuteBuiltinCommandAsyncGroupOffTest

        public async Task ExecuteBuiltinCommandAsyncGroupOffTest()
        {
            //Arrange 
            var dbConnection = new UnitTestDbConnection();
            Database.SetInitializer(new CreateFreshDbInitializer());

            var groupOnIdsRequestSentToAdapter = new List<Group>();
            var adapterManager = new StubIAdapterManager
            {
                FindZvsAdapterGuid = adapterGuid => new StubZvsAdapter
                {
                    IsEnabled = true,
                    DeactivateGroupAsyncGroup = async g => groupOnIdsRequestSentToAdapter.Add(g)
                }
            };
            var log = new StubIFeedback<LogEntry>();
            var cts = new CancellationTokenSource();
            var commmandProcessor = new CommandProcessor(adapterManager, dbConnection, log);

            var device = UnitTesting.CreateFakeDevice();
            var device2 = UnitTesting.CreateFakeDevice();
            var device3 = UnitTesting.CreateFakeDevice();
            using (var context = new ZvsContext(dbConnection))
            {
                context.Devices.Add(device);
                context.Devices.Add(device2);
                context.Devices.Add(device3);

                var group = new Group
                {
                    Name = "Test Group"
                };
                group.Devices.Add(device);
                group.Devices.Add(device2);
                context.Groups.Add(group);

                var builtinCommand = new BuiltinCommand
                {
                    Name = "Turn off Group",
                    UniqueIdentifier = "GROUP_OFF"
                };
                context.Commands.Add(builtinCommand);
                await context.SaveChangesAsync(new CancellationToken());

                //Act
                var result = await commmandProcessor.ExecuteBuiltinCommandAsync(builtinCommand, group.Id.ToString(CultureInfo.InvariantCulture), "", cts.Token);
                Console.WriteLine(result.Message);

                //Assert
                Assert.IsFalse(result.HasError);
                Assert.IsTrue(groupOnIdsRequestSentToAdapter.Count == 2, "Process did not run the correct amount of commands.");
                Assert.IsTrue(group.Id == groupOnIdsRequestSentToAdapter[0].Id, "Ran the wrong group!");
            }
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:54,代码来源:CommandProcessorTests.cs

示例5: ExecuteBuiltinCommandAsyncGroupOnBadIdTest

        public async Task ExecuteBuiltinCommandAsyncGroupOnBadIdTest()
        {
            //Arrange 
            var dbConnection = new UnitTestDbConnection();
            Database.SetInitializer(new CreateFreshDbInitializer());

            var adapterManager = new StubIAdapterManager();
            var log = new StubIFeedback<LogEntry>();
            var cts = new CancellationTokenSource();
            var commmandProcessor = new CommandProcessor(adapterManager, dbConnection, log);

            var device = UnitTesting.CreateFakeDevice();
            var device2 = UnitTesting.CreateFakeDevice();
            using (var context = new ZvsContext(dbConnection))
            {
                context.Devices.Add(device);
                var builtinCommand = new BuiltinCommand
                {
                    UniqueIdentifier = "GROUP_ON"
                };
                context.Commands.Add(builtinCommand);
                await context.SaveChangesAsync(new CancellationToken());

                //Act
                var result = await commmandProcessor.ExecuteBuiltinCommandAsync(builtinCommand, "0", "", cts.Token);
                Console.WriteLine(result.Message);

                //Assert
                Assert.IsTrue(result.HasError);
                Assert.IsTrue(result.Message.Contains("Invalid group"), "Expected to see 'Invalid group' in log");
            }
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:32,代码来源:CommandProcessorTests.cs

示例6: ExecuteBuiltinCommandAsyncRepollAllTest

        public async Task ExecuteBuiltinCommandAsyncRepollAllTest()
        {
            //Arrange 
            var dbConnection = new UnitTestDbConnection();
            Database.SetInitializer(new CreateFreshDbInitializer());

            var repollDeviceIdRequestSentToAdapter = new List<int>();
            var adapterManager = new StubIAdapterManager
            {
                FindZvsAdapterGuid = adapterGuid => new StubZvsAdapter
                {
                    IsEnabled = true,
                    RepollAsyncDevice = async d => repollDeviceIdRequestSentToAdapter.Add(d.Id)
                }
            };
            var log = new StubIFeedback<LogEntry>();
            var cts = new CancellationTokenSource();
            var commmandProcessor = new CommandProcessor(adapterManager, dbConnection, log);

            var device = UnitTesting.CreateFakeDevice();
            var device2 = UnitTesting.CreateFakeDevice();
            using (var context = new ZvsContext(dbConnection))
            {
                context.Devices.Add(device);
                context.Devices.Add(device2);
                var builtinCommand = new BuiltinCommand
                {
                    Name = "Repoll all",
                    UniqueIdentifier = "REPOLL_ALL"
                };
                context.Commands.Add(builtinCommand);
                await context.SaveChangesAsync(new CancellationToken());

                //Act
                var result = await commmandProcessor.ExecuteBuiltinCommandAsync(builtinCommand, device.Id.ToString(CultureInfo.InvariantCulture), "", cts.Token);
                Console.WriteLine(result.Message);

                //Assert
                Assert.IsFalse(result.HasError);
                Assert.IsTrue(repollDeviceIdRequestSentToAdapter.Count == 2, "Process did not run the correct amount of commands.");
                Assert.IsTrue(repollDeviceIdRequestSentToAdapter[0] == device.Id, "Wrong command processed");
                Assert.IsTrue(repollDeviceIdRequestSentToAdapter[1] == device2.Id, "Wrong command processed");
            }
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:44,代码来源:CommandProcessorTests.cs

示例7: ExecuteBuiltinCommandInvlaidDeviceIdAsyncRepollMeTest

        public async Task ExecuteBuiltinCommandInvlaidDeviceIdAsyncRepollMeTest()
        {
            //Arrange 
            var dbConnection = new UnitTestDbConnection();
            Database.SetInitializer(new CreateFreshDbInitializer());

            var repollDeviceIdRequestSentToAdapter = new List<int>();
            var adapterManager = new StubIAdapterManager
            {
                FindZvsAdapterGuid = adapterGuid => new StubZvsAdapter
                {
                    IsEnabled = true,
                    RepollAsyncDevice = async d => repollDeviceIdRequestSentToAdapter.Add(d.Id)
                }
            };
            var log = new StubIFeedback<LogEntry>();
            var cts = new CancellationTokenSource();
            var commmandProcessor = new CommandProcessor(adapterManager, dbConnection, log);

            using (var context = new ZvsContext(dbConnection))
            {
                var builtinCommand = new BuiltinCommand
                {
                    UniqueIdentifier = "REPOLL_ME"
                };
                context.Commands.Add(builtinCommand);
                await context.SaveChangesAsync(new CancellationToken());

                //Act
                var result = await commmandProcessor.ExecuteBuiltinCommandAsync(builtinCommand, 12.ToString(CultureInfo.InvariantCulture), "", cts.Token);
                Console.WriteLine(result.Message);

                //Assert
                Assert.IsTrue(result.HasError);
                Assert.IsTrue(result.Message.Contains("Cannot find device "), "Expect error message to contain 'Cannot find device '");
            }
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:37,代码来源:CommandProcessorTests.cs

示例8: ExecuteBuiltinCommandAsyncRepollDisabledAdapterMeTest

        public async Task ExecuteBuiltinCommandAsyncRepollDisabledAdapterMeTest()
        {
            //Arrange 
            var dbConnection = new UnitTestDbConnection();
            Database.SetInitializer(new CreateFreshDbInitializer());

            var adapterManager = new StubIAdapterManager
            {
                FindZvsAdapterGuid = adapterGuid => new StubZvsAdapter
                {
                    IsEnabled = false,
                }
            };
            var log = new StubIFeedback<LogEntry>();
            var cts = new CancellationTokenSource();
            var commmandProcessor = new CommandProcessor(adapterManager, dbConnection, log);

            var device = UnitTesting.CreateFakeDevice();
            using (var context = new ZvsContext(dbConnection))
            {
                context.Devices.Add(device);
                var builtinCommand = new BuiltinCommand
                {
                    UniqueIdentifier = "REPOLL_ME"
                };
                context.Commands.Add(builtinCommand);
                await context.SaveChangesAsync(new CancellationToken());

                //Act
                var result = await commmandProcessor.ExecuteBuiltinCommandAsync(builtinCommand, device.Id.ToString(CultureInfo.InvariantCulture), "", cts.Token);
                Console.WriteLine(result.Message);

                //Assert
                Assert.IsTrue(result.HasError);
                Assert.IsTrue(result.Message.Contains("adapter is disabled"), "Expect error message to contain 'adapter is disabled'");
            }
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:37,代码来源:CommandProcessorTests.cs

示例9: ExecuteBuiltinCommandAsyncTimeDelayTest

        public async Task ExecuteBuiltinCommandAsyncTimeDelayTest()
        {
            //Arrange 
            var dbConnection = new UnitTestDbConnection();
            Database.SetInitializer(new CreateFreshDbInitializer());

            var adapterManager = new StubIAdapterManager();
            var log = new StubIFeedback<LogEntry>();
            var cts = new CancellationTokenSource();
            var commmandProcessor = new CommandProcessor(adapterManager, dbConnection, log);

            using (var context = new ZvsContext(dbConnection))
            {
                var builtinCommand = new BuiltinCommand
                {
                    UniqueIdentifier = "TIMEDELAY"
                };
                context.Commands.Add(builtinCommand);
                await context.SaveChangesAsync(new CancellationToken());
                var sw = new Stopwatch();

                //Act
                sw.Start();
                var result = await commmandProcessor.ExecuteBuiltinCommandAsync(builtinCommand, "1", "", cts.Token);
                sw.Stop();

                Console.WriteLine(result.Message);

                //Assert
                Assert.IsFalse(result.HasError);
                Assert.IsFalse(sw.Elapsed < TimeSpan.FromMilliseconds(1000), "Time delay was not long enough");
                Assert.IsFalse(sw.Elapsed > TimeSpan.FromMilliseconds(1300), "Time delay was too long");
            }
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:34,代码来源:CommandProcessorTests.cs


注:本文中的CommandProcessor.ExecuteBuiltinCommandAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。