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");
        }
示例#2
0
        public async Task RegisterAsyncUpdatedDeviceTypeTest()
        {
            //arrange
            var dbConnection = new UnitTestDbConnection();

            Database.SetInitializer(new CreateFreshDbInitializer());

            var dtb     = new DeviceTypeBuilder(dbConnection);
            var adapter = UnitTesting.CreateFakeAdapter();
            var dt      = new DeviceType
            {
                AdapterId        = adapter.Id,
                UniqueIdentifier = "UNIT_TEST_DEVICE_TYPE1",
                Name             = "Unit Test Device Type"
            };

            adapter.DeviceTypes.Add(dt);
            using (var context = new ZvsContext(dbConnection))
            {
                context.Adapters.Add(adapter);
                await context.SaveChangesAsync();
            }

            dt.Name = "New Unit Test Device Type Name";

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

            //assert
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError);
        }
 public void ConstructorTest()
 {
     //arrange 
     var dbConnection = new UnitTestDbConnection();
     //act
     var dvb = new DeviceTypeBuilder(dbConnection);
     //assert 
     Assert.IsNotNull(dvb);
 }
示例#4
0
        public async Task RegisterAsyncRemvoedCommandOptionDeviceTypeTest()
        {
            //arrange
            var dbConnection = new UnitTestDbConnection();

            Database.SetInitializer(new CreateFreshDbInitializer());

            var dtb     = new DeviceTypeBuilder(dbConnection);
            var adapter = UnitTesting.CreateFakeAdapter();
            var dt      = new DeviceType
            {
                AdapterId        = adapter.Id,
                UniqueIdentifier = "UNIT_TEST_DEVICE_TYPE1",
                Name             = "Unit Test Device Type"
            };
            var dtc = new DeviceTypeCommand
            {
                UniqueIdentifier = "DTC1",
                Name             = "Test Device Type Command"
            };
            var option1 = new CommandOption
            {
                Name = "Option 1"
            };
            var option2 = new CommandOption
            {
                Name = "Option 2"
            };

            dt.Commands.Add(dtc);
            adapter.DeviceTypes.Add(dt);
            dtc.Options.Add(option1);
            dtc.Options.Add(option2);
            using (var context = new ZvsContext(dbConnection))
            {
                context.Adapters.Add(adapter);
                await context.SaveChangesAsync();
            }

            dtc.Options.Remove(option1);

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

            using (var context = new ZvsContext(dbConnection))
            {
                var dtc1 = context.DeviceTypeCommands
                           .Include(o => o.Options)
                           .First();

                //assert
                Console.WriteLine(result.Message);
                Assert.IsFalse(result.HasError);
                Assert.IsTrue(dtc1.Options.Count == 1, "Expected 2 options");
            }
        }
示例#5
0
        public void ConstructorTest()
        {
            //arrange
            var dbConnection = new UnitTestDbConnection();
            //act
            var dvb = new DeviceTypeBuilder(dbConnection);

            //assert
            Assert.IsNotNull(dvb);
        }
示例#6
0
        public override async Task OnDeviceTypesCreating(DeviceTypeBuilder deviceTypeBuilder)
        {
            //Sensors
            DeviceType sensor_dt = new DeviceType
            {
                UniqueIdentifier = "MQTT Device",
                Name             = "MQTT Device",
                ShowInList       = true
            };

            SensorTypeId = await deviceTypeBuilder.RegisterAsync(sensor_dt);
        }
        public async Task RegisterAsyncInvalidAdapterTest()
        {
            //arrange 
            var dbConnection = new UnitTestDbConnection();
            Database.SetInitializer(new CreateFreshDbInitializer());

            var dtb = new DeviceTypeBuilder( dbConnection);

            //act
            var result = await dtb.RegisterAsync(new Guid(), new DeviceType(), CancellationToken.None);

            //assert 
            Assert.IsTrue(result.HasError);
            Console.WriteLine(result.Message);
        }
        public async Task RegisterAsyncInvalidAdapterTest()
        {
            //arrange 
            var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "dtb-RegisterAsyncInvalidAdapterTest" };
            Database.SetInitializer(new CreateFreshDbInitializer());

            var dtb = new DeviceTypeBuilder( dbConnection);

            //act
            var result = await dtb.RegisterAsync(new Guid(), new DeviceType(), CancellationToken.None);

            //assert 
            Assert.IsTrue(result.HasError);
            Console.WriteLine(result.Message);
        }
