本文整理汇总了C#中StubIFeedback类的典型用法代码示例。如果您正苦于以下问题:C# StubIFeedback类的具体用法?C# StubIFeedback怎么用?C# StubIFeedback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StubIFeedback类属于命名空间,在下文中一共展示了StubIFeedback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadAdaptersNameTooLongAsyncTest
public async Task LoadAdaptersNameTooLongAsyncTest()
{
//Arrange
var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "am-LoadAdaptersNameTooLongAsyncTest" };
Database.SetInitializer(new CreateFreshDbInitializer());
var logEntries = new List<LogEntry>();
var log = new StubIFeedback<LogEntry>
{
ReportAsyncT0CancellationToken = (e, c) =>
{
Console.WriteLine(e.ToString());
logEntries.Add(e);
return Task.FromResult(0);
}
};
var longNameAdapter = new StubZvsAdapter
{
AdapterGuidGet = () => Guid.Parse("a0f912a6-b8bb-406a-360f-1eb13f50aae4"),
NameGet = () => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque magna diam, pellentesque et orci eget, pellentesque iaculis odio. Ut ultrices est sapien, ac pellentesque odio malesuada a. Etiam in neque ullamcorper massa gravida ullamcorper vel a posuere.",
DescriptionGet = () => "",
OnSettingsCreatingAdapterSettingBuilder = (s) => Task.FromResult(0),
OnDeviceTypesCreatingDeviceTypeBuilder = (s) => Task.FromResult(0)
};
var adapterManager = new AdapterManager(new List<ZvsAdapter>() { longNameAdapter }, dbConnection, log);
//act
await adapterManager.StartAsync(CancellationToken.None);
//assert
Assert.IsTrue(logEntries.Count(o => o.Level == LogEntryLevel.Error) == 1, "Expected 1 error");
}
示例2: ConstructorNullArg2Test
public void ConstructorNullArg2Test()
{
//arrange
var fb = new StubIFeedback<LogEntry>();
var pm = new StubIPluginManager();
var connection = new UnitTestDbConnection();
var tr = new TriggerRunner(fb, new StubICommandProcessor(), connection);
var st = new StubScheduledTaskRunner(fb, new StubICommandProcessor(), connection, new StubITimeProvider());
//act
new ZvsEngine(fb, null, pm, connection, tr, st);
//assert - throws exception
}
示例3: ConstructorNullArg3Test
public void ConstructorNullArg3Test()
{
//arrange
var fb = new StubIFeedback<LogEntry>();
var am = new StubIAdapterManager();
var connection = new StubIEntityContextConnection();
var tr = new TriggerRunner(fb, new StubICommandProcessor(), connection);
var st = new StubScheduledTaskRunner(fb, new StubICommandProcessor(), connection, new StubITimeProvider());
//act
new ZvsEngine(fb, am, null, connection, tr, st);
//assert - throws exception
}
示例4: BadJavascriptTest
public async Task BadJavascriptTest()
{
//Arrange
var logEntries = new List<LogEntry>();
var log = new StubIFeedback<LogEntry>();
var cts = new CancellationTokenSource();
var runner = new JavaScriptRunner(log, new StubICommandProcessor(), new UnitTestDbConnection());
const string script = @"logInfo(a'unit test message');";
//Act
var result = await runner.ExecuteScriptAsync(script, cts.Token);
Console.WriteLine(result.Message);
//Assert
Assert.IsTrue(result.HasError, result.Message);
}
示例5: ReportWarningAsyncTest
public async Task ReportWarningAsyncTest()
{
LogEntry logEntry = null;
//Arrange
IFeedback<LogEntry> log = new StubIFeedback<LogEntry>
{
ReportAsyncT0CancellationToken = async (value, ct) =>
{
logEntry = value;
}
};
//Act
await log.ReportWarningAsync("Warning Message", CancellationToken.None);
//Assert
Assert.IsTrue(logEntry.Level == LogEntryLevel.Warn);
Assert.IsTrue(logEntry.Message.Equals("Warning Message"));
}
示例6: 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'");
}
示例7: RunSceneAsyncInvalidSceneTest
public async Task RunSceneAsyncInvalidSceneTest()
{
//Arrange
var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "Scene-RunSceneAsyncInvalidSceneTest" };
Database.SetInitializer(new CreateFreshDbInitializer());
var logEntries = new List<LogEntry>();
var ranstoredCommands = new List<int>();
var log = new StubIFeedback<LogEntry>
{
ReportAsyncT0CancellationToken = (e, c) =>
{
Console.WriteLine(e.ToString());
logEntries.Add(e);
return Task.FromResult(0);
}
};
var commandProcessor = new StubICommandProcessor
{
RunCommandAsyncNullableOfInt32StringStringCancellationToken = (commandId, argument, argument2, cancellationToken) =>
{
if (commandId.HasValue) ranstoredCommands.Add(commandId.Value);
return Task.FromResult(Result.ReportSuccess());
}
};
var cts = new CancellationTokenSource();
var sceneRunner = new SceneRunner(log, commandProcessor, dbConnection);
//Act
var result = await sceneRunner.RunSceneAsync(-1, cts.Token);
//Assert
Assert.IsTrue(result.HasError);
Assert.IsTrue(logEntries.All(o => o.Level == LogEntryLevel.Warn), "Expected only info type log entries");
Assert.IsTrue(ranstoredCommands.Count == 0, "Scene runner did not run the correct amount of commands.");
}
示例8: StartPath2
public async Task StartPath2()
{
//Arrange
LogEntry logEntry = null;
var log = new StubIFeedback<LogEntry>
{
ReportAsyncT0CancellationToken = (e, c) =>
{
Console.WriteLine(e.ToString());
logEntry = e;
return Task.FromResult(0);
}
};
var cts = new CancellationTokenSource();
var tm = new ChangeListener(log, new ZvsEntityContextConnection());
//Act
await tm.StartAsync(cts.Token);
await tm.StartAsync(cts.Token);
//Assert
Assert.IsTrue(logEntry.Level == LogEntryLevel.Warn);
}
示例9: StartPath1
public async Task StartPath1()
{
//Arrange
var logEntries = new List<LogEntry>();
var log = new StubIFeedback<LogEntry>
{
ReportAsyncT0CancellationToken = (e, c) =>
{
Console.WriteLine(e.ToString()); logEntries.Add(e);
return Task.FromResult(0);
}
};
var cts = new CancellationTokenSource();
var tm = new ScheduledTaskRunner(log, new StubICommandProcessor(), new ZvsEntityContextConnection(), new CurrentTimeProvider());
//Act
await tm.StartAsync(cts.Token);
//Assert
Assert.IsTrue(logEntries.All(o => o.Level == LogEntryLevel.Info), "Expected only info type log entries");
Assert.IsTrue(logEntries.Any(o => o.Message.Contains("started")), "Manger not started or word started not in the log.");
}
示例10: StartPath1
public async Task StartPath1()
{
//Arrange
LogEntry logEntry = null;
var log = new StubIFeedback<LogEntry>
{
ReportAsyncT0CancellationToken = (e, c) =>
{
Console.WriteLine(e.ToString()); logEntry = e;
return Task.FromResult(0);
}
};
var cts = new CancellationTokenSource();
var tm = new TriggerRunner(log, new StubICommandProcessor(), new ZvsEntityContextConnection());
//Act
await tm.StartAsync(cts.Token);
//Assert
Assert.IsTrue(logEntry.Level == LogEntryLevel.Info);
Assert.IsTrue(logEntry.Message.Contains("started"), "Manger not started or word started not in the log.");
}
示例11: DelayTest
public async Task DelayTest()
{
//Arrange
var logEntries = new List<LogEntry>();
var log = new StubIFeedback<LogEntry>
{
ReportAsyncT0CancellationToken = (e, c) =>
{
Console.WriteLine(e);
logEntries.Add(e);
return Task.FromResult(0);
}
};
var cts = new CancellationTokenSource();
var runner = new JavaScriptRunner(log, new StubICommandProcessor(), new UnitTestDbConnection());
const string script = @"
function delayTest() {
logInfo('start');
setTimeout('logInfo(\'end\');', 3000);
};
delayTest();";
//Act
var result = await runner.ExecuteScriptAsync(script, cts.Token);
//Assert
Assert.IsFalse(result.HasError, result.Message);
Assert.IsTrue(logEntries.Count == 2, "Wrong number of log entries!");
Assert.IsTrue(logEntries[1].Datetime - logEntries[0].Datetime >= TimeSpan.FromSeconds(3), "Delay was too short!");
}
示例12: ReportResultAsyncErrorTest
public async Task ReportResultAsyncErrorTest()
{
LogEntry logEntry = null;
//Arrange
IFeedback<LogEntry> log = new StubIFeedback<LogEntry>
{
ReportAsyncT0CancellationToken = (value, ct) =>
{
logEntry = value;
return Task.FromResult(0);
}
};
//Act
await log.ReportResultAsync(Result.ReportError("Message Body"), CancellationToken.None);
//Assert
Assert.IsTrue(logEntry.Level == LogEntryLevel.Error);
Assert.IsTrue(logEntry.Message.Equals("Message Body"));
}
示例13: LessThanInvalidValuesTest
public async Task LessThanInvalidValuesTest()
{
//Arrange
var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "Trigger-LessThanInvalidValuesTest" };
Database.SetInitializer(new CreateFreshDbInitializer());
var logEntries = new List<LogEntry>();
var ranstoredCommands = new List<int>();
var log = new StubIFeedback<LogEntry>
{
ReportAsyncT0CancellationToken = (e, c) =>
{
Console.WriteLine(e.ToString());
logEntries.Add(e);
return Task.FromResult(0);
}
};
var commandProcessor = new StubICommandProcessor
{
RunCommandAsyncNullableOfInt32StringStringCancellationToken = ( commandId, argument, argument2, cancellationToken) =>
{
if (commandId.HasValue) ranstoredCommands.Add(commandId.Value);
return Task.FromResult(Result.ReportSuccess());
}
};
Database.SetInitializer(new CreateFreshDbInitializer());
var cts = new CancellationTokenSource();
var triggerManager = new TriggerRunner(log, commandProcessor, dbConnection);
await triggerManager.StartAsync(cts.Token);
var cmd = new Command();
var dv = new DeviceValue
{
Value = "first value",
ValueType = DataType.STRING,
Triggers = new ObservableCollection<DeviceValueTrigger> {
new DeviceValueTrigger
{
Name = "trigger1",
IsEnabled = true,
Operator = TriggerOperator.LessThan,
Value = "a",
Command = cmd
} }
};
var device = UnitTesting.CreateFakeDevice();
device.Values.Add(dv);
using (var context = new ZvsContext(dbConnection))
{
context.Devices.Add(device);
var r = await context.TrySaveChangesAsync(cts.Token);
Assert.IsFalse(r.HasError, r.Message);
dv.Value = "3";
//Act
var r2 = await context.TrySaveChangesAsync(cts.Token);
Assert.IsFalse(r2.HasError, r2.Message);
}
await Task.Delay(700, cts.Token);
await triggerManager.StopAsync(cts.Token);
//Assert
Assert.IsTrue(logEntries.Any(o => o.Level == LogEntryLevel.Warn), "Expected some warning log entries");
Assert.IsTrue(ranstoredCommands.Count == 0, "Trigger runner did not run the correct amount of commands.");
}
示例14: StartAsyncTest
public async Task StartAsyncTest()
{
//arrange
var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "engine-StartAsyncTest" };
Database.SetInitializer(new CreateFreshDbInitializer());
var logEntries = new List<LogEntry>();
var log = new StubIFeedback<LogEntry>
{
ReportAsyncT0CancellationToken = (e, c) =>
{
Console.WriteLine(e.ToString());
logEntries.Add(e);
return Task.FromResult(0);
}
};
var isAdapterManagerInitialized = false;
var isPluginManagerInitialized = false;
var am = new StubIAdapterManager { StartAsyncCancellationToken = async (ct) =>isAdapterManagerInitialized = true };
var pm = new StubIPluginManager { StartAsyncCancellationToken = async (ct) => isPluginManagerInitialized = true };
var tr = new TriggerRunner(log, new StubICommandProcessor(), dbConnection);
var st = new ScheduledTaskRunner(log, new StubICommandProcessor(), dbConnection,new CurrentTimeProvider());
var engine = new ZvsEngine(log, am, pm, dbConnection, tr, st);
//Act
await engine.StartAsync(CancellationToken.None);
//assert
Assert.IsNotNull(engine);
Assert.IsTrue(isAdapterManagerInitialized, "Adapter manager was not started!");
Assert.IsTrue(isPluginManagerInitialized, "Plugin manager was not started!");
Assert.IsTrue(engine.ScheduledTaskRunner.IsRunning, "Scheduled Task Runner was not started!");
Assert.IsTrue(engine.TriggerRunner.IsRunning, "Trigger Runner was not started!");
}
示例15: RequireSyntaxErrorJavaScriptTest
public async Task RequireSyntaxErrorJavaScriptTest()
{
//Arrange
var logEntries = new List<LogEntry>();
var log = new StubIFeedback<LogEntry>
{
ReportAsyncT0CancellationToken = (e, c) =>
{
Console.WriteLine(e);
logEntries.Add(e);
return Task.FromResult(0);
}
};
var cts = new CancellationTokenSource();
var runner = new JavaScriptRunner(log, new StubICommandProcessor(), new UnitTestDbConnection());
const string script = @"
function f1() {
require('TestScript2.js');
};
f1();";
//Act
var result = await runner.ExecuteScriptAsync(script, cts.Token);
//Assert
Assert.IsFalse(result.HasError, result.Message);
Assert.IsTrue(logEntries.Any(o => o.Level == LogEntryLevel.Error), "Expected error log entry");
}