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


C# ZvsContext.SaveChangesAsync方法代码示例

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


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

示例1: RegisterAsyncNewDeviceValueTest

        public async Task RegisterAsyncNewDeviceValueTest()
        {
            //arrange 
            var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "dvb-RegisterAsyncNewDeviceValueTest" };
            Database.SetInitializer(new CreateFreshDbInitializer());

            var dvb = new DeviceValueBuilder( dbConnection);

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

                var deviceValue = new DeviceValue
                {
                    Description = "Testing Value Description Here",
                    Name = "Test Value",
                    ValueType = DataType.BOOL,
                    Value = true.ToString(),
                    DeviceId = device.Id
                };

                //act
                var result = await dvb.RegisterAsync(deviceValue, device, CancellationToken.None);
                var dv = await context.DeviceValues.FirstOrDefaultAsync(o => o.Name == deviceValue.Name);


                //assert 
                Assert.IsFalse(result.HasError, result.Message);
                Assert.IsNotNull(dv, "Registered device value count not be found in database.");
                Console.WriteLine(result.Message);
            }
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:34,代码来源:DeviceValueBuilderTests.cs

示例2: RegisterAsyncNewDeviceTypeTest

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

            var dtb = new DeviceTypeBuilder( dbConnection);
            var adapter = UnitTesting.CreateFakeAdapter();
            using (var context = new ZvsContext(dbConnection))
            {
                context.Adapters.Add(adapter);
                await context.SaveChangesAsync();
            }

            var dt = new DeviceType
            {
                AdapterId = adapter.Id,
                UniqueIdentifier = "UNIT_TEST_DEVICE_TYPE1",
                Name = "Unit Test Device Type"
            };

            //act
            var result = await dtb.RegisterAsync(adapter.AdapterGuid, dt, CancellationToken.None);

            //assert 
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError);
            Assert.IsTrue(dt.Id > 0, "Expected device type to have a database generated Id");
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:29,代码来源:DeviceTypeBuilderTests.cs

示例3: RegisterPluginSettingPluginTest

        public async Task RegisterPluginSettingPluginTest()
        {
            //Arrange 
            var dbConnection = new UnitTestDbConnection();
            Database.SetInitializer(new CreateFreshDbInitializer());
            var pluginBuilder = new PluginSettingBuilder(dbConnection, CancellationToken.None);
            var dbPlugin = UnitTesting.CreateFakePlugin();
            using (var context = new ZvsContext(dbConnection))
            {
                context.Plugins.Add(dbPlugin);
                await context.SaveChangesAsync();
            }
            var plugin = new StubUnitTestPlugin
            {
                PluginGuidGet = () => dbPlugin.PluginGuid
            };

            var pluginSetting = new PluginSetting
            {
                Name = "Plugin Setting 1",
                ValueType = DataType.STRING,
                Value = "Hello World"
            };
               
            //act
            var result = await pluginBuilder.Plugin(plugin).RegisterPluginSettingAsync(pluginSetting, o => o.PropertyTest);

            Plugin a;
            using (var context = new ZvsContext(dbConnection))
            {
                a = await context.Plugins
                    .Include(o=> o.Settings)
                    .FirstOrDefaultAsync(o => o.PluginGuid == dbPlugin.PluginGuid);
            }

            //assert 
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError);
            Assert.IsTrue(a.Settings.Count == 1, "Expected 1 plugin setting");
            Assert.IsTrue(a.Settings[0].Name == pluginSetting.Name, "Plugin setting name mismatch");
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:41,代码来源:PluginSettingBuilderTests.cs

