本文整理汇总了C#中zvs.Processor.Tests.UnitTestDbConnection类的典型用法代码示例。如果您正苦于以下问题:C# UnitTestDbConnection类的具体用法?C# UnitTestDbConnection怎么用?C# UnitTestDbConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnitTestDbConnection类属于zvs.Processor.Tests命名空间,在下文中一共展示了UnitTestDbConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterAsyncNewTest
public async Task RegisterAsyncNewTest()
{
//arrange
var dbConnection = new UnitTestDbConnection();
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");
}
示例2: RegisterAsyncNewDeviceValueTest
public async Task RegisterAsyncNewDeviceValueTest()
{
//arrange
var dbConnection = new UnitTestDbConnection();
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);
}
}
示例3: LoadAdaptersNameTooLongAsyncTest
public async Task LoadAdaptersNameTooLongAsyncTest()
{
//Arrange
var dbConnection = new UnitTestDbConnection();
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");
}
示例4: 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");
}
示例5: RegisterAsyncNewTest
public async Task RegisterAsyncNewTest()
{
//arrange
var dbConnection = new UnitTestDbConnection();
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");
}
示例6: ConstructorNullArg1Test
public void ConstructorNullArg1Test()
{
//arrange
var dbConnection = new UnitTestDbConnection();
//act
new DeviceValueBuilder(null);
//assert - throws exception
}
示例7: ConstructorTest
public void ConstructorTest()
{
//arrange
var dbConnection = new UnitTestDbConnection();
//act
var bcb = new BuiltinCommandBuilder(dbConnection);
//assert
Assert.IsNotNull(bcb);
}
示例8: ConstructorTest
public void ConstructorTest()
{
//arrange
var dbConnection = new UnitTestDbConnection();
//act
var dvb = new DeviceValueBuilder(dbConnection);
//assert
Assert.IsNotNull(dvb);
}
示例9: ConstructorTest
public void ConstructorTest()
{
//arrange
var dbConnection = new UnitTestDbConnection();
//act
var ssb = new SceneSettingBuilder(dbConnection);
//assert
Assert.IsNotNull(ssb);
}
示例10: ConstructorNullArg1Test
public void ConstructorNullArg1Test()
{
var dbConnection = new UnitTestDbConnection();
Database.SetInitializer(new CreateFreshDbInitializer());
//arrange
//act
new TriggerRunner(null, new StubICommandProcessor(), new UnitTestDbConnection());
//assert - throws exception
}
示例11: RegisterAsyncNullDeviceValueTest
public async Task RegisterAsyncNullDeviceValueTest()
{
//arrange
var dbConnection = new UnitTestDbConnection();
var dvb = new DeviceValueBuilder( dbConnection);
//act
var result = await dvb.RegisterAsync(null, new Device(), CancellationToken.None);
//assert
Assert.IsTrue(result.HasError);
}
示例12: RegisterAsyncNullBuiltinCommandTest
public async Task RegisterAsyncNullBuiltinCommandTest()
{
//arrange
var dbConnection = new UnitTestDbConnection();
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);
}
示例13: RegisterAsyncNullDeviceTest
public async Task RegisterAsyncNullDeviceTest()
{
//arrange
var dbConnection = new UnitTestDbConnection();
var dsb = new DeviceSettingBuilder(dbConnection);
//act
var result = await dsb.RegisterAsync(null, CancellationToken.None);
//assert
Console.WriteLine(result.Message);
Assert.IsTrue(result.HasError, result.Message);
}
示例14: RegisterAsyncNullDeviceValueTest
public async Task RegisterAsyncNullDeviceValueTest()
{
//arrange
var dbConnection = new UnitTestDbConnection();
var dvb = new DeviceCommandBuilder( dbConnection);
//act
var result = await dvb.RegisterAsync(1, null, CancellationToken.None);
//assert
Assert.IsTrue(result.HasError);
Console.WriteLine(result.Message);
}
示例15: ConstructorNullArg3Test
public void ConstructorNullArg3Test()
{
//arrange
var fb = new StubIFeedback<LogEntry>();
var am = new StubIAdapterManager();
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, am, null, connection, tr, st);
//assert - throws exception
}