本文整理汇总了C#中CommandProcessor.ExecuteDeviceCommandAsync方法的典型用法代码示例。如果您正苦于以下问题:C# CommandProcessor.ExecuteDeviceCommandAsync方法的具体用法?C# CommandProcessor.ExecuteDeviceCommandAsync怎么用?C# CommandProcessor.ExecuteDeviceCommandAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommandProcessor
的用法示例。
在下文中一共展示了CommandProcessor.ExecuteDeviceCommandAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteDeviceCommandAsyncInvalidIdTest
public async Task ExecuteDeviceCommandAsyncInvalidIdTest()
{
//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.ExecuteDeviceCommandAsync(new DeviceCommand(), "", "", 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 locate"), "Expect error message to contain 'Cannot locate'");
}
示例2: ExecuteDeviceCommandAsyncAdapterNotLoadedTest
public async Task ExecuteDeviceCommandAsyncAdapterNotLoadedTest()
{
//Arrange
var dbConnection = new UnitTestDbConnection();
Database.SetInitializer(new CreateFreshDbInitializer());
var adapterManager = new StubIAdapterManager
{
FindZvsAdapterGuid = adapterGuid => null
};
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 deviceCommand = new DeviceCommand
{
Name = "Turn On"
};
device.Commands.Add(deviceCommand);
context.Devices.Add(device);
await context.SaveChangesAsync(CancellationToken.None);
//Act
var result = await commmandProcessor.ExecuteDeviceCommandAsync(deviceCommand, "1", "", 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("not loaded"), "Expect error message to contain 'not loaded'");
}
}
示例3: ExecuteDeviceCommandAsyncOkTest
public async Task ExecuteDeviceCommandAsyncOkTest()
{
//Arrange
var dbConnection = new UnitTestDbConnection();
Database.SetInitializer(new CreateFreshDbInitializer());
var commandsSendToAdapter = new List<int>();
var adapterManager = new StubIAdapterManager
{
FindZvsAdapterGuid = adapterGuid => new StubZvsAdapter
{
IsEnabled = true,
ProcessDeviceCommandAsyncDeviceDeviceCommandStringString = (adapterDevice, command, argument, argument2) =>
{
commandsSendToAdapter.Add(command.Id);
return Task.FromResult(0);
}
}
};
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 deviceCommand = new DeviceCommand
{
Name = "Turn On"
};
device.Commands.Add(deviceCommand);
context.Devices.Add(device);
await context.SaveChangesAsync(CancellationToken.None);
//Act
var result = await commmandProcessor.ExecuteDeviceCommandAsync(deviceCommand, "1", "", 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] == deviceCommand.Id, "Wrong command processed");
}
}