示例4: RegisterAdapterSettingAdapterTest

        public async Task RegisterAdapterSettingAdapterTest()
        {
            //Arrange 
            var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "asb-RegisterAdapterSettingAdapterTest" };
            Database.SetInitializer(new CreateFreshDbInitializer());
            var adapterBuilder = new AdapterSettingBuilder(dbConnection, CancellationToken.None);
            var dbAdapter = UnitTesting.CreateFakeAdapter();
            using (var context = new ZvsContext(dbConnection))
            {
                context.Adapters.Add(dbAdapter);
                await context.SaveChangesAsync();
            }
            var adapter = new StubUnitTestAdapter
            {
                AdapterGuidGet = () => dbAdapter.AdapterGuid
            };

            var adapterSetting = new AdapterSetting
            {
                Name = "Adapter Setting 1",
                ValueType = DataType.STRING,
                Value = "Hello World"
            };
               
            //act
            var result = await adapterBuilder.Adapter(adapter).RegisterAdapterSettingAsync(adapterSetting, o => o.PropertyTest);

            Adapter a;
            using (var context = new ZvsContext(dbConnection))
            {
                a = await context.Adapters
                    .Include(o=> o.Settings)
                    .FirstOrDefaultAsync(o => o.AdapterGuid == dbAdapter.AdapterGuid);
            }

            //assert 
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError);
            Assert.IsTrue(a.Settings.Count == 1, "Expected 1 adapter setting");
            Assert.IsTrue(a.Settings[0].Name == adapterSetting.Name, "Adapter setting name mismatch");
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:41,代码来源:AdapterSettingBuilderTests.cs

示例5: RegisterAsyncAddNewCommandTest

        public async Task RegisterAsyncAddNewCommandTest()
        {
            //arrange 
            var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "dcb-RegisterAsyncAddNewCommandTest" };
            Database.SetInitializer(new CreateFreshDbInitializer());
            var dvb = new DeviceCommandBuilder( dbConnection);

            var device = UnitTesting.CreateFakeDevice();
            using (var context = new ZvsContext(dbConnection))
            {
                context.Devices.Add(device);
                await context.SaveChangesAsync();
            }

            var deviceCommand = new DeviceCommand()
            {
                Name = "Unit Testing Command"
            };
            
            //act
            var result = await dvb.RegisterAsync(device.Id, deviceCommand, CancellationToken.None);
            Console.WriteLine(result.Message);

            Device d;
            using (var context = new ZvsContext(dbConnection))
            {
                d = await context.Devices
                    .Include(o=> o.Commands)
                    .FirstOrDefaultAsync(o => o.Id == device.Id);
            }

            //assert 
            Assert.IsFalse(result.HasError, result.Message);
            Assert.IsNotNull(d, "device not found!");
            Assert.IsTrue(d.Commands.Count == 1, "Device has an unexpected number of commands");
            Assert.IsTrue(d.Commands[0].Name == deviceCommand.Name, "Device command did not save correctly");
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:37,代码来源:DeviceCommandBuilderTests.cs

示例6: RunSceneAsyncMultipleCommandCancelRunTest

        public async Task RunSceneAsyncMultipleCommandCancelRunTest()
        {
            //Arrange 
            var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "Scene-RunSceneAsyncMultipleCommandCancelRunTest" };
            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);
                    logEntries.Add(e);
                    return Task.FromResult(0);
                }
            };
            var cts = new CancellationTokenSource();
            var commandProcessor = new StubICommandProcessor
            {
                RunCommandAsyncNullableOfInt32StringStringCancellationToken = ( commandId, argument, argument2, cancellationToken) =>
                {
                    if (commandId.HasValue) ranstoredCommands.Add(commandId.Value);
                    if (ranstoredCommands.Count == 2)
                    {
                        cts.Cancel();
                    }

                    return Task.FromResult(Result.ReportSuccessFormat("Ran command Id:{0}", commandId));
                }
            };
            var scene = new Scene
            {
                Name = "I have one command"
            };

            var cmd1 = new Command
            {
                Description = "Command 1"
            };
            var command1 = new SceneStoredCommand
            {
                SortOrder = 1,
                TargetObjectName = "Device 1",
                Description = "Turn On Device 1",
                Command = cmd1
            };

            var cmd2 = new Command
            {
                Description = "Command 2"
            };
            var command2 = new SceneStoredCommand
            {
                SortOrder = 2,
                Description = "TIME DELAY",
                Command = cmd2
            };

            var cmd3 = new Command
            {
                Description = "Command 3"
            };
            var command3 = new SceneStoredCommand
            {
                SortOrder = 3,
                TargetObjectName = "Device 3",
                Description = "Turn On Device 3",
                Command = cmd3
            };

            scene.Commands.Add(command3);
            scene.Commands.Add(command1);
            scene.Commands.Add(command2);

            using (var context = new ZvsContext(dbConnection))
            {
                context.Scenes.Add(scene);
                await context.SaveChangesAsync(CancellationToken.None);
            }

           
            var sceneRunner = new SceneRunner(log, commandProcessor, dbConnection);

            //Act
            var result = await sceneRunner.RunSceneAsync(scene.Id, cts.Token);

            Console.WriteLine(result.Message);

            //Assert
            Assert.IsFalse(result.HasError);
            Assert.IsTrue(logEntries.Count(o => o.Level == LogEntryLevel.Warn) == 0, "Expected one warning log entries");
            Assert.IsTrue(logEntries.Count(o => o.Level == LogEntryLevel.Error) == 0, "Expected zero error log entries");
            Assert.IsTrue(ranstoredCommands.Count == 2, "Scene runner did not run the correct amount of commands.");
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:96,代码来源:SceneRunnerTests.cs

示例7: RegisterPluginSettingOptionRemovedTest

        public async Task RegisterPluginSettingOptionRemovedTest()
        {
            //Arrange 
            var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "asb-RegisterPluginSettingOptionRemovedTest" };
            Database.SetInitializer(new CreateFreshDbInitializer());
            var pluginBuilder = new PluginSettingBuilder( dbConnection, CancellationToken.None);
            var dbPlugin = UnitTesting.CreateFakePlugin();

            var pluginSetting = new PluginSetting
            {
                Name = "Plugin Setting 1",
                ValueType = DataType.STRING,
                Value = "Hello World",
                UniqueIdentifier = "PropertyTest"
            };
            dbPlugin.Settings.Add(pluginSetting);
            var option1 = new PluginSettingOption
            {
                Name = "Option 1",
            };
            var option2 = new PluginSettingOption
            {
                Name = "Option 2",
            };
            pluginSetting.Options.Add(option1);
            pluginSetting.Options.Add(option2);
            using (var context = new ZvsContext(dbConnection))
            {
                context.Plugins.Add(dbPlugin);
                await context.SaveChangesAsync();
            }
            var plugin = new StubUnitTestPlugin
            {
                PluginGuidGet = () => dbPlugin.PluginGuid
            };
            pluginSetting.Options.Remove(option2);

            //act
            var result = await pluginBuilder.Plugin(plugin).RegisterPluginSettingAsync(pluginSetting, o => o.PropertyTest);

            PluginSetting a;
            using (var context = new ZvsContext(dbConnection))
            {
                a = await context.PluginSettings
                    .Include(o => o.Options)
                    .FirstOrDefaultAsync(o => o.Id == pluginSetting.Id);
            }

            //assert 
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError);
            Assert.IsTrue(a.Options.Count == 1, "Expected 2 plugin setting options");
            Assert.IsTrue(a.Options[0].Name == option1.Name, "Plugin option name mismatch");
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:54,代码来源:PluginSettingBuilderTests.cs

