• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# StubIFeedback类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中StubIFeedback的典型用法代码示例。如果您正苦于以下问题:C# StubIFeedback类的具体用法?C# StubIFeedback怎么用?C# StubIFeedback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



StubIFeedback类属于命名空间,在下文中一共展示了StubIFeedback类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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");
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:33,代码来源:AdapterManagerTests.cs


示例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
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:13,代码来源:ZvsEngineTests.cs


示例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
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:13,代码来源:ZvsEngineTests.cs


示例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);
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:15,代码来源:JavaScriptRunnerTests.cs


示例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"));
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:19,代码来源:FeedbackExtensionMethodTests.cs


示例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'");
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:21,代码来源:CommandProcessorTests.cs


示例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.");
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:39,代码来源:SceneRunnerTests.cs


示例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);
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:22,代码来源:ChangeListenerTests.cs


示例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.");
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:22,代码来源:ScheduledTaskRunnerTests.cs


示例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.");
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:22,代码来源:TriggerRunnerTests.cs


示例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!");
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:31,代码来源:JavaScriptRunnerTests.cs


示例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"));
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:20,代码来源:FeedbackExtensionMethodTests.cs


示例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.");
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:72,代码来源:TriggerRunnerTests.cs


示例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!");
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:38,代码来源:ZvsEngineTests.cs


示例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");

        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:29,代码来源:JavaScriptRunnerTests.cs


示例16: ActivateTriggerAsyncTest

        public async Task ActivateTriggerAsyncTest()
        {
            //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.ActivateTriggerAsync(0, cts.Token);

            //Assert
            Assert.IsTrue(logEntry == null);
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:21,代码来源:TriggerRunnerTests.cs


示例17: ConstructorNullArg6Test

        public void ConstructorNullArg6Test()
        {
            //arrange 
            var fb = new StubIFeedback<LogEntry>();
            var am = new StubIAdapterManager();
            var pm = new StubIPluginManager();
            var connection = new StubIEntityContextConnection();
            var tr = new TriggerRunner(fb, new StubICommandProcessor(), connection);

            //act
            new ZvsEngine(fb, am, pm, connection, tr, null);
            //assert - throws exception
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:13,代码来源:ZvsEngineTests.cs


示例18: ReportInfoTest

        public async Task ReportInfoTest()
        {
            //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 = @"logInfo('unit test message');";

            //Act
            var result = await runner.ExecuteScriptAsync(script, cts.Token);

            //Assert
            Assert.IsFalse(result.HasError, result.Message);
            Assert.IsTrue(logEntries.Count == 1, "Wrong number of log entries!");
            Assert.IsTrue(logEntries[0].Level == LogEntryLevel.Info, "Wrong log entry level!");
            Assert.IsTrue(logEntries[0].Message == "unit test message", "Wrong log message!");
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:27,代码来源:JavaScriptRunnerTests.cs


示例19: ShellTest

        public async Task ShellTest()
        {
            //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 = @"
function f1() { 
       var proc = shell('cmd.exe', 'dir');        
};
f1();";

            //using (ShimsContext.Create())
            // {
            //  ShimProcess.StartString = s =>
            //{
            //     Console.WriteLine(s);
            //  return new StubProcess();
            //};
            //Act
            var result = await runner.ExecuteScriptAsync(script, cts.Token);

            //Assert
            Assert.IsFalse(result.HasError, result.Message);

            //}
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:29,代码来源:JavaScriptRunnerTests.cs


示例20: MapPathTest

        public async Task MapPathTest()
        {
            //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 expected = Path.Combine(Utils.AppPath, "/test");
            var cts = new CancellationTokenSource();
            var runner = new JavaScriptRunner(log, new StubICommandProcessor(), new UnitTestDbConnection());
            const string script = @"
function f1() { 
       var path = mappath('/test');  
logInfo(path);      
};
f1();";

            //Act
            var result = await runner.ExecuteScriptAsync(script, cts.Token);

            //Assert
            Assert.IsFalse(result.HasError, result.Message);
            Assert.IsTrue(logEntries.Count == 1, "Expected 1 log entry");
            Assert.IsTrue(expected == logEntries[0].Message, "Unexpected path...");

        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:32,代码来源:JavaScriptRunnerTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# StubLoaders类代码示例发布时间:2022-05-24
下一篇:
C# StubIEntityContextConnection类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap