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


C# StubIEntityContextConnection类代码示例

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


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

示例1: LogEntrySingleContextLimitTest

        public async Task LogEntrySingleContextLimitTest()
        {
            //Arrange 
            var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "LogEntrySingleContextLimitTest" };
            Database.SetInitializer(new DropCreateDatabaseAlways<ZvsContext>());

            using (var context = new ZvsContext(dbConnection))
            {
                for (var i = 0; i < 2023; i++)
                {
                    context.LogEntries.Add(new LogEntry
                    {
                        Datetime = DateTime.Now,
                        Level = LogEntryLevel.Info,
                        Message = string.Format("hello world {0}", i),
                        Source = "Source"
                    });
                }
                await context.SaveChangesAsync(CancellationToken.None);
            }

            using (var context = new ZvsContext(dbConnection))
            {
                var currentLogEntryCount = context.LogEntries.Count();
                var firstentry = await context.LogEntries.OrderBy(o => o.Datetime).FirstAsync();
                var lastEntry = await context.LogEntries.OrderByDescending(o => o.Datetime).FirstAsync();
                //Aseert
                Assert.IsTrue(currentLogEntryCount == 2000, "Expected 2000 entries and got " + currentLogEntryCount);
                Assert.IsTrue(firstentry.Message == "hello world 24", "Expected first entry to start with 24");
                Assert.IsTrue(lastEntry.Message == "hello world 2022", "Expected last entry to start with 2002");
            }
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:32,代码来源:SaveChangesAsyncTests.cs

示例2: RegisterAsyncNewDeviceTypeTest

        public async Task RegisterAsyncNewDeviceTypeTest()
        {
            //arrange 
            var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "dtb-RegisterAsyncNewDeviceTypeTest" };
            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:m19brandon,项目名称:zVirtualScenes,代码行数:29,代码来源:DeviceTypeBuilderTests.cs

示例3: RegisterAsyncNewTest

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

            var builtinCommand = new BuiltinCommand
            {
                Name = "Unit Test Builtin Command",
                UniqueIdentifier = "BUILTIN_COMMAND1"
            };

            //act
            var result = await bcb.RegisterAsync(builtinCommand, CancellationToken.None);

            BuiltinCommand setting;
            using (var context = new ZvsContext(dbConnection))
            {
                setting =
                    await
                        context.BuiltinCommands.FirstOrDefaultAsync(
                            o => o.UniqueIdentifier == builtinCommand.UniqueIdentifier);

            }

            //assert 
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError, result.Message);
            Assert.IsNotNull(setting, "Expected new builtin command setting saved to DB");
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:31,代码来源:BuiltinCommandBuilderTests.cs

示例4: RegisterAsyncNewTest

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

            var deviceSetting = new DeviceSetting
            {
                Name = "Unit Test Device Setting",
                UniqueIdentifier = "DEVICE_SETTING1"
            };

            //act
            var result = await dsb.RegisterAsync(deviceSetting, CancellationToken.None);

            DeviceSetting setting;
            using (var context = new ZvsContext(dbConnection))
            {
                setting =
                    await
                        context.DeviceSettings.FirstOrDefaultAsync(
                            o => o.UniqueIdentifier == deviceSetting.UniqueIdentifier);

            }

            //assert 
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError, result.Message);
            Assert.IsNotNull(setting, "Expected new device setting saved to DB");
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:31,代码来源:DeviceSettingBuilderTests.cs

示例5: 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

示例6: 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

示例7: ConstructorNullArg1Test

 public void ConstructorNullArg1Test()
 {
     //arrange 
     var dbConnection = new StubIEntityContextConnection();
     //act
     new DeviceValueBuilder(null);
     //assert - throws exception
 }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:8,代码来源:DeviceValueBuilderTests.cs

示例8: ConstructorNullArg1Test

 public void ConstructorNullArg1Test()
 {
     var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "MultilpleTriggersTest" };
     Database.SetInitializer(new CreateFreshDbInitializer());
     //arrange 
     //act
     new TriggerRunner(null, new StubICommandProcessor(), new ZvsEntityContextConnection());
     //assert - throws exception
 }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:9,代码来源:TriggerRunnerTests.cs

示例9: ConstructorTest

 public void ConstructorTest()
 {
     //arrange 
     var dbConnection = new StubIEntityContextConnection();
     //act
     var bcb = new BuiltinCommandBuilder(dbConnection);
     //assert 
     Assert.IsNotNull(bcb);
 }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:9,代码来源:BuiltinCommandBuilderTests.cs

示例10: ConstructorTest

 public void ConstructorTest()
 {
     //arrange 
     var dbConnection = new StubIEntityContextConnection();
     //act
     var ssb = new SceneSettingBuilder(dbConnection);
     //assert 
     Assert.IsNotNull(ssb);
 }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:9,代码来源:SceneSettingBuilderTests.cs

示例11: ConstructorTest

 public void ConstructorTest()
 {
     //arrange 
     var dbConnection = new StubIEntityContextConnection();
     //act
     var dvb = new DeviceValueBuilder(dbConnection);
     //assert 
     Assert.IsNotNull(dvb);
 }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:9,代码来源:DeviceValueBuilderTests.cs

示例12: RegisterAsyncNullDeviceValueTest

        public async Task RegisterAsyncNullDeviceValueTest()
        {
            //arrange 
            var dbConnection = new StubIEntityContextConnection();
            var dvb = new DeviceValueBuilder( dbConnection);

            //act
            var result = await dvb.RegisterAsync(null, new Device(), CancellationToken.None);

            //assert 
            Assert.IsTrue(result.HasError);
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:12,代码来源:DeviceValueBuilderTests.cs

示例13: RegisterAsyncNullBuiltinCommandTest

        public async Task RegisterAsyncNullBuiltinCommandTest()
        {
            //arrange 
            var dbConnection = new StubIEntityContextConnection();
            var bcb = new BuiltinCommandBuilder(dbConnection);

            //act
            var result = await bcb.RegisterAsync(null, CancellationToken.None);

            //assert 
            Console.WriteLine(result.Message);
            Assert.IsTrue(result.HasError, result.Message);
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:13,代码来源:BuiltinCommandBuilderTests.cs

示例14: RegisterAsyncNullDeviceValueTest

        public async Task RegisterAsyncNullDeviceValueTest()
        {
            //arrange 
            var dbConnection = new StubIEntityContextConnection();
            var dvb = new DeviceCommandBuilder( dbConnection);

            //act
            var result = await dvb.RegisterAsync(1, null, CancellationToken.None);

            //assert 
            Assert.IsTrue(result.HasError);
            Console.WriteLine(result.Message);
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:13,代码来源:DeviceCommandBuilderTests.cs

示例15: 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


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