示例8: RegisterAsyncNothingToUpdateTest

        public async Task RegisterAsyncNothingToUpdateTest()
        {
            //arrange 
            var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "dvb-RegisterAsyncNothingToUpdateTest" };
            Database.SetInitializer(new CreateFreshDbInitializer());

            var dvb = new DeviceValueBuilder(dbConnection);

            var device = UnitTesting.CreateFakeDevice();
            using (var context = new ZvsContext(dbConnection))
            {
                context.Devices.Add(device);
                var deviceValue = new DeviceValue
                {
                    UniqueIdentifier = "UNIT_TESTING_VALUE1",
                    CommandClass = "Command Class 1",
                    CustomData1 = "Custom Data 1",
                    CustomData2 = "Custom Data 2",
                    Description = "Testing Value Description Here",
                    Name = "Test Value",
                    ValueType = DataType.BOOL,
                    Value = true.ToString(),
                    Genre = "Genre",
                    Index = "Index",
                    IsReadOnly = true
                };
                device.Values.Add(deviceValue);
                await context.SaveChangesAsync();

                //act
                var result = await dvb.RegisterAsync(deviceValue, device, CancellationToken.None);
                var dv = await context.DeviceValues.FirstOrDefaultAsync(o => o.Name == deviceValue.Name);

                //assert 
                Assert.IsFalse(result.HasError, result.Message);
                Assert.IsNotNull(dv, "Registered device value count not be found in database.");
                Console.WriteLine(result.Message);
            }

        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:40,代码来源:DeviceValueBuilderTests.cs

示例9: RunCommandTest

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

            int? commandIdRan = 0;
            var arg1Ran = "";
            var arg2Ran = "";

            var commandProcessor = new StubICommandProcessor
            {
                RunCommandAsyncNullableOfInt32StringStringCancellationToken = (commandId, argument, argument2, cancellationToken) =>
                {
                    commandIdRan = commandId;
                    arg1Ran = argument;
                    arg2Ran = argument2;
                    return Task.FromResult(Result.ReportSuccess());
                }
            };
            var log = new StubIFeedback<LogEntry>
            {
                ReportAsyncT0CancellationToken = (e, c) =>
                {
                    Console.WriteLine(e);
                    return Task.FromResult(0);
                }
            };

            var device0 = UnitTesting.CreateFakeDevice();
            var device = UnitTesting.CreateFakeDevice();

            using (var context = new ZvsContext(dbConnection))
            {
                var deviceCommand = new DeviceCommand
                {
                    Name = "Turn On"
                };
                device.Commands.Add(deviceCommand);
                context.Devices.Add(device0);
                context.Devices.Add(device);
                await context.SaveChangesAsync(CancellationToken.None);

                var cts = new CancellationTokenSource();
                var runner = new JavaScriptRunner(log, commandProcessor, dbConnection);
                var script =
                    [email protected]"
function f1() {{ 
       var result = runCommand({deviceCommand.Id
                        },'98', '0'); 
       logInfo(result.Message);
}};
f1();";

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

                //Assert
                Assert.IsFalse(result.HasError, result.Message);
                Assert.IsTrue(deviceCommand.Id == commandIdRan, "Wrong command ran!");
                Assert.IsTrue("98" == arg1Ran, "command argument1 not passed in correctly.");
                Assert.IsTrue("0" == arg2Ran, "command argument2 not passed in correctly.");
            }
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:64,代码来源:JavaScriptRunnerTests.cs

示例10: StopWhenNotStartedTest

        public async Task StopWhenNotStartedTest()
        {
            //Arrange 
            var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "am-StopWhenNotStartedTest" };
            Database.SetInitializer(new CreateFreshDbInitializer());
            var logEntries = new List<LogEntry>();
            var log = new StubIFeedback<LogEntry>
            {
                ReportAsyncT0CancellationToken = (e, c) =>
                {
                    logEntries.Add(e);
                    Console.WriteLine(e.ToString());
                    return Task.FromResult(0);
                }
            };

            var adapter = new Adapter()
            {
                AdapterGuid = Guid.Parse("a0f912a6-b8bb-406a-360f-1eb13f50aae4"),
                IsEnabled = true
            };
            using (var context = new ZvsContext(dbConnection))
            {
                context.Adapters.Add(adapter);
                await context.SaveChangesAsync(CancellationToken.None);
            }
            var unitTestingAdapter = new StubUnitTestAdapter
            {
                AdapterGuidGet = () => Guid.Parse("a0f912a6-b8bb-406a-360f-1eb13f50aae4"),
                NameGet = () => "Unit Testing Adapter",
                DescriptionGet = () => "",
                OnDeviceTypesCreatingDeviceTypeBuilder = (s) => Task.FromResult(0)
               
            };

            var adapterManager = new AdapterManager(new List<ZvsAdapter> { unitTestingAdapter }, dbConnection, log);

            //act
            await adapterManager.StopAsync(CancellationToken.None);

            //assert 
            Assert.IsTrue(logEntries.Count(o => o.Level == LogEntryLevel.Warn) == 1);
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:43,代码来源:AdapterManagerTests.cs

示例11: LoadAdaptersAsyncAutoStartTest

        public async Task LoadAdaptersAsyncAutoStartTest()
        {
            //Arrange 
            var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "am-LoadAdaptersAsyncAutoStartTest" };
            Database.SetInitializer(new CreateFreshDbInitializer());

            var log = new StubIFeedback<LogEntry>
            {
                ReportAsyncT0CancellationToken = (e, c) =>
                {
                    Console.WriteLine(e.ToString());
                    return Task.FromResult(0);
                }
            };

            var adapter = new Adapter()
            {
                AdapterGuid = Guid.Parse("a0f912a6-b8bb-406a-360f-1eb13f50aae4"),
                IsEnabled = true
            };
            using (var context = new ZvsContext(dbConnection))
            {
                context.Adapters.Add(adapter);
                await context.SaveChangesAsync(CancellationToken.None);
            }
            var isStarted = false;
            var unitTestingAdapter = new StubUnitTestAdapter
            {
                AdapterGuidGet = () => Guid.Parse("a0f912a6-b8bb-406a-360f-1eb13f50aae4"),
                NameGet = () => "Unit Testing Adapter",
                DescriptionGet = () => "",
                OnDeviceTypesCreatingDeviceTypeBuilder = (s) => Task.FromResult(0),
                StartAsync01 = () =>
                {
                    isStarted = true;
                    return Task.FromResult(0);
                }
            };
            unitTestingAdapter.OnSettingsCreatingAdapterSettingBuilder = async (settingBuilder) =>
            {
                var testSetting = new AdapterSetting
                {
                    Name = "Test setting",
                    Value = 360.ToString(CultureInfo.InvariantCulture),
                    ValueType = DataType.INTEGER,
                    Description = "Unit testing only"
                };

                await
                    settingBuilder.Adapter(unitTestingAdapter)
                        .RegisterAdapterSettingAsync(testSetting, o => o.PropertyTest);
            };

            var adapterManager = new AdapterManager(new List<ZvsAdapter> { unitTestingAdapter }, dbConnection, log);

            //act
            await adapterManager.StartAsync(CancellationToken.None);

            //assert 
            Assert.IsTrue(isStarted, "Adapter not started!");
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:61,代码来源:AdapterManagerTests.cs

示例12: RegisterNoUpdateDeviceTypeSettingTest

        public async Task RegisterNoUpdateDeviceTypeSettingTest()
        {
            //Arrange 
            var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "asb-RegisterNoUpdateDeviceTypeSettingTest" };
            Database.SetInitializer(new CreateFreshDbInitializer());

            var adapterBuilder = new AdapterSettingBuilder(dbConnection, CancellationToken.None);
            var deviceType = UnitTesting.CreateFakeDeviceType();
            var deviceTypeSetting = new DeviceTypeSetting
            {
                Name = "Device Type Setting 1",
                ValueType = DataType.STRING,
                Value = "Hello World",
                DeviceType =  deviceType
            };

            using (var context = new ZvsContext(dbConnection))
            {
                context.DeviceTypeSettings.Add(deviceTypeSetting);
                await context.SaveChangesAsync();
            }

            //act
            var result = await adapterBuilder.RegisterDeviceTypeSettingAsync(deviceTypeSetting);

            DeviceTypeSetting setting;
            using (var context = new ZvsContext(dbConnection))
            {
                setting = await context.DeviceTypeSettings.FirstOrDefaultAsync();
            }

            //assert 
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError);
            Assert.IsNotNull(setting, "Setting not found");
            Assert.IsTrue(setting.Value == deviceTypeSetting.Value, "Device type setting name mismatch");
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:37,代码来源:AdapterSettingBuilderTests.cs