示例#9
0
        public async Task RegisterAsyncInvalidAdapterTest()
        {
            //arrange
            var dbConnection = new UnitTestDbConnection();

            Database.SetInitializer(new CreateFreshDbInitializer());

            var dtb = new DeviceTypeBuilder(dbConnection);

            //act
            var result = await dtb.RegisterAsync(new Guid(), new DeviceType(), CancellationToken.None);

            //assert
            Assert.IsTrue(result.HasError);
            Console.WriteLine(result.Message);
        }
示例#10
0
 public override async Task OnDeviceTypesCreating(DeviceTypeBuilder deviceTypeBuilder)
 {
 }
 public override async Task OnDeviceTypesCreating(DeviceTypeBuilder deviceTypeBuilder)
 {
 }
        public async Task RegisterAsyncRemvoedCommandOptionDeviceTypeTest()
        {
            //arrange 
            var dbConnection = new UnitTestDbConnection();
            Database.SetInitializer(new CreateFreshDbInitializer());

            var dtb = new DeviceTypeBuilder(dbConnection);
            var adapter = UnitTesting.CreateFakeAdapter();
            var dt = new DeviceType
            {
                AdapterId = adapter.Id,
                UniqueIdentifier = "UNIT_TEST_DEVICE_TYPE1",
                Name = "Unit Test Device Type"
            };
            var dtc = new DeviceTypeCommand
            {
                UniqueIdentifier = "DTC1",
                Name = "Test Device Type Command"
            };
            var option1 = new CommandOption
            {
                Name = "Option 1"
            };
            var option2 = new CommandOption
            {
                Name = "Option 2"
            };
            dt.Commands.Add(dtc);
            adapter.DeviceTypes.Add(dt);
            dtc.Options.Add(option1);
            dtc.Options.Add(option2);
            using (var context = new ZvsContext(dbConnection))
            {
                context.Adapters.Add(adapter);
                await context.SaveChangesAsync();
            }

            dtc.Options.Remove(option1);

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

            using (var context = new ZvsContext(dbConnection))
            {
                var dtc1 = context.DeviceTypeCommands
                    .Include(o => o.Options)
                    .First();

                //assert 
                Console.WriteLine(result.Message);
                Assert.IsFalse(result.HasError);
                Assert.IsTrue(dtc1.Options.Count == 1, "Expected 2 options");
            }

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

            var dtb = new DeviceTypeBuilder( dbConnection);
            var adapter = UnitTesting.CreateFakeAdapter();
            var dt = new DeviceType
            {
                AdapterId = adapter.Id,
                UniqueIdentifier = "UNIT_TEST_DEVICE_TYPE1",
                Name = "Unit Test Device Type"
            };
            var dtc = new DeviceTypeCommand
            {
                UniqueIdentifier = "DTC1",
                Name = "Test Device Type Command"
            };
            dt.Commands.Add(dtc);
            adapter.DeviceTypes.Add(dt);
            using (var context = new ZvsContext(dbConnection))
            {
                context.Adapters.Add(adapter);
                await context.SaveChangesAsync();
            }

            dtc.Name = "New DTC Test Name";

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

            using (var context = new ZvsContext(dbConnection))
            {
                var dtc1 = context.DeviceTypeCommands.First();

                //assert 
                Console.WriteLine(result.Message);
                Assert.IsFalse(result.HasError);
                Assert.IsTrue(dtc1.Name == dtc.Name, "Command did not update");
            }

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

            var dtb = new DeviceTypeBuilder(dbConnection);
            var adapter = UnitTesting.CreateFakeAdapter();
            var dt = new DeviceType
            {
                AdapterId = adapter.Id,
                UniqueIdentifier = "UNIT_TEST_DEVICE_TYPE1",
                Name = "Unit Test Device Type"
            };
            adapter.DeviceTypes.Add(dt);
            using (var context = new ZvsContext(dbConnection))
            {
                context.Adapters.Add(adapter);
                await context.SaveChangesAsync();
            }

            dt.Name = "New Unit Test Device Type Name";

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

            //assert 
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError);

        }
