本文整理汇总了C#中CommandProcessor.ExecuteDeviceTypeCommandAsync方法的典型用法代码示例。如果您正苦于以下问题:C# CommandProcessor.ExecuteDeviceTypeCommandAsync方法的具体用法?C# CommandProcessor.ExecuteDeviceTypeCommandAsync怎么用?C# CommandProcessor.ExecuteDeviceTypeCommandAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommandProcessor
的用法示例。
在下文中一共展示了CommandProcessor.ExecuteDeviceTypeCommandAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteDeviceTypeCommandAsyncAdapterNotEnabledTest
public async Task ExecuteDeviceTypeCommandAsyncAdapterNotEnabledTest()
{
//Arrange
var dbConnection = new UnitTestDbConnection();
Database.SetInitializer(new CreateFreshDbInitializer());
var adapterManager = new StubIAdapterManager
{
FindZvsAdapterGuid = adapterGuid => new StubZvsAdapter
{
IsEnabled = false,
}
};
var ranstoredCommands = new List<int>();
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))
{
var deviceTypeCommand = new DeviceTypeCommand
{
Name = "Turn On"
};
device.Type.Commands.Add(deviceTypeCommand);
context.Devices.Add(device);
await context.SaveChangesAsync(CancellationToken.None);
//Act
var result = await commmandProcessor.ExecuteDeviceTypeCommandAsync(deviceTypeCommand, "", device.Id.ToString(CultureInfo.InvariantCulture), cts.Token);
Console.WriteLine(result.Message);
//Assert
Assert.IsTrue(result.HasError);
Assert.IsTrue(ranstoredCommands.Count == 0, "Process did not run the correct amount of commands.");
Assert.IsTrue(result.Message.Contains("adapter is disabled"), "Expect error message to contain 'adapter is disabled'");
}
}
示例2: ExecuteDeviceTypeCommandAsyncOkTest
public async Task ExecuteDeviceTypeCommandAsyncOkTest()
{
//Arrange
var dbConnection = new UnitTestDbConnection();
Database.SetInitializer(new CreateFreshDbInitializer());
var commandsSendToAdapter = new List<int>();
var adapterManager = new StubIAdapterManager
{
FindZvsAdapterGuid = adapterGuid => new StubZvsAdapter
{
IsEnabled = true,
ProcessDeviceTypeCommandAsyncDeviceTypeDeviceDeviceTypeCommandString = async (adapterDevice, command, argument, argument2) => commandsSendToAdapter.Add(command.Id)
}
};
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))
{
var deviceTypeCommand = new DeviceTypeCommand
{
Name = "Turn On"
};
device.Type.Commands.Add(deviceTypeCommand);
context.Devices.Add(device);
await context.SaveChangesAsync(CancellationToken.None);
//Act
var result = await commmandProcessor.ExecuteDeviceTypeCommandAsync(deviceTypeCommand, "1", device.Id.ToString(CultureInfo.InvariantCulture), cts.Token);
Console.WriteLine(result.Message);
//Assert
Assert.IsFalse(result.HasError);
Assert.IsTrue(commandsSendToAdapter.Count == 1, "Process did not run the correct amount of commands.");
Assert.IsTrue(commandsSendToAdapter[0] == deviceTypeCommand.Id, "Wrong command processed");
}
}
示例3: ExecuteDeviceTypeCommandAsyncInvalidIdTest
public async Task ExecuteDeviceTypeCommandAsyncInvalidIdTest()
{
//Arrange
var dbConnection = new UnitTestDbConnection();
Database.SetInitializer(new CreateFreshDbInitializer());
var adapterManager = new StubIAdapterManager();
var ranstoredCommands = new List<int>();
var log = new StubIFeedback<LogEntry>();
var cts = new CancellationTokenSource();
var commmandProcessor = new CommandProcessor(adapterManager, dbConnection, log);
//Act
var result = await commmandProcessor.ExecuteDeviceTypeCommandAsync(new DeviceTypeCommand(), "", "", cts.Token);
Console.WriteLine(result.Message);
//Assert
Assert.IsTrue(result.HasError);
Assert.IsTrue(ranstoredCommands.Count == 0, "Process did not run the correct amount of commands.");
Assert.IsTrue(result.Message.Contains("Cannot find device"), "Expect error message to contain 'Cannot find device'");
}