示例13: PurgeButton_Click

        private async void PurgeButton_Click(object sender, RoutedEventArgs e)
        {
            PurgeButton.IsEnabled = false;
            if (MessageBox.Show("Are you sure you want to delete all log entris in the database?",
                "Are you sure?", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
            {
                PurgeButton.IsEnabled = true;
                return;
            }

            using (var context = new ZvsContext(App.EntityContextConnection))
            {
                context.LogEntries.RemoveRange(context.LogEntries);
                await context.SaveChangesAsync(CancellationToken.None);
            }
            LogEntries.Clear();
            PurgeButton.IsEnabled = true;
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:18,代码来源:LogUserControl.xaml.cs

示例14: ValueChangeTest

        public async Task ValueChangeTest()
        {
            //arrange 
            var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "changelistener-ValueChangeTest" };
            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 cts = new CancellationTokenSource();
            var tm = new ChangeListener(log, dbConnection);

            //Act
            await tm.StartAsync(cts.Token);
            var device = UnitTesting.CreateFakeDevice();
            device.Values.Add(new DeviceValue
            {
                UniqueIdentifier = "DeviceTestValue1",
                Value = "0"
            });

            using (var context = new ZvsContext(dbConnection))
            {
                context.Devices.Add(device);
                await context.SaveChangesAsync(CancellationToken.None);
                device.Values.First().Value = "1";
                await context.SaveChangesAsync(CancellationToken.None);
            }
            await Task.Delay(100, CancellationToken.None);
            await tm.StopAsync(cts.Token);

            //Assert
            Assert.IsTrue(logEntries.Count == 3, "Unexpected number of log entries.");
            Assert.IsTrue(logEntries[1].Message.Contains("changed"), "Log message didn't contain changed.");
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:42,代码来源:ChangeListenerTests.cs

示例15: LoadPluginsAsyncAutoStartTest

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

            var log = new StubIFeedback<LogEntry>
            {
                ReportAsyncT0CancellationToken = (e, c) =>
                {
                    Console.WriteLine(e.ToString());
                    return Task.FromResult(0);
                }
            };

            var plugin = new Plugin()
            {
                PluginGuid = Guid.Parse("a0f912a6-b8bb-406a-360f-1eb13f50aae4"),
                IsEnabled = true
            };
            using (var context = new ZvsContext(dbConnection))
            {
                context.Plugins.Add(plugin);
                await context.SaveChangesAsync(CancellationToken.None);
            }
            var isStarted = false;
            var unitTestingPlugin = new StubUnitTestPlugin
            {
                PluginGuidGet = () => Guid.Parse("a0f912a6-b8bb-406a-360f-1eb13f50aae4"),
                NameGet = () => "Unit Testing Plugin",
                DescriptionGet = () => "",
                OnSettingsCreatingPluginSettingBuilder = s => Task.FromResult(0),
                OnDeviceSettingsCreatingDeviceSettingBuilder = s => Task.FromResult(0),
                OnSceneSettingsCreatingSceneSettingBuilder = s => Task.FromResult(0),
                StartAsync01 = () =>
                {
                    isStarted = true;
                    return Task.FromResult(0);
                }
            };
            unitTestingPlugin.OnSettingsCreatingPluginSettingBuilder = async settingBuilder =>
            {
                var testSetting = new PluginSetting
                {
                    Name = "Test setting",
                    Value = 360.ToString(CultureInfo.InvariantCulture),
                    ValueType = DataType.INTEGER,
                    Description = "Unit testing only"
                };

                await
                    settingBuilder.Plugin(unitTestingPlugin)
                        .RegisterPluginSettingAsync(testSetting, o => o.PropertyTest);
            };

            var pluginManager = new PluginManager(new List<ZvsPlugin> { unitTestingPlugin }, dbConnection, log, new StubIAdapterManager());

            //act
            await pluginManager.StartAsync(CancellationToken.None);

            //assert 
            Assert.IsTrue(isStarted, "Plugin not started!");
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:63,代码来源:PluginManagerTests.cs


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