示例#15
0
        public override async Task OnDeviceTypesCreating(DeviceTypeBuilder deviceTypeBuilder)
        {
            //Dimmer Type Devices
            var dimmerDt = new DeviceType
            {
                UniqueIdentifier = MiLightDeviceTypes.Color.ToString(),
                Name             = "MiLight Color Light",
                ShowInList       = true
            };

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "Z1TURNON",
                Name             = "Zone 1, Turn On",
                ArgumentType     = DataType.NONE,
                CustomData1      = "On",
                CustomData2      = "One",
                Description      = "Turns Zone 1 On."
            });
            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "Z1TURNOFF",
                Name             = "Zone 1, Turn Off",
                CustomData1      = "Off",
                CustomData2      = "One",
                ArgumentType     = DataType.NONE,
                Description      = "Turns Zone 1 Off."
            });
            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "Z2TURNON",
                Name             = "Zone 2, Turn On",
                ArgumentType     = DataType.NONE,
                CustomData1      = "On",
                CustomData2      = "Two",
                Description      = "Turns Zone 2 On."
            });
            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "Z2TURNOFF",
                Name             = "Zone 2, Turn Off",
                CustomData1      = "Off",
                CustomData2      = "Two",
                ArgumentType     = DataType.NONE,
                Description      = "Turns Zone 2 Off."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "Z3TURNON",
                Name             = "Zone 3, Turn On",
                ArgumentType     = DataType.NONE,
                CustomData1      = "On",
                CustomData2      = "Three",
                Description      = "Turns Zone 3 On."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "Z3TURNOFF",
                Name             = "Zone 3, Turn Off",
                CustomData1      = "Off",
                CustomData2      = "Three",
                ArgumentType     = DataType.NONE,
                Description      = "Turns Zone 3 Off."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "Z4TURNON",
                Name             = "Zone 4, Turn On",
                ArgumentType     = DataType.NONE,
                CustomData1      = "On",
                CustomData2      = "Four",
                Description      = "Turns Zone 4 On."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "Z4TURNOFF",
                Name             = "Zone 4, Turn Off",
                CustomData1      = "Off",
                CustomData2      = "Four",
                ArgumentType     = DataType.NONE,
                Description      = "Turns Zone 4 Off."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "ALLOFF",
                Name             = "All Off",
                CustomData1      = "AllOff",
                CustomData2      = "",
                ArgumentType     = DataType.NONE,
                Description      = "Turns All Zones Off."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "ALLON",
                Name             = "All On",
                CustomData1      = "AllOn",
                CustomData2      = "",
                ArgumentType     = DataType.NONE,
                Description      = "Turns All Zones On."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "HUE",
                Name             = "Hue",
                CustomData1      = "Hue",
                CustomData2      = "",
                ArgumentType     = DataType.DECIMAL,
                Description      = "Changes the current zone the specified hue."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "SETBRIGHTNESS",
                Name             = "SetBrightness",
                CustomData1      = "SetBrightness",
                CustomData2      = "",
                ArgumentType     = DataType.INTEGER,
                Description      = "Changes the current zone the specified brightness."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "EFFECTDOWN",
                Name             = "Previous effect",
                ArgumentType     = DataType.NONE,
                CustomData1      = "EffectDown",
                CustomData2      = "",
                Description      = "Changes the current zone to the previous effect."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "EFFECTUP",
                Name             = "Next Effect",
                CustomData1      = "EffectUp",
                CustomData2      = "",
                ArgumentType     = DataType.NONE,
                Description      = "Changes the current zone to the next effect."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "SPEEDDOWN",
                Name             = "Slower speed",
                ArgumentType     = DataType.NONE,
                CustomData1      = "SpeedDown",
                CustomData2      = "",
                Description      = "Changes the current effect to a slower speed."
            });
            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "SPEEDUP",
                Name             = "Faster Speed",
                CustomData1      = "SpeedUp",
                CustomData2      = "",
                ArgumentType     = DataType.NONE,
                Description      = "Changes the current effect to a faster speed."
            });

            var dimmerSaveResult = await deviceTypeBuilder.RegisterAsync(AdapterGuid, dimmerDt, CancellationToken);

            if (dimmerSaveResult.HasError)
            {
                await
                Log.ReportErrorFormatAsync(CancellationToken,
                                           "An error occured when registering the OpenZWave dimmer device type. {0}",
                                           dimmerSaveResult.Message);
            }

            using (var context = new ZvsContext(EntityContextConnection))
            {
                DimmerTypeId =
                    await
                    context.DeviceTypes.Where(o => o.UniqueIdentifier == MiLightDeviceTypes.Color.ToString())
                    .Select(o => o.Id)
                    .FirstOrDefaultAsync();
            }

            await base.OnDeviceTypesCreating(deviceTypeBuilder);
        }